//判断输入是否为数字

function isNumber( str ){
	if( str.length == 0 ) return false;
 	for( var loc=0; loc<str.length; loc++ )
 		if( (str.charAt(loc) < '0') || (str.charAt(loc) > '9') ) return false;
 	return true;
}

//对比两个两个日期的大小

function comparePsw(ps1,ps2){
  if(ps1<=ps2) return true;
  else return false;
}

//判断输入是否为空

function isEmpty(inStr){
    if(inStr==null || trim(inStr).length == 0 )
        return true;
    return false;
}

//compare String

function strEqual(str1, str2){
	if (isEmpty(str1) && isEmpty(str2) )
		return true;
	if (isEmpty(str1) || isEmpty(str2) || str1.length != str2.length){
		return false;
	}
	for(i=0;i< str1.lentgh; i++)
	  if(str1.charAt(i) != str2[i])
	  	return false;
	return true;
}

//去掉输入前后的空格

function trim(strText){
	if(!strText)
		return '';
  while (strText.substring(0,1) == ' ')
    strText = strText.substring(1, strText.length);
  while (strText.substring(strText.length-1,strText.length) == ' ')
    strText = strText.substring(0, strText.length-1);
  return strText;
}

//判断输入日期是否合法

function isValidDate(dateStr) {
// Date validation function courtesty of
// Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
   var datePat = /^(\d{4})(\/|-)(\d{1,2})\2(\d{1,2})$/; // requires 4 digit year
   var matchArray = dateStr.match(datePat); // is the format ok?
   if (matchArray == null) {
       alert(dateStr + " 不是标准的日期格式")
       return false;
    }
month = matchArray[3]; // parse date into variables
day = matchArray[4];
year = matchArray[1];
if (month < 1 || month > 12) { // check month range
alert("月份须1至12之间");
return false;
}
if (day < 1 || day > 31) {
alert("日期须在1至31之间");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert(month+"月没有31天")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert(year + "年2月没有" + day + "天");
return false;
   }
}
return true;
}

//判断输入的时间是否合法

function isValidTime(timeStr) {
    var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
    var matchArray = timeStr.match(timePat);
    if (matchArray == null) {
        alert("不是标准的时间格式");
        return false;
    }
    hour = matchArray[1];
    minute = matchArray[2];
    second = matchArray[4];
    ampm = matchArray[6];
    if (second=="") { second = null; }
    if (ampm=="") { ampm = null }
    if (hour < 0  || hour > 23) {
        alert("小时须在0至23之间");
        return false;
    }
    if (minute < 0 || minute > 59) {
        alert ("分钟须在0至59之间");
        return false;
    }
    if (second != null && (second < 0 || second > 59)) {
        alert ("秒须在0至59之间");
        return false;
    }
    return true;
}
//判断邮件地址是否合法

function check_email(address) {
  if ((address == "")
    || (address.indexOf ('@') == -1)
    || (address.indexOf ('.') == -1))
      return false;
  return true;
}
function IsNumber(str)
{
var number_chars = "1234567890";
var i;
for (i=0;i<str.length;i++)
{
if (number_chars.indexOf(str.charAt(i))==-1) 
return false;
}
return true;
}
function print(){
var winPrint = window.open("", "winPrint", "width=500,height=300,status=yes,menubar=no,scrollbars=yes,resizable=yes,top=10000,left=10000");
 winPrint.document.open("text/html", "replace");
 winPrint.document.write(unescape(formatHtmlStr(event.srcElement.document.all.report.value)));
 winPrint.document.close();
 winPrint.print();
 winPrint.close();
}

function formatHtmlStr(str){
return "<pre>"+str+"</pre>";
}

function saveFile()
{
  var win=window.open('','','top=10000,left=10000');
  win.document.write(formatHtmlStr(document.all.report.innerText));
  win.document.execCommand('SaveAs','','Sch_rpt_card.htm');
  win.close();
}
