// JavaScript Document驗證項目
function validatetime(source){//時間格式
	var source=document.getElementById(source);
	var reg = /^\d{4}-\d{2}-\d{2}$/
	var state = false;
	if (source.value != "") {
		if (reg.test(source.value)){
		    state = true;
		} else {
			state = false;    
		}
	} 
	if (source.value.substring(4,6) >12 | source.value.substring(6,8) >31){
		state = false;
	}else if (source.value.substring(4,6) == "02" & source.value.substring(6,8) > 29){
		state = false;
	}
	
	return state;
}
function valueInput(source){//判斷是否輸入
	var source=document.getElementById(source);
	if (source.value==""){
		return false;
	}else{
		return true;
	}
}
function compareDate(date1,date2){//日期比大小
	var adate1=document.getElementById(date1);
	var adate2=document.getElementById(date2);
	
	
	
	
	if (Date.parse(adate1.value.replace("-","/")) > Date.parse(adate2.value.replace("-","/"))){
		return false;
		
	}else{
	
		return true;
	}
	
}
function isnum(source){//是否數字
	var num=document.getElementById(source);
	if (isNaN(num.value)){
		return false;
	}else{
		return true;
	}
}
function compareValue(source, target){
	if (document.getElementById(source).value == document.getElementById(target).value){
		return true;
	}else{
		return false;
	}
}
//上下分頁
function pnpage(){
	
}
//按一下變不見
var context="請輸入關鍵字";
function textFocus(source){
	if (document.getElementById(source).value==context){
		document.getElementById(source).value="";
	}
}
//跑到別的地方又回來
function textblur(source){
	if (document.getElementById(source).value==""){
		document.getElementById(source).value=context;
	}
}
//上下頁
function pagecou(pntype){
	var pageno=document.getElementById("pageno");
	if (pntype=='p'){
		pageno.value=parseInt(pageno.value)-1;
		document.getElementById("frm").submit();
	}else if (pntype=='n'){
		pageno.value=parseInt(pageno.value)+1;
		document.getElementById("frm").submit();
	}
}

//驗證檔案格式
function validateFile(fileName,type){//pic 圖片
	pic=new Array('jpg','gif','png');
	var picobj=document.getElementById(fileName).value;
	var ext="";
	var count =0;
	for (var idx =0;idx<pic.length;idx++){
		ext=picobj.substring(picobj.lastIndexOf(".")+1);
		if (ext==pic[idx]){
			count++;
		}
	}
	if (count==0){
		return false;
	}
}

function validateemail(source){
	var source=document.getElementById(source);
	var reg_email = /^[a-zA-Z0-9\._-]+@+[a-zA-Z0-9\._-]+\.+[a-zA-Z]{2,3}$/
	if (reg_email.test(source.value)){
		return true;
	}else{
		return false;
	}
}
//是否含有特殊字元
function spcode(source){
	sp = new Array("''",'\'','!','@','#','$','%','^','&');
	for (var i = 0;i<sp.length;i++){
		if (document.getElementById(source).value.indexOf(sp[i])>-1){
			return false;
		}
	}
	
}
function selectText(source){
	if (document.getElementById(source).type == 'text')
	document.getElementById(source).select;
}
function alertText(source){
	if (document.getElementById(source).type == 'text')
	document.getElementById(source).style.backgroundcolor = '#999999';
}
function checkForm(source){
	if (document.getElementById(source).value == "請輸入關鍵字"){
		document.getElementById(source).value == "";
	}
	document.getElementById("frm").submit();
}
function validatepass(source){
	var reg_pwd =  /(^[a-zA-Z]+[0-9])/;///^[0-9A-Z]{6,15}$/
	var reg_pwd2 = /[^a-zA-Z0-9]/;
	var value = document.getElementById(source).value;
	
	if (value != "") {
		if (value.length > 6 && value.length < 30) {
		    if (reg_pwd.test(value)) {
				
			    return true;
			} else if (reg_pwd2.test(value)) {
			    return false;
		    } else {
			    return false;
		    } 
		} else {
			return false;
		}
	} else {
		return false;
	}
}
function validateLogin(){
	if (valueInput('uid')==false){
		alert("請輸入帳號");
		return false;
	}else if (valueInput('upass')==false){
		alert("請輸入密碼");
		return false;
	}else{
		document.getElementById("login").value="yes";
		document.getElementById("loginForm").submit();
	}
}
function logout(){
	
	document.getElementById("login").value="no";
	document.getElementById("loginForm").submit();
}
function validatecell(obj){
	if (obj.value!=""){
	if (obj.value.length<10 | isnum(obj.id)==false){
		alert('行動電話格式不正確');
		obj.select();
		return false;
	}
	}
}
//密碼格式
function checkPwdReg(value) {
	//var reg_pwd = /[!@#$%^&*+?]/;/[^a-zA-Z0-9]//^[a-zA-Z0-9]$/
	var reg_pwd2 = /\d&[a-zA-Z]/;
	
	if (value != "") {
		if (value.length > 5 && value.length < 17) {
		    if (reg_pwd2.test(value)) {
			    return false;
			//} else if (reg_pwd2.test(value)) {
			  //  return false;
		    } else {
			    return true;
		    } 
		} else {
			return false;
		}
	} else {
		return false;
	}

}
function validateChi(source){
	var value = document.getElementById(source).value;
	var reg_chi = /^[\u4e00-\u9fa5]{0,}$/;
	if ( value!=""){
		return reg_chi.test(value);
	}
}
function validateAge(){
	var countBirth = document.getElementById("mem_3").value;
	dates = countBirth.split('-');
	var birthDate = new Date(parseInt(dates[0]), parseInt(dates[1])-1 ,parseInt(dates[2]));
	var nowDate = new Date();
	
	var a = nowDate.getTime()-birthDate.getTime();
	
	if ( ((a/(24*60*60*365*1000))>20) && ((a/(24*60*60*365*1000))<100) ){
		return true;
	}else{
		return false;
	}
}
function validateUid(source){
	var value = document.getElementById(source).value;
	var uid = /^[A-Za-z0-9]+$/
	if (value!=""){
		return uid.test(value);
	}
}
