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+50)/2 : 0;
	tPos = (screen.height) ? (screen.height-height+100)/2 : 0;
	title = title ? title:'Image Popup';
	alt = alt ? alt:'';

	newWin = this.open('', '_blank', "toolbar=no,width="+(width+50)+",height="+(height+100)+",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: #aaa; }\n');
	tmp.write('a { text-decoration: none; font: normal 10px Arial, Helvetica, sans-serif}\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: #000000; }\n');
	tmp.write('.navigation {}\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();">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, name)
{
	lPos = (screen.width) ? (screen.width-width)/2 : 0;
	tPos = (screen.height) ? (screen.height-height)/2 : 0;
	name = (name) ? name : '_blank';

	newWin = this.open(url, name, "toolbar=no,width="+width+",height="+height+",left="+lPos+",top="+tPos+",directories=no,status=no,scrollbars=no,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) : "");
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;

	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
