/* 
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 '';
	}
}
//select 驗證 不可是第一項----------------------------------------------
function checklogintype(objForm,txtname, txt) {
	if ( eval( 'document.'+objForm+'.'+txtname)[0].selected){
	   return "\n     -  " + txt;
	} else {
		return '';
	}
}
//密碼 驗證 是否同相----------------------------------------------
function checkpassword(objForm,txtname,txtname2, txt) {
	if ( eval( 'document.'+objForm+'.'+txtname).value !=  eval('document.'+objForm+'.'+txtname2).value){
	   return "\n     -  " + txt + "兩次輸入不相同 " ;
	} else {
		return '';
	}
}

// 驗證 性別----------------------------------------------
function checkGender(objForm,radioname,txt) {
	 var j=0;
	 for (var i=0; i<eval( 'document.'+objForm+'.'+radioname).length; i++){
	 	 	  //alert(i + "位:" +  eval( 'document.'+objForm+'.'+radioname)[i].status); 
	 		  if ((eval( 'document.'+objForm+'.'+radioname)[i].status)){
	 		  	  return '';
			   }else {
	 		     j++;
			 }
	 }  
	 if (j>>0){	 	 return "\n     -  " + txt + "未選取 " ;  }
}

// 驗證 同意----------------------------------------------
function checkAccOk(objForm,radioname,txt) {
	 if ((eval( 'document.'+objForm+'.'+radioname)[0].status)){
	 		  	  return '';
			   }else {
	 		     return "\n     -  " + txt + "請同意! " ;
	    }
}
 
//長度驗證---------------------------------------------------------
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 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


//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;
    }
}
//-----------------------
function CallUpload (strUrl) {
   winprops = "height=200, width=380, scrollbars=yes, toolbar=yes,resizable";
   win = window.open(strUrl, "UploadFile", winprops);
}

function NewWindow (strUrl) {
   winprops = "height=480, width=800, scrollbars=yes, toolbar=no,resizable";
   win = window.open(strUrl, "Epaper", winprops);
}