﻿
// JScript File
e = document.createElement("link");
e.type = "text/css";
e.rel = "stylesheet";
e.href = "inc/modalDialog.css";
e.media = "screen";
document.getElementsByTagName("head")[0].appendChild(e);

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

//-------------------------------------------------------------------------------------------------------------------
//if (document.layers) 
//{ // Netscape
//    document.captureEvents(Event.MOUSEMOVE);
//    document.onmousemove = captureMousePosition;
//} 
//else if (document.all) { // Internet Explorer
//    document.onmousemove = captureMousePosition;
//}
// else if (document.getElementById) { // Netcsape 6
//    document.onmousemove = captureMousePosition;
//}
//// Global variables
// xMousePos = 0; // Horizontal position of the mouse on the screen
// yMousePos = 0; // Vertical position of the mouse on the screen
//function captureMousePosition(e) {
//    if (document.layers)
//    {
//        xMousePos = e.pageX;
//        yMousePos = e.pageY;
//    } else if (document.all) {
//        xMousePos = window.event.x+document.body.scrollLeft;
//        yMousePos = window.event.y+document.body.scrollTop;
//    } else if (document.getElementById) {
//        // Netscape 6 behaves the same as Netscape 4 in this regard 
//        xMousePos = e.pageX;
//        yMousePos = e.pageY;
//    }
//}
//-----------------------------------------function  for port detail button------------------------------------------
function showDetail1() 
    {
     var prdid = document.getElementById('drpPort').value;
     mywindow = window.open("viewDetail.aspx?pstring=" + prdid ,"","menubar=0,resizable=1,width=980,height=620,toolbar=0,location=0,directories=0,status=1,scrollbars=1");     
     mywindow.moveTo(20,40);
    }
//-------------------------------------------------End function-------------------------------------------------------
//---------------------------------------------function for check now pop window -------------------------------------
function fnCheckNowOpen(ctrl)
	{
	 var pid = document.getElementById('drpPort').value;
	 var prdid = document.getElementById('tbl1').rows[ctrl].cells[1].Id ;
	 var UnitVal=document.getElementById("txtHidden2").value;
	 //alert(prdid);
	 //alert(document.getElementById('tbl1').rows[ctrl].cells[0].innerHTML);
	 var orderquantity = formatdigit(document.getElementById('txtQty'+document.getElementById('tbl1').rows[ctrl].cells[2].Id.replace('.','')).value);
	 //alert(orderquantity);
	 var outctrl ='tbl1';
	 var table=document.getElementById("tbl1");
	 var tblpack = '';
	 for (curr_row = 0; curr_row < table.rows.length ; curr_row++)
      {
        if((table.rows[curr_row].cells[3].innerHTML == 'Bulk' || table.rows[curr_row].cells[3].innerHTML == 'Bulk-B' || table.rows[curr_row].cells[3].innerHTML == 'Bulk-T'))
        {
            if (table.rows[curr_row].cells[3].innerHTML == 'Bulk')
            {
                tblpack="Bulk-T";
            }
            else
            {
                tblpack = table.rows[curr_row].cells[3].innerHTML;
            }
        }
      }
    window.open('CheckNow.aspx?ctrl=' + ctrl + '&outctrl=' + outctrl + '&portid=' + pid + '&productid=' + prdid + '&orderquantity=' + orderquantity + '&tblpack=' + tblpack + '&UnitVal=' + UnitVal,'Check_Now','width=380,height=220');
}
//-----------------------------------------------End function--------------------------------------------------------
//------------------------------function to check numeric value and disallow alphabets------------------------------
//function IsNumeric(strString)
//   //  check for valid numeric strings	
//   {
//    var strValidChars = "0123456789.-";
//    var strChar;
//    var blnResult = true;

//    if (strString.length == 0) return false;

//   //  test strString consists of valid characters listed above
//   for (i = 0; i < strString.length && blnResult == true; i++)
//      {
//      strChar = strString.charAt(i);
//      if (strValidChars.indexOf(strChar) == -1)
//         {
//         blnResult = false;
//         }
//      }
//   return blnResult;
//   }
//   
   
    function DisAllowAlphabets(e){
      if(e.which){
        if ((e.which >= 48 && e.which <= 57)||(e.which==8)){
      		return true;}
     	else if(e.which == 45){
     		return true; }
    	else{ 
			return false; }
        }
      else if(window.event){    
       	if (window.event.keyCode >= 48 && window.event.keyCode <= 57){
      		window.event.returnValue=true;}
     	else if(window.event.keyCode == 45){
     		window.event.returnValue=true; }
    	else{ 
			window.event.returnValue=false; }  
        }
  } 
   //------------------------------------------End function----------------------------------------------------------
   //--------------------------add to order in order list with checking availability----------------------------------
function PopulateTable(str)
{
    var mainstr=str.split('|');
    for (var i=0;i<mainstr.length-1;++i)
    {
        //alert(mainstr[i]);
        addtoprodlist_New1(mainstr[i]);
    }
    
   // alert("Hi Pass1");
    
    CheckExceponDelete();
   // CheckExceponForEachRecord();
}

function addtoprodlist_New(avail)
{
//avail='mobil,21,P,34'
 var pk;
 var pk1;
 var info=avail.split("_");
 //var mainstr1=mainstr[0].split("&");
 //alert(mainstr[0]);
 //alert(info[0]);
 //alert(info[1]);
 //alert(info[2]);
 //alert(info[3]);
 //alert(info[4]);
 var d=window.opener.document;
 var table = d.getElementById("tbl1");
 if (!table) throw "Table not found";
 pk=info[2];
switch (info[2]) {
case 'Pail': pk1 = 'P'; break;
case 'Drum': pk1 = 'D'; break;
case 'Bulk-B': pk1 = 'B'; break;
case 'Bulk-T': pk1 = 'T'; break;
case 'Cartridge': pk1 = 'C'; break;
default: pk1 = 'unknown';
}

 
 
 var packmode =pk;
 var newavail='Y';
 var tblpack='';
 if (packmode == 'Bulk-T' || packmode == 'Bulk-B')
  {
   for (curr_row = 0; curr_row < table.rows.length ; curr_row++)
    {
    if(table.rows[curr_row].cells[4].innerHTML == 'Y')
    tblpack = table.rows[curr_row].cells[3].innerHTML;
    }
  }
 if(tblpack == 'Bulk-T' || tblpack == 'Bulk-B')
   {
   alert(tblpack);
   alert(packmode);
   if(tblpack != packmode)
    {
    newavail='N';
    }
   }
   alert(newavail);
 if(newavail == 'N')
   {
   alert('Sorry You have already choose '+ tblpack);
   //document.getElementById('txtQuantity').value='';
   //document.getElementById('drpPack').focus();
   }
 else
   {
   var i= window.opener.document.getElementById('tbl1').rows.length;
   var row = table.insertRow(-1); //append at the end
   var cell1 = row.insertCell(-1);
   var cell2 = row.insertCell(-1);
   var cell3 = row.insertCell(-1);
   var cell4 = row.insertCell(-1);
   var cell5 = row.insertCell(-1);
   var cell6 = row.insertCell(-1);
   var cell7 = row.insertCell(-1);
  if (i == 0)
    {
    cell1.innerHTML =  (1) + ".";
    }
  else
    {
    cell1.innerHTML =  (i + 1) + ".";
    }
  cell2.innerHTML = info[0];
  cell2.Id = info[1];
  cell3.innerHTML = "<input align='center' style='width:35px;' type='textbox' id='txtQty" + cell1.innerHTML.replace('.','')+"' onkeyup='MoveNextPrev(this,event);'/>";//formatdigit(info[4]);
  cell3.Id =cell1.innerHTML;
  cell4.innerHTML = pk;
  cell4.Id = pk2;
//  if(mainstr1[0].trim() == "N")
//    {
//    cell5.className="headline11norred";
//    }
//  else if(mainstr1[0].trim() == "Y")
//   {
   cell5.className="headline11norgreen";
//   }
  var valueind = i;
  cell5.innerHTML = '';
  cell6.innerHTML = "<a href=\"JavaScript:fnCheckNowOpen("+ valueind  + ");\" class='b-checknow'>Check now</a>";
  cell7.innerHTML = "<a href='#' class='b-remove' onclick='JavaScript:removepro();'>Remove Item</a>";
  cell7.Id = info[3];
  cell1.width="5%";
  cell2.width="40%";
  cell3.width="15%";
  cell4.width="10%";
  cell5.width="0%";
  cell6.width="15%";
  cell7.width="15%";
  //d.getElementById('txtQuantity').value='';
  //d.getElementById('drpProduct').focus();
  alert(info[1]+pk1);
  CheckExcep_new(info[1],pk1);
  }
}




//-------------------------------------on delete button check exceptionality---------------------------------------
  function CheckExceponForEachRecord()
  {
	var strSQL = document.getElementById('drpPort').value;
	var table = document.getElementById('tbl1');
	var pk1="";
	for(j= 0;j <table.rows.length;j++)
     {
        switch (table.rows[j].cells[3].Id) {
            case 'P': pk1 = 'Pail'; break;
            case 'D': pk1 = 'Drum'; break;
            case 'B': pk1 = 'Barge'; break;
            case 'B': pk1 = 'Barge'; break;
            case 'T': pk1 = 'Truck'; break;
            case 'C': pk1 = 'Cartridge'; break;
            case 'A': pk1='Any Pack'; break;
            default: pk1 = 'unknown';
            }

         if (table.rows[j].cells[1].Id != "0")
         {
            strSQL = strSQL + "&" + table.rows[j].cells[1].Id + "&" + pk1;
         }
     }
     
	var requestUrl = "exception_New_1.aspx" + "?S=E&C=" + encodeURIComponent(strSQL) ;
    CreateXmlHttp();	
	if(XmlHttp){
		XmlHttp.onreadystatechange = GetExceponforeachrecord;
		XmlHttp.open("GET", requestUrl,  true);		
		XmlHttp.send(null);		
	}
  }

function GetExceponforeachrecord(){
	if(XmlHttp.readyState == 4){
		if(XmlHttp.status == 200){		
		if((((XmlHttp.responseText).trim()).length)==0){
		        return true;
		     }      
		else {
		    //alert(XmlHttp.responseText);
		    WriteExceponforeachrecord((XmlHttp.responseText).trim());
		    return true;
		  }
		
		 }
		else{
			alert("There was a problem retrieving data from the server. Please try again!" )
			return false;
		 }
	  }
  }
  function WriteExceponforeachrecord(str)
  {
   //alert(str);
   var mainstr=str.trim().split("&");
   var j;
   var table = document.getElementById('tbl1');
   for(j= 0;j <table.rows.length;j++)
     {
        if (table.rows[j].cells[1].Id != "0")
         {
            table.rows[j].cells[6].Id=mainstr[j+1].substring(0,3);
            //alert(mainstr[j+1].substring(0,3));
         }
     }
    
    
  }
//--------------------------------------------------End function----------------------------------------------------






















function addtoprodlist_New1(avail)
{
//avail='mobil,21,P,34'
 var pk;
 var pk1;
 var info=avail.split("_");
 //alert(avail);
 //var mainstr1=mainstr[0].split("&");
 //alert(mainstr[0]);
 //alert(info[0]);
 //alert(info[1]);
 //alert(info[2]);
 //alert(info[3]);
 //alert(info[4]);
 var d=document;
 var table = d.getElementById("tbl1");
 if (!table) throw "Table not found";
 pk=info[2];
switch (info[2]) {
case 'Pail': pk1 = 'P'; break;
case 'Drum': pk1 = 'D'; break;
case 'Bulk-B': pk1 = 'B'; break;
case 'Bulk': pk1 = 'T'; break;
case 'Bulk-T': pk1 = 'T'; break;
case 'Cartridge': pk1 = 'C'; break;
case 'Any Pack': pk1='A'; break;
default: pk1 = 'unknown';
}

 
 
 var packmode =pk;
 if (packmode=="Bulk")
 {
    packmode="Bulk-T";
 }
 
 var newavail='Y';
 var tblpack='';
 if (packmode == 'Bulk-T' || packmode == 'Bulk-B')
  {
   for (curr_row = 0; curr_row < table.rows.length ; curr_row++)
    {
    if(table.rows[curr_row].cells[4].innerHTML == 'Y')
    tblpack = table.rows[curr_row].cells[3].innerHTML;
    }
  }
 if(tblpack == 'Bulk-T' || tblpack == 'Bulk-B')
   {
   if(tblpack != packmode)
    {
    newavail='N';
    }
   }
 if(newavail == 'N')
   {
   alert('Sorry You have already choose '+ tblpack);
   //document.getElementById('txtQuantity').value='';
   //document.getElementById('drpPack').focus();
   }
 else
   {
   var i= document.getElementById('tbl1').rows.length;
   var row = table.insertRow(-1); //append at the end
   var cell1 = row.insertCell(-1);
   var cell2 = row.insertCell(-1);
   var cell3 = row.insertCell(-1);
   var cell4 = row.insertCell(-1);
   var cell5 = row.insertCell(-1);
   var cell6 = row.insertCell(-1);
   var cell7 = row.insertCell(-1);
  if (i == 0)
    {
        cell1.innerHTML =  (1) + ".";
    }
  else
    {
        cell1.innerHTML =  (i + 1) + ".";
    }
  cell2.innerHTML = info[0];
  cell2.Id = info[1];
  if (packmode == 'Bulk-T' || packmode == 'Bulk-B' || packmode == 'Any Pack')
  {
    if (document.getElementById("txtHidden2").value=="LTR")
    {
        cell3.innerHTML = "<input align='center' style='width:35px;' type='textbox' id='txtQty" + cell1.innerHTML.replace('.','')+"' onkeyup='MoveNextPrev(this,event);'/> <label  id='label" + cell1.innerHTML.replace('.','')+"'>Lt.</label>";//formatdigit(info[4]);
    }
    else if (document.getElementById("txtHidden2").value=="USG")
    {
        cell3.innerHTML = "<input align='center' style='width:35px;' type='textbox' id='txtQty" + cell1.innerHTML.replace('.','')+"' onkeyup='MoveNextPrev(this,event);'/> <label  id='label" + cell1.innerHTML.replace('.','')+"'>USG</label>";//formatdigit(info[4]);
    }
    
  }
  else if(packmode == 'Drum' || packmode == 'Pail' || packmode == 'Cartridge')
  {
    cell3.innerHTML = "<input align='center' style='width:35px;' type='textbox' id='txtQty" + cell1.innerHTML.replace('.','')+"' onkeyup='MoveNextPrev(this,event);'/> <label  id='label" + cell1.innerHTML.replace('.','')+"'>Ea.</label>";
  }
  else
  {
    //cell3.innerHTML = "<input align='center' style='width:35px;' type='textbox' id='txtQty" + cell1.innerHTML.replace('.','')+"' onkeyup='MoveNextPrev(this,event);'/> <label  id='label" + cell1.innerHTML.replace('.','')+"'>Lt.</label>";//formatdigit(info[4]);
    if (document.getElementById("txtHidden2").value=="LTR")
    {
        cell3.innerHTML = "<input align='center' style='width:35px;' type='textbox' id='txtQty" + cell1.innerHTML.replace('.','')+"' onkeyup='MoveNextPrev(this,event);'/> <label  id='label" + cell1.innerHTML.replace('.','')+"'>Lt.</label>";//formatdigit(info[4]);
    }
    else if (document.getElementById("txtHidden2").value=="USG")
    {
        cell3.innerHTML = "<input align='center' style='width:35px;' type='textbox' id='txtQty" + cell1.innerHTML.replace('.','')+"' onkeyup='MoveNextPrev(this,event);'/> <label  id='label" + cell1.innerHTML.replace('.','')+"'>USG</label>";//formatdigit(info[4]);
    }
    
  }
  
  cell3.Id =cell1.innerHTML;
  
  //alert(cell3.Id);
  cell4.innerHTML = pk;
  cell4.Id = pk1;
//  if(mainstr1[0].trim() == "N")
//    {
//    cell5.className="headline11norred";
//    }
//  else if(mainstr1[0].trim() == "Y")
//   {
   cell5.className="headline11norgreen";
//   }
  var valueind = i;
  cell5.innerHTML = '';
  if (info[1]!="0")
  {
    cell6.innerHTML = "<a href=\"JavaScript:fnCheckNowOpen("+ valueind  + ");\" class='b-checknow'>Check now</a>";
  }
  else
  {
    cell6.innerHTML='';
  }
  cell7.innerHTML = "<a href='#' class='b-remove' onclick='JavaScript:removepro();'>Remove Item</a>";
  cell7.Id = info[3];
  cell1.width="7%";
  cell2.width="38%";
  cell3.width="15%";
  cell4.width="10%";
  cell5.width="1%";
  cell6.width="15%";
  cell7.width="15%";
  cell1.align="left";
  cell2.align="left";
  cell3.align="Middle";
  cell4.align="Middle";
  cell5.align="Middle";
  cell6.align="Middle";
  cell7.align="Middle";
  //d.getElementById('txtQuantity').value='';
  //d.getElementById('drpProduct').focus();
  //alert(info[1]+pk1);
     
  }
}
















