function formatCurrency2(num) {
num=num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num="0";
sign=(num == (num=Math.abs(num)));
num=Math.floor(num*100+0.50000000001);
cents=num%100;
num=Math.floor(num/100).toString();
if(cents<10)
cents="0" + cents;
for (var i=0; i < Math.floor((num.length-(1+i))/3); i++)
num=num.substring(0,num.length-(4*i+3))+''+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '' + num + '.' + cents);
}

function checkQTY(sText){
			   var ValidChars="0123456789";
			   var IsNumber=true;
			   var Char;
			
			   for (i=0; i < sText.length && IsNumber == true; i++) 
				  { 
				  Char=sText.charAt(i); 
				  if (ValidChars.indexOf(Char) == -1) 
					 {
					 IsNumber=false;
					 }
				  }
			   return IsNumber;
			}

   

/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function currencyFormat(fld, milSep, decSep, e) {
var sep=0;
var key='';
var i=j=0;
var len=len2=0;
var strCheck='0123456789';
var aux=aux2='';
var whichCode=(window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key=String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len=fld.value.length;
for(i=0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux='';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len=aux.length;
if (len == 0) fld.value='';
if (len == 1) fld.value='0'+ decSep + '0' + aux;
if (len == 2) fld.value='0'+ decSep + aux;
if (len > 2) {
aux2='';
for (j=0, i=len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j=0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value='';
len2=aux2.length;
for (i=len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}
//  End -->

function opencode(passdata,passdata1) {
	var objWin;
	
	objWin=window.open("listmember.asp?o=" + passdata + "&m=" + passdata1,"listmember","resizable=yes,scrollbars=yes,width=790,height=590,top=50,left=0");
	if (objWin.opener == null) {
		objWin.opener=self;
	}
}

function openMember(passdata) {
	var objWin;
	
	objWin=window.open("listmember.asp?o=" + passdata,"listmember","resizable=yes,scrollbars=yes,width=790,height=590,top=50,left=0");
	if (objWin.opener == null) {
		objWin.opener=self;
	}
}

function openProduct(passdata) {
	var objWin;
	
	objWin=window.open("ListProduct.asp?f=" + passdata,"listmember","resizable=yes,scrollbars=yes,width=790,height=500,top=10,left=0");
	if (objWin.opener == null) {
		objWin.opener=self;
	}
}

function updateMember(passdata) {
	var flag="";
	var selected_invoice;
	
	for (i=0; i<document.childForm.listmember.length; i++) {
		if (document.childForm.listmember[i].checked == true) {
			selected_invoice=i;
			flag += "1";
		} else {
			flag += "0";
		}
	}
	
	var tem=document.childForm.listmember[selected_invoice].value;
	document.write("tem="+tem);
	
	if (flag.lastIndexOf("1") != "-1") {
		if (passdata == 1) {
			opener.document.parentForm.fromMember.value=document.childForm.listmember[selected_invoice].value;
		document.write(opener.document.parentForm.fromMember.value);
		} else if (passdata == 2) {
			opener.document.parentForm.toMember.value=document.childForm.listmember[selected_invoice].value;
		}
		self.close();
	} else {
		alert("Please Select A Member");
	}
}

function updateCode(passdata) {
	var flag="";
	var selected_invoice;
	
	for (i=0; i<document.childForm.listmember.length; i++) {
		if (document.childForm.listmember[i].checked == true) {
			selected_invoice=i;
			flag += "1";
		} else {
			flag += "0";
		}
	}
	
	if (flag.lastIndexOf("1") != "-1") {
		if (passdata == 1) {
			opener.document.parentForm.sponsorcode.value=document.childForm.listmember[selected_invoice].value;
			opener.document.parentForm.stext.value=document.childForm.listmember1[selected_invoice].value;
		} else if (passdata == 2) {
			opener.document.parentForm.uplinecode.value=document.childForm.listmember[selected_invoice].value;
			opener.document.parentForm.utext.value=document.childForm.listmember1[selected_invoice].value;
		}
		self.close();
	} else {
		alert("Please Select A Member");
	}
}

function openListInvoices()
{
	var objWin;
	objWin=window.open("listInvoices.asp","ChooseInvoices","resizable=yes,scrollbars=yes,width=790,height=400,top=80,left=0")
	if(objWin.opener == null) 
		objWin.opener=self;
}

function updateParent()
{
	var flag="";
	var selected_invoice;
	
	for(i=0; i<document.childForm.invoicesList.length; i++)
	{
		if(document.childForm.invoicesList[i].checked == true)
		{
			selected_invoice=i;
			flag += "1";
		}
		else
			flag += "0";
	}
	
	if(flag.lastIndexOf("1") != "-1")
	{
		opener.document.parentForm.invoiceNo.value=document.childForm.invoicesList[selected_invoice].value;
		opener.document.parentForm.remark.disabled=false;
		self.close();
	}
	else
		alert("Please Select An Invoice");
}

function viewInvoiceDetails()
{
	if(document.parentForm.invoiceNo.value == "")
		alert("Please Enter An Invoice Number.");
	else
		location.href="stockreceived.asp?invoiceno=" + document.parentForm.invoiceNo.value + "&display=yes" + "&remark=" + document.getElementById("remark").value;
}

function displayInvoiceDetailsGrid()
{
	var layerObj=document.getElementById("invoiceDetailsLayer");
	layerObj.className="display";
}

function openSearch(f, s)
{
	var objWin;
	objWin=window.open("/gitl/hq/SearchBox.asp?f=" + f + "&s=" + s,"SearchBox","resizable=yes,scrollbars=yes,width=600,height=400,top=50,left=0");
	if (objWin.opener == null)
		objWin.opener=self;
}

function openSearch2(f, s)
{
	var objWin;
	
	objWin=window.open("/gitl/hq/SearchBox2.asp?f=" + f + "&s=" + s,"SearchBox","resizable=yes,scrollbars=yes,width=700,height=400,top=50,left=0");
	if (objWin.opener == null)
		objWin.opener=self;
}

function CheckNumField()
{
	Key=window.event.keyCode;
	if (Key!=13 && (Key < 48 || Key>57))
		window.event.returnValue=false;
}

function CheckMoneyField()
{
	Key=window.event.keyCode;
	if (Key!=13 && (Key < 48 || Key>57) && Key != 46)
	{
		window.event.returnValue=false;
		return;
	}
	if (Key == 46)
	{
		if(window.event.srcElement.value.search(/\./g)!=-1)
			window.event.returnValue=false;
		return;			
	}
/*		if(window.event.srcElement.value.search(/\./g)!=-1)
	{
		if(window.event.srcElement.value.search(/\./)+2 == window.event.srcElement.value.length-1)
		{
			if(window.event.srcElement.document.selection.createRange().htmlText == "")
				window.event.returnValue=false;
		}
	}*/
}

	
function trim(str)
{
	return str.replace( /[(^\s+)|($\s+)]/g, "" );
}

function openSTOCKIST(passdata) {
	var objWin;
	
	objWin=window.open("/gitl/hq/StkList.asp?f=" + passdata, "ListSTOCKIST","resizable=yes,scrollbars=yes,width=790,height=590,top=50,left=0");
	if (objWin.opener == null) {
		objWin.opener=self;
	}
}

function openSTOCKIST2(passdata,passdata1) {
	var objWin;
	
	objWin=window.open("ListSTOCKIST.asp?o=" + passdata + "&m=" + passdata1,"ListSTOCKIST","resizable=yes,scrollbars=yes,width=790,height=590,top=50,left=0");
	if (objWin.opener == null) {
		objWin.opener=self;
	}
}

function openSTOCKIST3(passdata,passdata1, passdata2) {
	var objWin;
	
	objWin=window.open("ListSTOCKIST.asp?o=" + passdata + "&m=" + passdata1 + "&p=" + passdata2,"ListSTOCKIST","resizable=yes,scrollbars=yes,width=790,height=590,top=50,left=0");
	if (objWin.opener == null) {
		objWin.opener=self;
	}

}

// when usign this function, the button name for print and close must follow the following name....
function GetPrint(){
		var printDisplay=document.getElementById('print').style.display;
		var closeDisplay=document.getElementById('print').style.display;
		
		document.getElementById('print').style.display="none";
		document.getElementById('close').style.display="none";
		window.print();
		document.getElementById('print').style.display=printDisplay;
		document.getElementById('close').style.display=closeDisplay;
	}

function editDG(cellid){
	var recCount=cellid;
	try{
		if (parent.document.getElementById('A'+recCount).value != ""){} 
	} catch(e){
		parent.addRowAdjection();
	}
}

function editDG2(cellid){
	var recCount=cellid;
	try{
		if (document.getElementById('A'+recCount).value != ""){} 
	} catch(e){
		addRowAdjection();
	}
}

function getPDFDownload(){
	window.open("http://ardownload.adobe.com/pub/adobe/reader/win/7x/7.0.8/enu/psa30se_ytb612_a708_DLM_en_us.exe","");
}

//print preview
function printpr()
{
	var OLECMDID=7;
	/* OLECMDID values:
	* 6 - print
	* 7 - print preview
	* 1 - open window
	* 4 - Save As
	*/
	var PROMPT=1; // 2 DONTPROMPTUSER 
	var WebBrowser='<OBJECT ID="WebBrowser" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
	WebBrowser1.ExecWB(OLECMDID, PROMPT);
	WebBrowser1.outerHTML="";
	<!--<input type='button' value='Print Preview' class='button' onclick="printpr();">&nbsp;-->
}

function getMulPayISCC(stype){
	try{
		if(stype=="CC"){
			for (i=1;i<=document.getElementById('paymentrow').value;i++) {
				if (document.getElementById('pA'+i).value =='CreditCard') {return "y";}
			}
		}
	}catch(e){}
	
	return "";
}

function exportFile(fn){
	document.execCommand('SaveAs', '1', 'excel_'+fn+'.xls');
}

function specChar(){
	//cannot space too
	Key=window.event.keyCode;
	//- 45
	if ((Key>=32 && Key<=38) || (Key>=41 && Key<=43) || Key==45 || Key==47 || Key==58 || (Key>=60 && Key<=63)  || Key==94 || Key==95 || Key==124 || Key==126 || Key==39)
		window.event.returnValue=false;
}

function printpr()
{
	var OLECMDID=7;
	/* OLECMDID values:
	* 6 - print
	* 7 - print preview
	* 1 - open window
	* 4 - Save As
	*/
	var PROMPT=1; // 2 DONTPROMPTUSER 
	var WebBrowser='<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
	WebBrowser1.ExecWB(OLECMDID, PROMPT);
	WebBrowser1.outerHTML 
}

function browser_hide(idname, stype, actiontype){
	try {
		var styletype="";
		if(stype=="rpt" || stype=="edit" || stype=="add" || stype=="ui"){
			if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 5 ){
				styletype=actiontype=="none" ? "none" : "";
				document.getElementById(idname).style.display=styletype;
			}else{
				styletype=actiontype;
				document.getElementById(idname).style.display=styletype;	
			}
		}
	}catch(e){}
}

function browser_value(idname, stype, val, actiontype){
	try {
		if (stype=="add" && actiontype=="opener")
			opener.document.getElementById(idname).value=val;
		if (stype=="add" && actiontype=="parent")
			parent.document.getElementById(idname).value=val;
		if (stype=="add" && actiontype=="self")
			document.getElementById(idname).value=val;
		if (stype=="edit" && actiontype=="parent")
			parent.document.getElementById(idname).value=val;
		if (stype=="rtn" && actiontype=="parent")
			return parent.document.getElementById(idname).value;
		if (stype=="rtn" && actiontype=="self")
			return document.getElementById(idname).value;
		if (stype=="readonly" && actiontype=="parent")
			return parent.document.getElementById(idname).readonly=true;		
		if (stype=="ui" && actiontype=="")
			document.getElementById(idname).value=val;
	}catch(e){}
}

function browser_checkbox(idname, stype, val, actiontype){
	try {
		if (stype=="edit" && actiontype=="parent")
			parent.document.getElementById(idname).checked=val;	
		if (stype=="rtn" && actiontype=="parent")
			return parent.document.getElementById(idname).checked; 
		if (stype=="rtn" && actiontype=="self")
			return document.getElementById(idname).checked; 
		if (stype=="ui" && actiontype=="")
			document.getElementById(idname).checked=val;	
	}catch(e){}
}

function browser_btn(idname, stype, val, actiontype){
	try {
		if (stype=="disabled" && actiontype=="parent")
			parent.document.getElementById(idname).disabled=val;	
		if (stype=="disabled" && actiontype=="")
			document.getElementById(idname).disabled=val;
		if (stype=="disabled" && actiontype=="self")
			document.getElementById(idname).disabled=val;		
	}catch(e){}
}

function browser_focus(idname, stype, val, actiontype){
	try {
		if (actiontype=="parent")
			parent.document.getElementById(idname).focus();	
		if (actiontype=="self")
			document.getElementById(idname).focus();	
	}catch(e){}
}

function flipCell(count){
	//f=document.getElementById("mcell");
	//f.style.display=(f.style.display=="block")?"none":"block";
}
