function delete_cookie (name, path)
{
   
	// Build expiration date string:
	var expiration_date = new Date ();
	expiration_date . setYear (expiration_date . getYear () - 1);
	expiration_date = expiration_date . toGMTString ();

	// Build set-cookie string:
	var cookie_string = escape (name) + "=; expires=" + expiration_date;
	if (path != null)
		cookie_string += "; path=" + path;

	// Delete the cookie:
	document . cookie = cookie_string;
}
//delete_cookie ("newcokie");

function timerPage()
{
         http.open('post', 'AutomaticEmails.aspx');
         http.onreadystatechange = response_trial;
         http.send(null);
}
function response_trial()
{
 if(http.readyState == 4)
     {
       
     }
}
function SetCookie(cookieName,cookieValue,nDays) 
{

     var today = new Date();
     var expire = new Date();
     if (nDays==null || nDays==0)nDays=1;
     expire.setTime(today.getTime() + 3600000*24*nDays);
     document.cookie = cookieName+"="+cookieValue+ ";expires="+expire.toGMTString();
}

//SetCookie('newcokie','hei',1) ;
//
function Send_Notification_Email(boolval,id)
{

         
         http.open('post', 'notification.aspx?valuetosend='+boolval+'&orderid='+document.getElementById(id).value);
         http.onreadystatechange = response2_send_notification;
         http.send(null);
}




function getUrl(url) 
{
var http = new ActiveXObject("microsoft.xmlhttp");
http.open("GET",url,false);
http.send();
return http.responseText;
}
function sub_allOrders()
{
          http.open('post', 'account.aspx');
          http.onreadystatechange = resp_jumpTo_orderspage;
          http.send(null);
}
function resp_jumpTo_orderspage()
{
     if(http.readyState == 4)
     {
        var response = http.responseText;
        All_orders_in_ordersPage('');
     }
}
function All_orders_in_ordersPage(str)
{
      
          http.open('post', 'orders.aspx?bindallorders=true');
          http.onreadystatechange = resp_get_orderspage;
          http.send(null);
}
function resp_get_orderspage()
{

  if(http.readyState == 4)
     {
        var response = http.responseText;
    
        if(response.indexOf('<!--all orders starts here-->')!=-1)
        {
         var arr=new Array();
         arr=response.split('<!--all orders starts here-->');
         arr=arr[1].split('<!--all orders ends here-->');
           
         document.getElementById('orders').innerHTML=arr[0];
        }
    }
}
function resp_send_notification()
{

     if(http.readyState == 4)
     {
        var response = http.responseText;
        if(response.indexOf('hiden_clientid is:')!=-1)
        {
       
            var arr=new Array();
            arr=response.split('hiden_clientid is:');
            arr=arr[1].split(':hiden_clientid ends');
            var order_details=new Array();
            order_details=response.split('<!-- order_details_start_here-->');
            order_details=order_details[1].split('<!-- order_details_end_here-->');
            alert(order_details[0]);
            document.getElementById(arr[0]).value=(order_details[0]);
            alert(document.getElementById(div_order_details).innerHTML);
            alert(document.getElementById('chummas'));
            var btn=document.getElementById('chummas');
            btn.click();
            
           // my_newWindow = window.open("notification.aspx","mywindow","status=1,width=700,height=700");
           // alert(my_newWindow.document.getElementById('txt_sub'));
           // my_newWindow.document.getElementById(arr[0]).value=(order_details[0]);
            
          // Send_Notification_Email('true','');

           // theFile = getUrl('http://refurbishedphones.com/trial.txt')
            
            //my_newWindow.document.execCommand("SaveAs");
          
        }
     }
}
function response2_send_notification()
{
if(http.readyState == 4)
     {
        var response = http.responseText;
        alert('Notification Has Been Sent');
        window.close();
     }
}
function OpenEmailNotification(action,orderid,email)
{
window.open('notification.aspx?'+action+'=true&orderid='+orderid+'&email='+email,'windownotify','menubar=0,resizable=0,width=450,height=450,scrollbars=yes');
}




var msgtop=parseInt(window.screen.width) / 2 - 350;// Set the top position of the div
var msgleft= parseInt(window.screen.width) / 2 - 150; // Set the left position of the div
var mov1 = parseInt(window.screen.width) / 2 - 350;   // the number on the left is the x co-ordinate
var mov2 = parseInt(window.screen.height) / 2 - 150;   // the number on the left is the y co-ordinate


/* The following three variables are for setting the properties of your table contained within the div. */ 
var tborder="0"
var cspace="0"
var cpad="0"
var tabheight=150 // Set the height of table
var tabwidth=350 // Set the width of table
var td1height=10
var td2height=30
var boxt=""
function Domsg(flag,txt_email)
{
  
    hidebox() // Hide the box after clicking on text link in box
    if(flag=="Yes")
    {
         
          http.open('post', 'order_page.aspx?action=savebilling&billing='+billingarra_savebilling+'&newcustomer=false');
          http.onreadystatechange = resp_billing_saved;
          http.send(null);
    }
    else
    {
         
          http.open('post', 'order_page.aspx?action=check_customer_exist&email='+document.getElementById(txt_email).value);
          http.onreadystatechange = resp_check_exisrting_customer;
          http.send(null);
                         
    }
    
} 



function DoFormbox(msgtext,txt_email)
{
   
    theString="<table width='"+tabwidth+"' height='"+tabheight+"' border="+tborder+" cellspacing="+cspace+" cellpadding="+cpad+"><tr><td height='"+td1height+"' class='td1style' align='left'><b>"
    theString+=""+msgtext+"</b></td></tr><tr><td height='"+td2height+"' align='center' class='td2style'><input type=\"button\" id=\"yesbtn\" value=\"Save Changes\" onclick=\"javascript:Domsg('Yes','"+txt_email+"')\" />&nbsp &nbsp"
    theString+="<input id=\"nobtn\" type=\"button\" value=\"New Customer\" onclick=\"javascript:Domsg('No','"+txt_email+"')\" /></td></tr></table>"
    if (document.layers) // Netscape 4.0+
    {
        document.formbox.document.write(theString)
        document.formbox.document.close()
        document.formbox.left=msgleft
        document.formbox.top=msgtop+40
        document.formbox.visibility="show"
    }
    else
    {

        if(document.getElementById) // Internet Explorer 5.0+ and Netscape 6.0+
        {
            elm=document.getElementById("formbox")
            elm.innerHTML=theString
            elm.style.top=msgtop
            elm.style.left=msgleft
            elm.style.visibility = "visible"
        }
    }
   
}

// This function is for hiding the div
function hidebox()
{
if (document.layers) // Netscape 4.0+
{
document.formbox.visibility="hidden"
}
if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+
{
elm.style.visibility="hidden"
}
}









//**********************************************************************************************************************************************************************

function email_from_all_list(listnumber,customerid,sessionid)
{
   //location.href("email.aspx?openwindow=true&ln="+listnumber+"&customerid="+customerid+"&sessionid="+sessionid);
   window.open('email.aspx?openwindow=true&ln='+listnumber+'&customerid='+customerid+'&sessionid='+sessionid,'windowemail','menubar=0,resizable=0,width=450,height=450,scrollbars=yes');
 
}
function handle_email_from_all_list()
{
//email_form
}
function Update_Followup(listnumber,customerid,ct)
{
  var txt_days=document.getElementById('txt_days'+ct).value;
  http.open('post','shoppinglist.aspx?action=update_followup&listnumber='+listnumber+'&customerid='+customerid+'&priority='+txt_days);
  http.onreadystatechange =handle_update_followUp;
  http.send(null);
}
function handle_update_followUp()
{
  window.location="all_shoppinglist.aspx";return false;
}
var current_shoppinglist_in_process="";
function action_all_shoppinglist(action,tablecount,listnumber,customerid)
{

  current_shoppinglist_in_process=tablecount;
 

   var confirmd=true;
  if(action=="DoneFromAll")
  {
  
   confirmd=confirm("Do You Want To Remove This From Display List?")
  }
  if(action=="delete_list_from_all_shoppinglist")
  {
    confirmd=confirm("Do You Want To Delete This List?")
  }
 if(confirmd)
   {
  
   document.getElementById('loading'+current_shoppinglist_in_process).style.display="block";
 
  http.open('post','shoppinglist.aspx?action='+action+'&listnumber='+listnumber+'&customerid='+customerid+'&tablenumber='+current_shoppinglist_in_process);
  http.onreadystatechange =handle_all_shoppinglist_change_status;
  http.send(null);
  }

}
function handle_all_shoppinglist_change_status()
{
    if(http.readyState==4)
    {

    document.getElementById('loading'+current_shoppinglist_in_process).style.display="none";
    document.getElementById('div_shop_'+current_shoppinglist_in_process).style.display="none";
    document.getElementById('status_div'+current_shoppinglist_in_process).style.display="none";
     
    }
    else
    {
    document.getElementById('loading'+current_shoppinglist_in_process).style.display="block";
    }
}

function edit_all_shoppinglist(listnumber,customerid)
{
  window.location="shoppinglist.aspx?action=edit_all_shoppinglist&listnumber="+listnumber+"&customerid="+customerid;return false;
 
}


var html_all_shoppinglist="";
var endofrec=true;

function all_shoppinglist(str)
{


  http.open('post','bind_a_shoplist.aspx');
  http.onreadystatechange =handle_all_shoppinglist;
  http.send(null);
}
var counter=0;
function handle_all_shoppinglist()
{
   if(http.readyState == 4)
     {
        var response = http.responseText;
        
        document.getElementById('save_load').style.display="none";
        if(response.indexOf('End of Priority Records')!=-1)
        {
      
          document.getElementById('div_all_shop'+counter).innerHTML="";
          endofrec=true;
        }
        else
        {
             if(response.indexOf('no list existing for this customer')!=-1)
             {
              
             }
             else
             {
                
              var arr=new Array();
               
               arr=response.split('<!--bind_a_list_starts_here-->');
                           
               
                arr=arr[1].split('<!--bind_a_list_ends-->');
                
               
                try
                {
                document.getElementById('div_all_shop0').innerHTML=arr[0];
              
                }
                catch(r)
                {
                 
                }
                          
               
               
             }
           
        
        }
        
     }
}
function nextClick_allshoppinglist(paging)
{
  http.open('post','bind_a_shoplist.aspx?'+paging+'=true');
  http.onreadystatechange =handle_all_shoppinglist;
  http.send(null);
}
function manual_shop_disp_none(id)
{
document.getElementById(id).style.display="none";
}
//**************************************************************************
function update_manual_shop(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;
  http.open('post','shoppinglist.aspx?action=update_manual&qty='+q+'&desc='+d+'&price='+p);
  http.onreadystatechange =handle_manual_shopping;
  http.send(null);
}
function handle_manual_shopping()
{
   if(http.readyState == 4)
     {
        var response = http.responseText;
        if(response.indexOf('<!--OPEN LiST START-->') != -1)
        {
            update = response.split('<!--OPEN LiST START-->');
            if(update[1].indexOf('<!--OPENLIST ENDS-->')!=-1)
            {
                 var openlist=new Array()
                 openlist=update[1].split('<!--OPENLIST ENDS-->');
                 document.getElementById('AJAX_OPENLIST_ID').innerHTML=openlist[0];
           }
        }
     }
}
function manual_add_items_shop()
{
  document.getElementById('manual_itm_shop').style.display="block";
}

function close_ticketing()
{

               document.getElementById('div_doc').innerHTML=ord_doc;
               document.getElementById('loading'+ticket_order).style.display="none";
               http.open('post','tckt_prnted.aspx?ready=true&orderid='+ticket_order);
               http.onreadystatechange = print_order_ticket_resp;
               http.send(null);
}
function clck_ship_address()
{
       http.open('post', 'order_page.aspx?action=nothing');
       http.onreadystatechange = handle_resp_newShip;
       http.send(null);
}
function handle_resp_newShip()
{
  if(http.readyState == 4)
     {
           var response = http.responseText;
            document.getElementById('pick_chk').checked=false;
           shipping_address_area(response);
     }
}
var shipping_adrs_html="";
function clck_blind()
{
    
    if(!document.getElementById('blind_chk').checked)
    {
      document.getElementById('blind_chk').checked=false;
    }
    
      document.getElementById('pick_chk').checked=false;
      if(shipping_adrs_html!="")
      {
        document.getElementById('shipping_address').innerHTML=  shipping_adrs_html;
      }
}
function clck_pick()
{
    if(!document.getElementById('pick_chk').checked)
    {
    document.getElementById('pick_chk').checked=false;
    }
  document.getElementById('blind_chk').checked=false;
  if(document.getElementById('shipping_address').innerHTML!="")
  {
    shipping_adrs_html=document.getElementById('shipping_address').innerHTML;
  }
  document.getElementById('shipping_address').innerHTML="";
  
}