function addtoprodlist(avail)
{

 var mainstr=avail.split("<");
 var mainstr1=mainstr[0].split("&");
 //alert(mainstr[0]);
 var d=document;
 var table = d.getElementById("tbl1");
 if (!table) throw "Table not found";
 if (($F('txtQuantity').trim()).length == 0)
  {
  alert("Quantity can not be blank");
  document.getElementById('txtQuantity').value='';
  document.getElementById('txtQuantity').focus();
  return false;
  }
 var packmode =d.getElementById('drpPack').options[d.getElementById('drpPack').selectedIndex].text;
 var newavail='Y';
 var tblpack='';
 if (packmode == 'Bulk-T' || packmode == 'Bulk-B')
  {
   for (curr_row = 0; curr_row < table.rows.length ; curr_row++)
    {
    if(table.rows[curr_row].cells[4].innerHTML == 'Y')
    tblpack = table.rows[curr_row].cells[3].innerHTML;
    }
  }
 if(tblpack == 'Bulk-T' || tblpack == 'Bulk-B')
   {
   if(tblpack != packmode)
    {
    newavail='N';
    }
   }
 if(newavail == 'N')
   {
   alert('Sorry You have already choose '+ tblpack);
   document.getElementById('txtQuantity').value='';
   document.getElementById('drpPack').focus();
   }
 else
   {
   var i= document.getElementById('tbl1').rows.length;
   var row = table.insertRow(-1); //append at the end
   var cell1 = row.insertCell(-1);
   var cell2 = row.insertCell(-1);
   var cell3 = row.insertCell(-1);
   var cell4 = row.insertCell(-1);
   var cell5 = row.insertCell(-1);
   var cell6 = row.insertCell(-1);
   var cell7 = row.insertCell(-1);
  if (i == 0)
    {
    cell1.innerHTML =  (1) + ".";
    }
  else
    {
    cell1.innerHTML =  (i + 1) + ".";
    }
  cell2.innerHTML = document.getElementById('drpProduct').options[document.getElementById('drpProduct').selectedIndex].text;
  cell2.Id = d.getElementById('drpProduct').value;
  cell3.innerHTML = formatdigit(document.getElementById('txtQuantity').value);
  cell3.Id =cell1.innerHTML;
  alert(cell3.Id);
  cell4.innerHTML = document.getElementById('drpPack').options[document.getElementById('drpPack').selectedIndex].text;
  cell4.Id = document.getElementById('drpPack').value;
  if(mainstr1[0].trim() == "N")
    {
    cell5.className="headline11norred";
    }
  else if(mainstr1[0].trim() == "Y")
   {
   cell5.className="headline11norgreen";
   }
  var valueind = i;
  cell5.innerHTML = mainstr1[0];
  cell6.innerHTML = "<a href=\"JavaScript:fnCheckNowOpen("+ valueind  + ");\" class='b-checknow'>Check now</a>";
  cell7.innerHTML = "<a href='#' class='b-remove' onclick='JavaScript:removepro();'>Remove Item</a>";
  cell7.Id = mainstr1[1];
  cell1.width="12%";
  cell2.width="18%";
  cell3.width="10%";
  cell4.width="14%";
  cell5.width="10%";
  cell6.width="22%";
  cell7.width="15%";
  d.getElementById('txtQuantity').value='';
  d.getElementById('drpProduct').focus();
  CheckExcep();
  }
}

function MoveNextPrev(ctrl,e)
{
    //alert('Hi');
    var id=ctrl.id;
    //alert('txtQty'+(eval(id.replace('txtQty',''))+1));
    var next=document.getElementById('txtQty'+(eval(id.replace('txtQty',''))+1));
    var prev=document.getElementById('txtQty'+(eval(id.replace('txtQty',''))-1));
    var keyPressed = e.which || e.keyCode;
    if (keyPressed == 40)
        {
            
            //alert("DOwn Key Pressed");
            if (next != null)
            {
                
                next.focus();
                //var i=divId.options[0].selected;
                return false;
            }   
        }
   else if (keyPressed == 38)
        {
            
            //alert("DOwn Key Pressed");
            if (prev != null)
            {
                
                prev.focus();
                //var i=divId.options[0].selected;
                return false;
            }   
        }
       
}












function CheckAvail_New()
  {
    var strSQL;
	var strvalue='';
	var cond = false;
	//alert('i am in avail');
	var port=document.getElementById('drpPort').value;
	var product=document.getElementById('drpProduct').value;
	var pack=document.getElementById('drpPack').value;
	strvalue=strvalue + "PortId=" + port + " and " ;
	strvalue=strvalue + "ProductId='" + product + "' and " ;
	strvalue=strvalue + "prdDistribution like '%" + pack + "%'" ;
	//strSQL= strvalue;
	// URL to get data from server
	var requestUrl = "AvailData.aspx" + "?C=" + encodeURIComponent(strvalue) ;
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp){
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = GetAvail_new;

		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		
		//Sends the request to server
		XmlHttp.send(null);		
    }
   }


function GetAvail_new(){
	// To make sure receiving response data from server is completed
 	if(XmlHttp.readyState == 4){
 		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        return true;
		     }      
		else {
		    addtoprodlist((XmlHttp.responseText).trim());
		    return true;
          	 }
		  }
		else{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		 }
	  }
  }


















function CheckAvail()
  {
    var strSQL;
	var strvalue='';
	var cond = false;
	//alert('i am in avail');
	var port=document.getElementById('drpPort').value;
	var product=document.getElementById('drpProduct').value;
	var pack=document.getElementById('drpPack').value;
	strvalue=strvalue + "PortId=" + port + " and " ;
	strvalue=strvalue + "ProductId='" + product + "' and " ;
	strvalue=strvalue + "prdDistribution like '%" + pack + "%'" ;
	//strSQL= strvalue;
	// URL to get data from server
	var requestUrl = "AvailData.aspx" + "?C=" + encodeURIComponent(strvalue) ;
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp){
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = GetAvail;

		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		
		//Sends the request to server
		XmlHttp.send(null);		
    }
   }


function GetAvail(){
	// To make sure receiving response data from server is completed
 	if(XmlHttp.readyState == 4){
 		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        return true;
		     }      
		else {
		    addtoprodlist((XmlHttp.responseText).trim());
		    return true;
          	 }
		  }
		else{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		 }
	  }
  }
//---------------------------------End function---------------------------------------------------------------------
//--------------------------------Function for remove button in order list------------------------------------------

function removepro()
   {
   var yesno = confirm("Are you sure to delete this row?");
   if (yesno == true)
     {
     var current = window.event.srcElement;
    //here we will delete the line
    while ( (current = current.parentElement) && current.tagName !="TR");
    current.parentElement.removeChild(current);
    var oRow;
    var curr_row;
     for(curr_row = 0; curr_row < document.getElementById('tbl1').rows.length ; curr_row++)
      {
      oRow = document.getElementById('tbl1').rows[curr_row];
      oRow.cells[0].innerHTML = curr_row + 1 + ".";
      if (oRow.cells[1].Id != "0")
      {
        oRow.cells[5].innerHTML = "<a href=\"JavaScript:fnCheckNowOpen("+ curr_row + ");\" class='b-checknow'>Check now</a>";
      }
      }
    CheckExceponDelete_OnDelete();
//    var table = document.getElementById("tbl4");
//    if (table.rows.length > 0)
//    { 
//        addtocalculate();
//    }
    }
   }
//---------------------------------End function---------------------------------------------------------------------

//---------------------------------------Function for check Exceptionality--------------------------------------------
function CheckExcep()
  {
    var strSQL;
	var strvalue='';
		
	var port=document.getElementById('drpPort').value;
	var product=document.getElementById('drpProduct').value;
	var pack=document.getElementById('drpPack').value;
	strvalue="PortId=" + port + " and " ;
	strvalue=strvalue + "ProductId='" + product + "' and " ;
	strvalue=strvalue + "prdDistribution like '%" + pack + "%'" ;
	
	var product=document.getElementById('drpProduct').value;
	var port=document.getElementById('drpPort').value;
		// URL to get data from server
	var requestUrl = "exception.aspx" + "?S=I&C=" + encodeURIComponent(strvalue) ;
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp){
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = GetExcep;

		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
  }

function CheckExcep_new(prod,pk)
  {
    //alert(prod);
    //alert(pk);
    var strSQL;
	var strvalue='';
		
	var port=document.getElementById('drpPort').value;
	var product=prod;
	var pack=pk;
	strvalue="PortId=" + port + " and " ;
	strvalue=strvalue + "ProductId='" + product + "' and " ;
	strvalue=strvalue + "prdDistribution like '%" + pack + "%'" ;
	
	//var product=document.getElementById('drpProduct').value;
	//var port=document.getElementById('drpPort').value;
		// URL to get data from server
	var requestUrl = "exception.aspx" + "?S=I&C=" + encodeURIComponent(strvalue) ;
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp){
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = GetExcep_new;

		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
  }


function GetExcep_new(){
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        return true;
		     }      
		else {
		    WriteExcep_new((XmlHttp.responseText).trim());
		    return true;
		  }
		
		 }
		else{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		 }
	  }
  }
function WriteExcep_new(str)
  {
  //alert(str);
  var mainstr=str.trim().split("&");
  var unit;
  if(document.getElementById("Op1").checked == true)
  unit=1;
  else if(document.getElementById("Op2").checked == true)
  unit=3.7852;
  var oRow;
  var xyz='';
  var LT;
  var SLT;
  var FLT;
  
  if(mainstr[1].trim().length > 0)
    {
    oRow = document.getElementById('tbl3').rows[2];
    if (oRow.cells[4].innerHTML.trim().length<=0 || oRow.cells[4].innerHTML.trim() == '-')
    {
        xyz='0';
    }
    else
    {
        xyz=changedigit(oRow.cells[4].innerHTML);
    }
    alert(xyz);
    //alert(parseInt(changedigit(oRow.cells[4].innerHTML)));
    //alert(parseInt(mainstr[1]));
    if(parseInt(xyz) < parseInt(mainstr[1]) || oRow.cells[4].innerHTML.trim() == '-')
     {
     oRow.cells[4].innerHTML = mainstr[1];
     }
    
    
    }
    
    
    
   
    
   if(mainstr[2].trim().length > 0)
    {
     oRow = document.getElementById('tbl3').rows[6];
     if(parseInt(changedigit(oRow.cells[4].innerHTML)) < parseInt(mainstr[2]) || oRow.cells[4].innerHTML.trim() == '-')
      {
      oRow.cells[4].innerHTML = formatdigit(Math.ceil(eval(mainstr[2])/unit));
      }
     }
    if(mainstr[3].trim().length > 0)
     {
     oRow = document.getElementById('tbl3').rows[10];
     if(parseInt(changedigit(oRow.cells[4].innerHTML)) < parseInt(mainstr[2]) || oRow.cells[4].innerHTML.trim() == '-')
      {
      oRow.cells[4].innerHTML = formatdigit(Math.ceil(eval(mainstr[3])/unit));
      }
     }
   }










function GetExcep(){
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        return true;
		     }      
		else {
		    WriteExcep((XmlHttp.responseText).trim());
		    return true;
		  }
		
		 }
		else{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		 }
	  }
  }
function WriteExcep(str)
  {
  var mainstr=str.trim().split("&");
  var unit;
  if(document.getElementById("Op1").checked == true)
  unit=1;
  else if(document.getElementById("Op2").checked == true)
  unit=3.7852;
  var oRow;
  if(mainstr[1].trim().length > 0)
    {
    oRow = document.getElementById('tbl3').rows[2];
    if(parseInt(changedigit(oRow.cells[4].innerHTML)) < parseInt(mainstr[2]) || oRow.cells[4].innerHTML.trim() == '-')
     {
     oRow.cells[4].innerHTML = mainstr[1];
     }
    }
   if(mainstr[2].trim().length > 0)
    {
     oRow = document.getElementById('tbl3').rows[6];
     if(parseInt(changedigit(oRow.cells[4].innerHTML)) < parseInt(mainstr[2]) || oRow.cells[4].innerHTML.trim() == '-')
      {
      oRow.cells[4].innerHTML = formatdigit(Math.ceil(eval(mainstr[2])/unit));
      }
     }
    if(mainstr[3].trim().length > 0)
     {
     oRow = document.getElementById('tbl3').rows[10];
     if(parseInt(changedigit(oRow.cells[4].innerHTML)) < parseInt(mainstr[2]) || oRow.cells[4].innerHTML.trim() == '-')
      {
      oRow.cells[4].innerHTML = formatdigit(Math.ceil(eval(mainstr[3])/unit));
      }
     }
   }
  //----------------------------------------------End function-------------------------------------------------------
  //-------------------------------------on delete button check exceptionality---------------------------------------
  function CheckExceponDelete()
  {
	var strSQL = document.getElementById('drpPort').value;
	var table = document.getElementById('tbl1');
	var pk1="";
	for(j= 0;j <table.rows.length;j++)
     {
        switch (table.rows[j].cells[3].Id) {
            case 'P': pk1 = 'Pail'; break;
            case 'D': pk1 = 'Drum'; break;
            case 'B': pk1 = 'Barge'; break;
            case 'B': pk1 = 'Barge'; break;
            case 'T': pk1 = 'Truck'; break;
            case 'C': pk1 = 'Cartridge'; break;
            case 'A': pk1='Any Pack'; break;
            default: pk1 = 'unknown';
            }

         if (table.rows[j].cells[1].Id != "0")
         {
            strSQL = strSQL + "&" + table.rows[j].cells[1].Id + "&" + pk1;
         }
     }
     //alert(strSQL);
	// URL to get data from server
	//alert(strSQL);
	var requestUrl = "exception.aspx" + "?S=D&C=" + encodeURIComponent(strSQL) ;
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp){
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = GetExceponDelete;

		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
  }

function GetExceponDelete(){
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        //alert(XmlHttp.responseText);
		        return true;
		     }      
		else {
		    //alert(XmlHttp.responseText);
		    WriteExceponDelete((XmlHttp.responseText).trim());
		    return true;
		  }
		
		 }
		else{
			alert("There was a problem retrieving data from the server. Please try again!" )
			return false;
		 }
	  }
  }
  function WriteExceponDelete(str)
  {
  //alert(str);
   var GetStr=str.trim().split("|");
   
   var mainstr=GetStr[1].trim().split("&");
   var j;
   var table = document.getElementById('tbl1');
   for(j= 0;j <table.rows.length;j++)
     {
        if (table.rows[j].cells[1].Id != "0")
         {
            table.rows[j].cells[6].Id=mainstr[j+1].substring(0,3);
            //alert(mainstr[j+1].substring(0,3));
         }
     }
   
   
   //WriteExceponforeachrecord(GetStr[1]);
   
   var mainstr=GetStr[0].trim().split("&");
   var unit;
   var LT;
   var SLT;
   var FLT;
   if(document.getElementById("Op1").checked == true)
   unit=1;
   else if(document.getElementById("Op2").checked == true)
   unit=3.7852;
   var oRow;
   //alert(mainstr[1]);
   //alert(mainstr[2]);
   //alert(mainstr[3]);
   if(mainstr[1] != 0)
    {
    oRow = document.getElementById('tbl3').rows[2];
    oRow.cells[4].innerHTML =mainstr[1];
    
    
    
    
    
    }
   else
    {
    oRow = document.getElementById('tbl3').rows[2];
    oRow.cells[4].innerHTML = "-";
    }
   
   if (oRow.cells[3].innerHTML.trim().length<=0 || oRow.cells[3].innerHTML.trim()=="-")
    {
        LT='0';
    }
    else
    {
        LT=changedigit(oRow.cells[3].innerHTML);
    }
    
    if (oRow.cells[4].innerHTML.trim().length<=0 || oRow.cells[4].innerHTML.trim()=="-")
    {
        SLT='0';
    }
    else
    {
        SLT=changedigit(oRow.cells[4].innerHTML);
    }
    
    if (parseInt(LT)>=parseInt(SLT))
    {
        FLT=LT;
    }
    else
    {
        FLT=SLT;
    }
    
    
    //alert(FLT);
    ResetEarliestDeliveryDate(FLT);
    
   
   
   
   
   
   
   
   if(mainstr[2] != 0)
    {
    oRow = document.getElementById('tbl3').rows[6];
    oRow.cells[4].innerHTML = formatdigit(Math.ceil(eval(mainstr[2])/unit));
    }
   else
    {
    oRow = document.getElementById('tbl3').rows[6];
    oRow.cells[4].innerHTML = "-";
    }
   if(mainstr[3] != 0)
    {
    oRow = document.getElementById('tbl3').rows[10];
    oRow.cells[4].innerHTML = formatdigit(Math.ceil(eval(mainstr[3])/unit));
    }
   else
    {
    oRow = document.getElementById('tbl3').rows[10];
    oRow.cells[4].innerHTML = "-";
    }
    
    
    
    
  }
//--------------------------------------------------End function----------------------------------------------------





//-------------------------------------on delete button check exceptionality---------------------------------------
  function CheckExceponDelete_OnDelete()
  {
	var strSQL = document.getElementById('drpPort').value;
	var table = document.getElementById('tbl1');
	var pk1="";
	for(j= 0;j <table.rows.length;j++)
     {
        switch (table.rows[j].cells[3].Id) {
            case 'P': pk1 = 'Pail'; break;
            case 'D': pk1 = 'Drum'; break;
            case 'B': pk1 = 'Barge'; break;
            case 'B': pk1 = 'Barge'; break;
            case 'T': pk1 = 'Truck'; break;
            case 'C': pk1 = 'Cartridge'; break;
            case 'A': pk1='Any Pack'; break;
            default: pk1 = 'unknown';
            }

         if (table.rows[j].cells[1].Id != "0")
         {
            strSQL = strSQL + "&" + table.rows[j].cells[1].Id + "&" + pk1;
         }
     }
     //alert(strSQL);
	// URL to get data from server
	//alert(strSQL);
	var requestUrl = "exception.aspx" + "?S=D&C=" + encodeURIComponent(strSQL) ;
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp){
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = GetExceponDelete_OnDelete;

		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
  }

function GetExceponDelete_OnDelete(){
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        //alert(XmlHttp.responseText);
		        return true;
		     }      
		else {
		    //alert(XmlHttp.responseText);
		    WriteExceponDelete_OnDelete((XmlHttp.responseText).trim());
		    return true;
		  }
		
		 }
		else{
			alert("There was a problem retrieving data from the server. Please try again!" )
			return false;
		 }
	  }
  }
  function WriteExceponDelete_OnDelete(str)
  {
  //alert(str);
   var GetStr=str.trim().split("|");
   
   var mainstr=GetStr[1].trim().split("&");
   var j;
   var table = document.getElementById('tbl1');
   for(j= 0;j <table.rows.length;j++)
     {
        if (table.rows[j].cells[1].Id != "0")
         {
            table.rows[j].cells[6].Id=mainstr[j+1].substring(0,3);
            //alert(mainstr[j+1].substring(0,3));
         }
     }
   
   
   //WriteExceponforeachrecord(GetStr[1]);
   
   var mainstr=GetStr[0].trim().split("&");
   var unit;
   var LT;
   var SLT;
   var FLT;
   if(document.getElementById("Op1").checked == true)
   unit=1;
   else if(document.getElementById("Op2").checked == true)
   unit=3.7852;
   var oRow;
   //alert(mainstr[1]);
   //alert(mainstr[2]);
   //alert(mainstr[3]);
   if(mainstr[1] != 0)
    {
    oRow = document.getElementById('tbl3').rows[2];
    oRow.cells[4].innerHTML =mainstr[1];
    
    
    
    
    
    }
   else
    {
    oRow = document.getElementById('tbl3').rows[2];
    oRow.cells[4].innerHTML = "-";
    }
   
   if (oRow.cells[3].innerHTML.trim().length<=0 || oRow.cells[3].innerHTML.trim()=="-")
    {
        LT='0';
    }
    else
    {
        LT=changedigit(oRow.cells[3].innerHTML);
    }
    
    if (oRow.cells[4].innerHTML.trim().length<=0 || oRow.cells[4].innerHTML.trim()=="-")
    {
        SLT='0';
    }
    else
    {
        SLT=changedigit(oRow.cells[4].innerHTML);
    }
    
    if (parseInt(LT)>=parseInt(SLT))
    {
        FLT=LT;
    }
    else
    {
        FLT=SLT;
    }
    
    
    //alert(FLT);
    ResetEarliestDeliveryDate(FLT);
    
   
   
   
   
   
   
   
   if(mainstr[2] != 0)
    {
    oRow = document.getElementById('tbl3').rows[6];
    oRow.cells[4].innerHTML = formatdigit(Math.ceil(eval(mainstr[2])/unit));
    }
   else
    {
    oRow = document.getElementById('tbl3').rows[6];
    oRow.cells[4].innerHTML = "-";
    }
   if(mainstr[3] != 0)
    {
    oRow = document.getElementById('tbl3').rows[10];
    oRow.cells[4].innerHTML = formatdigit(Math.ceil(eval(mainstr[3])/unit));
    }
   else
    {
    oRow = document.getElementById('tbl3').rows[10];
    oRow.cells[4].innerHTML = "-";
    }
    
    var table = document.getElementById("tbl4");
    if (table.rows.length > 0)
    { 
        addtocalculate();
    }
    
    
    
  }
