/*
Explain:Fansio通用javascript函數
Last Update : 2006-04-06
使用範例：<SCRIPT language=javascript src="formcheck.js"></SCRIPT>
*/

//驗證是否為空----------------------------------------------------
function txtcheck(objForm,txtname, txt) {
	if ( eval( 'document.'+objForm+'.'+txtname).value == "" ){
		return "\n     -  " + txt;
	} else {
		return '';
	}
}

//長度驗證---------------------------------------------------------
function lencheck(objForm,txtname,txt,len) {
	if ( eval( 'document.'+objForm+'.'+txtname).value.length > len ){
		return "\n     -  " + txt + "長度不得超過" + len + "個字元";
	} else {
		return '';
	}
}

//Email格式驗證---------------------------------------------------
function emailcheck(objForm,txtname,txt) {
	var txtmail = eval( 'document.'+objForm+'.'+txtname).value
	var len = txtmail.length;
	if (len!=0){
		for(var i=0;i<len;i++)
		{  var c= txtmail.charAt(i);
		   if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="-")||(c=="_")||(c==".")||(c=="@")))
		      return txt + "只能是數字,英文字母及'-','_'等符號,其他的符號都不能使用 !\n";
		}
		if ((txtmail.indexOf("@")==-1)||(txtmail.indexOf("@")==0)||(txtmail.indexOf("@")==(len-1)))
			return txt + "不正確 !\n";
		else if ((txtmail.indexOf("@")!=-1)&&(txtmail.substring(txtmail.indexOf("@")+1,len).indexOf("@")!=-1))
			return txt + "不正確 !\n";
		else if ((txtmail.indexOf(".")==-1)||(txtmail.indexOf(".")==0)||(txtmail.lastIndexOf(".")==(len-1)))
			return txt + "不完全 !\n";
		else return "";
	} else { 
		return "";
	}
}

function passwordcheck(objForm,pass1,pass2,txt) {
	var txtpass1 = eval( 'document.'+objForm+'.'+pass1).value
	var txtpass2 = eval( 'document.'+objForm+'.'+pass2).value
	if (txtpass1 != txtpass2)
	{
		return txt + "\n兩次輸入密碼不同";
	}else{
	return "";
	}
}

//檢查是否為數字--------------------------------------------------
function checkNumber(objForm,txtname,txt)
{
 var i,j,strTemp;
 var txtNum = eval( 'document.'+objForm+'.'+txtname).value
 var len = txtNum.length;
 strTemp="0123456789";
 if ( len== 0)
  return "\n\n     -  " + txt + " 請填入數字 !";
 for (i=0;i<len;i++)
 {
  j=strTemp.indexOf(txtNum.charAt(i)); 
  if (j==-1)
  {//字符
  return "\n\n     -  " + txt + " 請填入數字 !";
  }
 }
 //數字
 return "";
}

//check 欄位的最大值,與最小值--------------------------------------------
function objcheck(objname,objtxt,objlengthmin,objlengthmax) {
  objlength = objname.value.length;
  if (objlength < objlengthmin) {
  	focusname = objname;
    return "\n- 請輸入「"+objtxt+"」";
  }if (objlength > objlengthmax) {
  	focusname = objname;
    return "\n-「"+objtxt+"」 內容長度不得超過 "+objlengthmax+" 個字 \n\t現在的"+objtxt+"內容長度為 ["+objlength+"] !";
  }
  return "";
}//check 欄位的最大值,與最小值 end

function objchecklen(objname,objtxt,objlengthmin,objlengthmax) {
  objlength = eval( 'document.'+objname+'.'+objtxt).value.length;
  if (objlength < objlengthmin) {
  	focusname = objname;
    return "\n"+objtxt+" 小于規定長度";
  }if (objlength > objlengthmax) {
  	focusname = objname;
    return "\n"+objtxt+" 大于規定長度";
  }
  return "";
}

//check 閏年
function checkyear(x){
	if(x%4==0 && x%100!=0 || x%400==0){ 
		return true;
	}else { 
		return false;
	} 
} //check 閏年 end

//check 日期格式
function checkdatetype(intYear,intMonth,intDay){
  if (intYear>=0 && intMonth>=1 && intMonth<=12) {
	var arrdays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	if (checkyear(intYear)) {
	  arrdays[1]=29;
	}
	if (arrdays[intMonth-1]>=intDay){
	  return true;
	}
  }
  return false;
}//check 日期格式 end



//後臺復選-------------------------------------------
function unselectall(objForm)
{
    if(objForm.chkAll.checked){
	objForm.chkAll.checked = objForm.chkAll.checked&0;
    } 	
}

function CheckAll(objForm)
{
  for (var i=0;i<objForm.elements.length;i++)
    {
    var e = objForm.elements[i];
    if (e.Name != "chkAll"&&e.disabled!=true)
       e.checked = objForm.chkAll.checked;
    }
}
//-----------------------