
//关联focus事件，使input元素选中时变色，同时执行focusFunc事件和blurFunc事件，都以this为参数
function Checkbarcode()
{
   $("checkbarcode").value="checkbarcode";
  // alert($("checkbarcode").value);
   if(checkUserName($("barcode").value))
    return true;
   else
   {
    $("barcode").focus();
   return false;
   }
}

function $(e)
{	 
 return document.getElementById(e);
}

function $F(e)
{	 
 return document.getElementById(e).value;
}
 //attachFocusEvent2(focusArray2,  ShowMeiNotice,ShowMeiNotice,ShowMeiNotice);
 
 //字段   焦点移动   失去焦点   键按下 
 
function attachFocusEvent2(focusArray,  focusFunc, blurFunc,keydownFunc) {
	//alert("aaaaaaaaa");
	for (i=0;i<focusArray.length;i++)
	{
	//alert("bbbbbbbbb");
      // alert(focusArray[i].toUpperCase().indexOf("BUTTON"));
	   if(focusArray[i].toUpperCase().indexOf("BUTTON")<=-1)
	   {
	     var tagenames="";
	     try{
	     tagenames=  $(focusArray[i]).tagName;
	     }
	     catch(eeeee)
	     {
	       alert(focusArray[i]);
	     }
	     
	     if(tagenames=="INPUT"||tagenames=="SELECT"||tagenames=="TEXTAREA")
	     {   
	         $(focusArray[i]).onfocus=function(){ 
				        //this.className += " " + focusCss;         				
				        if(focusFunc != null){
 					       focusFunc(this.id);
				        }
			        } 
	        $(focusArray[i]).onblur=function(){ 
				        //this.className += " " + focusCss; 
				        if(blurFunc != null){
					        blurFunc(this.id);
				        }
        				
			        } 
			        $(focusArray[i]).onkeypress=function(){ 
				        //this.className += " " + focusCss; 
				        if(keydownFunc != null){
				        keydownFunc(this.id);
				         
				        }
        				
			        } 
			        
			    if(tagenames=="SELECT")
			    { 
			   // alert(focusArray[i]);
			      $(focusArray[i]).onchange=function(){ 
						        //this.className += " " + focusCss; 
		        				
						        if(blurFunc != null){
							        blurFunc(this.id);
						        }
		        				
					        } 
			    
			    }
	    }
	    
			        
		}
		else
		{
		    $(focusArray[i]).onclick=function(){ 
				        //this.className += " " + focusCss; 
        				
				        if(focusFunc != null){
					      return  ShowMeiAllNotice(focusArray);
				        }
        				
			        } 
		  
		}
		
	}
	
}

function focusEvent(obj,focusCss){
	//obj.className+=" "+focusCss;
	alert("bb");
}

function blurEvent(obj,focusCss){
	//obj.className=obj.className.replace(new RegExp(" " + focusCss + "\\b"), ""); 
}

function disable(elem) {
	$(elem).disabled = true;
}

function enable(elem) {
	$(elem).disabled = false;
}



function checkbirthday(year,month,day,birthday)
{
  var years=$(year).value;
  var months=$(month).value;
  var day=$(day).value;
 // alert(birthday);
  if(years!=""&months!=""&&day!="")
  {
     $(birthday).value=years+"-"+months+"-"+day;
     $(birthday+"_msg").className="notice";
     //return true;
     //alert("fdfsf");
  }
  else
  {
   $(birthday+"_msg").className="warning";
    return false;
  }
  
}

function SetBirdthdayselect(id,value)
{
   for (var i=0;i<$(id).options.length;i++)
   {
     if($(id).options[i].value==value)
     {
       $(id).options[i].selected=true;
       break;
     }
     
   }
}

function ShowMeiNotice(id)
{
	
    var ids="";
    var idtemp="";
   
     if(id==""||id==null)
      return false;
     
    try
    {
      var pos1=id.lastIndexOf("_");
      idtemp=id;
      //idtemp=id.substring(0,Pos1);
      //alert(idtemp+id);
    }
    catch(e)
    {
      idtemp=id
    }
    	
      var classnames="notice";
      var getvalue=extractHtmlText(Trim($(id).value));
      if(getvalue==""||getvalue==null)
         classnames="warning";
      else 
      {      
       if(!CheckViverMei(id))
           classnames="warning";
           else 
           classnames="notice";
       }
     // alert(idtemp);
      $(idtemp+"_msg").className=classnames;
      if(classnames=="warning")
        return false;              
}