//--------------------------------------------------End function----------------------------------------------------

























//--------------------------------------------presently not using function------------------------------------------
function addtocalculate1(resultstr)//unused function
 {
  var mainstr1=resultstr.split("<");
  var mainstr=mainstr1[0].trim().split("&");
  var d=document
  //d.getElementById("fd").style.visibility = "hidden";
  //d.getElementById("sd").style.visibility = "visible";
  var table = d.getElementById("tbl4");
  if (table.rows.length > 0)
   { 
   for(var i = table.rows.length; i > 0;i--)
    {
     table.deleteRow(i -1);
    }
   }
  if (!table) throw "Table not found";
  var i= document.getElementById('tbl1').rows.length;

//d.getElementById('tbl4').rows.length = 0;
  for(j= 0;j < d.getElementById('tbl1').rows.length;j++)
   {
   if(document.getElementById('tbl1').rows[j].cells[4].innerHTML.trim() == 'Y')
    {
    var row = table.insertRow(-1); 
    row.height="20";
    //append at the end
    var cell1 = row.insertCell(-1);
    var cell2 = row.insertCell(-1);
    var cell3 = row.insertCell(-1);
    var cell4 = row.insertCell(-1);
    var cell5 = row.insertCell(-1);
    cell1.width="50%";
    cell2.width="15%";
    cell3.width="15%";
    cell4.width="15%";
    cell5.width="15%";
    cell1.align="left";
    cell2.align="left";
    cell3.align="left";
    cell4.align="left";
    cell5.align="left";
    cell1.innerHTML =document.getElementById('tbl1').rows[j].cells[1].innerHTML;
    var quantity = document.getElementById('tbl1').rows[j].cells[2].innerHTML;
    if (document.getElementById('tbl1').rows[j].cells[3].innerHTML=='Bulk')
    {
        var pack='Bulk-T';
     }
     else
     {
        var pack = document.getElementById('tbl1').rows[j].cells[3].innerHTML;
     }
    if(document.getElementById("Op1").checked == true)
     {
     if(pack == 'Drum') result = quantity * 208 + ' Ltr';
     else  if(pack == 'Pail') result = quantity * 20 + ' Ltr';
     else if(pack == 'Cartridge') result =quantity * 12 + ' Ltr';
     else if(pack == 'Bulk-B') result =  quantity + ' Ltr';
     else if(pack == 'Bulk-T') result =  quantity + ' Ltr';
     }
     else if(document.getElementById("Op2").checked == true)
     {
     if(pack == 'Drum') result  = parseInt((quantity * 208)/3.7852) + ' USG';
     else if(pack == 'Pail') result =parseInt ((quantity * 20)/3.7852) + ' USG';
     else if(pack == 'Cartridge') result =parseInt ((quantity * 12)/3.7852) + ' USG'
     else if(pack == 'Bulk-B') result =  quantity + ' USG';
     else if(pack == 'Bulk-T') result =  quantity + ' USG';
     }
     cell2.innerHTML=result;
    }
  }
} 
//---------------------------------------------End function----------------------------------------------------------
//--------------------------------------function for validation button----------------------------------------------
function addtocalculate()
 {
  var d=document
  var unit;
  //alert(document.getElementById("txtDate").value);

  if(document.getElementById("txtDate").value=='dd MMM yyyy')
  {
  alert("Please Enter Requested Delivery Date");
  return;
  //document.getElementById("txtDate").focus;
    //return false;
  }
  if(document.getElementById("Op1").checked == true)
  unit=1;
  else if(document.getElementById("Op2").checked == true)
  unit=3.7852;
  var table = d.getElementById("tbl4");
  
  if (table.rows.length > 0)
   { 
   for(var i = table.rows.length; i > 0;i--)
    {
    table.deleteRow(i -1);
    }
   }
  if (!table) throw "Table not found";
  var i= d.getElementById('tbl1').rows.length;
  var quantity ="";
  for(j= 0;j < d.getElementById('tbl1').rows.length;j++)
   	{
		quantity = document.getElementById('txtQty'+document.getElementById('tbl1').rows[j].cells[2].Id.replace('.','')).value;
   if(quantity=="")
     {
  		alert("Please fill quantity before validation.");
		document.getElementById('txtQty'+document.getElementById('tbl1').rows[j].cells[2].Id.replace('.','')).focus();
		return;
  	 }
	}
  for(j= 0;j < d.getElementById('tbl1').rows.length;j++)
   {
   if(d.getElementById('tbl1').rows[j].cells[4].innerHTML.trim() == '')
     {
     var row = table.insertRow(-1); 
     row.height="20";
     //append at the end
     var cell1 = row.insertCell(-1);
     var cell2 = row.insertCell(-1);
     var cell3 = row.insertCell(-1);
     var cell4 = row.insertCell(-1);
     var cell5 = row.insertCell(-1);
     var cell6 = row.insertCell(-1);
     cell1.className="headline11nor";
     cell2.className="headline11nor";
     cell3.className="headline11nor";
     cell4.className="headline11nor";
     cell5.className="headline11nor";
     cell1.width="18%";
     cell2.width="25%";
     cell3.width="12%";
     cell4.width="14%";
     cell5.width="15%";
     cell6.width="14%";
     cell1.align="left";
     cell2.align="center";
     cell3.align="center";
     cell4.align="center";
     cell5.align="center";
     cell6.align="center";
     cell1.innerHTML =document.getElementById('tbl1').rows[j].cells[1].innerHTML;
     //alert(document.getElementById('tbl1').rows[j].cells[2].id);
     //alert('txtQty'+document.getElementById('tbl1').rows[j].cells[2].id);
     var quantity = document.getElementById('txtQty'+document.getElementById('tbl1').rows[j].cells[2].Id.replace('.','')).value;
	 
	 if (document.getElementById('tbl1').rows[j].cells[3].innerHTML=='Bulk')
    {
        var pack='Bulk-T';
     }
     else
     {
        var pack = document.getElementById('tbl1').rows[j].cells[3].innerHTML;
     }
    
	// var pack = document.getElementById('tbl1').rows[j].cells[3].innerHTML;
     //alert(pack);
     //alert(quantity);
     if(pack == 'Drum') result = quantity * 208 ;
     else if(pack == 'Pail') result = quantity * 20;
     else if(pack == 'Cartridge') result =quantity * 12 ;
     else if(pack == 'Bulk-B') result =  quantity ;
     else if(pack == 'Bulk-T') result =  quantity ;
     else if(pack == 'Bulk') result =  quantity ;
     else if(pack == 'Any Pack') result =  quantity ;
     else result=quantity;
     var excep = document.getElementById('tbl1').rows[j].cells[6].Id;
     
     //alert(excep);
     //alert(result);
     //alert(unit);
     //alert(pack);
     //alert(result);
     if(pack == 'Drum' || pack == 'Pail' || pack == 'Cartridge' || pack=='Any Pack') 
        {
        //alert(excep);
        if(excep.trim() == 'No')
           {
           //alert(excep);
           cell2.innerHTML=formatdigit(Math.ceil(eval(result)/unit));
           cell3.innerHTML="-";
           cell4.innerHTML="-";
           cell5.innerHTML="-";
           cell6.innerHTML="-";
           }
        else 
           {
           //alert(excep);
           cell2.innerHTML=formatdigit(Math.ceil(eval(result)/unit));
           cell3.innerHTML="-";
           cell4.innerHTML="-";
           cell5.innerHTML="-";
           cell6.innerHTML="-";
           }
        }
      else if (pack == 'Bulk-B' || pack == 'Bulk-T' || pack == 'Bulk') 
        {
          //  alert(pack);
          //  alert(result);
          if(excep.trim() == 'No')
           {
           cell2.innerHTML="-";
           cell3.innerHTML=formatdigit(result);
           cell4.innerHTML="-";
           cell5.innerHTML="-";
           cell6.innerHTML="-";
           }
         else
           {
           cell2.innerHTML="-";
           cell3.innerHTML="-";
           cell4.innerHTML=formatdigit(result);
           cell5.innerHTML="-";
           cell6.innerHTML="-";
           }
        }
     else
        {
        //alert(excep);
        if(excep.trim() == 'No')
           {
           //alert(excep);
           cell2.innerHTML=formatdigit(Math.ceil(eval(result)/unit));
           cell3.innerHTML="-";
           cell4.innerHTML="-";
           cell5.innerHTML="-";
           cell6.innerHTML="-";
           }
        else 
           {
           //alert(excep);
           cell2.innerHTML=formatdigit(Math.ceil(eval(result)/unit));
           cell3.innerHTML="-";
           cell4.innerHTML="-";
           cell5.innerHTML="-";
           cell6.innerHTML="-";
           }
        }
     
     
     }
   }
   //alert("kiuy");
 if(d.getElementById('tbl4').rows.length > 0)
   {
    findcalculate1();
    findcalculate2();
    CheckLeadTime();
    //WriteErrorCode();
    
    //WriteErrorCode();
   }
 } 
function findcalculate1()
  {
   var d=document;
   var valanci = 0; 
   var valbulkregular = 0; 
   var valbulkexception =0;
   var table = document.getElementById('tbl5');
   var tbl= document.getElementById('tbl4');
   var bulkreg=0;
   var bulkexcep =0;
   if (!table) throw "Table not found";
   for(var curr_row= 0;curr_row < d.getElementById('tbl4').rows.length;curr_row++)
      {
        if(tbl.rows[curr_row].cells[1].innerHTML.trim() != '-')
        valanci =eval(changedigit(valanci)) + eval(changedigit(tbl.rows[curr_row].cells[1].innerHTML.trim()));
        if(tbl.rows[curr_row].cells[2].innerHTML.trim() != "-")
         {
         if (eval(bulkreg)==0)
          {
          bulkreg = eval(changedigit(tbl.rows[curr_row].cells[2].innerHTML.trim()));
          }
        if (eval(changedigit(bulkreg)) > eval(changedigit(tbl.rows[curr_row].cells[2].innerHTML.trim()))) 
        bulkreg = eval(changedigit(tbl.rows[curr_row].cells[2].innerHTML.trim()));
        valbulkregular = eval(changedigit(valbulkregular)) + eval(changedigit(tbl.rows[curr_row].cells[2].innerHTML.trim()));
       }
   if(tbl.rows[curr_row].cells[3].innerHTML.trim() != "-")
     {
      if(eval(changedigit(bulkexcep))== 0)
       {
        bulkexcep=eval(changedigit(tbl.rows[curr_row].cells[3].innerHTML.trim()));
       }
       if(eval(changedigit(bulkexcep)) < eval(changedigit(tbl.rows[curr_row].cells[3].innerHTML.trim()))) 
       //alert(tbl.rows[curr_row].cells[3].innerHTML.trim());
       bulkexcep = eval(changedigit(tbl.rows[curr_row].cells[3].innerHTML.trim()));
       valbulkexception =eval(changedigit(valbulkexception)) + eval(changedigit(tbl.rows[curr_row].cells[3].innerHTML.trim()));
    }
  }
 if (valanci == 0)
  table.rows[8].cells[2].innerHTML = '-';
 else
  table.rows[8].cells[2].innerHTML =formatdigit(valanci);
 if (bulkreg == 0)
  table.rows[8].cells[3].innerHTML = '-';
 else
  table.rows[8].cells[3].innerHTML = formatdigit(bulkreg);
 //alert(bulkexcep);
 //alert(bulkreg);
 if(bulkexcep == 0)
    
  table.rows[8].cells[4].innerHTML = '-';
 else
  table.rows[8].cells[4].innerHTML =formatdigit(bulkexcep);
 //alert(table.rows[7].cells[4].innerHTML); 
 if((bulkexcep == 0) && (bulkreg == 0))
  table.rows[8].cells[5].innerHTML = '-';
 else
  table.rows[8].cells[5].innerHTML = formatdigit(eval(changedigit(valbulkregular)) +eval(changedigit(valbulkexception)));
  //alert(table.rows[7].cells[5].innerHTML);
}

function replaceZeroForBlank(str)
{
    if (str=="")
    {
        return("0");
    }
    else
    {
        return(str);
    }
}

