﻿ 

function ShowBigImg(obj,left_,top_,showbigimg)
{
    var bgobj;
    if(obj.tagName=="TD")
    {
      bgobj=obj.parentNode.parentNode.parentNode;
      obj.parentNode.parentNode.parentNode.className='tbodybg'
    }
    else
    {
       if(obj.tagName=="IMG")
       {
           var objnode= GetParentTag(obj.parentNode);
           if(objnode!=null)
           {
             bgobj=objnode.parentNode.parentNode.parentNode;
             objnode.parentNode.parentNode.parentNode.className='tbodybg';
             
           }
       }
    }
    
  
      
    
    if(showbigimg==null || showbigimg==true)
    {
        var boxObj = document.createElement("img");
        var imgelement=obj.getElementsByTagName("img")[0];
         
        if(obj.tagName=="IMG")
        {
          imgelement=obj;
          
        }
        var left=getLeft(imgelement)-left_;
        var top=getTop(imgelement)-top_;
            boxObj.id = "cartmsg";
            boxObj.style.position = "absolute";
            boxObj.style.zIndex = "9999";
            //boxObj.style.top="40px";
            //boxObj.style.left="50%";
            boxObj.style.top = top + "px";
            boxObj.style.left = left + "px";
            boxObj.style.margin = "0 0 0 0px";
            boxObj.style.padding = "3px 6px 0 6px";
            boxObj.style.width = "150px";
            boxObj.style.height = "150px";   
            boxObj.src = imgelement.src;
            boxObj.style.cursor="pointer";
            boxObj.onmouseout=function(){HiddenBigImg(this)}
            if(bgobj!=null)
            {
               boxObj.onmouseover=function(){bgobj.className='tbodybg';}
               
            }
            
            try{
            boxObj.onclick=function(){imgelement.parentNode.click();};
            }
            catch(e)
            {
            
            }
            
            document.body.appendChild(boxObj);
    }
}


function HiddenBigImg(obj)
{

    if($$("cartmsg")!=null)
    {
       document.body.removeChild($$("cartmsg"));
    }   
    
    if(obj.tagName=="TD")
    {
      obj.parentNode.parentNode.parentNode.className='';
    }
     
    
}

function GetParentTag(element)
{
   
   if(element!=null && element.parentNode.parentNode.tagName=="TD")
   {
            return element.parentNode.parentNode;
   }
  
}

function getTop(e){

var offset=e.offsetTop;
if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
return offset;

}
 
function getLeft(e){

var offset=e.offsetLeft;
if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
return offset;

}


function payonline(obj)
{
     
    var paypal= window.open("blank.html","test");   
    var oldhtml=obj.parentNode.innerHTML;
    var html="<form id='payatonce' action='https://www.paypal.com/cgi-bin/webscr' method='post' style='display:none;'>";
     html=html+oldhtml;
     html=html+"<input type='submit' id='paypalsubmit' value='paypaysubmit'/>";
     html=html+"</form>";
      
     paypal.document.write(html);
     document.getElementById('paypaysubmit').click();
        
}


String.prototype.gblen = function() {  
    var len = 0;  
    for (var i=0; i<this.length; i++) {  
        if (this.charCodeAt(i)>127 || this.charCodeAt(i)==94) {  
            len += 2;  
        } else {  
           len ++;  
        }  
    }  
    return len;  
} 

function clearinput(obj,objtxt)
{
    if(obj.value==objtxt)
    {
       obj.value="";
    }
}

function scrollup(o,d,c){
	if(d==c){
		var t=getFirstChild(o.firstChild).cloneNode(true);
		o.removeChild(getFirstChild(o.firstChild));
		o.appendChild(t);
		t.style.marginTop="0px";
	}else{
		c+=2;
		getFirstChild(o.firstChild).style.marginTop=-c+"px";
		window.setTimeout(function(){scrollup(o,d,c)},20);
	}
}

function getFirstChild(node){
  while (node.nodeType!=1)
  {
   	  node=node.nextSibling;
  }
  return node;
}


function DeleteFav(obj,id)
{
    var param="action=deletefavs&id="+id;
    $$.Ajax.post("/ajax.aspx",param,function(x)
    {
        if(x.responseText=="1")
        {
            obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
        }
        else
        {
          
        }
    },
    function(x)
    {
       
    })

}


function showsubnav(obj)
{
  var uls= obj.getElementsByTagName("ul");
  if(uls.length>0)
  {
     uls[0].style.display="block";
  }
  
}
 
