﻿/*function killErrors() {return true;}
window.onerror = killErrors;*/

var Ajax_msg="通讯失败";

function trim(s){return  s.replace(/(^\s*)|(\s*$)/g,  "");} 

function setTab(name,cursel,n){
	for(i=1;i<=n;i++){
		var menu=$('#'+name+i);
		var con=$("#con_"+name+"_"+i);
		menu[0].className=i==cursel?"hover":"";
		con[0].style.display=i==cursel?"block":"none";
	}
}

function menu(t0)
{
	for(i=0;i<=8;i++)
	{
		$("#menu0"+i)[0].style.display='none';
	}
	$("#menu0"+t0)[0].style.display='block';
}

function CheckAll(form)
{
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.Name != "chkAll")
       e.checked = form.chkAll.checked;
    }
}

function check_userlogin(theform)
{  
	if (trim(theform.username.value)=='')
	{   alert('用户名不能为空');
		theform.username.focus();
		theform.username.value='';
		return false
	}
	if (trim(theform.password.value)=='')
	{   alert('密码不能为空');
		theform.password.focus();
		theform.password.value='';
		return false
	}
	var param;
	param="/Inc/User.asp?action=CheckLogin";
	param+="&username="+escape(trim(theform.username.value));
	param+="&password="+escape(trim(theform.password.value));
	param+="&gourl="+escape(trim(theform.gourl.value));
	$.ajax({
	type:"post",
	cache:false,
	url:param,
	timeout:20000,
	error:function(){alert("通讯失败");},
	success:function(t0)
	{
		if(t0.substring(0,1)==0)
		{
			alert(t0.substring(1));
		}
		else
		{
			location.href=t0.substring(1);
			}
		}	
	});	
	return false
}

/*用户注册检测相关*/
function sd_ajaxcheck(t0)
{
	var t1 = $('#'+t0)[0].value;
	var t2="user_"+t0;
	var param;
	param="/Inc/ajax_check.asp";
	param+="?action="+escape(trim(t0));
	param+="&FormValue="+escape(trim(t1));
	$.ajax({
	type:"post",
	cache:false,
	url:param,
	timeout:20000,
	error:function(){$("#"+t2).html(Ajax_msg);},
	success:function(t00)
	{
		$("#"+t2).html(t00);
	}});
}