function CheckViverMei(id)
{   
       if(id.toUpperCase().indexOf("USERID")>-1)
           return checkUserName($(id).value);
       else if(id.toUpperCase().indexOf("EMAIL")>-1)
        return checkMail($(id).value);
         else if(id.toUpperCase().indexOf("ZIPCODE")>-1)
        return CheckZipCode(id);
       else if(id.toUpperCase().indexOf("PASSWORD")>-1)
       { 
           
          if( checkUserPwd($(id).value))
          {
            
            if(id.toUpperCase().indexOf("TABLEKEY")>-1)
            {
             
             return isEqual(id,"PASSWORD");
            }
            return true;
            
           
          }
          else
          return false;
       }
       else if(id.toUpperCase().indexOf("TEL")>-1)
        return validatePhoneNumber($(id).value);
       else
       
       return true;
        
        
        
        
        
   
}

function CheckZipCode(values)
{
   
   
   var str = $(values).value;
    	if(str.length!=6) 
    	{
    	  $(values+"_msg").innerHTML="邮编长度为应为6位"
    	 return false;
    	}															
    	var patn1 =  /^[1-9]\d{5}$/;
    	if(!patn1.test(str) ) 
    	{
    	$(values+"_msg").innerHTML="邮编应为6位数字"
    	  return false;
    	}
    	return true; 

}

//检测新密码　
 function CheckNewPassword(password1,password2)
 {
   var passwordtemp1=$(password1).value;
   var passwordtemp2=$(password2).value;
   var classnames="notice";
       
   var succ=false;    
   
   //alert("ddd");
   if(Trim(passwordtemp1).length<6)
   {
      succ=false;
   }
   else if(Trim(passwordtemp1)!=Trim(passwordtemp2))
   {
     succ=false;
     $(password2+"_msg").innerHTML="两次输入的密码不一致!";
     $(password2).value="";
      }
   else 
   {
    succ=true;
    }
    
    if(succ)
    $(password2+"_msg").className="notice";
    else 
    $(password2+"_msg").className="warning";
    
    return succ;
    
   
 }
function checkUserPwd(values)
{
    	var str = values;
    	if(!checkByteLength(str,6,20)) return false;
    																
    	var patn1 =   /^[a-zA-Z0-9_]+$/;
    	if(!patn1.test(str) ) return false;
    	return true; 
}
	
function isEqual(objid1,objid2){
	    if(document.getElementById(objid1).value == document.getElementById(objid2).value){
	        return true;
    	}else{
	        return false;
	    }
	}
	
	function validateMobile(obj){
    	var str1 = obj.value;
    	var str = tot(str1); 
    	obj.value = str;
    	if(str.length > 16){
    	    return 1;
    	}
    	if(str.length == 0){
    	    return -1;
    	}
    	var patn = /^[0-9]+$/;
    	if(patn.test(str)) return 0;
    	   return 2; 	
	}
	function validateNumber(obj){
    	var str1 = obj.value;
    	var str = tot(str1); 
    	obj.value = str;
    	if(str.length == 0){
    	    return -1;
    	}
    	var patn = /^[0-9-\/]+$/;
    	if(!patn.test(str)) return 1;
    	return 0;
	}


function tot(mobnumber){                        
    	while(mobnumber.indexOf("０")!=-1){           
    		mobnumber = mobnumber.replace("０","0");        
    	}                                               
    	while(mobnumber.indexOf("１")!=-1){             
	    	mobnumber = mobnumber.replace("１","1");}       
    	while(mobnumber.indexOf("２")!=-1){             
	    	mobnumber = mobnumber.replace("２","2");}       
    	while(mobnumber.indexOf("３")!=-1){             
	    	mobnumber = mobnumber.replace("３","3");}       
    	while(mobnumber.indexOf("４")!=-1){             
	    	mobnumber = mobnumber.replace("４","4");}       
    	while(mobnumber.indexOf("５")!=-1){             
	    	mobnumber = mobnumber.replace("５","5");}       
    	while(mobnumber.indexOf("６")!=-1){             
	    	mobnumber = mobnumber.replace("６","6");}       
    	while(mobnumber.indexOf("７")!=-1){             
	    	mobnumber = mobnumber.replace("７","7");}       
    	while(mobnumber.indexOf("８")!=-1){             
	    	mobnumber = mobnumber.replace("８","8");}       
    	while(mobnumber.indexOf("９")!=-1){             
	    	mobnumber = mobnumber.replace("９","9");}       
    	return mobnumber;                               
	}	  
	function validatePhoneNumber(values){
     	var str = values;
     	str = tot(str); 
    	if(str.length == 0){
    	   return false;
    	}
    	
     
    	var patn = /^\s*[.0-9_-_-]{7,18}\s*$/;
    	if(!patn.test(str)) return false;
    	return true; 
	}
	

	