function package_type_option_disp_none()
{
 document.getElementById('div_pack_option').style.display="none";
}
function convertordertoshop(orderid,query)
{
 window.location="shoppinglist.aspx?action=fromorders&orderid="+orderid+"&"+query;return false;
}
function ordertoshoppinglist(action,query)
{
window.location="shoppinglist.aspx?action="+action+"&"+query;return false;
}
function display_weight(id,type)
{
   try
   {
       document.getElementById('div_auto_part_ups' ).innerHTML="";
       document.getElementById('div_charge_label' ).innerHTML="";
     
       if(id=="")
       {
         document.getElementById('div_op_wt').style.display="none";
       }
       else
       {
         document.getElementById(id).style.display="block";
       }
      
       http.open('post', 'order_page.aspx?action=remove_packages');
       http.onreadystatechange = nothing_change;
       http.send(null);
   }
   catch(e)
   {
   }
}
function nothing_change()
{
if(http.readyState == 4)
    {
  
  cancel_packages();
  }
}

function bind_packagetype(typ,wt)
{

    var radioButtons = document.getElementsByName("packtype");
     for (var x = 0; x < radioButtons.length; x ++) 
      {
    
           if (radioButtons[x].value==typ) 
           {
           
              radioButtons[x].checked=true;
              
           }
     }
   
     if(typ!="Normal")
     {
      document.getElementById('div_op_wt').style.display="block";
      document.getElementById('txt_op_wt').value=wt;
     }
}




var delete_order_row="0";
var orderrow="0";
var val="0";
function delete_order(orderid,rownumber,status,count)
{
   var answer = confirm("Do you want to delete this order?")
   if(answer)
    {

     delete_order_row=orderid;
     orderrow=rownumber;

     var newct=document.getElementById('status_name'+orderrow).innerHTML;
     val=parseInt(newct)-1;
  
     document.getElementById('loading'+delete_order_row).style.display="block";
     http.open('post','orders.aspx?action=delete_order&orderid='+orderid+'&rownumber='+rownumber+'&status='+status+'&count='+count);
     http.onreadystatechange = handleresponse_deleted;
     http.send(null);
     }
}


function handleresponse_deleted()
{
        if(http.readyState == 4)
         {
               document.getElementById('big'+delete_order_row).style.display="none";
               if(val==0)
               {
                document.getElementById('gridname'+orderrow).style.display="none";
               }
               else
               {
               document.getElementById('status_name'+orderrow).innerHTML=val;
               }
              /* var response = http.responseText;
               if(response.indexOf('status_orders_count:')!=-1)
               {
                  
                   var newar=new Array();
                   var newar=response.split('status_orders_count:');
                   if(newar[1].indexOf(':status_orders_count')!=-1)
                   {
                       newar=newar[1].split(':status_orders_count');
                      
                       document.getElementById('status_name'+orderrow).innerHTML=newar[0];
                   }
               }*/
         }
}




function handleresponse_status_changed()
{
     if(http.readyState == 4)
     {
           var response = http.responseText;
                   
          
           if(response.indexOf('<!--all orders starts here-->')!=-1)
           {
               var newarr=response.split('<!--all orders starts here-->');
               if(newarr[1].indexOf('<!--all orders ends here-->')!=-1)
               {
                   newarr=newarr[1].split('<!--all orders ends here-->');
                   document.getElementById('loading'+delete_order_row).style.display="none";
                 
                   document.getElementById('orders').innerHTML=newarr[0];
                 
               }
           }
     }
}
var todisplay="card";
function delete_ids_fr(action,id)
{
    if(action=="delete_addrs")
    {
      todisplay="addrss";
    }
     var confirmed=false;
    confirmed=confirm('Do You Want To Delete This Record?');
   
    if(confirmed)
    {  
         http.open('post', 'order_page.aspx?action='+action+'&id='+id);
        http.onreadystatechange = delete_result;
         http.send(null);
     }
}
function delete_result()
{
    if(http.readyState == 4)
    {
         var response = http.responseText;
         if(todisplay=="card")
         {
           creditcard_area(response);
         }
         else
         {
           all_shippaddress_area(response);
         }
    }
}
function open_all_ship(id,sub)
{
 document.getElementById(id).style.display="block";
 document.getElementById(sub).style.display="none";
 

}
function close_all_ship(id,sub)
{
 document.getElementById(id).style.display="none";
 document.getElementById(sub).style.display="block";
}
function select_credit(id)
{
     http.open('post', 'order_page.aspx?action=select_creditcard&id='+id);
     http.onreadystatechange = Fill_paymentstuff;
     http.send(null);
}
function Fill_paymentstuff()
{
 if(http.readyState == 4)
    {
     var response = http.responseText;
     payment_area(response);
     document.getElementById('all_cardDetails').style.display="none";
    close_all_ship('all_cardDetails','div_open_cards');
    }
}
var pub_query="";
var saving_all_details=false;

var from_add_items=false;
function addItems(query,save_ship,save_pay,save_opt)
{
    pub_query=query;
    try
    {
    btn_ship=document.getElementById(save_ship);
    }
    catch(r)
    {
    }
    
    btn_payment=document.getElementById(save_pay);
    btn_optional=document.getElementById(save_opt);
    
   /* var radioButtons = document.getElementsByName("radio_printed");
    var printd="edited";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
             printd=radioButtons[x].value;
           }
     }
    
     
    radioButtons = document.getElementsByName("radio_company");
    var comp="BSI";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
             comp=radioButtons[x].value;
           }
     }
     
    radioButtons = document.getElementsByName("packtype");
    var type="";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
             type=radioButtons[x].value;
           }
     }*/
     saving_all_details=true;
     from_add_items=true;
     //var btn=document.getElementById(save_bill);
     try
     {
      btn_ship.click();
     }
     catch(shipnul)
     {
       btn_payment.click();
     }
     
    
   
  
   
     
     
}


var billing_correct=true;
function responsetoproductspage()
{
  if(http.readyState == 4)
    {
    window.location="products.aspx?"+pub_query;return false;
    }
}
function printdoc()
{
 window.print();
}

function checkuserid(action,query1,email)
{
 var login_email=document.getElementById(email).value;
    http.open('POST','login.aspx?action='+action+'&userid='+login_email+'&'+query1);
    http.onreadystatechange = handleResponse_login;
    http.send(null);
}
function loginfn_save(action,query1,email,psw,conf)
{
    var login_email=document.getElementById(email).value;
    var login_psw= document.getElementById(psw).value;
    var conf_psw=document.getElementById(conf).value;
    if(login_psw==conf_psw)
    {
        http.open('POST','login.aspx?action='+action+'&login_email='+login_email+'&login_psw='+login_psw+'&'+query1);
        http.onreadystatechange = handleResponse_login;
        http.send(null);
    }
    else
    {
    alert("Password Fields Are Not Matching");
    }

}

function loginfn(action,query1,email,psw)
{
    
    var login_email=document.getElementById(email).value;
    var login_psw= document.getElementById(psw).value;
 
    http.open('POST','login.aspx?action='+action+'&login_email='+login_email+'&login_psw='+login_psw+'&'+query1);
    http.onreadystatechange = handleResponse_login;
    http.send(null);

}
function handleResponse_login() 
{
   if(http.readyState == 4)
    {
        var response = http.responseText;
  

        if(response.indexOf('checking userid')!=-1)
        {
          
            var Login_arry=new Array();
            Login_arry=response.split(' <!--user_login_area_starts_here-->');
            Login_arry=Login_arry[1].split(' <!--user_login_area_ends_here-->');
            document.getElementById('user_login_div').innerHTML=Login_arry[0];
           
        }
        if(response.indexOf('Error in login')!=-1)
        {
       
            var newarr=new Array();
            newarr=response.split('<!--wrong Div starts here-->');
            newarr=newarr[1].split('<!--wrong Div ends here-->');
            document.getElementById('wrongdiv').innerHTML=newarr[0];
           
        }
       else
       {
          if(response.indexOf('<!--redirect starts here-->')!=-1)
          {
            var newarr=new Array();
            newarr=response.split('<!--redirect starts here-->');
            newarr=newarr[1].split('<!--redirect ends here-->');
    
            window.location=newarr[0];
          }
       }
    }
}

function changedivcolor(row,id)
{

    if(document.getElementById(id+row).className!="order_active")
    {
      document.getElementById(id+row).className="orders_mouseover";
    }

}
function changecolor_on_mouseout(row,id)
{

    if(document.getElementById(id+row).className!="order_active")
    {
    document.getElementById(id+row).className="orders_link";
    }
}
//ready to pack
function displayOrder(orderid,rownumber,status,divrow)
{
             
   var cur_disp_mode= document.getElementById('div_prod_list'+divrow).style.display;
   if(cur_disp_mode=="block")
   {
          dispmode="none";
          document.getElementById('div_prod_list'+divrow).style.display=dispmode;   
   }
   else
   {
        http.open('post', 'orders.aspx?action=bindlist&orderid='+orderid+'&rownumber='+rownumber+'&status='+status+'&divrow='+divrow);
        http.onreadystatechange = handleresponseDisplayorder;
        http.send(null);

   }
   
}

//ready to pack

   

