﻿// JScript File
//
var gv_sopAC=new Array();
var gv_sopName=new Array();
var gv_sopIndex=0; // 0-based currently selected customer index.
var gv_sopFocusIndex=0; //Currently focused customer
var gv_sopNumPerPage=0;
var gv_sopCurPage=0; //0-base current page number
var gv_sopTotPage=0;
var gv_sopEditingData=0;
var gv_sopDataCategory=null;
var gv_sopEditedName=null;  // Stores edited customer item name(name=cat_name, eg. 1_AC Ref
var gv_sopEditedValue=null; // Edited values
var gv_tempTable;
var gv_sopRowH=20;
var gv_scrollCurPage=0;
var gv_scrollTotPage=0;
var gv_orderNo=0;
var number=0;
var SopiPage = 1;
var SopTotalPage = 1;
function doSopList()
{
   
	var url = gv_rooturl+"?cmd=SopList"+"&SopiPage="+SopiPage;
	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 soptotalpages=xmlhttp.responseXML.getElementsByTagName("SopTotalPage");
                SopTotalPage = parseInt(soptotalpages[0].firstChild.nodeValue);
			    renewSopList(xmlhttp.responseXML);
			}
			document.getElementById('idloading').style.visibility='hidden';
		}
	}
	xmlhttp.send(null);
	document.getElementById('idloading').style.visibility='visible';
}

function renewSopList(xmldoc)
{
	var sops=xmldoc.getElementsByTagName("Sop");
	gv_sopAC.length=gv_sopName.length=0;
	gv_sopIndex=0;
	
    for(var i=0; i<sops.length; i++) {
		var curNode=sops[i].firstChild;
		gv_sopAC[i]=gv_sopName[i]="";
		while( curNode )  
		{
			switch(curNode.nodeName){
				case "OrderNo" : gv_sopAC[i]=curNode.firstChild.nodeValue;  break;
				case "Name" : gv_sopName[i]=curNode.firstChild.nodeValue;  break;
			}
			curNode=curNode.nextSibling;
		}
    }
    if(sops.length==0) alert("No sop found!");

     else
     {   
        //gv_sopCurPage=0; 
    	gv_sopTotPage=0;
		  showSopList();
	 }
   
}



//<CusList>
//  <Customer>
//    <AC>..</AC>
//    <Name>..</Name>
//  </Customer>
//  <Customer>
//    <AC>..</AC>
//    <Name>..</Name>
//  </Customer>
//<CusList>
//




