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)=='=' || 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)=='=' || str.charAt(i)=='~') 
     { 
         return false; 
      } 
   } 
     return true; 
} 

function validstring1(str) 
{ 
    var len; 
    len = str.length;
 
  for(var i=0; i<len; i++) 
  {
     return(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)=='=' || str.charAt(i)=='~');
   } 
}

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 isSignNumnull(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 isFloat(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; 
}

function isIntNum(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 ((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 '@' 
{
alert("请输入有效的E-mail地址！");
return false;
}
}

if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
{
alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "请重新输入" );
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"){
        alert("系统暂时只支持中国移动的手机号码(135-139)，请您使用其他方式注册.感谢您的使用！");
        return false;
     }
  }
  return true;
}

function replaceAll(theString,searchChar,newChar){
    	return theString.split(searchChar).join(newChar)
}
    	
function Trim(str){
 if(str.charAt(0) == " "){
  str = str.slice(1);
  str = Trim(str); 
 }
 if(str.charAt(str.length-1) == " "){
 str = str.substring(0,str.length-1);
 str = Trim(str); 
 }
 return str;
}

function isFileExists(filespec)
{
  var fso, s = filespec;
  fso = new ActiveXObject("Scripting.FileSystemObject");
  if (fso.FileExists(filespec))
    return true;
  else 
    return false;

}

//-------------------------------------------------- used in the hgpim
function snapdata(queryobject,filename,title){
window.open("../common/showselect.jsp?queryobject=" + queryobject + "&filename=" + filename + "&title=" + title,"","toolbar=0,scrollbars=1,resizable=no,width=250,height=300,top=100,left=400");
}

function snap_tbldata(queryobject,filename,title){
window.open("../column/showcolumforselect.jsp?queryobject=" + queryobject + "&filename=" + filename + "&title=" + title,"","toolbar=0,scrollbars=1,resizable=no,width=700,height=400,top=100,left=100");
}

function gotopage(theurl,thewidth,theheight){
	window.open(theurl,'editwin','width='+thewidth+',height='+theheight+',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes');
}
function isProjectcode(s) 
{ 
if (isEmpty(s)){  
return false; 
} 
if(!isCharsInBag (s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789#")){ 
return false; 
} 
return true; 
}