﻿//prevoious ajax//

// JScript File
function open_all_ship(id)
{
 document.getElementById(id).style.display="block";
}
function close_all_ship(id)
{
 document.getElementById(id).style.display="none";
}
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";
     
    }
}



 var pub_query="";
function addItems(query)
{
pub_query=query;
    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;
           }
     }
     http.open('post', 'order_page.aspx?action=addItems&company='+comp+'&status='+printd);
     http.onreadystatechange =responsetoproductspage;
     http.send(null);
     
}
function responsetoproductspage()
{
  if(http.readyState == 4)
    {
     location.href("products.aspx?"+pub_query);
    }
}
function printdoc()
{
 window.print();
}


function loginfn(action,query1,email,psw)
{
 
    var login_email=document.getElementById(email).value;
   
    var login_psw= document.getElementById(psw).value;
  
    http.open('get','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('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
       {
            var newarr=new Array();
            newarr=response.split('<!--redirect starts here-->');
            newarr=newarr[1].split('<!--redirect ends here-->');
           
            location.href(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 onclick_search(clintid,e)
{

    var btn=document.getElementById(clintid);
   
    
     if(window.event)
    {
              key = window.event.keyCode;     //IE
    }
    else
     {
          key = e.which;     //firefox
          
     }
 
    if (key == 13)
    {
      
        if(btn!=null)
        {
        __doPostBack('lnk_Go', 'eventArgument') 
      
        //document.form1.submit();
        // btn.click();
           
        }
    }
    
}
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 (key == 13)
    {
        var count=document.getElementById('hiden_count').value;
        sndRequpdate(action,count)
    }
        
}
function sndRequpdate(action,ct)
{
    var ship;
    var price;
    var qty;
    var productid;
    for(var y=0;y<ct;y++)
    {
    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;

        arr[y]=price;
        qtyarray[y]=qty;
        prodarr[y]=productid;
       
    }

    var test=arr.join('-');
    var prod=prodarr.join(',');
    var qtyar=qtyarray.join(',');

    http.open('POST', 'shoppinglist.aspx?action='+action+'&arr='+test+'&prodarr='+prod+'&qtyarr='+qtyar+'&ship='+ship);
    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")
    {
    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)
    {
         alert(Listnumber);
        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');
    location.href("order_page.aspx?"+convert);
    }
    else
    {
     
    
     
       var update = new Array();
       if(response.indexOf('added To cart from shoppinglist')!=-1)
       {
       location.href("addtocart.aspx?title=shoppinglist");
       }
       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];
                      
                    }
                    
                }
            }
          }
          }
        
     } 
}    
            
       

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;
}





//prevoius ajax
































//shopping list//


//shoppingList//








function delete_order(orderid,rownumber,status)
{
     http.open('post', 'orders.aspx?action=delete_order&orderid='+orderid+'&rownumber='+rownumber+'&status='+status);
     http.onreadystatechange = handleresponse_deleted;
     http.send(null);
}
function printorder(orderid)
{
//window.open("labels.aspx","mmwjnprint","");
location.href("orders.aspx?printticket=true&orderid="+orderid);

}
function Print_Label_orders(ordid)
{

 http.open('post','order_page.aspx?action=Print_Label_orders&orderid='+ordid);
 http.onreadystatechange = printlabel;
 http.send(null);
}
function changestatus_order(orderid,listid)
{
   
     var new_status=listid;
     http.open('post','orders.aspx?action=changestatus&orderid='+orderid+'&newstatus='+new_status);
     http.onreadystatechange = handleresponse_deleted;
     http.send(null);
}
function handleresponse_deleted()
{
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('orders').innerHTML=newarr[0];
             
           }
       }
   }
}
function printlabel()
{
  if(http.readyState == 4)
    {
       var response = http.responseText;
      
       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]);
           }
       }
       else
       {
         if(response.indexOf('FailedVoided')!=-1)
         {
         alert('Failed To Process,Contact UPS with TrackingNumber');
         }
         else
         {
           location.href("orders.aspx?print=true");
            //window.open("labels.aspx","mmwjnprint","");
         }
         
      }
  
    
    }
}

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");
  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)
{
location.href("order_page.aspx?edit_order=true&orderid="+orderid+"&customerid="+customerid+"&neworder=true");
}
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);
 }