function ShowMeiAllNotice(focusArray)
{
 var aaa=false;

   var classnames="notice";
   //alert("ShowMeiAllNotice");
    for (i=0;i<focusArray.length;i++)
	{   
	//alert("focusArray.length");
	      var id=focusArray[i];	                    
          try
        {
           var pos1=id.lastIndexOf("_");        
            idtemp=id.substring(0,Pos1);         
        }
        catch(e)
        {
          idtemp=id       
        }  
          var classnames="notice";
          var getvalue=Trim(extractHtmlText($(id).value));
          if(getvalue==""||getvalue==null)
             classnames="warning";
          else 
          {   if(!CheckViverMei(id))
               classnames="warning";
               else 
               classnames="notice";
           }
           
          
          $(idtemp+"_msg").className=classnames;
          if(classnames=="warning")
          {
          
           try
           {
           $(id).focus();
           }
           catch(kkkkk)
           {
              $(idtemp+"_msg").className="warning";
           }
            return false;
            break;
            }
          else 
             aaa=true;
        
        
     if(! Validator.Validate("",2))
       return false;
	   
	}
	try
	{
	 //SetViverMessage(1);
	}
	catch(e)
	{}
	
	
	if(aaa)
	//alert( window.event.srcElement.form.name);
	{
	  window.event.srcElement.disabled=true;
	  window.event.srcElement.form.submit();
	  
	  }
	 // return false;
	 //if(aaa)
	
	 // return false;
     
    // return false;
    //return false;
return aaa;
	 
      //alert(id);
     
}



function focusFunc(id)
{
 alert("bb");
}




/******************************去除字符串的头尾空格******************************/
function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function



//判断是否为<DIV></DIV>包装下的空串
function isEmptyDiv(str) {
	var trim = Trim(str);
	if (trim == "")
		return true;
	var rep = /^<DIV>(&nbsp;<\/DIV><DIV>)*(&nbsp;)*<\/DIV>$/i;
	if (rep.test(trim)) {
		return true;
	}
	else
		return false;

}

/******************************DOM操作函数******************************/
function _ge(id){
	return document.getElementById(id);
}

function removeAllChild(el){
		var firstChild = el.firstChild;
		var curChild = firstChild;
		while(curChild != null){
			el.removeChild(curChild);	
			curChild = curChild.nextSibling;
		}
}

