﻿// JScript File
var http = createRequestObject();
function createRequestObject() 
 {
       // find the correct xmlHTTP, works with IE, FF and Opera
	    var xmlhttp;
	    try 
	    {
  	    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch(e) 
      {
        try 
        {
    	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e) 
        {
    	    xmlhttp=null;
        }
      }
      if(!xmlhttp&&typeof XMLHttpRequest!="undefined") 
      {
  	    xmlhttp=new XMLHttpRequest();
      }
      return  xmlhttp;

}
function HandleNothing()
{
}
function RP_Recalculate(orderid)
{
    pckgdoneOrder=orderid;
     document.getElementById('div_ship_pr'+pckgdoneOrder).innerHTML="processing..";
    var params='action=ReCalculate&orderid='+orderid;
    http.open('post','trialpackdone.aspx?'+params,true);
    http.onreadystatechange = response_shipPrice_Save_RP;
    SetHTTP_Header(params);
    http.send(params);
}
function RP_ChangeMethod(id,orderid)
{
     pckgdoneOrder=orderid;
    var method=document.getElementById(id).value; 
    var params='action=ChangeMethod&method='+method+'&orderid='+orderid;
    http.open('post','trialpackdone.aspx?'+params,true);
    http.onreadystatechange =RP_HandleMethod;
    SetHTTP_Header(params);
    http.send(params);
}
function RP_HandleMethod()
{
    if(http.readyState==4)
    {
       RP_Recalculate(pckgdoneOrder);
    }
}
function response_shipPrice_Save_RP()
{
   if(http.readyState==4)
    {
      var response=http.responseText;
      var arr=new Array();
      if(response.indexOf('UPSERR:')!=-1)
      {
             arr=response.split('UPSERR:');
             arr=arr[1].split(':UPSERR');
             alert(arr[0]);
      }
      else
      {
          try
          {
             arr=response.split('ResponseResultStartsHere:');
             arr=arr[1].split(':ResponseResultEndsHere');
             var newResult=arr[0].split('!');
             document.getElementById('txt_ship_'+pckgdoneOrder).value="";
             document.getElementById('div_tax'+pckgdoneOrder).innerHTML=newResult[1];
             document.getElementById('div_total'+pckgdoneOrder).innerHTML=newResult[2];
             document.getElementById('div_ship_pr'+pckgdoneOrder).innerHTML=newResult[0];
          }
          catch(f)
          {
             document.getElementById('div_ship_pr'+pckgdoneOrder).innerHTML="";
          }
      }
     

    }
}
function HistoryBuildPageBUILD()
{
    var customerid=document.getElementById('hiden_customerid').value;
    if(customerid=="")
    {
       alert("No Customer Selected");
    }
    else
    {
       try
       {
        document.getElementById('div_pastOrders').innerHTML="";
        document.getElementById('div_currentOrders').innerHTML="";
        document.getElementById('div_DeletedOrders').innerHTML="";
        document.getElementById('div_Links').style.display="block";
       }
       catch(j)
       {
       }
       select_a_customer=true;
       openPastOrdersCustomer2()
    }
}
function clearShipPrice()
{
    startStr='<!--shipping_charge_starts_here -->';
    endStr='<!--shipping_charge_ends_here -->';
    IDFill='shipping_charge';
    var params='action=ClearShip';
    http.open('post','itemsfororder.aspx?'+params,true);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function HistoryWhenSelCust()
{
}

function deleteBoxBUILD(pcknumber)
{
    document.getElementById('desc_div_load').style.display="block";
    makeLinkColorBUILD('btn_shipping');
    startStr='<!--shipping_starts_here-->';
    endStr='<!--shipping_ends_here-->';
    var params='action=DeleteBox&packnumber='+pcknumber;
    IDFill='FillArea';
    http.open('post','buildshipping.aspx?'+params,true);
    http.onreadystatechange = Response_DeleteBox;
    SetHTTP_Header(params);
    http.send(params);
}
function Response_DeleteBox()
{
    if(http.readyState==4)
    {
    document.getElementById('desc_div_load').style.display="none";
    response_BUILD();
    }
}
function displayAccountPage()
{
      var params='accountfunctions.aspx';
      http.open('post',params,true);
      http.onreadystatechange = response_DisplayACCOUNT;
      SetHTTP_Header(params);
      http.send(params);
}
function response_DisplayACCOUNT()
{
   if(http.readyState==4)
   {
       var response = http.responseText;
      
       
       startStr='<!--accnnt_page_starts_here-->';
       endStr='<!--accnnt_page_ends_here-->';
       IDFill='div_account_page';
        Fill_area_BUILD(response,startStr,endStr,IDFill);
       /*startStr='<!--admin_info_starts-->';
       endStr='<!--admin_info_ends--> ';
       IDFill='div_adminTop';
       Fill_area_BUILD(response,startStr,endStr,IDFill);
       startStr='<!--companyInfo_starts-->';
       endStr='<!--companyInfo_ends-->';
       IDFill='div_companay';
       Fill_area_BUILD(response,startStr,endStr,IDFill);
       startStr='<!--addContactbtn_starts-->';
       endStr='<!--addContactbtn_ends-->';
       IDFill='div_addcontactBtn';
       Fill_area_BUILD(response,startStr,endStr,IDFill);
       startStr='<!--contacts_starts-->';
       endStr='<!--contacts_ends-->';
       IDFill='div_allcontacts';
       Fill_area_BUILD(response,startStr,endStr,IDFill);
       startStr='<!--DeleteCustome_starts-->';
       endStr='<!--DeleteCustome_ends-->';
       IDFill='div_delete';
       Fill_area_BUILD(response,startStr,endStr,IDFill);*/
       loginarea(response);
   }
       
    
}
function UpdateContact_accntBUILD(id,fname,lname,did,email,cell,admin,notify,ext,notes)
{

     var account=new Array();
     account[0]= document.getElementById(fname).value;
     account[1]= document.getElementById(lname).value;
     account[2]= document.getElementById(did).value;
     account[3]= document.getElementById(email).value;
     account[4]= document.getElementById(cell).value;
     var adm="false";
     if(document.getElementById(admin).checked)
     {
        adm="true";
     }
     var notifyx="false";
     if(document.getElementById(notify).checked)
     {
        notifyx="true";
     }
     account[5]= adm;
     account[6]= notifyx;
     account[7]= document.getElementById(ext).value;
     account[8]= document.getElementById(notes).value;
     var lengthAcnt=account.length;
     for(var j=0;j<lengthAcnt;j=parseInt(j)+1)
     {
        account[j]=RestrictedCharactersCheck(account[j]);
     }
     var errmsg="";
     if(document.getElementById(fname).value=="")
     {
         errmsg="FirstName To Be filled to Save The Contact";
     }
     if(document.getElementById(email).value=="")
     {
         errmsg="UserId is Required";
     }
     if(errmsg!="")
     {
          alert(errmsg);
     }
     else
     {
          var strAccnt=account.join('!');
          var params='accountfunctions.aspx?action=UpdateContact&contact='+strAccnt+'&id='+id;
          http.open('post',params,true);
          http.onreadystatechange =Save_Account;
          SetHTTP_Header(params);
          http.send(params);
     }
}
function SaveContact_accntBUILD(fname,lname,did,email,cell,admin,notify,ext,notes)
{


     var account=new Array();
     account[0]= document.getElementById(fname).value;
     account[1]= document.getElementById(lname).value;
     account[2]= document.getElementById(did).value;
     account[3]= document.getElementById(email).value;
     account[4]= document.getElementById(cell).value;
     var adm="false";
     if(document.getElementById(admin).checked)
     {
        adm="true";
     }
     var notifyx="false";
     if(document.getElementById(notify).checked)
     {
        notifyx="true";
     }
     account[5]= adm;
     account[6]= notifyx;
     account[7]= document.getElementById(ext).value;
     account[8]= document.getElementById(notes).value;
     var lengthAcnt=account.length;
     for(var j=0;j<lengthAcnt;j=parseInt(j)+1)
     {
        account[j]=RestrictedCharactersCheck(account[j]);
     }
     var errmsg="";
     if(document.getElementById(fname).value=="")
     {
         errmsg="FirstName To Be filled to Save The Contact";
     }
     if(document.getElementById(email).value=="")
     {
         errmsg="UserId is Required";
     }
     if(errmsg!="")
     {
          alert(errmsg);
     }
     else
     {
     
          var strAccnt=account.join('!');
          var params='accountfunctions.aspx?action=savecontact&contact='+strAccnt;
          http.open('post',params,true);
          http.onreadystatechange =Save_Account;
          SetHTTP_Header(params);
          http.send(params);
     }
}
function DeleteCustomerBUILD()
{
          var k=confirm('Are Sure that You Want to Delete the Customer');
          if(k)
          {
              var params='accountfunctions.aspx?action=DeleteCustomer';
              http.open('post',params,true);
              http.onreadystatechange =response_deleteCust;
              SetHTTP_Header(params);
              http.send(params);
          }
}
function response_deleteCust()
{
    if(http.readyState==4)
    {
      response_DisplayACCOUNT();
      alert('SucessFullyDeleted');
    }
}
function SaveAccountBUILD(btnsave,fname,lname,DIDtop,userid,cellphone,notify,payment,usercompany,usertype,telrad,company,phone,add1,add2,ext,fax,city,state,statebox,country,exttop,zip,notes,notestop,exempt)
{

     var account=new Array();
     account[0]= document.getElementById(fname).value;
     account[1]= document.getElementById(lname).value;
     account[2]= document.getElementById(DIDtop).value;
     account[3]= document.getElementById(userid).value;
     account[4]= document.getElementById(cellphone).value;
     var notifyx="false";
     if(document.getElementById(notify).checked)
     {
        notifyx="true";
     }
     account[5]= notifyx;
     account[6]= document.getElementById(company).value;
     account[7]= document.getElementById(phone).value;
     account[8]= document.getElementById(add1).value;
     account[9]= document.getElementById(add2).value;
     account[10]= document.getElementById(ext).value;
     account[11]= document.getElementById(fax).value;
     account[12]= document.getElementById(city).value;
     
     try
     {
        account[13]=document.getElementById(state).value;
     }
     catch(x)
     {
        account[13]=document.getElementById(statebox).value;
     }
     account[14]= document.getElementById(country).value;
     account[15]= document.getElementById(exttop).value;
     account[16]= document.getElementById(zip).value;
     account[17]= document.getElementById(notes).value;
     account[18]= document.getElementById(notestop).value;
     var tax="false";
     try
     {
         if(document.getElementById(exempt).checked)
         {
            tax="true";
         }
     }
     catch(NoTax)
     {
     }
     account[19]= tax
   
     account[20]=document.getElementById(payment).value;
     var UserCmp="BSI";
     var UserTp="End User";
     var radiobtns=document.getElementsByName('radio_list_company');
     for(var h=0;h<radiobtns.length;h++)
     {   
      if(radiobtns[h].checked)
         {
            UserCmp=radiobtns[h].value;
         }
     }
     radiobtns=document.getElementsByName('radio_list_usertype');
     for(var h=0;h<radiobtns.length;h++)
     {
         if(radiobtns[h].checked)
         {
            UserTp=radiobtns[h].value;
         }
     }
     account[21]=UserCmp;
     account[22]=UserTp;
     account[23]=document.getElementById(telrad).checked.toString();
     var lengthAcnt=account.length;
     for(var j=0;j<lengthAcnt;j=parseInt(j)+1)
     {
        account[j]=RestrictedCharactersCheck(account[j]);
     }
     var errmsg="";
     if(document.getElementById(fname).value=="" && document.getElementById(company).value=="")
     {
         errmsg="FirstName or Company To Be filled to Save The Account";
     }
     if(document.getElementById(userid).value=="")
     {
         errmsg="UserId is Required";
     }
     if(errmsg!="")
     {
          alert(errmsg);
     }
     else
     {
          loading_box();
          var strAccnt=account.join('!');
          var params='accountfunctions.aspx?action=SaveAccount&account='+strAccnt;
          http.open('post',params,true);
          http.onreadystatechange =saveANewAccountBUILD;
          SetHTTP_Header(params);
          http.send(params);
     }
}
function saveANewAccountBUILD()
{
if(http.readyState==4)
 {
      try
      {
      window.clearTimeout(SD); 
      }
      catch(g)
      {
      }
     document.getElementById("formbox").style.display="none";
     var response=http.responseText;
     if(response.indexOf('Existing Account')!=-1)
     {
         alert('We have an existing account with this UserId');
     }
     else
     {
       loginarea(response);
        alert('Saved');
     }
 }
}
function selectCountryFromAccountBUILD(id,txtState)
{

      var _country=document.getElementById(id).value;
      var params='accountfunctions.aspx?action=ChangeCountry&country='+_country;
      http.open('post',params,true);
      http.onreadystatechange =response_country_change_accountBUILD;
      SetHTTP_Header(params);
      http.send(params);
}
function response_country_change_accountBUILD()
{
    if(http.readyState==4)
    {
        var response = http.responseText;
        _custInfo=response.split('<!--state_information_starts_here-->');
        _custInfo=_custInfo[1].split('<!--state_information_ends_here-->');
         document.getElementById('state_div').innerHTML=_custInfo[0];
     }
}
function selectStateFromAccountBUILD(id,plc)
{
      var state=document.getElementById(id).value;
      if(state=="MN")
      {
        document.getElementById('div_exempt_box').style.display="block";
      }
      else
      {
        document.getElementById('div_exempt_box').style.display="none";
      }
//      var params='accountfunctions.aspx?action=ChangeState&state='+state;
//      http.open('post',params,true);
//      http.onreadystatechange =response_state_change_accountBUILD;
//      SetHTTP_Header(params);
//      http.send(params);
}
function response_state_change_accountBUILD()
{
   if(http.readyState==4)
    {
        var response = http.responseText;
        _custInfo=response.split('<!--exempt_information_starts_here-->');
        _custInfo=_custInfo[1].split('<!--exempt_information_ends_here-->');
         document.getElementById('div_exempt_box').innerHTML=_custInfo[0];
     }
}
function Save_Account()
{
 if(http.readyState==4)
 {
      try
      {
      window.clearTimeout(SD); 
      }
      catch(g)
      {
      }
     document.getElementById("formbox").style.display="none";
     var response=http.responseText;
     if(response.indexOf('Existing Account')!=-1)
     {
         alert('We have an existing account with this UserId');
     }
     else
     {
         response_DisplayACCOUNT();
         alert('Saved');
     }
 }
}
function response_ACCOUNT()
{
   if(http.readyState==4)
   {
       var response=http.responseText;
       response_BUILD();
       startStr='<!--companyInfo_starts-->';
       endStr='<!--companyInfo_ends-->';
       IDFill='div_companay';
       response_BUILD();
    }
    
}
function ChangeCountryBilltoBUILD(country)
{
          startStr='<!-- billto_state_starts_here-->';
          endStr='<!-- billto_state_ends_here-->';
          IDFill='div_state_BILL';
          var cntry=document.getElementById(country).value;
          var params='searchbuild.aspx?action=ChangeCountryBillto&country='+cntry;
          http.open('post',params,true);
          http.onreadystatechange = response_BUILD;
          SetHTTP_Header(params);
          http.send(params);
}
function ChangeShipCountryBUILD(country)
{

          startStr='<!--ship_to_state_starts_here-->';
          endStr='<!--ship_to_state_ends_here-->';
          IDFill='div_ship_to_state';
          var cntry=document.getElementById(country).value;
          var params='searchbuild.aspx?action=ChangeCountry&country='+cntry;
          http.open('post',params,true);
          http.onreadystatechange = response_BUILD;
          SetHTTP_Header(params);
          http.send(params);
}

function response_SaveContactBUILD()
{
 if(http.readyState == 4)
   {
    var response = http.responseText;
    var accntArr=new Array();
    try
    {
    accntArr=response.split('<!--account_starts_here-->');
    accntArr=accntArr[1].split('<!--account_ends_here-->');
    document.getElementById('div_account_page').innerHTML= accntArr[0];
    if(response.indexOf('AlreadyExisting UserId')!=-1)
     {
       alert('We have already an Existing account with this UserId');
     }
    else
     {
       alert('Contact Saved');
     }
    }
    catch(OrderPage)
    {
   
    }
   }
}

function addcontactsBUILD()
{
    var params='action=OpenContactField';
    http.open('post','accountfunctions.aspx?'+params,true);
    http.onreadystatechange = response_addcontactsBUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function response_addcontactsBUILD()
{
   if(http.readyState == 4)
     {
       
         var response = http.responseText;
         var contact_info_array=new Array();
         contact_info_array=response.split('<!--contact_fields_starts_here-->');
         contact_info_array=contact_info_array[1].split('<!--contact_fields_ends_here-->');
         document.getElementById('contact_fields').innerHTML=contact_info_array[0];
     }
}


function SaveOrderBUILD()
{
  var radio=document.getElementsByName('radio_status');
  var selected="";
  for(var j=0;j<radio.length;j++)
  {
      if(radio[j].checked)
      {
         selected=radio[j].value;
      }
  }
   
        var params='action=SaveOrder&status='+selected;
        http.open('post','searchbuild.aspx?'+params,true);
        http.onreadystatechange = response_SaveOrder;
        SetHTTP_Header(params);
        http.send(params);
  

}
function SelectContactBUILD_sub()
{
        var numb=document.getElementById('hiden_numbcontacts').value;
        var selected_contact=new Array();
        var ctct=0;
        numb=parseInt(numb);
        for(var j=0;j<numb;j++)
        {
            if(document.getElementById('chk_contact_'+j).checked)
            {
               selected_contact[ctct]=document.getElementById('chk_contact_'+j).value;
               ctct++;
            }
         }
         var joinArr=selected_contact.join(';');
         return joinArr;
}
function SelectContactBUILD()
{
    var joinArr=SelectContactBUILD_sub();
    var params='action=SelectContactForNotify&contacts='+joinArr;
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_nothing_changeBUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function response_nothing_changeBUILD()
{
   if(http.readyState==4)
    {
    
    }
}
function response_SaveOrder()
{
    if(http.readyState==4)
    {
       var response=http.responseText;
       var save=PhoneNumberForAirShip(response);
       if(save)
       {
       
           alert('Saved');
           document.getElementById('div_orders0').innerHTML="<div id=\"save_load\" STYLE=\"width:780px;background-color:gray;height:700px;vertical-align:middle;font-size:14px;font-weight:bold;\"><div id=\"loadingtextL\" style=\"padding-left:200px;padding-top:100px;\" ><FONT COLOR=black>Loading ...<BR>Please Wait...</FONT></div></div>";
           sub_OrdersNewDummy('0','Current');
       }
       else
       {
           alert('The Order Cannot be Saved Without a Valid ShipTo Phone');
       }
    }
}
function sub_allOrderscopy()
{
          http.open('post', 'customer2.aspx');
          http.onreadystatechange = resp_jumpTo_orderspageBUILD;
          http.send(null);
}
function resp_jumpTo_orderspageBUILD()
{
     if(http.readyState == 4)
     {
       
        var response = http.responseText;
        All_orders_in_ordersPageBUILD();
     }
}
function All_orders_in_ordersPageBUILD()
{

  http.open('post', 'orders.aspx');
  http.onreadystatechange = resp_get_orderspage;
  http.send(null);
}
function SelectUserCompany(id)
{
   var radiobtns=document.getElementsByName(id);
   var selected="";
   alert(radiobtns.length);
   for(var j=0;j<radiobtns.length;j++)
   {
      if(radiobtns[j].checked)
      {
         selected=radiobtns[j].value;
      }
   }
    startStr='<!--order_top_starts_here-->';
    endStr='<!--order_top_ends_here-->';
    IDFill='div_order_top';
    var params='action=selectUsercompany&usercompany='+selected;
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);
}

function SelectEditedPrinted(id)
{
  var radio=document.getElementsByName(id);
  var selected="";
  for(var j=0;j<radio.length;j++)
  {
      if(radio[j].checked)
      {
         selected=radio[j].value;
      }
  }
  alert(selected);
    startStr='<!--order_top_starts_here-->';
    endStr='<!--order_top_ends_here-->';
    IDFill='div_order_top';
    var params='action=selectEdited_Printed&printed='+selected;
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);

}
function saveOptionalBUILD(billby,notes,pio,reference,sticker,accnt,zip,selectbillby)
{
    var radio=document.getElementsByName(billby);
    var selected="";
    for(var j=0;j<radio.length;j++)
    {
        if(radio[j].checked)
        {
           selected=radio[j].value;
        }
    }
  var note=RestrictedCharactersCheck(document.getElementById(notes).value);
  var po=document.getElementById(pio).value;
  var ref=document.getElementById(reference).value;
  var stckr=document.getElementById(sticker).checked;
  var accntnumber="";
  var zipcode="";
  try
  {
      accntnumber=document.getElementById(accnt).value;
      zipcode=document.getElementById(zip).value;
  }
  catch(ifnoThirdparty)
  {
  }
    var params='action=SaveOptional&billby='+selected+'&notes='+note+'&pio='+po+'&ref='+ref+'&sticker='+stckr+'&accnt='+accntnumber+'&zip='+zipcode;
    startStr='<!--OptionalInfo_starts_here-->';
    endStr='<!--OptionalInfo_ends_here-->';
    IDFill='FillArea';
    IDFill='FillArea';
    http.open('post','buildshipping.aspx?'+params,true);
    if(selectbillby=="billby")
    {
    http.onreadystatechange = response_BUILD;
    }
    else
    {
    http.onreadystatechange = response_saveptionalBUILD;
    }
    SetHTTP_Header(params);
    http.send(params);
}
function response_saveptionalBUILD()
{
    if(http.readyState==4)
    {
        response_BUILD();
        alert('saved');
    }
}
function selectBillByBUILD(billby,notes,pio,reference,sticker,accnt,zip)
{
   saveOptionalBUILD(billby,notes,pio,reference,sticker,accnt,zip,'billby');
}
function DoneWeightBUILD(weight,insured,packtype)
{
     document.getElementById('div_selectTypeLoad').style.display="block";
     startStr='<!--shipping_starts_here-->';
     endStr='<!--shipping_ends_here-->';
     IDFill='FillArea';
     var wt="";
     try
     {
       wt=document.getElementById(weight).value;
     }
     catch(ifLetter)
     {
     }
     var ins=document.getElementById(insured).value;
     var params='action=SaveAirShipDetails&weight='+wt+'&insured='+ins;
     http.open('post','buildshipping.aspx?'+params,true);
     http.onreadystatechange = response_BUILD;
     SetHTTP_Header(params);
     http.send(params);
}
function done_packagesBUILD(length,width,height,weight,insured)
  {
     document.getElementById('div_selectTypeLoad').style.display="block";
     var ln=document.getElementById(length).value;
     var wd=document.getElementById(width).value;
     var ht=document.getElementById(height).value;
     var wt=document.getElementById(weight).value;
     var ins=document.getElementById(insured).value;
     startStr='<!--shipping_starts_here-->';
     endStr='<!--shipping_ends_here-->';
     IDFill='FillArea';
     var params='action=DonePackages&packtype=Normal&length='+ln+'&width='+wd+'&height='+ht+'&weight='+wt+'&insured='+ins;
     http.open('post','buildshipping.aspx?'+params,true);
     http.onreadystatechange = response_BUILD;
     SetHTTP_Header(params);
     http.send(params);
  }
function SaveIntlDescBUILD(id,processindid,event)
{
    if(checkForEnterKeyBUILD(event))
    {
        document.getElementById(processindid).innerHTML="Processing...........";
        var desc=document.getElementById(id).value;
        startStr='<!--shipping_starts_here-->';
        endStr='<!--shipping_ends_here-->';
        IDFill='FillArea';
        var params='action=SaveIntlDesc&Desc='+desc;
        http.open('post','buildshipping.aspx?'+params,true);
        http.onreadystatechange = response_BUILD;
        SetHTTP_Header(params);
        http.send(params);
    }
}
function DisplayWeightBoxBUILD(id,descLbl)
{
    document.getElementById('div_selectTypeLoad').style.display="block";
    var buttonlist=document.getElementsByName(id);
    var selected="Normal";
    for(var i=0;i<buttonlist.length;i++)
    {
         if(buttonlist[i].checked)
         {
            selected=buttonlist[i].value;
         }
    }
    startStr='<!--shipping_starts_here-->';
    endStr='<!--shipping_ends_here-->';
    IDFill='FillArea';
    var params='action=SelectPackType&Type='+selected;
    http.open('post','buildshipping.aspx?'+params,true);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function SelectServiceBUILD(ddn,descLbl)
{
    document.getElementById(descLbl).innerHTML="Processing.......";
    var service=document.getElementById(ddn).value;
    startStr='<!--shipping_starts_here-->';
    endStr='<!--shipping_ends_here-->';
    IDFill='FillArea';
    var params='action=SelectService&service='+service;
    http.open('post','buildshipping.aspx?'+params,true);
    http.onreadystatechange =response_selectService;
    SetHTTP_Header(params);
    http.send(params);
  
}
function PhoneNumberForAirShip(response)
{
        var save=true;
       if(response.indexOf('No Phone Selected')!=-1)
        {
        save=false;
          alert('For the selected service,You must add a PhoneNumber with the shippto Address');
        }
        return save;
}
function response_selectService()
{
    if(http.readyState==4)
    {
         var response=http.responseText;
         var save=PhoneNumberForAirShip(response);
         Fill_area_BUILD(response,startStr,endStr,IDFill);
       
    }
}
function checkForEnterKeyBUILD(event)
{
      var enterkey=false;
      var frfx=false;
      if(window.event)
      {
        key = window.event.keyCode;     //IE
      }
      else
      {
       frfx=true;
       
      }
      if(frfx)
      {
          if(e.which==13)
          {
            enterkey=true;
          }
      }
      else
      {
        if (key == 13)
        {
          enterkey=true;
        }
      }
      return enterkey;
}
function orderBUILD(id,query)
{  
    var params='action=addto_order&productID='+id+'&'+query;
    http.open('post','popups.aspx?'+params,true);
    http.onreadystatechange = handleResponse_Order_popup;
    SetHTTP_Header(params);
    http.send(params);
}
function manual_add_itemsBUILD()
{
 document.getElementById('manual_itm').style.display="block";
}

function cancel_BoxesBUILD()
{
document.getElementById('manual_pack').style.display="none";
}
function CreateBoxBUILD()
{
  document.getElementById('manual_pack').style.display="block";
}
function BUILD_SHIPPING(action)
{
    switch(action)
    {
        case "DisplayShipping":
            makeLinkColorBUILD('btn_shipping');
            startStr='<!--shipping_starts_here-->';
            endStr='<!--shipping_ends_here-->';
            IDFill='FillArea';
        break;
        case "DisplayOptionalInfo":
            makeLinkColorBUILD('btn_optional');
            startStr='<!--OptionalInfo_starts_here-->';
            endStr='<!--OptionalInfo_ends_here-->';
            IDFill='FillArea';
        break;
    }
    var params='action='+action;
    IDFill='FillArea';
    http.open('post','buildshipping.aspx?'+params,true);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);
}

function DeleteItemBUILD(id)
 {
    startStr='<!--item_table_starts_here-->';
    endStr='<!--item_table_ends_here-->';
    IDFill='FillArea';
    var params='action=Delete_Product&productId='+id;
    http.open('post','itemsfororder.aspx?'+params,true);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);
 }
 function GetBillByBUILD(event,id,idtext)
 {
 if(document.getElementById(id).value!="")
    {
        if(document.getElementById(id).value!="shipper")
        {
          document.getElementById(idtext).value="";
          alert('You cant change the ship price if UPS bill by is Receiver/Thirdparty');
        }
        else
        {
           if(checkForEnterKeyBUILD(event))
           {
            var count=document.getElementById('hiden_count').value;
            UpdateItemsBUILD(count);
           }
        }
    }
    else
    {
     if(checkForEnterKeyBUILD(event))
       {
        var count=document.getElementById('hiden_count').value;
        UpdateItemsBUILD(count);
       }
    }
 }
function UpdateIfEnterBUILD(event)
{
     if(checkForEnterKeyBUILD(event))
       {
        var count=document.getElementById('hiden_count').value;
        UpdateItemsBUILD(count);
       }
}
function UpdateItemsBUILD(ct)
{
    startStr='<!--item_table_starts_here-->';
    endStr='<!--item_table_ends_here-->';
    IDFill='FillArea';
    var subparams=UpadetItemFun(ct);
    var params='action=updateItems&'+subparams;
    http.open('post','itemsfororder.aspx?'+params,true);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function UpadetItemFun(ct)
{
    var coun=parseInt(ct)+1;
    var ship="";
    var price;
    var qty;
    var productid;
    var manualItem;
    var arr=new Array();
    var prodarr=new Array(); 
    var qtyarray =new Array(); 
    var exemptArr=new Array();
    var _exempItems="";
    try
    {
       ship=document.getElementById('txt_shipping').value;
    }
    catch(Pickup)
    {
    }
    for(var y=0;y<coun;y++)
    {
        _exempItems="";
        try
        {
            ship=document.getElementById('txt_shipping').value;
            if(document.getElementById('chk_exempt_item'+y)!=null)
            {
                if(document.getElementById('chk_exempt_item'+y).checked)
                {
               _exempItems="Exempt";
                }
               else
                {
                _exempItems="Include";
                }
            }
        }
        catch(f)
        {
        }
        price=document.getElementById('txt_price'+y).value;
        qty=document.getElementById('txt_qty'+y).value;
        productid=document.getElementById('hiden_prodid'+y).value;
        exemptArr[y]=_exempItems;
        arr[y]=price;
        qtyarray[y]=qty;
        prodarr[y]=productid;
    }
    var _exempt=exemptArr.join(',');
    var price=arr.join('-');
    var prod=prodarr.join('?');
    var qtyar=qtyarray.join(',');
    var subParams='pricearr='+price+'&prodarr='+prod+'&qtyarr='+qtyar+'&ship='+ship+'&exemptItemarr='+_exempt;
    return subParams;
}
function UpdateOrderPopUpBUILD(event)
{
  if(checkForEnterKeyBUILD(event))
   {
        var ct=document.getElementById('hiden_count').value;
        var subparams=UpadetItemFun(ct);
        var params='action=updateOrderItems&'+subparams;
        http.open('post','popups.aspx?'+params,true);
        http.onreadystatechange = handleResponse_Order_popup;
        SetHTTP_Header(params);
        http.send(params);
    }
}
function DoneItemsBUILD(ct)
{
    var subparams=UpadetItemFun(ct);
    var params='action=DoneItems&'+subparams;
    startStr='<!--item_table_starts_here-->';
    endStr='<!--item_table_ends_here-->';
    IDFill='FillArea';
    http.open('post','itemsfororder.aspx?'+params,true);
    http.onreadystatechange = response_DoneItemsBUILD;
    SetHTTP_Header(params);
    http.send(params);
   
}
function response_DoneItemsBUILD()
{
    if(http.readyState==4)
    {
      window.location="ordersystem.aspx";return false;
    }
}
function update_manualBUILD(qty,desc,price)
{
  var q=document.getElementById(qty).value;
  var d=document.getElementById(desc).value;
  d=d.replace("&","and");
  d=d.replace("'","\"\"");
  var p=document.getElementById(price).value;
  startStr='<!--item_table_starts_here-->';
  endStr='<!--item_table_ends_here-->';
  IDFill='FillArea';
  var params='action=update_manual&qty='+q+'&desc='+d+'&price='+p;
  http.open('post','itemsfororder.aspx?'+params,true);
  http.onreadystatechange = response_BUILD;
  SetHTTP_Header(params);
  http.send(params);
}
function BUILD_ITEMS(action)
{
    switch(action)
    {
    case "DisplayItems":
        startStr='<!--item_table_starts_here-->';
        endStr='<!--item_table_ends_here-->';
        IDFill='FillArea';
        break;
    }
    var params='action='+action;
    http.open('post','itemsfororder.aspx?'+params,true);
    http.onreadystatechange = response_BUILDITEMS;
    SetHTTP_Header(params);
    http.send(params);
}
var sectionToreturnFn="";
var sectionToreturnParam="";
function DisplayTopCommon(sectionFunction,sectionParam)
{
    sectionToreturnFn=sectionFunction;
    sectionToreturnParam=sectionParam;
    var params='action=DisplayOrderTop';
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_DisplayTopCommon;
    SetHTTP_Header(params);
    http.send(params);
}
function response_DisplayTopCommon()
{
   if(http.readyState==4)
    {
      var response=http.responseText;
      startStr='<!--order_top_starts_here-->';
      endStr='<!--order_top_ends_here-->';
      IDFill='div_order_top';
      Fill_area_BUILD(response,startStr,endStr,IDFill);
      var jk=sectionToreturnFn+"('"+sectionToreturnParam+"')";
      eval(jk);
      
    }
}



function response_BUILDITEMS()
{
    if(http.readystate==4)
    {
        response_BUILD();
        DisplayOrderTop();
    }
}
function response_BUILD_Items_sub()
{
    if(http.readystate==4)
    {
        response_BUILD();
        makeLinkColorBUILD('btn_items');
    }
}
function ClickAddItemsBUILD()
{
  window.location="products.aspx";
}
function click_paypalBUILD(id,ebaynumber)
{
    var radioButtons = document.getElementsByName(id);
    var method="Instant Payment";
    var ebaynumber=document.getElementById(ebaynumber).value;
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
             method=radioButtons[x].value;
           }
     }
          startStr='<!--payment_area_starts_here-->';
          endStr='<!--payment_area_ends_here-->';
          IDFill='FillArea';
          var params='searchbuild.aspx?action=Click_paypal&method='+method+'&ebaynumber='+ebaynumber;
          http.open('post',params,true);
          http.onreadystatechange = response_BUILD;
          SetHTTP_Header(params);
          http.send(params);
}
function SelectCreditCardBUILD(id)
{
          startStr='<!--payment_area_starts_here-->';
          endStr='<!--payment_area_ends_here-->';
          IDFill='FillArea';
          var params='searchbuild.aspx?action=SelectCreditCard&id='+id;
          http.open('post',params,true);
          http.onreadystatechange = response_BUILD;
          SetHTTP_Header(params);
          http.send(params);
}
function ClickCardTypeBUILD(id)
{
          var cardnumber=document.getElementById(id).value;
          startStr='<!--cardType_Area_start_here-->';
          endStr='<!--cardType_Area_end_here-->';
          IDFill='div_cardtype';
          var params='searchbuild.aspx?action=CreditCardNumberOnEnter&cardnumber='+cardnumber;
          http.open('post',params,true);
          http.onreadystatechange = response_BUILD;
          SetHTTP_Header(params);
          http.send(params);
}
function ClickEnterKeyonCardNumberBUILD(id,event)
{
      if(checkForEnterKeyBUILD(event))
      {
          ClickCardTypeBUILD(id);
      }
}
function RestrictedCharactersCheck(value)
{
     if(value.indexOf('\'')!=-1)
     {
        value=value.replace(/\'/g,"''");
     }
     if(value.indexOf('&')!=-1)
     {
        value=value.replace(/&/g,encodeURIComponent('&'));
     }
     return value;
}
function save_paymentBUILD(radio_paypal,radioPayment,ebaynumber,clearingdate,codamount,cardtype,cardnumber,cardid,cardname,cardmonth,cardyear,notes)
{  
    var dontpostback=false;
    close_all_ship('all_cardDetails','div_open_cards');
    var radioButtons = document.getElementsByName(radioPayment);
    var exp="CreditCard";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
           exp=radioButtons[x].value;
            
           }
     }
     var payment=new Array();
     switch(exp)
     {
     default:
     var nts="";
     try
     {
        var nts=RestrictedCharactersCheck(document.getElementById(notes).value);
     }
     catch(f)
     {
     }
     payment[0]=nts;
     break;
     case "CreditCard":
     payment[0]=document.getElementById(cardtype).innerHTML;
     payment[1]=document.getElementById(cardnumber).value;
     payment[2]=document.getElementById(cardid).value;
     payment[3]=RestrictedCharactersCheck(document.getElementById(cardname).value);
     payment[4]=document.getElementById(cardmonth).value;
     payment[5]=document.getElementById(cardyear).value;
     var msg="Some of the CreditCard fields are missing or Invalid";
     var d = new Date();
     var curr_month = d.getMonth();
     var curr_year = d.getFullYear();
     var _lenYear=curr_year.toString().length;
     var _postion=parseInt(_lenYear)-2;
     for(var j=0;j<payment.length;j++)
     {
      if(payment[j].toString().length>0)
       {
           if(j==1)
           {
                   var lengthOfnumber=16;
                   if(payment[j].toString().substring(0,1).toString()=="3")
                   {
                     lengthOfnumber=15;
                   }
                    if(payment[j].toString().length!=lengthOfnumber)
                    {
                      msg=" Number of digits in CreditCard number is wrong";
                      dontpostback=true;
                    }
           }
           if(j==4 || j==5)
           {
                 if(payment[j].toString().length!=2)
                 {
                 msg="CreditCard month & year should be filled with 2 digits";
                 dontpostback=true;
                 }
                 if(document.getElementById(cardmonth).value!="")
                 {
                 
                     if(document.getElementById(cardmonth).value>12)
                     {
                        msg="Invalid CreditCard Month";
                        dontpostback=true;
                     }
                 }
                  if(document.getElementById(cardyear).value!="")
                  {
                   if(document.getElementById(cardyear).value<curr_year.toString().substring(_postion,4).toString())
                     {
                        msg="Invalid CreditCard Year";
                     }
                  }
                 if(document.getElementById(cardyear).value!="" && document.getElementById(cardmonth).value!="")
                 {
                    if(document.getElementById(cardyear).value==curr_year.toString().substring(_postion,4).toString())
                     {
                   
                         if(document.getElementById(cardmonth).value<curr_month)
                         {
                            msg="Invalid CreditCard Month";
                            dontpostback=true;
                         }
                     }
                 }  
          
           }
             if(j!=0 && j!=3)
             {
               if(isNaN(payment[j].toString()))
               {
              
              
                  msg="Some of the CreditCard fields are missing or Invalid";
                  dontpostback=true;
                  if(j==1)
                  {
                 
                    if(payment[j].toString().indexOf('*')!=-1)
                    {
                     msg="";
                     dontpostback=false;
                    }
                  }
                
               }
             }
        }
          
     }
     break;
     case "COD":
     payment[0]=document.getElementById(codamount).value;
     break;
     case "COD Certified":
     payment[0]=document.getElementById(codamount).value;
     break;
     case "PayPal":
     payment[0]=RestrictedCharactersCheck(document.getElementById(ebaynumber).value);
     var radioebay = document.getElementsByName(radio_paypal);
      for (var x = 0; x < radioebay.length; x ++) 
      {
           if (radioebay[x].checked) 
           {
             payment[1]=radioebay[x].value;
            
           }
     }
     if( payment[1].toString().toLowerCase()=="e-check")
     {
       payment[2]=document.getElementById(clearingdate).value;
     }
     else
     {
       payment[2]="";
     }
     break;
  } 
        var paymntar=payment.join('!');
      
        if(dontpostback)
        {
           alert(msg);
        }
        else
        {
          startStr='<!--payment_area_starts_here-->';
          endStr='<!--payment_area_ends_here-->';
          IDFill='FillArea';
          var params='searchbuild.aspx?action=save_payment&method='+exp+'&payment='+paymntar;
          http.open('post',params,true);
          http.onreadystatechange = response_save_paymentBUILD;
          SetHTTP_Header(params);
          http.send(params);
        }

}
function response_save_paymentBUILD()
{
    if(http.readyState==4)
    {
       response_BUILD();
       alert('saved');
    }
}
function SetHTTP_Header(params)
{
 http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 http.setRequestHeader("Content-length", params.length);
 http.setRequestHeader("Connection", "close");
}