function handle_save_withoutalert()
{

}
function void_shipmnt()
{
     http.open('post', 'order_page.aspx?action=void_shipmnt');
     http.onreadystatechange =voidship;
     http.send(null);
}
function voidship()
{
   if(http.readyState == 4)
       {
           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)
               {
               alert('Shipment Has Been Voided');
               }
           }
          
       }
}
function saveorder()
{
    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;
           }
     }


     http.open('post', 'order_page.aspx?action=SaveOrder&status='+exp);
     http.onreadystatechange =handle_saveorder;
     http.send(null);
}
function handle_saveorder()
{
   if(http.readyState == 4)
    {
    var err=false;
     var response = http.responseText;
     
         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(!err)
           {
             alert('saved');
             location.href("orders.aspx");
           }
     }
}
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]);
        }
        }
    }
 }

function process_ups(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('*');
 
 
 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!=8)
         {
           addressfieldempty="true";
         }
     }
 }
                     
 if(addressfieldempty=="false")
    {    
          
       http.open('post','order_page.aspx?action='+action+'&shipping_address='+shippingarra);
       if(action=="void_ship")
       {
       http.onreadystatechange = voidship;
       }
       else
       {
           if(action=="print_label")
           {
             
              http.onreadystatechange = printlabel;
           }
           else
           {
              http.onreadystatechange = handleResponse_itemsadd_ship;
           }
       }
        http.send(null);
   }
   else
   {
    alert('Shipping Address is not Filled');
   }
                    
 
}




function savethirdparty(zip,account)
{
     http.open('post', 'order_page.aspx?action=save_thirdparty&zip='+zip+'&account='+account);
     http.onreadystatechange = alertsaved;
     http.send(null);

}
function thirdparty()
{
    if(document.getElementById('thirdparty_details').style.display=="none")
    {
    document.getElementById('thirdparty_details').style.display="block";
    }
    else
    {
    document.getElementById('thirdparty_details').style.display="none";
    }
}
function selected_carditcard()
{
if(http.readyState == 4)
        {
           var response = http.responseText;
           creditcard_area(response);
           document.getElementById('all_cardDetails').style.display="none";
        }
}

function payment_selected(method)
{

    switch(method)
    {
     case "BillTo":
     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":
     document.getElementById('div_ebay').style.display="none";
     document.getElementById('clearingbox_stuff').style.display="none";
     document.getElementById('div_cod_amnt').style.display="none";
    
     http.open('post', 'order_page.aspx?action=all_cards');
     http.onreadystatechange = selected_carditcard;
     http.send(null);

     break;
     case "COD":
     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":
     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":
     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)
{

    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)
     {
     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":
     payment[0]=document.getElementById(codamount).value;
     break;
     case "COD Certified":
     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 = alertsaved;
     http.send(null);

}
function save_optional(notes,thirdparty,pio,blindship,sticker,thirdpartyzip,thirdpartyaccnt)
{
                     var shipping=new Array();
                     shipping[0]= document.getElementById(notes).value;
                     shipping[1]=document.getElementById(thirdparty).checked;
                     shipping[2]=document.getElementById(pio).value;
                     shipping[3]=document.getElementById(blindship).checked;
                     shipping[4]=document.getElementById(sticker).checked;
                     if(document.getElementById(thirdparty).checked)
                     {
                     shipping[5]=document.getElementById(thirdpartyzip).value;
                     shipping[6]=document.getElementById(thirdpartyaccnt).value;
                     
                     }
                     var optional=shipping.join('*');
                    
                     http.open('post', 'order_page.aspx?action=save_optional&optional='+optional);
                     http.onreadystatechange = alertsaved;
                     http.send(null);
}
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";
        }
}
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('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 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];
          }
      }
}
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(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('post', 'order_page.aspx?action=save_ship_address&shipping_address='+shippingarra);
                     http.onreadystatechange = handleResponse_saveshipaddrss;
                     http.send(null);
}
function handleResponse_saveshipaddrss()
{
if(http.readyState == 4)
    {
   
       var response = http.responseText;
       shipping_charges_area(response);
       alert('saved');
  
    }

}
function savebilling(txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state)
{
          var str=document.getElementById(txt_email).value;
   
          if(document.getElementById(txt_email).value=="")
          {
             alert('Enter a valid Email Address to create a new account');
          }
          else
          {
                if((str.indexOf(".") > 2) && (str.indexOf("@") > 0))
                {
             
       	             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;
                    
                     for(var t=0;t<billing.length;t++)
                     {
                       if(billing[t].indexOf("&")>0)
                       {
                          billing[t]=billing[t].replace("&","and");
                       }
                     }
                    
                     
                     var billingarra=billing.join('*');
                     alert(billingarra);
                     http.open('post', 'order_page.aspx?action=savebilling&billing='+billingarra);
                     http.onreadystatechange = alertsaved;
                     http.send(null);
        	       
		         }
		         else
		         {
		           alert("Invalid E-mail ID");
        	      
                   
                 }
         }
                
}
function alertsaved()
{
 if(http.readyState == 4)
    {
     var response = http.responseText;
    
     if(response.indexOf('Extra Characters in BillingAddress')!=-1)
       {
        alert('Extra Characters in BillingAddress');
       }
       else
       {
       loginarea(response);
        alert('saved');
       }
   
   
    }
}
function clearbilling(txt_fname,txt_city,txt_add1,txt_add2,txt_zip,txt_phone,txt_email,txt_company,txt_lastname,state)
{
            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="";
                
                
               
}
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);
       shipping_charges_area(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
       {
      
       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
   {
       http.open('post','order_page.aspx?action='+action);
       http.onreadystatechange = handleResponse_create_box;
       http.send(null);
   }
  
  
}
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('*');
 
  
 
  http.open('post', 'order_page.aspx?action=select_color&value='+document.getElementById(ddn_id).value+'&shipping_address='+shippingarra);
  http.onreadystatechange = handleResponse_itemsadd_ship;
  http.send(null);
  
}

