function checkFrm(objFrm, lang){
	var radio_choice = false;
	var DateObj = new Date();

	for(count=0;count<objFrm.radio_Button.length;count++){
		if(objFrm.radio_Button[count].checked == true){
			radio_choice = true;
			selectCount = count;
		}
	}
	
	if(radio_choice == false){
		if(lang=='en'){
			alert("Please select Lost or Found");
		}else{
			alert("請選擇遺失寵物或待領寵物");
		}
		return false;
	}else{
		objFrm.typeOfStatus.value = objFrm.radio_Button[selectCount].value;
	}

	if(objFrm.species.value==""){
		if(lang=='en'){
			alert("Please select Species");
		}else{
			alert("請選擇種類");
		}
		objFrm.species.focus();
		return false;
	}
	
	if(objFrm.district.value==""){
		if(lang=='en'){
			alert("Please select District");
		}else{
			alert("請選擇地區");
		}
		objFrm.district.focus();
		return false;
	}
	
	if(objFrm.breed.value==""){
		if(lang=='en'){
			alert("Please select Breed");
		}else{
			alert("請選擇品種");
		}
		objFrm.breed.focus();
		return false;
	}
	
	if(objFrm.location.value.length == 0){
		if(lang=='en'){
			alert("Please fill in Location");
		}else{
			alert("請輸入位置");
		}
		objFrm.location.focus();
		return false;
	}
	
	if(objFrm.sex.value==""){
		if(lang=='en'){
			alert("Please select Sex");
		}else{
			alert("請選擇性別");
		}
		objFrm.sex.focus();
		return false;
	}
	
	if(objFrm.Age.value==""){
		if(lang=='en'){
			alert("Please select Age");
		}else{
			alert("請選擇年齡");
		}
		objFrm.Age.focus();
		return false;
	}
	
	if(objFrm.pet_Color.value==""){
		if(lang=='en'){
			alert("Please select Color");
		}else{
			alert("請選擇顏色");
		}
		objFrm.pet_Color.focus();
		return false;
	}
/*	
	if(objFrm.pet_name.value.length == 0){
		if(lang=='en'){
			alert("Please fill in Pet Name");
		}else{
			alert("請輸入寵物名稱");
		}
		objFrm.pet_name.focus();
		return false;
	}
	
	if(objFrm.microchip.value.length == 0){
		if(lang=='en'){
			alert("Please fill in Microchip ID");
		}else{
			alert("請輸入晶片編號");
		}
		objFrm.microchip.focus();
		return false;
	}

	if(isNaN(objFrm.microchip.value)){
		if(lang=='en'){
			alert("Microchip ID should be Number");
		}else{
			alert("晶片編號必須是數字");
		}
		objFrm.microchip.focus();
		return false;
	}
*/
	if(objFrm.microchip.value!=""){
		 for (var i=0; i< objFrm.microchip.value.toString().length; i++) {
			if(!(/[A-Za-z0-9]/.test( objFrm.microchip.value.charAt(i) ) )){ /// match any non-digit
				if(lang=='en'){
					alert("Microchip ID should be Number or alphabets");
				}else{
					alert("晶片編號必須是數字或英文字");
				}
				objFrm.microchip.focus();
				return false;
			}
		}
    }
    
    if(objFrm.Reunion.value!=""){
		var firstMark = objFrm.Reunion.value.indexOf("/");
		var lastMark = objFrm.Reunion.value.lastIndexOf("/");
		var strLen = objFrm.Reunion.value.lenght;
		if(firstMark == lastMark){
			if(lang=='en'){
				alert("Date of Reunion format incorrect");
			}else{
				alert("重聚日期格式不正確");
			}
			objFrm.Reunion.focus();
			return false;
		}else{
			RYear = objFrm.Reunion.value.substring(0, firstMark);
			RMonth = objFrm.Reunion.value.substring(firstMark+1, lastMark);
			RDay = objFrm.Reunion.value.substring(lastMark+1, strLen);
			
			if(RMonth < 10) RMonth = "0"+parseInt(RMonth, 10);
			if(RDay < 10 ) RDay = "0"+parseInt(RDay, 10);
			
			ReunionDate = RYear + "-" + RMonth + "-" + RDay;
			
			if(!isValidDate(ReunionDate)){
				if(lang=='en'){
					alert("Invalid Reunion Date Entry!");
				}else{
					alert("不正確的日期");
				}
				objFrm.Reunion.focus();
				return false;
			}else{
				d1 = new Date(DateObj.getFullYear(), DateObj.getMonth()+1, DateObj.getDate());
				d2 = new Date(RYear, RMonth, RDay);
				
				if (d1.getTime()<d2.getTime()) {
					if(lang=='en'){
						alert("Invalid Reunion Date Entry!");
					}else{
						alert("重聚日期不正確");
					}
					return false;
				}
			}
		}
    }

	if(objFrm.contact_person.value.length == 0){
		if(lang=='en'){
			alert("Please fill in Contact Person");
		}else{
			alert("請輸入聯絡人");
		}
		objFrm.contact_person.focus();
		return false;
	}
	
	if(objFrm.contact_no.value.length == 0){
		if(lang=='en'){
			alert("Please fill in Contact No");
		}else{
			alert("請輸入聯絡電話");
		}
		objFrm.contact_no.focus();
		return false;
	}
	
	if(objFrm.pwd.value.length == 0){
		if(lang=='en'){
			alert("Please enter Password");
		}else{
			alert("請輸入更新密碼");
		}
		objFrm.pwd.focus();
		return false;
	}
	
	if(objFrm.pwd.value.length < 4){
		if(lang=='en'){
			alert("Password should not less than 4 characters");
		}else{
			alert("密碼不可少於4個字元");
		}
		objFrm.pwd.focus();
		return false;
	}
	
	if(objFrm.c_pwd.value.length == 0){
		if(lang=='en'){
			alert("Please enter the confirm Password");
		}else{
			alert("請輸入確定密碼");
		}
		objFrm.c_pwd.focus();
		return false;
	}
	
	if(objFrm.c_pwd.value!=objFrm.pwd.value){
		if(lang=='en'){
			alert("Password incorrect");
		}else{
			alert("密碼不正確");
		}
		objFrm.pwd.focus();
		return false;
	}

	if(objFrm.Email.value.length > 0){
		if(!checkMail(objFrm.Email.value)){
			if(lang=='en'){
				alert("Invalid Email Entry!");
			}else{
				alert("不正確的電郵地址");
			}
			objFrm.Email.focus();
			return false;
		}
	}

	PYear = objFrm.Year.value;
	PMonth = objFrm.Month.value;
	PDay = objFrm.Day.value;

	if(PMonth < 10) PMonth = "0"+PMonth;
	if(PDay < 10 ) PDay = "0"+PDay;
	
	PostDate = PYear + "-" + PMonth + "-" + PDay;
	
	if(!isValidDate(PostDate)){
		if(lang=='en'){
			alert("Invalid Date Entry!");
		}else{
			alert("不正確的日期");
		}
		objFrm.Day.focus();
		return false;
	}else{
		d1 = new Date(DateObj.getFullYear(), DateObj.getMonth()+1, DateObj.getDate());
		d2 = new Date(PYear, PMonth, PDay);
		
		if (d1.getTime()<d2.getTime()) {
			if(lang=='en'){
				alert("Invalid Date Entry!");
			}else{
				alert("不正確的日期");
			}
			return false;
		}
	}

	objFrm.submit();
}

