var defaultEmptyOK = false
var decimalPointDelimiter = "."
var daysInMonth = new Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function isFloat (s)
{   
    var i;
    var seenDecimalPoint = false;
    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }
    return true;
}

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function isInteger (s)
{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }
    return true;
}
function isSignedInteger (s)
{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}
function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}
function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}
//
function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);
    if (!isInteger(s, false)) return false;
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}
function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}
//
function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}
function daysInFebruary (year)
{   
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}


function isDate (year, month, day)
{   
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}



 
//是否为空
function notBlank(str) {
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) != " ")
			return true
	}
	return false
}

//判断是否全为空格(包括空)
function isAllBlank(str)
{
	return !notBlank(str);
}
function notArrBlank(pArry) {
  var result = true;
  if(typeof pArry.length =='undefined') 	
  {
 		if (!notBlank(pArry.value))
  		{
  			result= false;						
		}	  		
  }
  for (var i=0; i < pArry.length; i=i+1)
  {
  		if (!notBlank(pArry[i].value))
  			result= false						
  }
  if(!result)
  {
  		alert('请输入数量');	
  }
  return result;
}

//判断是否一个数字的数组
function isNumArr(pArry) 
{
  var result = false;
  if(typeof pArry.length =='undefined') 	
  {
 		if (isNaN(pArry.value))
  		{
  			result= false;						
		}	  		
  }
  for (var i=0; i < pArry.length; i=i+1)
  {
  	if (isNaN(pArry[i].value))
  		result= false						
	}
	return result;
}

//选中
function hasSelectCheckBox(pArry) {
	if(typeof pArry.length =='undefined') 
	{
		if(!pArry.checked) 
		{
			alert("请选中要操作的条目!");	
			return false;
		}
		return true;
	}
  	for (var i=0; i < pArry.length; i=i+1)
  	{
	  	if (pArry[i].checked)
	  	{
	  		
	  		return true;				
	  	}		
	}
	alert("请选中要操作的条目!");
	return false;
}

//得到第一个被选中的checkBox的value属性值
function getFirstValue(pArry)
{
	if(typeof pArry.length =='undefined') 
	{
		return pArry.value;
	}
  	for (var i=0; i < pArry.length; i=i+1)
  	{
	  	if (pArry[i].checked)
	  	{
	  		return pArry[i].value;				
	  	}		
	}
}
//判断一个YYYY-MM-DD格式的串是否合法日期
function isDate2(inDate)
{
	var date1 = inDate;
	if(inDate.indexOf("-")!=-1)
			nameList = inDate.split("-");
	else
			nameList = inDate.split("/");
				
	if(nameList.length !=2 && isDate1(date1)) return true;

	if(nameList.length != 2) return false;
	if(!isYear(nameList[0]) || !isMonth(nameList[1]))	return false;
	return true;
}

function isDate1(inDate)
{
	//alert('in isDate1');
	validity = true;
	
	if(inDate.indexOf("-")!=-1)
			nameList = inDate.split("-");
	else
			nameList = inDate.split("/");
	if ( nameList.length != 3){
		validity = false;			
		return validity;
	}

	var sss ="0";
	if(nameList[1].charCodeAt(0) == sss.charCodeAt(0)) nameList[1]=nameList[1].substr(1);
	if(nameList[2].charCodeAt(0) == sss.charCodeAt(0)) nameList[2]=nameList[2].substr(1);
			
	
	if (!isDate(nameList[0],nameList[1],nameList[2])){
		validity = false;
		return validity;	
	}
	
	return validity;
}

function notArrFloat(pArry) {
  for (var i=0; i < pArry.length; i=i+1)
  	{
  	if (!isFloat(pArry[i].value))
  		return false						
	}
	return true
}	

function isArrInteger(pArry) {
  var result = true;
  if(typeof pArry.length =='undefined') 	
  {
 		if (!isInteger(pArry.value))
  		{
  			result= false;						
		}	  		
  }	
  for (var i=0; i < pArry.length; i=i+1)
  {
  	if (!isInteger(pArry[i].value))
  		result= false;						
  }
  if(!result)
  {
  		alert('输入数量须为整数!');	
  }  
  return result;
}