function showSopList()
{
	if(gv_sopAC.length==0) return;
    gv_tempTable = document.getElementById('tempTable');
	var ycur=gv_tempTable.style.pixelTop=gv_device==Nokia ? 28:26;
	var tdstr="<td height='"+gv_sopRowH+"px'>";
	var tabstr="<table border='1' cellpadding='1' cellspacing='0' style='position:absolute;width:"+(gv_winw-4)+"px;left:2px;'>"; 
	//var ixs=gv_sopCurPage*gv_sopNumPerPage;
	var idx=0;
    for(var i=0; i<gv_sopAC.length; i++) {
		var imgName=idx==gv_sopIndex ? 'radon.png':'radoff.png';
		var trColor=idx==gv_sopIndex ? '#ffcc00':'#add8e6';
		var radstr="<td width='22px' height='"+gv_sopRowH+"px'><input type='image' src='img/"+imgName+
			"' id='sop_img"+idx+"' onclick='sopRowClicked(event);'";
		if(gv_device==Nokia) radstr+="onfocus='overSopItem(event);' onblur='leavSopItem(event);'></td>";
		else radstr+="onmouseover='overSopItem(event);' onmouseleave='leavSopItem(event);'></td>";
		tabstr+="<tr id='sop_row"+idx+"' onclick='sopRowClicked(event);' style='background-color:"+
			trColor+";'>"+radstr + tdstr+gv_sopAC[i]+"</td>"+tdstr+gv_sopName[i]+"</td></tr>";
		//ycur+=gv_sopRowH;
		//if(ycur+45>gv_winh) break; else
	    idx++;
    }
//    if(gv_sopTotPage==0) {
//		gv_scrollCurPage=gv_sopCurPage=0;
//		gv_sopNumPerPage=i;
//		var ntt=gv_sopAC.length;
//		gv_sopTotPage=0;
//		while(ntt>0) {gv_sopTotPage++; ntt-=gv_sopNumPerPage; }
		gv_scrollTotPage=SopTotalPage;
		if(gv_device!=Nokia) {
			var mleft=document.getElementById('img_mleft3');
			mleft.onclick=sopPageLeft;
			mleft.style.cursor='hand';
			var mright=document.getElementById('img_mright3');
			mright.onclick=sopPageRight;
			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_sopFocusIndex=gv_sopIndex;
	
    var sopcmd = document.getElementById('sopCmds');
	sopcmd.style.pixelLeft=gv_winw-sopcmd.style.pixelWidth-1;
	sopcmd.style.pixelTop = gv_winh-29;
    sopcmd.style.visibility='visible';
    if(gv_device!=Nokia) {
		var btn1=document.getElementById('btnSopDetail');
		if(btn1==null) setSopPageScrollCommands(
			"<input type='button' id='btnSopDetail' value='Details' onclick='showSopDetail(0);' />",
			"<input type='button' id='btnSopEdit' value='Edit' onclick='editSopDetail(0);' />");
			
	     }
	setSopPageScroll();
	doNokiaMenuSopList();    
}
function setSopPageScroll()
{   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 sopRowClicked(ee)
{
	var srcele=getEventObject(ee);
	if(srcele.id.length<8) return;
	var newIndex=parseInt(srcele.id.substring(7));
	if(gv_sopIndex==newIndex) return;
	document.getElementById('sop_row'+gv_sopIndex).style.backgroundColor='#add8e6';
	document.getElementById('sop_img'+gv_sopIndex).src='img/radoff.png';
	document.getElementById('sop_row'+newIndex).style.backgroundColor='#ffcc00';
	document.getElementById('sop_img'+newIndex).src='img/radon.png';
	gv_sopIndex=newIndex;
}
function overSopItem(e_event)
{
	var srcobj=getEventObject(e_event);
	if(srcobj.id=='sop_img'+gv_sopIndex) return; // Entering the current selection
	srcobj.src="img/radover.png";
}
function leavSopItem(e_event)
{
	var srcobj=getEventObject(e_event);
	if(srcobj.id=='sop_img'+gv_sopIndex) return; // Leaving the current selection
	srcobj.src="img/radoff.png";
}
function sopPageLeft()
{
	if(gv_scrollCurPage<=0) return;
    
   
	var selcat=document.getElementById('selsopcat');
	var selsopitemcat=document.getElementById('selsopitemcat');
	 //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_sopEditingData==1) checkSopPageEdited(gv_scrollCurPage+1); //Save any edited data to memory
			selcat.selectedIndex=gv_scrollCurPage;
			showSopDataPage();
		}
			else if(selsopitemcat)
		{
		   
			if(gv_sopItemEditingData==1) checkSopItemPageEdited(gv_scrollCurPage-1);
			selsopitemcat.selectedIndex=gv_scrollCurPage;
	        
			showSopItemDataPage();
		}
		else
		 { //customer list
			gv_sopCurPage=gv_scrollCurPage;		
			gv_sopIndex=0;
			SopiPage--;
			if(SopiPage < 1)
			{
			    SopiPage = 1;
			    return;
			}
			doSopList();
		}
	}
	else {
		divtab.style.pixelLeft=tleft+30;
		setTimeout("sopPageLeft();",75);
	}
}
 
function sopPageRight()
{
         

	if(gv_scrollCurPage>=gv_scrollTotPage-1) return;

	var selcat=document.getElementById('selsopcat'); //If null, then in Customer List.
	var selsopitemcat=document.getElementById('selsopitemcat');
	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_sopEditingData==1) checkSopPageEdited(gv_scrollCurPage-1); //Save any edited data to memory
			showSopDataPage();			
		}
		else if(selsopitemcat)
		{
		   selsopitemcat.selectedIndex=gv_scrollCurPage;
			if(gv_sopItemEditingData==1) checkSopItemPageEdited(gv_scrollCurPage-1);
			showSopItemDataPage();
			
		}
		else { //customer list
		gv_sopCurPage=gv_scrollCurPage;		
			gv_sopIndex=0;
			SopiPage++;
			if(SopiPage > SopTotalPage)
			{
			    SopiPage = SopTotalPage;
			    return;
			}
			doSopList();
		}
	}
	else
	 {
		divtab.style.pixelLeft=tleft-30;
	
		  setTimeout("sopPageRight();",75);
	 }
}