function insertAfter(parent, node, referenceNode) {
    parent.insertBefore(node, referenceNode.nextSibling);
}
function checkformatpicture(str)
{
  if(str.length>3)
  {
    var strss=str.substring(str.length-3,str.length).toUpperCase();
    if(strss=="JPG"||strss=="GIF"||strss=="PNG")
    return true;
    else 
    return false;
  }
  else
  return false;
  
}
/******************************字符串输入正确性检查******************************/
//检查输入是否包含半角和全角的单双引号、正反斜杠、尖括号
function containsIllegalChar(content) {
	var regi = /^(.*)['"‘“\/\\<>](.*)$/;
	if (regi.test(content))
		return true;
	else
		return false;
}


function testUrl(str){
	var illegalChar = /^(.*)['"‘“<>](.*)$/;
	if (illegalChar.test(str))
		return false;
	else
		return true;
}

function checkUserName(str) {
 // 	var patn =   /^[a-zA-Z]+[a-zA-Z0-9]+$/; 
    var patn =/^[\w\d]*$/; // ^\w+$
    	//alert(patn.test(str));
    	if(!checkByteLength(str,6,20)) return false;
    	if(!patn.test(str)){
        	return false;
	    }
	    return true;
}
function checkByteLength(str,minlen,maxlen) {
		if (str == null) return false;
		var l = str.length;
		var blen = 0;
		
		blen=str.length;
		if (blen > maxlen || blen < minlen) {
			return false;
		}
		return true;
	}      
function checkMail(str){
	var mail=/^(.+)@(.+)\.(.+)$/;
	if(!mail.test(str))
		return false;
	var illegalChar = /^(.*)['"‘“\/\\<>](.*)$/;
	if (illegalChar.test(str))
		return false;
	else
		return true;
}

//检查日期格式（xxxx-xx-xx）
function checkDateFormat(str) {
	var format = /^\d{4}\-\d{2}\-\d{2}$/;
	if (format.test(str)) 
		return true;
	else 
		return false;
}

//检查生日是否正确，应该小于今天
function checkBirthday(str) {
	var today = new Date();
	var barray = str.split(new RegExp("-", "g"));
	var birthday = new Date(barray[0], barray[1] - 1 , barray[2]);
	if (parseInt(barray[0]) < 1900) {
		return -1;
	}
	if (birthday.getTime() > today.getTime()) {
		return 1;
	}
	else if (birthday.getFullYear() < 1900) {
		return -1;
	}
	else {
		return 0;
	}
}

//从html代码中提取文本
function extractHtmlText(content) {
	var regstr = new String("<[^<>]*>");  
	var reg1 = new RegExp(regstr,"ig");			
	if(reg1.test(content))
	{
		content = content.replace(reg1,"");
	}	
	regstr = new String("(&nbsp;)|(&lt;)|(&gt;)|(&amp;)|(&quot;)");  
	reg1 = new RegExp(regstr,"ig");	
	if(reg1.test(content))
	{
		content = content.replace(reg1,"");
	}		
	return content;
}

function convertStr(str){
	if(str == null)
		return '&nbsp;';
	str=Trim(str);
	if(str=='')
		str='&nbsp;';		
	return str;	
}

//把回车都替换成<br>标记
function replaceLineBreak(str) {
	return str.replace("\n", "<br>");
}

//textarea客户端限制最大输入字符数,用法 onkeyup="textareaLimit(this, 250)"
function textareaLimit(field, maxlen){
	if (field.value.length > maxlen) {		
		field.value = field.value.substring(0, maxlen);
		alert("超过最大字数限制" + maxlen +"个! ");
	}
}
function textLimit(text, maxlen){
	if (text.length > maxlen) {		
		text = text.substring(0, maxlen);
		alert("超过最大字数限制" + maxlen +"个! ");
	}
}

//将字符串中的换行转换成页面显示所需要的<br>换行,使用方法str.nlToBr()
String.prototype.nlToBr=function(){return this.trim().nl2br();}
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"");};
String.prototype.nl2br=function(){return this.split("\n").join("<br />\n");};
String.prototype.trimSQ= function(){return this.replace("&#39;","\\\'");};//把esacpe后的单引号转化为转义的单引号
String.prototype.escape=function(){return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g,"&#34;").replace(/'/g,"&#39;");};
String.prototype.escape_freemark=function(){return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g,"&quot;");};
String.prototype.unescape_freemark=function(){return this.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g,"\"");};

//和trimpath冲突，故注掉
//String.prototype.replace=function(_7,_8){return this.split(_7).join(_8);};

//搜索数组
function searchList(el, list){
	var i=0;
	for(i=0; i<list.length; i++){
		if(el == list[i]){
			return true;
		}
	}
	
	return false;
}
//去掉数组中相同的元素，返回去重后的数组
function removeSameEl(list){
	var newList = new Array();
	var i;
	var el;
	
	for(i=0; i<list.length; i++){
		el = list[i];
		if(el != null){
			var data;
			if(!searchList(el, newList)){
				newList.push(el);
			}	
		}
	}
	
	return newList;
}

//在数组指定位置插入元素，position<0插入最前面，大于数组长度插入最后面。前面元素不变，后面的元素后移
function insertShiftAt(list, el, position){
	if(position < 0){
		position = 0;
	}else if(position > list.length){
		positon = list.length;
	}
	var prevList
	var nextList;
	for(i=list.length; i>position ; i--){
		list[i] = list[i-1];
	}
	list[position] = el;
}

//"<div  id=\"ViverMeimessageForYou\" style=\"display:none; position:absolute; width:100px;\" class=warning>aaa</div>")
var Messagestringdiv="<div id=\"ViverMeimessageForYou\" class=loadings style=\"position:absolute;display:none; left: expression((body.clientWidth-200)/2);expression((body.clientHeight-30)/2); width:200px ;height:20px; font-weight:bold \"> ";
 
