
//判断正整数
function isPosInteger(inputVal)
{
	if (! isEmpty(inputVal)) {
		inputStr=inputVal.toString();
		for (var i=0;i<=inputStr.length-1;i++)
		{
			var oneChar=inputStr.charAt(i);
			if (oneChar<"0" || oneChar>"9") {
				return false;
			}
		}
	  }
	  return true;
}

//cut string's head and string's rear spaces
function trim(inputVal)
{
	inputStr=inputVal.toString();
	var oneChar="";
	var headSpaceIndex=0;
	var rearSpaceIndex=0;
	if (! isEmpty(inputStr)) {
		//cut head space
		for (var i=0;i<=inputStr.length-1;i++)
		{
			oneChar=inputStr.charAt(i);
			if (oneChar!=" ") {
				headSpaceIndex=i;
				break;
			}
		}
		//cut rear space
		sLength=inputStr.length;

		for (var k=sLength-1;k>=0;k--) {
			oneChar=inputStr.charAt(k);
			if (oneChar!=" ") {

				rearSpaceIndex=k+1;
				break;
			}
		}

		if (headSpaceIndex==0 && rearSpaceIndex==sLength) {
			return inputStr;
		} else {
			if (headSpaceIndex==0 && rearSpaceIndex!=sLength) {
				inputStr=inputStr.substring(0,rearSpaceIndex);
				return inputStr;
			} else {
				inputStr=inputStr.substring(headSpaceIndex,rearSpaceIndex);
				return inputStr;
			}
		}
	 } else {
		return "";
	 }
}

//检查Email地址
function checkEmail(inputVal)
{
	if (! isEmpty(inputVal))
	{
		inputStr=inputVal.toString();
		if (inputVal.indexOf("@")==-1) {
			return false;
		}
	 }
	 return true;
}

//检查空值
function isEmpty(inputStr)
{
	if (inputStr=="" || inputStr==null) {
		return true;
	}
	return false;
}

//验证两个日期(年月)的大小,条件是这两个日期已经是合法日期.应先用checkDate判断后,再使用该函数
function isStartLessThanEndYM(s1,s2,e1,e2){
   if (s1.length==1)
	  startYear="0"+s1;
   else
	  startYear=s1;

   if (s2.length==1)
	  startMonth="0"+s2;
   else
	  startMonth=s2;

   if (e1.length==1)
	  endYear="0"+e1;
   else
	  endYear=e1;

   if (e2.length==1)
	  endMonth="0"+e2;
   else
	  endMonth=e2;

   if(startYear>endYear){
	   return false;
   }else{
		if (startYear==endYear){
		   if(startMonth>endMonth){
			   return false;
		   }else{
			   return true;
		   }
		}else
		return true;
   }
   return false;
}




function openwindowless(url, winName, width, height){
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 )){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	theproperty = "width=" + width + ","
			+ "height=" + height + ","
			+ "location=0,"
			+ "menubar=0,"
			+ "resizable=1,"
			+ "scrollbars=1,"
			+ "status=0,"
			+ "titlebar=0,"
			+ "toolbar=0,"
			+ "hotkeys=0,"
			+ "screenx=" + xposition + "," //仅适用于Netscape
			+ "screeny=" + yposition + "," //仅适用于Netscape
			+ "left=" + xposition + "," //IE
			+ "top=" + yposition; //IE
	window.open( url,winName,theproperty);
}

function openwindow(url, winName, width, height){
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 )){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	theproperty = "width=" + width + ","
			+ "height=" + height + ","
			+ "location=0,"
			+ "menubar=0,"
			+ "resizable=0,"
			+ "scrollbars=0,"
			+ "status=0,"
			+ "titlebar=0,"
			+ "toolbar=0,"
			+ "hotkeys=0,"
			+ "screenx=" + xposition + "," //仅适用于Netscape
			+ "screeny=" + yposition + "," //仅适用于Netscape
			+ "left=" + xposition + "," //IE
			+ "top=" + yposition; //IE
	window.open( url,winName,theproperty);
}
function openwindowf( url, winName, width, height)
{
xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 ))
{
xposition = (screen.width - width) / 2;
yposition = (screen.height - height) / 2;
}
theproperty= "width=" + width + ","
+ "height=" + height + ","
+ "location=0,"
+ "menubar=0,"
+ "resizable=0,"
+ "scrollbars=0,"
+ "status=0,"
+ "titlebar=0,"
+ "toolbar=0,"
+ "hotkeys=0,"
+ "screenx=" + xposition + "," //仅适用于Netscape
+ "screeny=" + yposition + "," //仅适用于Netscape
+ "left=" + xposition + "," //IE
+ "top=" + yposition; //IE
window.open( url,winName,theproperty );
}

  //返回指定年月的天数
function getDaysOfMonth(yearStr,monthStr)
{
	if (isPosInteger(yearStr) && isPosInteger(monthStr))
	{
		if ((monthStr>=1) && (monthStr<=12))
		{

			switch (monthStr)
			{
			case "1":
			case "01":
			case "3":
			case "03":
			case "5":
			case "05":
			case "7":
			case "07":
			case "8":
			case "08":
			case "10":
			case "12":
			return 31;
			case "4":
			case "04":
			case "6":
			case "06":
			case "9":
			case "09":
			case "11":
     		return 30;
			case "2":
			case "02":
				//是否润年
				if((yearStr % 4 == 0) && ((yearStr % 100 != 0) || (yearStr %400 == 0)))
				{
						return 29;
				 } else {
						return 28;
				 }
				break;
			}
		 }
	}
}