function getsubfolders(id)
{
   
    http.open('get', 'dummyproducts.aspx?parentID='+id);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function nextclic(id)
{


    var df=document.getElementById('hidenpagenum').value;
    var t=1;
    var newpage=parseInt(df)+parseInt(t);
  
    http.open('get', 'dummyproducts.aspx?parentID='+id+'&pageID='+newpage);
    http.onreadystatechange = handleResponseprod;
    http.send(null);
}
function handleResponseprod() 
{
    if(http.readyState == 4)
    {
      var response = http.responseText;
       
         if(response.indexOf(':responsewritepagenumber')!=-1)
         {
         var numb=new Array();
         numb=response.split(':responsewritepagenumber');
       
         }
               var update = new Array();
              
               if(response.indexOf('"dummyprod">' != -1)) 
                {
                    update = response.split('"dummyprod">');
                   
                }
         
               var responsepart=update[1].toString();
             
               var arr=new Array();
               var t= update[1].indexOf('<input type="hidden" id="hgg" />');
      
                if(t!= -1)
                {
                    arr = responsepart.split('<input type="hidden" id="hgg" />');
                }
              
               document.getElementById('jklit').innerHTML=arr[0];
               
            document.getElementById('top_pagenu').innerHTML=numb[0];
            document.getElementById('hidenpagenum').value=numb[0];
           
               
           
      }
}


function __doPostBack(eventTarget, eventArgument) 
{
   if (!theForm.onsubmit || (theForm.onsubmit() != false)) 
   {
       theForm.__EVENTTARGET.value = eventTarget;
       theForm.__EVENTARGUMENT.value = eventArgument;
       theForm.submit();
    }
}
function login_click(clintid)
{
 var btn=document.getElementById(clintid);
   
    
     if(window.event)
    {
              key = window.event.keyCode;     //IE
    }
    else
     {
          key = e.which;     //firefox
          
     }
 
    if (key == 13)
    {
      
        if(btn!=null)
        {
       
        btn.click();
           
        }
    }
}
function pageClick(passto,pagenumberId,query)
{

  
 var pagenumb=document.getElementById(pagenumberId).innerHTML;


window.location="products.aspx?"+passto+"=true&pagenumber="+pagenumb+"&"+query;return false;
}
function onclick_search(btnid,txtbox,drpdwn,e)
{
   
  
    var searchword=document.getElementById(txtbox).value; 
    var searchin=document.getElementById(drpdwn).value; 
    
     if(window.event)
    {
              key = window.event.keyCode;     //IE
    }
    else
     {
          key = e.which;     //firefox
          
     }

    if (key == 13 || key==0)
    {
      
     
      window.location="products.aspx?searchword="+searchword+"&searchin="+searchin;return false;
      
    }
    
}
var windowHandle=null;
var handlr=false;
 /*function onenterkey(txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state,e)
 {
        var srchword=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;
        http.open('post', 'search.aspx?srchword='+srchword);
        http.onreadystatechange = handleResponsepopup;
        http.send(null);
       
  }*/


var arr=new Array();
var prodarr=new Array(); 
var qtyarray =new Array();  
var i=0;

 function ticketprinted(valu,orderid)
 {
    http.open('POST','orders.aspx?valu='+valu+'&orderid='+orderid);
    http.onreadystatechange = handleResponse_nothi;
    http.send(null);
 }
 function handleResponse_nothi()
 {
 }

  
 
function findkey(action,e)
{  
 
    if(window.event)
    {
              key = window.event.keyCode;     //IE
    }
    else
     {
          key = e.which;     //firefox
          
     }
 if(action=="exempt_prod")
 {
 key=13;
 action="update_openlist";
 }
    if (key == 13)
    {
        var count=document.getElementById('hiden_count').value;
        sndRequpdate(action,count)
    }
        
}
function sndRequpdate(action,ct)
{
    var ship;
    var price;
    var qty;
    var productid;
     var exemptArr=new Array();
    var _exempItems="NoTax";
    for(var y=0;y<ct;y++)
    {
    if(document.getElementById('chk_exempt_item'+y)!=null)
        {
            if(document.getElementById('chk_exempt_item'+y).checked)
            {
           
           _exempItems="Exempt";
            }
            else
            {
            _exempItems="Include";
            }
        }
    if(document.getElementById('txt_shipping')!=null)
    {
            ship=document.getElementById('txt_shipping').value;
           
            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 days="nothing";
    if(action=="update_openlist")
    {
      days=document.getElementById('txt_days').value;
    }
    var test=arr.join('-');
    var prod=prodarr.join(',');
    var qtyar=qtyarray.join(',');
    var _exempt=exemptArr.join(',');
    http.open('POST', 'shoppinglist.aspx?action='+action+'&arr='+test+'&prodarr='+prod+'&qtyarr='+qtyar+'&ship='+ship+'&days='+days+'&exemptItem='+_exempt);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function openpopupemail(LN)
{
alert(LN);

}
var Listnumber="";
var session="";
var converttoOrder=false;
function sndReqEmailing(action,LN,sessionid)
{
    if(action=="email")
    {
    
      window.open('email.aspx?ln='+LN+'&sessionid='+sessionid,'windowemailforshop','menubar=0,resizable=0,width=450,height=450,scrollbars=yes');
   // location.href("shoppinglist.aspx?LN="+LN+"&sessionid="+sessionid+"&windowopen=true");
    }
    else
    {
    if(action=="order")
    {
      converttoOrder=true;
    }
        http.open('post', 'shoppinglist.aspx?action='+action+'&LN='+LN+'&sessionid='+sessionid);
        http.onreadystatechange = handleResponse;
        http.send(null);
    }
}
function handleResponse_emailing()
{
  if(http.readyState == 4)
    {
        
        if(Listnumber!="")
        {
          var response = http.responseText;
         // alert(response);
          //window.open('email.aspx?ln='+Listnumber+'&sessionid='+session,'mmwjnfgf','menubar=0,resizable=0,width=450,height=450,scrollbars=yes');
        }
    }
}
function sndReq(action,LN) 
{


      
   
        http.open('post', 'shoppinglist.aspx?action='+action+'&LN='+LN);
        http.onreadystatechange = handleResponse;
        http.send(null);
  
   
 
}

function functionfindpage(action,query1,query2,title)
{
    http.open('POST', 'masterpagefunctions.aspx?action='+action+'&query1='+query1+'&query2='+query2+'&title='+title);
    http.onreadystatechange = handleResponse;
    http.send(null);

}


function addtoshop(action,productid,query)
{
  
 
    http.open('POST', 'shoppinglist.aspx?'+query+'&action='+action+'&prodid='+productid);
    http.onreadystatechange = handleResponse_addto;
    http.send(null);
    
 
   
}


function handleResponse()
{
  if(http.readyState == 4)
    {
   
    var response = http.responseText;
 
    if(converttoOrder)
    {
    
        var convert=new Array();
        convert=response.split('convertingorder');
        convert=convert[1].split('convertingorderending');
        window.location="order_page.aspx?"+convert;return false;
    }
    else
    {
    var exist_days=false;
     try
     {
       
       var days=document.getElementById('txt_days').value;
     exist_days=true;
       }
       catch(ex)
       {
       }
     
       var update = new Array();
          
       if(response.indexOf('added To cart from shoppinglist')!=-1)
       {
        
       window.location="addtocart.aspx?title=shoppinglist";return false;
       }
       if(response.indexOf('<!--OPEN LiST START-->') != -1)
        {
          
            update = response.split('<!--OPEN LiST START-->');
           
            if(update[1].indexOf('<!--OPENLIST ENDS-->')!=-1)
            {
          
                 var openlist=new Array()
                 openlist=update[1].split('<!--OPENLIST ENDS-->');
               
                 document.getElementById('AJAX_OPENLIST_ID').innerHTML=openlist[0];
        
                if(openlist[1].indexOf('<!--Saved Shopping List START-->')!=-1)
                {
                    var newupdate=new Array();
                    newupdate=openlist[1].split('<!--Saved Shopping List START-->');
                
                    if(newupdate[1].indexOf('<!--Saved Shopping List ENDS-->')!=-1)
                    {
                       var savedlist=new Array();
                       savedlist=newupdate[1].split('<!--Saved Shopping List ENDS-->');
                      
                       document.getElementById('AJAX_SAVEDLIST_ID').innerHTML=savedlist[0];
                      
                    }
                    
                }
            }
          }
          if(exist_days)
          {
          document.getElementById('txt_days').value=days;
          }
         
          }
        
     } 
}    
            
       

function handleResponse_addto() 
{
    if(http.readyState == 4)
    {
       var response = http.responseText;
     var th_arr=new Array();
       th_arr=response.split('<!--buttons starting here-->');
      
       th_arr=th_arr[1].split('<!--buttons ending here-->');
      document.getElementById('buttons').innerHTML=th_arr[0];
     
       var update = new Array();
       if(response.indexOf('mastr' != -1)) 
        {
            update = response.split('mastr">');
           
        }
       var responsepart=update[1].toString();
       var arr=new Array();
       var t= update[1].indexOf('</form>');
       if(t!= -1)
        {
            arr = responsepart.split('</div></form>');
        }
        var hj=document.getElementById('mastr');
        hj.innerHTML=arr[0];
        if(document.getElementById('mastertop')!=null)
        {
           document.getElementById('mastertop').focus();
        }
      }
}




 

function get_mouse(e)
{

var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft;
skn.left=x+Xoffset;
var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop;
skn.top=y+yyy;
}

var ticket_order="";
function printorder(orderid,page)
{
     ticket_order=orderid;
     http.open('post','printorder.aspx?orderid='+orderid);
     http.onreadystatechange = print_order_ticket;
     http.send(null);

 //location.href("orders.aspx?printticket=true&orderid="+orderid);
}
function gar()
{
var tck_pr_con=false;
    if(confirm("Ready To Print?"))
    {
     tck_pr_con=true;
     window.print();
    }
    return tck_pr_con;

}
 var ord_doc="";
function print_order_ticket()
{
 if(http.readyState == 4)
      {
          var response = http.responseText;
          var arr=new Array();
          arr=response.split('<!--ticketing starts here-->');
          arr=arr[1].split('<!--ticketing ends here-->');
          ord_doc= document.getElementById('div_doc').innerHTML;
          document.getElementById('div_doc').innerHTML=arr[0];
        
          /* if(gar())
           {
               
           }
           else
           {
             document.getElementById('div_doc').innerHTML=ord_doc;
          document.getElementById('loading'+ticket_order).style.display="none";
           }*/
              
         
      }
      else
      {
           document.getElementById('loading'+ticket_order).style.display="block";
      }
}

function print_order_ticket_resp()
{
 if(http.readyState == 4)
      {
          var response = http.responseText;
          var arr=new Array();
          arr=response.split(' <!--ticket_page_status_starts-->');
          arr=arr[1].split(' <!--ticket_page_status_ends-->');
          document.getElementById('radio'+ticket_order).innerHTML=arr[0];
          document.getElementById('loading'+ticket_order).style.display="none";
      }
}
var label_order="";
function Print_Label_orders(ordid)
{
     label_order=ordid;
     http.open('post','order_page.aspx?action=Print_Label_orders&orderid='+ordid);
     http.onreadystatechange = printlabel;
     http.send(null);
}
function changestatus_order(orderid,listid)
{
     delete_order_row=orderid;
     document.getElementById('loading'+delete_order_row).style.display="block";
     var new_status=listid;
     http.open('post','orders.aspx?action=changestatus&orderid='+orderid+'&newstatus='+new_status);
     http.onreadystatechange = handleresponse_status_changed;
     http.send(null);
}
var label_ready=false;
function printlabel()
{

    if(http.readyState == 4)
      {
          document.getElementById('loading'+label_order).style.display="none";
          label_ready=true;
           var response = http.responseText;
           var noerror=true;
           if(response.indexOf('some of the fields are missing in shipping address')!=-1)
           {
                 alert('some of the fields are missing in shipping address');
                 noerror=false;
           }
           if(response.indexOf('Error in Printing Labels')!=-1)
           {
                 alert('Error in Printing Labels');
                  noerror=false;
           }
           if(response.indexOf('errorUPS:')!=-1)
           {
               var error=new Array();
               error=response.split('errorUPS:');
               if(error[1].indexOf(':error_ups')!=-1)
               {
              
                 error=error[1].split('error_ups');
                 alert(error[0]);
                  
               }
               noerror=false;
           }
           
         if(response.indexOf('FailedVoided')!=-1)
         {
            alert('Failed To Process,Contact UPS with TrackingNumber');
            noerror=false;
         }
            
         if(noerror)
         {
       
         //location.href("orders.aspx?print=true");
          http.open('post','labels.aspx?orderid='+label_order);
          http.onreadystatechange = printing_label_hei;
          http.send(null);
           
         }
          
     }
      else
      {
        document.getElementById('loading'+label_order).style.display="block";
       
      }
     
   
}




function dum_delay(pr_print_tim)
{
      if(confirm("Printed The Label?"))
      {
        pr_print_tim=true;
      }
      else
      {
        pr_print_tim= dum_delay(pr_print_tim)
      }
      return pr_print_tim;
}



function Func1Delay(pr_print_tim)
{
      
      //setTimeout("Func1()", 100);
      pr_print_tim=dum_delay(pr_print_tim)
     
      return pr_print_tim;
     
}

function printing_label_hei()
{
     if(http.readyState == 4)
      {
          var response = http.responseText;
          var arr=new Array();
          arr=response.split('<!--ticketing starts here-->');
          arr=arr[1].split('<!--ticketing ends here-->');
          var ord_doc= document.getElementById('div_doc').innerHTML;
          document.getElementById('div_doc').innerHTML=arr[0];
         window.print();  
         // var pr_print_tim=false;
         // pr_print_tim= Func1Delay(pr_print_tim);
         // if(pr_print_tim)
         // {
              document.getElementById('div_doc').innerHTML=ord_doc;
                document.getElementById('btn_ship_notify'+label_order).disabled=false;
              document.getElementById('div_ed'+label_order).style.display="none";
              document.getElementById('prnt_lb'+label_order).style.display="none";
              document.getElementById('btn_void_ship'+label_order).style.display="block";
              document.getElementById('loading'+label_order).style.display="none";
              
      
             
              /*var pck=new Array();
              pck=response.split('Package count of labels:');
              pck=pck[1].split(':Package count of labels ends');
              
              http.open('post','orders.aspx?delete_label=true&orderid='+label_order+'&pck='+pck[0]);
              http.onreadystatechange =nothing_as_such_hei;
              http.send(null);*/
         // }
      }
      else
      {
        document.getElementById('loading'+label_order).style.display="block";
      }
}
function nothing_as_such_hei()
{
}
function select_company_and_printed(company,status)
{
     var radioButtons = document.getElementsByName("radio_company");
     for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].value==company) 
           {
             radioButtons[x].checked=true;
           }
     }
     radioButtons = document.getElementsByName("radio_printed");
     for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].value==status) 
           {
             radioButtons[x].checked=true;
           }
     }
}

function update_manual(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;
  http.open('post','order_page.aspx?action=update_manual&qty='+q+'&desc='+d+'&price='+p);
  http.onreadystatechange = handleResponse_itemsadd;
  http.send(null);
}
function manual_add_items()
{
 document.getElementById('manual_itm').style.display="block";
}


function edit_order(orderid,customerid)
{
   window.location="order_page.aspx?edit_order=true&orderid="+orderid+"&customerid="+customerid+"&neworder=true";return false;
}
function radio_printed_status()
{
    var radioButtons = document.getElementsByName("radio_printed");
    var exp="edited";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
             exp=radioButtons[x].value;
           }
     }
     http.open('post', 'order_page.aspx?action=radio_printed_status&status='+exp);
     http.onreadystatechange =handle_save_withoutalert;
     http.send(null);
}
function radio_company_status()
{
    var radioButtons = document.getElementsByName("radio_company");
    var exp="BSI";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
             exp=radioButtons[x].value;
           }
     }
     http.open('post', 'order_page.aspx?action=radio_company_status&company='+exp);
     http.onreadystatechange =handle_save_withoutalert;
     http.send(null);
}
 function ticketprinted(valu,orderid)
 {
    http.open('POST','orders.aspx?valu='+valu+'&orderid='+orderid);
    http.onreadystatechange = handle_save_withoutalert;
    http.send(null);
 }var continue_btn_onlin_order;