Messagestringdiv +="</div>";

document.write(Messagestringdiv);


function CenterDivToWholeWindow(id )

{

var the_div = document.getElementById("ViverMeimessageForYou");

var w_width = document.body.clientWidth;
var w_height = document.body.clientHeight;


the_div.style.top = document.documentElement.scrollTop+320;

}



function ShowViverMeiWarn(id)
{ 
  if(id==1)
   $("ViverMeimessageForYou").style.display="block";
  else  
  { 
   $("ViverMeimessageForYou").style.display="none";
   //tttt=setInterval("setalpha()",1000);
  //alert("fd'fdf");
  // clearInteval(tttt);

      }
}



function SetViverMessage(id)
{
  var content="";
  if (id==1)
      content="数据提交中,请稍候...";
   else if (id==2)
      content="已成功保存...";
   else if (id==3)
     content="保存失败...";
   else if (id==4)
      content="模块加载中，请稍候...";
      else if (id==5)
      content="您输入的验证码不正确...";
       else if (id==6)
      content="您输入的用户名不可以为空";
        else if (id==7)
      content="您输入的用户名已经被注册";
          else if (id==8)
      content="您输入的用户名可以使用";
         else if (id==9)
      content="您输入的用户名密码不正确";
         
      CenterDivToWholeWindow(id);
$("ViverMeimessageForYou").innerHTML=content;
 
 
 if(id!=1)
 {
  $("ViverMeimessageForYou").style.display="block";
   var timeouts=setTimeout("ShowViverMeiWarn(" +id + ")",1500);
   //clearTimeout(timeouts);
  }
else
{
 $("ViverMeimessageForYou").style.display="block";
}

}
function ViverShowMessage( id)
{
   
  // movePageShow();
 
  
  
}




