function addLoadEvent(func) 
{
    var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function submitAndDisableForm(form)
{
    form.submit();
    var elements = form.elements();
    for(var i=0;i<elements.length;i++) {
        elements[i].disabled=true;
    }
}

function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

function popupImage(image, width, height, title, alt)
{
	lPos = (screen.width) ? (screen.width-width)/2 : 0;
	tPos = (screen.height) ? (screen.height-height)/2 : 0;
	title = title ? title:'Image Popup';
	alt = alt ? alt:'';

	newWin = this.open('', '_blank', "toolbar=no,width="+width+",height="+height+",left="+lPos+",top="+tPos+",directories=no,status=no,scrollbars=no,resize=no,menubar=no");
	var tmp = newWin.document;

	tmp.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">\n');
	tmp.write('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>'+title+'</title>\n');
	tmp.write('<head>\n');
	tmp.write('<title>'+title+'</title>\n');
	tmp.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n');
	tmp.write('<style type="text/css">\n');
	tmp.write('body { margin: 0px; background-color: #7c7d6f; }\n');
	tmp.write('a { text-decoration: none; }\n');
	tmp.write('img { border: 1px solid #000; }\n');
	tmp.write('.description { font: normal 12px Arial, Helvetica, sans-serif; color: #000000; line-height: 20px; }\n');
	tmp.write('.title { font: bold 12px Arial, Helvetica, sans-serif; color: #000; }\n');
	tmp.write('.navigation { font: normal 10px Arial, Helvetica, sans-serif; color: #a24547; }\n');
	tmp.write('</style>\n');
	tmp.write('</head>\n');
	tmp.write('<body>\n');
	tmp.write('<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="10" align="center">\n');
	tmp.write('<tr><td align="center" class="title">'+title+'</td></tr>\n');
	tmp.write('<tr><td align="center" height="*" class="description"><img src="'+image+'" alt="'+alt+'" /></td></tr>\n');
	tmp.write('<tr><td align="center"><a href="javascript:window.close();" class="navigation">Close Window</a></td></tr>\n');
	tmp.write('</table>\n');
	tmp.write('</body>\n');
	tmp.write('</html>');

	tmp.close();
	newWin.focus();
}

function popupWindow(url, width, height)
{
	lPos = (screen.width) ? (screen.width-width)/2 : 0;
	tPos = (screen.height) ? (screen.height-height)/2 : 0;

	newWin = this.open(url, '_blank', "toolbar=no,width="+width+",height="+height+",left="+lPos+",top="+tPos+",directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
	newWin.focus();
}

function number_format( number, decimals, dec_point, thousands_sep ) 
{
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? "." : dec_point;
	var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;

	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

var UniqueID = 1234 // Make each link open in a new window 
var newWinOffset = 0 // Position of first pop-up

function PlayerOpen(soundfiledesc,soundfilepath) { 
	PlayWin = window.open('',UniqueID,'width=320,height=190,top=' + newWinOffset +',left=0,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0,personalbar=0');
	PlayWin.focus(); 

	var winContent = "<html><head><title>" + soundfiledesc + "</title></head><body bgcolor='#95A2AB'><link href='/css/style.css' rel='stylesheet' type='text/css'>"; 
	winContent += "<p class=title>" + soundfiledesc + "</p>";

	winContent += "<OBJECT width='300' height='42'>"; 
	winContent += "<param name='SRC' value='" + soundfilepath + "'>";
	winContent += "<param name='AUTOPLAY' VALUE='true'>"; 
	winContent += "<param name='CONTROLLER' VALUE='true'>";
	winContent += "<param name='BGCOLOR' VALUE='#95A2AB'>"; 
	winContent += "<EMBED SRC='" + soundfilepath + "' AUTOSTART='TRUE' LOOP='FALSE' WIDTH='300' HEIGHT='42' CONTROLLER='TRUE' BGCOLOR='#95A2AB'></EMBED>";
	winContent += "</OBJECT>"; 

	winContent += "<p style='font-size:12px;font-family:Verdana,sans-serif;text-align:center'><a href='" + soundfilepath +"'>Download this file</a> <SPAN style='font-size:10px'>(right-click or Option-click)</SPAN></p>";
	winContent += "<FORM><DIV align='center'><INPUT type='button' value='Close Window' onclick='javascript:window.close();' class='button'></DIV></FORM>"; 
	winContent += "</BODY></HTML>"; 

	PlayWin.document.write(winContent); 
	PlayWin.document.close(); // "Finalizes" new window 
	UniqueID = UniqueID + 1 // newWinOffset = newWinOffset + 20 // subsequent pop-ups will be this many pixels lower 
} 