function findcalculate2()
  {
  var CheckError='';
  
  var table = document.getElementById('tbl5');
  var tbl=document.getElementById('tbl3');
  var validatepack = '-'; 
  var valdatepackcom ='-'
  var validatebulkregular= '-';
  var validatebulkexc = '-';
  var validateleadtime='-';
  var validatetotbulk ='-';
  var lblPackCalc=document.getElementById("tdPackVol");
  var result=''; 
  var curr_row;
  var tbl1=document.getElementById('tbl1');
  for (curr_row = 0; curr_row < tbl1.rows.length ; curr_row++)
    {
    if((tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk-T' || tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk-B' || tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk'))
        
        if (tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk')
        {
            result ='Bulk-T';
        }
        else
        {
            result =tbl1.rows[curr_row].cells[3].innerHTML;    
        }
     
    }
////   if (result =='Bulk-B')
////     {
////        lblPackCalc.innerHTML="Pack Volume Calculation";
////     }
////    else if(result =='Bulk-T' || result == '')
////     {
////     lblPackCalc.innerHTML="Pack Volume Calculation";
////     }
////    
    var TruckCalculation=document.getElementById("txtHidden10").value;
    //alert(TruckCalculation);
    if ((result == 'Bulk-B') || ((result == 'Bulk-T') && (TruckCalculation > 0)))
     {
     //var cmppacked =changedigit(tbl.rows[8].cells[1].innerHTML.trim());
     var cmppackedcom =changedigit(tbl.rows[10].cells[1].innerHTML.trim());
     }
    else
     {
     //var cmppacked =changedigit(tbl.rows[8].cells[1].innerHTML.trim());
     var cmppackedcom =changedigit(tbl.rows[8].cells[1].innerHTML.trim());
     }
     //alert(cmppackedcom);
   var cmptruckreg =changedigit(tbl.rows[6].cells[3].innerHTML.trim());
   var cmpbargereg =changedigit(tbl.rows[10].cells[3].innerHTML.trim());
   var cmptruckexc =changedigit(tbl.rows[6].cells[4].innerHTML.trim());
   var cmpbargeexc =changedigit(tbl.rows[10].cells[4].innerHTML.trim());
   //alert(cmpbargeexc);
   var cmptottruck =changedigit(tbl.rows[8].cells[3].innerHTML.trim());
   if (eval(cmptruckexc)>eval(cmptottruck))
   {
    cmptottruck=cmptruckexc;
   }
   var cmptotbarge =changedigit(tbl.rows[12].cells[3].innerHTML.trim());
   if (eval(cmpbargeexc)>eval(cmptotbarge))
   {
    cmptotbarge=cmpbargeexc;
   }
   var valpack=changedigit(table.rows[8].cells[2].innerHTML.trim());
   var valbulkreg =changedigit(table.rows[8].cells[3].innerHTML.trim());
   var valbulkexc=changedigit(table.rows[8].cells[4].innerHTML.trim());
   var totbulk=changedigit(table.rows[8].cells[5].innerHTML.trim());
   
   var PackGap
   var BulkRegGap
   var BulkExcGap
   var BulkTotal
   
   // pack case
//    if(valpack.length == 0)
//      {
//      validatepack ='N/A';
//      }
//    else if(eval(valpack) >= eval(cmppacked))
//     validatepack = 'Y';
//    else
//     validatepack = 'N';
//     //alert(validatepack);
//   // pack combined
   if(valpack.length  == 0)
     {
     validatepackcom ='N/A';
     PackGap='N/A';
     }
   else if(eval(valpack) >= eval(cmppackedcom))
     {
     validatepackcom = 'Y';
     PackGap='0';
     }
   else{
    validatepackcom = 'N';
    PackGap=eval(cmppackedcom)-eval(valpack);}
    //alert(validatepackcom);
  //bulk regular case
  //alert(result);
  //alert(cmptruckreg+','+cmpbargereg+','+cmptruckexc+','+cmpbargeexc);
  
  if(valbulkreg.length  == 0)
    {
    validatebulkregular = 'N/A';
    BulkRegGap='N/A';
    }
  else if(result == 'Bulk-T')
    {
   
  if(eval(valbulkreg) >= eval(cmptruckreg)){
   validatebulkregular = 'Y';
   BulkRegGap='0';}
  else{
   validatebulkregular = 'N';
   BulkRegGap=eval(cmptruckreg)-eval(valbulkreg);}
   }
  else if(result == 'Bulk-B')
   {
   if(eval(valbulkreg) >= eval(cmpbargereg)){
     validatebulkregular = 'Y';
     BulkRegGap='0';}
   else{
     validatebulkregular = 'N';
     BulkRegGap=eval(cmpbargereg)-eval(valbulkreg);}
   }  
    //alert(validatebulkregular);
  // bulk exception case 
  if(valbulkexc.length  == 0)
    {
    validatebulkexc ='N/A';
    BulkExcGap='N/A';
    }
  else if(result == 'Bulk-T')
    {
    if(eval(valbulkexc) >= eval(cmptruckexc)){
      validatebulkexc = 'Y';
      BulkExcGap='0';}
    else{
      validatebulkexc = 'N';
      BulkExcGap=eval(cmptruckexc)-eval(valbulkexc);}
     }
  else if(result == 'Bulk-B')
    {
    if(eval(valbulkexc) >= eval(cmpbargeexc)){
      validatebulkexc = 'Y';
      BulkExcGap='0';}
    else{
      validatebulkexc = 'N';
      BulkExcGap=eval(cmpbargeexc)-eval(valbulkexc);}
    }
    //alert(validatebulkexc);
  //totalbulk 
    if(totbulk.length  == 0){
     validatetotbulk ='N/A';
     BulkTotal='N/A';}
    else if(result == 'Bulk-T')
     {
     if(eval(totbulk) >= eval(cmptottruck)){
       validatetotbulk = 'Y';
       BulkTotal='0';}
     else{
       validatetotbulk = 'N'; 
       BulkTotal=eval(cmptottruck)-eval(totbulk);}
     }
    else if(result == 'Bulk-B')
     {
      if(eval(totbulk) >= eval(cmptotbarge)){
        validatetotbulk = 'Y';
        BulkTotal='0';}
      else{
        validatetotbulk = 'N'; 
        BulkTotal=eval(cmptotbarge)-eval(totbulk);}
      }
//alert(validatetotbulk);
//    if (validatepack == 'Y')
//    {
//          table.rows[5].cells[2].className = "headline11norgreenw";
//          table.rows[5].cells[2].innerHTML =  "PASS";
//     }
//     
//    else 
//    {
//        if(validatepack == 'N')
//        {
//              table.rows[5].cells[2].className = "headline11norredw";
//              table.rows[5].cells[2].innerHTML =  "Pack Volume Fee";
//              CheckError='Y';
//         }
//        else
//        {
//             table.rows[5].cells[2].className = "headline11norBlackw";
//             table.rows[5].cells[2].innerHTML =  validatepack;
//        }
//    }
    
    
    
    if (validatepackcom == 'Y')
    {
        table.rows[5].cells[2].className = "headline11norgreenw"; 
        table.rows[5].cells[2].innerHTML =  "PASS";
        table.rows[7].cells[2].className = "headline11norgreenw"; 
        table.rows[7].cells[2].innerHTML =  PackGap;
    }
    else 
    {
        if (validatepackcom == 'N')
        {
            table.rows[5].cells[2].className = "headline11norredw";
            table.rows[5].cells[2].innerHTML =  "Pack Volume Fee";
            table.rows[7].cells[2].className = "headline11norredw";
            table.rows[7].cells[2].innerHTML =  PackGap;
            CheckError='Y';
        }
        else
        {
            table.rows[5].cells[2].className = "headline11norblackw"; 
            table.rows[5].cells[2].innerHTML =  validatepackcom;
            table.rows[7].cells[2].className = "headline11norblackw";
            table.rows[7].cells[2].innerHTML =  PackGap;
        }
    }
    if (validatebulkregular == 'Y')
    {
        table.rows[5].cells[3].className = "headline11norgreenw";
        table.rows[5].cells[3].innerHTML = "PASS";
        table.rows[7].cells[3].className = "headline11norgreenw";
        table.rows[7].cells[3].innerHTML = BulkRegGap;
    }
    else 
    {
        if(validatebulkregular == 'N')
        {
            table.rows[5].cells[3].className = "headline11norredw";
            table.rows[5].cells[3].innerHTML = "Bulk Volume Fee";
            CheckError='Y';
            table.rows[7].cells[3].className = "headline11norredw";
            table.rows[7].cells[3].innerHTML = BulkRegGap;
        }
        else
        {
            table.rows[5].cells[3].className = "headline11norblackw"; 
            table.rows[5].cells[3].innerHTML = validatebulkregular;
            table.rows[7].cells[3].className = "headline11norblackw";
            table.rows[7].cells[3].innerHTML = BulkRegGap;
        }
    }
    if (validatebulkexc == 'Y')
    {
        table.rows[5].cells[4].className = "headline11norgreenw";
        table.rows[5].cells[4].innerHTML = "PASS";
        table.rows[7].cells[4].className = "headline11norgreenw";
        table.rows[7].cells[4].innerHTML = BulkExcGap;
        
    }    
    else 
    {
        if (validatebulkexc == 'N')
        {
            table.rows[5].cells[4].className = "headline11norredw";
            table.rows[5].cells[4].innerHTML = "Bulk Volume Fee";
            CheckError='Y';
            table.rows[7].cells[4].className = "headline11norredw";
            table.rows[7].cells[4].innerHTML = BulkExcGap;
        
        }
        else
        {
            table.rows[5].cells[4].className = "headline11norblackw";
            table.rows[5].cells[4].innerHTML = validatebulkexc;
            table.rows[7].cells[4].className = "headline11norblackw";
            table.rows[7].cells[4].innerHTML = BulkExcGap;
        }
    }
    if (validatetotbulk == 'Y')
    {
        table.rows[5].cells[5].className = "headline11norgreenw";
        table.rows[5].cells[5].innerHTML = "PASS";
        table.rows[7].cells[5].className = "headline11norgreenw";
        table.rows[7].cells[5].innerHTML = BulkTotal;
        
    }
    else 
    {
        if (validatetotbulk == 'N')
        {
            table.rows[5].cells[5].className = "headline11norredw";
            table.rows[5].cells[5].innerHTML = "Bulk Volume Fee";
            CheckError='Y';
            table.rows[7].cells[5].className = "headline11norredw";
            table.rows[7].cells[5].innerHTML = BulkTotal;
        }
        else 
        {
            table.rows[5].cells[5].className = "headline11norblackw"; 
            table.rows[5].cells[5].innerHTML = validatetotbulk;
            table.rows[7].cells[5].className = "headline11norblackw";
            table.rows[7].cells[5].innerHTML = BulkTotal;
        }
    }
 }

function sleep(milliSeconds){ 
var startTime = new Date().getTime(); // get the current time 
while (new Date().getTime() < startTime + milliSeconds); // hog cpu 
} 

 function WriteLeadTime(leadtstr)
   {
   var ErrorLead="";
    var LeadTimeGap="";
    var mainstr=leadtstr.split("<");
    var leadtime=mainstr[0];
    var validateleadtime='';
    var table = document.getElementById('tbl5');
    var tbl=document.getElementById('tbl3');
    var cmpleadtime = tbl.rows[2].cells[3].innerHTML.trim();
    if (tbl.rows[2].cells[4].innerHTML.trim() != '-')
      { 
      if (eval(cmpleadtime) < eval(tbl.rows[2].cells[4].innerHTML.trim()))
        cmpleadtime = tbl.rows[2].cells[4].innerHTML.trim();
      }
    table.rows[8].cells[6].innerHTML =leadtime;
    if(eval(leadtime) >= eval(cmpleadtime))
       {
       validateleadtime = 'Y';
       LeadTimeGap='0';
       }
    else
    {
       validateleadtime = 'N';
        LeadTimeGap=eval(cmpleadtime)-eval(leadtime);
    }  
    if (validateleadtime == 'Y')
    {
        table.rows[5].cells[6].className = "headline11norgreenw";
        table.rows[5].cells[6].innerHTML = "PASS";
        table.rows[7].cells[6].className = "headline11norgreenw";
        table.rows[7].cells[6].innerHTML = LeadTimeGap;
        ErrorLead="PASS";
            
    }
    else
    {
        table.rows[5].cells[6].className = "headline11norredw";
        table.rows[5].cells[6].innerHTML = "Short Notice Fee";
        //CheckError='Y';
        ErrorLead="Short Notice Fee";
        table.rows[7].cells[6].className = "headline11norredw";
        table.rows[7].cells[6].innerHTML = LeadTimeGap;
        
        
    }
    //sleep(3000);
   WriteErrorCode(ErrorLead);
   }


function WriteErrorCode(ErrorTime)
{

    var ErrorCode
    var ErrorText
    ErrorCode='';
    ErrorText='';
    
    var table = document.getElementById('tbl5');
    //alert(table.rows[5].cells[7].innerHTML);
    //ErrorCode='2AG,';
    //ErrorCode='2AG,';
    //ErrorCode='2AG,';
    //ErrorCode=table.rows[5].cells[6].innerHTML;
    //alert(table.rows[5].cells[6].innerHTML);
//    alert(ErrorTime);
    if (ErrorTime.length>4)
    {
        ErrorCode='2AG, ';
        ErrorText=ErrorTime+', ';
    }
    
    var curr_row;
    var i=0;
    var table1=document.getElementById("tbl1");
    
    
    
    if ((table.rows[5].cells[2].innerHTML.length>4) || (table.rows[5].cells[3].innerHTML.length>4) ||(table.rows[5].cells[4].innerHTML.length>4) || (table.rows[5].cells[5].innerHTML.length>4) || (table.rows[5].cells[5].innerHTML.length>4))
    {
        ErrorCode=ErrorCode+'2AJ, ';
    }
    
    for (curr_row = 0; curr_row < table1.rows.length ; curr_row++)
    {
    if((table1.rows[curr_row].cells[1].Id == '0') && i==0)
     {
        i=i+1;
        ErrorCode=ErrorCode+"2AI, ";
     }
        
    }
    var prt=document.getElementById("txtPortName").value;
    if (prt=="Non-Listed Port")
    {
        ErrorCode=ErrorCode+"2AH, ";
    }
    
    
    
    if ((table.rows[5].cells[2].innerHTML.length>4) || (table.rows[5].cells[2].innerHTML.length>4))
    {
        ErrorText=ErrorText + 'Pack Volume Fee, ';
    }
    
    if ((table.rows[5].cells[3].innerHTML.length>4) || (table.rows[5].cells[4].innerHTML.length>4) || (table.rows[5].cells[5].innerHTML.length>4))
    {
        ErrorText=ErrorText + 'Bulk Volume Fee, ';
    }
    //alert(ErrorText);
    //alert(ErrorCode);
    //ErrorCode=ErrorCode.subString(0,ErrorCode.length-2);
    //ErrorText=ErrorText.subString(0,ErrorText.length-2);
    
    i=0;
    for (curr_row = 0; curr_row < table1.rows.length ; curr_row++)
    {
    if((table1.rows[curr_row].cells[1].Id == '0') && i==0)
     {
        i=i+1;
        ErrorText=ErrorText+"Non-Listed Product/Article, ";
     }
        
    }
    
    //var prt=document.getElementById("txtPortName").value;
    if (prt=="Non-Listed Port")
    {
        ErrorText=ErrorText+"Non-Listed Port, ";
    }
    
    
    
    
    var ErrCode=document.getElementById("lblErrorCode");
    var ErrString=document.getElementById("lblErrorString");
    //alert(ErrCode);
    //alert(ErrString);
    if (ErrorCode.length>2)
    {
    ErrorCode=ErrorCode.substring(0,ErrorCode.length-2);
    ErrCode.innerHTML='<span style="font-weight:bold;">Reason Code(s)</span>(In Order):  '+'<span style="font-size:14px; font-weignt:bold;">'+ErrorCode.substring(0,4)+'</span>'+'<span style="font-size:11px;">'+ErrorCode.substring(4,ErrorCode.length)+'</span>';
    ErrorText=ErrorText.substring(0,ErrorText.length-2);
    ErrString.innerHTML='<span style="font-weight:bold;">Reason Text(s)</span>(In Order):  '+ErrorText;
    }
    else
    {
        ErrCode.innerHTML='';
        ErrString.innerHTML='';
    }
    //return;
    
    
    
    
}





 function CheckLeadTime()
  {
    var portid = document.getElementById('drpPort').value;
    var deldate= document.getElementById('txtDate').value;
    var valuestr=deldate + "&" + portid;
	// URL to get data from server
	var requestUrl = "checkonport.aspx" + "?strSQL=" + encodeURIComponent(valuestr) ;
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp){
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = GetLeadTime;

		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
  }

  function GetLeadTime(){
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		 WriteLeadTime((XmlHttp.responseText).trim());
		    
		        return true;
		     }      
		else {
		    WriteLeadTime((XmlHttp.responseText).trim());
		    
		    return true;
		  }
		
		 }
		else{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		 }
	  }
  }

//---------------------------------------------------End function---------------------------------------------------
//-------------------------------------------function for dispaly to show unit--------------------------------------
  function CalculateUnit()
    {
     var result='';
     var d=document;
//     var quantity = d.getElementById('txtQuantity').value;
//     if(quantity == '')
//       quantity = 0;
     var pack = d.getElementById('drpPack').options[d.getElementById('drpPack').selectedIndex].text;
     if(document.getElementById("Op1").checked == true)
      {
      if(pack == 'Drum') result = quantity * 208;
      else  if(pack == 'Pail') result = quantity * 20;
      else if(pack == 'Cartridge') result =quantity * 12;
      else if(pack == 'Bulk-B') result =  quantity;
      else if(pack == 'Bulk-T') result =  quantity;
      d.getElementById('lblCalculate').innerHTML = formatdigit(result) + ' Ltr';
      }
      else if(document.getElementById("Op2").checked == true)
      {
      if(pack == 'Drum') result  = parseInt((quantity * 208)/3.7852);
      else if(pack == 'Pail') result =parseInt ((quantity * 20)/3.7852);
      else if(pack == 'Cartridge') result =parseInt ((quantity * 12)/3.7852);
      else if(pack == 'Bulk-B') result =  quantity;
      else if(pack == 'Bulk-T') result =  quantity;
      d.getElementById('lblCalculate').innerHTML = formatdigit(result) + ' USG';
      }
    }
    function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function ActivateQty(ctrl)
{
    var ch=document.getElementById(ctrl.id);
    var qty=document.getElementById(ctrl.id.replace('chk','Qty'));
    if (ch.checked==true)
    {
        qty.disabled=false;
    }
    else
    {
        qty.disabled=true;
        qty.value='';
        document.getElementById(ctrl.id.replace('chk','lbl')).innerHTML='';
    }
}


    function CalculateUnit_New(ctrl)
    {
     var result='';
     var d=document;
     //alert(d.getElementById(ctrl.id).value);
     var quantity = d.getElementById(ctrl.id).value;
     if(quantity == '')
       quantity = 0;
     var pack = Right(ctrl.id,1);
     if(document.getElementById("Op1").checked == true)
      {
      if(pack == 'D') result = quantity * 208;
      else  if(pack == 'P') result = quantity * 20;
      else if(pack == 'C') result =quantity * 12;
      else if(pack == 'B') result =  quantity;
      else if(pack == 'T') result =  quantity;
      d.getElementById(ctrl.id.replace('Qty','lbl')).innerHTML = formatdigit(result) + ' Ltr';
      }
      else if(document.getElementById("Op2").checked == true)
      {
      if(pack == 'D') result  = parseInt((quantity * 208)/3.7852);
      else if(pack == 'P') result =parseInt ((quantity * 20)/3.7852);
      else if(pack == 'C') result =parseInt ((quantity * 12)/3.7852);
      else if(pack == 'B') result =  quantity;
      else if(pack == 'T') result =  quantity;
      d.getElementById(ctrl.id.replace('Qty','lbl')).innerHTML = formatdigit(result) + ' USG';
      }
    }
    
//----------------------------------------End funtion----------------------------------------------------------------
//----------------------------------------Function change region ---------------------------------------------------- 
  function CheckRegion() 
   {
    var strvalue;
	strvalue="Region&" + document.getElementById('drpRegion').value;
    // URL to get data from server
	var requestUrl = "Data.aspx" + "?strvalue=" + encodeURIComponent(strvalue);
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = CheckRegionDetail;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		//Sends the request to server
		XmlHttp.send(null);		
	 }
}

function CheckRegionDetail()
{
// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        changeRegiondetail(XmlHttp.responseText);
		        return true;
		         }      
		else {
		    changeRegiondetail(XmlHttp.responseText);
		    return true;
      		 }
		 }
		else
		{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		}
	  }
}
function changeRegiondetail(strstring)
 {
  var mainstr=strstring.split("<");
  var main=mainstr[0].trim().split("$");
  var mainstr1=main[0].trim().split("%");
  var mainstr2=mainstr1[0].trim().split("&");
  var mainstr3=mainstr1[1].trim().split("&");
  var country = document.getElementById('drpCountry');
  for (var i = country.length - 1; i>=0; i--) 
   {
    country.remove(i);
   }
  for(i=0;i< mainstr3.length-1 ;i++)
   {
   var newOpt = new Option(mainstr3[i], mainstr2[i]);
   var selLength = i;
   country.options[selLength] = newOpt;
   }   
  var port = document.getElementById('drpPort');
  var i;
  for (var i = port.length - 1; i>=0; i--)
   {
    port.remove(i);
   }
  for(var i=0;i<mainstr2.length -1;i++)
   {
     var newOpt = new Option(mainstr3[i+1], mainstr2[i+1]);
     var selLength = i;
     country.options[selLength] = newOpt;
   }
    //country.options[1].selected = mainstr3[0];
  var mainstr4=main[1].trim().split("%");
  var mainstr5=mainstr4[0].trim().split("&");
  var mainstr6=mainstr4[1].trim().split("&");
  var port = document.getElementById('drpPort');
  for (var i = port.length - 1; i>=0; i--)
   {
    port.remove(i);
   }
    for(var i=0;i<mainstr5.length-1 ;i++)
    {
    var newOpt = new Option(mainstr6[i+1], mainstr5[i+1]);
    var selLength = i;
    port.options[selLength] = newOpt;
    }
    //port.options[1].selecteditem = mainstr6[0];
    CheckPortCalculate()
 }
function CheckRegion1(str)
 {
  CheckRegion();
  document.getElementById('drpCountry').value=str;
}
//-----------------------------------End function-----------------------------------------------------------------
//----------------------------------function for change country---------------------------------------------------
function CheckCountry()
 {
   var strvalue;
	strvalue="Country&" + document.getElementById('drpCountry').value;
   // URL to get data from server
	var requestUrl = "Data.aspx" + "?strvalue=" + encodeURIComponent(strvalue);
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = CheckCountryDetail;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		//Sends the request to server
		XmlHttp.send(null);		
	 }
}

function CheckCountryDetail()
{
// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		
		        changeCountrydetail(XmlHttp.responseText);
		        return true;
		         }      
		else {
		
		    changeCountrydetail(XmlHttp.responseText);
		    return true;
      		 }
		 }
		else
		{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		}
	  }
    }
 function changeCountrydetail(strstring)
  {
   var mainstr=strstring.split("<");
   var mainstr1=mainstr[0].trim().split("%");
   var mainstr2=mainstr1[0].trim().split("&");
   var mainstr3=mainstr1[1].trim().split("&");
   var port = document.getElementById('drpPort');
   for (var i = port.length - 1; i>=0; i--)
    {
    port.remove(i);
    }
   for(var i=0;i<mainstr3.length-1 ;i++)
    {
    var newOpt = new Option(mainstr3[i+1], mainstr2[i+1]);
    var selLength = i;
    port.options[selLength] = newOpt;
    }
    //port.options[1].selected = mainstr3[0];
    CheckPortCalculate()
 }
 
 function CheckCountry1(str)
  {
  CheckCountry();
  document.getElementById('drpPort').value=str;
  }