function hiddensubnav(obj)
{
  var uls= obj.getElementsByTagName("ul");
  if(uls.length>0)
  {
     uls[0].style.display="none";
  }  
}


function GetSmallClassList(obj)
{
     var param="action=getsmallclass&bigclassid="+obj.options[obj.selectedIndex].value;  
     $$.Ajax.post("/ajax.aspx",param,function(x)
     {
        $$("SmallClass").outerHTML=x.responseText;
     },
     function(x)
     {
        
     })
   
}



function SearchOrder(obj)
{
  
   var html="<form method='post' action='SearchOrder.aspx' name='tempform' id='tempform'>";
   html=html+"<input type='text' value='"+obj.parentNode.getElementsByTagName("input")[0].value+"' name='orderkey' id='orderkey' /><input type='submit' id='tempsubmitbt'/>";
   html=html+"</form>";
   
   $$("submittempform").innerHTML=html;
   $$("tempsubmitbt").click();
}

function TrackingOrder(obj)
{

   var html="<form method='post' action='/tracking.aspx' name='tempform' id='tempform'>";
   html=html+"<input type='text' value='"+obj.parentNode.getElementsByTagName("input")[0].value+"' name='orderNumber' id='orderNumber' /><input type='submit' id='tempsubmitbt'/>";
   html=html+"</form>";
   $$("submittempform").innerHTML=html;
   $$("tempsubmitbt").click();
   
}

function SearchPorducts(obj)
{

   var html="<form method='get' action='/research_product.aspx' name='tempform' id='tempform' target='searchorder'>";
   html=html+"<input type='hidden' name='BigClassID' value='0' /><input type='text' value='"+obj.parentNode.getElementsByTagName("input")[0].value+"' name='keyword' id='keyword' /><input type='submit' id='tempsubmitbt'/>";
   html=html+"</form>";
   $$("submittempform").innerHTML=html;
   $$("tempsubmitbt").click();
   
}

function SaveMyAlert(obj)
{

    var bigclassid=$$("BigCatList").options[$$("BigCatList").selectedIndex].value;
    var smallclassid=$$("SmallClass").options[$$("SmallClass").selectedIndex].value;
    var param="action=savemyalert&bigclassid="+bigclassid+"&smallclassid="+smallclassid+"&SubscribeName="+$$("SubscribeName").value;
    obj.disabled=true;
    $$.Ajax.post("/ajax.aspx",param,function(x)
    {
        if(x.responseText=="1")
        {
           $$("opttext").innerHTML="Save Successful!";
        }
        else
        {
            $$("opttext").innerHTML="Save Failed!";
        }
    },
    function(x)
    {
    
    });
    
}



function EditQty(obj,id)
{
   
}

function DeleteProductItem(obj,id)
{
     var param="action=deletecartitem&actionid="+id;
    
     $$.Ajax.post("ajax.aspx",param,function(x)
     {
        if(x.responseText=="1")
        {
          window.location.reload();
        }
       
     },function(x)
     {
         
     })
     
}

function SearchOrdersToAdd(obj,type)
{

   var xinghao=$$("key").value;
   var param="action=searchadd&xinghao="+encodeURIComponent(xinghao)+"&qty=1";
   if(xinghao=="")
   {
      
       return ;
   }
   else
   {
     $$.Ajax.post("ajax.aspx",param,function(x)
     {
        if(x.responseText=="1")
        {
          window.location.reload();
        }
        else
        {
           $$("key").value="Only item number";
           $$("key").style.color="red"; 
        }
     },function(x)
     {
        //$$("adderrbox").innerHTML="No product to add. please in a Item No.";
     })
   }

}

function deletealter(obj,id)
{
    var param="action=deletealert&id="+id;
    $$.Ajax.post("/ajax.aspx",param,function(x)
    {
        obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
    }
    ,function(x)
    {
    
    })

}

function DeleteSelectAlter(obj)
{
    var allinputs=$$("#ShopCart input");
    var ids="";
     for(j=1;j<allinputs.length;j++)
     {
       ids+=allinputs[j].id+",";
     }
     ids=ids+"0";
      
    var param="action=deleteselectalert&ids="+ids;
    $$.Ajax.post("/ajax.aspx",param,function(x)
    {
        var alltr= $$("#ShopCart tr");
        for(n=1;n<alltr.length;n++)
        {
           alltr[n].parentNode.removeChild(alltr[n]);
        }
    }
    ,function(x)
    {
    
    })
}

function CheckAllBox(obj)
{
 
   var inputs = obj.parentNode.parentNode.parentNode.getElementsByTagName("input");
   for(j=0;j<inputs.length;j++)
   {
      inputs[j].checked=obj.checked;
   }
   
}


