﻿// JScript File
//
var gv_invAC=new Array();
var gv_invName=new Array();
var gv_invIndex=0; // 0-based currently selected customer index.
var gv_invFocusIndex=0; //Currently focused customer
var gv_invNumPerPage=0;
var gv_invCurPage=0; //0-base current page number
var gv_invTotPage=0;
var gv_invEditingData=0;
var gv_invDataCategory=null;
var gv_invEditedName=null;  // Stores edited customer item name(name=cat_name, eg. 1_AC Ref
var gv_invEditedValue=null; // Edited values
var gv_tempTable;
var gv_invRowH=20;
var gv_scrollCurPage=0;
var gv_scrollTotPage=0;
var InviPage = 1;
var InvTotalPage = 1;

function doInvList()
{
	var url = gv_rooturl+"?cmd=InvoiceList"+"&InviPage="+InviPage;
	var xmlhttp = newHttpRequest(url,true);
	if( xmlhttp==null ) return;
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 ) {
			if( xmlhttp.status!=200 ) alert("Connection error");
			else
			{
			    var invtotalpages=xmlhttp.responseXML.getElementsByTagName("InvTotalPage");
                InvTotalPage = parseInt(invtotalpages[0].firstChild.nodeValue);
			    renewInvList(xmlhttp.responseXML);
			}
			document.getElementById('idloading').style.visibility='hidden';
		}
	}
	xmlhttp.send(null);
	document.getElementById('idloading').style.visibility='visible';
}