var _billto_online_order=false;
function getPaymentTypeFromOrderOnline(radioname,continuebtn)
{
continue_btn_onlin_order=continuebtn;
     var _radio=document.getElementById(radioname);
    // for(var x=0; x<_radio.length;x++)
    // {
        if(_radio.checked)
        {
           //CausesValidation
           if(_radio.value=="CreditCard")
           {
             document.getElementById('div_with').style.display="block";
             document.getElementById('div_without').style.display="none";
             document.getElementById('div_creditcard').style.display="block";
           }
           else
           {
            document.getElementById('div_with').style.display="block";
             document.getElementById('div_without').style.display="none";
              _billto_online_order=true;
               document.getElementById('div_creditcard').style.display="none";
           }
        }
     //}
}

function click_order_online()
{
    
    var con=confirm('Click Ok to Process Your Order,Cancel to return to the form');
    if(con)
    {
        if(_billto_online_order)
         {
            window.location="order.aspx?continue=true&creditcard=false";
            return false;
         }
        /* else
         {
         document.getElementById('div_with').style.display="block";
         alert(continue_btn_onlin_order);
         continue_btn_onlin_order.click();
          // window.location="order.aspx?continue=true&creditcard=true";
         }*/
    }
    else
    {
        return false;
  
    }
    
}
function handle_save_withoutalert()
{

}
var void_order="";
function void_shipmnt(orderid)
{
     void_order=orderid;
     http.open('post', 'order_page.aspx?action=void_shipmnt&orderid='+orderid);
     http.onreadystatechange =voidship;
     http.send(null);
}
function voidship()
{
   if(http.readyState == 4)
       {
       document.getElementById('loading'+void_order).style.display="none";
           var response = http.responseText;
          
           if(response.indexOf('FailedVoided:')!=-1)
           {
              
               var result=new Array();
               result=response.split('FailedVoided:');
              
               if(result[1].indexOf(':voidedfailed')!=-1)
               {
              
               result=result[1].split(':voidedfailed');
               alert(result[0]);
                
                
               }
           }
           else
           {
               if(response.indexOf('SuccessVoided')!=-1)
               {
                
               
                document.getElementById('btn_void_ship'+void_order).style.display="none";
                document.getElementById('div_ed'+void_order).style.display="block";
                document.getElementById('prnt_lb'+void_order).style.display="block";
                alert('Shipment Has Been Voided');
               
               }
           }
          
       }
       else
       {
        document.getElementById('loading'+void_order).style.display="block";
       }
}



var btn_ship;
var btn_payment;
var btn_optional;



function saveorder(save_ship,save_pay,save_opt)
{
    try
    {
    btn_ship=document.getElementById(save_ship);
    }
    catch(r)
    {
    }
    btn_payment=document.getElementById(save_pay);
    btn_optional=document.getElementById(save_opt);

    saving_all_details=true;
    
  // var btn=document.getElementById(save_ship);
    try
    {
    btn_ship.click();
    }
    catch(r)
    {
    btn_payment.click();
    }
  
       
     
}
var shipping_correct=false;
var options_saved=false;
var updated_items_section=false;

function handle_saveorder()
{
   if(http.readyState == 4)
    {
   
           var err=false;
           var response = http.responseText;
           document.getElementById('save_load').style.display="none";
         if(response.indexOf('Select a Customer')!=-1)
           {
              alert('Select a Customer');
              err=true;
           }
           if(response.indexOf('Some required fields are missing')!=-1)
           {
           alert('Some required fields are missing  or extra characters appearing in any of the fields');
           err=true;
           }
          if(response.indexOf('Printed The Label.You cannot Update the changes')!=-1)
          {
            alert('Printed The Label.You cannot Update the changes');
          }
          if(!err)
           {
            
                alert('saved');
                  
                var gh=location.href;
             
                window.location="ordersub.aspx";return false;
             
           }
     }
}

 

function detail_order(id)
{

    var y=document.getElementById(id).style.display;
   
    if(y=="none")
    {
    document.getElementById(id).style.display="block";
    document.getElementById(id).focus();
    }
    else
    {
    document.getElementById(id).style.display="none";
    }
    
}
function mouse_change_history(id)
{
    var y=document.getElementById(id).style.backgroundColor;
    if(y=="yellow")
    {
    document.getElementById(id).style.backgroundColor ="#BDCFF2";
    }
    else
    {
    document.getElementById(id).style.backgroundColor ="yellow";
    }
    document.getElementById(id).focus();
}
function History_orderpage()
{
                     var y=document.getElementById('history_detail').style.display;
                     if(y=="none")
                     {
                         http.open('post', 'order_page.aspx?action=History');
                         http.onreadystatechange = handleHistory;
                         http.send(null);
                     }
                     else
                     {
                     document.getElementById('history_detail').style.display="none";
                     }
}
function handleHistory()
{
if(http.readyState == 4)
    {
     var response = http.responseText;
     history_area(response);
     detail_order('history_detail');
    }
}
function verifyadd(txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state)
 {
                    var shipping=new Array();
                     shipping[0]= document.getElementById(txt_fname).value;
                     shipping[1]=document.getElementById(txt_city).value;
                     shipping[2]=document.getElementById(txt_add1).value;
                     shipping[3]=document.getElementById(state).value;
                     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;
                     var shippingarra=shipping.join('*');
                    
                     http.open('get', 'order_page.aspx?action=verifyaddress&shipping_address='+shippingarra);
                     http.onreadystatechange = handleresponseverify;
                     http.send(null);
 }
function handleresponseverify()
 {
  if(http.readyState == 4)
    {
    var response = http.responseText;
  
        if(response.indexOf('verification Result:')!=-1)
        {
        var verify=new Array();
        verify=response.split('verification Result:');
        if(verify[1].indexOf('verification done')!=-1)
        {
        verify=verify[1].split('verification done');
        alert(verify[0]);
        }
        }
    }
 }
var procecssing_ups=false;
function process_ups(save_pay,save_opt,txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state,action,save)
{       
 var shipping=new Array();
 shipping[0]= document.getElementById(txt_fname).value;
 shipping[1]=document.getElementById(txt_city).value;
 shipping[2]=document.getElementById(txt_add1).value;
 shipping[3]=document.getElementById(state).value;
 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;
 var shippingarra=shipping.join('*');
 procecssing_ups=true;
 saving_all_details=true;
 var addressfieldempty="false";
 for(var h=0;h<shipping.length;h=parseInt(h)+1)
 {
    
    if(shipping[h]=="")
     {
       if(h!=6 && h!=4 && h!=7 && h!=9 && h!=8)
         {
           addressfieldempty="true";
         }
     }
 }
 

 
     var packagetype="Normal";
     var radioButtons = document.getElementsByName("packtype");
     for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
              packagetype=radioButtons[x].value;
           }
     }
 
   var wt=document.getElementById('txt_op_wt').value;       
  if(addressfieldempty=="false")
    {    
        if(action=="ship_rate")
        {
           btn_optional=document.getElementById(save_opt);
           var bbt=document.getElementById(save_pay);
           bbt.click();
        }
        else
        {
               http.open('post','order_page.aspx?action='+action+'&packagetype='+packagetype+'&weight='+wt+'&shipping_address='+shippingarra);
               if(action=="void_ship")
               {
               http.onreadystatechange = voidship;
               }
               else
               {
                   if(action=="print_label")
                   {
                     
                      http.onreadystatechange = printlabel;
                   }
                   else
                   {
                      http.onreadystatechange = just_label;
                   }
               }
               http.send(null);
         }
    }
   else
   {
    alert('Shipping Address is not Filled');
   }
                    
 
}
function ExemptSelect(exemptFromorderpage)
{
var _exm=true;
if(exemptFromorderpage=="False")
{
_exm=false;
}
document.getElementById('chk_salestax').checked=_exm;
}
function savethirdparty(zip,account)
{
                    

     http.open('post', 'order_page.aspx?action=save_thirdparty&zip='+zip+'&account='+account);
     http.onreadystatechange = alertsaved;
     http.send(null);

}
//**shoppinglist***
function Toatl_calculation_area(response)
{
}
var _exemptShoppinglist=false;
function salesTaxExemptShoppinglist()
{
    _exemptShoppinglist=document.getElementById('chk_salestax').checked;
     http.open('post', 'shoppinglist.aspx?action=Exempt&Exempt='+_exempt);
     http.onreadystatechange = response_Exempt_shoppinglist;
     http.send(null);
}
function response_Exempt_shoppinglist()
{
if(http.readyState == 4)
    {
      var response = http.responseText;
      Toatl_calculation_area(response);
      if(_exemptShoppinglist)
      {
        document.getElementById('chk_salestax').checked=true;
      }
    }
}
//**shoppinglist***
var _exempt=false;
function salesTaxExempt()
{
    _exempt=document.getElementById('chk_salestax').checked;
     http.open('post', 'order_page.aspx?action=Exempt&Exempt='+_exempt);
     http.onreadystatechange = response_Exempt;
     http.send(null);
}
function response_Exempt()
{
if(http.readyState == 4)
    {
      var response = http.responseText;
      shipping_charges_area(response);
      if(_exempt)
      {
        document.getElementById('chk_salestax').checked=true;
      }
    }
}
function thirdparty(edit,selectedbox)
{
    
    var radiobuttons=document.getElementsByName('billby');
    var notselected=false;
    
    for(var x=0;x<radiobuttons.length;x++)
    {
           if(radiobuttons[x].value==selectedbox)
           {
              radiobuttons[x].checked="true";
           }
           if(radiobuttons[x].checked)
           {
            
                 if(radiobuttons[x].value=="shipper" || radiobuttons[x].value=="Shipper")
                  {
                  
                    notselected=true;
                    
                  }
               
           }
     }
   
    
    if(edit==true)
    {
   
      notselected=false;
    }
  
    if(notselected)
    {
     document.getElementById('thirdparty_details').style.display="none";
    
    }
    else
    {
    document.getElementById('thirdparty_details').style.display="block";
    }
}
function selected_carditcard()
{
if(http.readyState == 4)
        {
       
           var response = http.responseText;
          creditcard_area(response);
         
        }
}
 

function payment_selected(method)
{
     
   //open_all_ship('all_cardDetails','div_open_cards');
  
    switch(method)
    {
     default:
     try
     {
     document.getElementById('all_cardDetails').style.display="none";
     }
     catch(f)
     {
     }
     document.getElementById('div_payment_note').style.display="block";
     document.getElementById('div_ebay').style.display="none";
     document.getElementById('clearingbox_stuff').style.display="none";
     document.getElementById('div_cod_amnt').style.display="none";
     document.getElementById('table_creditcard').style.display="none";
     break;
     case "BillTo":
     try
     {
     document.getElementById('all_cardDetails').style.display="none";
     }
     catch(f)
     {
     }
     document.getElementById('div_payment_note').style.display="none";
     document.getElementById('div_ebay').style.display="none";
     document.getElementById('clearingbox_stuff').style.display="none";
     document.getElementById('div_cod_amnt').style.display="none";
     document.getElementById('table_creditcard').style.display="none";
     break;
     case "CreditCard":
      try
     {
     document.getElementById('all_cardDetails').style.display="none";
     }
     catch(f)
     {
     }
     document.getElementById('div_payment_note').style.display="none";
     document.getElementById('div_ebay').style.display="none";
     document.getElementById('clearingbox_stuff').style.display="none";
     document.getElementById('div_cod_amnt').style.display="none";
     document.getElementById('table_creditcard').style.display="block";
     http.open('post', 'order_page.aspx?action=all_cards');
     http.onreadystatechange = selected_carditcard;
     http.send(null);

     break;
     case "COD":
      try
     {
     document.getElementById('all_cardDetails').style.display="none";
     }
     catch(f)
     {
     }
     document.getElementById('div_payment_note').style.display="none";
     document.getElementById('div_ebay').style.display="none";
     document.getElementById('clearingbox_stuff').style.display="none";
     document.getElementById('table_creditcard').style.display="none";
     document.getElementById('div_cod_amnt').style.display="block";
     break;
     case "COD Certified":
      try
     {
     document.getElementById('all_cardDetails').style.display="none";
     }
     catch(f)
     {
     }
     document.getElementById('div_payment_note').style.display="none";
     document.getElementById('div_ebay').style.display="none";
     document.getElementById('clearingbox_stuff').style.display="none";
     document.getElementById('table_creditcard').style.display="none";
     document.getElementById('div_cod_amnt').style.display="block";
     break;
     case "PayPal":
      try
     {
     document.getElementById('all_cardDetails').style.display="none";
     }
     catch(f)
     {
     }
     document.getElementById('div_payment_note').style.display="none";
     document.getElementById('table_creditcard').style.display="none";
     document.getElementById('div_cod_amnt').style.display="none";
     document.getElementById('div_ebay').style.display="block";
      var radioebay = document.getElementsByName("ebay_rad");
      radioebay[0].checked=true;
     break;
    
    }
    
}
function select_ebay_method(mthd)
{
      var radioebay = document.getElementsByName("ebay_rad");
      for (var x = 0; x < radioebay.length; x ++) 
      {
           if (radioebay[x].value==mthd) 
           {
            radioebay[x].checked=true;
            
           }
     }
 switch(mthd)
    {
     case "E-check":
     document.getElementById('clearingbox_stuff').style.display="block";
     break;
     case "Instant Payment":
     document.getElementById('clearingbox_stuff').style.display="none";
     break;
    
    }
}

