﻿function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function filter_setvalue(obj, objvalue) {

    MM_findObj(obj).value = objvalue;

    if ($("#static_isenable").val() == 1) {
        /*配置提交URL*/
        var cate = $("#lcate").val();
        var brand_id = $("#brand_id").val();
        var isgallerylist = $("#isgallerylist").val();
        var orderby = $("#orderby").val();
        var page = $("#page").val();
        var actURL = "/product/" + cate + "-" + brand_id + "-" + isgallerylist + "-" + orderby + "-" + page + ".htm";
        $("#form_filter").attr("action", actURL)
        /*配置提交URL*/
    }
    
    setTimeout(filter_setvalue_do, 0);
}
function filter_setvalue_do(){
	MM_findObj("form_filter").submit();
}
function AutosizeImage(ImgD,maxwidth,maxheight){  
	 var image=new Image();
	 image.src=ImgD.src;
     if(image.width>0  &&  image.height>0){  
       flag=true;  
       if(image.width/image.height >= maxwidth/maxheight){  
         if(image.width > maxwidth){      
         ImgD.width=maxwidth;  
         ImgD.height=(image.height*maxwidth)/image.width;  
         }else{  
         ImgD.width=image.width;      
         ImgD.height=image.height;  
         }
         }  
       else{  
         if(image.height>maxheight){      
         ImgD.height=maxheight;  
         ImgD.width=(image.width*maxheight)/image.height;            
         }else{  
         ImgD.width=image.width;      
         ImgD.height=image.height;  
         }  
         }  
       }  
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];AutosizeImage(x,300,300);x.src=a[i+2];AutosizeImage(x,300,300);MM_findObj("demo1").href=a[i+2];}
}

