$().ready(function(){
	initMenu();
	initProductCate();
});
var zdCache={};

//初始化导航栏事件
function initMenu(){
	var len = $(".menuList").find("li").length;
	for (var i=0;i<len;i++){
		$(".menuList").find("li").eq(i).attr("no",i);
	}
	$(".menuList>li").mouseover(function(){
		$(this).siblings("li").removeClass("hover");
		var id = $(this).attr("no") || 0;
		$(this).addClass("hover");
		$(".menuContList").css("display","none");
		if (id>0){
			$(".m"+id).css("display","block");
		}
	})
}

//获取子分类
function getChildClass(){
	var val = $("#productName").val();
	if (val==0){
		$("#productCate").html("<option value=\"0\">所有小类</option>");
	}else{
		$("#productCate").html("<option value=\"0\">正在加载分类...</option>");
		$.get("/product/proc.asp?typeid="+val,
			function(s){
				if (s=="" || s=="0"){
					$("#productCate").html("<option value=\"0\">所有小类</option>");
				}else{
					$("#productCate").html("<option value=\"0\">所有小类</option>"+s);
				}
			}
		);
	}
}

//产品
function initProductCate(){
	$(".cateListTitle").mouseover(function(){
		$(".cateListTitle").removeClass("open");
		$(".cateListCont").css("display","none");
		$(this).addClass("open");
		$(this).parent().find(".cateListCont").css("display","block");
	})
	$(".cateListCont").eq(0).css("display","block");
}

//sous
function searchProduct(){
	var v1 = $("#productName").val();
	var v2 =$("#productCate").val();
	var key = $("#key").val();
	var type = 0;
	var str = "";
	key = key.replace(/^\s+/ig,"");
	if (key=="关键字" || key=="")
	{
		alert("请输入查询关键字！");
	}else{
		type = (v2==0)? v1 : v2 ;
		str = "/search?type="+type+"&key="+ encodeURI(key);
		window.location.href=str;
	}
}

function getbyid(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	}else if (document.all) {
		return document.all[id];
	}else if (document.layers) {
		return document.layers[id];
	}else {
		return null;
	}
}
function checkForms(){
	var temp,state
	state=true;
	if (getbyid("txtUserNa").value==""){
		getbyid("txtUserNa").className="online_input_err";
		getbyid("check_name").style.display="block";
		state=false;
		}else{
			getbyid("txtUserNa").className="online_input";
			getbyid("check_name").style.display="none";
			}
	if (getbyid("txtTel").value==""){
		getbyid("txtTel").className="online_input_err";
		getbyid("check_tel").style.color="red";
		state=false;
		}else{
			if (isphone(getbyid("txtTel").value)){
				getbyid("txtTel").className="online_input";
				getbyid("check_tel").innerHTML='';
			}else{
				getbyid("txtTel").className="online_input_err";
				getbyid("check_tel").innerHTML="您输入的电话号码不符合规范！示例:021-12345678"
				getbyid("check_tel").style.color="red";
				state=false;
			}	
		}
	if (getbyid("txtMail").value==""){
		getbyid("txtMail").className="online_input_err";
		getbyid("check_mail").style.color="red";
		state=false;
		}else{
			if (ismail(getbyid("txtMail").value)){
				getbyid("txtMail").className="online_input";
				getbyid("check_mail").innerHTML='';
			}else{
				getbyid("txtMail").className="online_input_err";
				getbyid("check_mail").innerHTML="错误的邮箱地址！"
				getbyid("check_mail").style.color="red";
				state=false;
			}
		}
	if (getbyid("txtMobile").value!=""){
			if (ismobile(getbyid("txtMobile").value)){
				getbyid("txtMobile").className="online_input";
				getbyid("check_mobile").innerHTML='';
			}else{
				getbyid("txtMobile").className="online_input_err";
				getbyid("check_mobile").innerHTML="错误的手机号码！"
				getbyid("check_mobile").style.color="red";
				state=false;
			}
	}
	if (getbyid("txtAddress").value!=""){
			if (getbyid("txtAddress").value.length>5){
				getbyid("txtAddress").className="online_input";
				getbyid("check_address").innerHTML='';
			}else{
				getbyid("txtAddress").className="online_input_err";
				getbyid("check_address").innerHTML="你输入的地址太短啦！"
				getbyid("check_address").style.color="red";
				state=false;
			}
	}
	if (getbyid("txtContents").value==""){
		getbyid("txtContents").className="online_text_err";
		getbyid("check_content").style.color="red";
		state=false;
		}else{
			getbyid("txtContents").className="online_text";
			getbyid("check_content").style.color="#999999";
			}
		
	return state;
	
} 


function ismail(x){ 
var reg=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; 
if(!reg.test(x)){ 
	return false
	} 
else 
	{ 
	return true
	} 
}


function isphone(x){ 
var reg=/^(^[0-9]{3,4}\-[0-9]{6,8}$)|(^\([0-9]{3,4}\)[0-9]{6,8}$)/; 
	if(!reg.test(x)){ 
		return false
	}else{ 
		return true
	} 
} 
function ismobile(x){ 
	var reg=/^(^0{0,1}13[0-9]{9}$)|(^0{0,1}15[0-9]{9}$)/; 
	if(!reg.test(x)){ 
		return false
	}else{ 
		return true
	} 
} 

function drawImage(ImgD,widthStr,heightStr){ 
	var image=new Image(); 
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){ 
		if(image.width/image.height>= 1){ 
			if(image.width>widthStr){
   				ImgD.width=widthStr; 
   				ImgD.height=(image.height*widthStr)/image.width; 
  			}else{ 
  			 	ImgD.width=image.width;
   				ImgD.height=image.height; 
  			}
		}else{ 
  			if(image.height>heightStr){
   				ImgD.height=heightStr; 
   				ImgD.width=(image.width*heightStr)/image.height; 
  			}else{ 
   				ImgD.width=image.width;
   				ImgD.height=image.height; 
  			} 
		} 
	}
}