function save_payment(ebaynumber,clearingdate,codamount,cardtype,cardnumber,cardid,cardname,cardmonth,cardyear,notes)
{
   close_all_ship('all_cardDetails','div_open_cards');
    var nts=document.getElementById(notes).value;
    if(nts.indexOf('&')>0)
    {
    nts=nts.replace("&","and");
    }
    var radioButtons = document.getElementsByName("r1");
    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:
     payment[0]=nts;
     break;
     case "CreditCard":
     payment[0]=document.getElementById(cardtype).value;
     payment[1]=document.getElementById(cardnumber).value;
     payment[2]=document.getElementById(cardid).value;
     payment[3]=document.getElementById(cardname).value;
     payment[4]=document.getElementById(cardmonth).value;
     payment[5]=document.getElementById(cardyear).value;
     break;
     case "COD":
     document.getElementById('div_charge_label' ).innerHTML="";
     payment[0]=document.getElementById(codamount).value;
     break;
     case "COD Certified":
     document.getElementById('div_charge_label' ).innerHTML="";
     payment[0]=document.getElementById(codamount).value;
     break;
     case "PayPal":
     payment[0]=document.getElementById(ebaynumber).value;
     var radioebay = document.getElementsByName("ebay_rad");
      for (var x = 0; x < radioebay.length; x ++) 
      {
           if (radioebay[x].checked) 
           {
             payment[1]=radioebay[x].value;
            
           }
     }
   if( payment[1].toString()=="E-check")
   {
     payment[2]=document.getElementById(clearingdate).value;
     }
     else
     {
     payment[2]="";
     }
     break;
    

     } 
     var paymntar=payment.join('*');

     http.open('post', 'order_page.aspx?action=save_payment&method='+exp+'&payment='+paymntar);
     http.onreadystatechange = resp_savepayment;
     http.send(null);

}
function resp_savepayment()
{
       if(http.readyState == 4)
        {
           if(saving_all_details)
             {
               btn_optional.click();
             }
             else
             {
             alert('saved');
             }
         }
}

function save_optional(ref,notes,thirdparty,pio,sticker,thirdpartyzip,thirdpartyaccnt)
{
                     var shipping=new Array();
                       
                        var radiobuttons=document.getElementsByName(thirdparty);
                    
                         var billby="";
                        for(var x=0;x<radiobuttons.length;x++)
                        {
                          
                           if(radiobuttons[x].checked)
                           {
                              billby=radiobuttons[x].value;
                              
                           }
                        }
                    
                    // var chckboxvalues=document.getElementsByName(thirdparty);
                   
                     shipping[0]= document.getElementById(notes).value;
                     shipping[1]=billby;
                     shipping[2]=document.getElementById(pio).value;
                     shipping[3]=document.getElementById(sticker).checked;
                     shipping[4]=document.getElementById(ref).value;
                    
                     
                     if(billby!="shipper")
                     {
                     
                     shipping[5]=document.getElementById(thirdpartyzip).value;
                     shipping[6]=document.getElementById(thirdpartyaccnt).value;
                     
                     }
                     var optional=shipping.join('*');
                     optional=optional.replace("&","and");
                     optional=optional.replace("'","\"\"");
                    
                    
                     http.open('post', 'order_page.aspx?action=save_optional&optional='+optional);
                     http.onreadystatechange = resp_save_optional;
                     http.send(null);
}
function resp_save_optional()
{
       if(http.readyState == 4)
        {
            if(!saving_all_details)
            {
               alert('saved')
            }
            else
            {
             var count=document.getElementById('hiden_count').value;
             var bb=document.getElementById('hiden_count');
             bb.click();
            }
   
        }
}


function select_ship(addrsnumber)
{
                     http.open('post', 'order_page.aspx?action=select_ship_address&addrsnumber='+addrsnumber);
                     http.onreadystatechange = fill_selected_shipadd;
                     http.send(null);
}
function fill_selected_shipadd()
{
if(http.readyState == 4)
        {
       
           var response = http.responseText;
           shipping_charges_area(response);
           shipping_address_area(response);
           
           document.getElementById('ship_pop').style.display="none";
           close_all_ship('ship_pop','div_open_ship_addrs');
        }
}
function Company_Area(response)
{

    if(response.indexOf('usercompany is:')!=-1)
    {
    
        var company=new Array();
        company=response.split('usercompany is:');
        if(company[1].indexOf(':usercompany')!=-1)
        {
              company=company[1].split(':usercompany');
              var radioButtons = document.getElementsByName("radio_company");
            
              for (var x = 0; x < radioButtons.length; x ++) 
               {
               
                  if (radioButtons[x].value==company[0]) 
                  {
                    radioButtons[x].checked=true;
                  }
               }
         }
    }
}
function payment_area(response)
{
        if(response.indexOf(' <!--payement start here-->')!=-1)
          {
            var ship_ups_ch=new Array();
            ship_ups_ch=response.split('<!--payement start here-->');
            if(ship_ups_ch[1].indexOf('<!--payement ends here-->')!=-1)
              {
              ship_ups_ch=ship_ups_ch[1].split('<!--payement ends here-->');
              document.getElementById('payment_stuff').innerHTML=ship_ups_ch[0];
              }
           }
}
function creditcard_area(response)
{
        if(response.indexOf('<!--creditcard area starts-->')!=-1)
          {
            var ship_ups_ch=new Array();
            ship_ups_ch=response.split('<!--creditcard area starts-->');
            if(ship_ups_ch[1].indexOf('<!--creditcard area ends-->')!=-1)
              {
              ship_ups_ch=ship_ups_ch[1].split('<!--creditcard area ends-->');
               document.getElementById('all_cardDetails').innerHTML=ship_ups_ch[0];
                document.getElementById('div_open_cards').style.display="block";
              // document.getElementById('all_cardDetails').style.display="block";
              }
           }
}
function history_area(response)
{
 if(response.indexOf('<!--history starts here-->')!=-1)
          {
            var ship_ups_ch=new Array();
            ship_ups_ch=response.split('<!--history starts here-->');
            if(ship_ups_ch[1].indexOf('<!--history ends here-->')!=-1)
              {
              ship_ups_ch=ship_ups_ch[1].split('<!--history ends here-->');
              document.getElementById('history_detail').innerHTML=ship_ups_ch[0];
              }
           }
}
function shipping_address_area(response)
{


         if(response.indexOf('<!--shipping address starts here-->')!=-1)
          {
            var ship_ups_ch=new Array();
            ship_ups_ch=response.split('<!--shipping address starts here-->');
            if(ship_ups_ch[1].indexOf('<!--shipping address ends here-->')!=-1)
              {
              ship_ups_ch=ship_ups_ch[1].split('<!--shipping address ends here-->');
              document.getElementById('shipping_address').innerHTML=ship_ups_ch[0];
              }
           }
}
function billing_address_area(response)
{
           var billing_add=new Array();
           billing_add=response.split('<!--billing address starts here-->');
           if(billing_add[1].indexOf('<!--billing address ends here-->')!=-1)
               {
               var new_bill=new Array();
                 new_bill=billing_add[1].split('<!--billing address ends here-->');
               }
            document.getElementById('billing_address').innerHTML=new_bill[0];
}
function just_label_charge_change(response)
{
     if(response.indexOf('<!--ups_charge_label_starting-->')!=-1)
      {
          var ship_ups_ch=new Array();
          ship_ups_ch=response.split('<!--ups_charge_label_starting-->');
         if(ship_ups_ch[1].indexOf('<!--ups_charge_label_ending-->')!=-1)
          {
          ship_ups_ch=ship_ups_ch[1].split('<!--ups_charge_label_ending-->');
         
          document.getElementById('div_charge_label').innerHTML=ship_ups_ch[0];
          }
      }
      if(response.indexOf('<!--shipping_charge_starts_here -->')!=-1)
      {
          var ship_ups_ch=new Array();
          ship_ups_ch=response.split('<!--shipping_charge_starts_here -->');
         if(ship_ups_ch[1].indexOf('<!--shipping_charge_ends_here -->')!=-1)
          {
          ship_ups_ch=ship_ups_ch[1].split('<!--shipping_charge_ends_here -->');
          
          document.getElementById('shipping_charge').innerHTML=ship_ups_ch[0];
          }
      }
}
function shipping_charges_area(response)
{
   if(response.indexOf('<!--ups_charge_starting -->')!=-1)
       {
            var billing_add=new Array();
            billing_add=response.split('<!--ups_charge_starting -->');
           
           if(billing_add[1].indexOf('<!--ups_charge_ending -->')!=-1)
               {
                 var new_bill=new Array();
                 new_bill=billing_add[1].split('<!--ups_charge_ending -->');
               
                 document.getElementById('div_ups_charge').innerHTML=new_bill[0];
               }
              
       }
       
     
       if(response.indexOf('<!--shipping_charge_starts_here -->')!=-1)
      {
          var ship_ups_ch=new Array();
          ship_ups_ch=response.split('<!--shipping_charge_starts_here -->');
         if(ship_ups_ch[1].indexOf('<!--shipping_charge_ends_here -->')!=-1)
          {
          ship_ups_ch=ship_ups_ch[1].split('<!--shipping_charge_ends_here -->');
          
          document.getElementById('shipping_charge').innerHTML=ship_ups_ch[0];
          }
      }
       if(response.indexOf('Exempt Checked')!=-1)
           {
          
           document.getElementById('chk_salestax').checked=true;
           }
}
function UPS_table_area(response)
{
 if(response.indexOf('<!--new order page ups stuff starting here-->')!=-1)
       {
         var items=new Array();
         items=response.split('<!--new order page ups stuff starting here-->')
    
         if(items[1].indexOf('<!--new order page ups stuff ends here-->')!=-1)
         {
            var  newitems=new Array();
            newitems=items[1].split('<!--new order page ups stuff ends here-->');
             document.getElementById('ups_div' ).innerHTML="";
           document.getElementById('ups_div' ).innerHTML=newitems[0];
         
         }
       }
}
function product_table_area(response)
{
 if(response.indexOf('<!--item_table_starts_here-->')!=-1)
       {
      
         var items=new Array();
         items=response.split('<!--item_table_starts_here-->')
      
         if(items[1].indexOf('<!--new orderpage items table ends here-->')!=-1)
         {

            var  newitems=new Array();
            newitems=items[1].split('<!--new orderpage items table ends here-->');
             document.getElementById('items_table' ).innerHTML="";
           
           document.getElementById('items_table' ).innerHTML=newitems[0];
       
        
         }
       }
}
function loginarea(response)
{
 if(response.indexOf('<!--master page login area starts-->')!=-1)
         {
             var masterpagestuff=new Array();
             masterpagestuff=response.split('<!--master page login area starts-->');
             if(masterpagestuff[1].indexOf('<!--master page login area ends-->')!=-1)
             {
              masterpagestuff=masterpagestuff[1].split('<!--master page login area ends-->');
              document.getElementById('master_login_data').innerHTML=masterpagestuff[0];
             }
             
         }
}
function all_shippaddress_area(response)
{

      if(response.indexOf('<!--all_ship_address_starts_here-->')!=-1)
         {
             var masterpagestuff=new Array();
             masterpagestuff=response.split('<!--all_ship_address_starts_here-->');
             if(masterpagestuff[1].indexOf('<!--all_ship_address_ends_here-->')!=-1)
             {
              masterpagestuff=masterpagestuff[1].split('<!--all_ship_address_ends_here-->');
              document.getElementById('ship_pop').innerHTML=masterpagestuff[0];
                document.getElementById('ship_pop').style.display="block";
             }
             
         }
}