//---------------------------------------------End function---------------------------------------------------------
//------------------------------------Function for change port------------------------------------------------------
function CheckPortCalculate()
  {
    clearall1();
	var strvalue;
	strvalue=document.getElementById('drpPort').value;
	var oRow;
    var curr_row;
    if(document.getElementById('tbl1').rows.length > 0)
    {
    for (curr_row = 0; curr_row < document.getElementById('tbl1').rows.length ; curr_row++)
     {
         oRow = document.getElementById('tbl1').rows[curr_row];
         strvalue = strvalue + '&' + oRow.cells[1].Id ;
         strvalue = strvalue + '&' + oRow.cells[3].Id ;
     }
    }
    GetBreakUp();
	// URL to get data from server
	//alert(strvalue);
	var requestUrl = "checkPortDetail.aspx" + "?strvalue=" + encodeURIComponent(strvalue);
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = GetPortCalculate;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		//Sends the request to server
		XmlHttp.send(null);		
	 }
}
function GetPortCalculate(){
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        return true;
		         }      
		else {
		    WritePortCalculate((XmlHttp.responseText).trim());
		    return true;
      		 }
		 }
		else
		{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		}
	  }
  }
    function  WritePortCalculate(strstring)
     {
     //alert(strstring);
       var mainstr=strstring.split("<");
       var main=mainstr[0].trim().split("~");
       var mainstr1=main[0].trim().split("&");
       var oRow;
       var unit;
       if(document.getElementById("Op1").checked == true)
        unit=1;
       else if(document.getElementById("Op2").checked == true)
        unit=3.7852;
      var j=document.getElementById("txtOrderDate");
      j.value=mainstr1[13];
      
      document.getElementById("txtEarliestDeliveryDate").value=mainstr1[14];
      document.getElementById("txtHidden10").value=mainstr1[16];
      var lblEarliest=document.getElementById("lblEarliestDeliveryDate");
      var txtHidden=document.getElementById("txtHidden");
      
      //alert(mainstr1[15]);
//      if (mainstr1[15].length >3)
//      {
//        //alert(mainstr1[15]);
//        lblEarliest.title=mainstr1[15];
//        lblEarliest.style.display='block';
//      }
//      else
//      {
//        lblEarliest.title='';
//        lblEarliest.style.display='none';
//      }
      //alert(mainstr1[13]);
      
      oRow = document.getElementById('tbl3').rows[2];
      oRow.cells[1].innerHTML = mainstr1[1];
      oRow.cells[3].innerHTML = mainstr1[6];
     
      oRow = document.getElementById('tbl3').rows[4];
      oRow.cells[1].innerHTML = mainstr1[2];
      oRow.cells[3].innerHTML = mainstr1[4];
        
      oRow = document.getElementById('tbl3').rows[6];
      oRow.cells[1].innerHTML = mainstr1[0];
      oRow.cells[3].innerHTML = formatdigit(Math.ceil(eval(mainstr1[9])/unit));
     
      oRow = document.getElementById('tbl3').rows[8];
      oRow.cells[1].innerHTML =formatdigit(Math.ceil(eval(mainstr1[7])/unit));
      oRow.cells[3].innerHTML = formatdigit(Math.ceil(eval(mainstr1[10])/unit));
     
      oRow = document.getElementById('tbl3').rows[10];
      oRow.cells[1].innerHTML = formatdigit(Math.ceil(eval(mainstr1[8])/unit));
      oRow.cells[3].innerHTML = formatdigit(Math.ceil(eval(mainstr1[11])/unit));
     
      oRow = document.getElementById('tbl3').rows[12];
      oRow.cells[1].innerHTML = mainstr1[3];
      oRow.cells[3].innerHTML = formatdigit(Math.ceil(eval(mainstr1[12])/unit));
    /*  for (curr_row = 0; curr_row < document.getElementById('tbl1').rows.length ; curr_row++)
        {
        var main1=main[curr_row + 1].split("&");
        oRow = document.getElementById('tbl1').rows[curr_row];
        if(main1[0].trim() == "N")
          {
          oRow.cells[4].className="headline11norred";
          }
        else if(main1[0].trim() == "Y")
          {
          oRow.cells[4].className="headline11norgreen";
           }
        oRow.cells[4].innerHTML = main1[0];
         }
    addtocalculate();
    CheckExceponDelete();*/
    clearall1();
 }








function ResetEarliestDeliveryDate(FLT)
  {
    var strvalue;
	strvalue="REDD|"+document.getElementById('drpPort').value+"|"+FLT;
	//alert(strvalue);
	var requestUrl = "CheckDeliveryDateForHoliday.aspx" + "?strvalue=" + encodeURIComponent(strvalue);
    CreateXmlHttp();	
	if(XmlHttp)
	{
		XmlHttp.onreadystatechange = GetEDD;
		XmlHttp.open("GET", requestUrl,  true);		
		XmlHttp.send(null);		
	 }
}
function GetEDD(){
	if(XmlHttp.readyState == 4){
		if(XmlHttp.status == 200){		
		if((((XmlHttp.responseText).trim()).length)==0){
		        return true;
		         }      
		else {
		    WriteEDD((XmlHttp.responseText).trim());
		    return true;
      		 }
		 }
		else
		{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		}
	  }
  }
    function  WriteEDD(strstring)
     {
     //alert(strstring);
       var mainstr=strstring.split("|");
       document.getElementById("txtEarliestDeliveryDate").value=mainstr[0];
      
      var lblEarliest=document.getElementById("lblEarliestDeliveryDate");
      var txtHidden=document.getElementById("txtHidden");
     }































 //-----------------------------------------End function---------------------------------------------------------
 //--------------------------------------Create XMLHTTP object---------------------------------------------------
//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp(){
	//Creating object of XMLHTTP in IE
	try{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	   }
	catch(e)
	{
		try{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		   } 
		catch(oc){
			XmlHttp = null;
		   }
	   }	   
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined"){
		XmlHttp = new XMLHttpRequest();
	  }
  }
  //-----------------------------------End funtion----------------------------------------------------------------
  //-----------------------------------set the value with ','-----------------------------------------------------

  function changedigit(strval)
   {
    //alert("CD"+strval);
     var str=new String(strval);
     var cngstr = str.replace(/\D/g,'');
     return (cngstr);
   }
  function formatdigit(strValue)
			{
	//		    alert("FD"+strValue);
				strValue = strValue.toString().replace(/\$|\,/g,'');
				//alert(strValue);
				dblValue = parseFloat(strValue);
				dblValue = Math.floor(dblValue*100);
				intCents = dblValue%100;
				strCents = intCents.toString();
				dblValue = Math.floor(dblValue/100).toString();
				strQuot="0";
				if(intCents<10)
					strCents = "0" + strCents;
				for(var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
					dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
					dblValue.substring(dblValue.length-(4*i+3));
					if(dblValue =="0") 
					  return (strQuot);
					else
				      return (dblValue);}
  //-----------------------------------------------function for clear all button----------------------------------
   function clearall()
       {
       var table1 = document.getElementById("tbl1");
       var table2 = document.getElementById("tbl5");
       var table3 = document.getElementById("tbl3");
       var table = document.getElementById("tbl4");
       
       
       if (table.rows.length > 0 || table1.rows.length > 0)
       {
        if(confirm('Are you sure to clear all data') == true)
       {
       document.getElementById("TxtHidden1").value='';
       
        var errorCode=document.getElementById("lblErrorCode");
       var errorText=document.getElementById("lblErrorString");
       
       errorCode.innerHTML='';
       errorText.innerHTML='';
       
      if (table.rows.length > 0)
        { 
         for(var i = table.rows.length; i > 0;i--)
           {
            table.deleteRow(i -1);
           }
        }
        //alert("Hi1");
       if (table1.rows.length > 0)
        { 
         for(var i = table1.rows.length; i > 0;i--)
          {
           table1.deleteRow(i -1);
          }
         table2.rows[5].cells[2].innerHTML = '';
         table2.rows[5].cells[3].innerHTML = '';
         table2.rows[5].cells[4].innerHTML = '';
         table2.rows[5].cells[5].innerHTML = '';
         table2.rows[5].cells[6].innerHTML = '';
         table2.rows[5].cells[7].innerHTML = '';
         table2.rows[7].cells[2].innerHTML = '';
         table2.rows[7].cells[3].innerHTML = '';
         table2.rows[7].cells[4].innerHTML = '';
         table2.rows[7].cells[5].innerHTML = '';
         table2.rows[7].cells[6].innerHTML = '';
         table2.rows[8].cells[2].innerHTML = '';
         table2.rows[8].cells[3].innerHTML = '';
         table2.rows[8].cells[4].innerHTML = '';
         table2.rows[8].cells[5].innerHTML = '';
         table2.rows[8].cells[6].innerHTML = '';
         table3.rows[2].cells[4].innerHTML = '-';
         table3.rows[6].cells[4].innerHTML = '-';
         table3.rows[10].cells[4].innerHTML = '-';
        }
      }
    }
   }
   
   function clearall1()
       {
       var table1 = document.getElementById("tbl1");
       var table2 = document.getElementById("tbl5");
       var table3 = document.getElementById("tbl3");
       var table = document.getElementById("tbl4");
       document.getElementById("TxtHidden1").value='';
       
       var errorCode=document.getElementById("lblErrorCode");
       var errorText=document.getElementById("lblErrorString");
       
       errorCode.innerHTML='';
       errorText.innerHTML='';
       if (table.rows.length > 0 || table1.rows.length > 0)
       {
        
      if (table.rows.length > 0)
        { 
         for(var i = table.rows.length; i > 0;i--)
           {
            table.deleteRow(i -1);
           }
        }
        //alert("Hi1");
       if (table1.rows.length > 0)
        { 
         for(var i = table1.rows.length; i > 0;i--)
          {
           table1.deleteRow(i -1);
          }
         table2.rows[5].cells[2].innerHTML = '';
         table2.rows[5].cells[3].innerHTML = '';
         table2.rows[5].cells[4].innerHTML = '';
         table2.rows[5].cells[5].innerHTML = '';
         table2.rows[5].cells[6].innerHTML = '';
         table2.rows[5].cells[7].innerHTML = '';
         table2.rows[7].cells[2].innerHTML = '';
         table2.rows[7].cells[3].innerHTML = '';
         table2.rows[7].cells[4].innerHTML = '';
         table2.rows[7].cells[5].innerHTML = '';
         table2.rows[7].cells[6].innerHTML = '';
         table2.rows[8].cells[2].innerHTML = '';
         table2.rows[8].cells[3].innerHTML = '';
         table2.rows[8].cells[4].innerHTML = '';
         table2.rows[8].cells[5].innerHTML = '';
         table2.rows[8].cells[6].innerHTML = '';
         table3.rows[2].cells[4].innerHTML = '-';
         table3.rows[6].cells[4].innerHTML = '-';
         table3.rows[10].cells[4].innerHTML = '-';
        }
      }
    }
   
   
   
 //------------------------------------------------End function--------------------------------------------------

  
//-----------------------------------change the value in unit----------------------------------------------------

function changeunitusg()
   {
    var unit;
    unit=3.7852;
    if (document.getElementById("txtHidden2").value!="USG")
    {
    document.getElementById("txtHidden2").value="USG";
    var tbl =document.getElementById('tbl3');
    var tbl1 =document.getElementById('tbl1');
    var tbl2 =document.getElementById('tbl4');
    var tbl3 =document.getElementById('tbl5');
    var curr_row;
    tbl.rows[8].cells[1].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[8].cells[1].innerHTML))/unit));
    tbl.rows[10].cells[1].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[10].cells[1].innerHTML))/unit));
    tbl.rows[6].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[6].cells[3].innerHTML))/unit));
    tbl.rows[8].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[8].cells[3].innerHTML))/unit));
    tbl.rows[10].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[10].cells[3].innerHTML))/unit));
    tbl.rows[12].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[12].cells[3].innerHTML))/unit));
    if(tbl.rows[6].cells[4].innerHTML != '-')
       tbl.rows[6].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[6].cells[4].innerHTML))/unit));
    if(tbl.rows[10].cells[4].innerHTML != '-')
       tbl.rows[10].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[10].cells[4].innerHTML))/unit));
    if (tbl1.rows.length > 0 )
       {
       for (curr_row = 0; curr_row < tbl1.rows.length ; curr_row++)
         {
          if((tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk-T') || (tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk-B') ||(tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk'))
            {
                document.getElementById('txtQty'+tbl1.rows[curr_row].cells[2].Id.replace('.','')).value=formatdigit(Math.ceil(changedigit(document.getElementById('txtQty'+tbl1.rows[curr_row].cells[2].Id.replace('.','')).value)/unit));
                document.getElementById('label'+tbl1.rows[curr_row].cells[2].Id.replace('.','')).innerHTML="USG";
              //tbl1.rows[curr_row].cells[2].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl1.rows[curr_row].cells[2].innerHTML))/unit));
             }
          }
        }
     if (tbl2.rows.length > 0 )
       {
       for (curr_row = 0; curr_row < tbl2.rows.length ; curr_row++)
         {
          if(tbl2.rows[curr_row].cells[1].innerHTML != '-' && tbl2.rows[curr_row].cells[1].innerHTML != 'N/A')
             tbl2.rows[curr_row].cells[1].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl2.rows[curr_row].cells[1].innerHTML))/unit));
          if(tbl2.rows[curr_row].cells[2].innerHTML != '-' && tbl2.rows[curr_row].cells[2].innerHTML != 'N/A')
             tbl2.rows[curr_row].cells[2].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl2.rows[curr_row].cells[2].innerHTML))/unit));
          if(tbl2.rows[curr_row].cells[3].innerHTML != '-' && tbl2.rows[curr_row].cells[3].innerHTML != 'N/A')
             tbl2.rows[curr_row].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl2.rows[curr_row].cells[3].innerHTML))/unit));
          if(tbl2.rows[curr_row].cells[4].innerHTML != '-' && tbl2.rows[curr_row].cells[4].innerHTML != 'N/A')
             tbl2.rows[curr_row].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl2.rows[curr_row].cells[4].innerHTML))/unit));
          }
        if(tbl3.rows[7].cells[2].innerHTML != '-' && tbl3.rows[7].cells[2].innerHTML != 'N/A')
          tbl3.rows[7].cells[2].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[7].cells[2].innerHTML))/unit));
        if(tbl3.rows[7].cells[3].innerHTML != '-' && tbl3.rows[7].cells[3].innerHTML != 'N/A')
          tbl3.rows[7].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[7].cells[3].innerHTML))/unit));
        if(tbl3.rows[7].cells[4].innerHTML != '-' && tbl3.rows[7].cells[4].innerHTML != 'N/A')
         tbl3.rows[7].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[7].cells[4].innerHTML))/unit));
        if(tbl3.rows[7].cells[5].innerHTML != '-' && tbl3.rows[7].cells[5].innerHTML != 'N/A')
         tbl3.rows[7].cells[5].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[7].cells[5].innerHTML))/unit));
        
        if(tbl3.rows[8].cells[2].innerHTML != '-' && tbl3.rows[8].cells[2].innerHTML != 'N/A')
          tbl3.rows[8].cells[2].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[8].cells[2].innerHTML))/unit));
        if(tbl3.rows[8].cells[3].innerHTML != '-' && tbl3.rows[8].cells[3].innerHTML != 'N/A')
          tbl3.rows[8].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[8].cells[3].innerHTML))/unit));
        if(tbl3.rows[8].cells[4].innerHTML != '-' && tbl3.rows[8].cells[4].innerHTML != 'N/A')
         tbl3.rows[8].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[8].cells[4].innerHTML))/unit));
        if(tbl3.rows[8].cells[5].innerHTML != '-' && tbl3.rows[8].cells[5].innerHTML != 'N/A')
         tbl3.rows[8].cells[5].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[8].cells[5].innerHTML))/unit));
        }
       }
     //CalculateUnit();
   }
  function changeunitltr()
     {
      var unit;
      unit=3.7852;
      if (document.getElementById("txtHidden2").value!="LTR")
      {
      document.getElementById("txtHidden2").value="LTR";
      var tbl =document.getElementById('tbl3');
      var tbl1 =document.getElementById('tbl1');
      var tbl2 =document.getElementById('tbl4');
      var tbl3 =document.getElementById('tbl5');
      var curr_row;

      tbl.rows[8].cells[1].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[8].cells[1].innerHTML))*unit));
      tbl.rows[10].cells[1].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[10].cells[1].innerHTML))*unit));
      tbl.rows[6].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[6].cells[3].innerHTML))*unit));
      tbl.rows[8].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[8].cells[3].innerHTML))*unit));
      tbl.rows[10].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[10].cells[3].innerHTML))*unit));
      tbl.rows[12].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[12].cells[3].innerHTML))*unit));
      if(tbl.rows[6].cells[4].innerHTML != '-' && tbl.rows[6].cells[4].innerHTML != 'N/A')
        tbl.rows[6].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[6].cells[4].innerHTML))*unit));
      if(tbl.rows[10].cells[4].innerHTML != '-' && tbl.rows[10].cells[4].innerHTML != 'N/A')
        tbl.rows[10].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl.rows[10].cells[4].innerHTML))*unit));
      if (tbl1.rows.length > 0 )
          {
           for (curr_row = 0; curr_row < tbl1.rows.length ; curr_row++)
            {
            if(tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk-T' || tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk-B' || tbl1.rows[curr_row].cells[3].innerHTML == 'Bulk')
              {
               document.getElementById('txtQty'+tbl1.rows[curr_row].cells[2].Id.replace('.','')).value=formatdigit(Math.ceil(changedigit(document.getElementById('txtQty'+tbl1.rows[curr_row].cells[2].Id.replace('.','')).value)*unit));
               document.getElementById('label'+tbl1.rows[curr_row].cells[2].Id.replace('.','')).innerHTML="Lt.";
               //tbl1.rows[curr_row].cells[2].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl1.rows[curr_row].cells[2].innerHTML))*unit));
              //formatdigit(document.getElementById('txtQty'+document.getElementById('tbl1').rows[ctrl].cells[2].Id.replace('.','')).value)
              }
             }
           }
      if (tbl2.rows.length > 0 )
          {
          for (curr_row = 0; curr_row < tbl2.rows.length ; curr_row++)
             {
             if(tbl2.rows[curr_row].cells[1].innerHTML != '-' && tbl2.rows[curr_row].cells[1].innerHTML != 'N/A')
               tbl2.rows[curr_row].cells[1].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl2.rows[curr_row].cells[1].innerHTML))*unit));
             if(tbl2.rows[curr_row].cells[2].innerHTML != '-' && tbl2.rows[curr_row].cells[2].innerHTML != 'N/A')
               tbl2.rows[curr_row].cells[2].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl2.rows[curr_row].cells[2].innerHTML))*unit));
             if(tbl2.rows[curr_row].cells[3].innerHTML != '-' && tbl2.rows[curr_row].cells[3].innerHTML != 'N/A')
               tbl2.rows[curr_row].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl2.rows[curr_row].cells[3].innerHTML))*unit));
             if(tbl2.rows[curr_row].cells[4].innerHTML != '-' && tbl2.rows[curr_row].cells[4].innerHTML != 'N/A')
               tbl2.rows[curr_row].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl2.rows[curr_row].cells[4].innerHTML))*unit));
              }
          if(tbl3.rows[7].cells[2].innerHTML != '-' && tbl3.rows[7].cells[2].innerHTML != 'N/A')
            tbl3.rows[7].cells[2].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[7].cells[2].innerHTML))*unit));
          if(tbl3.rows[7].cells[3].innerHTML != '-' && tbl3.rows[7].cells[3].innerHTML != 'N/A')
            tbl3.rows[7].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[7].cells[3].innerHTML))*unit));
          if(tbl3.rows[7].cells[4].innerHTML != '-' && tbl3.rows[7].cells[4].innerHTML != 'N/A')
            tbl3.rows[7].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[7].cells[4].innerHTML))*unit));
          if(tbl3.rows[7].cells[5].innerHTML != '-' && tbl3.rows[7].cells[5].innerHTML != 'N/A')
            tbl3.rows[7].cells[5].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[7].cells[5].innerHTML))*unit));
        
          if(tbl3.rows[8].cells[2].innerHTML != '-' && tbl3.rows[8].cells[2].innerHTML != 'N/A')
            tbl3.rows[8].cells[2].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[8].cells[2].innerHTML))*unit));
          if(tbl3.rows[8].cells[3].innerHTML != '-' && tbl3.rows[8].cells[3].innerHTML != 'N/A')
            tbl3.rows[8].cells[3].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[8].cells[3].innerHTML))*unit));
          if(tbl3.rows[8].cells[4].innerHTML != '-' && tbl3.rows[8].cells[4].innerHTML != 'N/A')
            tbl3.rows[8].cells[4].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[8].cells[4].innerHTML))*unit));
          if(tbl3.rows[8].cells[5].innerHTML != '-' && tbl3.rows[8].cells[5].innerHTML != 'N/A')
            tbl3.rows[8].cells[5].innerHTML =formatdigit(Math.ceil(eval(changedigit(tbl3.rows[8].cells[5].innerHTML))*unit));
          }
          }
      //CalculateUnit();
    }

