﻿function $(obj){return document.getElementById(obj);}

function showTip(nID){
	for(var i=0;i<9;i++){
		if(i==nID){
			$("tip_"+i).style.display="block";
			$("a_"+i).style.background="url(/i/n1.png) repeat-x";
			$("a_"+i).style.color="#000";
			$("a_"+i).style.borderRight="1px solid #853212";
			$("a_"+i).style.borderLeft="1px solid #853212";
			$("a_"+i).style.padding="0px 16px";
		}else{
			$("tip_"+i).style.display="none";
			$("a_"+i).style.background="none";
			$("a_"+i).style.color="#FFF";
			$("a_"+i).style.borderRight="";
			$("a_"+i).style.borderLeft="";
			$("a_"+i).style.padding="0px 17px";
		}
	}
}
function showDiv(sID,oID){
	$("ilnc_"+sID).style.display="block";
	$("ilnt_"+sID).className="ilnta1";
	$("ilnc_"+oID).style.display="none";
	$("ilnt_"+oID).className="ilnta2";
}

//设备导购
function selsType(d){if($("sType"+d).checked==true){$("sType"+d).checked=false;}else{$("sType"+d).checked=true;}}
function chkGuide(){
	$("sebg").style.background="";
	$("nabg").style.background="";
	$("tebg").style.background="";
	$("embg").style.background="";
	if(!IsCheck("sType")){$("sebg").style.background="#EEE";alert("请选择您所需要的服务！");return false;}
	if($("uName").value==""){$("nabg").style.background="#EEE";alert("请输入您的真实姓名！");$("uName").focus();return false;}
	if($("uTel").value==""){$("tebg").style.background="#EEE";alert("请输入您的联系电话！");$("uTel").focus();return false;}
	if($("eMail").value==""){$("embg").style.background="#EEE";alert("请输入您的电子邮件！");$("eMail").focus();return false;}else{if(!isEmail($("eMail").value)){$("embg").style.background="#EEE";alert("您输入的电子邮件有误！");$("eMail").focus();return false;}}
	for(var i=0;i<$("selPro").options.length;i++){$("selPro").options[i].selected=true;}
}

function moveOption(e1, e2){
	for(var i=0;i<$(e1).options.length;i++){
		if($(e1).options[i].selected){
			var e = $(e1).options[i];
			$(e2).options.add(new Option(e.text, e.value));
			$(e1).remove(i);
			i=i-1
		}
	}
}

//用户中心
function chkLogin(){
	if($("userName").value==""){alert("请输入用户名！");$("userName").focus();return false;}
	if($("userPwd").value==""){alert("请输入密码！");$("userPwd").focus();return false;}
}
function goUrl(r){window.location.href=r;}


//产品列表
function showCls(d,t){
	for(var i=0;i<t;i++){$("bc_"+i).className="bcls b0";$("sc_"+i).className="scls none"}
	$("bc_"+d).className="bcls b1";$("sc_"+d).className="scls";
}

function showCon(cID,tID){
	for(var i=0;i<=tID;i++){$("nc_"+i).className="none";}
	$("nc_"+cID).className="";
	if(cID==tID){$("nc_about").className="none";}else{$("nc_about").className="";}
}

function oCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy");}

function chkReg(){
	$("userbg").style.background="";
	$("pwdbg").style.background="";
	$("namebg").style.background="";
	$("telbg").style.background="";
	$("mailbg").style.background="";
	if($("uName").value==""){$("userbg").style.background="#EEE";alert("请输入用户名！");$("uName").focus();return false;}
	if($("uPwd").value==""){$("pwdbg").style.background="#EEE";alert("请输入密码！");$("uPwd").focus();return false;}
	if($("rName").value==""){$("namebg").style.background="#EEE";alert("请输入您的姓名！");$("rName").focus();return false;}
	if($("uTel").value==""){$("telbg").style.background="#EEE";alert("请输入您的联系电话！");$("uTel").focus();return false;}
	if($("uMail").value==""){$("mailbg").style.background="#EEE";alert("请输入电子邮件！");$("uMail").focus();return false;}else{if(!isEmail($("uMail").value)){$("mailbg").style.background="#EEE";alert("您输入的电子邮件有误！");$("uMail").focus();return false;}}
	for(var i=0;i<$("buyPro").options.length;i++){$("buyPro").options[i].selected=true;}
	for(var i=0;i<$("attPro").options.length;i++){$("attPro").options[i].selected=true;}
}

function IsCheck(oID){
	var isChk=false;
	var oL=document.getElementsByName(oID);
	if(oL!=null){if(oL.length>0){for(var i=0;i<oL.length;i++){if(oL[i].checked==true){isChk=true;break;}}}}
	return isChk;
}

function chkFaq(){
	$("bgCls").style.background="";
	$("bgTitle").style.background="";
	$("bgName").style.background="";
	$("bgEMail").style.background="";
	$("bgQuestion").style.background="";
	if($("faqCls").value==""){$("bgCls").style.background="#EEE";alert("请选择问题类型！");$("faqCls").focus();return false;}
	if($("faqTitle").value==""){$("bgTitle").style.background="#EEE";alert("请输入问题标题！");$("faqTitle").focus();return false;}
	if($("faqName").value==""){$("bgName").style.background="#EEE";alert("请输入您的姓名！");$("faqName").focus();return false;}
	if($("faqEMail").value==""){$("bgEMail").style.background="#EEE";alert("请输入您经常使用的电子邮件！");$("faqEMail").focus();return false;}else{if(!isEmail($("faqEMail").value)){$("bgEMail").style.background="#EEE";alert("您输入的电子邮件有误！");$("faqEMail").focus();return false;}}
	if($("faqCon").value==""){$("bgQuestion").style.background="#EEE";alert("请输入具体问题内容！");$("faqCon").focus();return false;}
}


function isEmail(strEmail) {
    if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}


function AjaxPost(m,posturl,data,callback)
{
	var req=(window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
	data=data+"&m="+Math.random()
	if (m=="1"){
		req.open("POST",posturl,true);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.setRequestHeader("CharSet","GB2312");
		req.send(data);
	}else{
		req.open("GET",posturl+"?"+data,true);
		req.send(null);
	}
	req.onreadystatechange = function() {
		if (req.readyState == 4 && req.status == 200) {
			var reqtext=req.responseText;
			$(callback).innerHTML=reqtext;
		}
	}	
}
function setHits(ID,aTy){
	AjaxPost(1,"/Hits.asp","Act=UpdateHits&ID="+ID+"&aTy="+aTy,aTy);
}

var flag=false;
function DrawImage(ImgD,ImgW,ImgH){
	var image=new Image();
	var iwidth = ImgW;
	var iheight = ImgH;
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
	flag=true;
	if(image.width/image.height>= iwidth/iheight){
		if(image.width>iwidth){  
		ImgD.width=iwidth;
		ImgD.height=(image.height*iwidth)/image.width;
		}else{
		ImgD.width=image.width;  
		ImgD.height=image.height;
		}
		}
	else{
		if(image.height>iheight){  
		ImgD.height=iheight;
		ImgD.width=(image.width*iheight)/image.height;		
		}else{
		ImgD.width=image.width;  
		ImgD.height=image.height;
		}
		}
	}
}