Validator = {
 Require : /.+/,
 Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
 Phone : /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/,
// Mobile : /^1[35][4-9]\d{8}(,1[35][4-9]\d{8})*$/,
 // /^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/,
 Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
 IdCard : "this.IsIdCard(value)",
 Currency : /^\d+(\.\d+)?$/,
 Number : /^\d+$/,
 Zip : /^[1-9]\d{5}$/,
 QQ : /^[1-9]\d{4,8}$/,
 Integer : /^[-\+]?\d+$/,
 Double : /^[-\+]?\d+(\.\d+)?$/,
 English : /^[A-Za-z]+$/,
 Chinese :  /^[\u0391-\uFFE5]+$/,
 Username : /^[a-z]\w{3,}$/i,
 UnSafe : /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,
 IsSafe : function(str){return !this.UnSafe.test(str);},
 SafeString : "this.IsSafe(value)",
 Filter : "this.DoFilter(value, getAttribute('accept'))",
 Limit : "this.limit(value.length,getAttribute('min'),  getAttribute('max'))",
 LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",
 Date : "this.IsDate(value, getAttribute('min'), getAttribute('format'))",
 Repeat : "value == document.getElementsByName(getAttribute('to'))[0].value",
 Range : "getAttribute('min') < (value|0) && (value|0) < getAttribute('max')",
 Compare : "this.compare(value,getAttribute('operator'),getAttribute('to'))",
 Custom : "this.Exec(value, getAttribute('regexp'))",
 Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
 ErrorItem : [document.forms[0]],
 ErrorMessage : ["以下原因导致提交失败：\t\t\t\t"],
 Validate : function(theForm, mode){
  var obj = theForm ;
  if (obj=="")
   obj=document.forms[0];
  
  //alert(obj.name);
  var count = obj.elements.length;
  this.ErrorMessage.length = 1;
  this.ErrorItem.length = 1;
  this.ErrorItem[0] = obj;
  for(var i=0;i<count;i++){
   with(obj.elements[i]){
   //alert(obj.elements[i].style.display);
    var _dataType = getAttribute("alt");
    if(typeof(_dataType) == "object" || typeof(this[_dataType]) == "undefined")  continue;
    this.ClearState(obj.elements[i]);
    if(getAttribute("require") == "false" && value == "") continue;
    switch(_dataType){
     case "IdCard" :
     case "Date" :
     case "Repeat" :
     case "Range" :
     case "Compare" :
     case "Custom" :
     case "Group" : 
     case "Limit" :
     case "LimitB" :
     case "SafeString" :
     case "Filter" :
      if(!eval(this[_dataType])) {
       this.AddError(i, getAttribute("title"));
      }
      break;
     default :
      if(!this[_dataType].test(value)){
       this.AddError(i, getAttribute("title"));
      }
      break;
    }
   }
  }
  if(this.ErrorMessage.length > 1){
   mode = mode || 1;
   var errCount = this.ErrorItem.length;
   switch(mode){
   case 2 :
    for(var i=1;i<errCount;i++)
     this.ErrorItem[i].style.color = "red";
   case 1 :
    alert(this.ErrorMessage.join("\n"));
    this.ErrorItem[1].focus();
    break;
   case 3 :
    for(var i=1;i<errCount;i++){
    try{
     var span = document.createElement("SPAN");
     span.id = "__ErrorMessagePanel";
     span.style.color = "red";
     this.ErrorItem[i].parentNode.appendChild(span);
     span.innerHTML = this.ErrorMessage[i].replace(/\d+:/,"*");
     }
     catch(e){alert(e.description);}
    }
    this.ErrorItem[1].focus();
    break;
   default :
    alert(this.ErrorMessage.join("\n"));
    break;
   }
   return false;
  }
  return true;
 },
 limit : function(len,min, max){
  min = min || 0;
  max = max || Number.MAX_VALUE;
  return min <= len && len <= max;
 },
 LenB : function(str){
  return str.replace(/[^\x00-\xff]/g,"**").length;
 },
 ClearState : function(elem){
  with(elem){
   if(style.color == "red")
    style.color = "";
   var lastNode = parentNode.childNodes[parentNode.childNodes.length-1];
   if(lastNode.id == "__ErrorMessagePanel")
    parentNode.removeChild(lastNode);
  }
 },
 AddError : function(index, str){
  this.ErrorItem[this.ErrorItem.length] = this.ErrorItem[0].elements[index];
  this.ErrorMessage[this.ErrorMessage.length] = this.ErrorMessage.length + ":" + str;
 },
 Exec : function(op, reg){
  return new RegExp(reg,"g").test(op);
 },
 compare : function(op1,operator,op2){
  switch (operator) {
   case "NotEqual":
    return (op1 != op2);
   case "GreaterThan":
    return (op1 > op2);
   case "GreaterThanEqual":
    return (op1 >= op2);
   case "LessThan":
    return (op1 < op2);
   case "LessThanEqual":
    return (op1 <= op2);
   default:
    return (op1 == op2);            
  }
 },
 MustChecked : function(name, min, max){
  var groups = document.getElementsByName(name);
  var hasChecked = 0;
  min = min || 1;
  max = max || groups.length;
  for(var i=groups.length-1;i>=0;i--)
   if(groups[i].checked) hasChecked++;
  return min <= hasChecked && hasChecked <= max;
 },
 DoFilter : function(input, filter){
return new RegExp("^.+\.(?=EXT)(EXT)$".replace(/EXT/g, filter.split(/\s*,\s*/).join("|")), "gi").test(input);
 },
 IsIdCard : function(number){
  var date, Ai;
  var verify = "10x98765432";
  var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  var area = ['','','','','','','','','','','','北京','天津','河北','山西','内蒙古','','','','','','辽宁','吉林','黑龙江','','','','','','','','上海','江苏','浙江','安微','福建','江西','山东','','','','河南','湖北','湖南','广东','广西','海南','','','','重庆','四川','贵州','云南','西藏','','','','','','','陕西','甘肃','青海','宁夏','新疆','','','','','','台湾','','','','','','','','','','香港','澳门','','','','','','','','','国外'];
  var re = number.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})(\d{3}[x\d])))$/i);
  if(re == null) return false;
  if(re[1] >= area.length || area[re[1]] == "") return false;
  if(re[2].length == 12){
   Ai = number.substr(0, 17);
   date = [re[9], re[10], re[11]].join("-");
  }
  else{
   Ai = number.substr(0, 6) + "19" + number.substr(6);
   date = ["19" + re[4], re[5], re[6]].join("-");
  }
  if(!this.IsDate(date, "ymd")) return false;
  var sum = 0;
  for(var i = 0;i<=16;i++){
   sum += Ai.charAt(i) * Wi[i];
  }
  Ai +=  verify.charAt(sum%11);
  return (number.length ==15 || number.length == 18 && number == Ai);
 },
 IsDate : function(op, formatString){
  formatString = formatString || "ymd";
  var m, year, month, day;
  switch(formatString){
   case "ymd" :
    m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));
    if(m == null ) return false;
    day = m[6];
    month = m[5]*1;
    year =  (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
    break;
   case "dmy" :
    m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));
    if(m == null ) return false;
    day = m[1];
    month = m[3]*1;
    year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
    break;
   default :
    break;
  }
  if(!parseInt(month)) return false;
  month = month==0 ?12:month;
  var date = new Date(year, month-1, day);
        return (typeof(date) == "object" && year == date.getFullYear() && month == (date.getMonth()+1) && day == date.getDate());
  function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
 }
 }
 
