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("/dclassic/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("/dclassic/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("/dclassic/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 GetFriendlyPrint(title)
{
	var winRpt;
	winRpt = window.open(title);
	winRpt.document.writeln('<link href=\"/dclassic/_css/Default.css\" rel=\"stylesheet\" type=\"text/css\">');
	winRpt.document.writeln('<table border=\"0\" align=\"center\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"center\">');
	winRpt.document.writeln(document.getElementById("contentForm").innerHTML);
	winRpt.document.writeln('</td></tr></table>');
	winRpt.document.close();
}

function getDateMM(val){
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";

	for(var i=0; i<12; i++){
		if(strMonthArray[i] == val){
			break;
		}
	}
	return i+1;	
}

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==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")
			parent.document.getElementById(idname).focus();	
	}catch(e){}
}

function flipCell(count){
	//f=document.getElementById("mcell");
	//f.style.display=(f.style.display=="block")?"none":"block";
}