function delet_product_orderpage(action,id)
 {
 
    http.open('post', 'order_page.aspx?action='+action+'&deletingid='+id);
    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 (key == 13)
    {
       
        var count=document.getElementById('hiden_count').value;
        Requpdate_orderpage(action,count);
       // document.getElementById('lnl_save').disabled = true;

        //lnl_save
        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();  
    if(document.getElementById('txt_shipping')!=null)
        {
            ship=document.getElementById('txt_shipping').value;
           
        }
    for(var y=0;y<coun;y++)
    {
    
       
        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;

        arr[y]=price;
        qtyarray[y]=qty;
        prodarr[y]=productid;
      
    }

    var test=arr.join('-');
    var prod=prodarr.join(',');
    var qtyar=qtyarray.join(',');
   
    http.open('post', 'order_page.aspx?action=update&arr='+test+'&prodarr='+prod+'&qtyarr='+qtyar+'&ship='+ship);
    if(action=="update_ship")
    {
        http.onreadystatechange = handleResponse_itemsadd_ship;
    }
    else
    {
     http.onreadystatechange = handleResponse_itemsadd;
    }
   
    http.send(null);
    
}
function handleResponse_itemsadd_ship()
{
 if(http.readyState == 4)
    {
   
       var response = http.responseText;
       shipping_charges_area(response);
  
    }
}

function handleResponse_itemsadd()
{

    if(http.readyState == 4)
    {
      var response = http.responseText;
      UPS_table_area(response);
      product_table_area(response);
      shipping_charges_area(response);
    }
}
function select(customerid)
{
  
    kill();
    http.open('post','order_page.aspx?action=select_customer&custid='+customerid);
    http.onreadystatechange = select_customer;
    http.send(null);
}
function select_customer()
{
  if(http.readyState == 4)
        {
           var response = http.responseText;
           shipping_charges_area(response);
           billing_address_area(response);
           loginarea(response);
           all_shippaddress_area(response);
           shipping_address_area(response);
           creditcard_area(response);
           payment_area(response);
           
       }
}
function handle_same_as_billing()
  {
      if(http.readyState == 4)
        {
           var response = http.responseText;
           shipping_charges_area(response);
           shipping_address_area(response);
          
       }
 }

function order(id,query)
{  location.href("order_page.aspx?action=addto_order&productID="+id+'&'+query);
}
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 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);
       
  }
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.dek.style
    }
    if(ns4)
    {
         document.captureEvents(Event.MOUSEMOVE);
    }
    else
    {
       skn.visibility="hidden"
       skn.display="none"
    }
    
}
function kill()
{
document.getElementById('dekpopup').style.display="none";

    
} 
function open()
{
document.getElementById('dekpopup').style.display="block";
}
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;

}