function checkMail(inEmail)
{
	var x = inEmail;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function viewDetail(ID, Page)
{
	frm01.ID.value=ID;
	frm01.PageNo.value=Page;
	frm01.submit();
}

function checkFrm_search(lang){
	if(search_frm.search_key.value==""){
		if(lang=='en'){
			alert("Please enter the Keyword!!");
		}else{
			alert("請輸入關鍵字!!");
		}
		search_frm.search_key.focus();
		return false;
	}
	
	search_frm.submit();
}

function checkFrm2(objFrm, lang){
	var checkFlage = true;
	var radio_choice = false;

	for(count=0;count<objFrm.radio_Button.length;count++){
		if(objFrm.radio_Button[count].checked == true){
			radio_choice = true;
			selectCount = count;
		}
	}
	
	if(radio_choice != false){
		objFrm.searchType.value = objFrm.radio_Button[selectCount].value;
		checkFlage = true;
	}

	if(objFrm.search_species.value!=""){
		checkFlage = true;
	}
	
	if(objFrm.search_breed.value!=""){
		checkFlage = true;
	}
	
	if(objFrm.search_sex.value!=""){
		checkFlage = true;
	}
	
	if(objFrm.search_Age.value!=""){
		checkFlage = true;
	}
	
	if(objFrm.search_district.value!=""){
		checkFlage = true;
	}
	
	PYear = objFrm.search_Year.value;
	PMonth = objFrm.search_Month.value;
	PDay = objFrm.search_Day.value;

	if(PMonth < 10) PMonth = "0"+PMonth;
	if(PDay < 10 ) PDay = "0"+PDay;
	
	PostDate = PYear + "-" + PMonth + "-" + PDay;
	
	if(!isValidDate(PostDate)){
		if(lang=='en'){
			alert("Invalid Date Entry!");
		}else{
			alert("不正確的日期!");
		}
		objFrm.search_Day.focus();
		return false;
	}

	if(checkFlage){
		objFrm.submit();
/*	}else{
		alert("Please select at least one item for searching");
		return false;*/
	}
}

function changeLang(lang){
	if(location.href.toString().lastIndexOf(".asp") > 0){
		frm01.lang.value = lang;
		frm01.action = location.href.toString().substring(location.href.toString().lastIndexOf("/")+1, location.href.toString().lastIndexOf(".asp")+4);
		frm01.action = frm01.action + "?lang=" + frm01.lang.value;
//		alert(frm01.action);
		frm01.submit();
/*
		if(frm01.ID.value!=""){
			tmpValue = "&ID="+frm01.ID.value;
		}else{
			tmpValue = "";
		}
		document.location = location.href.toString().substring(location.href.toString().lastIndexOf("/")+1, location.href.toString().lastIndexOf(".asp")+4) + "?lang=" + lang + tmpValue;
*/
	}else{
		document.location = "index.asp?lang=" + lang;
	}
}

function PopWin(url,page,x,y,z){
	eval("nw = window.open(url, page,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,pageXOffset=0,pageYOffset=0,top=0,left=" + z + ",width=" + x + ",height=" + y + "')");
	if ( nw.focus != null)
	{nw.focus();}
}

function searchSimilar(type, species, district){
	frm02.searchType.value=type;
	frm02.search_species.value=species;
	frm02.search_district.value=district;
	frm02.submit();
}