
////////// Check Null of Apartment ///////
function checkApartmentsNull(){
   form = document.apartmentForm;
   
   if(form.PreName.value == ""){
     alert('please fill in title');
	 form.PreName.focus();
	 return false;
   }
   if(form.firstName.value == ""){
     alert('please fill in firstname');
	 form.firstName.focus();
	 return false;
   }
    if(form.lastName.value == ""){
     alert('please fill in lastname');
	 form.lastName.focus();
	 return false;
   }
    if((form.Gender[0].checked == false) && (form.Gender[1].checked == false)){
     alert('please fill in gender');
	// form.Gender.focus();
	 return false;
   }
    if(form.dbDay.value == ""){
     alert('please fill in date of birth (day)');
	 form.dbDay.focus();
	 return false;
   }
    if(form.dbMonth.value == ""){
     alert('please fill in date of birth (month)');
	 form.dbMonth.focus();
	 return false;
   }
    if(form.dbYear.value == ""){
     alert('please fill date of birth (year)');
	 form.dbYear.focus();
	 return false;
   }
    if(form.Nation.value == ""){
     alert('please fill in nationality');
	 form.Nation.focus();
	 return false;
   }
   /*
   if(form.Address.value == ""){
     alert('please fill in address');
	 form.Address.focus();
	 return false;
   }
  if(form.City.value == ""){
     alert('please fill in city');
	 form.City.focus();
	 return false;
   }
   if(form.Province.value == ""){
     alert('please fill in state/province');
	 form.Province.focus();
	 return false;
   }
    if(form.Country.value == ""){
     alert('please select country');
	 form.Country.focus();
	 return false;
   }   
   */
   //// check format email ////

  if(form.Email.value == ""){
     alert('please fill in email address');
	 form.Email.focus();
	 return false;
   }

   if(echeck(form.Email.value)==1){
		alert("Invalid your email is not correct!");
		form.Email.focus() ;
		return false;
	}

 	if(form.NumRoom.value == ""){
     alert('please fill in No. of room');
	 form.NumRoom.focus();
	 return false;
   }

   if(!validateInt(form.NumRoom)){
     alert('No. of room must be integer');
     form.NumRoom.value = "";
	 form.NumRoom.focus();
	 return false;
   }

	 if(form.RoomType.value == ""){
     alert('please fill in room type');
	 form.RoomType.focus();
	 return false;
   }
	 if(form.BedType.value == ""){
     alert('please fill in bed type');
	 form.BedType.focus();
	 return false;
   }
 	if(form.NumAdult.value == ""){
     alert('please fill in adults');
	 form.NumAdult.focus();
	 return false;
   }

   if(!validateInt(form.NumAdult)){
     alert('adult must be integer');
	 form.NumAdult.value = "";
	 form.NumAdult.focus();
	 return false;
   }

 	if(form.NumChild.value == ""){
     alert('please fill in children');
	 form.NumChild.focus();
	 return false;
   }

   if(!validateInt(form.NumChild)){
     alert('child must be integer');
	 form.NumChild.value = "";
	 form.NumChild.focus();
	 return false;
   }

   if(form.CheckInDate.value == ""){
     alert('please fill in check-in date');
	 form.CheckInDate.focus();
	 return false;
   }
    if(form.CheckOutDate.value == ""){
     alert('please fill in check-out date');
	 form.CheckOutDate.focus();
	 return false;
   }
 	if(form.DepFrom.value == ""){
     alert('please fill in departure from');
	 form.DepFrom.focus();
	 return false;
   }
   if(form.ArrivalDate.value == ""){
     alert('please fill in arrival date');
	 form.ArrivalDate.focus();
	 return false;
   }
    if(form.avHour.value == ""){
     alert('please fill in arrival time(hour)');
	 form.avHour.focus();
	 return false;
   }
    if(form.avMinute.value == ""){
     alert('please fill in arrival time(minute)');
	 form.avMinute.focus();
	 return false;
   }
    if(form.avAmPm.value == ""){
     alert('please fill in arrival time(Am or Pm)');
	 form.avAmPm.focus();
	 return false;
   }
   
    
   return true;

}


