$(document).ready(function(){
          $("#kleft>li").hover(function(){
              $(this).children(".sortsub").show();
              },function(){
              $(this).children(".sortsub").hide();
          });
          $("#nav>li").hover(function(){
              $(this).children(".navsub").show();
              },function(){
              $(this).children(".navsub").hide();
          });
	      $(".proimg img,.fml img,.fmm img,.hot img,.xg img,.listBox img,.newsshow img").lazyload({
            placeholder : "images/grey.gif",
            effect:"fadeIn",
			failurelimit : 30
           });

});
$.fn.extend({     
   AdAdvance:function(){
	var listobj=this;
    var objs =$('dd',this);
	var view =0;//parseInt( Math.random()*objs.length);
	objs.each(function(i){			   			
	$(this).mouseover( function(){$('dt',listobj).hide();$(this).next().show();})
	});
    }	
}); 
function AddFavorite(sURL, sTitle) 
{ 
    try 
    { 
        window.external.addFavorite(sURL, sTitle); 
    } 
    catch (e) 
    { 
        try 
        { 
            window.sidebar.addPanel(sTitle, sURL, ""); 
        } 
        catch (e) 
        { 
            alert("加入收藏失败，请使用Ctrl+D进行添加"); 
        } 
    } 
} 


function checkcart()
{ 
  flag3=0	
  a=document.getElementsByName("addressid");
  if(a.length>0)
  {
  for(i=0;i<a.length;i++)
  {	
	   if(a[i].checked) {
			if(a[i].value=="newadd"){
			if(document.getElementById("sheng").options[document.getElementById("sheng").selectedIndex].text=="请选择省份"||document.getElementById("shi").options[document.getElementById("shi").selectedIndex].text=="请选择城市"||document.getElementById("qu").options[document.getElementById("qu").selectedIndex].text=="请选择区县"){alert('请选择省市区！');return false;} 
			if(document.getElementById("shname").value==""){alert('请填写收货人！');return false;} 
			if(document.getElementById("shemail").value==""){alert('请填写收货人邮箱！');return false;}
			if(document.getElementById("shaddress").value==""){alert('请填写收货人地址！');return false;}
			if(document.getElementById("shtel").value==""){alert('请填写收货人电话！');return false;}
	   }
	 flag3=1;
	 break;	
	} 
  }
  }else{
	     if(document.getElementById("sheng").options[document.getElementById("sheng").selectedIndex].text=="请选择省份"||document.getElementById("shi").options[document.getElementById("shi").selectedIndex].text=="请选择城市"||document.getElementById("qu").options[document.getElementById("qu").selectedIndex].text=="请选择区县"){alert('请选择省市区！');return false;} 
	    if(document.getElementById("shname").value==""){alert('请填写收货人！');return false;} 
		if(document.getElementById("shemail").value==""){alert('请填写收货人邮箱！');return false;}
		if(document.getElementById("shaddress").value==""){alert('请填写收货人地址！');return false;}
		if(document.getElementById("shtel").value==""){alert('请填写收货人电话！');return false;}
		flag3=1;
		
	  
  }
  if(flag3==0){alert('您必须选择一个收货地址或添加一个收货地址！');return false;}
  flag=0	
  s=document.getElementsByName("deliveryid");
  for(i=0;i<s.length;i++)
  {
	if(s[i].checked) {
	 flag=1;
	 break;	
	} 
  }
  if(flag==0){alert('您必须选择一个快递方式！');return false;}
  flag1=0	
  s1=document.getElementsByName("paymentid");
  for(i=0;i<s1.length;i++)
  {
	if(s1[i].checked) {
	 flag1=1;
	 break;	
	} 
  }
  if(flag1==0){alert('您必须选择一个支付方式！');return false;}
  
}

function Adddelivery(price)
{
	document.getElementById("pay2").innerHTML= price;
	t=parseFloat(document.getElementById("pay1").innerHTML)+parseFloat(price)+parseFloat(document.getElementById("pay3").innerHTML);
	document.getElementById("pay4").innerHTML=t;
}

function Addpayment(price)
{
	document.getElementById("pay3").innerHTML= price;
	t=parseFloat(document.getElementById("pay1").innerHTML)+parseFloat(price)+parseFloat(document.getElementById("pay2").innerHTML);
	document.getElementById("pay4").innerHTML=t;
}
function getCookie(objName){//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for(var i = 0;i < arrStr.length;i ++){
     var temp = arrStr[i].split("=");
     if(temp[0] == objName) return unescape(temp[1]);
    }
   }