function save_ship_address(contact,ext,fax,txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state)
{
                     var shipping=new Array();
                     shipping[0]= document.getElementById(txt_fname).value;
                     shipping[1]=document.getElementById(txt_city).value;
                     shipping[2]=document.getElementById(txt_add1).value;
                     shipping[3]=document.getElementById(state).value;
                     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;
                    var emptyshipaddress=true;
                     for(var t=0;t<shipping.length;t++)
                     {
                       if(shipping[t]!="")
                           {
                            emptyshipaddress=false;
                           }
                       if(shipping[t].indexOf("&")>0)
                       {
                         
                          shipping[t]=shipping[t].replace("&","and");
                       }
                     }
                     if(!emptyshipaddress)
                     {
                     
                         var shippingarra=shipping.join('*');
                        if(saving_all_details)
                            {
                            http.open('post','order_page.aspx?savingall=true&action=save_ship_address&shipping_address='+shippingarra);
                            }
                            else
                            {
                              http.open('post','order_page.aspx?action=save_ship_address&shipping_address='+shippingarra);
                            }
                         http.onreadystatechange = handleResponse_saveshipaddrss;
                         http.send(null);
                     }
                     else
                     {
                      if(!saving_all_details)
                        {
                           alert('Empty Shipping Address');
                        }
                        else
                        {
                        save_ship_add_func("ghh");
                        }
                     }
                    
}


function save_ship_add_func(response)
{
       if(!saving_all_details)
       {
            
             if(response.indexOf('Billing Address Is Not Saved')!=-1)
             {
                   alert('Billing Address Is Not Saved');
             }
             else
             {
               
                 shipping_charges_area(response);
                 alert('saved');
                     
                
             }
       }
       else
       {
      
         btn_payment.click();
       }
       
}



function handleResponse_saveshipaddrss()
{
if(http.readyState == 4)
    {
       
        var response = http.responseText;
        save_ship_add_func(response);
  
    }

}
  var billingarra_savebilling;
function savebilling(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)
{


    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]= document.getElementById(txt_fname).value;
                     billing[1]=document.getElementById(txt_city).value;
                     billing[2]=document.getElementById(txt_add1).value;
                     billing[3]=document.getElementById(state).value;
                     billing[4]=document.getElementById(txt_add2).value;
                     billing[5]=document.getElementById(txt_zip).value;
                     billing[6]=document.getElementById(txt_phone).value;
                     billing[7]=document.getElementById(txt_email).value;
                     billing[8]=document.getElementById(txt_company).value;
                     billing[9]=document.getElementById(txt_lastname).value;
                     billing[10]=document.getElementById(contact).value;
                     billing[11]=document.getElementById(fax).value;
                     billing[12]=document.getElementById(ext).value;
                     billing[13]=document.getElementById(customernotes).value;
                     billing[14]=userCmp;
                     billing[15]=userTyp;
                       
                    
                     for(var t=0;t<billing.length;t++)
                     {
                       if(billing[t].indexOf("&")>0)
                       {
                          billing[t]=billing[t].replace("&","and");
                       }
                     }
                    billingarra_savebilling=billing.join('*');
                    var newcustomer=false;
                    if(!saving_all_details)
                    {
                     DoFormbox('If you are trying to create a new customer click on new customer,otherwise,"Save Changes"',txt_email);
                    
                      
                       //var result=confirm('If you want to save this as a new customer Information,Click OK');
                        /*if(!confirmResult)
                        {
                             newcustomer=true;
                             http.open('post', 'order_page.aspx?action=check_customer_exist&email='+document.getElementById(txt_email).value);
                             http.onreadystatechange = resp_check_exisrting_customer;
                             http.send(null);
                        }
                        else
                        {
                          http.open('post', 'order_page.aspx?action=savebilling&billing='+billingarra_savebilling+'&newcustomer='+newcustomer);
                          http.onreadystatechange = resp_billing_saved;
                          http.send(null);
                        }     */       
                    }
                    else
                    {
                   
                         http.open('post', 'order_page.aspx?action=savebilling&billing='+billingarra_savebilling+'&newcustomer=true');
                         http.onreadystatechange = resp_billing_saved;
                         http.send(null);
                    }
                    
                 
    
             }
        
                
}
function resp_check_exisrting_customer()
{

if(http.readyState == 4)
    {
       var response = http.responseText;
  
 if(response.indexOf('We Have Already A Customer With The Same Email Id')!=-1)
   {
   
   alert('We Have Already A Customer With The Same Email Id');
    
   }
   else
   {
         http.open('post', 'order_page.aspx?action=savebilling&billing='+billingarra_savebilling+'&newcustomer=true');
         http.onreadystatechange = resp_billing_saved;
         http.send(null);
   }
   }
  
}

function resp_billing_saved()
{
if(http.readyState == 4)
    {
       var response = http.responseText;
    
       if(response.indexOf('Extra Characters in BillingAddress')!=-1)
       {
         alert('Extra Characters in BillingAddress');
         billing_correct=false;
       }
       else
        {
        Company_Area(response);
           loginarea(response);
           if(!saving_all_details)
             {
               billing_correct=true;
               alert('saved');
             }
             else
             {
              
               if(btn_ship!=null)
                 {
                
                    btn_ship.click();
                 }
                 else
                 {
                    btn_payment.click();
                 }
             }
        }
     }
}
function alertsaved()
{
 if(http.readyState == 4)
    {
     var response = http.responseText;
    
     if(response.indexOf('Extra Characters in BillingAddress')!=-1)
       {
        alert('Extra Characters in BillingAddress');
        billing_correct=false;
       }
       else
       {
        loginarea(response);
        if(!saving_all_details)
        {
          alert('saved');
          
        }
       }
   
   
    }
}
function clearbilling(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)
{
            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="";
                   
                     var radioButton = document.getElementById(usercompany+"_2");
                     radioButton.checked=true;
                     radioButton = document.getElementById(usertype+"_2");
                     radioButton.checked=true;
                    
             if(addrss=="shipping")
             {
              http.open('post','order_page.aspx?action=clear_shipping');
              http.onreadystatechange = nothing_as_such;
               http.send(null);
             }   
                
               
}
function nothing_as_such()
{
}
function same_as_billing()
{

     http.open('post','order_page.aspx?action=same_as_billing');
     http.onreadystatechange = handle_same_as_billing;
     http.send(null);
}

function delete_manual_box(pck)
{
  http.open('post', 'order_page.aspx?action=dele_manual_box&packnumber='+pck);
  http.onreadystatechange = UpdateUpsStuff;
  http.send(null);
}
function cancel_packages()
  {
 
                 http.open('post', 'order_page.aspx?action=cancel_packages');
                 http.onreadystatechange = handleResponse_create_box;
                 http.send(null);
  }
  function done_packages(length,width,height,weight,insured)
  {
 
  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;
                 http.open('post', 'order_page.aspx?action=done_packages&length='+ln+'&width='+wd+'&height='+ht+'&weight='+wt+'&insured='+ins);
                 http.onreadystatechange = UpdateUpsStuff;
                 http.send(null);
  }
  
  function UpdateUpsStuff()
  {
   if(http.readyState == 4)
    {
       var response = http.responseText;
       UPS_table_area(response);
       just_label_charge_change(response)
   
    }
  }
 
function boxes(action)
{
   var txt=document.getElementById('manual_auto').innerHTML;
   
   if(action=="select_type_boxes")
   {
       if(txt=="Manual Adding Boxes")
       {
       document.getElementById('manual_auto').innerHTML="Auto Adding Boxes";
       document.getElementById('add_a_box').innerHTML="Create A Box";
       }
       else
       {
       handle_res_comm();
       //document.getElementById('manual_auto').innerHTML="Manual Adding Boxes";
      // document.getElementById('add_a_box').innerHTML="";
       http.open('post','order_page.aspx?action=autoadding_boxes');
       http.onreadystatechange = UpdateUpsStuff;
       http.send(null);
       }
   }
   else
   {
       handle_res_comm();
       http.open('post','order_page.aspx?action='+action);
       http.onreadystatechange = handleResponse_create_box;
       http.send(null);
   }
  
  
}

function handle_res_comm()
{
     radioButtons = document.getElementsByName("packtype");
     document.getElementById('div_op_wt').style.display="none";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
       
           if (radioButtons[x].value=="Normal") 
           {
             radioButtons[x].checked=true;
           }
     }
   
}
function handleResponse_create_box()
{
 if(http.readyState == 4)
    {
     var response = http.responseText;
      

     if(response.indexOf('<!--manual packa starts here-->')!=-1)
       {
            var billing_add=new Array();
            billing_add=response.split('<!--manual packa starts here-->');
           
           if(billing_add[1].indexOf('<!--manual packa ends here-->')!=-1)
               {
                 var new_bill=new Array();
                 new_bill=billing_add[1].split('<!--manual packa ends here-->');
                 document.getElementById('manual_pack').innerHTML=new_bill[0];
                 
               }
              
       }
   }
}
 

function selectcolor(ddn_id,txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state)
{

     var shipping=new Array();
     shipping[0]= document.getElementById(txt_fname).value;
     shipping[1]=document.getElementById(txt_city).value;
     shipping[2]=document.getElementById(txt_add1).value;
     shipping[3]=document.getElementById(state).value;
     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;
     var shippingarra=shipping.join('*');
     
     
    if(document.getElementById(ddn_id).value!="black" && document.getElementById(ddn_id).value!="orange" && document.getElementById(ddn_id).value!="USPS" && document.getElementById(ddn_id).value!="FED EX" && document.getElementById(ddn_id).value!="Courier" && document.getElementById(ddn_id).value!="DHL")
    {
       document.getElementById('div_pack_option').style.display="block";
       
    }
    else
    {
    document.getElementById('div_pack_option').style.display="none";
    }
      http.open('post', 'order_page.aspx?action=select_color&value='+document.getElementById(ddn_id).value+'&shipping_address='+shippingarra);
      http.onreadystatechange = handle_select_color;
      http.send(null);
  
}
function handle_select_color()
{
   if(http.readyState == 4)
    {
       var response = http.responseText;
       shipping_charges_area(response);
       
    }
}
function delet_product_orderpage(action,id,count)
 {
   
    http.open('post', 'order_page.aspx?action='+action+'&deletingid='+id+'&count='+count);
    http.onreadystatechange = handleResponse_itemsadd;
    http.send(null);
 }