//<CusList>
//  <Customer>
//    <AC>..</AC>
//    <Name>..</Name>
//  </Customer>
//  <Customer>
//    <AC>..</AC>
//    <Name>..</Name>
//  </Customer>
//<CusList>
//
function renewInvList(xmldoc)
{
	var invoices=xmldoc.getElementsByTagName("Invoice");
	gv_invAC.length=gv_invName.length=0;
	gv_invIndex=0;
	
    for(var i=0; i<invoices.length; i++) {
		var curNode=invoices[i].firstChild;
		gv_invAC[i]=gv_invName[i]="";
		while( curNode )  
		{
			switch(curNode.nodeName){
				case "InvoiceNumber" : gv_invAC[i]=curNode.firstChild.nodeValue;  break;
				case "ACRef" : gv_invName[i]=curNode.firstChild.nodeValue;  break;
			}
			curNode=curNode.nextSibling;
		}
    }
    if(invoices.length==0) alert("No invoices found!");
    else {
        //gv_invCurPage=0;
		gv_invTotPage=0;
		showInvList();
	}
}
function showInvList()
{
	if(gv_invAC.length==0) return;
    gv_tempTable = document.getElementById('tempTable');
	var ycur=gv_tempTable.style.pixelTop=gv_device==Nokia ? 28:26;
	var tdstr="<td height='"+gv_invRowH+"px'>";
	var tabstr="<table border='1' cellpadding='1' cellspacing='0' style='position:absolute;width:"+(gv_winw-4)+"px;left:2px;'>"; 
	//var ixs=gv_invCurPage*gv_invNumPerPage;
	var idx=0;
    for(var i=0; i<gv_invAC.length; i++) {
		var imgName=idx==gv_invIndex ? 'radon.png':'radoff.png';
		var trColor=idx==gv_invIndex ? '#ffcc00':'#add8e6';
		var radstr="<td width='22px' height='"+gv_invRowH+"px'><input type='image' src='img/"+imgName+
			"' id='inv_img"+idx+"' onclick='invoiceRowClicked(event);'";
		if(gv_device==Nokia) radstr+="onfocus='overInvoiceItem(event);' onblur='leavInvoiceItem(event);'></td>";
		else radstr+="onmouseover='overInvoiceItem(event);' onmouseleave='leavInvoiceItem(event);'></td>";
		tabstr+="<tr id='inv_row"+idx+"' onclick='invoiceRowClicked(event);' style='background-color:"+
			trColor+";'>"+radstr + tdstr+gv_invAC[i]+"</td>"+tdstr+gv_invName[i]+"</td></tr>";
		//ycur+=gv_invRowH;
		//if(ycur+45>gv_winh) break; else 
		idx++;
    }
//    if(gv_invTotPage==0) {
//		gv_scrollCurPage=gv_invCurPage=0;
//		gv_invNumPerPage=i;
//		var ntt=gv_invAC.length;
//		gv_invTotPage=0;
//		while(ntt>0) {gv_invTotPage++; ntt-=gv_invNumPerPage; }
		gv_scrollTotPage=InvTotalPage;
		if(gv_device!=Nokia) {
			var mleft=document.getElementById('img_mleft3');
			mleft.onclick=invPageLeft;
			mleft.style.cursor='hand';
			var mright=document.getElementById('img_mright3');
			mright.onclick=invPageRight;
			mright.style.cursor='hand';
		}
//    }
    gv_tempTable.innerHTML=tabstr+"</table>";
    gv_tempTable.style.left='0px';
    gv_tempTable.style.visibility='visible';
    if(gv_device!=Nokia) {
		var btnBack=document.getElementById("back2submenu");
		btnBack.style.pixelTop=gv_winh-28;
	}
	//gv_invFocusIndex=gv_invIndex;
	
    var invoicecmd = document.getElementById('sopCmds');
	invoicecmd.style.pixelLeft=gv_winw-invoicecmd.style.pixelWidth-1;
	invoicecmd.style.pixelTop = gv_winh-29;
    invoicecmd.style.visibility='visible';
    if(gv_device!=Nokia) {
		var btn1=document.getElementById('btnInvoiceDetail');
		if(btn1==null) setInvPageScrollCommands(
			"<input type='button' id='btnInvoiceDetail' value='Details' onclick='showInvDetail(0);' />",
			"<input type='button' id='btnInvoiceEdit' value='Edit' onclick='editInvDetail(0);' />");
			
	     }
	setInvPageScroll();
	doNokiaMenuInvList();    
}
function setInvPageScroll()
{   var pncur=document.getElementById('pn_cur3');
    pncur.innerHTML='Page '+(gv_scrollCurPage+1)+' of '+gv_scrollTotPage;
    var pnleft=document.getElementById('pn_left3');
    pnleft.innerHTML=gv_scrollCurPage>0 ? gv_scrollCurPage.toString():'';
    var pnright=document.getElementById('pn_right3');
    pnright.innerHTML=gv_scrollCurPage<gv_scrollTotPage-1 ? (gv_scrollCurPage+2).toString():'';  
}
function invoiceRowClicked(ee)
{
	var srcele=getEventObject(ee);
	if(srcele.id.length<8) return;
	var newIndex=parseInt(srcele.id.substring(7));
	if(gv_invIndex==newIndex) return;
	document.getElementById('inv_row'+gv_invIndex).style.backgroundColor='#add8e6';
	document.getElementById('inv_img'+gv_invIndex).src='img/radoff.png';
	document.getElementById('inv_row'+newIndex).style.backgroundColor='#ffcc00';
	document.getElementById('inv_img'+newIndex).src='img/radon.png';
	gv_invIndex=newIndex;
}
function overInvoiceItem(e_event)
{
	var srcobj=getEventObject(e_event);
	if(srcobj.id=='inv_img'+gv_invIndex) return; // Entering the current selection
	srcobj.src="img/radover.png";
}
function leavInvoiceItem(e_event)
{
	var srcobj=getEventObject(e_event);
	if(srcobj.id=='inv_img'+gv_invIndex) return; // Leaving the current selection
	srcobj.src="img/radoff.png";
}
function invPageLeft()
{
	if(gv_scrollCurPage<=0) return;
    
   
	var selcat=document.getElementById('selinvcat');
	var selinvitemcat=document.getElementById('selinvitemcat');
	 //If null, then in Customer List.
	var divtab=document.getElementById('tempTable');
	var tleft=divtab.style.pixelLeft;

	if(tleft>=gv_winw-30) {	
		gv_scrollCurPage--;
		divtab.style.pixelLeft=0;
		if(selcat) { //Customer data
			if(gv_invEditingData==1) checkInvPageEdited(gv_scrollCurPage+1); //Save any edited data to memory
			selcat.selectedIndex=gv_scrollCurPage;
			showInvDataPage();
		}
			else if(selinvitemcat)
		{
		   
//			if(gv_sopItemEditingData==1) checkSopItemPageEdited(gv_scrollCurPage-1);
			selinvitemcat.selectedIndex=gv_scrollCurPage;
	        
			showInvItemDataPage();
		}
		else
		 { //customer list
			gv_invCurPage=gv_scrollCurPage;		
			gv_invIndex=0;
			InviPage--;
			if(InviPage < 1)
			{
			    InviPage = 1;
			    return;
			}
			doInvList();
		}
	}
	else {
		divtab.style.pixelLeft=tleft+30;
		setTimeout("invPageLeft();",75);
	}
}
 
function invPageRight()
{
         

	if(gv_scrollCurPage>=gv_scrollTotPage-1) return;

	var selcat=document.getElementById('selinvcat'); //If null, then in Customer List.
	var selinvitemcat=document.getElementById('selinvitemcat');
	var divtab=document.getElementById('tempTable');
	var tleft=divtab.style.pixelLeft;
	if(tleft<30-gv_winw) {	
		gv_scrollCurPage++;
		divtab.style.pixelLeft=0;
		if(selcat) { //Customer data
			selcat.selectedIndex=gv_scrollCurPage;
			if(gv_invEditingData==1) checkInvPageEdited(gv_scrollCurPage-1); //Save any edited data to memory
			showInvDataPage();			
		}
		else if(selinvitemcat)
		{
		   selinvitemcat.selectedIndex=gv_scrollCurPage;
//			if(gv_invItemEditingData==1) checkSopItemPageEdited(gv_scrollCurPage-1);
			showInvItemDataPage();
			
		}
		else { //customer list
		gv_invCurPage=gv_scrollCurPage;		
			gv_invIndex=0;
			InviPage++;
			if(InviPage > InvTotalPage)
			{
			    InviPage = InvTotalPage;
			    return;
			}
			doInvList();
		}
	}
	else
	 {
		divtab.style.pixelLeft=tleft-30;
	
		  setTimeout("invPageRight();",75);
	 }
}



