﻿function suit(){
	var vs = $("from_who","email","phone","cls_id","title","content","checkcode");
	if(vs[0].value==""){
		alert('请填写您的姓名！');
		vs[0].focus();
		return false;
	}
	
	if(vs[1].value=="" && vs[2].value==""){
		alert("邮箱和电话必填其一！");
		if(vs[1].value==""){vs[1].focus();}
		else if (vs[2].value=="") {vs[2].focus();}
		return false;
	}
	
	if( vs[1].value != ""){
		if(IsEmail(vs[1].value)==false){
			alert("请填写合法的邮箱地址！");
			return false;
		}
	}
	
	if(vs[2].value !=""){
		if(IsPhone(vs[2].value)==false){
			alert("请填写正确的电话号码!\r\r如果为固定电话,请加上区号.");
			vs[2].focus();
			return false;
		}				
	}
	
	if(vs[3].value =="0"){
		alert("没有选择要投递的信箱类别!")
		vs[3].focus();
		return false;
	}
	
	if(vs[4].value ==""){
		alert('请您填写留言主题！');
		vs[4].focus();
		return false;
	}
	
	if(vs[5].value==""){
		alert('请填写信件内容！');
		vs[5].focus();
		return false;
	}
	
	if(vs[5].value.length<10) {
		alert('信件内容太短！不允许提交。');
		vs[5].focus();
		return false;
	}
	
	if(vs[6].value ==""){
		alert('请填写验证码');
		return false;
		vs[6].focus();
	}
	
	if (vs[6].value.length != 6){
		alert("验证码应为6个字符。");
		vs[6].focus();
		return (false);
	}
	
	if(!checkVcode(vs[6].value)){
		alert("验证码只能输入数字和字母。");
		vs[6].value="";
		vs[6].focus();
		return (false);
	}
	
	return true;			
}

function checkVcode(thecode){
	var checkOK = "0123456789abcdefghijklmnopqrstuvwxyz-";
	var checkStr = thecode.toLowerCase();;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j)){
				break;
			}
			if (j == checkOK.length){
				allValid = false;
				break;
			}
		}
	}
	return allValid;
}

function IsEmail(mail){
	return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
}

function IsPhone(mobile){
	var reg0=/^13\d{5,9}$/;   //130--139。至少7位
	var reg1=/^153\d{8}$/;  //联通153。至少7位
	var reg2=/^159\d{8}$/;  //移动159。至少7位
	var reg3=/^158\d{8}$/;
	var reg4=/^150\d{8}$/;
	var reg5=/^0\d{2,3}-{0,1}\d{7,8}$/;
	if (reg0.test(mobile)){return true;}
	if (reg1.test(mobile)){return true;}
	if (reg2.test(mobile)){return true;}
	if (reg3.test(mobile)){return true;}
	if (reg4.test(mobile)){return true;}
	if (reg5.test(mobile)){return true;}
	return false;
}

var show_checkcode = false;
function get_checkcode() {
	var chkCodeFile = "/inc/checkcode.asp";
	if(!show_checkcode){
		if($("img_checkcode")){
			$("img_checkcode").innerHTML ='<img id="checkcodeimg" src="' + chkCodeFile + '?t='+Math.random()+'" alt="点击刷新" style="cursor:pointer;border:0;" onclick=\"this.src=\'' + chkCodeFile + '?t=+Math.random()\';\" />'
			show_checkcode = true;
		}
		if($("isok_checkcode")){
			$("isok_checkcode").innerHTML = '<a href="javascript://" onclick="setTimeout(function(){ $(\'checkcodeimg\').src=\'' + chkCodeFile + '?t=\'+Math.random()},100);">看不清<\/a>';
		}
	}
}

function ly(){
	if($('add_new').style.display=='none'){
		var ptop;
		var pleft;
		pleft = parseInt(document.body.clientWidth);
		pleft = Math.abs(pleft - parseInt(document.getElementById('add_new').style.width))/2; 
		$('add_new').style.left=pleft +"px";
		$('add_new').style.top="80px";
		$('add_new').style.display='block';
	}else{
		$('add_new').style.display='none';
	}
}

function refreshbg(v,t){
	var o = $("attention");
	var bg = "url(images/attention.gif) no-repeat ";
	if(t==1){
		bg="url(images/helpful.gif) no-rpeat ";
		o=$("helpful");
	}
	var colour="#E68B4D";
	if (v==1){
		bg += " 0px -84px";
		colour="#FFFFFF"
	}else{
		bg += " left top";
	}
	o.style.background=bg;
	o.down("span").style.color=colour;
}

function updatehelpful(i,c){
	var cookieName ="isUpdated" + i;
	if(readCookie(cookieName)=="true"){
		alert("您已经提交了反馈信息,\r\r感谢您对我们工作的支持!");
		return;
	}
	var uri = "helpful.asp";
	var pas="i="+i;
	if(c!=null){
		pas += "&c=" + c;
	}
	var myAjax = new Ajax.Request(
		uri,
		{
			method:'get',
			parameters:pas,
			onComplete:updates
		}
	)
}
function updates(response) 
{ 
    $('hvalue').innerHTML = response.responseText; 
}

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