function CheckAll(obj)
{
 
   var inputs = $$(".chkbox");
    
   for(j=0;j<inputs.length;j++)
   {
      inputs[j].checked=obj.checked;       
   }
   
}

function deleteselectcheckbox(actionid,tablename)
{
   var param="action=deletecheckboxitem&tablename="+tablename;
   var inputs = $$(".chkbox");    
   var ids=[];
   for(j=0;j<inputs.length;j++)
   {
      if(inputs[j].checked==true)
      {
        ids.push(inputs[j].value);   
      }    
   }
   if(ids.length==0)
   {
     $$("btactiontxt").innerHTML="Please select one product to remove at least!";     
     return ;
   }
   else
   {
     $$("btactiontxt").innerHTML="";
   }
   param=param+"&filed="+actionid+"&ids="+ids.join(",");
   $$.Ajax.post("ajax.aspx",param,function(x)
   {
      window.location.reload();
      
   },function(x)
   {
   
   })
   
}


function updateselectcheckbox(actionid,tablename)
{
  
   
   var param="action=updatecheckboxitem&tablename="+tablename;
   var inputs = $$(".chkbox");    
   var qtys=$$(".qtychk");
   var ids=[];
   var values=[];   
   var proids=[];
   for(j=0;j<inputs.length;j++)
   {
      if(inputs[j].checked==true)
      {
        ids.push(inputs[j].value); 
        values.push(qtys[j].value);
        proids.push(inputs[j].name);
      }    
   }
   if(ids.length==0)
   {
     $$("btactiontxt").innerHTML="Please select one product to update at least";     
     return ;
   }
   else
   {
     $$("btactiontxt").innerHTML="";
   }
   param=param+"&filed="+actionid+"&ids="+ids.join(",")+"&values="+values.join(",")+"&proids="+proids.join(",");
    
   $$.Ajax.post("ajax.aspx",param,function(x)
   {
      window.location.reload();
      
   },function(x)
   {
   
   })
   
}

function SendServiceMessage(obj)
{
   var titletxt=$$("title").value;
   var htmltxt=$$("html").value;
   var param="action=savemessage&title="+titletxt+"&html="+htmltxt;
   $$.Ajax.post("/ajax.aspx",param,function(x)
   {
      $$("serviceMessage").innerHTML=$$("serviceMessage").innerHTML+"<div class='messageitem'><h3>"+titletxt+"</h3><div>"+htmltxt+"</div></div>";
   }
   ,function(x)
   {
   
   })

}


function checkishtml()
{
            var url=window.location.href;
            if(url.toLowerCase().indexOf(".html")!=-1 || url.toLowerCase()=="http://www.usbsea.com/")
            {  
               return true
            }
            else
            {
              return false;
            }
            
}

function initselectrate()
{
            var obj=$$("Header_RateType");
            var ishtml=checkishtml();
            if(ishtml==true)
            {     
               //document.write("<style type='text/css' id='priceshowcss'>.htmlhlflag,.htmlhlprice {display:none;}</style>");
               $$.Cookies.set("ratetypesflag","$");
               $$.Cookies.set("ratetypesname","USD");
               $$.Cookies.set("oldratetypesflag","$"); 
               $$.Cookies.set("oldratetypesname","USD");    
               obj.options[0].selected=true;    
               window.onload=function(){                
                  ChangeHTMLRate();
                 // $$("priceshowcss").parentNode.removeChild($$("priceshowcss"));
                };               
               return ;
            }
            var flag=$$.Cookies.get("ratetypesflag");
            if(flag==null || flag=="")
            {
               flag="$";
               $$.Cookies.set("ratetypesflag","$");
               $$.Cookies.set("ratetypesname","USD");
            }
             
            for(j=0;j<obj.options.length;j++){
              if(obj.options[j].value==flag)
              {
                 obj.options[j].selected=true;
              }
            }
            
            
 }

function changeTypes(obj)
{
    var oldtypeflag= $$.Cookies.get("ratetypesflag");
    var oldtypename= $$.Cookies.get("ratetypesname");
    if(oldtypeflag==null)
    {
       oldtypeflag="$";
    }
    if(oldtypename==null)
    {
       oldtypename="USD";
    }
    
    $$.Cookies.set("oldratetypesflag",oldtypeflag);
    $$.Cookies.set("oldratetypesname",oldtypename);    
    $$.Cookies.set("ratetypesflag",obj.options[obj.selectedIndex].value);
    $$.Cookies.set("ratetypesname",obj.options[obj.selectedIndex].text);
    var ishtml=checkishtml();
    if(ishtml==false)
    {
        window.location.reload();
        return ;
    }
    
    ChangeHTMLRate();
    
}