function findkey_orderpage(action,e)
{  

    var key=0;
    if(window.event)
    {
              key = window.event.keyCode;     //IE
    }
    else
     {
          key = e.which;     //firefox
          
     }
  
   
    if(action=="exempt_prod")
    {
    key =13;
    }

    if (key == 13)
    {
       
        var count=document.getElementById('hiden_count').value;
        Requpdate_orderpage(action,count);
        return true;
    }
    else
    {
        return true;   
    }  
}
function Requpdate_orderpage(action,ct)
{

    var coun=parseInt(ct)+1;
    var ship;
    var price;
    var qty;
    var productid;
    var manualItem;
    arr=new Array();
    prodarr=new Array(); 
    qtyarray =new Array(); 
    var exemptArr=new Array();
    var _exempItems="NoTax";
   
    if(document.getElementById('txt_shipping')!=null)
        {
            ship=document.getElementById('txt_shipping').value;
           
        }
    for(var y=0;y<coun;y++)
    {
        if(document.getElementById('chk_exempt_item'+y)!=null)
        {
            if(document.getElementById('chk_exempt_item'+y).checked)
            {
           
           _exempItems="Exempt";
            }
            else
            {
            _exempItems="Include";
            }
        }
    
       
        if(document.getElementById('txt_shipping')!=null)
        {
            ship=document.getElementById('txt_shipping').value;
            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 test=arr.join('-');
    var prod=prodarr.join(',');
    var qtyar=qtyarray.join(',');
    
    
    
    // btn=document.getElementById(save_pay);
    // btn.click();
     
    
    
    if(saving_all_details)
    {
       http.open('post', 'order_page.aspx?savingall=true&action=update&arr='+test+'&prodarr='+prod+'&qtyarr='+qtyar+'&ship='+ship+'&exemptItem='+_exempt);
    }
    else
    {
  
     http.open('post', 'order_page.aspx?action=update&arr='+test+'&prodarr='+prod+'&qtyarr='+qtyar+'&ship='+ship+'&exemptItem='+_exempt);
    }
    if(action=="update_ship")
    {
   
        http.onreadystatechange = handleResponse_itemsadd_ship;
    }
    else
    {
        http.onreadystatechange = handleResponse_itemsadd_dup;
    }
   
    http.send(null);
    
}
function handleResponse_itemsadd_ship()
{

 if(http.readyState == 4)
    {
   
     
       var response = http.responseText;
       shipping_charges_area(response);
     
  
    }
}
function just_label()
{
if(http.readyState == 4)
    {
   
       var response = http.responseText;
       just_label_charge_change(response);
  
    }
}
function handleResponse_itemsadd_dup()
{
var wt="";
 if(http.readyState == 4)
    {
    
     if(!saving_all_details)
       {
          updated_items_section=true;
          var response = http.responseText;
          UPS_table_area(response);
          product_table_area(response);
          just_label_charge_change(response)
       }
       else
       {
       saving_all_details=false;
         try
         {
           var wt=document.getElementById('txt_op_wt').value;
         }
         catch(cot)
          {
        
          }
          
    var radioButtons = document.getElementsByName("radio_status");
    var exp="Current";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
             exp=radioButtons[x].value;
           }
     }
    radioButtons = document.getElementsByName("radio_printed");
    var printd="edited";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
             printd=radioButtons[x].value;
           }
     }
    var pickup=document.getElementById('pick_chk').checked;
    var blind=document.getElementById('blind_chk').checked;
    radioButtons = document.getElementsByName("radio_company");
    var comp="BSI";
    for (var x = 0; x < radioButtons.length; x ++) 
      {
           if (radioButtons[x].checked) 
           {
             comp=radioButtons[x].value;
           }
     }
    radioButtons = document.getElementsByName("packtype");
    var type="Normal";
    for (var x = 0; x < radioButtons.length; x ++) 
    {
           if (radioButtons[x].checked) 
           {
             type=radioButtons[x].value;
           }
    }
          if(procecssing_ups)
          {
               procecssing_ups=false;
               http.open('post','order_page.aspx?action=ship_rate&packagetype='+type+'&weight='+wt);
               http.onreadystatechange = just_label;
               http.send(null);
          }
          else
          {
              if(from_add_items)
              {
                 from_add_items=false;
                 http.open('post', 'order_page.aspx?action=addItems&company='+comp+'&status='+printd+'&type='+type+'&wt='+wt+'&pickup='+pickup+'&blind='+blind);
                 http.onreadystatechange =responsetoproductspage;
                 http.send(null);
              }
              else
              {
                document.getElementById('save_load').style.display="block";
                http.open('post', 'order_page.aspx?action=SaveOrder&status='+exp+'&company='+comp+'&stat='+printd+'&type='+type+'&wt='+wt+'&pickup='+pickup+'&blind='+blind);
                http.onreadystatechange =handle_saveorder;
                http.send(null);
              }
          }
       }
    }
}
function handleResponse_itemsadd()
{

    if(http.readyState == 4)
    {
      var response = http.responseText;
      UPS_table_area(response);
      product_table_area(response);
      shipping_charges_area(response);
      
    }
}
function clear_links()
{
        document.getElementById('div_shoppinglist').innerHTML="";
        document.getElementById('div_link_oc_shoplist').style.display="none";
        
        document.getElementById('div_pastorders').innerHTML="";
        document.getElementById('div_link_oc_pastorders').style.display="none";
        
        document.getElementById('div_currentorders').innerHTML="";
        document.getElementById('div_link_oc_currentorders').style.display="none";
        
        
        
       
        document.getElementById('div_Links').style.display="none";
}
function clearaddresscustomer2()
{
     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_contact_person').value="";
        document.getElementById('txt_lastname').value="";
       document.getElementById('txt_email').value="";
        document.getElementById('txt_fax').value="";
       document.getElementById('txt_phone').value="";
        document.getElementById('txt_ext_bill').value="";
        document.getElementById('txt_company').value="";
         document.getElementById('txt_custNotes').value="";
        
        
         var radiobuttons=document.getElementsByName("radio_list_company");
        for(var x=0;x<radiobuttons.length;x++)
        {
           if(radiobuttons[x].value=="ALL")
           {
            radiobuttons[x].checked=true;
           }
        }
        radiobuttons=document.getElementsByName("radio_list_usertype");
         for(var x=0;x<radiobuttons.length;x++)
        {
           if(radiobuttons[x].value=="ALL")
           {
            radiobuttons[x].checked=true;
           }
        }
        
        clear_links();
     
}

function selectCust2(customerid)
{
    kill();
    clear_links();
    http.open('post','customer2.aspx?action=select_customer&custid='+customerid);
    http.onreadystatechange = select_customer2;
    http.send(null);
}
var select_a_customer=false;
function select_customer2()
{
 if(http.readyState == 4)
   {
       var response = http.responseText;
       if(response.indexOf('customerInfo:')!=-1)
       {
            var billing_add=new Array();
            billing_add=response.split('customerInfo:');
           
           if(billing_add[1].indexOf(':customerInfo ends')!=-1)
               {
                   var new_bill=new Array();
                   new_bill=billing_add[1].split(':customerInfo ends');
                   customerInfo=new Array();
                   customerInfo=new_bill[0].split('!');
                   document.getElementById('txt_fname').value=customerInfo[0];
                   document.getElementById('txt_city').value=customerInfo[2];
                   document.getElementById('txt_add1').value=customerInfo[11];
                   document.getElementById('state').value=customerInfo[3];
                   document.getElementById('txt_add2').value=customerInfo[12];
                   document.getElementById('txt_zip').value=customerInfo[4];
                   document.getElementById('txt_contact_person').value=customerInfo[10];
                   document.getElementById('txt_lastname').value=customerInfo[1];
                   document.getElementById('txt_email').value=customerInfo[9];
                   document.getElementById('txt_fax').value=customerInfo[7];
                   document.getElementById('txt_phone').value=customerInfo[5];
                   document.getElementById('txt_ext_bill').value=customerInfo[6];
                   document.getElementById('txt_company').value=customerInfo[8];
                   document.getElementById('div_Links').style.display="block";
                   document.getElementById('hiden_customerid').value=customerInfo[14];
                   document.getElementById('txt_custNotes').value=customerInfo[13];
                                
                   loginarea(response);
                   
                   
                     var radiobuttons=document.getElementsByName("radio_list_company");
                  
                   
                    for(var x=0;x<radiobuttons.length;x++)
                    {
                  
                     
                       if(radiobuttons[x].value==customerInfo[15])
                       {
                        radiobuttons[x].checked=true;
                       }
                    }
                    radiobuttons=document.getElementsByName("radio_list_usertype");
                    for(var x=0;x<radiobuttons.length;x++)
                    {
                       if(radiobuttons[x].value==customerInfo[16])
                       {
                        radiobuttons[x].checked=true;
                       }
                    }
                   
                   select_a_customer=true;
                   openShoppingListCustomer2();
                    
                  
               }
       }
       
   }
}

function openShoppingListCustomer2()
{

loading_box();
      var custID=document.getElementById('hiden_customerid').value;
     http.open('post','customer2editing.aspx?action=openlist&customerid='+custID);
    http.onreadystatechange = response_openshoppinglistcustomer2;
    http.send(null);

}
function response_openshoppinglistcustomer2()
{

 if(http.readyState == 4)
        {
       window.clearTimeout(SD); 
         document.getElementById("formbox").style.display="none";
         
           var response = http.responseText;
            var count=new Array();
                      if(response.indexOf('listcount:')!=-1)
                      {
                         count=response.split('listcount:');
                         count=count[1].split(':listcount');
                         document.getElementById('div_shop_count').innerHTML=count[0];
                      }
          if(response.indexOf('Empty Grid')!=-1)
          {
              if(select_a_customer)
              {
               openPastOrdersCustomer2();
               
              }
              else
              {
                 alert('There Is No ShoppingList For This Customer');
              }
          }
          else
          {
             if(response.indexOf('<!--Saved Shopping List START-->')!=-1)
                {
                    var newupdate=new Array();
                    newupdate=response.split('<!--Saved Shopping List START-->');
                
                    if(newupdate[1].indexOf('<!--Saved Shopping List ENDS-->')!=-1)
                    {
                       var savedlist=new Array();
                       savedlist=newupdate[1].split('<!--Saved Shopping List ENDS-->');
                     
                       document.getElementById('div_shoppinglist').style.display="block";
                       document.getElementById('div_shoppinglist').innerHTML=savedlist[0];
                      if(select_a_customer)
                       {
                        openPastOrdersCustomer2();
                       }
                    }
                    
                }
            }
            makedisplayblock('div_shoppinglist','div_link_oc_shoplist');
       }
}
function deleteOrder_from_customer2(orderid,status)
{
if(confirm("Do You Want To Delete This Order From The List?"))
{
  
    loading_box();
   
    document.getElementById('big'+orderid+'_'+status).innerHTML="";
    http.open('post','customer2editing.aspx?action=deleteorder&orderid='+orderid);
    http.onreadystatechange = response_delete_order_customer2;
    http.send(null);
 }
}
function response_delete_order_customer2()
{
 if(http.readyState == 4)
        {
         select_a_customer=true;
            openPastOrdersCustomer2();
          window.clearTimeout(SD); 
        }
}
function change_statusOfOrders_from_customer2(orderid,newstatus,oldstatus)
{

     
  loading_box();
     document.getElementById('big'+orderid+'_'+oldstatus).innerHTML="";
    
     http.open('post','customer2editing.aspx?action=changestatus&orderid='+orderid+'&newstatus='+newstatus);
     http.onreadystatechange = handleresponse_change_statusOfOrders_from_customer2;
     http.send(null);
}
function handleresponse_change_statusOfOrders_from_customer2()
{
     if(http.readyState == 4)
        {
        
           var response = http.responseText;
           select_a_customer=true;
            openPastOrdersCustomer2();
            //openCurrentOrdersCustomer2();
          
           window.clearTimeout(SD); 
        }
}

function delete_list_from_customer2(listnumber)
{
if(confirm("Do You Want To Delete This List?"))
{
    var custID=document.getElementById('hiden_customerid').value;
    http.open('post','customer2editing.aspx?action=delete_openList&customerid='+custID+'&listnumber='+listnumber);
    http.onreadystatechange = response_openshoppinglistcustomer2;
    http.send(null);
 }

}
function openCurrentOrdersCustomer2()
{
    loading_box();
    var custID=document.getElementById('hiden_customerid').value;
    http.open('post','customer2editing.aspx?action=openorders&customerid='+custID+'&status=Current');
    http.onreadystatechange = response_open_CurrentOrders_customer2;
    http.send(null);
}
function moveWin()
 {
  //   // change the ++ on the left to -- in order to make the pop-up scroll backwards
  
 } 
function loading_box()
{    
   
    var msg=" Processing..Please..wait";
    document.getElementById("formbox").style.display="block";
    var theString="<table width='"+tabwidth+"' height='"+tabheight+"' border="+tborder+" cellspacing="+cspace+" cellpadding="+cpad+"><tr><td height='"+td1height+"' class='td1style' align='left'><b>"
    theString+=""+msg+"</b></td></tr>&nbsp &nbsp"
    theString+="</table>";
    if (document.layers) // Netscape 4.0+
    {
        document.formbox.document.write(theString)
        document.formbox.document.close()
        document.formbox.left=msgleft
        document.formbox.top=document.body.scrollTop+40
        document.formbox.visibility="show"
    }
    else
    {

        if(document.getElementById) // Internet Explorer 5.0+ and Netscape 6.0+
        {
            elm=document.getElementById("formbox")
            elm.innerHTML=theString
            elm.style.top=msgtop
            elm.style.left=msgleft
            elm.style.visibility = "visible"
        }
    }
  
 


   msgtop=document.documentElement.scrollTop+400;
   //moveTo(mov1,mov2);
  //loading_box();
   SD=window.setTimeout("loading_box();", 3); 
}

function scrollingDetector()
{
var scroltop=0;
if (navigator.appName == "Microsoft Internet Explorer")
    {
         if (document.documentElement && !document.documentElement.scrollTop)
         {
         alert('p');
         }
         else if (document.documentElement && document.documentElement.scrollTop)
         {
         scroltop=document.documentElement.scrollTop;
         }
         else if (document.body && document.body.scrollTop)
         {
         alert('r');
         }


     alert("You're at " + scroltop + " pixels.");
    }

else
    {
     alert("You're at " + window.pageYOffset + " pixels.");
    }
}


