//判斷上傳圖檔副檔名。
function isValidImageExt(imageName,iValue){
	arrayValue = iValue.split("、");
	var checkValue = 0;
		for(i=0;i<arrayValue.length;i++){
			if(imageName.substring(imageName.length - 3, imageName.length).toLowerCase() != arrayValue[i]){
				checkValue++;
			}
		}
    if(checkValue == arrayValue.length ){return false;}else{return true;} 
}
//型錄分類表單。
function CheckCataAreaForm(theform){
	if(theform.selimg[2].checked && !theform.uploadimg.value){
		alert("請選擇分類圖檔!!");
		theform.uploadimg.focus();
		return false;
	}else if(theform.selimg[2].checked && theform.uploadimg.value){
      if(!isValidImageExt(theform.uploadimg.value,"gif、jpg、png")){
        alert("上傳圖檔必須為gif、jpg、png格式 !!");				
		return false;
	  }
    }
	 return true;
}
//型錄資料表單。
function CheckCataDataForm(theform){
	if(theform.selfile[1].checked && !theform.uploadfile.value){
		alert("請選擇型錄檔案!!");
		theform.uploadfile.focus();
		return false;
	}
	 return true;
}
//聯絡訊息。
function CheckContact(theform){
	var alert_str="",focus_name="";
	if(!theform.company.value){
		alert_str += "請輸入公司名稱!!\n";
		focus_name="company";
	}
	if(!theform.name.value){
		alert_str += "請輸入聯絡人!!\n";
		if(focus_name=="") focus_name="name";
	}
	if(!theform.phone.value){
		alert_str += "請輸入電話!!\n";
		if(focus_name=="") focus_name="phone";
	}
	if(theform.email.value.indexOf('@') < 0 || theform.email.value.indexOf('.') < 0 || theform.email.value.length  < 10){
		alert_str += "請輸入Email!!\n";
		if(focus_name=="") focus_name="email";
	}
	if(!theform.title.value){
		alert_str += "請輸入聯絡主旨!!\n";
		if(focus_name=="") focus_name="title";
	}
	if(!theform.content.value){
		alert_str += "請輸入內容!!\n";
		if(focus_name=="") focus_name="content";
	}
	if(alert_str != ""){
		alert(alert_str);
		theform.elements[focus_name].focus();
		return false;
	}else{
		return true;
	}
}
//會員登入。
function CheckMemberLogin(theform){
	var alert_str="",focus_name="";
	if(!theform.userid.value){
		alert_str += "Please input Member ID!!\n";
		focus_name="userid";
	}
	if(!theform.password.value){
		alert_str += "Please input Password!!\n";
		if(focus_name=="") focus_name="password";
	}
	if(alert_str != ""){
		alert(alert_str);
		theform.elements[focus_name].focus();
		return false;
	}else{
		return true;
	}
}
//加入會員。
function CheckMemberJoin(theform){
	var alert_str="",focus_name="";
	if(!theform.userid.value){
		alert_str += "Please input Member ID!!\n";
		focus_name="userid";
	}
	if(!theform.password.value){
		alert_str += "Please input Password!!\n";
		if(focus_name=="") focus_name="password";
	}
	if(theform.password.value != theform.repassword.value){
		alert_str += "Password and Confirm Password no match!!\n";
		if(focus_name=="") focus_name="repassword";
	}
	if(!theform.company.value){
		alert_str += "Please input Company Name!!\n";
		if(focus_name=="") focus_name="company";
	}
	if(!theform.name.value){
		alert_str += "Please input Contact Person!!\n";
		if(focus_name=="") focus_name="name";
	}
	if(theform.email.value.indexOf('@') < 0 || theform.email.value.indexOf('.') < 0 || theform.email.value.length  < 10){
		alert_str += "Please input E-mail!!\n";
		if(focus_name=="") focus_name="email";
	}
	if(!theform.phone.value){
		alert_str += "Please input Tel!!\n";
		if(focus_name=="") focus_name="phone";
	}
	if(!theform.address.value){
		alert_str += "Please input Address!!\n";
		if(focus_name=="") focus_name="address";
	}

	if(alert_str != ""){
		alert(alert_str);
		theform.elements[focus_name].focus();
		return false;
	}else{
		return true;
	}
}
//忘記密碼。
function CheckMemberForgot(theform){
	var alert_str="",focus_name="";
	if(!theform.userid.value){
		alert_str += "Please input Member ID!!\n";
		focus_name="userid";
	}
	if(theform.email.value.indexOf('@') < 0 || theform.email.value.indexOf('.') < 0 || theform.email.value.length  < 10){
		alert_str += "Please input E-mail!!\n";
		if(focus_name=="") focus_name="email";
	}
	if(alert_str != ""){
		alert(alert_str);
		theform.elements[focus_name].focus();
		return false;
	}else{
		return true;
	}
}
