
function formSubmit(method,action){
   if(method != ""){
      document.all['method'].value = method;
   }
   if(action != ""){
      document.forms[0].action = action;
   }
   //alert(document.all['method'].value+"==="+document.forms[0].action);
   //   if(document.forms.length > 1){
     document.forms[0].submit();
   //}
}
function searchSubmit(search){
   //alert("search");
   document.all['search'].value = search;
   //if(document.forms.length > 1){
     document.forms[0].submit();
   //}

}


function formatTime(value){
    //alert("333"+value+"3333");
    value = value.trim();
    //alert("333"+value+"3333");
    if(value.indexOf(":")>0){
        str = value.split(":");
        sI = str[0]+str[1]+"";
        if(str[0].length!=2){
           return false;
        }else if(sI>2400){
           return false;
        }else{
           return true;
        }
    }else{
        return false;
    }
}

function formatDate(value){
    if(value.indexOf("-")>0){
       str = value.split("-");
       //alert("-");
       for(i=0; i<str.length; i++){
          //alert(str[i]);
          if(isNaN(str[i])){
              return false;
          }
       }
       return true;
    }else{
       if(isNaN(value)){
           return false;
       }
       return true;
    }

}
function formatDateTime(value){
	    if(value==""){
	        return true;
	    }else{
	        var datetime = value.split(" ");
	        if(datetime.length==2){
	        	var date1 = datetime[0].split("-");
	            var time1 = datetime[1].split(":");
	            if(date1.length==3){
	            if(date1[0].length==4 && date1[1].length==2 && date1[2].length==2){
	                if(isNaN(date1[0])) return false;
	                if(isNaN(date1[1]) || date1[1]>12) return false;
	                if(isNaN(date1[2]) || date1[2]>31) return false;
	            }else{
	                return false;
	            }
	            }else{
	                return false;
	            }
	            if(time1.length==2){
	            if(time1[0].length==2 && time1[1].length==2){
	                if((time1[0]+time1[1]+"")>2400) return false;
	            }else{
	                return false;
	            }
	            return true;
	            }else{
	               return false;
	            }
	        }else{
	           return false;
	        }

	    }

	}

function formatInteger(value){
    if(isNaN(value)){
        return false;
    }
    return true;
}
function getCheckBoxArray(element){
    var values = new Array();
    if(null == element){
        //alert("????????????????????");
    }else if(null == element.length){
        if(element.checked){
            values.push(element.value);
        }
    }else{
        for(i=0; i<element.length; i++){
            if(element[i].checked){
                 values.push(element[i].value);
            }
        }
    }
    return values;
}

function showMsg(msg){
   //alert("test showMsg");
   if(msg!=""){
      alert(msg);
   }
}
function select(element,flag){
    if(null == element){
        return;
    }else if(null == element.length){
        element.checked = flag;
        return;
    }else{
        for(i=0; i<element.length; i++){
           element[i].checked = flag;
        }
    }

}

function newOpen(theURL,theTitle,w,h) {
    lef=(screen.width-w)/2;
	to=(screen.height-h-100)/2;
	window.open(theURL, "", "width="+w+", height="+h+",left="+lef+",top="+to+",toolbar=no")
}


//************************************************
//检查电话号码  biao add
function NumRegCheck(obj)
 {
  var uplimit = obj.checkrule.split(",")[0];
  var downlimit = obj.checkrule.split(",")[1];
  var reg = "";
  if (downlimit == null)
   {
     reg = eval("/^[0-9]{"+uplimit+"}$/");
   }
  else
   {
     reg = eval("/^[0-9]{"+uplimit+","+downlimit+"}$/");
   }
  var str = obj.value;
  var flag = reg.test(str);
  return flag;
 }
//************************************************



function checkEmail(email) {
    if (email == "") return false;
    var myReg = /^[_\-\.a-zA-Z0-9]+@([_\-a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,3}$/;
    if (myReg.test(email) == false) {
        return false;
    }
    return true;
}

//登陆名
function isLoginName(login){
    var login = trim(login);
    if (login == "") return false;
    var myReg = /^([a-zA-z_]{1})([w]*)$/;
    if (myReg.test(login) == false) {
        return false;
    }
    return true;
}

//检查身份证号
function isIdCardNo(idcard)
{
        var  area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}

	var  idcard,Y,JYM;
	var  S,M;
	var  idcard_array  =  new  Array();
	idcard_array  =  idcard.split("");
	//地区检验
	if(area[parseInt(idcard.substr(0,2))]==null)  return  false;
	//身份号码位数及格式检验
	switch(idcard.length){
		case  15:
		if  (  (parseInt(idcard.substr(6,2))+1900)  %  4  ==  0  ||  ((parseInt(idcard.substr(6,2))+1900)  %  100  ==  0  &&  (parseInt(idcard.substr(6,2))+1900)  %  4  ==  0  )){
		ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性
		}  else  {
		ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性
		}
		if(ereg.test(idcard))  return  true;
		else  return  false;
		break;
		case  18:
		//18位身份号码检测
		//出生日期的合法性检查
		//闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
		//平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
		if  (  parseInt(idcard.substr(6,4))  %  4  ==  0  ||  (parseInt(idcard.substr(6,4))  %  100  ==  0  &&  parseInt(idcard.substr(6,4))%4  ==  0  )){
		ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式
		}  else  {
		ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式
		}
		if(ereg.test(idcard)){//测试出生日期的合法性
		//计算校验位
		S  =  (parseInt(idcard_array[0])  +  parseInt(idcard_array[10]))  *  7
		+  (parseInt(idcard_array[1])  +  parseInt(idcard_array[11]))  *  9
		+  (parseInt(idcard_array[2])  +  parseInt(idcard_array[12]))  *  10
		+  (parseInt(idcard_array[3])  +  parseInt(idcard_array[13]))  *  5
		+  (parseInt(idcard_array[4])  +  parseInt(idcard_array[14]))  *  8
		+  (parseInt(idcard_array[5])  +  parseInt(idcard_array[15]))  *  4
		+  (parseInt(idcard_array[6])  +  parseInt(idcard_array[16]))  *  2
		+  parseInt(idcard_array[7])  *  1
		+  parseInt(idcard_array[8])  *  6
		+  parseInt(idcard_array[9])  *  3  ;
		Y  =  S  %  11;
		M  =  "F";
		JYM  =  "10X98765432";
		M  =  JYM.substr(Y,1);//判断校验位
		if(M  ==  idcard_array[17])  return  true;  //检测ID的校验位
		else  return  false;
		}
		else  return  false;
		break;
		default:
		return  false;
		break;
	}
}

