function format_number(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	//result = AddComma(result);
	return result;
}

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 winOpenAdjNotnew(url, widthb, heightb, toolb, menub, scrollb, resizeb, statusb){
	var h = heightb;
	var w = widthb;
	var t = toolb
	var m = menub
	var sc = scrollb
	var r = resizeb
	var st= statusb

	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings = 'height=' + h + ',width=' + w + ',top=' + (TopPosition-50) + ',left=' + LeftPosition + ',toolbar=' + t + ', menubar=' + m + ', scrollbars=' + sc + ', resizable=' + r + ', status=' + st + ''
	var rtnVal = window.open(url, 'Popup', settings)

}

function winOpenAdj(url, widthb, heightb, toolb, menub, scrollb, resizeb, statusb){
	var h = heightb;
	var w = widthb;
	var t = toolb
	var m = menub
	var sc = scrollb
	var r = resizeb
	var st= statusb

	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings = 'height=' + h + ',width=' + w + ',top=' + (TopPosition-50) + ',left=' + LeftPosition + ',toolbar=' + t + ', menubar=' + m + ', scrollbars=' + sc + ', resizable=' + r + ', status=' + st + ''
	var rtnVal = window.open(url, '_openadj', settings)

}


function ExecuteURL(url){
	document.frmMain.action = url;
	document.frmMain.submit();
}

function ExecuteURLNews(url){
	document.frmShow.action = url;
	document.frmShow.submit();
}


function GoToURL(url){
	document.location = url;

}

//here you place the idxt of every element you want.
var idxt1=new Array('b1','b2');
function switchid1(id){	
	hideallidxt1();
	showdiv1(id);
}

function hideallidxt1(){
	//loop through the array and hide each element by id
	for (var i=0;i<idxt1.length;i++){
		hidediv1(idxt1[i]);
	}		  
}

function hidediv1(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv1(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

//here you place the idxt of every element you want.
var idxt2=new Array('c1','c2');
function switchid2(id){	
	hideallidxt2();
	showdiv2(id);
}

function hideallidxt2(){
	//loop through the array and hide each element by id
	for (var i=0;i<idxt2.length;i++){
		hidediv2(idxt2[i]);
	}		  
}

function hidediv2(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv2(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}


//here you place the idxt of every element you want.
var idxt3=new Array('d1','d2');
function switchid3(id){	
	hideallidxt3();
	showdiv3(id);
}

function hideallidxt3(){
	//loop through the array and hide each element by id
	for (var i=0;i<idxt3.length;i++){
		hidediv3(idxt3[i]);
	}		  
}

function hidediv3(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv3(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}


function numeralsOnly(thisComp,e,isDecimal) {
	var key;
	var keychar;
	if (window.event) {
	key = window.event.keyCode;
	}
	else if (e) {
	key = e.which;
	}
	else {
	return true;
	}

	// check double period/decimal/point
	if (  ((thisComp.value).indexOf('.') > -1) && key == 46){
	alert('ไม่อนุญาติให้ใส่จุดมากกว่า1ครั้ง.');
	return false;
	}

	var str = ' 0123456789';
	//str +=isDecimal ? '.':";
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
	return true;
	}
	else if (((str).indexOf(keychar) > -1)) {
	return true;
	}

	alert('ใส่เฉพาะตัวเลขเท่านั้น.');
	thisComp.focus();
	//thisComp.select();
	return false;
}


function numeralsOnly2(thisComp,e,isDecimal) {
	var key;
	var keychar;
	if (window.event) {
	key = window.event.keyCode;
	}
	else if (e) {
	key = e.which;
	}
	else {
	return true;
	}

	// check double period/decimal/point
	if (  ((thisComp.value).indexOf('.') > -1) && key == 46){
	alert('ไม่อนุญาติให้ใส่จุดมากกว่า1ครั้ง.');
	return false;
	}

	var str = ' 0123456789/-';
	//str +=isDecimal ? '.':";
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
	return true;
	}
	else if (((str).indexOf(keychar) > -1)) {
	return true;
	}

	alert('ใส่เฉพาะตัวเลขเท่านั้น.');
	thisComp.focus();
	//thisComp.select();
	return false;
}


function numeralsOnly3(thisComp,e,isDecimal) {
	var key;
	var keychar;
	if (window.event) {
	key = window.event.keyCode;
	}
	else if (e) {
	key = e.which;
	}
	else {
	return true;
	}

	// check double period/decimal/point
	if (  ((thisComp.value).indexOf('.') > -1) && key == 46){
	alert('ไม่อนุญาติให้ใส่จุดมากกว่า1ครั้ง.');
	return false;
	}

	var str = ' 0123456789.';
	//str +=isDecimal ? '.':";
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
	return true;
	}
	else if (((str).indexOf(keychar) > -1)) {
	return true;
	}

	alert('ใส่เฉพาะตัวเลขเท่านั้น.');
	thisComp.focus();
	//thisComp.select();
	return false;
}




function EnglishOnly(thisComp,e,isDecimal) {
	var key;
	var keychar;
	if (window.event) {
	key = window.event.keyCode;
	}
	else if (e) {
	key = e.which;
	}
	else {
	return true;
	}

	// check double period/decimal/point
	//if (  ((thisComp.value).indexOf('.') > -1) && key == 46){
	//alert('ไม่อนุญาติให้ใส่จุดมากกว่า1ครั้ง.');
	//return false;
	//}

	var str = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,._/*-+=!@#$%^&*()<>:;\'';
	//str +=isDecimal ? '.':";
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
	return true;
	}
	else if (((str).indexOf(keychar) > -1)) {
	return true;
	}

	alert('ใส่เฉพาะภาษาอังกฤษเท่านั้น.');
	thisComp.focus();
	//thisComp.select();
	return false;
}