/*重复密码检测相关*/
function sd_reg_pass(t0,str)
{
	var t1 = $('#'+t0)[0].value;
	var t3 = $('#'+str)[0].value;
	var t2="user_"+t0;
	var param;
	param="/Inc/ajax_check.asp";
	param+="?action="+escape(trim(t0));
	param+="&FormValue="+escape(trim(t1));
	param+="&password="+escape(trim(t3));
	$.ajax({
	type:"post",
	cache:false,
	url:param,
	timeout:20000,
	error:function(){$("#"+t2).html(Ajax_msg);},
	success:function(t00)
	{
		$("#"+t2).html(t00);
	}});
}
//会员注册
function CheckUserReg(theform)
{
	
	if (trim(theform.t0.value)==''||theform.t0.value.length<4 ||theform.t0.value.length>20)
	{
		theform.t0.focus();
		return false
	}
	if (trim(theform.t1.value)==''||theform.t1.value.length<4 ||theform.t1.value.length>10)
	{
		theform.t1.focus();
		return false
	}
	if (trim(theform.t2.value)==''||trim(theform.t2.value)!=trim(theform.t2.value))
	{
		theform.t2.focus();
		return false
	}
	if (trim(theform.t3.value).search(/^[^\s@:"'<>,&]{2,}@[^\[\.]+\.[^\[]{2,}$/gi)<0)
	{
		theform.t3.focus();
		return false
	}
	if (trim(theform.t4.value)=='')
	{
		theform.t4.focus();
		return false
	}
	
	if ($('#agree')[0].checked)
	{
		theform.Submit.value='提交中…';
		theform.Submit.disabled=true;
	var param;
	param="/Inc/User.asp?action=RegSave";
	param+="&username="+escape(trim(theform.t0.value));
	param+="&password="+escape(trim(theform.t1.value));
	param+="&repass="+escape(trim(theform.t2.value));
	param+="&email="+escape(trim(theform.t3.value));
	param+="&code="+escape(trim(theform.t4.value));
	param+="&agree=1";
	$.ajax({
	type:"post",
	cache:false,
	url:param,
	timeout:20000,
	error:function(){alert(Ajax_msg);},
	success:function(t0)
	{
		if(t0.substring(0,1)==0){
			alert(t0.substring(1));
			theform.Submit.value='提交';
			theform.Submit.disabled=false;
		}
		else{
			theform.t0.value='';
			theform.t1.value='';
			theform.t2.value='';
			theform.t3.value='';
			theform.t4.value='';
			theform.Submit.value='提交';
			theform.Submit.disabled=false;
			alert(t0.substring(1));
			}
		}	
	});
	return false;
		}
	else
	{
		alert('您只有同意会员注册协议，才能继续注册!');
		return false;
	}
}

function check_GetMyPass(theform)
{
	if (trim(theform.t0.value)=='')
	{
		alert("请输入您的邮箱地址");
		theform.t0.focus();
		return false
	}
	if (trim(theform.t0.value).search(/^[^\s@:"'<>,&]{2,}@[^\[\.]+\.[^\[]{2,}$/gi)<0)
	{
		alert("邮箱地址格式不正确");
		theform.t0.focus();
		return false
	}
	
	var param;
	param="/Inc/User.asp?action=GetMyPass";
	param+="&email="+escape(trim(theform.t0.value));
	$.ajax({
	type:"post",
	cache:false,
	url:param,
	timeout:20000,
	error:function(){alert(Ajax_msg);},
	success:function(t0)
	{
		alert(t0.substring(1));
		if(t0.substring(0,1)==1){theform.t0.value='';}
	}	
	});	
	return false
}

function checkedit(theform)
{
	if (trim(theform.t0.value)=='')
	{
		alert("请输入您的邮箱地址");
		theform.t0.focus();
		return false
	}
	if (trim(theform.t0.value).search(/^[^\s@:"'<>,&]{2,}@[^\[\.]+\.[^\[]{2,}$/gi)<0)
	{
		alert("邮箱地址格式不正确");
		theform.t0.focus();
		return false
	}
	if (trim(theform.t6.value)=='')
	{
		alert("请输入您的姓名");
		theform.t6.focus();
		return false
	}
}

function check_address(theform)
{
	if (trim(theform.t0.value)=='')
	{
		alert("请输入收货人");
		theform.t0.focus();
		return false
	}
	if (trim(theform.t1.value)==''&&trim(theform.t2.value)=='')
	{
		alert("电话和手机至少输入一项");
		theform.t1.focus();
		return false
	}
	
	if (trim(theform.t3.value)=='')
	{
		alert("请输入邮编");
		theform.t3.focus();
		return false
	}
	if (trim(theform.t4.value)=='')
	{
		alert("请输入地址");
		theform.t4.focus();
		return false
	}
}

function check_pass(theform)
{
	if (trim(theform.t0.value)=='')
	{
		alert("请输入原密码");
		theform.t0.focus();
		return false
	}
	if (trim(theform.t1.value)=='')
	{
		alert("请输入新密码");
		theform.t1.focus();
		return false
	}
	if (trim(theform.t2.value)=='')
	{
		alert("请确认新密码");
		theform.t2.focus();
		return false
	}
	if (trim(theform.t1.value)!=trim(theform.t2.value))
	{
		alert("新密码和确认密码不一致");
		theform.t1.focus();
		return false
	}
}


function checksearch(theform)
{
	if (trim(theform.t1.value)=='')
	{alert('关键字不能为空');
	theform.t1.focus();
	theform.t1.value='';
	return false
	}
	if (theform.t1.value=='请输入关键字')
	{alert('关键字不能为空');
	theform.t1.focus();
	theform.t1.value='';
	return false
	}
}

function check_comment(theform,id)
{
	if(islogin())
	{
		$("#showmsg").html("登录后才能评论，请先<a href=login.asp>登录</a>或<a href=reg.asp>注册</a>");
		return false
	}

	if(trim(theform.t0.value).length<10)
	{
		$("#showmsg").html("评论内容不能小于10个字符");
		theform.t0.focus();
		return false
	}
	if(trim(theform.t0.value).length>200)
	{
		$("#showmsg").html("评论内容不能超过200个字符");
		theform.t0.focus();
		return false
	}

	if(trim(theform.t1.value).length<2)
	{
		$("#showmsg").html("姓名不能小于2个字符");
		theform.t1.focus();
		return false
	}
	if(trim(theform.t1.value).length>10)
	{
		$("#showmsg").html("姓名不能超过10个字符");
		theform.t1.focus();
		return false
	}
	var param;
	param="/Inc/Comment.asp?action=add&id="+escape(id);
	param+="&t0="+escape(trim(theform.t0.value));
	param+="&t1="+escape(trim(theform.t1.value));
	$.ajax({
	type:"post",
	cache:false,
	url:param,
	timeout:20000,
	error:function(){alert(Ajax_msg);},
	success:function(t0)
	{
		if(t0.substring(0,1)==1)
		{
			theform.t0.value='';
			theform.t1.value='';
			$("#showmsg").html("评论提交成功，请等待审核");
		}
		else
		{
			$("#showmsg").html(t0.substring(1));
		}
	}	
	});
	return false
}

function islogin()
{
	var param;
	var is_true;
	param="/Inc/User.asp?action=ajaxcheck";
	$.ajax({
	type:"post",
	async:false,
	cache:false,
	url:param,
	timeout:20000,
	error:function(){alert(Ajax_msg);},
	success:function(t0)
	{
		if(t0==0)
		{
		 is_true=true;	
		}
		else{
		 is_true=false;
		}
	}	
	});
	return is_true;
}

function change(){
   if(!document.all)
      return
   if (event.srcElement.id=="foldheader") {
      var srcIndex = event.srcElement.sourceIndex
      var nested = document.all[srcIndex+1]
      if (nested.style.display=="none") {
         nested.style.display=''
      }
      else {
         nested.style.display="none"
      }
   }
}
document.onclick=change

function Digg_Action(t0,t1,t2,t3,t4,t5)
{
	$.ajax({
	type: "get",
	cache:false,
	url: "/Inc/Digg.asp?id="+t0+"&action="+t1+"",
	timeout: 20000,
	error: function(){alert(Ajax_msg);},
	success: function(t6){
		var t7=t6.split(':');
		var sUp=parseInt(t7[0]);
		var sDown=parseInt(t7[1]);
		var sTotal=sUp+sDown;
		if(sTotal==0)
		{
			var spUp=0;var spDown=0;
		}
		else
		{
		var spUp=(sUp/sTotal)*100;
		spUp=Math.round(spUp*10)/10;
		var spDown=100-spUp;
		spDown=Math.round(spDown*10)/10;
		}
		var t8=t7[2];
		if (t8==1)
		{
			$('#'+t2).html(spUp+"%("+sUp+")");
			$('#'+t3).html(spDown+"%("+sDown+")")
			$('#'+t4)[0].style.width=spUp+'%';
			$('#'+t5)[0].style.width=spDown+'%';
		}
		else{alert('您不是已表过态了嘛！');}
		}
	});
}

function checkbook(theform)
{  
	if (trim(theform.title.value)=='')
	{   alert('标题不能为空');
		theform.title.focus();
		theform.title.value='';
		return false
	}
	var temp=""; 
	for(var i=0;i<theform.stype.length;i++) 
	{ 
	if(theform.stype[i].checked) 
	temp+=theform.stype[i].value; 
	}
	if(temp=="")
	{
		alert("请选择类别");
		return false
	}
	if (trim(theform.content.value)=='')
	{   alert('内容不能为空');
		theform.content.focus();
		theform.content.value='';
		return false
	}
	var param;
	param="Inc/book.asp?action=save";
	param+="&title="+escape(trim(theform.title.value));
	param+="&stype="+escape(temp);
	param+="&content="+escape(trim(theform.content.value));
	param+="&email="+escape(trim(theform.email.value));
	param+="&tel="+escape(trim(theform.tel.value));
	$('#showmsg')[0].style.display='block';
	$('#showmsg').html("数据处理中");
	$.ajax({
	type:"post",
	cache:false,
	url:param,
	timeout:20000,
	error:function(){$('#showmsg').html(Ajax_msg);},
	success:function(t0)
	{
		$('#showmsg').html(t0.substring(1));
		if(t0.substring(0,1)==1){theform.title.value='';theform.content.value='';theform.email.value='';theform.tel.value='';setTimeout("$('#showmsg')[0].style.display='none';","3000");}
		}
	});
	return false
}

function checkmail(theform)
{  
	if (trim(theform.t0.value)=='')
	{   alert('您的邮箱不能为空');
		theform.t0.focus();
		theform.t0.value='';
		return false
	}
	if (trim(theform.t0.value).search(/^[^\s@:"'<>,&]{2,}@[^\[\.]+\.[^\[]{2,}$/gi)<0)
	{   alert('邮箱格式错误');
		theform.t0.focus();
		theform.t0.value='';
		return false
	}
	if (trim(theform.t2.value)=='')
	{   alert('邮件标题不能为空');
		theform.t2.focus();
		theform.t2.value='';
		return false
	}
	if (trim(theform.t3.value)=='')
	{   alert('邮件内容不能为空');
		theform.t3.focus();
		theform.t3.value='';
		return false
	}
}
