//请修改此变量，与config.inc.asp中的RZ_ROOT的值相同
var rzroot="/";

//根据ID获取元素
function $(id){
	return document.getElementById(id);
}
//根据ID获取值
function v(id){
	return $(id).value;
}
/*首页显示产品_BEGIN*/
function ajax_getProducts(typeid,lan)
{
	document.getElementById("index_productlist_detail").innerHTML="<img src='"+rzroot+"images/loading.gif'/>";
	var date=new Date();
  	var stamp=date.getTime();
	var loader = new net.ContentLoader(rzroot+"ajax.asp?ajax=1&path="+typeid+"&lan="+lan+"&timestamp="+stamp,
		statechange_getProducts,stateerror_getProducts);
}
function statechange_getProducts()
{
var respText = this.req.responseText;
document.getElementById("index_productlist_detail").innerHTML=respText;
}
function stateerror_getProducts(){
	document.getElementById("index_productlist_detail").innerHTML="连接服务器出错";
}
function showproducttype(){
	var producttype = document.getElementById("index_producttype");
	if(producttype.style.display=="none"){
		producttype.style.display="";
	}else{
		producttype.style.display="none";
	}
}
function hiddeproducttype(){
	var producttype = document.getElementById("index_producttype");
	producttype.style.display="none";
}
/*首页显示产品_END*/

/*产品留言_BEGIN*/
function ajax_getRecordComments(proc,rid,lan)
{
	document.getElementById("recordcomment").innerHTML="<img src='"+rzroot+"images/loading.gif'/>";
	var date=new Date();
  	var stamp=date.getTime();
	var loader = new net.ContentLoader(rzroot+"plugins/recordcomment.asp?proc="+proc+"&rid="+rid+"&lan="+lan+"&timestamp="+stamp,
		statechange_getRecordComments,stateerror_getRecordComments);
}
function statechange_getRecordComments()
{
var respText = this.req.responseText;
document.getElementById("recordcomment").innerHTML=respText;
}
function stateerror_getRecordComments(){
	document.getElementById("recordcomment").innerHTML="连接服务器出错";
}

function ajax_AddRecordComment(proc,rid,lan,cat)
{
	document.getElementById("recordcomment_dialog").innerHTML="<img src='"+rzroot+"images/loading.gif'/>";
	document.getElementById("recordcomment_dialog").style.display='';
	var date=new Date();
  	var stamp=date.getTime();
	var url=rzroot+"plugins/recordcomment_addcomment.asp?proc="+proc+"&rid="+rid+"&lan="+lan+"&cat="+cat+"&timestamp="+stamp;
	var loader = new net.ContentLoader(url,
		statechange_AddRecordComment,stateerror_AddRecordComment);
}
function statechange_AddRecordComment()
{
	var respText = this.req.responseText;
	document.getElementById("recordcomment_dialog").innerHTML=respText;
}
function stateerror_AddRecordComment(){
	alert("连接服务器出错");
	document.getElementById("recordcomment_dialog").style.display="none";
}

function checkform_AddRecordComment()
{
	var flag=isNotEmpty("title","标题-Title")&&isNotEmpty("author","昵称-Nickname")&&checkEmail("email","Email")&&isNotEmpty("content","内容-Content")&&checkLength("title","标题-Title",2,50)&&checkLength("author","昵称-Nickname",2,20)&&checkLength("content","内容-Content",5,1000);
	return flag;
}

/*保存商品留言_BEGIN*/
function ajax_saveRecordComment(cat)
{
	if(checkform_AddRecordComment()){
		var date=new Date();
		var stamp=date.getTime();
		var params="title="+document.getElementById("title").value;
		params+="&messagetype=4";
		params+="&author="+document.getElementById("author").value;
		params+="&rid="+document.getElementById("rid").value;
		params+="&email="+document.getElementById("email").value;
		params+="&content="+document.getElementById("content").value;
		params+="&proc="+document.getElementById("proc").value;
		document.getElementById("recordcomment_dialog").style.display='';
		var url=rzroot+"plugins/recordcomment_savecomment.asp?timestamp="+stamp;
		if (cat==1)
		{
			var loader = new net.ContentLoader(url,
			statechange_saveRecordComment,stateerror_saveRecordComment,"POST",params);
		}else{
			var loader = new net.ContentLoader(url,
			statechange_saveRecordComment2,stateerror_saveRecordComment,"POST",params);
		}
		
	}
}
function statechange_saveRecordComment()
{
	var respText = this.req.responseText;
	alert(respText);
	document.getElementById("recordcomment_dialog").style.display="none";
	load_recordcomment();
}
function statechange_saveRecordComment2()
{
	var respText = this.req.responseText;
	alert(respText);
	document.getElementById("recordcomment_dialog").style.display="none";
	location.reload();
}
function stateerror_saveRecordComment(){
	alert("连接服务器出错");
	document.getElementById("recordcomment_dialog").style.display="none";
}
/*保存商品留言_END*/

/*产品留言_END*/