function doNokiaMenuSopList()
{
	if(window.widget) {
		window.menu.clear();
		var mShow = new MenuItem('Show Sop Details',2102);
		mShow.onSelect=showSopDetail;
		window.menu.append(mShow);
		var mEdit = new MenuItem('Edit Sop Details',2103);
		mEdit.onSelect=editSopDetail;
		window.menu.append(mEdit);
		var mBack = new MenuItem('Back',2104);
		mBack.onSelect=backSops;
		window.menu.append(mBack);
	}
}
function getSopDetail()
{
	var ACIndex=gv_sopCurPage*gv_sopNumPerPage+gv_sopIndex;
	if(	gv_sopEditingData==0)
	 {
	   var url = gv_rooturl+"?cmd=ShowSopDetail&OrderNo="+gv_sopAC[ACIndex]+"&index="+ACIndex;
	 }
	else if(gv_sopEditingData==1)
	{
	   var url = gv_rooturl+"?cmd=EditSopDetail&OrderNo="+gv_sopAC[ACIndex]+"&index="+ACIndex;
	}
	var xmlhttp = newHttpRequest(url,true);
	gv_orderNo=gv_sopAC[ACIndex];
	if( xmlhttp==null ) return;
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 ) {
			if( xmlhttp.status!=200 ) alert("Connection error");
			else {
				gv_sopDataCategory=xmlhttp.responseXML.getElementsByTagName("DataCategory");
				if(gv_sopDataCategory.length==0) alert("Cannot load details!");
				else {
					gv_scrollCurPage=0;
					gv_scrollTotPage=gv_sopDataCategory.length;
					showSopDataPage();
				}
			}
			document.getElementById('idloading').style.visibility='hidden';
		}
	}
	xmlhttp.send(null);
	document.getElementById('idloading').style.visibility='visible';
	gv_sopEditedName=null;
	gv_sopEditedValue=null;
}
function showSopDetail(cmdid)
{
	gv_sopEditingData=0;
	getSopDetail();

}
function editSopDetail(cmdid)
{
	gv_sopEditingData=1;
	getSopDetail();
}
var SopN_Format = "",SopN_Tax_Code = "",SopN_Department="",SopN_Courier = "",SopN_G_Tax_Code="",SopN_G_Department="",SopN_Bank_Account="";
var Sop_Format = "",Sop_Tax_Code = "",Sop_Department="",Sop_Courier = "",Sop_G_Tax_Code="",Sop_G_Department="",Sop_Bank_Account="";
var oSop_Format ="",oSop_Tax_Code = "",oSop_Department="",oSop_Courier = "",oSop_G_Tax_Code="",oSop_G_Department="",oSop_Bank_Account="";
function showSopDataPage()
{ 
	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='selsopcat' onchange='jumpToSopCat();'>";
    for(var ic=0; ic<gv_sopDataCategory.length; ic++) {
		var attName0=gv_sopDataCategory[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_sopDataCategory.length; ic++) {
		var attName=gv_sopDataCategory[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_sopRowH;
	var curNode=gv_sopDataCategory[ic].firstChild;
		var end_tdr = gv_sopEditingData==1 ? "></td></tr>":" ReadOnly></td></tr>";	

	while( curNode ) 
		{
			var itemName=curNode.nodeName;
			var itemId=ic.toString()+"_"+itemName;
			var ndv=curNode.firstChild;
		    var itemVal=getEditedSopData(itemId);
		     if(itemVal==null) itemVal=ndv?ndv.nodeValue:'';

			if(	gv_sopEditingData==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' onchange='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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' onchange='showSaveSopDataButton();' "+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' onchange='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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' onchange='showSaveSopDataButton();' "+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='selsopitempagecat' onchange='jumpToSopItemPageCat();'>";
	        var sopItems = 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='showSopItemDetail()' 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='showSaveSopDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
			 	 }
			}

			if(gv_sopEditingData==1)
			{     
			      if(itemName=="SopN_Format")
	              {
	                 if(ndv !=null)
	                 { SopN_Format = ndv.nodeValue;}
	              }
			      else if(itemName=="SopN_Tax_Code")
	              {
	                 if(ndv !=null)
	                 { SopN_Tax_Code = ndv.nodeValue;}
	              }
			      else if(itemName=="SopN_Department")
	              {
	                 if(ndv !=null)
	                 { SopN_Department = ndv.nodeValue;}
	              }
			      else if(itemName=="SopN_Courier")
	              {
	                 if(ndv !=null)
	                 { SopN_Courier = ndv.nodeValue;}
	              }
			      else if(itemName=="SopN_G_Tax_Code")
	              {
	                 if(ndv !=null)
	                 { SopN_G_Tax_Code = ndv.nodeValue;}
	              }
			      else if(itemName=="SopN_G_Department")
	              {
	                 if(ndv !=null)
	                 { SopN_G_Department = ndv.nodeValue;}
	              }
			      else if(itemName=="SopN_Bank_Account")
	              {
	                 if(ndv !=null)
	                 { SopN_Bank_Account = ndv.nodeValue;}
	              }
	             else if(itemName=="Format")
                 {
                    var rowJumpSop="<tr><td align='right'"+tdh+">Format &nbsp</td><td><select class='edtxt'  id='Sop_Format' value='Sop_Format' "+widstyle+" onchange =' SopDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attSopName=curNode.childNodes[i].childNodes[0].data;                          
                     if(attSopName) 
                     {
                        rowJumpSop+="<option value='"+attSopName+"'";
                       if(Sop_Format == "" && SopN_Format==attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       else if(attSopName == Sop_Format || Sop_Format == attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       rowJumpSop+=">"+attSopName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpSop+"</select></td></tr>";
	             }
 
			     else if(itemName=="Tax_Code")
                 {
                    var rowJumpSop="<tr><td align='right'"+tdh+">Tax Code &nbsp</td><td><select class='edtxt'  id='Sop_Tax_Code' value='Sop_Tax_Code' "+widstyle+" onchange =' SopDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attSopName=curNode.childNodes[i].childNodes[0].data;                       
                     if(attSopName) 
                     {
                        rowJumpSop+="<option value='"+attSopName+"'";
                       if(Sop_Tax_Code == "" && SopN_Tax_Code==attSopName.slice(1,3).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       else if(attSopName == Sop_Tax_Code || Sop_Tax_Code == attSopName.slice(1,3).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       rowJumpSop+=">"+attSopName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpSop+"</select></td></tr>";
	             }
			     else if(itemName=="Department")
                 {
                    var rowJumpSop="<tr><td align='right'"+tdh+">Department &nbsp</td><td><select class='edtxt'  id='Sop_Department' value='Sop_Department' "+widstyle+" onchange =' SopDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attSopName=curNode.childNodes[i].childNodes[0].data;                           
                     if(attSopName) 
                     {
                        rowJumpSop+="<option value='"+attSopName+"'";
                       if(Sop_Department == "" && SopN_Department==attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       else if(attSopName == Sop_Department || Sop_Department == attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       rowJumpSop+=">"+attSopName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpSop+"</select></td></tr>";
	             }
			     else if(itemName=="Courier")
                 {
                    var rowJumpSop="<tr><td align='right'"+tdh+">Courier &nbsp</td><td><select class='edtxt'  id='Sop_Courier' value='Sop_Courier' "+widstyle+" onchange =' SopDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attSopName=curNode.childNodes[i].childNodes[0].data;                        
                     if(attSopName) 
                     {
                        rowJumpSop+="<option value='"+attSopName+"'";
                       if(Sop_Courier == "" && SopN_Courier==attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       else if(attSopName == Sop_Courier || Sop_Courier == attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       rowJumpSop+=">"+attSopName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpSop+"</select></td></tr>";
	             }
			     else if(itemName=="G_Tax_Code")
                 {
                    var rowJumpSop="<tr><td align='right'"+tdh+">Tax Code &nbsp</td><td><select  class='edtxt' id='Sop_G_Tax_Code' value='Sop_G_Tax_Code' "+widstyle+" onchange ='SopDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attSopName=curNode.childNodes[i].childNodes[0].data;                           
                     if(attSopName) 
                     {
                        rowJumpSop+="<option value='"+attSopName+"'";
                       if(Sop_G_Tax_Code == "" && SopN_G_Tax_Code==attSopName.slice(1,3).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       else if(attSopName == Sop_G_Tax_Code || Sop_G_Tax_Code == attSopName.slice(1,3).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       rowJumpSop+=">"+attSopName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpSop+"</select></td></tr>";
	             }
			     else if(itemName=="G_Department")
                 {
                    var rowJumpSop="<tr><td align='right'"+tdh+">Department &nbsp</td><td><select  class='edtxt' id='Sop_G_Department' value='Sop_G_Department' "+widstyle+" onchange ='SopDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attSopName=curNode.childNodes[i].childNodes[0].data;                       
                     if(attSopName) 
                     {
                        rowJumpSop+="<option value='"+attSopName+"'";
                       if(Sop_G_Department == "" && SopN_G_Department==attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       else if(attSopName == Sop_G_Department || Sop_G_Department == attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       rowJumpSop+=">"+attSopName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpSop+"</select></td></tr>";
	             }
			     else if(itemName=="Bank_Account")
                 {
                    var rowJumpSop="<tr><td align='right'"+tdh+">Bank Account &nbsp</td><td><select class='edtxt'  id='Sop_Bank_Account' value='Sop_Bank_Account' "+widstyle+" onchange =' SopDropDownList();'>";
                    for(var i=0; i< curNode.childNodes.length; i++) 
                    { 
                      var attSopName=curNode.childNodes[i].childNodes[0].data;                     
                     if(attSopName) 
                     {
                        rowJumpSop+="<option value='"+attSopName+"'";
                       if(Sop_Bank_Account == "" && SopN_Bank_Account==attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       else if(attSopName == Sop_Bank_Account || Sop_Bank_Account == attSopName.slice(0,2).replace(/(\s*$)/g,"")) { rowJumpSop+="selected=true"; }
                       rowJumpSop+=">"+attSopName+"</option>"; 
                     }
                  }  
                      rowtxt+=rowJumpSop+"</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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"' ReadOnly"+end_tdr;
                
                  }
                  else if(itemName=="Order_Number")
                  {
  			            rowtxt+="<tr><td align=right "+tdh+">Order Number &nbsp</td>";
		            	rowtxt+="<td "+tdh+"><input type='text' class='edtxt' onchange='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='showSaveSopDataButton();' "+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='selsopitempagecat' onchange='jumpToSopItemPageCat();'>";
	        var sopItems = 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='viewItemForSopPageButton()' 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='showSaveSopDataButton();' "+widstyle+
			        	"value='"+itemVal+"' id='"+itemId+"'"+end_tdr;
			 	 }
			}
			curNode=curNode.nextSibling;
			ycur+=gv_sopRowH;
			}
		
		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_sopEditingData==1) { setSopPageScrollCommands("<input type='button' id='savesopdata' value='Save' onclick='saveSopData(0);' />","");}
   	if(document.getElementById('savesopdata')==null) setSopPageScrollCommands('','');
	setSopPageScroll();
	setTopTitle('Sop -> Sop Data');
	doNokiaMenuSopPage();
}
function doNokiaMenuSopPage()
{
	if(window.widget) {
		window.menu.clear();
		var mBack = new MenuItem('Back',2104);
		mBack.onSelect=backSops;
		window.menu.append(mBack);
	}
}

function viewItemForSopPageButton()
{
    document.getElementById('savesopdata').style.visibility = "hidden";
    showSopItemDetail();
}

function SopDropDownList()
{
  var Sop_For = document.getElementById('Sop_Format');
  var Sop_Tax = document.getElementById('Sop_Tax_Code'); 
  var Sop_Dep = document.getElementById('Sop_Department');
  var Sop_Cou = document.getElementById('Sop_Courier');
  var Sop_G_Tax = document.getElementById('Sop_G_Tax_Code');
  var Sop_G_Dep = document.getElementById('Sop_G_Department');
  var Sop_Bank = document.getElementById('Sop_Bank_Account');
  if(Sop_For)
  {
    if(Sop_For.selectedIndex)
    {
       Sop_Format = Sop_For.options[Sop_For.selectedIndex].value;
       oSop_Format = "ok";
    }
  }
  if(Sop_Tax)
  {
    if(Sop_Tax.selectedIndex)
    {
       Sop_Tax_Code = Sop_Tax.options[Sop_Tax.selectedIndex].value;
       oSop_Tax_Code = "ok";
    }
  }
    if(Sop_Dep)
  {
    if(Sop_Dep.selectedIndex)
    {
       Sop_Department = Sop_Dep.options[Sop_Dep.selectedIndex].value;
       oSop_Department = "ok";
    }
  }
  if(Sop_Cou)
  {
    if(Sop_Cou.selectedIndex)
    {
       Sop_Courier = Sop_Cou.options[Sop_Cou.selectedIndex].value;
       oSop_Courier = "ok";
    }
  }
  if(Sop_G_Tax)
  {
    if(Sop_G_Tax.selectedIndex)
    {
       Sop_G_Tax_Code = Sop_G_Tax.options[Sop_G_Tax.selectedIndex].value;
       oSop_G_Tax_Code = "ok";
    }
  }
  if(Sop_G_Dep)
  {
    if(Sop_G_Dep.selectedIndex)
    {
       Sop_G_Department = Sop_G_Dep.options[Sop_G_Dep.selectedIndex].value;
       oSop_G_Department = "ok";
    }
  }
  if(Sop_Bank)
  {
    if(Sop_Bank.selectedIndex)
    {
       Sop_Bank_Account = Sop_Bank.options[Sop_Bank.selectedIndex].value;
       oSop_Bank_Account = "ok";
    }
  }

	if(document.getElementById('savesopdata')) return;
	setSopPageScrollCommands("<input type='button' id='savesopdata' value='Save' onclick='saveSopData(0);' />","");

}
function viewSopItemDataPage()
{
//  gv_chooseDetail = "chooseSopItem";
  showSopItemDetail();
}

function setSopPageScrollCommands(cmd1,cmd2)
{
	document.getElementById('sopbtn1').innerHTML=cmd1;
	document.getElementById('sopbtn2').innerHTML=cmd2;
	var sopcmd=document.getElementById('sopCmds').style;
	var ncmds=cmd1.length<5 ? 0:1;
	if(cmd2.length>5) ncmds++;
	sopcmd.pixelWidth=150+50*ncmds;
	sopcmd.pixelLeft=gv_winw-sopcmd.pixelWidth-1;
}
function jumpToSopCat()
{
	var selcat = document.getElementById('selsopcat');
	if(gv_sopEditingData==1) checkSopPageEdited(gv_scrollCurPage); //Save any edited data to memory
	gv_scrollCurPage=selcat.selectedIndex;	
	showSopDataPage();
}

function  jumpToSopItemPageCat()
{
var selcat = document.getElementById('selsopitempagecat');
	//if(gv_sopItemEditingData==1) checkSopPageEdited(gv_scrollCurPage); //Save any edited data to memory
	if(selcat)
	{
	   gv_sopItemIndex=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
//
function backSops()
{
 var selnewsopitemcat=document.getElementById('selnewsopitemcat');
 var selnewquoitemcat=document.getElementById('selnewquoitemcat');
 var selnewinvitemcat=document.getElementById('selnewinvitemcat');
 var seleditnewsopitemcat=document.getElementById('seleditnewsopitemcat');
 var seleditnewquoitemcat=document.getElementById('seleditnewquoitemcat');
 var seleditnewinvitemcat=document.getElementById('seleditnewinvitemcat');
 var selsopcat = document.getElementById('selsopcat');
 var selsopitemcat = document.getElementById('selsopitemcat');
 var selinvcat=document.getElementById('selinvcat');
 var selinvitemcat = document.getElementById('selinvitemcat');
 if(selnewsopitemcat==null && selsopcat==null && selsopitemcat==null && selinvcat==null && selinvitemcat == null && selnewquoitemcat == null && selnewinvitemcat == null && seleditnewsopitemcat==null && seleditnewquoitemcat == null && seleditnewinvitemcat == null) 
 {
     gv_scrollCurPage=0;
     SopiPage = 1;
     InviPage = 1;
     setSopPageScrollCommands("","");
     strNewSopItem = "";// clean strNewSopItem 
	 NewSopItemDDVal = "";// in order to clean strNewSopItem
	 addNewSopDropDownValue = "";// in order to clean strNewSopItem
	 document.getElementById("SopHiddenField").value = "";// in order to clean strNewSopItem

     strNewInvItem = "";
     NewInvItemDDVal = "";
     addNewInvDropDownValue = "";
     document.getElementById("InvHiddenField").value = "";

     strNewQuoItem = "";
     NewQuoItemDDVal = "";
     addNewQuoDropDownValue = "";
     document.getElementById("QuoHiddenField").value = "";     
     
 	 document.getElementById('back2submenu').style.visibility='hidden';
	 document.getElementById('tempTable').style.visibility='hidden';
	 document.getElementById('sopCmds').style.visibility='hidden';
	 doNokiaMenuMain();
     showSubMenu();
     return 0;
 }
 if(selsopcat)//Sop
 {
  gv_scrollCurPage=gv_sopCurPage;
  gv_scrollTotPage = gv_sopTotPage;
  setTopTitle('Sop -> '+gv_subCmdName);
  setSopPageScrollCommands("","");
  showSopList();

 }
  else if(selsopitemcat)//SopItem
 {
  gv_scrollCurPage= 1;
  gv_scrollTotPage = 8;
  setTopTitle('Sop -> '+gv_subCmdName);
  if(gv_sopEditingData==1) { document.getElementById('savesopdata').style.visibility = "hidden";}
  showSopDataPage();

 }

 else if(selnewsopitemcat)//newSopItem
 {
  gv_scrollCurPage=1;
  gv_scrollTotPage = 8;
  setTopTitle('Sop -> '+gv_subCmdName);
  NewSopItemTurnPage = 0;
  if(document.getElementById('savenewsopdata') == null) { setNewSopPageScrollCommands("<input type='button' id='savenewsopdata' value='Save' onclick='saveNewSopData();' />",""); }
  showNewSopDataPage("OtherLoad");
 } 
 
 else if(seleditnewsopitemcat)//newSopItem
 {
  gv_scrollCurPage=1;
  gv_scrollTotPage = 8;
  setTopTitle('Sop -> '+gv_subCmdName);
  if(NewSopItemTurnPage != 0) { NewSopItemTurnPage = 0;}
  if(document.getElementById('savenewsopdata') == null) { setNewSopPageScrollCommands("<input type='button' id='savenewsopdata' value='Save' onclick='saveNewSopData();' />",""); }
  showNewSopDataPage("OtherLoad");
 } 
   else if(selinvcat)//invoice
    {
	  gv_scrollCurPage=gv_invCurPage;
	  gv_scrollTotPage=gv_invTotPage
	  setTopTitle('Sop -> '+gv_subCmdName);
	  setInvPageScrollCommands("","");
	  showInvList();
	}
   else if(selinvitemcat)//invoice Item
 {
  gv_scrollCurPage=1;
  gv_scrollTotPage = 8;
  setTopTitle('Sop -> '+gv_subCmdName);
  if(gv_invEditingData==1){ document.getElementById('saveinvdata').style.visibility = "hidden"; }
  showInvDataPage();

 }
 else if(selnewquoitemcat)//new quo item
 {
  gv_scrollCurPage=1;
  gv_scrollTotPage = 8;
  setTopTitle('Sop -> '+gv_subCmdName);
  NewQuoItemTurnPage = 0;
  if(document.getElementById('savenewquodata') == null) { setNewQuoPageScrollCommands("<input type='button' id='savenewquodata' value='Save' onclick='saveNewQuoData();' />",""); }
  showNewQuoDataPage("OtherLoad");
 }
  else if(seleditnewquoitemcat)//new quo item
 {
  gv_scrollCurPage=1;
  gv_scrollTotPage = 8;
  setTopTitle('Sop -> '+gv_subCmdName);
  if(NewQuoItemTurnPage != 0) { NewQuoItemTurnPage = 0;}
  if(document.getElementById('savenewquodata') == null) { setNewQuoPageScrollCommands("<input type='button' id='savenewquodata' value='Save' onclick='saveNewQuoData();' />",""); }
  showNewQuoDataPage("OtherLoad");
 }
 else if(selnewinvitemcat)//new inv item
 {
  gv_scrollCurPage=1;
  gv_scrollTotPage = 8;
  setTopTitle('Sop -> '+gv_subCmdName);
  NewInvItemTurnPage = 0;
  if(document.getElementById('savenewinvdata') == null) { setNewInvPageScrollCommands("<input type='button' id='savenewinvdata' value='Save' onclick='saveNewInvData();' />",""); }
  showNewInvDataPage("OtherLoad");
 }
 else if(seleditnewinvitemcat)//new inv item
 {
  gv_scrollCurPage=1;
  gv_scrollTotPage = 8;
  setTopTitle('Sop -> '+gv_subCmdName);
  if(NewInvItemTurnPage != 0) { NewInvItemTurnPage = 0; }
  if(document.getElementById('savenewinvdata') == null) { setNewInvPageScrollCommands("<input type='button' id='savenewinvdata' value='Save' onclick='saveNewInvData();' />",""); }
  showNewInvDataPage("OtherLoad");
 }

}
//itemName=cat_name, eg, 1_AC Ref
function setEditSopData(itemName,edValue)
{
	if(!gv_sopEditedName) {
		gv_sopEditedName=new Array();
		gv_sopEditedValue=new Array();
	}
	for(var i=0; i<gv_sopEditedName.length; i++){
		if(gv_sopEditedName[i]==itemName) {	gv_sopEditedValue[i]=edValue; return; }
	}
	gv_sopEditedValue[gv_sopEditedName.length]=edValue;	
	gv_sopEditedName[gv_sopEditedName.length]=itemName;
}
//return: edited string value, null if not edited
function getEditedSopData(itemName)
{
	if(!gv_sopEditedName) return null;	
	for(var i=0; i<gv_sopEditedName.length; i++) {
		if(gv_sopEditedName[i]==itemName) return gv_sopEditedValue[i];
	}
}
function showSaveSopDataButton()
{
	if(document.getElementById('savesopdata')) return;
	setSopPageScrollCommands("<input type='button' id='savesopdata' value='Save' onclick='saveSopData(0);' />","");
}
function checkSopPageEdited(pagenum)
{
	var itemEle=null;
    for(var ic=pagenum; ic<gv_sopDataCategory.length; ic++) {
		var attName=gv_sopDataCategory[ic].attributes.getNamedItem("title");	
		if(attName==null) continue;
		var curNode=gv_sopDataCategory[ic].firstChild;
		while( curNode ) 
		{
		  if(curNode.nodeName != "SopN_Format" && curNode.nodeName != "Format" && curNode.nodeName != "SopN_Tax_Code" && curNode.nodeName != "Tax_Code" && curNode.nodeName != "SopN_Department" && curNode.nodeName != "Department" && curNode.nodeName != "SopN_Courier" && curNode.nodeName != "Courier" && curNode.nodeName != "SopN_G_Tax_Code" && curNode.nodeName != "G_Tax_Code" && curNode.nodeName != "SopN_G_Department" && curNode.nodeName != "G_Department" && curNode.nodeName != "SopN_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) setEditSopData(itemId,newv);
		  }
			curNode=curNode.nextSibling;
		}
		if(itemEle==null) break;
    }
}

function saveSopData(cmdid)
{
    Sop_Format = Sop_Format.slice(0,2).replace(/(\s*$)/g,""); 
    Sop_Tax_Code = Sop_Tax_Code.slice(1,3).replace(/(\s*$)/g,"");
    Sop_Department = Sop_Department.slice(0,2).replace(/(\s*$)/g,"");
    Sop_Courier = Sop_Courier.slice(0,1).replace(/(\s*$)/g,"");
    Sop_G_Tax_Code = Sop_G_Tax_Code.slice(1,3).replace(/(\s*$)/g,"");
    Sop_G_Department = Sop_G_Department.slice(0,2).replace(/(\s*$)/g,"");
    Sop_Bank_Account = Sop_Bank_Account.slice(0,2).replace(/(\s*$)/g,"");

	var ACIndex=gv_sopCurPage*10+gv_sopIndex;
	var url=gv_rooturl+"?cmd=SaveSopData&OrderNo="+gv_sopAC[gv_sopIndex]+"&index="+ACIndex;
//	if(oSop_Format == "ok"){ url+="&0_Format="+Sop_Format;}
	if(oSop_Tax_Code == "ok"){ url+="&5_Tax_Code="+Sop_Tax_Code;}
	if(oSop_Department == "ok"){ url+="&5_Department="+Sop_Department;}
	if(oSop_Courier == "ok"){ url+="&3_Courier="+Sop_Courier;}
	if(oSop_G_Tax_Code == "ok"){ url+="&7_G_Tax_Code="+Sop_G_Tax_Code;}
	if(oSop_G_Department == "ok"){ url+="&7_G_Department="+Sop_G_Department;}
	if(oSop_Bank_Account == "ok"){ url+="&7_Bank_Account="+Sop_Bank_Account;}

	checkSopPageEdited(gv_scrollCurPage);
	if(gv_sopEditedName!=null) 
   {
	 for(var i=0; i<gv_sopEditedName.length; i++) 
	 url += "&"+gv_sopEditedName[i]+"="+gv_sopEditedValue[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_sopEditedName=null;
		        gv_sopEditedValue=null;
		        document.getElementById('savesopdata').style.visibility = "hidden";
                SopN_Format = "",SopN_Tax_Code = "",SopN_Department="",SopN_Courier = "",SopN_G_Tax_Code="",SopN_G_Department="",SopN_Bank_Account="";
                Sop_Format = "",Sop_Tax_Code = "",Sop_Department="",Sop_Courier = "",Sop_G_Tax_Code="",Sop_G_Department="",Sop_Bank_Account="";
                oSop_Format ="",oSop_Tax_Code = "",oSop_Department="",oSop_Courier = "",oSop_G_Tax_Code="",oSop_G_Department="",oSop_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';	
}



