//-----------------------------------End of section---------------------------------------------------------------

function SelectPRD()
 {
   var strvalue;
	strvalue="Product&" + document.getElementById('drpPort').value;
   // URL to get data from server
	var requestUrl = "Data.aspx" + "?strvalue=" + encodeURIComponent(strvalue);
    CreateXmlHttp();	
    
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
	    XmlHttp.onreadystatechange = SelectProductDetail;
		XmlHttp.open("GET", requestUrl, true);	
		//alert(XmlHttp.responseText);	
		XmlHttp.send(null);		
	 }
}

function SelectProductDetail()
{
// To make sure receiving response data from server is completed
    if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		
		        PopulateProductDetail(XmlHttp.responseText);
		        return true;
		         }      
		else {
		    //alert(XmlHttp.responseText);
		    PopulateProductDetail(XmlHttp.responseText);
		    return true;
      		 }
		 }
		else
		{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		}
	  }
    }
 function PopulateProductDetail(strstring)
  {
   //alert(strstring);
   var InnerScript="";
   var mainstr=strstring.split("|");
   InnerScript=InnerScript+"<table width='97%' border='0' cellspacing='0' cellpadding='0'>";
   for (var i=0;i<mainstr.length-1;i++)
   {
        if (i%2==0)
        {
            InnerScript=InnerScript+"<tr class='subheadR2'>";
            var mainstr1=mainstr[i].split("^");
            //InnerScript=InnerScript+"<td width='8%' style='padding-left:5px;' align='left' onmouseover='ClosePopup_OnClick();'></td>";
            //alert(mainstr1[4]);
            if (mainstr1[2] == 2)
            {
            
                InnerScript=InnerScript+"<td width='58%' class='line3g11' align='left' onmouseover='ClosePopup_OnClick();'><font color='red'><label id='prod"+mainstr1[0]+"' title='" +mainstr1[4]+"'>"+mainstr1[1]+"</label></font></td>";
            }
            else
            {
                InnerScript=InnerScript+"<td width='56%' class='line3g11' align='left' onmouseover='ClosePopup_OnClick();'><label id='prod"+mainstr1[0]+"' title='" +mainstr1[4]+"'>"+mainstr1[1]+"</label></td>";
            }
            if (mainstr1[3].indexOf(",") == -1)
            {
                InnerScript=InnerScript+"<td width='13%' class='line3g11' align='Right' onmouseover='ClosePopup_OnClick();'><label id='lbl"+mainstr1[0]+"' onclick='ClosePopup_OnClick();'>"+mainstr1[3]+"</label><input type='checkbox' id='chk"+mainstr1[0]+"' name='chkprd' value='"+mainstr1[0]+"' onclick='ClosePopup_OnClick();CheckBulkType(this);' /></td>";
            }
            else
            {
                InnerScript=InnerScript+"<td width='15%' class='line3g11' align='Right'><img src='images/arrow_bl_right1.gif' id='A"+mainstr1[0]+"' title='"+mainstr1[3]+"' onmouseover='JavaScript:CallDist(this);'/></td>";
            }
            if (i == 0)
            {
                InnerScript=InnerScript+"<td id='idTD' width='28%' style='padding-left:5px;' align='left' rowspan='"+mainstr.length+4+"'><div align='left' height='100%' id='divHero'></div></td>";
            }
            InnerScript=InnerScript+"</tr>";
        }
        else
        {
            InnerScript=InnerScript+"<tr class='subheadR1'>";
            var mainstr1=mainstr[i].split("^");
            //InnerScript=InnerScript+"<td width='8%' style='padding-left:5px;' align='left' onmouseover='ClosePopup_OnClick();'></td>";
            if (mainstr1[2] == 2)
            {
                InnerScript=InnerScript+"<td width='58%' class='line3g11' align='left' onmouseover='ClosePopup_OnClick();'><font color='red'><label id='prod"+mainstr1[0]+"' title='" +mainstr1[4]+"' onclick='ClosePopup_OnClick();'>"+mainstr1[1]+"</label></font></td>";
            }
            else
            {
                InnerScript=InnerScript+"<td width='56%' class='line3g11' align='left' onmouseover='ClosePopup_OnClick();'><label id='prod"+mainstr1[0]+"' title='" +mainstr1[4]+"' onclick='ClosePopup_OnClick();'>"+mainstr1[1]+"</label></td>";
            }
            if (mainstr1[3].indexOf(",") == -1)
            {
                InnerScript=InnerScript+"<td width='13%' class='line3g11' align='Right' onmouseover='ClosePopup_OnClick();'><label id='lbl"+mainstr1[0]+"' onclick='ClosePopup_OnClick();'>"+mainstr1[3]+"</label><input type='checkbox' id='chk"+mainstr1[0]+"' name='chkprd' value='"+mainstr1[0]+"' onclick='ClosePopup_OnClick();CheckBulkType(this);' /></td>";
            }
            else
            {
                InnerScript=InnerScript+"<td width='15%' class='line3g11' align='Right'><img src='images/arrow_bl_right1.gif' id='A"+mainstr1[0]+"' title='"+mainstr1[3]+"' onmouseover='JavaScript:CallDist(this);'/></td>";
            }
            if (i == 0)
            {
                InnerScript=InnerScript+"<td id='idTD' width='28%' style='padding-left:5px;' align='left' rowspan='"+mainstr.length+4+"'><div align='left' height='100%' id='divHero'></div></td>";
            }
            InnerScript=InnerScript+"</tr>";
        }
   }
   
   InnerScript=InnerScript+"<tr class='subheadR2'><td colspan='2'><H3><font color='blue'>Non Listed Products</font></H3></td></tr>";
   
   for (var j=1;j<=4;j++)
   {
       if (i%2==0)
            {
                InnerScript=InnerScript+"<tr class='subheadR2'>";
                InnerScript=InnerScript+"<td width='56%' class='line3g11' align='left' onmouseover='ClosePopup_OnClick();'><input type='text' id='text"+j+"' onclick='ClosePopup_OnClick();'/></td>";
                InnerScript=InnerScript+"<td width='15%' class='line3g11' align='Right'><img src='images/arrow_bl_right1.gif' id='ANL"+j+"' title='Bulk-B,Bulk-T,Drum,Pail,Any Pack' onmouseover='JavaScript:CallDist(this);'/></td></tr>";
            }
       else
            {
                InnerScript=InnerScript+"<tr class='subheadR1'>";
                InnerScript=InnerScript+"<td width='56%' class='line3g11' align='left' onmouseover='ClosePopup_OnClick();'><input type='text' id='text"+j+"' onclick='ClosePopup_OnClick();'/></td>";
                InnerScript=InnerScript+"<td width='15%' class='line3g11' align='Right'><img src='images/arrow_bl_right1.gif' id='ANL"+j+"' title='Bulk-B,Bulk-T,Drum,Pail,Any Pack' onmouseover='JavaScript:CallDist(this);'/></td></tr>";
            }
      i++;
  }
   InnerScript=InnerScript+"</table>";
   //alert(InnerScript);
       CallMe(InnerScript);
 }
function SetReminderForDefault(ctrl)
{
    
    var ch=document.getElementById(ctrl.id);
    var tbl=document.getElementById("tbl3");
    var txt=document.getElementById("TxtHidden1");
    var defaultModeOfTransport=tbl.rows[4].cells[3].innerHTML;
    //alert(defaultModeOfTransport);
    
    var BulkType='';
    var SelectedType='';
    if (ch.id.indexOf("chk")>-1)
    {
        BulkType=document.getElementById(ch.id.replace('chk','lbl')).innerHTML;
    }
    else
    {
        BulkType=document.getElementById('TDRS'+ch.id).innerHTML;
    }
    //alert(BulkType);
        if (BulkType == "Bulk")
        {
            BulkType="Bulk-T";
        }
        if (BulkType == "Bulk-T")
        {
            SelectedType="Truck";
        }
        else if (BulkType == "Bulk-B")
        {
            SelectedType="Barge";
        }
    //alert(SelectedType);
    if ((BulkType=="Bulk-B" || BulkType=="Bulk-T") && (defaultModeOfTransport!=SelectedType) && (txt.value.length<=0))
    {
        var yesno = confirm("Default vehicle for this port is " + defaultModeOfTransport +". But you have selected " + SelectedType +". Are you sure?");
        if (yesno==true)
        {
            txt.value="Yes";
        }
        else
        {
            txt.value="Yes";
            ctrl.checked=false;
        }
        
    }
    
    
    
    
    
    
}

function CheckBulkType(ctrl)
{
    var j;
    SetReminderForDefault(ctrl);
    var ch=document.getElementById(ctrl.id);
        var string='';
        //alert("HI1111");
	    var form1=document.getElementById('NSPopUP');
	    form1=form1.getElementsByTagName('*');
	    j=0;
	    //alert("HI");
	    for (var i=0; i<form1.length; i++) 
	    {
	        var j="";
            var myType = form1[i].type;
            //alert(myType);
            if (myType == 'checkbox')
            {
                if (form1[i].checked == true) 
                {           
                    var multiPkg=document.getElementById(form1[i].id.replace('chk','A'));
                    var siglePkg=document.getElementById(form1[i].id.replace('chk','lbl'));
                    //var string1=document.getElementById(form1[i].id.replace('chk','prod')).innerHTML+"_"+form1[i].value+"_";
                    if (multiPkg==null)
                    {
                        //string=string+string1+siglePkg.innerHTML+"_No_0"+"|";
                        string=string+siglePkg.innerHTML+"|";
                    }
                    else
                    {
                        var pkgArr=multiPkg.title.split(",");
                        for (var z=0;z<pkgArr.length;z++)
                        {
                            if (pkgArr[z].indexOf("_")>-1)
                            {
                                string=string+pkgArr[z].replace("_","")+"|";
                            }
                        }
                    }
                    j=j+1;
                }
             }
          else if (myType == 'text')
            {
                //alert("Text1");
                if (form1[i].value.length > 0) 
                {           
                    var multiPkg=document.getElementById(form1[i].id.replace('text','ANL'));
                   //var multiPkg=document.getElementById(form1[i].id);
                    //var string1=form1[i].value+"_"+0+"_";
                    if (multiPkg==null)
                    {
                    
                    }
                    else
                    {
                        var pkgArr=multiPkg.title.split(",");
                        for (var z=0;z<pkgArr.length;z++)
                        {
                            if (pkgArr[z].indexOf("_")>-1)
                            {
                                string=string+pkgArr[z].replace("_","")+"|";
                            }
                        }
                    }
                    j=j+1;
                 }
             }
          
          else if ((form1[i].title != '') && (isNaN(form1[i].title)==true) && (form1[i].id.indexOf("ANL")<=-1))
            {
                    var multiPkg=document.getElementById(form1[i].id);
                    //var string1=document.getElementById(form1[i].id.replace('A','prod')).innerHTML+"_"+form1[i].id.replace('A','')+"_";
                    if (multiPkg==null)
                    {
                    
                    }
                    else
                    {
                        var pkgArr=multiPkg.title.split(",");
                        for (var z=0;z<pkgArr.length;z++)
                        {
                            if (pkgArr[z].indexOf("_")>-1)
                            {
                                string=string+pkgArr[z].replace("_","")+"|";
                            }
                        }
                    }
                    j=j+1;
                
             }
        }
    
    
   // alert(string);

var table = document.getElementById("tbl1");
for (curr_row = 0; curr_row < table.rows.length ; curr_row++)
    {
    
        string=string+table.rows[curr_row].cells[3].innerHTML+'|';
    }

//alert(string);




var BulkType='';
    if (ch.id.indexOf("chk")>-1)
    {
        BulkType=document.getElementById(ch.id.replace('chk','lbl')).innerHTML;
    }
    else
    {
        BulkType=document.getElementById('TDRS'+ch.id).innerHTML;
    }
    
    if (BulkType == "Bulk")
    {
        BulkType="Bulk-T";
    }
    
    if (string.indexOf("Bulk-B")>-1)
    {
        document.getElementById("txtHidden3").value="Bulk-B";
    }
    else if (string.indexOf("Bulk-T")>-1)
    {
        document.getElementById("txtHidden3").value="Bulk-T";
    }
    //alert(BulkType);
        if (BulkType == "Bulk-T")
        {
            if (string.indexOf("Bulk-B")>-1)
            {
                alert("You have already selected barge for another bulk product. Accordingly, truck selection for any bulk product within same order is not possible.");
                ctrl.checked=false;
            }
        }
        
        
        
        else if (BulkType == "Bulk-B")
        {
            if (string.indexOf("Bulk-T")>-1)
            {
                alert("You have already selected truck for another bulk product. Accordingly, barge selection for any bulk product within same order is not possible.");
                ctrl.checked=false;
            }
        }

}













function ShowPort1()
 {
    //alert("showport1 start");
   var strvalue;
	strvalue=document.getElementById('txtPortName').value;
   // URL to get data from server
	var requestUrl = "PortMatch.aspx" + "?strvalue=" + encodeURIComponent(strvalue);
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = SelectPortMatch;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		//Sends the request to server
		XmlHttp.send(null);		
	 }
}

function SelectPortMatch()
{
// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        
		        PopulatePortMatch(XmlHttp.responseText);
		        return true;
		         }      
		else {
		
		    PopulatePortMatch(XmlHttp.responseText);
		    return true;
      		 }
		 }
		else
		{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		}
	  }
    }
    
    

 function PopulatePortMatch(strstring)
  {
  //alert(strstring);
   var InnerScript="";
   var lst=document.getElementById("lstPortName");
   lst.options.length = 0;
   
   var mainstr=strstring.split("|");
    //alert(mainstr.length-1);
   for (var i=0;i<mainstr.length-1;i++)
   {
    //alert(mainstr[i]);
   
    var mainstr1=mainstr[i].split("^");
    
    lst.options[lst.length] = new Option(mainstr1[1],mainstr1[0]);

   }
   //lst.focus();
   
   //alert(InnerScript);
       //CallMe(InnerScript);
 }










function GetBreakUp()
 {
    //alert("showport1 start");
   var strvalue;
	strvalue=document.getElementById('drpPort').value;
	rdd=document.getElementById("txtDate").value;
   // URL to get data from server
	var requestUrl = "GetLeadTimeBreakUp.aspx" + "?strvalue=" + encodeURIComponent(strvalue)+'|'+encodeURIComponent(rdd);
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = SelectLeadTimeBreakUp;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		//Sends the request to server
		XmlHttp.send(null);		
	 }
}

function SelectLeadTimeBreakUp()
{
// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        
		        PopulateLeadTimeBreakUp(XmlHttp.responseText);
		        return true;
		         }      
		else {
		
		    PopulateLeadTimeBreakUp(XmlHttp.responseText);
		    return true;
      		 }
		 }
		else
		{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		}
	  }
    }
    
    

 function PopulateLeadTimeBreakUp(strstring)
  {
  //alert(strstring);
   var InnerScript="";
   var lst=document.getElementById("lblBreakUp");
   //lst.options.length = 0;
   
   //alert(strstring);
   var mainstr=strstring.split("|");
   //alert(mainstr[0].substring(0,3));
   if (mainstr.length>1)
   {
   lst.innerHTML=mainstr[0];
   }
   else
   {
   lst.innerHTML="";
   }
   
   // alert(mainstr.length-1);
   
 }


function IsDeliveryDayIsHoliday()
 {
    //alert("showport1 start");
   var strvalue;
	strvalue=document.getElementById('drpPort').value;
	rdd=document.getElementById("txtDate").value;
   // URL to get data from server
	var requestUrl = "CheckDeliveryDateForHoliday.aspx" + "?strvalue=" + encodeURIComponent(strvalue)+'|'+encodeURIComponent(rdd);
    CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = SelectIsDeliveryDayIsHoliday;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);		
		//Sends the request to server
		XmlHttp.send(null);		
	 }
}