function trim()
{
	s = this;
	while(s.charCodeAt(0) == 32) //前删除空格
	{
		s = s.substr(1);	
	}
	var len = s.length;
	while(s.charCodeAt(len-1) ==32) //后删除空格
	{
		s = s.substr(0,s.length-1);
	}
	return s;
}

String.prototype.trim = trim;  //重载一个trim方法

function equals(ps2)
{
	var ps1 = this;
	if(ps1.length != ps2.length) return false;
	for(var i=0;i<ps1.length;i++)
	{
		//alert(ps1.charCodeAt(i) == ps2.charCodeAt(i));
		if(ps1.charCodeAt(i) != ps2.charCodeAt(i) ) return false;
	}
	return true;
}
String.prototype.equals = equals;  //重载一个equals方法

function getFirstSelected(pArry)
{
	if(typeof pArry.length =='undefined') 
	{
		return pArry.value;
	}
  	for (var i=0; i < pArry.length; i=i+1)
  	{
	  	if (pArry[i].checked)
	  	{
	  		
	  		return pArry[i].value;				
	  	}		
	}
}

function chkNull(els){
	for (i=0;i<els.length;i++){
	  	if((els[i].className=="text" ||els[i].className=="order_txtctrl") && els[i].notnull){
	  		//var val=els[i].value;
	  		if (els[i].notnull=="true" && els[i].value.trim()==""){
	  			alert('对不起，' + els[i].chinese + '内容不能为空!');
	  			els[i].focus();
	  			return false;
	  		}
	  	}
	}
	return true;
}
function addzero(str,len){
	if (str==null || str.trim()==""){
		for (var mm=0;mm<len;mm++) str +="0";
	}else{
		for (var nn=str.length;nn<len;nn++){
			str ="0"+str;
		}
	}
	return str;
}



var lastNick = "";
//	用户昵称检测
function checkNick()
{
	var nick = document.mform.nickname.value;
	if (nick == "")
	{
		alert("输入登录名");
    	document.mform.elements['nickname'].value="";
    	document.mform.elements['nickname'].focus();
    	return false;
	}
	if(!isUserid(nick)){
  		document.mform.nickname.focus();
		return false;
	}
	if (nick == lastNick)
	{
		return false;
	}
	lastNick = nick;
	document.checkNickForm.TPL_NICK.value = nick;
	document.all("usefulMsg").innerText = "检测中，请稍等..."
	document.checkNickForm.submit();
	return true;
}	

function chk(){
	var oform = document.mform;
	if (!isUserid(oform.nickname.value)){
  		oform.nickname.focus();
		return false;
  	}
	if (oform.password.value.length<4){
		alert("设置密码不能为空且不少于4位！");
		oform.password.focus();
		return false;
	}
	if (oform.pswa.value.trim()==""){
		alert("请输入确认密码！");
		oform.pswa.focus();
		return false;
	}
	if (oform.password.value!=oform.pswa.value){
		alert("两次输入密码不一致,请重新输入!");
		oform.password.value="";
		oform.pswa.value="";
		oform.password.focus();
		return false;
	}
	if (oform.turename.value==""){
		alert("请输入您的真实姓名！");
		oform.turename.focus();
		return false;
	}
	if (oform.RegVerifyCode.value.length<1){
		alert("验证码不为空！");
		oform.RegVerifyCode.focus();
		return false;
	}
	//if (oform.email.value.trim()==""){
		//alert("电子邮件不能为空.");
  		//oform.email.focus();
		//return false;
  	//}
	if (oform.email.value.trim()!=""){
  	if (!isemail(oform.email.value)){
  		oform.email.focus();
		return false;
  	}
	}
	return true;
}

function isemail (s) 
{
	if (s.length > 100)
	{
		window.alert("email地址长度不能超过100位!");
		return false;
	}

	var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
	var re = new RegExp(regu);
	if (s.search(re) != -1) {
		return true;
	} else {
		window.alert ("请输入有效合法的E-mail地址(xxx@xxx.xxx) ！")
		return false;
	}
}
//验证用户id是否合法
//登录名必须以字母开头，限用英文小写、数字、下划线；
//必须以英文字母开头，4-25个字符，为了方便，可以使用大写中划线，下划线，点号等符号
function isUserid(id){
	if (id.length > 25||id.length<2)
	{
		window.alert("警告:登录名长度应为4-25!");
		return false;
	}
	return true;
}