function IsBirthday( BYear, BMonth, BDay )
{
	if ( BYear < 1901 || BYear > 2006 || BMonth < 1 || BMonth > 12 || BDay < 1 || BDay > 31 )
		return false;

	if ( BMonth == 2 && BDay > 29 )
		return false;

	if ( BMonth == 2 && BYear % 4 !=0 && BDay == 29 )
		return false;

	if (( BMonth == 4 || BMonth == 6 || BMonth == 9 || BMonth == 11 ) && BDay == 31 )
		return false;

    return true;
}

function HaveNoNumber ( Number )
 {
 Text = "1234567890";

 for ( i = 0; i <= Number.length - 1; i++ )
  {
  Char = Number.charAt ( i );
  Index = Text.indexOf ( Char );

  if ( Index == -1 )
   return true;
  }

 return false;
 }

// 手机

function isMobileFormatValid(mobile) {
	if (mobile.length != 11 ) {
		return false;
	}
		if (mobile.substr(0,2) != '13'&&mobile.substr(0,2) != '15') {
		return false;
	}
        if (HaveNoNumber(mobile)) {
            return false;
	}
	return true;
}

String.prototype.lTrim=function(){return this.replace(/^\s*/,"");};
String.prototype.rTrim=function(){return this.replace(/\s*$/,"");};
String.prototype.trim=function(){return this.rTrim().lTrim();};

function filerString(str , length){
    if( str.length > length)
        document.write(str.substring(0,length)+"...");
    else
        document.write(str);
}

function rtnString(str ,length){
    if( str.length > length)
        return str.substring(1,length)+"..";
    return str;
}

function getByteLength(string ){

    return string.replace(/[^\x00-\xff]/g, "**").length
}

function outVocation(vocation){
        if (vocation == '') {
            return ;
        }
        var list = ['','网吧','软件店','批发商','零售商','书店','超市','电子商务','声讯台','邮政','其他'];
        document.write(list[vocation]);
}

function outStatus(status){
        if (status == '') {
            return ;
        }
        var list = ['申 请','启 用','禁 用','启用并验证需IP'];
        document.write(list[status]);
}
function outGame(gameId){
    if(gameId == ''){
        return ;
    }
    if(gameId == 1)
       document.write('街头篮球');
    if(gameId == 11)
       document.write('魔法飞球');
    if(gameId == 2)
       document.write('蒸汽幻想');
    if(gameId == 12)
       document.write('拍拍部落');
    if(gameId == 20)
    	document.write('露娜');
    return;
}

function outSystem(sysid){
    var type = sysid;

    if(sysid == 0)
       type = '全部' ;
    if(sysid == 1)
       type = '篮球' ;
    if(sysid == 20)
       type = '露娜' ;
    document.write(type);
}

function outAgentType(agentType){
    var type='';

    if(agentType == 1)
       type = '总 代' ;
    if(agentType == 3)
       type = '经销商' ;
    if(agentType == 8)
       type = '直销商' ;
    document.write(type);
}

function outRelation(relation){
    if (relation == '') {
        return ;
    }
    var list = ['','大于','大于等于','小于','小于等于','等于'];
    document.write(list[relation]);
}

//字符在 32 到 127 ascii 之间
function errorAscii(pass){
    for (i=0;i<pass.length;i++)
        if (pass.charCodeAt(i)<32 || pass.charCodeAt(i)>127)
            return true;
    return false;
}

//返回真为通过，返回假为不通过
function checkIP(ip)
{
   var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/; //匹配IP地址的正则表达式
   if(re.test(ip))
   {
       if( RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256)
            return true;
   }
   //alert("请输入合法的计算机IP地址");
   return false;
}

function outCategory(categoryId){
        if (categoryId == '') {
            return ;
        }
        var list = ['','系统使用咨询','在线卡转帐问题','一卡通政策咨询','给系统的建议','其他问题咨询'];
        document.write(list[categoryId]);
}