///////////////////////////////////////////

function validateForm(){
	var str_value = Trim($F("temptkeyword3"));
	if(str_value == "" || str_value.length == 0){
		alert("邀请码的值不能为空!");
		$F("temptkeyword3").value = "";
		$("temptkeyword3").focus();
		return false;
	}
	
	str_value = Trim($F("userid"));
	if(str_value == "" || str_value.length == 0){
		alert("用户名的值不能为空!");
		$F("userid").value = "";
		$("userid").focus();
		return false;
	}else if(str_value.length < 6 || str_value.length > 12){
		alert("用户名的长度在6~12位之间!");
		$F("userid").value = "";
		$("userid").focus();
		return false;
	}else{
		if(checkUserName(str_value) == false){
			alert("用户名的输入格式不正确!");
			$F("userid").value = "";
			$("userid").focus();
			return false;
		}
	}
	
	str_value = Trim($F("password"));
	var patn1 =   /^[a-zA-Z0-9_]+$/;
	if(!checkByteLength(str_value,6,20)){
		alert("用户密码的长度在6~12位之间!");
		$F("password").value = "";
		$("password").focus();
		return false;
	}
	if(!patn1.test(str_value) ){
		alert("用户密码的的输入格式不正确!");
		$F("password").value = "";
		$("password").focus();
		return false;
	}
	
	str_value = Trim($F("tel2"));
	if(str_value.length == "" || str_value.length == 0){
		alert("重复密码的值不能为空!");
		$F("tel2").value = "";
		$("tel2").focus();
		return false;
	}else{
		if($("tel2").value!=$("password").value)
       	{
         alert("您输入的密码不一致,请重新输入!");
         return false;
       	}
	}
	
	str_value = Trim($F("company_name"));
	if(str_value.length == "" || str_value.length == 0){
		alert("公司名称不能为空!");
		$("company_name").focus();
		return false;
	}
	
	str_value = Trim($F("contact_people"));
	if(str_value.length == "" || str_value.length == 0){
		alert("法人代表不能为空!");
		$("contact_people").focus();
		return false;
	}
	
	str_value = Trim($F("address"));
	if(str_value.length == "" || str_value.length == 0){
		alert("公司地址不能为空!");
		$("address").focus();
		return false;
	}
	
	str_value = Trim($F("real_name"));
	if(str_value.length == "" || str_value.length == 0){
		alert("联系人不能为空!");
		$("real_name").focus();
		return false;
	}
	
	str_value = Trim($F("tel"));
	if(str_value.length == "" || str_value.length == 0){
		alert("电话号码不能为空!");
		$("tel").focus();
		return false;
	}else{
		if(!validatePhoneNumber(str_value)){
			alert("电话号码的格式不正确!");
			$("tel").focus();
			return false;
		}
	}
	
	str_value = Trim($F("company_email"));
	if(str_value.length == "" || str_value.length == 0){
		alert("邮件地址不能为空!");
		$("company_email").focus();
		return false;
	}else if(!checkMail(str_value)){
		alert("邮件地址格式不正确!");
		$("company_email").focus();
		return false;
	}
	
	str_value = Trim($F("bigclass"));
	if(str_value.length == "" || str_value.length == 0 || str_value == '0'){
		alert("行业类别1不能为空,请选择行业类别!");
		$("bigclass").focus();
		return false;
	}
	
	str_value = Trim($F("smallclass"));
	if(str_value.length == "" || str_value.length == 0 || str_value == '0'){
		alert("行业类别2不能为空,请选择行业类别!");
		$("smallclass").focus();
		return false;
	}
	
	str_value = Trim($F("province"));
	if(str_value.length == "" || str_value.length == 0 || str_value == '0'){
		alert("所在省不能为空,请选择所在省!");
		$("province").focus();
		return false;
	}
	
	str_value = Trim($F("city"));
	if(str_value.length == "" || str_value.length == 0 || str_value == '0'){
		alert("所在省不能为空,请选择所在省!");
		$("city").focus();
		return false;
	}
	
	str_value = Trim($F("companyinfo"));
	if(str_value.length == "" || str_value.length == 0 ){
		alert("公司介绍不能为空!");
		$("companyinfo").focus();
		return false;
	}
	
	str_value = Trim($F("productinfo"));
	if(str_value.length == "" || str_value.length == 0 ){
		alert("产品描述不能为空!");
		$("productinfo").focus();
		return false;
	}
	
	
	
	str_value = Trim($F("validatecode"));
	if(str_value.length == "" || str_value.length == 0 ){
		alert("验证码不能为空!");
		$("validatecode").focus();
		return false;
	}
	
	return true;
}