function SelectIsDeliveryDayIsHoliday()
{
// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if((((XmlHttp.responseText).trim()).length)==0){
		        
		        PopulateLeadTimeBreakUp(XmlHttp.responseText);
		        return true;
		         }      
		else {
		
		    PopulateIsDeliveryDayIsHoliday(XmlHttp.responseText);
		    return true;
      		 }
		 }
		else
		{
			alert("There was a problem retrieving data from the server. Please try again!" );
			return false;
		}
	  }
    }
    
    

 function PopulateIsDeliveryDayIsHoliday(strstring)
  {
  var rdd=document.getElementById("txtDate");
  //alert(strstring);
   //var InnerScript="";
   //var lst=document.getElementById("lblBreakUp");
   //lst.options.length = 0;
   
   //alert(strstring);
   var mainstr=strstring.split("|");
   //alert(mainstr[0].substring(0,3));
   if (mainstr.length>1)
   {
    if (mainstr[0]=="N")
        {
           //alert(rdd.value +" is " + mainstr[1] + " for this port. Please select some other day.");
           //rdd.value="dd MMM yyyy";
           //return false;
           GetBreakUp();
            return true;
        }
    else
        {
            GetBreakUp();
            return true;
            
        }
   }
   else
   {
   GetBreakUp()
    return true;
   }
   
   // alert(mainstr.length-1);
   
 }








































function setPort()
{
var sel=document.getElementById("lstPortName");
var port=document.getElementById("drpPort");



//port.value=sel.options[sel.selectedIndex].value;

document.getElementById("txtPortName").value=sel.options[sel.selectedIndex].text;

setSelectedIndex(port,sel.options[sel.selectedIndex].text);

var popD=document.getElementById("NSPopUP9");
if (popD != null)
{
    document.body.removeChild(popD);
}

}

function setSelectedIndex(s, v) {
//alert("Pass1");
for ( var i = 0; i < s.options.length; i++ ) {
if ( s.options[i].text == v ) {
s.options[i].selected = true;
//alert("Pass2");
CheckPortCalculate();
return;
}
}
}




































    function GenerateOrderList_Gan()
    
    {
         var j;
        var string='';
        //alert("HI1111");
	    var form1=document.getElementById('NSPopUP');
	    form1=form1.getElementsByTagName('*');
	    j=0;
	    //alert("HI");
	    for (var i=0; i<form1.length; i++) 
	    {
	        var j="";
            var myType = form1[i].type;
            //alert(myType);
            if (myType == 'checkbox')
            {
                if (form1[i].checked == true) 
                {           
                    var multiPkg=document.getElementById(form1[i].id.replace('chk','A'));
                    var siglePkg=document.getElementById(form1[i].id.replace('chk','lbl'));
                    var string1=document.getElementById(form1[i].id.replace('chk','prod')).innerHTML+"_"+form1[i].value+"_";
                    if (multiPkg==null)
                    {
                        //string=string+string1+siglePkg.innerHTML+"_No_0"+"|";
                        string=string+string1+siglePkg.innerHTML+"_"+document.getElementById(form1[i].id.replace('chk','prod')).title+"_0"+"|";
                    }
                    else
                    {
                        var pkgArr=multiPkg.title.split(",");
                        for (var z=0;z<pkgArr.length;z++)
                        {
                            if (pkgArr[z].indexOf("_")>-1)
                            {
                                string=string+string1+pkgArr[z].replace("_","")+"_"+document.getElementById(form1[i].id.replace('chk','prod')).title+"_0"+"|";
                            }
                        }
                    }
                    j=j+1;
                }
             }
          else if (myType == 'text')
            {
                //alert("Text1");
                if (form1[i].value.length > 0) 
                {           
                    var multiPkg=document.getElementById(form1[i].id.replace('text','ANL'));
                   //var multiPkg=document.getElementById(form1[i].id);
                    var string1=form1[i].value+"_"+0+"_";
                    if (multiPkg==null)
                    {
                    
                    }
                    else
                    {
                        var pkgArr=multiPkg.title.split(",");
                        for (var z=0;z<pkgArr.length;z++)
                        {
                            if (pkgArr[z].indexOf("_")>-1)
                            {
                                string=string+string1+pkgArr[z].replace("_","")+"_No_0"+"|";
                            }
                        }
                    }
                    j=j+1;
                 }
             }
          
          else if ((form1[i].title != '') && (isNaN(form1[i].title)==true) && (form1[i].id.indexOf("ANL")<=-1))
            {
                    var multiPkg=document.getElementById(form1[i].id);
                    var string1=document.getElementById(form1[i].id.replace('A','prod')).innerHTML+"_"+form1[i].id.replace('A','')+"_";
                    if (multiPkg==null)
                    {
                    
                    }
                    else
                    {
                        var pkgArr=multiPkg.title.split(",");
                        for (var z=0;z<pkgArr.length;z++)
                        {
                            if (pkgArr[z].indexOf("_")>-1)
                            {
                                string=string+string1+pkgArr[z].replace("_","")+"_"+document.getElementById(form1[i].id.replace('A','prod')).title+"_0"+"|";
                            }
                        }
                    }
                    j=j+1;
                
             }
        }
        //alert(string);
        PopulateTable(string);
        closePopUp();
    }
    
    function GoToList(e)
    {
//if (e.value == '') { e.value='-- Enter & Select Name --'; }" onfocus="if(e.value == '-- Enter & Select Name --') { e.value=''; }
//        var pName=document.getElementById("txtPortName");
//        var portname=document.getElementById("txtPortName").value;
//        var divId=document.getElementById("lstPortName");
//        var popDIv=document.getElementById("NSPopUP9");
//        //alert("Hi Out");
//        var top;
//        var innerHTML;
//        var left;
//        
//        //alert(window.event.keyCode);
//        
//        if (e.which)
//        {        
//            if (e.which == 40)
//            {
//                alert("DOwn Key Pressed");
//                if (popD != null)
//                {
//                    divId.setfocus;
//                    return false;
//                }   
//            }
//        }
//        else if(window.event)
//        {
//           if (window.event.keyCode == 40)
//            {
//                alert("DOwn Key Pressed");
//                if (popDIv != null)
//                {
//                    
//                    divId.setfocus;
//                    return false;
//                }   
//            }
//        }
    }
    
    
    
    
    
    
    
    
    function FindEnter(e)
    {
    var keyPressed = e.which || e.keyCode;

        if (keyPressed == 13)
            {
                setPort();
            }
        else if (keyPressed == 38)
            {
                //alert(document.getElementById("lstPortName").selectedIndex);
                if (document.getElementById("lstPortName").selectedIndex<=0)
                    {
                        document.getElementById('txtPortName').focus();
                    }
            }
        
    
    }
    
    function ShowPort(e)
    {
       
        //alert("Hi 1");
//        evt = e || window.event;
//  var keyPressed = evt.which || evt.keyCode;

        var pName=document.getElementById("txtPortName");
        var portname=document.getElementById("txtPortName").value;
        var divId=document.getElementById("lstPortName");
        var popDIv=document.getElementById("NSPopUP9");
        //alert("Hi Out");
        var top;
        var innerHTML;
        var left;
        
        //alert(window.event.keyCode);
  var keyPressed = e.which || e.keyCode;
        if (keyPressed == 40)
            {
                //alert("DOwn Key Pressed");
                if ((popDIv != null) && (divId.options.length>0))
                {
                    
                    divId.focus();
                    var i=divId.options[0].selected;
                    return false;
                }   
            }
        if (portname.length >= 1)
        {
        
        if (popDIv==null)
            {
            
                innerHTML="<select size='5' name='lstPortName' ID='lstPortName' Style='position:static; width:250px;' Height='77px' onclick='setPort();' onkeydown='FindEnter(event);'><option selected='selected' value='1'></option></select>"
                top=getTop(pName)+25;
                left=getLeft(pName);
                //alert(top);
                //alert(left);
                createPopUp_Port("500px","300px",top+"px",left+"px","title",innerHTML);
            }
            ShowPort1();
            
            return false;
        }
        else
        {   
            var popD=document.getElementById("NSPopUP9");
            if (popD != null)
            {
                document.body.removeChild(popD);
            }
        }
    }
    

   function CallMe(str)
   {
        
        var body = str;
        var title = "<a href='JavaScript:GenerateOrderList_Gan();' class='b-order'>Add to Order List</a>";
        var prod=document.getElementById('drpProduct');
        var top=getTop(prod)+25;
        var left=getLeft(prod);
        createPopUp_Product("450px","350px",top+"px",left+"px",title, body);
        return false;
   }
   
   function CallDist(ctrl)
   {
        var InnerScript="";
        var ch=document.getElementById(ctrl.id);
        var ttl=ch.title;
        var pack=ttl.split(",");
        InnerScript=InnerScript+"<table width='97%%' border='0' cellspacing='0' cellpadding='0'>";
        for(var i=0;i<pack.length;i++)
        {
            InnerScript=InnerScript+"<td width='20%' style='padding-left:5px;' align='left'>";
            if (pack[i].indexOf("_")!=-1)
            {
                InnerScript=InnerScript+"<input type='checkbox' checked='checked' id='"+ctrl.id+"_"+pack[i].replace('_','')+"' name='chkpack' onclick='CheckBulkType(this);CalculatePackTitle(this);' /></td>";
            }
            else
            {
                InnerScript=InnerScript+"<input type='checkbox' id='"+ctrl.id+"_"+pack[i].replace('_','')+"' name='chkpack' onclick='CheckBulkType(this);CalculatePackTitle(this);' /></td>";
            }
            InnerScript=InnerScript+"</td>";
            InnerScript=InnerScript+"<td id='TDRS"+ctrl.id+"_"+pack[i].replace('_','')+"' width='75%' class='line3g11' align='left'>"+pack[i].replace('_','')+"</td>";
            InnerScript=InnerScript+"</tr>";
        }
        //InnerScript=InnerScript+"<tr><td width='90%' colspan='2' align='right'><input type='button' value='Ok' onclick='return closePopUp1();'/></td></tr></table>";
        InnerScript=InnerScript+"</table>";
        var body = InnerScript;
        var title = "";//"<input type='button' value='Ok' onclick='return closePopUp1();'/>";
        var bodyMain=document.getElementById("NSPopUP");
        var bodyFrame=document.getElementById("idTD");
        var prod=document.getElementById('drpProduct');
        var top=getTopOfDIV(ch);
        //alert(top);
        //alert(bodyMain.style.width);
        var left=getLeftOfDIV(bodyFrame)+10;//+ch.style.width;
        //alert(left);
        var ht=(pack.length*30);
        createPopUp_Pack("100px",ht+"px",top+"px",left+"px",title, body);
        return false;
   }
   
   function CalculatePackTitle(ctrl)
   {
        
        var ch=document.getElementById(ctrl.id);
        var pack=ch.id.split('_');
        var pk=document.getElementById(pack[0]);
        var j;
        var string='';
        var form1=document.getElementById('NSPopUP1');
	    form1=form1.getElementsByTagName('*');
	    j=0;
	    for (var i=0; i<form1.length; i++) 
	    {
            var myType = form1[i].type;
            if (myType == 'checkbox')
            {
                if (form1[i].checked == true)
                {
                    var pack1=form1[i].id.split("_");
                    string=string+"_"+pack1[1]+",";
                }
                else
                {
                    var pack1=form1[i].id.split("_");
                    string=string+pack1[1]+",";
                }
            }    
        }
        string=string.substring(0,string.length-1);
        pk.title=string;
        var check=string.split("_");
        if (check.length > 1)
            {
                pk.src="images/arrow_bl_dn1.gif";
            }
        else
            {
               pk.src="images/arrow_bl_right1.gif";
            }
        
  }
   
   
   function getTop( oElement )
    {
    var iReturnValue = 0;
    while( oElement != null ) {
    iReturnValue += oElement.offsetTop;
    oElement = oElement.offsetParent;
    }
    return iReturnValue;
    }
  function getLeft( oElement )
    {
    var iReturnValue = 0;
    while( oElement != null ) {
    iReturnValue += oElement.offsetLeft;
    oElement = oElement.offsetParent;
    }
    return iReturnValue;
  }
  
  function getTopOfDIV( oElement )
    {
    var iReturnValue = 0;
    while( oElement.id != "NSPopBodyFrame" ) {
    
    iReturnValue += oElement.offsetTop;
    oElement = oElement.offsetParent;
    //alert(oElement.id);
    }
    return iReturnValue;
    }
  function getLeftOfDIV( oElement )
    {
    var iReturnValue = 0;
    while( oElement.id != "NSPopBodyFrame" ) {
    iReturnValue += oElement.offsetLeft;
    oElement = oElement.offsetParent;
    }
    return iReturnValue;
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
        
/* function createPop(width,height,title,id)
--------------------------------   
   Create the "PopUp" window
--------------------------------   */
function showPopUp(width,height,title,id) {
  // ensure the given ID exists
  obj = document.getElementById(id);
  if (obj == null ) return;
  width = width.replace(/\s/g,'')  // remove spaces from width parameter
  height = height.replace(/\s/g,'')  // remove spaces from height parameter
  // Create semi-transparent div to cover the screen
  e = document.createElement("div");
  e.id = "NSPopTransparent";
  e.style.opacity = ".5";                  
  e.style.MozOpacity = ".5";               
  e.style.KhtmlOpacity = ".5";  // older konqueror and safari
  e.style.filter = "alpha(opacity=50)";
  e.style.height = "100%";
  e.style.width = "100%";
  oContainer = document.body.appendChild(e);
  // if the document is longer than the screen height (it scrolls)
  if (document.body.offsetHeight + 24 > oContainer.offsetHeight)
    e.style.height = (document.body.offsetHeight + 24) + "px";
  disableAll(document.body,"input");
  disableAll(document.body,"select");
  disableAll(document.body,"textarea");

  // create outside div
  e = document.createElement("div");
  e.id = "NSPopUP";
  // center the outside div within the viewable section of the document
  var top = (getWindowSize()[1] / 2) - (getNumericPortion(height) );
  if (width.substr(width.length-1) == "%")
    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width)/100 * getWindowSize()[0] /2 );
  else 
    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width) / 2 );
  if (height.substr(width.length-1) == "%")
    var top = (getWindowSize()[1] / 2) + getScrollXY()[1] - (getNumericPortion(height)/100 * getWindowSize()[1] /2 );
  else
    var top = (getWindowSize()[1] / 2) + getScrollXY()[1]- (getNumericPortion(height) / 2 );
   
  e.style.left = left + "px";
  e.style.top = top + "px";
  e.style.height = height;
  e.style.width = width;
  oPop=document.body.appendChild(e);
  
  // create title bar
  e = document.createElement("div");
  e.id = "NSPopTitle";
  // Make the box movable when the mouse is pressed on the title bar
  e.onmousedown = movePop
  e.onmouseup = endMovePop
  oTitle = oPop.appendChild(e);

  // Add a close button to the title bar
  e = document.createElement("img")
  e.style.width = "18px";
  e.style.height = "18px";
  e.style.magin = "1px";
  e.src = "images/close.gif";
  e.id ="NSPopCloseButton";
  e.onclick = closePopUp;
  oTitle.appendChild(e);

  // Add the Title Text
  e = document.createElement("div");
  e.id = "NSPopTitleText";
  e.innerHTML = title;
  oTitle.appendChild(e);

  // create body of popup
  e = document.createElement("div");
  e.id = "NSPopBodyFrame";
  e.style.height = (oPop.offsetHeight - oTitle.offsetHeight - 2) + "px";
  oBody = oPop.appendChild(e);
  e = document.createElement("div");
  e.id="NSPopBodyText";
  e.innerHTML = obj.innerHTML;
  oText= oBody.appendChild(e);
  
}

function showPopUp(width,title,id) {
  // ensure the given ID exists
  obj = document.getElementById(id);
  if (obj == null ) return;
  if (obj.scrollHeight<500)
  height=obj.scrollHeight+30+"px";
  else
  height="530px";
  width = (width+201).replace(/\s/g,'')  // remove spaces from width parameter
  width = "680px";
  height = height.replace(/\s/g,'')  // remove spaces from height parameter
  // Create semi-transparent div to cover the screen
  e = document.createElement("div");
  e.id = "NSPopTransparent";
  e.style.opacity = ".5";                  
  e.style.MozOpacity = ".5";               
  e.style.KhtmlOpacity = ".5";  // older konqueror and safari
  e.style.filter = "alpha(opacity=50)";
  e.style.height = "100%";
  e.style.width = "100%";
  oContainer = document.body.appendChild(e);
  // if the document is longer than the screen height (it scrolls)
  if (document.body.offsetHeight + 24 > oContainer.offsetHeight)
    e.style.height = (document.body.offsetHeight + 24) + "px";
  disableAll(document.body,"input");
  disableAll(document.body,"select");
  disableAll(document.body,"textarea");

  // create outside div
  e = document.createElement("div");
  e.id = "NSPopUP";
  // center the outside div within the viewable section of the document
  var top = (getWindowSize()[1] / 2) - (getNumericPortion(height) );
  if (width.substr(width.length-1) == "%")
    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width)/100 * getWindowSize()[0] /2 );
  else 
    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width) / 2 );
  if (height.substr(width.length-1) == "%")
    var top = (getWindowSize()[1] / 2) + getScrollXY()[1] - (getNumericPortion(height)/100 * getWindowSize()[1] /2 );
  else
    var top = (getWindowSize()[1] / 2) + getScrollXY()[1]- (getNumericPortion(height) / 2 );
    
    if(top <0) {top=0;}
  e.style.left = left + "px";
  e.style.top = top + "px";
  e.style.height = height;
  e.style.width = width;
  oPop=document.body.appendChild(e);
  
  // create title bar
  e = document.createElement("div");
  e.id = "NSPopTitle";
  // Make the box movable when the mouse is pressed on the title bar
  e.onmousedown = movePop
  e.onmouseup = endMovePop
  oTitle = oPop.appendChild(e);

  // Add a close button to the title bar
  e = document.createElement("img")
  e.style.width = "18px";
  e.style.height = "18px";
  e.style.magin = "1px";
  e.src = "images/close.gif";
  e.id ="NSPopCloseButton";
  e.onclick = closePopUp;
  oTitle.appendChild(e);

  // Add the Title Text
  e = document.createElement("div");
  e.id = "NSPopTitleText";
  e.innerHTML = title;
  oTitle.appendChild(e);

  // create body of popup
  e = document.createElement("div");
  e.id = "NSPopBodyFrame";//alert(oPop.offsetHeight - oTitle.offsetHeight - 2);
  //e.style.height = (oPop.offsetHeight - oTitle.offsetHeight - 2) + "px";
  e.style.height = "500px";
  
  
  oBody = oPop.appendChild(e);
  e = document.createElement("div");
  e.id="NSPopBodyText";
  e.innerHTML = obj.innerHTML;
  oText= oBody.appendChild(e);
  
}