////////// Check Null of Inquiry ///////
function checkInquiryNull(){
   form = document.inquiryForm;  
  
	if(form.Title.value == ""){
		 alert('please select title');
		 form.Title.focus();
		 return false;
	}

   if(form.Firstname.value == ""){
     alert('please fill in firstname');
	 form.Firstname.focus();
	 return false;
   }
    if(form.Lastname.value == ""){
     alert('please fill in lastname');
	 form.Lastname.focus();
	 return false;
   }

   if(form.Gender.value == ""){
		 alert('please select gender');
		 form.Gender.focus();
		 return false;	
   }

    if(form.dbDay.value == ""){
     alert('please fill in date of birth');
	 form.dbDay.focus();
	 return false;
   }
    if(form.dbMonth.value == ""){
     alert('please fill in month of birth');
	 form.dbMonth.focus();
	 return false;
   }
    if(form.dbYear.value == ""){
     alert('please fill in year of birth');
	 form.dbYear.focus();
	 return false;
   }
    if(form.Country.value == ""){
     alert('please select country of residence');
	 form.Country.focus();
	 return false;
   }
 	if(form.Nation.value == ""){
     alert('please select your nationality');
	 form.Nation.focus();
	 return false;
   }

//// check format email ////
	if(form.Email.value == ""){
     alert('please fill in email address');
	 form.Email.focus();
	 return false;
   }

   /*
	if (form.Email.value != "") {
	var Email=form.Email.value;

	if (Email.indexOf(' ')==-1 && 0<Email.indexOf('@') && Email.indexOf('@')+1 < Email.length) return true;
	else alert ("Your format email address wrong")
	return false;
	}
 	/// End ////
    */

	 if(form.Inquiry.value == ""){
     alert('please select inquiry type');
	 form.Inquiry.focus();
	 return false;
   }
	 if(form.PresentIll.value == ""){
     alert('please fill in present illness');
	 form.PresentIll.focus();
	 return false;
   }

   if(form.captchatext.value != form.captchapix.value){
     alert('Security text mismatch, please try again.');
	 form.captchatext.focus();
	 return false;
   } 
    
   return true;

}


//check email
function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);

		if ((str==null)||(str=="")){
			return -1;
		}

		if (str.indexOf(at)==-1){
			return 1;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			return 1;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			return 1;
		}

		if (str.indexOf(at,(lat+1))!=-1){
			return 1;
		}

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return 1;
		}

		if (str.indexOf(dot,(lat+2))==-1){
			return 1;
		}

		if (str.indexOf(" ")!=-1){
			return 1;
		}

		return 0;

	}





/////////////// Radio for Apartment ///////////////////
function radioChange(radioValue){
    if (radioValue =="0"){
   window.location= 'index.php?p=serviceApartment&flag=0';
    }
    
    if (radioValue =="1"){
   window.location= 'index.php?p=serviceApartment&flag=1';
    }
}

/////////////// Radio for Apartment ///////////////////
function radioChangeApartment(radioValue){
    if (radioValue =="0"){
   window.location= 'index.php?p=serviceApartment&flag=0';
    }
    
    if (radioValue =="1"){
   window.location= 'index.php?p=serviceApartment&flag=1';
    }
}

///////////// Check Null of Greeting Card //////////////

function checkGreetingCardNull(){
   form = document.greetingCardForm;
 
   if(form.PatientFirstname .value == ""){
     alert('please fill in patient firstname ');
	 form.PatientFirstname.focus();
	 return false;
   }
   if(form.PatientLastname.value == ""){
		 alert('please fill in patient lastname');
		 form.PatientLastname.focus();
		 return false;
   }
   if(form.PatientRoomNo.value == ""){
		 alert('please fill in room number');
		 form.PatientRoomNo.focus();
		 return false;
   }
   if(form.SenderFirstname.value == ""){
		 alert('please fill in sender firstname');
		 form.SenderFirstname.focus();
		 return false;
   }
   if(form.SenderLastname.value == ""){
		 alert('please fill in sender lastname');
		 form.SenderLastname.focus();
		 return false;
   }
   if(form.SenderEmail.value == ""){
     alert('please fill in email address');
	 form.SenderEmail.focus();
	 return false;
   }

   if(echeck(form.SenderEmail.value)==1){
		alert("Invalid your email is not correct!");
		form.SenderEmail.focus() ;
		return false;
	}
     
 return true;
}

