﻿function $(){
return document.getElementById(arguments[0]);
}

function bindCheckHandle(){
	var objs = document.getElementsByName("msgs");
	for(var i = 0;i<objs.length;i++){
		objs[i].onclick = function(){
			var _hid_Prod = $("productids");
			var _div_msgContainer = $("msgContainer");
			var _id = parseInt(this.id.substr(3));
			var tempHTML = _div_msgContainer.innerHTML;
			if(this.checked){
				if(_hid_Prod.value.indexOf(","+ _id) != -1)
					return;
				_hid_Prod.value += "," + _id;
				tempHTML += (tempHTML == "" ? "" : "　|　") + "<a href=\"http://" + window.location.host + "/product/view.asp?id=" + _id + "\">" + this.value + "</a>";
			}
			else{
				if(_hid_Prod.value.indexOf(","+ _id) == -1)
					return;
				var tempHTML = _div_msgContainer.innerHTML;
				_hid_Prod.value = _hid_Prod.value.replace("," + _id, "");
				tempHTML = tempHTML.replace(new RegExp("(　\\|　)?<a\\shref=\"http://" + window.location.host + "/product/view.asp\\?id=" + _id + "\">[^<]+</a>","ig"),"");
			}
			_div_msgContainer.innerHTML = tempHTML;
			//将同一页面同一个产品状态同步
			var oMsgs = document.getElementsByName("msgs");
			for(var _i = 0 ; _i < oMsgs.length; _i++){
				if(oMsgs[_i].id == this.id)
					oMsgs[_i].checked = this.checked;
			}
		}
	}
}

function AddIntroduce(obj)
{
	var text = obj.value;
	var oTarget = document.getElementById('Introduce');
	var bPrefix = true;
     if(obj.checked){
		if(oTarget.value.indexOf(text) == -1){
			if(oTarget.value == "")
				oTarget.value = text;
			else
				oTarget.value += (bPrefix? "；" : "") + text;
		}
	}
	else{
		var reg = new RegExp("；?" + text , "ig");
		oTarget.value = oTarget.value.replace(reg,"");
	}
}

function AddMessage(obj)
{
	var text = obj.value;
	var oTarget = document.getElementById('message');
	var bPrefix = true;
     if(obj.checked){
		if(oTarget.value.indexOf(text) == -1){
			if(oTarget.value == "")
				oTarget.value = text;
			else
				oTarget.value += (bPrefix? "；" : "") + text;
		}
	}
	else{
		var reg = new RegExp("；?" + text , "ig");
		oTarget.value = oTarget.value.replace(reg,"");
	}
}

function chk(boxID){
	var dd=eval("document.vForm."+ boxID);
	for(var i=0;i<dd.length;i++){
		if(dd[i].checked==true)return true;
	}
	return false;
}

function IsURL(str_url){
    var sTemp;
    var strRegex = "^((https|http|ftp|rtsp|mms)?://)" 
    + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@ 
          + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 
          + "|" // 允许IP和DOMAIN（域名）
          + "([0-9a-z_!~*'()-]+\.)*" // 域名- www. 
          + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 
          + "[a-z]{2,6})" // first level domain- .com or .museum 
          + "(:[0-9]{1,4})?" // 端口- :80 
          + "((/?)|" // a slash isn't required if there is no file name 
          + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; 
          var re=new RegExp(strRegex);
		  sTemp=str_url.substring(0,7);
	      sTemp=sTemp.toUpperCase(); 
    //re.test()
          if (re.test(str_url)){
		     if ((sTemp!="HTTP://")||(str_url.length<10)){
		        return (false); 
	         }else{
                return (true); 
			 }
          }else{ 
              return (false); 
          }
      }

function checkform(objForm){

      var objForm;
	　var re = /^[_a-zA-Z0-9\-\.]+@([\-_a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,3}$/;
	　var rc = /^[0-9]{6}$/;
      var rai = /^\d{15}$|^\d{18}$|^\d{17}x$/;
	  var rtel = /^[_0-9\-\.]+-[0-9]{7,8}$/;
	  var ram = /^\d{11}/;
	  var raq = /^[0-9]{4,9}$/;
	  
	  var CorpName = objForm.CorpName.value;
	  var Contact = objForm.Contact.value;
	  var Phone = objForm.Phone.value;
	  var Mobile = objForm.Mobile.value;
	  var Email = objForm.Email.value;
	  var Postcode = objForm.Postcode.value;
	  var Address = objForm.Address.value;
	  var Agented = objForm.Agented.value;
	  var County = objForm.County.value;
	  var Introduce = objForm.Introduce.value;
	  var message = objForm.message.value;
	  
	  if (CorpName.length<1 || CorpName.length >200)
	  {
		  alert("【公司/个人名称】不能为空或长度不符合规范，请重新填写！\n");
		  objForm.CorpName.focus();
		  return false;
	  }
	  
	  if (Contact.length<1 || Contact.length >30)
	  {
		  alert("【联系人】不能为空或长度不符合规范，请重新填写！\n");
		  objForm.Contact.focus();
		  return false;
	  }
	  
      if (Phone == "" || (!Phone.match(rtel))){
		  alert("【联系电话】不能为空或者格式错误\n");
          objForm.Phone.focus();
          return false;
          }
		  
	  if (Mobile == "" || (!Mobile.match(ram))){
		  alert("【手机号码】】不能为空或者格式错误\n");
		  objForm.Mobile.focus();
		  return false;
	     }
		 
      if (Email == "" || (!Email.match(re))){
          alert("【电子邮件】】不能为空或者格式错误\n");
          objForm.Email.focus();
          return false;
          }
		  
	  if (Postcode != '' && (!Postcode.match(rc))){
		  alert("【邮政编码】格式错误，请填写正确的邮政编码\n");
		  objForm.Postcode.focus();
		  return false;
	     }
		 
	  if (chk("cbRegion") == false)
	  {
		  alert("请选择【希望代理区域】！\n");
		  return false;
	  }
	  
	  if (County != '' && County.length >200)
	  {
		  alert("【希望代理县市】必须少于200字符！\n");
		  objForm.County.focus();
		  return false;
	  }
	  
	  if (Agented != '' && Agented.length >100)
	  {
		  alert("【曾经代理产品】必须少于100字符！\n");
		  objForm.Agented.focus();
		  return false;
	  }
	  
	  if (Introduce == "" || Introduce.length >200)
	  {
		  alert("【我的优势】不能为空或长度不符合规范，请重新填写！\n");
		  objForm.Introduce.focus();
		  return false;
	  }
	  
	  if (message == "" || message.length >200)
	  {
		  alert("【代理留言】不能为空或长度不符合规范，请重新填写！\n");
		  objForm.message.focus();
		  return false;
	  }
	  		 
	  if(confirm("确认资料填写正确并提交吗？")){
		  return true;
	     }else{
		  return false;
	     }
          
  }           