function Addbuy(proid,kc,qdl){
  kk=getCookie("username");
  if(typeof(kk) == "undefined"){alert("请登录后再使用购物车！");throw new Error("stoprun");}
  flag=0;
  id=proid.split("_")[1];
  num=document.getElementById(proid).value;
  if(num>kc){alert("现货不够！请重填！");flag=1;}
  if(num<qdl){alert("订购数量小于最小起订量！");flag=1;}
  if(flag==0){
  $.ajax({
		type:'GET',
		url: 'Common/AjaxAddCart.php',
		data:{id:id,num:num},
		cache: false, 
		success:function(msg){
		 addbumsg(id);
		}
        })
  }
}
function addbumsg(id){
	    html="<font color=''>成功加入购物车！</font><p><a href='Cart.php?setup=cart' style='float:left'>查看购物车</a><a href='javascript:closemsg("+id+");' style='float:right;'>继续购物</a></p>"
        document.getElementById("msg_"+id).className="addbuymsg";
		document.getElementById("msg_"+id).style.display="";
		document.getElementById("msg_"+id).innerHTML=html;
		setTimeout("closemsg(id)",1800);
	
}
function closemsg(id){
	document.getElementById("msg_"+id).style.display="none";
}
function AddCartbuy(proid,kc,qdl,price,num1){
  kk=getCookie("username");
  if(typeof(kk) == "undefined"){alert("请登录后再使用购物车！");throw new Error("stoprun");}
  flag=0;
  id=proid.split("_")[1];
  num=document.getElementById(proid).value;
  if(num>kc){alert("现货不够！请重填！");document.getElementById(proid).value=num1; flag=1;}
  if(num<qdl){alert("订购数量小于最小起订量！");document.getElementById(proid).value=num1;flag=1;}
  if(flag==0){
  $.ajax({
		type:'GET',
		url: 'Common/AjaxAddCart.php',
		data:{id:id,num:num},
		cache: false, 
		success:function(msg){
		   document.getElementById("prototal_"+id).value=formatFloat((price*num),2);
		   var s = document.getElementsByName("total");  
		   tot=0;
		   for( var i = 0; i < s.length; i++ )  
			  {  
					tot+=parseFloat(s[i].value);  
		   }
		   tot=formatFloat(tot,2);   
		   document.getElementById("totalprice").innerHTML=tot;
		}
        })
  }
}
function formatFloat(f, dec)

{

   if(dec<0)    return    "Error:dec<0!";     
   result=parseInt(f)+(dec==0?"":".");     
   f-=parseInt(f);     
   if(f==0)     
   for(i=0;i<dec;i++)    result+='0';     
   else    {     
   for(i=0;i<dec;i++)    f*=10;     
   result+=parseInt(Math.round(f));     
   }     
   return    result;     

}
function Adaddress(){
	if(document.getElementById("newaddress").style.display=="none")
	{
    
	  document.getElementById("newaddress").style.display="";
	 
	}else{
		
	  document.getElementById("newaddress").style.display="none";	
	 
	}
}

function AutoResizeImage(maxWidth,maxHeight,objImg){
	var img = new Image();
	img.src = objImg.src;
	var hRatio;
	var wRatio;
	var Ratio = 1;
	var w = img.width;
	var h = img.height;
	wRatio = maxWidth / w;
	hRatio = maxHeight / h;
	if (maxWidth ==0 && maxHeight==0){
	Ratio = 1;
	}else if (maxWidth==0){//
	if (hRatio<1) Ratio = hRatio;
	}else if (maxHeight==0){
	if (wRatio<1) Ratio = wRatio;
	}else if (wRatio<1 || hRatio<1){
	Ratio = (wRatio<=hRatio?wRatio:hRatio);
	}
	if (Ratio<1){
	w = w * Ratio;
	h = h * Ratio;
	}
	objImg.height = h;
	objImg.width = w;
}
function change(value){
	$("#smalld").attr("src",value);
	$("#smalld").attr("jqimg", value);
}
function searchd(){
	v=document.getElementById("searchkeyd").value;
	v=ReplaceAll(v,"/","~");
	location.href="s-"+v+"-0-0-0-0-0-1.html";
}
function ReplaceAll(str, sptr, sptr1)
{
while (str.indexOf(sptr) >= 0)
{
   str = str.replace(sptr, sptr1);
}
return str;
}

function jskc(str){
$("#jskc").html("<img src='/images/2012/loading.gif' />");
$.ajax({
		type:'GET',
		url: 'Caiji/Ajaxkc.php',
		data:{bh:str},
		cache: false, 
		success:function(msg){
		$("#jskc").html(msg);
		}
        });
}
function jskcl(xx,str){
$("#"+xx).html("<img src='/images/2012/loading.gif' />");
$.ajax({
		type:'GET',
		url: 'Caiji/Ajaxkc.php',
		data:{bh:str},
		cache: false, 
		success:function(msg){
		$("#"+xx).html(msg);
		}
        });
}