function createPopUp(width,height,title,innerHTML) {
  // ensure the given ID exists  
  width = width.replace(/\s/g,'')  // remove spaces from width parameter
  height = height.replace(/\s/g,'')  // remove spaces from height parameter
  // Create semi-transparent div to cover the screen
  e = document.createElement("div");
  e.id = "NSPopTransparent";
  e.style.opacity = ".5";                  
  e.style.MozOpacity = ".5";               
  e.style.KhtmlOpacity = ".5";  // older konqueror and safari
  e.style.filter = "alpha(opacity=50)";
  e.style.height = "100%";
  e.style.width = "100%";
  oContainer = document.body.appendChild(e);
  // if the document is longer than the screen height (it scrolls)
  if (document.body.offsetHeight + 24 > oContainer.offsetHeight)
    e.style.height = (document.body.offsetHeight + 24) + "px";
  disableAll(document.body,"input");
  disableAll(document.body,"select");
  disableAll(document.body,"textarea");

  // create outside div
  e = document.createElement("div");
  e.id = "NSPopUP";
  // center the outside div within the viewable section of the document
  var top = (getWindowSize()[1] / 2) - (getNumericPortion(height) );
  if (width.substr(width.length-1) == "%")
    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width)/100 * getWindowSize()[0] /2 );
  else 
    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width) / 2 );
  if (height.substr(width.length-1) == "%")
    var top = (getWindowSize()[1] / 2) + getScrollXY()[1] - (getNumericPortion(height)/100 * getWindowSize()[1] /2 );
  else
    var top = (getWindowSize()[1] / 2) + getScrollXY()[1]- (getNumericPortion(height) / 2 );
  e.style.left = left + "px";
  e.style.top = top + "px";
  e.style.height = height;
  e.style.width = width;
  oPop=document.body.appendChild(e);
  
  // create title bar
  e = document.createElement("div");
  e.id = "NSPopTitle";
  // Make the box movable when the mouse is pressed on the title bar
  e.onmousedown = movePop
  e.onmouseup = endMovePop
  oTitle = oPop.appendChild(e);

  // Add a close button to the title bar
  e = document.createElement("img")
  e.style.width = "18px";
  e.style.height = "18px";
  e.style.magin = "1px";
  e.src = "images/close.gif";
  e.id ="NSPopCloseButton";
  e.onclick = closePopUp;
  oTitle.appendChild(e);

  // Add the Title Text
  e = document.createElement("div");
  e.id = "NSPopTitleText";
  e.innerHTML = title;
  oTitle.appendChild(e);

  // create body of popup
  e = document.createElement("div");
  e.id = "NSPopBodyFrame";
  e.style.height = (oPop.offsetHeight - oTitle.offsetHeight - 2) + "px";
  oBody = oPop.appendChild(e);
  e = document.createElement("div");
  e.id="NSPopBodyText";
  e.innerHTML = innerHTML;
  oText= oBody.appendChild(e);
  
}

function createPopUp(width,title,innerHTML) {
  // ensure the given ID exists  
  width = width.replace(/\s/g,'')  // remove spaces from width parameter  
  // Create semi-transparent div to cover the screen
  e = document.createElement("div");
  e.id = "NSPopTransparent";
  e.style.opacity = "0";                  
  e.style.MozOpacity = "0";               
  e.style.KhtmlOpacity = "0";  // older konqueror and safari
  e.style.filter = "alpha(opacity=0)";
  e.style.height = "100%";
  e.style.width = "100%";
  oContainer = document.body.appendChild(e);
  // if the document is longer than the screen height (it scrolls)
  if (document.body.offsetHeight + 24 > oContainer.offsetHeight)
    e.style.height = (document.body.offsetHeight + 24) + "px";
  disableAll(document.body,"input");
  disableAll(document.body,"select");
  disableAll(document.body,"textarea");

  // create outside div
  f = document.createElement("div");
  f.id = "NSPopUP";
 
  oPop=document.body.appendChild(f);
  
  // create title bar
  e = document.createElement("div");
  e.id = "NSPopTitle";
  // Make the box movable when the mouse is pressed on the title bar
  e.onmousedown = movePop
  e.onmouseup = endMovePop
  oTitle = oPop.appendChild(e);

  // Add a close button to the title bar
  e = document.createElement("img")
  e.style.width = "18px";
  e.style.height = "18px";
  e.style.magin = "1px";
  e.src = "images/close.gif";
  e.id ="NSPopCloseButton";
  e.onclick = closePopUp;
  oTitle.appendChild(e);

  // Add the Title Text
  e = document.createElement("div");
  e.id = "NSPopTitleText";
  e.innerHTML = title;
  oTitle.appendChild(e);

  // create body of popup
  e = document.createElement("div");
  e.id = "NSPopBodyFrame";
  
  oBody = oPop.appendChild(e);
  e = document.createElement("div");
  e.id="NSPopBodyText";
  e.innerHTML = innerHTML;
  oText= oBody.appendChild(e);
  
  height=oText.scrollHeight+30+"px";
  height = height.replace(/\s/g,'')  // remove spaces from height parameter
  
   // center the outside div within the viewable section of the document
  var top = (getWindowSize()[1] / 2) - (getNumericPortion(height) );
  if (width.substr(width.length-1) == "%")
    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width)/100 * getWindowSize()[0] /2 );
  else 
    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width) / 2 );
  if (height.substr(width.length-1) == "%")
    var top = (getWindowSize()[1] / 2) + getScrollXY()[1] - (getNumericPortion(height)/100 * getWindowSize()[1] /2 );
  else
    var top = (getWindowSize()[1] / 2) + getScrollXY()[1]- (getNumericPortion(height) / 2 );
    
    if(top <0) {top=0;}
  f.style.left = left + "px";
  f.style.top = top + "px";
  f.style.height = height;
  f.style.width = width;
  
  oBody.style.height = (oPop.offsetHeight - oTitle.offsetHeight - 2) + "px";
}


function createPopUp_Product(width,height,top,left,title,innerHTML) {
  // ensure the given ID exists  
  width = width.replace(/\s/g,'')  // remove spaces from width parameter  
  // create outside div
  f = document.createElement("div");
  f.id = "NSPopUP";
  //f.onblur=closePopUp; 
  oPop=document.body.appendChild(f);
  
  // create title bar
  e = document.createElement("div");
  e.id = "NSPopTitle";
  // Make the box movable when the mouse is pressed on the title bar
  e.onmousedown = movePop
  e.onmouseup = endMovePop
  oTitle = oPop.appendChild(e);

  // Add a close button to the title bar
  e = document.createElement("img")
  e.style.width = "18px";
  e.style.height = "18px";
  e.style.magin = "1px";
  e.src = "images/close.gif";
  e.id ="NSPopCloseButton";
  e.onclick = closePopUp;
  oTitle.appendChild(e);

  // Add the Title Text
  e = document.createElement("div");
  e.id = "NSPopTitleText";
  e.innerHTML = title;
  oTitle.appendChild(e);

  // create body of popup
  e = document.createElement("div");
  e.id = "NSPopBodyFrame";
  
  //e.onblur=closePopUp;
  oBody = oPop.appendChild(e);
  e = document.createElement("div");
  //e.style.width = "67%";
  e.id="NSPopBodyText";
  e.innerHTML = innerHTML;
  oText= oBody.appendChild(e);
  
  //height=oText.scrollHeight+30+"px";
  //height = height.replace(/\s/g,'')  // remove spaces from height parameter
  
   // center the outside div within the viewable section of the document
//  var top = (getWindowSize()[1] / 2) - (getNumericPortion(height) );
//  if (width.substr(width.length-1) == "%")
//    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width)/100 * getWindowSize()[0] /2 );
//  else 
//    var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (getNumericPortion(width) / 2 );
//  if (height.substr(width.length-1) == "%")
//    var top = (getWindowSize()[1] / 2) + getScrollXY()[1] - (getNumericPortion(height)/100 * getWindowSize()[1] /2 );
//  else
//    var top = (getWindowSize()[1] / 2) + getScrollXY()[1]- (getNumericPortion(height) / 2 );
//    
//    if(top <0) {top=0;}
  f.style.left = left;//left + "px";
  f.style.top = top;//top + "px";
  f.style.height = height;
  f.style.width = width;
  //f.setfocus;
  oBody.style.height = (oPop.offsetHeight - oTitle.offsetHeight - 2) + "px";
}


function createPopUp_Pack(width,height,top,left,title,innerHTML) {
  width = width.replace(/\s/g,'')  // remove spaces from width parameter  
  var ds=document.getElementById('NSPopUP1');
  if (ds!=null)
  {
    closePopUp1();
  }
  var mainDIV=document.getElementById("divHero");
  f = document.createElement("div");
  f.id = "NSPopUP1";
  oPop=mainDIV.appendChild(f);
  e = document.createElement("div");
  e.id = "NSPopBodyFrame1";
  oBody = oPop.appendChild(e);
  e = document.createElement("div");
  e.id="NSPopBodyText1";
  e.innerHTML = innerHTML;
  oText= oBody.appendChild(e);
  f.style.left = left;//left + "px";
  f.style.top = top;//top + "px";
  f.style.height = height;
  f.style.width = width;
  oBody.style.height = (oPop.offsetHeight - 2) + "px";
}

  
function createPopUp_Port(width,height,top,left,title,innerHTML) {
  //width = width.replace(/\s/g,'')  // remove spaces from width parameter  
  f = document.createElement("div");
  f.id = "NSPopUP9";
  oPop=document.body.appendChild(f);
  
//  e = document.createElement("div");
//  e.id = "NSPopTitle9";
//  e.onmousedown = movePop
//  e.onmouseup = endMovePop
//  oTitle = oPop.appendChild(e);

//  e = document.createElement("img")
//  //e.style.width = "18px";
//  e.style.height = "18px";
//  e.style.magin = "1px";
//  e.src = "images/close.gif";
//  e.id ="NSPopCloseButton9";
//  e.onclick = closePopUp;
//  oTitle.appendChild(e);

//  e = document.createElement("div");
//  e.id = "NSPopTitleText9";
//  e.innerHTML = title;
//  oTitle.appendChild(e);

  e = document.createElement("div");
  e.id = "NSPopBodyFrame9";
  
  oBody = oPop.appendChild(e);
  e = document.createElement("div");
  //e.style.width = "67%";
  e.id="NSPopBodyText9";
  e.innerHTML = innerHTML;
  oText= oBody.appendChild(e);
  
  f.style.left = left;//left + "px";
  f.style.top = top;//top + "px";
  f.style.height = height;
  f.style.width = width;
  //f.setfocus;
  f.style.position="absolute";
  //f.style.zIndex=50;
  //alert(f.style.left);
  //alert(f.style.top);
  //alert(f.style.height);
  //alert(f.style.width);
  oBody.style.height = (oPop.offsetHeight - 2) + "px";







}


function setBreakUpDiv()
{
    
    var f=document.getElementById("divBreakUp");
    var lbl=document.getElementById("lblBreakUp");
    var img=document.getElementById("imgBreakUp");
    var td1=document.getElementById("tdWeekendCalculation");
    //alert(td1.innerHTML);
    //alert(td1.innerHTML.substring(0,4));
    td1.innerHTML=lbl.innerHTML;
    if ((td1.innerHTML.length>3) && (td1.innerHTML.substring(0,4)!="<FOR"))
    {
        
        td1.style.width='210px';
        var left=getLeft(img);
        var top=getTop(img)+20;
        f.style.top=top+'px';
        f.style.left=left-190+'px';
        f.style.position="absolute";
        f.style.display='block';
    }
    else
    {
        f.style.display='none';
    }
}
function letBreakUpDiv()
{
    var f=document.getElementById("divBreakUp");
    f.style.display='none';
    
}
function setEarliestDeliveryDateDiv()
{
    
    var f=document.getElementById("divBreakUp");
    var lbl=document.getElementById("lblEarliestDeliveryDate");
    var td1=document.getElementById("tdWeekendCalculation");
    //alert(td1.innerHTML);
    //alert(td1.innerHTML.substring(0,4));
    td1.innerHTML="Lead time is complete working days in the delivery location.";
    if ((td1.innerHTML.length>3) && (td1.innerHTML.substring(0,4)!="<FOR"))
    {
        var left=getLeft(lbl);
        var top=getTop(lbl)+20;
        td1.style.width='110px';
       
        f.style.top=top+'px';
        f.style.left=left+'px';
        f.style.position="absolute";
        f.style.display='block';
    }
    else
    {
        f.style.display='none';
    }
}

function setSelectProductDiv()
{
    var f=document.getElementById("divBreakUp");
    var lbl=document.getElementById("lblSelectProduct");
    var td1=document.getElementById("tdWeekendCalculation");
    //alert(td1.innerHTML);
    //alert(td1.innerHTML.substring(0,4));
    td1.innerHTML="Offered Products & Packs and in some instances alternatives are listed. For Non-Listed requirements please first ensure availability.</Br></br>Bulk-B=Bulk by Barge.</br>Bulk-T=Bulk by Tank-Truck.";
    if ((td1.innerHTML.length>3) && (td1.innerHTML.substring(0,4)!="<FOR"))
    {
        var left=getLeft(lbl);
        var top=getTop(lbl)+20;
        td1.style.width='170px';
       
        f.style.top=top+'px';
        f.style.left=left+'px';
        f.style.position="absolute";
        f.style.display='block';
    }
    else
    {
        f.style.display='none';
    }
}

function setPVCDiv()
{
    var f=document.getElementById("divBreakUp");
    var lbl=document.getElementById("lblPVC");
    var td1=document.getElementById("tdWeekendCalculation");
    //alert(td1.innerHTML);
    //alert(td1.innerHTML.substring(0,4));
    td1.innerHTML="Includes any unique pack product's specific min. volume requirement different than port general conditions.";
    if ((td1.innerHTML.length>3) && (td1.innerHTML.substring(0,4)!="<FOR"))
    {
        var left=getLeft(lbl);
        var top=getTop(lbl)+20;
        td1.style.width='140px';
       
        f.style.top=top+'px';
        f.style.left=left+'px';
        f.style.position="absolute";
        f.style.display='block';
    }
    else
    {
        f.style.display='none';
    }
}
function setSPLDiv()
{
    var f=document.getElementById("divBreakUp");
    var lbl=document.getElementById("lblSPL");
    var td1=document.getElementById("tdWeekendCalculation");
    //alert(td1.innerHTML);
    //alert(td1.innerHTML.substring(0,4));
    td1.innerHTML="Indicates any unique bulk product's min. volume requirement different than port general conditions.";
    if ((td1.innerHTML.length>3) && (td1.innerHTML.substring(0,4)!="<FOR"))
    {
        var left=getLeft(lbl);
        var top=getTop(lbl)+20;
        td1.style.width='140px';
       
        f.style.top=top+'px';
        f.style.left=left+'px';
        f.style.position="absolute";
        f.style.display='block';
    }
    else
    {
        f.style.display='none';
    }
}





function letBreakUpDiv()
{
    var f=document.getElementById("divBreakUp");
    f.style.display='none';
    
}





function ClosePopup_OnClick()
{
  var ds=document.getElementById('NSPopUP1');
  if (ds!=null)
  {
    closePopUp1();
  }
}









/* function closePopUp()
--------------------------------
   Removes the semi-transparent div
   Removes the Pop-Up window
   enables all elements
--------------------------------   */
function closePopUp(){
  //oDiv = document.getElementById("NSPopTransparent");
  //document.body.removeChild(oDiv);
  oDiv = document.getElementById("NSPopUP");
  document.body.removeChild(oDiv);
  //enableAll(document.body,"input");
  //enableAll(document.body,"select");
  //enableAll(document.body,"textarea");
}      
function closePopUp1()
{
    pDiv=document.getElementById("divHero");
    oDiv = document.getElementById("NSPopUP1");
    pDiv.removeChild(oDiv);
  
}
/* function disableAll(obj,type)
--------------------------------   
  Disable all elements of the specified type
  within the specified object
-------------------------------- */
function disableAll(obj,type) {
  oInput = obj.getElementsByTagName(type);
  for (i=0;i<oInput.length ;i++) {
    oInput[i].disabled = true;
  }
}
 
/* function enableAll(obj,type)
--------------------------------   
   Enable all elements of the specified type
   within the specified object
--------------------------------  */   
function enableAll(obj,type) {
  oInput = obj.getElementsByTagName(type);
  for (i=0;i<oInput.length ;i++) {
    oInput[i].disabled = false;
  }
}
 
/* Global Variables required for popup move events
-------------------------------------------------- */
var mouseStartX = -99999;
var mouseStartY = -99999;
var popLeft;
var popTop;

/* function movePop()
----------------------------------
  Starts the watch for the mousemove
  and mouseup events on the document 
  object.
---------------------------------- */  
function movePop() {
  mouseStartX = -99999;
  mouseStartY = -99999;
  popLeft= document.getElementById("NSPopUP").offsetLeft;
  popTop = document.getElementById("NSPopUP").offsetTop;
  document.onmousemove = movePop1;
  document.onmouseup = endMovePop;
}

/* function movePop1(e)
----------------------------------
   perform the actual move of the popup
   e = mouse move event
---------------------------------- */   
function movePop1(e) {
  if (!e) var e = window.event;  // if IE, then we need to assign e
  if (e.pageX) {    // FF, opera, netscape
    posX = e.pageX;   
    posY = e.pageY;
  }
  else if (e.clientX) {  // IE
    posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;  
    posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
  }
  obj = document.getElementById("NSPopUP");
  if (mouseStartX == -99999) mouseStartX = posX;  // -99999 is an arbitrary number.  It is unlikely to be hit 
  if (mouseStartY == -99999) mouseStartY = posY;
  var offsetX = posX - mouseStartX; // determine the difference from where the mouse started to where it is now
  var offsetY = posY - mouseStartY;
  vPosX = popLeft + offsetX;
  vPosY = popTop + offsetY;
  // ensure that the pop-up is not moved off the screen
  if (vPosX < 0) vPosX = 0;
  if (vPosX + obj.offsetWidth > document.body.offsetWidth +10) vPosX = document.body.offsetWidth - obj.offsetWidth +10;
  if (vPosY < 0) vPosY = 0;
  if (document.body.offsetHeight > getWindowSize()[1]) {
    if (vPosY + obj.offsetHeight > document.body.offsetHeight + 20) vPosY = document.body.offsetHeight - obj.offsetHeight + 20;
  }
  else {
    if (vPosY + obj.offsetHeight > getWindowSize()[1] -1) vPosY = getWindowSize()[1] - obj.offsetHeight -1;
  }
  obj.style.left = vPosX + "px";
  obj.style.top = vPosY + "px";
}   

/* function endMovePop()
----------------------------------
   disables the watch for the mousemove and 
   mouseup events on the document object
---------------------------------- */   
function endMovePop() {
  document.onmousemove = function() {};
  document.onmouseup = function() {};
}

function getWindowSize() {
  var myWidth = 0;
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) { 
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } 
  else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
  } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight] ;
}

function getScrollXY() {
  var scrOfX = 0;
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } 
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } 
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getNumericPortion(str) {
  return str.match(/\d*/);
} 