function ChangeHTMLRate()
{
   
     var ishtml=checkishtml();
     if(ishtml==false)
     {   
        return ;
     }
    
    var allpricelist=$$(".htmlhlprice");
    var allpriceflag=$$(".htmlhlflag");
    var oldrate = $$.Cookies.get("oldratetypesflag");
    var newrate = $$.Cookies.get("ratetypesflag");
    if(oldrate==null)
    {
      oldrate="$";
    }
    
    if(newrate==null)
    {
      newrate="USD";
    }
     
    for(i=0;i<allpriceflag.length;i++)
    {
       
       allpriceflag[i].innerHTML=newrate;  
        
    }
      
    for(i=0;i<allpricelist.length;i++)
    {
      try{
         
         allpricelist[i].innerText=(parseFloat(allpricelist[i].getAttribute("name"))/window.hlarray[newrate]).toFixed(2);
       }
       catch(e)
       {
         
       } 
      
    }
    
    
    
}


function SetCurrentNav(num)
{
   $$.Cookies.set("usbseanavindex",num);
}

function SetCurrentSubNav(obj)
{
   var num=obj.split("|")[0].replace("qh_con","")
   SetCurrentNav(num);  
   $$.Cookies.set("usbseasubnavindex",obj);
}

function InitUsbseaNavs()
{
    var nav= $$.Cookies.get("usbseanavindex");
    if(nav!=null)
    {
       qiehuan(nav);
    }
    var subnav=$$.Cookies.get("usbseasubnavindex");
    if(subnav!=null)
    {
      var lis=$$("#"+subnav.split("|")[0]+" li");
      lis[parseInt(subnav.split("|")[1])].className="curruentsubnav";
    }
}

function changeproductspage(url,page,pagecount)
{
   if(page>pagecount)
   {
     page=pagecount;
   }    
   window.location.href=url+page;
}

function SetProductsCookies(ProductsID)
{
   var ids=$$.Cookies.get("usbseRevenltlyproduct");
   if(ids==null)
   {
      ids=ProductsID;
   }
   else
   {
       var idarray=ids.split(",");
       var hasid=false;
       for(i=0;i<idarray.length;i++)
       {
          if(idarray[i]==ProductsID)
          {
            hasid=true;
          }
       }   
       if(hasid==false && !isNaN(parseInt(ProductsID)))
       {
         ids=ids+","+parseInt(ProductsID);
       }
   }
   
   $$.Cookies.set("usbseRevenltlyproduct",ids);
   
}


function BuyProducts(obj,id,xinghao)
{
   var num=1;
   var inputs=obj.parentNode.getElementsByTagName("input");
   if(inputs.length>0)
   {
     num=inputs[0].value;
   }
   var url="/buy.aspx?action=searchadd&buynum="+num+"&key="+encodeURIComponent(xinghao)+"&id="+id; 
   window.location.href=url;
   
}


function initLoginUserInfo()
{
   var ishtml= checkishtml();
   if(!ishtml)
   {
     return ;
   }
   try{
        var loginname= $$.Cookies.get("loginusername");     
        if(loginname!=null && loginname!="")
        {
            var boxobj = $$("#body_a .loginbox");
            if(boxobj!=null && boxobj.length>0)
            {
               boxobj[0].innerHTML="<span>Hi,<B>"+loginname+"</B>!</span>&nbsp;(<a href=\"/SignOut.aspx\">Sign out</a>)&nbsp;&nbsp; ";
            }
        }
    }
    catch(e)
    {
    
    }
}
 

function deleteselectcheckboxpdf(obj)
{
    var inputs=$$("#ShopCart input");
    var ids=[];
    for(i=1;i<inputs.length;i++)
    {
       if(inputs[i].checked==true)
       {
          ids.push(inputs[i].value);
       }
    }
    
   if(ids.length==0)
   {
     $$("btactiontxt").innerHTML="Please select one product to remove at least";     
     return ;
   }
   else
   {
     $$("btactiontxt").innerHTML="";
   }
   param="action=deletepdfproducts&ids="+ids.join(",");
    
   $$.Ajax.post("CreateQuotitionAddProduct.aspx",param,function(x)
   {
       for(i=1;i<inputs.length;i++)
       {
           if(inputs[i].checked==true)
           {
               inputs[i].parentNode.parentNode.parentNode.removeChild(inputs[i].parentNode.parentNode);
           }
       }
      
   },function(x)
   {
   
   })
}

