﻿//加入收藏
function AddFavorite(sURL, sTitle) 
{ 
 try 
    { 
     window.external.addFavorite(sURL, sTitle); 
 } 
 catch (e) 
    { 
     try 
        { 
         window.sidebar.addPanel(sTitle, sURL, ''); 
        } 
        catch (e) 
        { 
         alert('加入收藏失败，请使用Ctrl+D进行添加'); 
     } 
 } 
} 
// 设置首页 
function setHomepage(url){  
    if (document.all){   
        document.body.style.behavior = 'url(#default#homepage)';   
        document.body.setHomePage(url);   
    }else if (window.sidebar){   
        if (window.netscape){   
            try {   
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
            }catch (e) {   
                alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");   
            }   
        }   
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);   
        prefs.setCharPref('browser.startup.homepage', url);   
    }   
} 

//图片缩放
function DrawImage(ImgD,FitWidth,FitHeight){
     var image=new Image();
     image.src=ImgD.src;
     if(image.width>0 && image.height>0){
         if(image.width/image.height>= FitWidth/FitHeight){
             if(image.width>FitWidth){
                 ImgD.width=FitWidth;
                 ImgD.height=(image.height*FitWidth)/image.width;
             }else{
                 ImgD.width=image.width; 
                ImgD.height=image.height;
             }
         } else{
             if(image.height>FitHeight){
                 ImgD.height=FitHeight;
                 ImgD.width=(image.width*FitHeight)/image.height;
             }else{
                 ImgD.width=image.width; 
                ImgD.height=image.height;
             } 
        }
     }
 }
 
//单选框切换  
  function show_1(){ 
    var tbobj=document.getElementById("tb1"); 
        tbobj.style.display=""; 
  } 
  function hid_1(){ 
    var tbobj=document.getElementById("tb1"); 
        tbobj.style.display="none"; 
  }
  function show_2(){ 
    var tbobj=document.getElementById("tb2"); 
        tbobj.style.display=""; 
  } 
  function hid_2(){ 
    var tbobj=document.getElementById("tb2"); 
        tbobj.style.display="none"; 
  } 
  function show_3(){ 
    var tbobj=document.getElementById("tb3"); 
        tbobj.style.display=""; 
  } 
  function hid_3(){ 
    var tbobj=document.getElementById("tb3"); 
        tbobj.style.display="none"; 
  } 
  
//下拉菜单显示隐藏
function hide(tb,sl)
{
  if(document.getElementById(sl).value == "0")
     document.getElementById(tb).style.display = "none";
  else
     document.getElementById(tb).style.display = "block";
}

  

//模块切换代码
function cc(num){
    for(var id = 1;id<=2;id++)
    {
    var mainlay="lay"+id;
	var maintt="tt"+id;
    if(id==num){
    document.getElementById(mainlay).style.display="block";
	document.getElementById(maintt).className="bg2";
	}
    else{
	document.getElementById(maintt).className="bg1";
	document.getElementById(mainlay).style.display="none";
	}
  }
}

//选项卡
function selectTag(showContent,selfObj){
	// 操作标签
	var tag = document.getElementById("tags").getElementsByTagName("li");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "";
	}
	selfObj.parentNode.className = "selectTag";
	// 操作内容
	for(i=0; j=document.getElementById("tagContent"+i); i++){
		j.style.display = "none";
	}
	document.getElementById(showContent).style.display = "block";
} 

//折叠菜单
function showdiv(divnum,divbefor){
        for(i=1;i<=divnum;i++){
    if(i==divbefor){
      document.getElementById("Nav_"+i).className = "te33"
      document.getElementById("Content_"+i).className ="block";
    }else{
      document.getElementById("Nav_"+i).className = "te3"
      document.getElementById("Content_"+i).className ="none";
    }
        }
}


