﻿function checkall(form){
	var i;
	for(i=0;i<form.elements.length;i++){
		if(form.elements[i].name!='chkall')
			form.elements[i].checked=form.chkall.checked;
	}
}

function confirmwin(){
	return window.confirm('永久删除所有选中的记录？');
}


function popwin(pagesrc,winname,width,height,top,left){
	newwin=window.open(pagesrc,winname,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+width+',height='+height+',top='+top+',left='+left);
	newwin.focus();
}

function checkStr(val,str)
{
  if (val.value==" ")
  { 
     alert(str+"不允许为空！");
	 val.focus();
	 return false;
  }
  return true;
}
function checkLen1(val,str,len)
{
  if (val.value.length>len) 
  {
     alert(str+"长度要求不大于"+ len + "个字符");
	 val.focus();
	 return false;
  }
   return true;
}
function checkLen(val,str,len)
{
  if (val.value=="")
  { 
     alert(str+"不允许为空！");
	 val.focus();
	 return false;
  }
  if (val.value.length>len) 
  {
     alert(str+"长度要求不大于"+ len + "个字符");
	 val.focus();
	 return false;
  }
   return true;
}

function checkEqual(val1,val2,str)
{
   if (val1.value==val2.value) return true;
   else
   {
     alert(str+"不一致！");
	 val1.focus();
	 return false;
	 }
}

function checkInt(val,str)
{
  if (!isFormatStr("0123456789",val.value))
  {
    alert(str+"必须是整数！");
	 val.focus();
	 return false;
  }
   return true;
}

function checkNum(val,str,maxval)
{
  if (!isFormatStr("0123456789.",val.value))
  {
     alert(str+"必须是数字！");
	 val.focus();
	 return false;
  }
   return true;
}


function checkDate(year,month,day)
{  
    var isdate= true;
	if (isNaN(parseInt(year.value)) || isNaN(parseInt(month.value)) || isNaN(parseInt(day.value)))
	     isdate = false;
	else
	{
	  var  thedate = new Date();
	   var  y=parseInt(year.value);
       var  m=parseInt(month.value);
       var  d=parseInt(day.value);
       var standardDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
       if (y>=1900 && y<=thedate.getYear() && m>=1 && m<=12 )
		 {
		    if ((y%4==0&&y%100!=0)||y%400==0)  standardDays[1]=29;
		    if ( d>=1 && d<=standardDays[m-1] ) 
			 {
			 	 year.value=y;
         	     month.value=m;
            	 day.value=d;
                 isdate=true;
         	  }
			 else
			    isdate=false;
		 }
		else
		  isdate = false;
	}
	if (!isdate)
	{
	    alert("日期填写不正确！");
        year.focus();
	 }
	 return isdate;
}

function checkEmail(val,str)
{
   if (checkStr(val,str))
   {
      if ((val.value.indexOf("@")<= 0) || (val.value.indexOf(".") <= 0) || (val.value.indexOf("'") > 0))
     {	
	     alert("请输入正确的邮箱地址！"+str);
         val.focus();
    	 return false;
      }
	  return true;
     }
  else    
    return false;
}

function checkJPG(val,str)
{
  if (val.value=="") return true;
  if (val.value.length<4 || !isJPG(val.value))
    {
     alert(str+"必须是JPG格式图片！");
	 val.focus();
	 return false;
  }
   return true;
}

function isJPG(filename)
{
  var fileext;
  var my_value=filename;
  if (my_value.length<4) return false;
  fileext=my_value.substr(my_value.length-3,3);
  fileext=fileext.toUpperCase();              
  if (fileext == "JPG")
      return true;
  else
      return false;
}

function isFormatStr(okstr,str)
 {
//  var checkOK = "0123456789";
  var checkOK = okstr
  var checkStr = str;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  
  if(str==""){
  return false;
  }
  
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else
      allNum += ch;
  }
  if (!allValid)
  {  
    return (false);
  }

  if (decPoints > 1)
  {    
    return (false);
  }
  return (true);
 }
 
function openscriphtml(val){
	if (navigator.appName!="Microsoft Internet Explorer")
	alert("此功能 Netscape 用户不能使用！")
else
	{newwin=window.open('../htmledit/editor.html','','width=640,height=450,status=1');
	newwin.focus();
	newwin.execScript("var formID='" + val + "';");
	}
}