/*弹出添加留言对话框_BEGIN*/
function ajax_AddComment(lan)
{
	document.getElementById("dialog_comment").innerHTML="<img src='"+rzroot+"images/loading.gif'/>";
	document.getElementById("dialog_comment").style.display='';
	var date=new Date();
  	var stamp=date.getTime();
	var loader = new net.ContentLoader("commentlist_addcomment.asp?lan="+lan+"&timestamp="+stamp,
		statechange_AddComment,stateerror_AddComment);
}
function statechange_AddComment()
{
	var respText = this.req.responseText;
	document.getElementById("dialog_comment").innerHTML=respText;
}
function stateerror_AddComment(){
	alert("连接服务器出错");
	document.getElementById("dialog_comment").style.display="none";
}
/*弹出添加留言对话框_END*/
//检查添加留言对话框
//非空验证
function isNotEmpty(el_name,el_title)
{
	var e=document.getElementById(el_name);
	e.style.border="1px solid #9093BE";
	if (e.value==""){
		alert("请填写"+el_title);
		e.style.border="2px solid red";
		e.focus();
		return false;
	}else{
		return true;
	}
}
function checkform_AddComment()
{
	var flag=isNotEmpty("title","标题-Title")&&isNotEmpty("author","昵称-Nickname")&&isNotEmpty("email","Email")&&isNotEmpty("content","内容-Content")&&checkEmail("email","Email")&&checkLength("title","标题-Title",2,100)&&checkLength("author","昵称-Nickname",2,40)&&checkLength("content","内容-Content",10,1000);
	if (document.getElementById("tel").value!=""){
		flag=flag&&checkPhone("tel","电话/手机-Phone/Mobile");
	}
	return flag;
}
//检查Email地址
function checkEmail(el_name,el_title) {
	e=document.getElementById(el_name);
	el_value = e.value;
	if (el_value=="")
	{
		return true;
	}
	if(!validateEmailByReg(el_value)) {
		alert(el_title+"不合法，请重新填写！");
		e.style.border="2px solid red";
		e.focus();
		return false;
	}
	return true;
}
//检查电话号码
function checkPhone(el_name,el_title){ 
	e=document.getElementById(el_name);
	el_value = e.value;
	var reg=/^([\d-+()]*)$/;
	if (reg.test(el_value)==false)
	{
		alert(el_title+"不合法，请重新填写！is not valid");
		e.style.border="2px solid red";
		e.focus();
		return false;
	}
	return true;
}

//检查长度
function checkLength(el_name,el_title,min_Len,max_Len){ 
	e=document.getElementById(el_name);
	el_value = e.value;
	if (el_value.length>max_Len)
	{
		alert(el_title+"字符过多，最多"+max_Len+"个字符！");
		e.style.border="2px solid red";
		e.focus();
		return false;
	}
	if (el_value.length<min_Len)
	{
		alert(el_title+"字符过少，最少"+min_Len+"个字符！");
		e.style.border="2px solid red";
		e.focus();
		return false;
	}
	return true;
}

function validateEmailByReg(str){
    return(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(str));
}
/*保存留言_BEGIN*/
function ajax_saveComment()
{
	if(checkform_AddComment()){
		var date=new Date();
		var stamp=date.getTime();
		var params="title="+document.getElementById("title").value;
		params+="&messagetype="+document.getElementById("messagetype").value;
		params+="&author="+document.getElementById("author").value;
		params+="&company="+document.getElementById("company").value;
		params+="&email="+document.getElementById("email").value;
		params+="&tel="+document.getElementById("tel").value;
		params+="&content="+document.getElementById("content").value;
		document.getElementById("dialog_comment").style.display='';
		var loader = new net.ContentLoader("commentlist_savecomment.asp?timestamp="+stamp,
			statechange_saveComment,stateerror_saveComment,"POST",params);
	}
}
function statechange_saveComment()
{
	var respText = this.req.responseText;
	alert(respText);
	document.getElementById("dialog_comment").style.display="none";
	location.reload();
}
function stateerror_saveComment(){
	alert("连接服务器出错");
	document.getElementById("dialog_comment").style.display="none";
}
/*保存留言_END*/
/*专题查看*/
function ajax_showspecial(specialid,lan)
{
	document.getElementById("special_content").innerHTML="<img src='"+rzroot+"images/loading.gif'/>";
	var date=new Date();
  	var stamp=date.getTime();
	var loader = new net.ContentLoader(rzroot+"ajax.asp?ajax=2&specialid="+specialid+"&lan="+lan+"&timestamp="+stamp,
		statechange_showspecial,stateerror_showspecial);
}
function statechange_showspecial()
{
var respText = this.req.responseText;
document.getElementById("special_content").innerHTML=respText;
}
function stateerror_showspecial(){
	document.getElementById("special_content").innerHTML="连接服务器出错";
}
//关闭留言框
function closeDialog(dialogname){
	var el=$(dialogname);
	el.innerHTML="";
	el.style.display="none";
}
//显示搜索框
function showSearch(){
	var e=document.getElementById("searchbox");
	if(e.style.display=="none"){
		e.style.display="";
	}else{
		e.style.display="none";
	}
}
function checksearch(){
	var loc;
	if(isNotEmpty("keyword","关键字-Keyword")&&checkLength("keyword","关键字-Keyword",2,20)){
		loc=v("searchtype")+"--"+escape(v("keyword"));
		document.location=loc;
	}
}

function hideElement(id){
	$(id).style.display="none";
}
function displayList(id){
	var el=document.getElementById(id)
	el.style.display="";
}

/*增加点击数*/
function ajax_AddHits(proc,id)
{
	
	var date=new Date();
  	var stamp=date.getTime();
	var url=rzroot+"plugins/addhits.asp?proc="+proc+"&id="+id+"&timestamp="+stamp;
	var loader = new net.ContentLoader(url,
		statechange_AddHits,stateerror_AddHits);
}
function statechange_AddHits()
{
	var respText = this.req.responseText;
	//alert(respText);
	if (respText.length>0)
	{
		document.getElementById("hits").innerHTML=respText;
	}
}
function stateerror_AddHits(){
	
}