function openPastOrdersCustomer2()
{
 
    loading_box();
    var custID=document.getElementById('hiden_customerid').value;
    http.open('post','customer2editing.aspx?action=openorders&customerid='+custID+'&status=Done');
    http.onreadystatechange = response_open_PastOrders_customer2;
    http.send(null);
}
 function function_currentOrders_customer2(response)
 {
                 try
                  {
                  window.clearTimeout(SD); 
                  }
                  catch(g)
                  {
                  }
                 
                  document.getElementById("formbox").style.display="none";
                  var count=new Array();
                      if(response.indexOf('currentordercount:')!=-1)
                      {
                         count=response.split('currentordercount:');
                         count=count[1].split(':currentordercount');
                         document.getElementById('div_currentOrd_count').innerHTML=count[0];
                      }
          if(response.indexOf('Empty Grid')!=-1)
          {
           
            if(!select_a_customer)
              {
                 alert('There Is No Current Orders For This Customer');
             }
             else
             {
               
             }
          }
          else
          {
                   
           if(response.indexOf('<!--orders start here-->')!=-1)
                {
               
                    var newupdate=new Array();
                    newupdate=response.split('<!--orders start here-->');
                    if(newupdate[1].indexOf('<!--orders end here-->')!=-1)
                    {
                       var savedlist=new Array();
                       savedlist=newupdate[1].split('<!--orders end here-->');
                       document.getElementById('div_currentOrders').style.display="block";
                       document.getElementById('div_currentOrders').innerHTML=savedlist[0];
                      if(select_a_customer)
                      {
                      
                       openNotesCustomer2();
                      }
                      
                    }
                    
                }
          }
 
 }
function response_open_CurrentOrders_customer2()
{
     if(http.readyState == 4)
        {
      
           var response = http.responseText;
            function_currentOrders_customer2(response);
            makedisplayblock('div_currentOrders','div_link_oc_currentorders');
           
        }
}
function function_pastOrders_customer2(response)
{
                  try
                  {
                  window.clearTimeout(SD); 
                  }
                  catch(g)
                  {
                  }
    document.getElementById("formbox").style.display="none";
        var count=new Array();
                      if(response.indexOf('pastordercount:')!=-1)
                      {
                         count=response.split('pastordercount:');
                         count=count[1].split(':pastordercount');
                         document.getElementById('div_pastOrd_count').innerHTML=count[0];
                      }
        if(response.indexOf('Empty Grid')!=-1)
          {
            if(select_a_customer)
              {
               
               openCurrentOrdersCustomer2();
              }
              else
              {
             alert('There Is No Past Orders For This Customer');
             }
          }
          else
          {
                     
              if(response.indexOf('<!--orders start here-->')!=-1)
                {
                    var newupdate=new Array();
                    newupdate=response.split('<!--orders start here-->');
                
                    if(newupdate[1].indexOf('<!--orders end here-->')!=-1)
                    {
                       var savedlist=new Array();
                       savedlist=newupdate[1].split('<!--orders end here-->');
                     
                      document.getElementById('div_pastOrders').style.display="block";
                       document.getElementById('div_pastOrders').innerHTML=savedlist[0];
                      if(select_a_customer)
                      {
                      
                       openCurrentOrdersCustomer2();
                      }
                      
                    }
                    
                }
           }
}

function PagingOnPastOrders(Paging)
{     

    var lastIndex=document.getElementById('hidenIndex').value;
    var custID=document.getElementById('hiden_customerid').value;
    http.open('post','customer2editing.aspx?action=openorders&customerid='+custID+'&status=Done&Index='+lastIndex+'&'+Paging+'=true');
    http.onreadystatechange = response_open_PastOrders_customer2;
    http.send(null);
}
function response_open_PastOrders_customer2()
{
 
     if(http.readyState == 4)
        {
           var response = http.responseText;
           function_pastOrders_customer2(response);
           if(response.indexOf('LastIndex:')!=-1)
           {
               var arr=new Array();
               arr=response.split('LastIndex:');
               arr=arr[1].split(':LastIndex');
               document.getElementById('hidenIndex').value=arr[0];
               
           }
          
         
          if(response.indexOf('Show Prevoius Button')!=-1)
           {
            document.getElementById('pagerPrev').style.display="Block";
            document.getElementById('pager_prev_top').style.display="Block";
           }
           if(response.indexOf('Show Next Button')!=-1)
           {
             document.getElementById('pagerNext').style.display="Block";
             document.getElementById('pager_next_top').style.display="Block";
           }
           if(response.indexOf('remove Next button')!=-1)
           {
             document.getElementById('pagerNext').style.display="none";
             document.getElementById('pagerPrev').style.display="Block";
             document.getElementById('pager_next_top').style.display="none";
             document.getElementById('pager_prev_top').style.display="Block";
             
             
           }
             
           
          
          if(response.indexOf('remove Prev button')!=-1)
          {
             document.getElementById('pagerNext').style.display="Block";
             document.getElementById('pagerPrev').style.display="None";
             document.getElementById('pager_next_top').style.display="block";
             document.getElementById('pager_prev_top').style.display="none";
          }
          if(response.indexOf('Display Paging Block:')!=-1)
          {
            var dispBlock=new Array();
            dispBlock=response.split('Display Paging Block:');
            dispBlock=dispBlock[1].split(':Display Paging Block');
             document.getElementById('paging_block_pastorders').innerHTML=dispBlock[0];
               document.getElementById('paging_block_top').innerHTML=dispBlock[0];
            
          }
           
      
           makedisplayblock('div_pastOrders','div_link_oc_pastorders');
        }
}


function select(customerid)
{
  
    close_all_ship('dekpopup','link_open_customer');
    http.open('post','order_page.aspx?action=select_customer&custid='+customerid);
    http.onreadystatechange = select_customer;
    http.send(null);
}
function payment_all_area(response)
{

      if(response.indexOf('<!--payment_all_area_start-->')!=-1)
       {
            var billing_add=new Array();
            billing_add=response.split('<!--payment_all_area_start-->');
           
           if(billing_add[1].indexOf('<!--payment_all_area_end-->')!=-1)
               {
                 var new_bill=new Array();
                 new_bill=billing_add[1].split('<!--payment_all_area_end-->');
                
                 document.getElementById('payement_order_page').innerHTML=new_bill[0];
                 
               }
              
       }

}
function select_customer()
{
      if(http.readyState == 4)
        {
           var response = http.responseText;
         
           Company_Area(response);
           product_table_area(response);
           shipping_charges_area(response);
           billing_address_area(response);
           loginarea(response);
           all_shippaddress_area(response);
           shipping_address_area(response);
           payment_all_area(response);
           creditcard_area(response);
           payment_all_area(response)
           //payment_area(response); 
           document.getElementById('all_cardDetails').style.display="none";
           document.getElementById('div_open_cards').style.display="block";
           open_all_ship('all_cardDetails','div_open_cards');
          
           var radioButtons = document.getElementsByName("r1");
           var _selectPayment="CreditCard";
           if(response.indexOf('Payement Method is:')!=-1)
           {
               var tharr=new Array();
               tharr=response.split('Payement Method is:');
               tharr=tharr[1].split(':Payement_Method_ends');
               _selectPayment=tharr[0];
              
           }
            for (var x = 0; x < radioButtons.length; x ++) 
               {
                   if (radioButtons[x].value==_selectPayment) 
                   {
                     radioButtons[x].checked=true;
                   }
               }
              payment_selected(_selectPayment);
        }
}



function handle_same_as_billing()
  {
       if(http.readyState == 4)
        {
           var response = http.responseText;
           if(response.indexOf('Billing Address Is Not Saved')!=-1)
           {
               alert('Billing Address Is Not Saved');
           }
           else
           {
               shipping_charges_area(response);
               shipping_address_area(response);
               close_all_ship('ship_pop','div_open_ship_addrs');
           }
       }
 }
function convertoOrderFromAll_list(action,listnumber,sessionid,customerid)
{
        converttoOrder=true;
   
        http.open('post', 'shoppinglist.aspx?action='+action+'&LN='+listnumber+'&sessionid='+sessionid+'&customerid='+customerid);
        http.onreadystatechange = handleResponse;
        http.send(null);
 
}
function order(id,query)
{  
   window.location="order_page.aspx?action=addto_order&productID="+id+'&'+query;return false;
}

function changecolor(count)
 {
  var tbl=document.getElementById('table_add'+count);
 

  tbl.style.background ="teal";
  
 }
 function mouseoutcolorItem(count)
 {
  var tbl=document.getElementById('table_add'+count);
  tbl.style.background ="yellow";
 }
 function mouseoutcoloralterItem(count)
 {
  var tbl=document.getElementById('table_add'+count);
 
  tbl.style.background ="yellow";
 }
 function changecolor_ship(id)
 {
  var tbl=document.getElementById(id);
  tbl.style.background ="teal";
 }
 function mouseoutcolorItem_ship(id)
 {
  var tbl=document.getElementById(id);
  tbl.style.background ="yellow";
 }
 function mouseoutcoloralterItem_ship(id)
 {
  var tbl=document.getElementById(id);
  tbl.style.background ="yellow";
 }
 function disbal_company(id)
 {

      var comp=document.getElementById(id).value;
      if(comp.length>35)
       {
          document.getElementById(id).value = comp.substring(0, 35);
          alert('This Field Allows Only 35 Characters');
       }
 }
 ///trial starts******************************************************
function onenterkeycustomer2()
 {
        //disbal_company(txt_company);
     
        
        var usercompany="ALL";
        var usertype="ALL";
        var radiobuttons=document.getElementsByName("radio_list_company");
        for(var x=0;x<radiobuttons.length;x++)
        {
           if(radiobuttons[x].checked)
           {
            usercompany=radiobuttons[x].value;
           }
        }
        radiobuttons=document.getElementsByName("radio_list_usertype");
        for(var x=0;x<radiobuttons.length;x++)
        {
           if(radiobuttons[x].checked)
           {
            usertype=radiobuttons[x].value;
           }
        }
       
        
        if(usercompany=="ALL")
        {
        usercompany="";
        }
        if(usertype=="ALL")
        {
        usertype="";
        }
        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('txt_contact_person').value+"!"+document.getElementById('txt_ext_bill').value+"!";
        srchword+=document.getElementById('txt_fax').value+"!"+usercompany+"!"+usertype;
   
        http.open('post', 'searchcustomer2.aspx?srchword='+srchword);
        http.onreadystatechange = handleResponsepopup;
        http.send(null);
       
  }
 
function onenterkey(usercompany,usertype,contact,ext,fax,txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state,e)
 {
 
 
        //disbal_company(txt_company);
        
        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(contact).value+"!"+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;
        
        http.open('post', 'search.aspx?srchword='+srchword);
        http.onreadystatechange = handleResponsepopup;
        http.send(null);
       
  }
function handleResponsepopup()
{
 if(http.readyState == 4)
        {
    
        
          var response = http.responseText;
      
          if(response.indexOf('No Data Available')!=-1)
          {
            // popup('No Data Available','yellow')
            popupvisible('No Data Available');
          }
          else
          {
               var update = new Array();
              
               if(response.indexOf('"form1">' != -1)) 
                {
                    update = response.split('"form1">');
                   
                }
         
               var responsepart=update[1].toString();
           
               var arr=new Array();
               var t= update[1].indexOf('</form>');
      
                if(t!= -1)
                {
                    arr = responsepart.split('</form>');
                }
              //popup(arr[0],'yellow');
              
             popupvisible(arr[0]);
              
           }
        
        
         
        }
        
}
Xoffset=-60;    // modify these values to ...
Yoffset= 20;    // change the popup position.


var old,skn,iex=(document.all),yyy=-1000;

var ns4=document.layers;
var ns6=document.getElementById&&!document.all;
var ie4=document.all;

function popupvisible(msg)
{

commondekpopup();

var content=msg;

if(ns4){skn.document.write(content);skn.document.close();skn.visibility="visible";document.getElementById('wrap').style.visible="visible"}
 if(ns6){document.getElementById("dekpopup").innerHTML=content;skn.display='';document.getElementById('wrap').style.display=''}
 if(ie4){document.all("dekpopup").innerHTML=content;skn.display='';document.getElementById('wrap').style.display='';}
 document.getElementById('dekpopup').style.display="block";
 document.getElementById('wrap').style.display="block";
}

function commondekpopup()
{
    if (ns4)
    {
         skn=document.dekpopup
    }
    else if (ns6)
    {
    
         skn=document.getElementById("dekpopup").style
    }
    else if (ie4)
    {
        skn=document.all.dekpopup.style
    }
    if(ns4)
    {
         document.captureEvents(Event.MOUSEMOVE);
    }
    else
    {
       skn.visibility="visible"
       skn.display="block"
    }
    
}
function makedisplaynone(id,subid)
{



document.getElementById(id).style.display="none";
document.getElementById(subid).style.display="block";
}
function makedisplayblock(id,subid)
{

document.getElementById(subid).style.display="none";
document.getElementById(id).style.display="block";
}
function kill()
{
document.getElementById('dekpopup').style.display="none";

    
} 
function opencustomerlist(id)
{
document.getElementById('dekpopup').style.display="block";
document.getElementById(id).style.display="none";

    
} 











 //////**************************trial ends***************************





//****************************************************************
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;

}