function addLoadEvent(fn) 
{
        if (typeof window.addEventListener != 'undefined') 
        {  
         window.addEventListener('load',fn,false);  
        } 
         else if (typeof document.addEventListener != 'undefined') 
        {
         document.addEventListener('load',fn,false); 
        }
        else if (typeof window.attachEvent != 'undefined') 
        {  
         window.attachEvent('onload',fn);
        } 
         else
        { 
             var oldfn = window.onload; 
             if (typeof window.onload != 'function') 
             { 
                  window.onload = fn;  
             }  
             else
             { 
                  window.onload = function() {
                  lodfn(); 
                   fn(); 
                   }; 
             }  
        }

}


function SaveOrderAddress(obj)
{
   var numchk=$$(".chkred");
   var error="";
   for(i=0;i<numchk.length;i++)
   {
      if(numchk[i].previousSibling.value=="")
      {
         numchk[i].style.color="red";
         error=error+i;
      }
      else
      {
         numchk[i].style.color="#000";
      }
   }
  
   if (error == "") {
       obj.style.filter = "alphaopacity=80 gray";
      $$("MyUsbSeaForm").submit();
   }
   
}

function GotoSaveOrderAddress()
{
   var flag=$$.Cookies.get("ratetypesflag");
    $$.Cookies.set("ordertotalmoney",$$("totalmoneyfont").innerHTML);
    $$.Cookies.set("bankfeemoney",$$("bankfee").innerHTML.replace("$","").replace(flag,""));
   var inputs=$$("#ShopCart input");
   if(inputs.length<2)
   {
     return false;
   }
   window.location.href="/OrderAddress.aspx?PaymentMethod="+$$("PaymentMethod").options[$$("PaymentMethod").selectedIndex].value+"&ShippingMethod="+$$("ShippingMethod").options[$$("ShippingMethod").selectedIndex].value+"&Remark="+$$("Remark").value;
}



function CheckQuotition(obj)
{
   var numchk=$$(".chkred");
   var error="";
   for(i=0;i<numchk.length;i++)
   {
      if(numchk[i].previousSibling.value=="")
      {
         numchk[i].style.color="red";
         error=error+i;
      }
      else
      {
         numchk[i].style.color="#000";
      }
   }
   
   if($$("xinghao").length>3 || error!="")
   {
     return false;
   }
   
   return true;
}


function Usbsea_Search_Products(obj,defaulttxt)
{
    if(defaulttxt=='Only item number')
    {
       var param="action=addproducttopdf&keyword="+encodeURIComponent($$("usbseakeyword").value);
        $$.Ajax.post("CreateQuotitionAddProduct.aspx",param,function(x)
        {
           
           if(x.responseText=="1")
           {
             
              window.location.href="/CreateQuotitionAddProduct.aspx";
              
           }
           else
           {              
              $$("usbseakeyword").value="Only item number";
              $$("usbseakeyword").style.color="red"; 
           }
        },
        function(x)
        {
        
        });
    
    }
    else
    {
       
        $$("searchbox").submit();
    }
    
}


function CheckPrecent(obj)
{
   
   
   if(obj.indexOf("%")==-1)
   {
      obj.value=obj.value+"%";
   }
   else
   {
      if(!isNaN(parseFloat(obj.value)))
      {
         obj.value=obj.value+"%";
      }
      else
      {
         obj.value="100%";
      }
   }
   
}


function CheckProductsCat(obj)
{
   if($$("#ShopCart")!=null)
   {   
       if($$("#ShopCart tr").length<2)
       {
          return false;
       }
       else
       {
          return true;
       }
   }
   
   return false;
   
}


function SearchAddFromFav(obj)
{

   var inputs=$$("#ShopCart td .chkbox");
   var ids=[];
   var xinghao=[];
   for(i=0;i<inputs.length;i++)
   {
      if(inputs[i].checked==true)
      {
         ids.push(1);
         xinghao.push(inputs[i].name);
      }
   }
   
   if(xinghao.length<1)
   {
       $$("btactiontxt").innerHTML="Please select one product to order at least!";     
       return ;
   }
   
   var param="action=searchaddfromfav&qty="+ids.join(",")+"&xinghao="+encodeURIComponent(xinghao.join("|"));
   $$.Ajax.post("/ajax.aspx",param,function(x)
   {
      
        if(x.responseText=="1")
        {
            window.location.href="/MakeOrderOnline.aspx";
        }
   
   },
   function(x)
   {
      
   })

}