function submitForm(){
	if(validateForm()){
		window.event.srcElement.disabled=true;
	  	window.event.srcElement.form.submit();
	}
}

function userValidateLevel(){

	str_value = Trim($F("company_name"));
	if(str_value.length == "" || str_value.length == 0){
		alert("公司名称不能为空!");
		$("company_name").focus();
		return false;
	}
	
	str_value = Trim($F("contact_people"));
	if(str_value.length == "" || str_value.length == 0){
		alert("法人代表不能为空!");
		$("contact_people").focus();
		return false;
	}
	
	str_value = Trim($F("address"));
	if(str_value.length == "" || str_value.length == 0){
		alert("公司地址不能为空!");
		$("address").focus();
		return false;
	}
	
	str_value = Trim($F("real_name"));
	if(str_value.length == "" || str_value.length == 0){
		alert("联系人不能为空!");
		$("real_name").focus();
		return false;
	}
	
	str_value = Trim($F("tel"));
	if(str_value.length == "" || str_value.length == 0){
		alert("电话号码不能为空!");
		$("tel").focus();
		return false;
	}else{
		if(!validatePhoneNumber(str_value)){
			alert("电话号码的格式不正确!");
			$("tel").focus();
			return false;
		}
	}
	
	str_value = Trim($F("company_email"));
	if(str_value.length == "" || str_value.length == 0){
		alert("邮件地址不能为空!");
		$("company_email").focus();
		return false;
	}else if(!checkMail(str_value)){
		alert("邮件地址格式不正确!");
		$("company_email").focus();
		return false;
	}
	
	str_value = Trim($F("bigclass"));
	if(str_value.length == "" || str_value.length == 0 || str_value == '0'){
		alert("行业类别1不能为空,请选择行业类别!");
		$("bigclass").focus();
		return false;
	}
	
	str_value = Trim($F("smallclass"));
	if(str_value.length == "" || str_value.length == 0 || str_value == '0'){
		alert("行业类别2不能为空,请选择行业类别!");
		$("smallclass").focus();
		return false;
	}
	
	str_value = Trim($F("province"));
	if(str_value.length == "" || str_value.length == 0 || str_value == '0'){
		alert("所在省不能为空,请选择所在省!");
		$("province").focus();
		return false;
	}
	
	str_value = Trim($F("city"));
	if(str_value.length == "" || str_value.length == 0 || str_value == '0'){
		alert("所在省不能为空,请选择所在省!");
		$("city").focus();
		return false;
	}
	
	str_value = Trim($F("companyinfo"));
	if(str_value.length == "" || str_value.length == 0 ){
		alert("公司介绍不能为空!");
		$("companyinfo").focus();
		return false;
	}
	
	str_value = Trim($F("productinfo"));
	if(str_value.length == "" || str_value.length == 0 ){
		alert("产品描述不能为空!");
		$("productinfo").focus();
		return false;
	}
	
	
	
	str_value = Trim($F("validatecode"));
	if(str_value.length == "" || str_value.length == 0 ){
		alert("验证码不能为空!");
		$("validatecode").focus();
		return false;
	}
	
	var userRole = document.all.igree;
    for(var i=0;i<userRole.length;i++){
         if(userRole[0].checked == false){
            alert("您要选择同意服务条款后才可升级!");
			return false;
         }
     }  
	
	return true;
}