//用户注册验证
function rUserName(str){
  if(str =="" || str.length<3 || str.length>20) {
    document.getElementById("UserName1").innerHTML = "<font color=red><strong>登录用户名长度必须为 3-20 字符。</strong></font>";
    document.addform.UserName.focus();
    document.addform.UserName.select();
	return false;
  }
  document.getElementById("UserName1").innerHTML = "用户名符合！";
}
function rEmail(str){
  var filter=/^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/;
  if (str =="" || !filter.test(str)) {
     document.getElementById("Email1").innerHTML = "<font color=red><strong>请输入正确的邮箱地址。</strong></font>";
     document.addform.Email.focus();
     document.addform.Email.select();
     return false;
  }
  document.getElementById("Email1").innerHTML = "邮箱符合！";
}
function replaceInput(obj,event){
	if(event.keyCode!=37 && event.keyCode!=39){
      var IsTitle=/[^\u4E00-\u9FA50-9a-zA-Z_\.]/g;
	  if(IsTitle.test(obj.value)){
	    obj.value=obj.value.replace(IsTitle,'');
	  }
	}
}
function rPassWord(str){
  if( str =="" || str.length<3 || str.length>20) {
    document.getElementById("PassWord1").innerHTML = "<font color=red><strong>密码长度必须为 3-20 字符。</strong></font>";
    document.addform.PassWord.focus();
    document.addform.PassWord.select();
    return false;
  }
  if( str == addform.UserName.value) {
    document.getElementById("PassWord1").innerHTML = "<font color=red><strong>密码不能与登录用户名相同。</strong></font>";
    document.addform.PassWord.focus();
    document.addform.PassWord.select();
    return false;
  }
  document.getElementById("PassWord1").innerHTML = "密码可以使用";
}
function rPass(str){
  if(str =="") {
    document.getElementById("Pass1").innerHTML = "<font color=red><strong>请重复输入密码。</strong></font>";
    document.addform.Pass.focus();
    document.addform.Pass.select();
    return false;
  }
  if(addform.PassWord.value != str) {
    document.getElementById("Pass1").innerHTML = "<font color=red><strong>两次输入的密码不一致。</strong></font>";
    document.addform.Pass.focus();
    document.addform.Pass.select();
    return false;
  }
  document.getElementById("Pass1").innerHTML = "确认密码正确";
}

function rRealName(str){
  if(str =="") {
    document.getElementById("RealName1").innerHTML = "<font color=red><strong>请输入真实姓名。</strong></font>";
    document.addform.RealName.focus();
    document.addform.RealName.select();
    return false;
  }
  document.getElementById("RealName1").innerHTML = "真实姓名正确";
}

function rUserTel(str){
  if(str =="") {
    document.getElementById("UserTel1").innerHTML = "<font color=red><strong>请输入联系电话。</strong></font>";
    document.addform.UserTel.focus();
    document.addform.UserTel.select();
    return false;
  }
  document.getElementById("UserTel1").innerHTML = "联系电话正确";
}

function rUserPhoto(str){
  if(str =="") {
    document.getElementById("UserPhoto1").innerHTML = "<font color=red><strong>请输入手机号码。</strong></font>";
    document.addform.UserPhoto.focus();
    document.addform.UserPhoto.select();
    return false;
  }
  document.getElementById("UserPhoto1").innerHTML = "手机号码正确";
}

function rUserShop(str){
  if(str =="") {
    document.getElementById("UserShop1").innerHTML = "<font color=red><strong>请输入店名。</strong></font>";
    document.addform.UserShop.focus();
    document.addform.UserShop.select();
    return false;
  }
  document.getElementById("UserShop1").innerHTML = "店名正确";
}

function rAddress(str){
  if(str =="") {
    document.getElementById("Address1").innerHTML = "<font color=red><strong>请输入联系地址。</strong></font>";
    document.addform.Address.focus();
    document.addform.Address.select();
    return false;
  }
  document.getElementById("Address1").innerHTML = "联系地址正确";
}