function doNokiaMenuInvList()
{
	if(window.widget) {
		window.menu.clear();
		var mShow = new MenuItem('Show Invoice Details',2102);
		mShow.onSelect=showInvDetail;
		window.menu.append(mShow);
		var mEdit = new MenuItem('Edit Invoice Details',2103);
		mEdit.onSelect=editInvDetail;
		window.menu.append(mEdit);
		var mBack = new MenuItem('Back',2104);
		mBack.onSelect=backSops;
		window.menu.append(mBack);
	}
}
function getInvDetail()
{
	var ACIndex=gv_invCurPage*gv_invNumPerPage+gv_invIndex;
	if(gv_invEditingData==0)
	{
	  var url = gv_rooturl+"?cmd=ShowInvoiceDetail&InvoiceNumber="+gv_invAC[ACIndex]+"&index="+ACIndex;
	}
	if(gv_invEditingData==1)
	{
	  var url = gv_rooturl+"?cmd=EditInvoiceDetail&InvoiceNumber="+gv_invAC[ACIndex]+"&index="+ACIndex;
	}
		var xmlhttp = newHttpRequest(url,true);
	gv_orderNo=gv_invAC[ACIndex];
	if( xmlhttp==null ) return;
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 ) {
			if( xmlhttp.status!=200 ) alert("Connection error");
			else {
				gv_invDataCategory=xmlhttp.responseXML.getElementsByTagName("DataCategory");
				if(gv_invDataCategory.length==0) alert("Cannot load details!");
				else {
					gv_scrollCurPage=0;
					gv_scrollTotPage=gv_invDataCategory.length;
					showInvDataPage();
				}
			}
			document.getElementById('idloading').style.visibility='hidden';
		}
	}
	xmlhttp.send(null);
	document.getElementById('idloading').style.visibility='visible';
	gv_invEditedName=null;
	gv_invEditedValue=null;
}
function showInvDetail(cmdid)
{
	gv_invEditingData=0;
	getInvDetail();

}
function editInvDetail(cmdid)
{
	gv_invEditingData=1;
	getInvDetail();
}
var InvN_Format = "",InvN_Tax_Code = "",InvN_Department="",InvN_Courier = "",InvN_G_Tax_Code="",InvN_G_Department="",InvN_Bank_Account="";
var Inv_Format = "",Inv_Tax_Code = "",Inv_Department="",Inv_Courier = "",Inv_G_Tax_Code="",Inv_G_Department="",Inv_Bank_Account="";
var oInv_Format ="",oInv_Tax_Code = "",oInv_Department="",oInv_Courier = "",oInv_G_Tax_Code="",oInv_G_Department="",oInv_Bank_Account="";
function showInvDataPage()
{ 
	var widstyle="style='width:"+Math.round(gv_winw/2).toString()+"px' ";
	var tabstr="<table cellpadding='1' cellspacing='0' style='position:absolute;background-color:#98F898;width:"+(gv_winw-4)+"px;left:2px;'>"; 
	var ycur=gv_tempTable.style.pixelTop=gv_device==Nokia ? 28:26;
	var tdh="height='"+gv_sopRowH+"px'";  //height='24px'
	var rowJump="<tr><td align=right "+tdh+">Jump to Page</td><td><select class='edtxt' "+widstyle+" id='selinvcat' onchange='jumpToInvCat();'>";
    for(var ic=0; ic<gv_invDataCategory.length; ic++) {
		var attName0=gv_invDataCategory[ic].attributes.getNamedItem("title");
		if(attName0) {
			var tname=attName0.value.replace('_',' ');
			rowJump+="<option label='"+tname+"'";
			if(ic==gv_scrollCurPage) rowJump+=" selected=true";
			rowJump+=">"+tname+"</option>";
		}
	}	
	rowJump+="</select></td></tr>";

	
 for(var ic=gv_scrollCurPage; ic<gv_invDataCategory.length; ic++) {
		var attName=gv_invDataCategory[ic].attributes.getNamedItem("title");	
		if(attName==null) continue;
		var rowtxt=ic==gv_scrollCurPage ? rowJump:'';
		rowtxt += "<tr><td colspan=2 align=center "+tdh+" style='color:blue;font-weight:bold;text-decoration:underline;'>"
			+attName.value+"</td></tr>";
			
			ycur+=gv_invRowH;
	var curNode=gv_invDataCategory[ic].firstChild;
		var end_tdr = gv_invEditingData==1 ? "></td></tr>":" ReadOnly></td></tr>";	

	while( curNode ) 
		{
			var itemName=curNode.nodeName;
			var itemId=ic.toString()+"_"+itemName;
			var ndv=curNode.firstChild;
		    var itemVal=getEditedInvData(itemId);
		     if(itemVal==null) itemVal=ndv?ndv.nodeValue:'';

			if(	gv_invEditingData==0)
			{
			if(curNode.firstChild != null) { var cusDropDownVal = curNode.childNodes[0].data; } else { var cusDropDownVal = "";}
			     if(itemName=="Tax_Code")
                 {
                      rowtxt+="<tr><td align='right'"+tdh+">Tax Code &nbsp</td><td><select class='edtxt'  "+widstyle+" ReadOnly><option value='"+cusDropDownVal+"' selected='true'>"+cusDropDownVal+"</option></select " +end_tdr; 
	             }
	             else if(itemName=="Format")
                 {
                      rowtxt+="<tr><td align='right'"+tdh+">Format &nbsp</td><td><select  class='edtxt' "+widstyle+" ReadOnly><option value='"+cusDropDownVal+"' selected='true'>"+cusDropDownVal+"</option></select " +end_tdr; 
	             }

			     else if(itemName=="Department")
                 {
                      rowtxt+="<tr><td align='right'"+tdh+">Department &nbsp</td><td><select class='edtxt'  "+widstyle+" ReadOnly><option value='"+cusDropDownVal+"' selected='true'>"+cusDropDownVal+"</option></select " +end_tdr; 
	             }
			     else if(itemName=="Courier")
                 {
                      rowtxt+="<tr><td align='right'"+tdh+">Courier &nbsp</td><td><select class='edtxt'  "+widstyle+" ReadOnly><option value='"+cusDropDownVal+"' selected='true'>"+cusDropDownVal+"</option></select " +end_tdr; 
	             }
			     else if(itemName=="G_Tax_Code")
                 {
                      rowtxt+="<tr><td align='right'"+tdh+">Tax Code &nbsp</td><td><select  class='edtxt' "+widstyle+" ReadOnly><option value='"+cusDropDownVal+"' selected='true'>"+cusDropDownVal+"</option></select " +end_tdr; 
	             }
			     else if(itemName=="G_Department")
                 {
                      rowtxt+="<tr><td align='right'"+tdh+">Department &nbsp</td><td><select  class='edtxt' "+widstyle+" ReadOnly><option value='"+cusDropDownVal+"' selected='true'>"+cusDropDownVal+"</option></select " +end_tdr; 
	             }
			     else if(itemName=="Bank_Account")
                 {
                      rowtxt+="<tr><td align='right'"+tdh+">Bank Account &nbsp</td><td><select  class='edtxt' "+widstyle+" ReadOnly><option value='"+cusDropDownVal+"' selected='true'>"+cusDropDownVal+"</option></select " +end_tdr; 
	             }

                 else if(itemName=="Customer_ACRef")
                  {
         			   rowtxt+="<tr><td align=right "+tdh+">Customer A/C &nbsp<br>Ref &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
         
                  }
                  else if(itemName=="Order_Type")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Order Type &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"' ReadOnly"+end_tdr;
                
                  }

                  else if(itemName=="Customer_Order_Number")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Customer Order &nbsp<br>Number &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="Customer_Tel_No")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Customer Tel No &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="VAT_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">V.A.T GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                  else if(itemName=="NC")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">N/C &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }

                   else if(itemName=="Consign_Number")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Consign. Number &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="Delivery_Post_Code")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Delivery Post Code &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="Discount")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Discount% &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="Payment_Amount_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Payment Amount &nbsp<br>GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                  else if(itemName=="Set_Gross_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Gross GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
		 else if(itemName=='Item_No')	
	      {
	      //     var rowJump1="<tr><td align=right "+tdh+">Item No</td><td><select class='edtxt' "+"style='width:95px' "+" id='selsopcat1' onchange='jumpToSopCat();'><input type='Button'  Value='ViewItem' Runat='server' style='color:blue;font-weight:bold;width:65px;height:20px;text-decoration:underline;'/>";
	       var rowJump1="<tr><td align=right "+tdh+">Item No &nbsp</td><td><select class='edtxt' "+widstyle+" id='selinvitempagecat' onchange='jumpToInvItemPageCat();'>";
	        var invItems = curNode.firstChild;
	          for(var i=0; i<curNode.childNodes.length;i++)   
	           {
	           var attName1=curNode.childNodes[i].childNodes[0].data;                          
	             	if(attName1) 
	             	{
			            var tname1=attName1.replace('_',' ');
		                  rowJump1+="<option label='"+tname1+"'";
		                  // 	if(i==gv_scrollCurPage) rowJump1+=" selected=true";
		                       rowJump1+=">"+tname1+"</option>";		   
		             }
            	}	 
            	 
	      //    rowJump1+="</select></td></tr>"; 
	          rowJump1+="<tr><td colspan=2 align=center "+tdh+" style='color:blue;font-weight:bold;text-decoration:underline;'><input type='Button'  Value='ViewItem' id='ViewButton' onclick='showInvItemDetail()' Runat='server' style='color:blue;font-weight:bold;width:65px;height:20px;text-decoration:underline;'/></td></tr>";
	                  rowtxt+=rowJump1;
	              
           } 
      	          else
                 {
			            rowtxt+="<tr><td align=right "+tdh+">"+itemName.replace('_',' ')+"&nbsp&nbsp"+"</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt'  "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
			 	 }
			}

			if(gv_invEditingData==1)
			{     
			      if(itemName=="InvN_Format")
	              {
	                 if(ndv !=null)
	                 { InvN_Format = ndv.nodeValue;}
	              }
			      else if(itemName=="InvN_Tax_Code")
	              {
	                 if(ndv !=null)
	                 { InvN_Tax_Code = ndv.nodeValue;}
	              }
			      else if(itemName=="InvN_Department")
	              {
	                 if(ndv !=null)
	                 { InvN_Department = ndv.nodeValue;}
	              }
			      else if(itemName=="InvN_Courier")
	              {
	                 if(ndv !=null)
	                 { InvN_Courier = ndv.nodeValue;}
	              }
			      else if(itemName=="InvN_G_Tax_Code")
	              {
	                 if(ndv !=null)
	                 { InvN_G_Tax_Code = ndv.nodeValue;}
	              }
			      else if(itemName=="InvN_G_Department")
	              {
	                 if(ndv !=null)
	                 { InvN_G_Department = ndv.nodeValue;}
	              }
			      else if(itemName=="InvN_Bank_Account")
	              {
	                 if(ndv !=null)
	                 { InvN_Bank_Account = ndv.nodeValue;}
	              }
//	             else if(itemName=="Format")
//                 {
//                    var rowJumpInv="<tr><td align='right'"+tdh+">Format &nbsp</td><td><select class='edtxt'  id='Inv_Format' value='Inv_Format' ReadOnly "+widstyle+" onchange ='InvDropDownList();'>";
//                    for(var i=0; i< curNode.childNodes.length; i++) 
//                    { 
//                      var attInvName=curNode.childNodes[0].data;                       
//                     if(attInvName) 
//                     {
//                        rowJumpInv+="<option value='"+attInvName+"'";
//                       if(Inv_Format == "" && InvN_Format==attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
//                       else if(attInvName == Inv_Format || Inv_Format == attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
//                       rowJumpInv+=">"+attInvName+"</option>"; 
//                     }
//                  }  
//                      rowtxt+=rowJumpInv+"</select></td></tr>";
//	             }
 
			     else if(itemName=="Tax_Code")
                 {
                    var rowJumpInv="<tr><td align='right'"+tdh+">Tax Code &nbsp</td><td><select  class='edtxt' id='Inv_Tax_Code' value='Inv_Tax_Code' "+widstyle+" onchange =' InvDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attInvName=curNode.childNodes[i].childNodes[0].data;                      
                     if(attInvName) 
                     {
                        rowJumpInv+="<option value='"+attInvName+"'";
                       if(Inv_Tax_Code == "" && InvN_Tax_Code==attInvName.slice(1,3).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       else if(attInvName == Inv_Tax_Code || Inv_Tax_Code == attInvName.slice(1,3).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       rowJumpInv+=">"+attInvName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpInv+"</select></td></tr>";
	             }
			     else if(itemName=="Department")
                 {
                    var rowJumpInv="<tr><td align='right'"+tdh+">Department &nbsp</td><td><select class='edtxt'  id='Inv_Department' value='Inv_Department' "+widstyle+" onchange =' InvDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attInvName=curNode.childNodes[i].childNodes[0].data;                        
                     if(attInvName) 
                     {
                        rowJumpInv+="<option value='"+attInvName+"'";
                       if(Inv_Department == "" && InvN_Department==attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       else if(attInvName == Inv_Department || Inv_Department == attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       rowJumpInv+=">"+attInvName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpInv+"</select></td></tr>";
	             }
			     else if(itemName=="Courier")
                 {
                    var rowJumpInv="<tr><td align='right'"+tdh+">Courier &nbsp</td><td><select class='edtxt'  id='Inv_Courier' value='Inv_Courier' "+widstyle+" onchange =' InvDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attInvName=curNode.childNodes[i].childNodes[0].data;                
                     if(attInvName) 
                     {
                        rowJumpInv+="<option value='"+attInvName+"'";
                       if(Inv_Courier == "" && InvN_Courier==attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       else if(attInvName == Inv_Courier || Inv_Courier == attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       rowJumpInv+=">"+attInvName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpInv+"</select></td></tr>";
	             }
			     else if(itemName=="G_Tax_Code")
                 {
                    var rowJumpInv="<tr><td align='right'"+tdh+">Tax Code &nbsp</td><td><select class='edtxt'  id='Inv_G_Tax_Code' value='Inv_G_Tax_Code' "+widstyle+" onchange ='InvDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attInvName=curNode.childNodes[i].childNodes[0].data;                         
                     if(attInvName) 
                     {
                        rowJumpInv+="<option value='"+attInvName+"'";
                       if(Inv_G_Tax_Code == "" && InvN_G_Tax_Code==attInvName.slice(1,3).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       else if(attInvName == Inv_G_Tax_Code || Inv_G_Tax_Code == attInvName.slice(1,3).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       rowJumpInv+=">"+attInvName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpInv+"</select></td></tr>";
	             }
			     else if(itemName=="G_Department")
                 {
                    var rowJumpInv="<tr><td align='right'"+tdh+">Department &nbsp</td><td><select class='edtxt'  id='Inv_G_Department' value='Inv_G_Department' "+widstyle+" onchange ='InvDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attInvName=curNode.childNodes[i].childNodes[0].data;                         
                     if(attInvName) 
                     {
                        rowJumpInv+="<option value='"+attInvName+"'";
                       if(Inv_G_Department == "" && InvN_G_Department==attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       else if(attInvName == Inv_G_Department ||  Inv_G_Department == attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       rowJumpInv+=">"+attInvName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpInv+"</select></td></tr>";
	             }
			     else if(itemName=="Bank_Account")
                 {
                    var rowJumpInv="<tr><td align='right'"+tdh+">Bank Account &nbsp</td><td><select class='edtxt'  id='Inv_Bank_Account' value='Inv_Bank_Account' "+widstyle+" onchange =' InvDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attInvName=curNode.childNodes[i].childNodes[0].data;                        
                     if(attInvName) 
                     {
                        rowJumpInv+="<option value='"+attInvName+"'";
                       if(Inv_Bank_Account == "" && InvN_Bank_Account==attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       else if(attInvName == Inv_Bank_Account || Inv_Bank_Account == attInvName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpInv+="selected=true"; }
                       rowJumpInv+=">"+attInvName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpInv+"</select></td></tr>";
	             }
	              
			       else if(itemName=="Customer_ACRef")
                  {
         			   rowtxt+="<tr><td align=right "+tdh+">Customer A/C &nbsp<br>Ref &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
         
                  }
                  else if(itemName=="Customer_Order_Number")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Customer Order &nbsp<br>Number &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                  else if(itemName=="Order_Type")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Order Type &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"' ReadOnly "+end_tdr;
                
                  }

                   else if(itemName=="Customer_Tel_No")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Customer Tel No &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="VAT_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">V.A.T GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                  else if(itemName=="NC")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">N/C &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }

                   else if(itemName=="Consign_Number")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Consign. Number &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="Delivery_Post_Code")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Delivery Post Code &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="Discount")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Discount% &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="Payment_Amount_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Payment Amount &nbsp<br>GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                   else if(itemName=="Total_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Total GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"' ReadOnly "+end_tdr;
                
                  }
                   else if(itemName=="Total_VAT")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Total VAT &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"' ReadOnly "+end_tdr;
                
                  }
                  else if(itemName=="Gross_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Gross GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"' ReadOnly "+end_tdr;
                
                  }
                  else if(itemName=="Set_Gross_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Gross GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"' ReadOnly "+end_tdr;
                
                  }
                   else if(itemName=="Amount GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Amount GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"' ReadOnly "+end_tdr;
                
                  }
                  else if(itemName=="Total_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Total GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"' ReadOnly "+end_tdr;
                
                  }
                   else if(itemName=="Carriage_GBP")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Carriage GBP &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }
                  else if(itemName=="Carriage_VAT")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Carriage VAT &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
                
                  }                                                         
		 else if(itemName=='Item_No')	
	      {
	      //     var rowJump1="<tr><td align=right "+tdh+">Item No</td><td><select class='edtxt' "+"style='width:95px' "+" id='selsopcat1' onchange='jumpToSopCat();'><input type='Button'  Value='ViewItem' Runat='server' style='color:blue;font-weight:bold;width:65px;height:20px;text-decoration:underline;'/>";
	       var rowJump1="<tr><td align=right "+tdh+">Item No &nbsp</td><td><select class='edtxt' "+widstyle+" id='selinvitempagecat' onchange='jumpToInvItemPageCat();'>";
	        var invItems = curNode.firstChild;
	          for(var i=0; i<curNode.childNodes.length;i++)   
	           {
	           var attName1=curNode.childNodes[i].childNodes[0].data;                           
	             	if(attName1) 
	             	{
			            var tname1=attName1.replace('_',' ');
		                  rowJump1+="<option label='"+tname1+"'";
		                  // 	if(i==gv_scrollCurPage) rowJump1+=" selected=true";
		                       rowJump1+=">"+tname1+"</option>";		   
		             }
            	}	 
            	 
	      //    rowJump1+="</select></td></tr>"; 
	          rowJump1+="<tr><td colspan=2 align=center "+tdh+" style='color:blue;font-weight:bold;text-decoration:underline;'><input type='Button'  Value='ViewItem' id='ViewButton' onclick='viewItemForInvPageButton()' Runat='server' style='color:blue;font-weight:bold;width:65px;height:20px;text-decoration:underline;'/></td></tr>";
	                  rowtxt+=rowJump1;
	              
           } 

      	          else
                 {
			            rowtxt+="<tr><td align=right "+tdh+">"+itemName.replace('_',' ')+"&nbsp&nbsp"+"</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveInvDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
			 	 }
			}
			curNode=curNode.nextSibling;
			ycur+=gv_invRowH;
			}
		
		if(ic==gv_scrollCurPage) tabstr+=rowtxt;
		//if(ic==gv_scrollCurPage || ycur+45<gv_winh) tabstr+=rowtxt; else break;
   }
    tabstr += "</table>";
    gv_tempTable.innerHTML = tabstr;
    if(gv_invEditingData==1){ setInvPageScrollCommands("<input type='button' id='saveinvdata' value='Save' onclick='saveInvData(0);' />",""); }
   	if(document.getElementById('saveinvdata')==null) setInvPageScrollCommands('','');
	setInvPageScroll();
	setTopTitle('Sop -> Invoice Data');
	doNokiaMenuInvPage();
}

function doNokiaMenuInvPage()
{
	if(window.widget) {
		window.menu.clear();
		var mBack = new MenuItem('Back',2102);
		mBack.onSelect=backSops;
		window.menu.append(mBack);
	}
}

function viewItemForInvPageButton()
{
    document.getElementById('saveinvdata').style.visibility = "hidden";
    showInvItemDetail();
}


function InvDropDownList()
{
  var Inv_For = document.getElementById('Inv_Format');
  var Inv_Tax = document.getElementById('Inv_Tax_Code'); 
  var Inv_Dep = document.getElementById('Inv_Department');
  var Inv_Cou = document.getElementById('Inv_Courier');
  var Inv_G_Tax = document.getElementById('Inv_G_Tax_Code');
  var Inv_G_Dep = document.getElementById('Inv_G_Department');
  var Inv_Bank = document.getElementById('Inv_Bank_Account');
  if(Inv_For)
  {
    if(Inv_For.selectedIndex)
    {
       Inv_Format = Inv_For.options[Inv_For.selectedIndex].value;
       oInv_Format = "ok";
    }
  }
  if(Inv_Tax)
  {
    if(Inv_Tax.selectedIndex)
    {
       Inv_Tax_Code = Inv_Tax.options[Inv_Tax.selectedIndex].value;
       oInv_Tax_Code = "ok";
    }
  }
    if(Inv_Dep)
  {
    if(Inv_Dep.selectedIndex)
    {
       Inv_Department = Inv_Dep.options[Inv_Dep.selectedIndex].value;
       oInv_Department = "ok";
    }
  }
  if(Inv_Cou)
  {
    if(Inv_Cou.selectedIndex)
    {
       Inv_Courier = Inv_Cou.options[Inv_Cou.selectedIndex].value;
       oInv_Courier = "ok";
    }
  }
  if(Inv_G_Tax)
  {
    if(Inv_G_Tax.selectedIndex)
    {
       Inv_G_Tax_Code = Inv_G_Tax.options[Inv_G_Tax.selectedIndex].value;
       oInv_G_Tax_Code = "ok";
    }
  }
  if(Inv_G_Dep)
  {
    if(Inv_G_Dep.selectedIndex)
    {
       Inv_G_Department = Inv_G_Dep.options[Inv_G_Dep.selectedIndex].value;
       oInv_G_Department = "ok";
    }
  }
  if(Inv_Bank)
  {
    if(Inv_Bank.selectedIndex)
    {
       Inv_Bank_Account = Inv_Bank.options[Inv_Bank.selectedIndex].value;
       oInv_Bank_Account = "ok";
    }
  }

	if(document.getElementById('saveinvdata')) return;
	setInvPageScrollCommands("<input type='button' id='saveinvdata' value='Save' onclick='saveInvData(0);' />","");

}


function setInvPageScrollCommands(cmd1,cmd2)
{
	document.getElementById('sopbtn1').innerHTML=cmd1;
	document.getElementById('sopbtn2').innerHTML=cmd2;
	var invoicecmd=document.getElementById('sopCmds').style;
	var ncmds=cmd1.length<5 ? 0:1;
	if(cmd2.length>5) ncmds++;
	invoicecmd.pixelWidth=150+50*ncmds;
	invoicecmd.pixelLeft=gv_winw-invoicecmd.pixelWidth-1;
}
function jumpToInvCat()
{
	var selcat = document.getElementById('selinvcat');
	if(gv_invEditingData==1) checkInvPageEdited(gv_scrollCurPage); //Save any edited data to memory
	gv_scrollCurPage=selcat.selectedIndex;	
	showInvDataPage();
}

function  jumpToInvItemPageCat()
{
var selcat = document.getElementById('selinvitempagecat');
	//if(gv_sopItemEditingData==1) checkInvPageEdited(gv_scrollCurPage); //Save any edited data to memory
	{
	   gv_invItemIndex=selcat.selectedIndex;	
	}
	//showSopItemDataPage();
 
}

// Back button clicked. Customers Commands -> Customer List -> Customer Data
// If in Customer Data, then go back to "Customer List" here and return 1
// If in Customer List, then do nothing here and return 1. The calling function will return to the submenu
//

//itemName=cat_name, eg, 1_AC Ref
function setEditInvData(itemName,edValue)
{
	if(!gv_invEditedName) {
		gv_invEditedName=new Array();
		gv_invEditedValue=new Array();
	}
	for(var i=0; i<gv_invEditedName.length; i++){
		if(gv_invEditedName[i]==itemName) {	gv_invEditedValue[i]=edValue; return; }
	}
	gv_invEditedValue[gv_invEditedName.length]=edValue;	
	gv_invEditedName[gv_invEditedName.length]=itemName;
}
//return: edited string value, null if not edited
function getEditedInvData(itemName)
{
	if(!gv_invEditedName) return null;	
	for(var i=0; i<gv_invEditedName.length; i++) {
		if(gv_invEditedName[i]==itemName) return gv_invEditedValue[i];
	}
}
function showSaveInvDataButton()
{
	if(document.getElementById('saveinvdata')) return;
	setInvPageScrollCommands("<input type='button' id='saveinvdata' value='Save' onclick='saveInvData(0);' />","");
}
function checkInvPageEdited(pagenum)
{
	var itemEle=null;
    for(var ic=pagenum; ic<gv_invDataCategory.length; ic++) {
		var attName=gv_invDataCategory[ic].attributes.getNamedItem("title");	
		if(attName==null) continue;
		var curNode=gv_invDataCategory[ic].firstChild;
		while( curNode ) 
		{
		   if(curNode.nodeName != "InvN_Format" && curNode.nodeName != "Format" && curNode.nodeName != "InvN_Tax_Code" && curNode.nodeName != "Tax_Code" && curNode.nodeName != "InvN_Department" && curNode.nodeName != "Department" && curNode.nodeName != "InvN_Courier" && curNode.nodeName != "Courier" && curNode.nodeName != "InvN_G_Tax_Code" && curNode.nodeName != "G_Tax_Code" && curNode.nodeName != "InvN_G_Department" && curNode.nodeName != "G_Department" && curNode.nodeName != "InvN_Bank_Account" && curNode.nodeName != "Bank_Account" && curNode.nodeName != "Item_No" )
           {
			var ndv=curNode.firstChild;
			var oldv=ndv?ndv.nodeValue:''
			var itemId=ic.toString()+"_"+curNode.nodeName;
			itemEle=document.getElementById(itemId);
			if(itemEle==null) break;
			var newv=itemEle.value;
			if(oldv!=newv) setEditInvData(itemId,newv);
			}
			curNode=curNode.nextSibling;
		}
		if(itemEle==null) break;
    }
}

function backInvoices()
{
	var selinvcat=document.getElementById('selinvcat');
	if(selinvcat==null) return 0;
    if(selinvcat)
    {
	  gv_scrollCurPage=gv_invCurPage;
	  gv_scrollTotPage=gv_invTotPage
	  setTopTitle('Sop -> '+gv_subCmdName);
	  setInvPageScrollCommands("","");
	  showInvList();
	}
}

function saveInvData(cmdid)
{
    Inv_Format = Inv_Format.slice(0,2).replace(/(\s*$)/g,""); 
    Inv_Tax_Code = Inv_Tax_Code.slice(1,3).replace(/(\s*$)/g,"");
    Inv_Department = Inv_Department.slice(0,2).replace(/(\s*$)/g,"");
    Inv_Courier = Inv_Courier.slice(0,1).replace(/(\s*$)/g,"");
    Inv_G_Tax_Code = Inv_G_Tax_Code.slice(1,3).replace(/(\s*$)/g,"");
    Inv_G_Department = Inv_G_Department.slice(0,2).replace(/(\s*$)/g,"");
    Inv_Bank_Account = Inv_Bank_Account.slice(0,2).replace(/(\s*$)/g,"");

	//if(gv_invEditedName==null) return;
	var ACIndex=gv_invCurPage*10+gv_invIndex;
	var url=gv_rooturl+"?cmd=SaveInvoiceData&InvoiceNumber="+gv_invAC[gv_invIndex]+"&index="+ACIndex;
	if(oInv_Format == "ok"){ url+="&0_Format="+Inv_Format;}
	if(oInv_Tax_Code == "ok"){ url+="&5_Tax_Code="+Inv_Tax_Code;}
	if(oInv_Department == "ok"){ url+="&5_Department="+Inv_Department;}
	if(oInv_Courier == "ok"){ url+="&3_Courier="+Inv_Courier;}
	if(oInv_G_Tax_Code == "ok"){ url+="&7_G_Tax_Code="+Inv_G_Tax_Code;}
	if(oInv_G_Department == "ok"){ url+="&7_G_Department="+Inv_G_Department;}
	if(oInv_Bank_Account == "ok"){ url+="&7_Bank_Account="+Inv_Bank_Account;}
	checkInvPageEdited(gv_scrollCurPage);
    if(gv_invEditedName!=null) 
    {
	    for(var i=0; i<gv_invEditedName.length; i++) 
		url += "&"+gv_invEditedName[i]+"="+gv_invEditedValue[i];
	}	
	var xmlhttp = newHttpRequest(url,true);
	if( xmlhttp==null ) return;
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 ) {
			if( xmlhttp.status!=200 ) alert("Connection error");
			else if(xmlhttp.responseText=='1') {
				alert("Data saved OK.");
				gv_invEditedName=null;
		        gv_invEditedValue=null;
		        document.getElementById('saveinvdata').style.visibility = "hidden";
		        InvN_Format = "",InvN_Tax_Code = "",InvN_Department="",InvN_Courier = "",InvN_G_Tax_Code="",InvN_G_Department="",InvN_Bank_Account="";
                Inv_Format = "",Inv_Tax_Code = "",Inv_Department="",Inv_Courier = "",Inv_G_Tax_Code="",Inv_G_Department="",Inv_Bank_Account="";
                oInv_Format ="",oInv_Tax_Code = "",oInv_Department="",oInv_Courier = "",oInv_G_Tax_Code="",oInv_G_Department="",oInv_Bank_Account="";
		     	backSops();		    
			}
			else alert("Server error!");
			document.getElementById('idloading').style.visibility='hidden';
			document.getElementById('idSaving').style.visibility='hidden';
		}
	}
	xmlhttp.send(null);
	document.getElementById('idloading').style.visibility='visible';
	document.getElementById('idSaving').style.visibility='visible';	
}




