function payment_selectedBUILD(id)
{
  var paymentType="";
  var paymentlist=document.getElementsByName(id);
  for(var k=0;k<paymentlist.length;k++)
  {
      if(paymentlist[k].checked)
      {
       paymentType=paymentlist[k].value;
      }
  }
  startStr='<!--payment_area_starts_here-->';
  endStr='<!--payment_area_ends_here-->';
  IDFill='FillArea';
  var params='searchbuild.aspx?action=selectPayment&method='+paymentType;
  http.open('post',params,true);
  http.onreadystatechange = response_BUILD;
  SetHTTP_Header(params);
  http.send(params);
  
}
function save_ship_addressBUILD(contact,ext,fax,txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state,country,state_text,shipSaveBtn)
{  
     var shipping=new Array();
     var _shipTostate="";
         try
         {
         _shipTostate=document.getElementById(state).value;
         }
         catch(y)
         {
         }
         if(_shipTostate=="")
         {
             try
             {
             _shipTostate=document.getElementById(state_text).value;
             }
             catch(y)
             {
             }
         }
     
       
     shipping[0]= document.getElementById(txt_fname).value;
     shipping[1]=document.getElementById(txt_city).value;
     shipping[2]=document.getElementById(txt_add1).value;
     shipping[3]=_shipTostate;
     shipping[4]=document.getElementById(txt_add2).value;
     shipping[5]=document.getElementById(txt_zip).value;
     shipping[6]=document.getElementById(txt_phone).value;
     shipping[7]=document.getElementById(txt_email).value;
     shipping[8]=document.getElementById(txt_company).value;
     shipping[9]=document.getElementById(txt_lastname).value;
     shipping[10]=document.getElementById(ext).value;
     shipping[11]=document.getElementById(contact).value;
     shipping[12]=document.getElementById(fax).value;
     shipping[13]=document.getElementById(country).value;
     var emptyshipaddress=false;
     for(var t=0;t<shipping.length;t=parseInt(t)+1)
     {
        if(t==8)
         {
             if(shipping[t].toString()=="")
             {
               if(shipping[0].toString()=="")
               {
                  emptyshipaddress=true;
               }
             }
         }
         if(t==1 || t==2 || t==3 || t==5 || t==13)
         {
             if(shipping[t].toString()=="")
             {
             if(t==3)
             {
                 if(document.getElementById(country).value!="US" || document.getElementById(country).value!="CA")
                 {
                   emptyshipaddress=false;
                 }
                 else
                 {
                   emptyshipaddress=true;
                 }
             }
             else
             {
                emptyshipaddress=true;
             }
                
             }
         }
         shipping[t]=RestrictedCharactersCheck(shipping[t].toString())
     }
     if(!emptyshipaddress)
     {
          var action="SaveShipAddress";
          if(document.getElementById(shipSaveBtn).value=="Update")
          {
            action="UpdateShipAddress";
          } 
          startStr='<!--shipping address starts here-->';
          endStr='<!--shipping address ends here-->';
          IDFill='FillArea';
          var shippingarra=shipping.join('*');
          var params='searchbuild.aspx?action='+action+'&shipping_address='+shippingarra;
          http.open('post',params,true);
          http.onreadystatechange = AlertWithReplace;
          SetHTTP_Header(params);
          http.send(params);
     }
     else
     {
       alert('One of The fields in Shipping Address is Missing or Invalid');
     }
}
function AlertWithReplace()
{
   if(http.readyState==4)
    {
      var response=http.responseText;
        if(response.indexOf('Unable to Update')!=-1)
        {
         alert('Unable to Update');
        }
        else
        {
         alert('Saved');
        }
      response_BUILD();
    }
}
function alertSavedOrNot()
{
    if(http.readyState==4)
    {
        var response=http.responseText;
        if(response.indexOf('Unable to Update')!=-1)
        {
         alert('Unable to Update');
        }
        else
        {
         alert('Saved');
        }
    }

}
var startStr="";
var endStr="";
var IDFill="";
function verifyShipAddressBUILD(city,statetxtbox,statedrpdwn,country,zip)
{
    var cty=document.getElementById(city).value;
    var state="";
    try
    {
      state=document.getElementById(statetxtbox).value;
    }
    catch(ifNostatebox)
    {
    }
    if(state=="")
    {
      state=document.getElementById(statedrpdwn).value;
    }
    var zipcode=document.getElementById(zip).value;
    var cntry=document.getElementById(country).value;
    var params='action=VerifyAddress&city='+cty+'&state='+state+'&zip='+zipcode+'&country='+cntry;
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_verifyAddress_BUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function response_verifyAddress_BUILD()
{
    if(http.readyState == 4)
    {
       var response = http.responseText;
       var billing_add=new Array
       billing_add=response.split('verification Result:');
       if(billing_add[1].indexOf('verification done')!=-1)
         {
              var new_bill=new Array();
              new_bill=billing_add[1].split('verification done');
         }
       try
        {
         alert(new_bill[0]);
        }
        catch(u)
        {
        }
    }
}
function select_shipBUILD(action,id)
{

    startStr='<!--shipping address starts here-->';
    endStr='<!--shipping address ends here-->';
    IDFill='FillArea';
    var params='action='+action+'&shipId='+id;
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function clickPickUpBUILD(checkBoxId)
{
    var pickUp=false;
    if(document.getElementById(checkBoxId).checked)
    {
      pickUp=true;
    }
    startStr='<!--shipping address starts here-->';
    endStr='<!--shipping address ends here-->';
    IDFill='FillArea';
    var params='action=ClickPickUp&pickup='+pickUp;
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function clickBlindBUILD(checkBoxId)
{
    var Blindship=false;
    if(document.getElementById(checkBoxId).checked)
    {
      Blindship=true;
    }
   
    var params='action=ClickBlindShip&blindship='+Blindship;
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_nothing_changeBUILD;
    SetHTTP_Header(params);
    http.send(params);
   
}

function BillTo()
{

  startStr='<!--billing address starts here-->';
  endStr='<!--billing address ends here-->';
  IDFill='FillArea';
    var params='action=DisplayBillTo';
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_BillToBUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function makeLinkColorBUILD(id)
{
   document.getElementById(id).className="BUILD_topButtonLinkVisited";
}
function response_BillToBUILD()
{
    if(http.readyState==4)
    {
      var response=http.responseText;
      loginarea(response);
      response_BUILD();
      makeLinkColorBUILD('btn_billto');
      DisplayOrderTop();
    }
}
function DisplayOrderTop()
{
    var params='action=DisplayOrderTop';
    http.open('post','searchbuild.aspx?'+params,true);
    http.onreadystatechange = response_OrderTop;
    SetHTTP_Header(params);
    http.send(params);
}
function response_OrderTop()
{
   if(http.readyState==4)
    {
      startStr='<!--order_top_starts_here-->';
      endStr='<!--order_top_ends_here-->';
      IDFill='div_order_top';
      response_BUILD();
    }
}
function response_DisplayShippingBUILD()
{
    if(http.readyState==4)
    {
       makeLinkColorBUILD('btn_shipto');
       response_BUILD();
       open_all_ship('ship_pop','div_open_ship_addrs');
    }
}
function BuildOrder(action)
{
   
    switch(action)
    {
    case "ClickNewAddress":
         startStr='<!--shipping address starts here-->';
         endStr='<!--shipping address ends here-->';
         IDFill='FillArea';
         break;
     case "DisplayBillTo":
         BillTo();
         break;
     case "DisplayShipTo":
        startStr='<!--shipping address starts here-->';
        endStr='<!--shipping address ends here-->';
        IDFill='FillArea';
        break;
    case "SameAsBillTo":
        startStr='<!--shipping address starts here-->';
        endStr='<!--shipping address ends here-->';
        IDFill='FillArea';
        break;
    case "DisplayPayment":
        makeLinkColorBUILD('btn_payment');
        startStr='<!--payment_area_starts_here-->';
        endStr='<!--payment_area_ends_here-->';
        IDFill='FillArea';
        break;
      }
    if(action!="DisplayBillTo")
    {
        var params='action='+action;
        http.open('post','searchbuild.aspx?'+params,true);
        if(action=="DisplayShipTo")
        {
          http.onreadystatechange = response_DisplayShippingBUILD;
        }
        else
        {
          http.onreadystatechange = response_BUILD;
        }
        SetHTTP_Header(params);
        http.send(params);
    }
}

function UpdateBillingBUILD(usercompany,usertype,customernotes,contact,ext,fax,txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state,country)
{
  var radioButton = document.getElementById(usercompany+"_1");
   var userCmp="BSI";
   if(radioButton.checked)
       {
       userCmp="TIGER";
       }
   radioButton = document.getElementById(usertype+"_1");
   var userTyp="End User";
   if(radioButton.checked)
     {
      userTyp="Dealer";
     }
    var str=document.getElementById(txt_email).value;
    if(document.getElementById(txt_email).value=="")
      {
         alert('Enter a valid Email Address to create a new account');
         saving_all_details=false;
      }
      else
       {
         billing_correct=true;
         var billing=new Array();
         billing[0]=RestrictedCharactersCheck(document.getElementById(txt_fname).value);
         billing[1]=RestrictedCharactersCheck(document.getElementById(txt_city).value);
         billing[2]=RestrictedCharactersCheck(document.getElementById(txt_add1).value);
         billing[3]=RestrictedCharactersCheck(document.getElementById(state).value);
         billing[4]=RestrictedCharactersCheck(document.getElementById(txt_add2).value);
         billing[5]=RestrictedCharactersCheck(document.getElementById(txt_zip).value);
         billing[6]=RestrictedCharactersCheck(document.getElementById(txt_phone).value);
         billing[7]=RestrictedCharactersCheck(document.getElementById(txt_email).value);
         billing[8]=RestrictedCharactersCheck(document.getElementById(txt_company).value);
         billing[9]=RestrictedCharactersCheck(document.getElementById(txt_lastname).value);
         billing[10]=RestrictedCharactersCheck(document.getElementById(contact).value);
         billing[11]=RestrictedCharactersCheck(document.getElementById(fax).value);
         billing[12]=RestrictedCharactersCheck(document.getElementById(ext).value);
         billing[13]=RestrictedCharactersCheck(document.getElementById(customernotes).value);
         billing[14]=userCmp;
         billing[15]=userTyp;
         billing[16]=document.getElementById(country).value;
        
         for(var t=0;t<billing.length;t++)
         {
           if(billing[t].indexOf("&")>0)
           {
              billing[t]=billing[t].replace("&","and");
           }
         }
         
        var contacts=SelectContactBUILD_sub();
        var billingarra_savebilling="";
        billingarra_savebilling=billing.join('*');
        var params='action=updateCustomerInfo&contacts='+contacts+'&billing='+billingarra_savebilling
        http.open('post','searchbuild.aspx?'+params,true);
        http.onreadystatechange = response_alert_savedBUILD;
        SetHTTP_Header(params);
        http.send(params);
     }           
}
function response_alert_savedBUILD()
{
 if(http.readyState == 4)
    {
    alert('saved');
    }
}



function BUILDselectSUB(customerid)
{

    var params='action=selectCustFromList&custid='+customerid;
    window.location="buildorder.aspx?"+params;
   
}
function BUILDselect(customerid)
{

    startStr='<!--billing address starts here-->';
    endStr='<!--billing address ends here-->';
    IDFill='FillArea';
    try
    {
    close_all_ship('dekpopup','link_open_customer');
    }
    catch(g)
    {
    }
    var params='action=select_customer&custid='+customerid;
    http.open('post','searchbuild.aspx?action=select_customer&custid='+customerid,true);
    http.onreadystatechange = response_BillToBUILD;
    SetHTTP_Header(params);
    http.send(params);
}
function response_BUILD()
{
  if(http.readyState == 4)
    {
       var response = http.responseText;
       Fill_area_BUILD(response,startStr,endStr,IDFill);
    }
}
function Fill_area_BUILD(response,start,end,IDtoFill)
{

    var billing_add=new Array
    billing_add=response.split(start);
    var new_bill=new Array();
    if(billing_add[1].indexOf(end)!=-1)
    {
        new_bill=billing_add[1].split(end);
    }
    try
    {
        document.getElementById(IDtoFill).innerHTML=new_bill[0];
    }
    catch(u)
    {
       alert(u);
    }
} 

function onenterkeyBUILD(usercompany,usertype,contact,ext,fax,txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state,country,e)
 {
       disbal_company(txt_company);
       var srchword=document.getElementById(txt_fname).value+"!"+document.getElementById(txt_city).value+"!";
       srchword+=document.getElementById(txt_add1).value+"!"+document.getElementById(state).value+"!";
       srchword+=document.getElementById(txt_add2).value+"!"+document.getElementById(txt_zip).value+"!";
       srchword+=document.getElementById(txt_phone).value+"!"+document.getElementById(txt_email).value+"!";
       srchword+=document.getElementById(txt_company).value+"!"+document.getElementById(txt_lastname).value+"!";
       srchword+=''+"!"+document.getElementById(ext).value+"!"+document.getElementById(fax).value;
       var radioButton = document.getElementById(usercompany+"_1");
       var userCmp="BSI";
       if(radioButton.checked)
       {
       userCmp="TIGER";
       }
       radioButton = document.getElementById(usercompany+"_2");
       if(radioButton.checked)
       {
       userCmp="";
       }
       radioButton = document.getElementById(usertype+"_1");
       var userTyp="End User";
       if(radioButton.checked)
       {
       userTyp="Dealer";
       }
       radioButton = document.getElementById(usertype+"_2");
       if(radioButton.checked)
       {
       userTyp="";
       }
       srchword+="!"+userCmp+"!"+userTyp+"!"+'';
       srchword+="!"+document.getElementById(country).value;
       var params='srchword='+srchword;
       http.open('post', 'searchbuild.aspx?srchword='+srchword);
       http.onreadystatechange = handleResponsepopupBUILD;
       SetHTTP_Header(params);
       http.send(params);
       
  }
function handleResponsepopupBUILD()
{
  if(http.readyState == 4)
    {
      var response = http.responseText;
     
      if(response.indexOf('No Data Available')!=-1)
      {
        popupvisible('No Data Available');
      }
      else
      {
        var update = new Array();
        if(response.indexOf('<!--Search Result Start Here-->')!= -1) 
         {
            update = response.split('<!--Search Result Start Here-->');
         }
        var responsepart=update[1].toString();
        var arr=new Array();
        var t= update[1].indexOf('<!--Search Result End Here-->');
        if(t!= -1)
            {
                arr = responsepart.split('<!--Search Result End Here-->');
            }
        popupvisible(arr[0]);
      }
   }
}
function onChangeContactsNewOrderBUILD(id)
{
    var _orderBy=document.getElementById(id).value;
    var params='action=SelectOrderBy&orderby='+_orderBy;
    http.open('post', 'searchbuild.aspx?action=SelectOrderBy&orderby='+_orderBy);
    http.onreadystatechange = response_nothing_tochange;
    SetHTTP_Header(params);
    http.send(params);
}
function clearShippingBUILD(txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state,contact,fax,ext,country,txt_state)
{
    try
    {
     document.getElementById(txt_state).value="";
    }
    catch(f)
    {
    }
    document.getElementById(txt_fname).value="";
    document.getElementById(txt_city).value="";
    document.getElementById(txt_add1).value="";
    document.getElementById(state).value="";
    document.getElementById(txt_add2).value="";
    document.getElementById(txt_zip).value="";
    document.getElementById(txt_phone).value="";
    document.getElementById(txt_email).value="";
    document.getElementById(txt_company).value="";
    document.getElementById(txt_lastname).value="";
    document.getElementById(contact).value="";
    document.getElementById(fax).value="";
    document.getElementById(ext).value="";
    document.getElementById(country).value="US";
    var params='action=ClearShipAddress';
    http.open('post', 'searchbuild.aspx?'+params);
    http.onreadystatechange = response_BUILD;
    SetHTTP_Header(params);
    http.send(params);
    
}
function response_nothingBUILD()
{
}
function clearbillingBUILD(usercompany,usertype,txt_customernotes,txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state,contact,fax,ext,addrss,country,txt_state)
{
    try
    {
    document.getElementById(txt_state).value="";
    }
    catch(f)
    {
    }
    document.getElementById(txt_fname).value="";
    document.getElementById(txt_city).value="";
    document.getElementById(txt_add1).value="";
    document.getElementById(state).value="";
    document.getElementById(txt_add2).value="";
    document.getElementById(txt_zip).value="";
    document.getElementById(txt_phone).value="";
    document.getElementById(txt_email).value="";
    document.getElementById(txt_company).value="";
    document.getElementById(txt_lastname).value="";
    document.getElementById(contact).value="";
    document.getElementById(fax).value="";
    document.getElementById(ext).value="";
    document.getElementById(txt_customernotes).value="";
    document.getElementById(country).value="US";
    var radioButton = document.getElementById(usercompany+"_2");
    radioButton.checked=true;
    radioButton = document.getElementById(usertype+"_2");
    radioButton.checked=true;
    document.getElementById('div_popUp_contacts_dup').innerHTML="";
    try
    {
      document.getElementById('div_Links').style.display="none";
    }
    catch(ifnoElement)
    {
    }
}
function Save_contact_order_pageBUILD(action)
{
    if(document.getElementById('btn_save_contact').value!="SaveContact")
    {
      action="Update Contact";
    }
    var contact=new Array()
    contact=Set_up_Array_Contacts_BUILD();
    SaveContact_BUILD(action,contact);
    
}
var contactIdToEdit="";
function editContactBUILD(id,action)
{
    contactIdToEdit=id;
    http.open('post', 'searchbuild.aspx?action='+action+'&id='+id);
    http.onreadystatechange = response_edit_contact_order_page;
    var params='action='+action+'&id='+id;
    SetHTTP_Header(params);
    http.send(params);
}
function SaveContact_BUILD(action,contact)
{
    var _cont=true; 
    if(contact[0].toString()=="" || contact[2].toString()=="" )
     {
        alert('Firstname or UserId is Not Filled');
       _cont=false;
     }
     if(_cont)
     {
        var cont=contact.join('!');
        var params='action='+action+'&contacts='+cont;
        http.open('post', 'searchbuild.aspx?action='+action+'&contacts='+cont);
        http.onreadystatechange = response_SaveContact_order_pageBUILD;
        SetHTTP_Header(params);
        http.send(params);
     }
}
function response_SaveContact_order_pageBUILD()
{
 if(http.readyState == 4)
   {
        var response = http.responseText;
        if(response.indexOf('AlreadyExisting UserId')!=-1)
        {
           alert('We have an existing account with this UserId');
        }
        else
        {
            var accntArr=new Array();
            try
            {
            accntArr=response.split(' <!--orderby_starts_here-->');
            accntArr=accntArr[1].split(' <!--orderby_ends_here-->');
            document.getElementById('div_orderby').innerHTML= accntArr[0];
            accntArr=new Array();
            accntArr=response.split('<!--Contacts_start_here-->');
            accntArr=accntArr[1].split('<!--Contacts_end_here-->');
            document.getElementById('div_popUp_contacts_dup').innerHTML= accntArr[0];
            cancel_contact_order_page();
            }
            catch(OrderPage)
            {
           
            }
         }
   }
}

function Set_up_Array_Contacts_BUILD()
{
    var contact=new Array();
    contact[0]=document.getElementById('txt_fname_cont').value;
    contact[1]=document.getElementById('txt_lname_cont').value;
    contact[2]=document.getElementById('txt_email_cont').value;
    contact[3]=document.getElementById('txt_did').value;
    contact[4]=document.getElementById('txt_cell').value;
    contact[5]=document.getElementById('txt_ext_contact').value;
    contact[6]=document.getElementById("txt_notes_contact").value;
    contact[7]=document.getElementById('chk_email').checked;
    contact[8]=document.getElementById('chk_admin').checked;
    contact[9]="";
    contact[10]=contactIdToEdit;
    return contact;
}

        


