
/*--判断特定栏位值是否有填--*/
function isEmpty(str) { 
	for (var i = 0; i < str.length; i++)
		if (" " != str.charAt(i))return false; 
		return true; 
}

function Check(f) { 
	var Lens = 0, tmps = 0;
	var tmp;
	var oo = document.CheckDataForm;
	//Lens = parseInt(oo.requirednum.value);
	for (var i = 0; i < oo.required.length; i++){
		tmp = oo.required[i].value.split(";");
		if (null != f[tmp[1]]){
			if(tmp[0] == "text"){
				if(f[tmp[1]].type.indexOf("select") > -1){
					if (isEmpty(f[tmp[1]].options[f[tmp[1]].selectedIndex].value))return EmptyAlert("您还有这栏位忘了填喔！\n\n"+tmp[2],f[tmp[1]]);
					//alert(f[tmp[1]].options[f[tmp[1]].selectedIndex].value);
				}else{
					if (isEmpty(f[tmp[1]].value))return EmptyAlert("您还有这栏位忘了填喔！\n\n"+tmp[2],f[tmp[1]]);
				}
			}else if(tmp[0] == "int"){
				if (isEmpty(f[tmp[1]].value))return EmptyAlert("您还有这栏位忘了填喔！\n\n"+tmp[2],f[tmp[1]]);
				if (isNaN(f[tmp[1]].value))return EmptyAlert("这栏位应该是数值喔！\n\n"+tmp[2],f[tmp[1]]);
			}else if(tmp[0] == "ints"){
				if (!isEmpty(f[tmp[1]].value))if(isNaN(f[tmp[1]].value))return EmptyAlert("这栏位应该是数值喔！\n\n"+tmp[2],f[tmp[1]]);
			}else if(tmp[0] == "radio"){
				tmps = 0;
				for(var j = 0; j < f[tmp[1]].length; j++)if(f[tmp[1]][j].checked)tmps = 1;
				if(tmps == 0)return EmptyAlert("您还有这栏位忘了点选喔！\n\n"+tmp[2],f[tmp[1]][0]);
			}else if(tmp[0] == "checkbox"){
				tmps = 0;
				for(var j = 0; j < f[tmp[1]].length; j++)if(f[tmp[1]][j].checked)tmps += 1;
				if(parseInt(tmp[3]) == parseInt(tmp[4]) && tmps != parseInt(tmp[3])){
					return EmptyAlert("有这栏位您只能点选 " + tmp[3] + " 个选项喔！\n\n"+tmp[2],f[tmp[1]][0]);
				}else if(parseInt(tmp[3]) > 0 && tmps < parseInt(tmp[3])){
					return EmptyAlert("这栏位您最少要点选 " + tmp[3] + " 个选项喔！\n\n"+tmp[2],f[tmp[1]][0]);
				}else if(parseInt(tmp[4]) > 0 && tmps > parseInt(tmp[4])){
					return EmptyAlert("这栏位您最多能点选 " + tmp[4] + " 个选项喔！\n\n"+tmp[2],f[tmp[1]][0]);
				}
			}else if(tmp[0] == "Email"){
				if(f[tmp[1]] != null)if (!verifyAddress(f[tmp[1]]))return false;	
			}else if(tmp[0] == "Emails"){
				if(f[tmp[1]] != null && !isEmpty(f[tmp[1]].value))if (!verifyAddress(f[tmp[1]]))return false;	
			}
		}else if(tmp[0] == "Date"){
			intMonth = f[tmp[1]+"Mon"].options[f[tmp[1]+"Mon"].selectedIndex].value;
			intDay = f[tmp[1]+"Day"].options[f[tmp[1]+"Day"].selectedIndex].value;
			if (!checkDateFormat(f[tmp[1]+"Year"].value,intMonth,intDay))return EmptyAlert("您还有这栏位忘了点选 或 日期不正确 喔！\n\n"+tmp[2],f[tmp[1]+"Year"]);
		}
	}
	return true;
}


function EmptyAlert(strTmp,objs){
	alert(strTmp);
	objs.focus();
	return false;				
}


/*--检查密码--*/
function verifyPWD(obj) { 
	var email = obj.value;
	var pattern = /^([a-zA-Z0-9_-])+/;
	if (email.length > 15 || email.length < 6){
		alert("限制密码字数6-15字"); 
		obj.focus();
		return false; 
	}
    flag = pattern.test(email); 
	if(flag) { 
		return true; 
	}else { 
		alert("密码限用数字与英文，不可使用特殊符号"); 
		obj.focus();
		return false; 
	} 
} 		

/*--检查电子邮件--*/
function verifyAddress(obj) { 
	// obtain form value into variable 
	var email = obj.value; 
	 // define regex 
	var pattern = /^([a-zA-Z\.0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
	// test for pattern 
	if (email.length = 0)return true;
    flag = pattern.test(email); 

	if(flag) { 
		//alert("Email检查无误"); 
		return true; 
	}else { 
		alert("不正确的Email"); 
		obj.focus();
		return false; 
	} 
} 	


/*--检验日期--*/
function checkDateFormat(iYear, iMonth, iDay) {
	if (iDay == null || iMonth == null || iYear == null)  { return false; }
	if (iYear.length != 4 || isNaN(iYear) || iYear <= 0)  { return false; }
	if (iMonth.length == 0 || iMonth <= 0)  { return false; }
	if (iDay.length == 0 || iDay <= 0)  { return false; }

	if ((iMonth == 4) || 
		(iMonth == 6) || 
		(iMonth == 9) || 
		(iMonth == 11) ) {
		if (iDay > 30) { return false; }  
	}

	if (iMonth==2) {
		if ((iYear % 4)==0) {
			if (iDay > 29) { return false; }
		} else {
			if (iDay > 28) { return false; } 
		}
	}
	return true;
}


/*--检验密码--*/
function CheckillegalPassword(PWDObj, cPWDObj){
	if(PWDObj.value.length < 6 && PWDObj.value.length >= 0){
		alert("新登入密码 请填写 6 码以上！");
		PWDObj.focus();
	}else if(PWDObj.value != cPWDObj.value){
		alert("新登入密码 和 新登入密码确认 不一样！(确认大小是否相同)");
		PWDObj.focus();
	}else if(illegalPassword(PWDObj.value)){
		alert("新登入密码 请自订半形 a-z, A-Z, 0-9");
		PWDObj.focus();
	}else if(illegalPassword2(PWDObj.value)){
		alert("密码每个字元不能相同！");
		PWDObj.focus();
	}else{
		return true;
	}
	return false;
}

function illegalPassword(idd){
	var xid =  idd.toUpperCase();
	if(idd.length == 0)  return  false;
	var c  =  xid.charAt(0);
	for(var i = 0; i < xid.length; i++) {
		c = xid.charAt(i);
		if(!((('0'<=c)&&(c<='9'))||(('A'<=c)&&(c<='Z')) || c=='@' || c<='_')) return true;
	}
	return  false;		
}

function illegalPassword2(idd){
	var xid =  idd.toUpperCase();
	var c  =  xid.charAt(0);
	for(var i = 1; i < xid.length; i++) {
		if(c != xid.charAt(i))return false;
	}
	return true;
}

/*--检验帐户--*/
function isCorrectAccount(strAcc){
	if(strAcc.match(/^([a-zA-Z0-9_\-@])+$/)) { 
		return true; 
	}else { 
		alert("帐号不能含有‘ A-z, 0-9, _, @, - ’以外的字元！"); 
		return false; 
	} 
}
