nDaysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
nDaysInLeapMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
sCheckMSG="请输入邮箱名或者手机号码";
sCheckMSGNULL="请输入邮箱名或者手机号码";
sCheckMSG_MUSTINPUT="非常抱歉，此字段为必填字段,麻烦再填写一次";


function getnDaysInMonth(monthNo, p_year) {
	if ((p_year % 4) == 0) {
			if ((p_year % 100) == 0 && (p_year % 400) != 0)
					return nDaysInMonth[monthNo];

			return nDaysInLeapMonth[monthNo];
	} else
			return nDaysInMonth[monthNo];
}

function isValidDate(yVal, mVal, dVal)
	{
       if(dVal>getnDaysInMonth((mVal-1),yVal))
	        return false;
    	else if(yVal=='' || mVal=='' || dVal=='')
			return false;
		else if(yVal<1900 || yVal>2100)
			return false;
		else if(mVal<1 || mVal>12)
			return false;
		else if(dVal<1 || dVal>31)
			return false;
		else if(mVal==2 && dVal>29)
			return false;
		else
			return true;
	}

function isValidTime(hVal, mVal, sVal)
	{

    	if(hVal=='' || mVal=='' || sVal=='')
			return false;
		else if(hVal<0 || hVal>24)
			return false;
		else if(mVal<0 || mVal>59)
			return false;
		else if(sVal<0 || sVal>59)
			return false;
		else
			return true;
	}
	
function validstring(str) 
{ 
    var len; 
    len = str.length;
  if(str.length==0)
  return false;
 
  for(var i=0; i<len; i++) 
  {
     if(str.charAt(i)=="'" || str.charAt(i)=='<' || str.charAt(i)=='>' || str.charAt(i)=='\'' || str.charAt(i)=='\"' || str.charAt(i)=='!' || str.charAt(i)=='&'  || str.charAt(i)=='*' || str.charAt(i)=='(' || str.charAt(i)==')' || str.charAt(i)=='+' || str.charAt(i)=='=' || str.charAt(i)=='~') 
     { 
         return false; 
      } 
   } 
     return true; 
} 

function validpwdstring(str) 
{ 
    var len; 
    len = str.length;
  if(str.length==0)
  return false;

 
  for(var i=0; i<len; i++) 
  {
     if(str.charAt(i)=="'" || str.charAt(i)=='\'' || str.charAt(i)=='\"') 
     { 
         return false; 
      } 
   } 
     return true; 
} 

function validstringnull(str) 
{ 
    var len; 
    len = str.length;
 
  for(var i=0; i<len; i++) 
  {
     if(str.charAt(i)=="'" || str.charAt(i)=='<' || str.charAt(i)=='>' || str.charAt(i)=='\'' || str.charAt(i)=='\"' || str.charAt(i)=='!' || str.charAt(i)=='&'  || str.charAt(i)=='*' || str.charAt(i)=='(' || str.charAt(i)==')' || str.charAt(i)=='+' || str.charAt(i)=='=' || str.charAt(i)=='~') 
     { 
         return false; 
      } 
   } 
     return true; 
} 

function isCharsInBag (s, bag) 
{  
var i; 
for (i = 0; i < s.length; i++) 
{  
var c = s.charAt(i); 
if (bag.indexOf(c) == -1) return false; 
} 
return true; 
} 


function isEmpty(s) 
{  
return ((s == null)||(s.length == 0));  
} 


function isNum(s) 
{ 
if (isEmpty(s)){  
return false; 
} 
if(!isCharsInBag (s, "0123456789.")){ 
return false; 
} 
return true; 
}

function isNumnull(s) 
{ 

if(!isCharsInBag (s, "0123456789.")){ 
return false; 
} 
return true; 
}

function isDigital(s) 
{ 
if (isEmpty(s)){  
return false; 
} 
if(!isCharsInBag (s, "0123456789")){ 
return false; 
} 
return true; 
}

function isDigitalnull(s) 
{ 
  if(!isCharsInBag (s, "0123456789")){ 
	return false; 
  } 
return true; 
}

//---------------------------------------------------Email判断
function isEmail(s)
{
if (isEmpty(s))
{

return false;
}
//is s contain whitespace
if (isWhitespace(s))
{

return false;
}
var i = 1;
var len = s.length;

if (len > 40)
{

return false;
}

pos1 = s.indexOf("@");
pos2 = s.indexOf(".");
pos3 = s.lastIndexOf("@");
pos4 = s.lastIndexOf(".");

if((pos4+1)==s.length)
   return false;
if((pos1+1)==pos2)
  return false;

if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len)){

return false;
}
else{ 
if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1) 
|| ( pos1 != pos3 ) //find two @
|| ( pos4 < pos3 ) ) //. should behind the '@' 
{
return false;
}
}

if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
{

return false;
}
return true;
}

function isEmailnull(s)
{
//is s contain whitespace
if (isWhitespace(s))
{

return false;
}
var i = 1;
var len = s.length;

if (len > 40)
{

return false;
}

pos1 = s.indexOf("@");
pos2 = s.indexOf(".");
pos3 = s.lastIndexOf("@");
pos4 = s.lastIndexOf(".");

if((pos4+1)==s.length)
   return false;
if((pos1+1)==pos2)
  return false;

if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len)){

return false;
}
else{ 
if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1) 
|| ( pos1 != pos3 ) //find two @
|| ( pos4 < pos3 ) ) //. should behind the '@' 
{

return false;
}
}

if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
{

return false;
}
return true;
}

//----------------------------------------------------空格判断
function isWhitespace (s)
{ 
var whitespace = " \t\n\r";
var i;
for (i = 0; i < s.length; i++)
{ 
var c = s.charAt(i);
if (whitespace.indexOf(c) >= 0) 
{
return true;
}
}

return false;
}


//----------------------------------------------------手机号码和Email判断
function isvalidEmail_MP(s)
{ 
 if(s.length==0){
    return false;  
 }
 if(s.indexOf("@")!=-1)
   if(!isEmail(s))
     return false;
   else
     return true;
 else{
   if(!isvalidMP(s))
     return false;
   else
     return true;
 }

}
//------------------------------check Mobile Phone
function isvalidMP(s){
   if(!isNum(s))
     	return false;
   else{
     if(s.length!=11){
        return false;
     }
     if(s.substring(0,3)!="135" && s.substring(0,3)!="136" && s.substring(0,3)!="137" && s.substring(0,3)!="138" && s.substring(0,3)!="139" && s.substring(0,3)!="130" && s.substring(0,3)!="131" && s.substring(0,3)!="133"){
        
        return false;
     }
  }
  return true;
}