function rCode(str){
  if("True" == "True" && str == "") {
    document.getElementById("Code1").innerHTML = "<font color=red><strong>请输入验证码。</strong></font>";
    document.addform.Code.focus();
    document.addform.Code.select();
    return false;
  }
  document.getElementById("Code1").innerHTML = "";
}

function ClickSubmit(){
  var Msg = "";
  if (document.addform.UserName.value =="" || document.addform.UserName.value.length<3 || document.addform.UserName.value.length>20){
    document.getElementById("UserName1").innerHTML = "<font color=red><strong>登录用户名长度必须为 3-20 字符。</strong></font>";
    Msg = "Err";
  }
  var filter=/^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/;
  if (document.addform.Email.value =="" || !filter.test(document.addform.Email.value)){
    document.getElementById("Email1").innerHTML = "<font color=red><strong>请输入正确的邮箱地址。</strong></font>";
    Msg = "Err";
  }
  if (document.addform.PassWord.value =="" || document.addform.PassWord.value.length<3 || document.addform.PassWord.value.length>20 || document.addform.PassWord.value==document.addform.UserName.value){
    document.getElementById("PassWord1").innerHTML = "<font color=red><strong>密码长度必须为 3-20 字符且不能和用户名相同。</strong></font>";
    Msg = "Err";
  }
  if (document.addform.Pass.value == "" || document.addform.PassWord.value != document.addform.Pass.value){
    document.getElementById("Pass1").innerHTML = "<font color=red><strong>请重复输入密码且和登录密码一至。</strong></font>";
    Msg = "Err";
  }
  if (document.addform.RealName.value == ""){
    document.getElementById("RealName1").innerHTML = "<font color=red><strong>请输入真实姓名。</strong></font>";
    Msg = "Err";
  }
  if (document.addform.UserTel.value == ""){
    document.getElementById("UserTel1").innerHTML = "<font color=red><strong>请输入联系电话。</strong></font>";
    Msg = "Err";
  }
  if (document.addform.UserPhoto.value == ""){
    document.getElementById("UserPhoto1").innerHTML = "<font color=red><strong>请输入手机号码。</strong></font>";
    Msg = "Err";
  }
  if (document.addform.UserShop.value == ""){
    document.getElementById("UserShop1").innerHTML = "<font color=red><strong>请输入店名。</strong></font>";
    Msg = "Err";
  }
  if (document.addform.Address.value == ""){
    document.getElementById("Address1").innerHTML = "<font color=red><strong>请输入联系地址。</strong></font>";
    Msg = "Err";
  }  
  if ("True" == "True" && document.addform.Code.value == ""){
    document.getElementById("Code1").innerHTML = "<font color=red><strong>请输入验证码。</strong></font>";
    Msg = "Err";
  }
  if ( Msg != ""){
	return false;
  }else{
    document.addform.submit();
  }
}

//验证码
function get_Code(){
  document.getElementById("imgurl").src='/inc/CodeNum.asp?'+Math.random()
}

//密码强度检测 Begin =======================
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; //特殊字符
}

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);
}

function bitTotal(num){
	modes=0;
	for (i=0;i<4;i++){
		if (num & 1) modes++;
		num>>>=1;
	}
	return modes;
}

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:
			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;
}
//密码强度检测 End =======================


function show(){
    if (document.getElementById("vip").style.display=="none"){
    document.getElementById("vipTit").style.display = "";
    document.getElementById("vip").style.display = "";
    }else{
    document.getElementById("vipTit").style.display = "none";
    document.getElementById("vip").style.display = "none";
    }
    }

//实现反向选择
  function SelectAll() {
	for (var j=0;j<document.selform.ID.length;j++) {
		var e=document.selform.ID[j];
		e.checked=!e.checked;
	}
    }
	
function Open_w(t0,t1,t2,t3,t4)
{
	var t5=showModalDialog(t0,t3,'dialogWidth:'+t1+'pt;dialogHeight:'+t2+'pt;status:no;help:no;;');
	if (t5!=null) t4.value=t5;
}