function switchimgborder(objid){

  if (MM_findObj("product_img_s_1")!=null){MM_findObj("product_img_s_1").className="img_border_off";}
  if (MM_findObj("product_img_s_2")!=null){MM_findObj("product_img_s_2").className="img_border_off";}
  if (MM_findObj("product_img_s_3")!=null){MM_findObj("product_img_s_3").className="img_border_off";}
  if (MM_findObj("product_img_s_4")!=null){MM_findObj("product_img_s_4").className="img_border_off";}
  if (MM_findObj("product_img_s_5")!=null){MM_findObj("product_img_s_5").className="img_border_off";}
  if (MM_findObj(objid)!=null){MM_findObj(objid).className="img_border_on";}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function detail_option(cur_option) {
    for (var i = 1; i < 6; i++) {
        try {
            if (i == cur_option) {
                MM_findObj("but_detail" + i).className = "select_selected";
                MM_findObj("detail" + i).style.display = "";
            }
            else {
                MM_findObj("but_detail" + i).className = "select_uselected";
                MM_findObj("detail" + i).style.display = "none";
            }
        }
        catch (err) { }
    }
}

function setUseful(review_id,status)
{
    
    if(status)
    {
        $("#span_userful_" + review_id).load("/product/reviews_do.aspx?action=use&review_id="+review_id+"&fresh=" + Math.random()+"");
    }
    else
    {
        $("#span_userful_" + review_id).load("/product/reviews_do.aspx?action=useless&review_id="+review_id+"&fresh=" + Math.random()+"");
    }
}

//CharMode函数
//测试某个字符是属于哪一类.
function CharMode(iN){
if(iN>=48&&iN<=57)//数字
return 1;
if(iN>=65&&iN<=90)//大写字母
return 2;
if(iN>=97&&iN<=122)//小写
return 4;
else
return 8;//特殊字符
}

//bitTotal函数
//计算出当前密码当中一共有多少种模式
function bitTotal(num){
modes=0;
for(i=0;i<4;i++){
if(num&1) modes++;
num>>>=1;
}
return modes;
}

//checkStrong函数
//返回密码的强度级别

function checkStrong(sPW){
if(sPW.length<=4)
return 0;//密码太短
Modes=0;
for(i=0;i<sPW.length;i++){
//测试每一个字符的类别并统计一共有多少种模式.
Modes|=CharMode(sPW.charCodeAt(i));
}

return bitTotal(Modes);

}

//pwStrength函数
//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色

function pwStrength(pwd){
O_color="#eeeeee";
L_color="#FF0000";
M_color="#FF9900";
H_color="#33CC00";
if(pwd==null||pwd==""){
Lcolor=Mcolor=Hcolor=O_color;
}
else{
S_level=checkStrong(pwd);
switch(S_level){
case 0:
Lcolor=Mcolor=Hcolor=O_color;
case 1:
Lcolor=L_color;
Mcolor=Hcolor=O_color;
break;
case 2:
Lcolor=Mcolor=M_color;
Hcolor=O_color;
break;
default:
Lcolor=Mcolor=Hcolor=H_color;
}
}

document.getElementById("strength_L").style.background=Lcolor;
document.getElementById("strength_M").style.background=Mcolor;
document.getElementById("strength_H").style.background=Hcolor;
return;
}

function RefillAddress(targetdiv, statename, cityname, countyname, statecode, citycode, countycode) 
{
	$.ajax({
		type: "get", 
		global: false, 
		async: false,
		dataType: "html",
		url: encodeURI("/public/ajax_address.aspx?action=fill&targetdiv="+ targetdiv +"&statename="+ statename +"&cityname="+ cityname +"&countyname="+ countyname +"&statecode="+ statecode +"&citycode="+ citycode +"&countycode="+ countycode +"&timer="+Math.random()),
		
		success:function(data){
			$("#"+ targetdiv).html(data);
		    $("#"+ statename).val(statecode);
            $("#"+ cityname).val(citycode);
            $("#"+ countyname).val(countycode);
		},
		error: function (){
			alert("Error Script");
		}
    });
}

function AddCartExt(obj)
{
    var ext_c = $("#ext_c").val();
    var ext_m = $("#ext_m").val();

    if (ext_c != null && ext_m != null) {
        if (ext_c.length == 0 || ext_m.length == 0) {
            alert("请选择商品颜色尺码");
            return false;
        }
    }
    else {
        ext_c = "";
        ext_m = "";
    }
    
    obj.href = obj.href + "&buy_amount=" + $("#buy_amount").val() + "&ext_c=" + encodeURI(ext_c) + "&ext_m=" + encodeURI(ext_m);
    
    ext_c = null;
    ext_m = null;
}
function updatetime(settime,divname)
{   
    var i;
    var showthis;
    //alert(settime);
    for(i=1;i<=200;i++)
    { setTimeout("update("+i+","+settime+",'"+divname+"')",i*1000); }
    
}
function update(num,settime,divname) 
    { //alert(showthis);
    if(num>settime) 
    { ; }
    else
    { showthis=settime-num;
     MM_findObj(divname).innerHTML="距离结束时间还有： <font class='t12_red'><b>"+Math.floor(showthis/(3600*24))+"</b></font> 天 <font class='t12_red'><b>"+Math.floor((showthis%(3600*24))/3600)+"</b></font> 小时 <font class='t12_red'><b>"+Math.floor((showthis%3600)/60)+"</b></font> 分钟 <font class='t12_red'><b>"+(showthis%3600)%60+"</b></font> 秒"; }
 }
 
 function updatetime_list(settime,divname)
{   
    var i;
    var showthis;
    for(i=1;i<=150;i++)
    { setTimeout("update_list("+i+","+settime+",'"+divname+"')",i*1000); }
    
}
function update_list(num,settime,divname) 
    { //alert(divname);
    if(num>settime) 
    { ; }
    else
    { showthis=settime-num;
     MM_findObj(divname).innerHTML="<font class='t12_red'><b>"+Math.floor(showthis/(3600*24))+"</b></font>天<font class='t12_red'><b>"+Math.floor((showthis%(3600*24))/3600)+"</b></font>小时<font class='t12_red'><b>"+Math.floor((showthis%3600)/60)+"</b></font>分<font class='t12_red'><b>"+(showthis%3600)%60+"</b></font>秒"; }
 }
 
 
 function homecountdown(settime, divname) {
     var i;
     var showthis;
     //for (i = 1; i <= 500; i++)
     //{ setTimeout("homecountdown_2(" + i + "," + settime + ",'" + divname + "')", i * 1000); }

     setTimeout("homecountdown_2(1," + settime + ",'" + divname + "')", i * 1000);

 }
 function homecountdown_2(num, settime, divname) {
     if (num > settime)
     { ; }
     else {
         showthis = settime - num;

         try {

             var hour = Math.floor((showthis % (3600 * 24)) / 3600);
             var minute = Math.floor((showthis % 3600) / 60);
             var second = (showthis % 3600) % 60;
             
             if (hour < 10) { hour = "0" + hour; }
             if (minute < 10) { minute = "0" + minute; }
             if (second < 10) { second = "0" + second; }

             $("#" + divname + "hour").html(hour);
             $("#" + divname + "minute").html(minute);
             $("#" + divname + "second").html(second);
         }
         catch (err) { }

         setTimeout("homecountdown_2(" + (num + 1) + "," + settime + ",'" + divname + "')", 1000);
     }
 }

 function ListCountdown(num, settime, divname) {
     if (num > settime)
     { ; }
     else {
         showthis = settime - num;

         try {
         
             var hour = Math.floor((showthis % (3600 * 24)) / 3600);
             var minute = Math.floor((showthis % 3600) / 60);
             var second = (showthis % 3600) % 60;

             if (hour.length < 2) {
                 $("#" + divname + "_h_1").html("0");
                 $("#" + divname + "_h_2").html(hour);
             }
             else {
                 $("#" + divname + "_h_1").html(parseInt(hour / 10));
                 $("#" + divname + "_h_2").html(parseInt(hour) - (parseInt(hour / 10) * 10));
             }
             
             if (minute.length < 2) {
                 $("#" + divname + "_m_1").html("0");
                 $("#" + divname + "_m_2").html(minute);
             }
             else {
                 $("#" + divname + "_m_1").html(parseInt(minute / 10));
                 $("#" + divname + "_m_2").html(parseInt(minute) - (parseInt(minute / 10) * 10));
             }

             if (second.length < 2) {
                 $("#" + divname + "_s_1").html("0");
                 $("#" + divname + "_s_2").html(second);
             }
             else {
                 $("#" + divname + "_s_1").html(parseInt(second / 10));
                 $("#" + divname + "_s_2").html(parseInt(second) - (parseInt(second / 10) * 10));
             }
         }
         catch (err) { }

         setTimeout("ListCountdown(" + (num + 1) + "," + settime + ",'" + divname + "')", 1000);
     }
 }
 
