// goes to tours booking form
function goToToursForm () {
	document.frmTours.submit();
}

/****************************************
		PLC Booking Form
****************************************/

// checks if data is null
function pal_isNull(strText) {
	if(strText == "") 
		return true;
	else 
		return false;
}

// removes whitespaces
function pal_trim(strText){
  var ewan=null;
  var i=0;
  var j=parseInt(strText.length-1);
  
  while(strText.charAt(i)==" ")
  	i++;
  
  while(strText.charAt(j)==" ")
  	j--;
  
  if(j==-1) 
  	return strText.substring(0,0);
  else 
  	return strText.substring(i,j+1);
} 

// checks validity of email address
function pal_checkEmail(strEmail) {
	var atPos = strEmail.indexOf("@");
	var stopPos = strEmail.lastIndexOf(".");
	var ch;
	var checkAT = 0;
	var IsEmail;
	var message = "true";

	if (strEmail == "") 
		message = "false";

	// checks for @ and .
	if (atPos == -1 || stopPos == -1) 
		message = "false";

	// checks if @ is used first before .
	if (stopPos < atPos) 
		message = "false";

	// checks if . does not follow @ immediately
	if (stopPos - atPos == 1)
		message = "false";
	
	// checks for spaces	
	if (strEmail.indexOf(" ") != -1) 
		message = "false";
		
	// checks for invalid characters
	for(i=0; i<parseInt(strEmail.length); i++) {
		ch= strEmail.charAt(i)
		
		//Check for more than 1 '@' character
		if (ch == "@") {
			checkAT = checkAT + 1;
			if (checkAT >= 2) {
				IsEmail = false;
				break;
			}
		}
		
		if ((( ch >= "A") && (ch <= "Z")) || ((ch >= "a") && (ch <= "z")) || ((ch >= "0") && (ch <= "9")) ||
		(ch == "-") || (ch == ".") || (ch == "@") || (ch == "_")) {
			IsEmail= true;
		} else {
			IsEmail= false;
			break;
		}
	}
	
	if (!IsEmail) 
		message = "false";

	return message;
}

function clearPLCForm() {
	document.frmPLC.reset();
}

function validatePLCForm() {
	var frmtName = /^[A-Za-z\-\.\s]+$/;
	var frmtPhoneNum =  /^[\d\(\)\-\+]+$/;
	var frmtChars = /^[A-Za-z0-9\.\-\&\s]+$/;
	var frmtNumPlus = /^[0-9\.]+$/;
	var frmtDate = /^[0-9A-Za-z\-\.\s]+$/;

	var msgName = "Alpha characters only with or without space/s";
	var msgPhoneNum = "Numeric characters, parentheses (), dash (-), and plus (+) only";
	var msgChars = "Alphanumeric characters, dash (-), and ampersand (&) only with or without space/s";
	var msgNumPlus = "Numeric characters and decimal point (.) only";
	var msgDate = "Alphanumeric characters, dash (-), period (.), slash (\), and comma (,) only with or without white space/s";
	
	var strName = pal_trim(document.frmPLC.name.value);
	var strEmail = document.frmPLC.email.value;
	var strCourse = pal_trim(document.frmPLC.courseTitle.value);
	var strDesignation = pal_trim(document.frmPLC.designation.value);
	var strCompany = pal_trim(document.frmPLC.company.value);
	var strCompAddress = pal_trim(document.frmPLC.companyAddress.value);
	var strCompPhone = pal_trim(document.frmPLC.companyPhone.value);
	var strHomeAddress = pal_trim(document.frmPLC.homeAddress.value);
	var strHomePhone = pal_trim(document.frmPLC.homePhone.value);
	var strFax = pal_trim(document.frmPLC.fax.value); 
	var strDate = pal_trim(document.frmPLC.preferredDates.value);
	var strFee = pal_trim(document.frmPLC.courseFee.value);

	var error = "";

	if (pal_isNull(strName)) 
		error = error + " - Name\n";
	if (pal_isNull(strEmail))
		error = error + " - Email Address\n";
	if (pal_isNull(strCourse))	
		error = error + " - Course Title\n";

	if (error != "")
		alert("Please fill in the following data:\n\n" + error + "\n\n");
	else {
		if (!frmtName.test(strName))
			error = error + " - Name - " + msgName + "\n";
		if (! (pal_isNull(strDesignation) || frmtChars.test(strDesignation)) )
			error = error + " - Designation - " + msgChars + "\n";
		if (! (pal_isNull(strCompany) || frmtChars.test(strCompany)) )
			error = error + " - Company - " + msgChars + "\n";
		if (! (pal_isNull(strCompAddress) || frmtChars.test(strCompAddress)) )
			error = error + " - Company Address - " + msgChars + "\n";
		if (! (pal_isNull(strCompPhone) || frmtPhoneNum.test(strCompPhone)) )
			error = error + " - Company Phone Number - " + msgPhoneNum + "\n";
		if (pal_checkEmail(strEmail) == "false")
			error = error + " - Email Address\n";
		if (! (pal_isNull(strHomeAddress) || frmtChars.test(strHomeAddress)) )
			error = error + " - Home Address - " + msgChars + "\n";
		if (! (pal_isNull(strHomePhone) || frmtPhoneNum.test(strHomePhone)) )
			error = error + " - Home Phone Number - " + msgPhoneNum + "\n";
		if (! (pal_isNull(strFax) || frmtPhoneNum.test(strFax)) )
			error = error + " - Fax Number - " + msgPhoneNum + "\n";
		if (!frmtChars.test(strCourse))
			error = error + " - Course Title - " + msgChars + "\n";
		if (! (pal_isNull(strDate) || frmtDate.test(strDate)) )
			error = error + " - Preferred Dates - " + msgDate + "\n";
		if (! (pal_isNull(strFee) || frmtNumPlus.test(strFee)) )
			error = error + " - Course Fee - " + msgNumPlus + "\n";
		if (error != "")
			alert("Please enter valid data for the following:\n\n" + error + "\n\n");
		else
			document.frmPLC.submit();	
	}


}


/****************************************************
		Tours Booking Form
****************************************************/
// populate year
function pal_populateYear(){
	d = new Date();
	yearNow = d.getFullYear();
	yearNext = d.getFullYear() + 1;
	alert(yearNow);
alert(yearNext);
	if (document.frmTours.check_in_year1 != null) {
		document.frmTours.check_in_year1.options[0].text="";
		document.frmTours.check_in_year1.options[0].value="";
		document.frmTours.check_in_year1.options[1].text=yearNow;
		document.frmTours.check_in_year1.options[1].value=yearNow;
		document.frmTours.check_in_year1.options[2].text=yearNext;
		document.frmTours.check_in_year1.options[2].value=yearNext;
		
		document.frmTours.check_out_year1.options[0].text="";
		document.frmTours.check_out_year1.options[0].value="";
		document.frmTours.check_out_year1.options[1].text=yearNow;
		document.frmTours.check_out_year1.options[1].value=yearNow;
		document.frmTours.check_out_year1.options[2].text=yearNext;
		document.frmTours.check_out_year1.options[2].value=yearNext;
	}
	
	if (document.frmTours.check_in_year2 != null) {
		document.frmTours.check_in_year2.options[0].text="";
		document.frmTours.check_in_year2.options[0].value="";
		document.frmTours.check_in_year2.options[1].text=yearNow;
		document.frmTours.check_in_year2.options[1].value=yearNow;
		document.frmTours.check_in_year2.options[2].text=yearNext;
		document.frmTours.check_in_year2.options[2].value=yearNext;
		
		document.frmTours.check_out_year2.options[0].text="";
		document.frmTours.check_out_year2.options[0].value="";
		document.frmTours.check_out_year2.options[1].text=yearNow;
		document.frmTours.check_out_year2.options[1].value=yearNow;
		document.frmTours.check_out_year2.options[2].text=yearNext;
		document.frmTours.check_out_year2.options[2].value=yearNext;
	}
	
	if (document.frmTours.check_in_year3 != null) {
		document.frmTours.check_in_year3.options[0].text="";
		document.frmTours.check_in_year3.options[0].value="";
		document.frmTours.check_in_year3.options[1].text=yearNow;
		document.frmTours.check_in_year3.options[1].value=yearNow;
		document.frmTours.check_in_year3.options[2].text=yearNext;
		document.frmTours.check_in_year3.options[2].value=yearNext;
		
		document.frmTours.check_out_year3.options[0].text="";
		document.frmTours.check_out_year3.options[0].value="";
		document.frmTours.check_out_year3.options[1].text=yearNow;
		document.frmTours.check_out_year3.options[1].value=yearNow;
		document.frmTours.check_out_year3.options[2].text=yearNext;
		document.frmTours.check_out_year3.options[2].value=yearNext;
	}
} 

// validate form
function validateTourForm(){
	var frmtName = /^[A-Za-z\-\.\s]+$/;
	var frmtNum =  /^[\d]+$/;
	var frmtAlphaNum = /^[A-Za-z0-9\s]+$/;
	var frmtNumPlus = /^[0-9\-]+$/;
	var frmtChars = /^[A-Za-z0-9\.\-\&\s]+$/;
	var frmtPhoneNum = /^[0-9\-\(\)\+]+$/;
	var frmtComments = /^[A-Za-z0-0\.\,\-\@\s]+$/;

	var intItinerary = document.frmTours.itinerary.value;
	var intHotel = document.frmTours.hotel.value;
	var strNameFrom = pal_trim(document.frmTours.nameFrom.value);
	var strNameTo = pal_trim(document.frmTours.nameTo.value);
	var strNameStopover = pal_trim(document.frmTours.nameStopover.value);
	
	var strDayLeaving1 = pal_trim(document.frmTours.day_leaving1.value);
	var strMonthLeaving1 = pal_trim(document.frmTours.month_leaving1.value);
	var strTimeLeaving1 = pal_trim(document.frmTours.time_leaving1.value);
	var strClassLeaving1 = pal_trim(document.frmTours.class_leaving1.value);
	var strYearLeaving1 = "";
	
	var strDayLeaving2 = pal_trim(document.frmTours.day_leaving2.value);
	var strMonthLeaving2 = pal_trim(document.frmTours.month_leaving2.value);
	var strTimeLeaving2 = pal_trim(document.frmTours.time_leaving2.value);
	var strClassLeaving2 = pal_trim(document.frmTours.class_leaving2.value);
	var strYearLeaving2 = "";
	
	if (intItinerary == "4") {
		var strDayLeaving3 = pal_trim(document.frmTours.day_leaving3.value);
		var strMonthLeaving3 = pal_trim(document.frmTours.month_leaving3.value);
		var strTimeLeaving3 = pal_trim(document.frmTours.time_leaving3.value);
		var strClassLeaving3 = pal_trim(document.frmTours.class_leaving3.value);
		var strYearLeaving3 = "";
		
		var strDayLeaving4 = pal_trim(document.frmTours.day_leaving4.value);
		var strMonthLeaving4 = pal_trim(document.frmTours.month_leaving4.value);
		var strTimeLeaving4 = pal_trim(document.frmTours.time_leaving4.value);
		var strClassLeaving4 = pal_trim(document.frmTours.class_leaving4.value);
		var strYearLeaving4 = "";
	}
	
	var strOptionalTours = pal_trim(document.frmTours.optional_tours.value);
	var strTicketCountry1 = pal_trim(document.frmTours.ticket_country1.value);	
	
	var strHotelName1 = pal_trim(document.frmTours.hotel_name1.value);
	var strCheckInDay1 = pal_trim(document.frmTours.check_in_day1.value);
	var strCheckInMonth1 = pal_trim(document.frmTours.check_in_month1.value);
	var strCheckInYear1 = pal_trim(document.frmTours.check_in_year1.value);
	var strCheckOutDay1 = pal_trim(document.frmTours.check_out_day1.value);
	var strCheckOutMonth1 = pal_trim(document.frmTours.check_out_month1.value);
	var strCheckOutYear1 = pal_trim(document.frmTours.check_out_year1.value);
	var strRoomType1 = pal_trim(document.frmTours.type_room1.value);

	//with stopover
	if (intHotel == "3") {
		var strHotelName2 = pal_trim(document.frmTours.hotel_name2.value);
		var strCheckInDay2 = pal_trim(document.frmTours.check_in_day2.value);
		var strCheckInMonth2 = pal_trim(document.frmTours.check_in_month2.value);
		var strCheckInYear2 = pal_trim(document.frmTours.check_in_year2.value);
		var strCheckOutDay2 = pal_trim(document.frmTours.check_out_day2.value);
		var strCheckOutMonth2 = pal_trim(document.frmTours.check_out_month2.value);
		var strCheckOutYear2 = pal_trim(document.frmTours.check_out_year2.value);
		var strRoomType2 = pal_trim(document.frmTours.type_room2.value);
		
		var strHotelName3 = pal_trim(document.frmTours.hotel_name3.value);
		var strCheckInDay3 = pal_trim(document.frmTours.check_in_day3.value);
		var strCheckInMonth3 = pal_trim(document.frmTours.check_in_month3.value);
		var strCheckInYear3 = pal_trim(document.frmTours.check_in_year3.value);
		var strCheckOutDay3 = pal_trim(document.frmTours.check_out_day3.value);
		var strCheckOutMonth3 = pal_trim(document.frmTours.check_out_month3.value);
		var strCheckOutYear3 = pal_trim(document.frmTours.check_out_year3.value);
		var strRoomType3 = pal_trim(document.frmTours.type_room3.value);
	}		
	
	var strLastName1 = pal_trim(document.frmTours.last_name1.value);
	var strFirstName1 = pal_trim(document.frmTours.first_name1.value);
	var strMabuhayClubCardNumber1 = pal_trim(document.frmTours.mabuhay_club_card_number1.value);
	var strAge1 = pal_trim(document.frmTours.age1.value);
	var strInfantSeat1 = pal_trim(document.frmTours.infant_seat1.value);
	var strTypeAccommodation1 = pal_trim(document.frmTours.type_accommodation1.value)
	
	var strLastName2 = pal_trim(document.frmTours.last_name2.value);
	var strFirstName2 = pal_trim(document.frmTours.first_name2.value);
	var strMabuhayClubCardNumber2 = pal_trim(document.frmTours.mabuhay_club_card_number2.value);
	var strAge2 = pal_trim(document.frmTours.age2.value);
	var strInfantSeat2 = pal_trim(document.frmTours.infant_seat2.value);
	var strTypeAccommodation2 = pal_trim(document.frmTours.type_accommodation2.value)
	
	var strLastName3 = pal_trim(document.frmTours.last_name3.value);
	var strFirstName3 = pal_trim(document.frmTours.first_name3.value);
	var strMabuhayClubCardNumber3 = pal_trim(document.frmTours.mabuhay_club_card_number3.value);
	var strAge3 = pal_trim(document.frmTours.age3.value);
	var strInfantSeat3 = pal_trim(document.frmTours.infant_seat3.value);
	var strTypeAccommodation3 = pal_trim(document.frmTours.type_accommodation3.value)
	
	var strLastName4 = pal_trim(document.frmTours.last_name4.value);
	var strFirstName4 = pal_trim(document.frmTours.first_name4.value);
	var strMabuhayClubCardNumber4 = pal_trim(document.frmTours.mabuhay_club_card_number4.value);
	var strAge4 = pal_trim(document.frmTours.age4.value);
	var strInfantSeat4 = pal_trim(document.frmTours.infant_seat4.value);
	var strTypeAccommodation4 = pal_trim(document.frmTours.type_accommodation4.value)
	
	var strLastName5 = pal_trim(document.frmTours.last_name5.value);
	var strFirstName5 = pal_trim(document.frmTours.first_name5.value);
	var strMabuhayClubCardNumber5 = pal_trim(document.frmTours.mabuhay_club_card_number5.value);
	var strAge5 = pal_trim(document.frmTours.age5.value);
	var strInfantSeat5 = pal_trim(document.frmTours.infant_seat5.value);
	var strTypeAccommodation5 = pal_trim(document.frmTours.type_accommodation5.value)
	
	var strLastName6 = pal_trim(document.frmTours.last_name6.value);
	var strFirstName6 = pal_trim(document.frmTours.first_name6.value);
	var strMabuhayClubCardNumber6 = pal_trim(document.frmTours.mabuhay_club_card_number6.value);
	var strAge6 = pal_trim(document.frmTours.age6.value);
	var strInfantSeat6 = pal_trim(document.frmTours.infant_seat6.value);
	var strTypeAccommodation6 = pal_trim(document.frmTours.type_accommodation6.value)
	
	var strLastName7 = pal_trim(document.frmTours.last_name7.value);
	var strFirstName7 = pal_trim(document.frmTours.first_name7.value);
	var strMabuhayClubCardNumber7 = pal_trim(document.frmTours.mabuhay_club_card_number7.value);
	var strAge7 = pal_trim(document.frmTours.age7.value);
	var strInfantSeat7 = pal_trim(document.frmTours.infant_seat7.value);
	var strTypeAccommodation7 = pal_trim(document.frmTours.type_accommodation7.value)
	
	var strName = pal_trim(document.frmTours.name.value);
	var strEmail = document.frmTours.email.value;
	var strHomePhone = pal_trim(document.frmTours.home_phone_no.value);
	var strBusinessPhone = pal_trim(document.frmTours.business_phone_no.value);
	var strComments = pal_trim(document.frmTours.comments.value);
	
	var error = "";
	var strLeavingDate = "";
	var strCheckInDate = "";
	var strCheckOutDate = "";
	var errnum = "";

	if (pal_isNull(strDayLeaving1)) 
		error = error + " - 1st Itinerary - Day\n";
	if (pal_isNull(strMonthLeaving1))
		error = error + " - 1st Itinerary - Month\n";
	if (pal_isNull(strTimeLeaving1))
		error = error + " - 1st Itinerary - Approx. Time\n";
	if (pal_isNull(strClassLeaving1))
		error = error + " - 1st Itinerary - Class\n";
		
	// with stopover
	if (intItinerary == "4") {
		if (pal_isNull(strDayLeaving2)) 
			error = error + " - 2nd Itinerary - Day\n";
		if (pal_isNull(strMonthLeaving2))
			error = error + " - 2nd Itinerary - Month\n";
		if (pal_isNull(strTimeLeaving2))
			error = error + " - 2nd Itinerary - Approx. Time\n";
		if (pal_isNull(strClassLeaving2))
			error = error + " - 2nd Itinerary - Class\n";
			
		// if not required but at least one field has a value
		if (!pal_isNull(strDayLeaving3) || !pal_isNull(strMonthLeaving3) || !pal_isNull(strTimeLeaving3) || !pal_isNull(strClassLeaving3)) {
			if (pal_isNull(strDayLeaving3)) 
				error = error + " - 3rd Itinerary - Day\n";
			if (pal_isNull(strMonthLeaving3))
				error = error + " - 3rd Itinerary - Month\n";
			if (pal_isNull(strTimeLeaving3))
				error = error + " - 3rd Itinerary - Approx. Time\n";
			if (pal_isNull(strClassLeaving3))
				error = error + " - 3rd Itinerary - Class\n";
		}	
		if (!pal_isNull(strDayLeaving4) || !pal_isNull(strMonthLeaving4) || !pal_isNull(strTimeLeaving4) || !pal_isNull(strClassLeaving4)) {
			if (pal_isNull(strDayLeaving4)) 
				error = error + " - 4th Itinerary - Day\n";
			if (pal_isNull(strMonthLeaving4))
				error = error + " - 4th Itinerary - Month\n";
			if (pal_isNull(strTimeLeaving4))
				error = error + " - 4th Itinerary - Approx. Time\n";
			if (pal_isNull(strClassLeaving4))
				error = error + " - 4th Itinerary - Class\n";
		}	
	}
	// if not required but at least one field has a value
	else {
		if (!pal_isNull(strDayLeaving2) || !pal_isNull(strMonthLeaving2) || !pal_isNull(strTimeLeaving2) || !pal_isNull(strClassLeaving2)) {
			if (pal_isNull(strDayLeaving2)) 
				error = error + " - 2nd Itinerary - Day\n";
			if (pal_isNull(strMonthLeaving2))
				error = error + " - 2nd Itinerary - Month\n";
			if (pal_isNull(strTimeLeaving2))
				error = error + " - 2nd Itinerary - Approx. Time\n";
			if (pal_isNull(strClassLeaving2))
				error = error + " - 2nd Itinerary - Class\n";
		}	
	}

	if (pal_isNull(strTicketCountry1))
		error = error + " - City to Buy the Holiday Package\n";		

	// no stopover
	if (intHotel == "1") {
		if (pal_isNull(strHotelName1)) 
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Hotel Name\n";
		if (pal_isNull(strCheckInDay1))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-in Day\n";
		if (pal_isNull(strCheckInMonth1))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-in Month\n";
		if (pal_isNull(strCheckInYear1))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-in Year\n";
		if (pal_isNull(strCheckOutDay1))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-out Day\n";
		if (pal_isNull(strCheckOutMonth1))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-out Month\n";
		if (pal_isNull(strCheckOutYear1))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-out Year\n";
	}
	// with stopover
	else {
		if (!pal_isNull(strHotelName1) || !pal_isNull(strCheckInDay1) || !pal_isNull(strCheckInMonth1) || !pal_isNull(strCheckInYear1) || !pal_isNull(strCheckOutDay1) || !pal_isNull(strCheckOutMonth1) || !pal_isNull(strCheckOutYear1) ) {
			if (pal_isNull(strCheckInDay1))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-in Day\n";
			if (pal_isNull(strCheckInMonth1))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-in Month\n";
			if (pal_isNull(strCheckInYear1))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-in Year\n";
			if (pal_isNull(strCheckOutDay1))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-out Day\n";
			if (pal_isNull(strCheckOutMonth1))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-out Month\n";
			if (pal_isNull(strCheckOutYear1))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-out Year\n";
		}
		
		if (pal_isNull(strHotelName2)) 
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Hotel Name\n";
		if (pal_isNull(strCheckInDay2))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-in Day\n";
		if (pal_isNull(strCheckInMonth2))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-in Month\n";
		if (pal_isNull(strCheckInYear2))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-in Year\n";
		if (pal_isNull(strCheckOutDay2))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-out Day\n";
		if (pal_isNull(strCheckOutMonth2))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-out Month\n";
		if (pal_isNull(strCheckOutYear2))
			error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-out Year\n";
			
		if (!pal_isNull(strHotelName3) || !pal_isNull(strCheckInDay3) || !pal_isNull(strCheckInMonth3) || !pal_isNull(strCheckInYear3) || !pal_isNull(strCheckOutDay3) || !pal_isNull(strCheckOutMonth3) || !pal_isNull(strCheckOutYear3)) {
			if (pal_isNull(strCheckInDay3))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-in Day\n";
			if (pal_isNull(strCheckInMonth3))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-in Month\n";
			if (pal_isNull(strCheckInYear3))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-in Year\n";
			if (pal_isNull(strCheckOutDay3))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-out Day\n";
			if (pal_isNull(strCheckOutMonth3))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-out Month\n";
			if (pal_isNull(strCheckOutYear3))
				error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-out Year\n";
		}
	}

	if (pal_isNull(strLastName1))
		error = error + " - Passenger 1 - Last Name\n"; 		
	if (pal_isNull(strFirstName1))
		error = error + " - Passenger 1 - First Name\n"; 
 	
	if (!pal_isNull(strLastName2) || !pal_isNull(strFirstName2) || !pal_isNull(strMabuhayClubCardNumber2) || !pal_isNull(strAge2) || !pal_isNull(strInfantSeat2) || !pal_isNull(strTypeAccommodation2)) {
		if (pal_isNull(strLastName2))
			error = error + " - Passenger 2 - Last Name\n";
		if (pal_isNull(strFirstName2))
			error = error + " - Passenger 2 - First Name\n";
	}
	if (!pal_isNull(strLastName3) || !pal_isNull(strFirstName3) || !pal_isNull(strMabuhayClubCardNumber3) || !pal_isNull(strAge3) || !pal_isNull(strInfantSeat3) || !pal_isNull(strTypeAccommodation3)) {
		if (pal_isNull(strLastName3))
			error = error + " - Passenger 3 - Last Name\n";
		if (pal_isNull(strFirstName3))
			error = error + " - Passenger 3 - First Name\n";

	}
	if (!pal_isNull(strLastName4) || !pal_isNull(strFirstName4) || !pal_isNull(strMabuhayClubCardNumber4) || !pal_isNull(strAge4) || !pal_isNull(strInfantSeat4) || !pal_isNull(strTypeAccommodation4)) {
		if (pal_isNull(strLastName4))
			error = error + " - Passenger 4 - Last Name\n";
		else if (!frmtName.test(strLastName4))
			error = error + " - Passenger 4 - Valid Last Name - Alphanumeric characters only with or without space/s.\n";
		if (pal_isNull(strFirstName4))
			error = error + " - Passenger 4 - First Name\n";
		else if (!frmtName.test(strFirstName4))
			error = error + " - Passenger 4 - Valid First Name - Alphanumeric characters only with or without space/s.\n";
	}
	if (!pal_isNull(strLastName5) || !pal_isNull(strFirstName5) || !pal_isNull(strMabuhayClubCardNumber5) || !pal_isNull(strAge5) || !pal_isNull(strInfantSeat5) || !pal_isNull(strTypeAccommodation5)) {
		if (pal_isNull(strLastName5))
			error = error + " - Passenger 5 - Last Name\n";
		if (pal_isNull(strFirstName5))
			error = error + " - Passenger 5 - First Name\n";
	}
	if (!pal_isNull(strLastName6) || !pal_isNull(strFirstName6) || !pal_isNull(strMabuhayClubCardNumber6) || !pal_isNull(strAge6) || !pal_isNull(strInfantSeat6) || !pal_isNull(strTypeAccommodation6)) {
		if (pal_isNull(strLastName6))
			error = error + " - Passenger 6 - Last Name\n";
		if (pal_isNull(strFirstName6))
			error = error + " - Passenger 6 - First Name\n";
	}
	if (!pal_isNull(strLastName7) || !pal_isNull(strFirstName7) || !pal_isNull(strMabuhayClubCardNumber7) || !pal_isNull(strAge7) || !pal_isNull(strInfantSeat7) || !pal_isNull(strTypeAccommodation7)) {
		if (pal_isNull(strLastName7))
			error = error + " - Passenger 7 - Last Name\n";
		if (pal_isNull(strFirstName7))
			error = error + " - Passenger 7 - First Name\n";
	}
	
	if (pal_isNull(strName))
		error = error + " - Contact Person - Name\n"; 
	if (pal_isNull(strEmail))
		error = error + " - Contact Person - Email\n";

	if (error != "")
		alert("Please fill in the following data:\n\n" + error + "\n\n");
	else {
		d = new Date();
		yearNow = d.getYear();
		monthNow = d.getMonth() + 1; // January is 0
		dateNow = d.getDate();
		yearNext = d.getYear() + 1;
		
		strLeavingYear1 = yearNow;
		strLeavingYear2 = yearNow;
		strLeavingYear3 = yearNow;
		strLeavingYear4 = yearNow;
		
		if(strDayLeaving1 < 10)
			strDayLeaving1 = "0" + strDayLeaving1;	
		if (pal_check2Dates(dateNow,monthNow,yearNow,strDayLeaving1,strMonthLeaving1,yearNow) == "1")
			strLeavingYear1 = yearNext;
		
		// validate 1st flight date		
		strLeavingDate = strDayLeaving1 + "-" + strMonthLeaving1 + "-" + strLeavingYear1;
		if (checkPALDate(strLeavingDate)>0)
			error = error + " - 1st Itinerary - Leaving Date\n";			
		
		// validate 2nd flight date
		if (!pal_isNull(strDayLeaving2) || !pal_isNull(strMonthLeaving2)) {
			if(strDayLeaving2 < 10)
				strDayLeaving2 = "0" + strDayLeaving2;	
			if (pal_check2Dates(dateNow,monthNow,yearNow,strDayLeaving2,strMonthLeaving2,yearNow) == "1")
				strLeavingYear2 = yearNext;
			strLeavingDate = strDayLeaving2 + "-" + strMonthLeaving2 + "-" + strLeavingYear2;
			if (checkPALDate(strLeavingDate)>0)
				error = error + " - 2nd Itinerary - Leaving Date\n";		
		}
		if (intItinerary == "4") {
			// validate 3rd flight date
			if (!pal_isNull(strDayLeaving3) || !pal_isNull(strMonthLeaving3)) {
				if(strDayLeaving3 < 10)
					strDayLeaving3 = "0" + strDayLeaving2;	
				if (pal_check2Dates(dateNow,monthNow,yearNow,strDayLeaving3,strMonthLeaving3,yearNow) == "1")
					strLeavingYear3 = yearNext;
				strLeavingDate = strDayLeaving3 + "-" + strMonthLeaving3 + "-" + strLeavingYear3;
				if (checkPALDate(strLeavingDate)>0)
					error = error + " - 3rd Itinerary - Leaving Date\n";		
			}
			
			// validate 4th flight date
			if (!pal_isNull(strDayLeaving4) || !pal_isNull(strMonthLeaving4)) {
				if(strDayLeaving4 < 10)
					strDayLeaving4 = "0" + strDayLeaving2;	
				if (pal_check2Dates(dateNow,monthNow,yearNow,strDayLeaving4,strMonthLeaving4,yearNow) == "1")
					strLeavingYear4 = yearNext;
				strLeavingDate = strDayLeaving4 + "-" + strMonthLeaving4 + "-" + strLeavingYear4;
				if (checkPALDate(strLeavingDate)>0)
					error = error + " - 4th Itinerary - Leaving Date\n";		
			}
		}
		
		// validate 1st hotel dates
		if (!pal_isNull(strCheckInDay1) || !pal_isNull(strCheckInMonth1) || !pal_isNull(strCheckInYear1) || !pal_isNull(strCheckOutDay1) || !pal_isNull(strCheckOutMonth1) || !pal_isNull(strCheckOutYear1)) {
			if(strCheckInDay1 < 10)
				strCheckInDay1 = "0" + strCheckInDay1;	
			strCheckInDate = strCheckInDay1 + "-" + strCheckInMonth1 + "-" + strCheckInYear1;
			
			if(strCheckOutDay1 < 10)
				strCheckOutDay1 = "0" + strCheckOutDay1;			
			strCheckOutDate = strCheckOutDay1 + "-" + strCheckOutMonth1 + "-" + strCheckOutYear1;
			
			if (intHotel == "1") {
				if (checkPALDate(strCheckInDate)>0)
					error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-in Date\n";
				if (checkPALDate(strCheckOutDate)>0)
					error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-out Date\n"
			}
			else {
				if (checkPALDate(strCheckInDate)>0)
					error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-in Date\n";
				if (checkPALDate(strCheckOutDate)>0)
					error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-out Date\n"
			}
		}
		
		if (intHotel == "3") {
			// validate 2nd hotel dates
			if (!pal_isNull(strCheckInDay2) || !pal_isNull(strCheckInMonth2) || !pal_isNull(strCheckInYear2) || !pal_isNull(strCheckOutDay2) || !pal_isNull(strCheckOutMonth2) || !pal_isNull(strCheckOutYear2)) {
				if(strCheckInDay2 < 10)
					strCheckInDay2 = "0" + strCheckInDay2;	
				strCheckInDate = strCheckInDay2 + "-" + strCheckInMonth2 + "-" + strCheckInYear2;
				
				if(strCheckOutDay2 < 10)
					strCheckOutDay2 = "0" + strCheckOutDay2;			
				strCheckOutDate = strCheckOutDay2 + "-" + strCheckOutMonth2 + "-" + strCheckOutYear2;
				
				if (checkPALDate(strCheckInDate)>0)
					error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-in Date\n";
				if (checkPALDate(strCheckOutDate)>0)
					error = error + " - Hotel Accommodation in "+ strNameTo +" - Check-out Date\n"
			}
			
			// validate 3rd hotel dates
			if (!pal_isNull(strCheckInDay3) || !pal_isNull(strCheckInMonth3) || !pal_isNull(strCheckInYear3) || !pal_isNull(strCheckOutDay3) || !pal_isNull(strCheckOutMonth3) || !pal_isNull(strCheckOutYear3)) {
				if(strCheckInDay3 < 10)
					strCheckInDay3 = "0" + strCheckInDay3;	
				strCheckInDate = strCheckInDay3 + "-" + strCheckInMonth3 + "-" + strCheckInYear3;
				
				if(strCheckOutDay3 < 10)
					strCheckOutDay3 = "0" + strCheckOutDay2;			
				strCheckOutDate = strCheckOutDay3 + "-" + strCheckOutMonth3 + "-" + strCheckOutYear3;
				
				if (checkPALDate(strCheckInDate)>0)
					error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-in Date\n";
				if (checkPALDate(strCheckOutDate)>0)
					error = error + " - Hotel Accommodation in "+ strNameStopover +" - Check-out Date\n"
			}
		}

		//CHECK IF VALID
		if (! (pal_isNull(strOptionalTours) || frmtChars.test(strOptionalTours)) )
			error = error + " - Optional Tours - Alphanumeric characters, dash (-), and ampersand (&) only with or without space/s\n";

		//CHECK IF VALID HOTEL INPUT
		if (strHotelName1 != "") {
			if (!frmtAlphaNum.test(strHotelName1))
				error = error + " - Hotel Name - Alphanumeric characters only with or without space/s.\n";
			if (strRoomType1 != "" && !frmtName.test(strRoomType1))
				error = error + " - Room Type - Alpha characters only with or without space/s.\n";
		}
		if (strHotelName2 != "") {
			if (!frmtAlphaNum.test(strHotelName2))
				error = error + " - Hotel Name #2 - Alphanumeric characters only with or without space/s.\n";
			if (strRoomType2 != "" && !frmtName.test(strRoomType2))
				error = error + " - Room Type #2 - Alpha characters only with or without space/s.\n";
		}

		if (strHotelName3 != "") {
			if (!frmtAlphaNum.test(strHotelName3))
				error = error + " - Hotel Name #3 - Alphanumeric characters only with or without space/s.\n";
			if (strRoomType3 != "" && !frmtName.test(strRoomType3) )
				error = error + " - Room Type #3 - Alpha characters only with or without space/s.\n";
		}

		//CHECK IF VALID PASSENGER INPUT
		if (strLastName1 != "") {
			if (!frmtName.test(strLastName1))
				error = error + " - Passenger 1 - Last Name - Alpha characters only with or without space/s\n";
			if (!frmtName.test(strFirstName1))
				error = error + " - Passenger 1 - First Name - Alpha characters only with or without space/s.\n";
			if (strMabuhayClubCardNumber1 != "" && !frmtNum.test(strMabuhayClubCardNumber1))
				error = error + " - Passenger 1 - Mabuhay Miles Card Number - Numeric characters only.\n";
			if (strAge1 != "" && !frmtNumPlus.test(strAge1))
				error = error + " - Passenger 1 - Child's Age or Infant's Birthday - Numeric characters and dash (-) only.\n";
		}
		if (strLastName2 != "") {
			if (!frmtName.test(strLastName2))
				error = error + " - Passenger 2 - Last Name - Alpha characters only with or without space/s\n";
			if (!frmtName.test(strFirstName2))
				error = error + " - Passenger 2 - First Name - Alpha characters only with or without space/s.\n";
			if (strMabuhayClubCardNumber2 != "" && !frmtNum.test(strMabuhayClubCardNumber2))
				error = error + " - Passenger 2 - Mabuhay Miles Card Number - Numeric characters only.\n";
			if (strAge2 != "" && !frmtNumPlus.test(strAge2))
				error = error + " - Passenger 2 - Child's Age or Infant's Birthday - Numeric characters and dash (-) only.\n";
		}
		if (strLastName3 != "") {
			if (!frmtName.test(strLastName3))
				error = error + " - Passenger 3 - Last Name - Alpha characters only with or without space/s\n";
			if (!frmtName.test(strFirstName3))
				error = error + " - Passenger 3 - First Name - Alpha characters only with or without space/s.\n";
			if (strMabuhayClubCardNumber3 != "" && !frmtNum.test(strMabuhayClubCardNumber3))
				error = error + " - Passenger 3 - Mabuhay Miles Card Number - Numeric characters only.\n";
			if (strAge3 != "" && !frmtNumPlus.test(strAge3))
				error = error + " - Passenger 3 - Child's Age or Infant's Birthday - Numeric characters and dash (-) only.\n";
		}

		if (strLastName4 != "") {
			if (!frmtName.test(strLastName4))
				error = error + " - Passenger 4 - Last Name - Alpha characters only with or without space/s\n";
			if (!frmtName.test(strFirstName4))
				error = error + " - Passenger 4 - First Name - Alpha characters only with or without space/s.\n";
			if (strMabuhayClubCardNumber4 != "" && !frmtNum.test(strMabuhayClubCardNumber4))
				error = error + " - Passenger 4 - Mabuhay Miles Card Number - Numeric characters only.\n";
			if (strAge4 != "" && !frmtNumPlus.test(strAge4))
				error = error + " - Passenger 4 - Child's Age or Infant's Birthday - Numeric characters and dash (-) only.\n";
		}
		if (strLastName5 != "") {
			if (!frmtName.test(strLastName5))
				error = error + " - Passenger 5 - Last Name - Alpha characters only with or without space/s\n";
			if (!frmtName.test(strFirstName5))
				error = error + " - Passenger 5 - First Name - Alpha characters only with or without space/s.\n";
			if (strMabuhayClubCardNumber5 != "" && !frmtNum.test(strMabuhayClubCardNumber5))
				error = error + " - Passenger 5 - Mabuhay Miles Card Number - Numeric characters only.\n";
			if (strAge5 != "" && !frmtNumPlus.test(strAge5))
				error = error + " - Passenger 5 - Child's Age or Infant's Birthday - Numeric characters and dash (-) only.\n";
		}
		if (strLastName6 != "") {
			if (!frmtName.test(strLastName6))
				error = error + " - Passenger 6 - Last Name - Alpha characters only with or without space/s\n";
			if (!frmtName.test(strFirstName6))
				error = error + " - Passenger 6 - First Name - Alpha characters only with or without space/s.\n";
			if (strMabuhayClubCardNumber6 != "" && !frmtNum.test(strMabuhayClubCardNumber6))
				error = error + " - Passenger 6 - Mabuhay Miles Card Number - Numeric characters only.\n";
			if (strAge6 != "" && !frmtNumPlus.test(strAge6))
				error = error + " - Passenger 6 - Child's Age or Infant's Birthday - Numeric characters and dash (-) only.\n";
		}
		if (strLastName7 != "") {
			if (!frmtName.test(strLastName7))
				error = error + " - Passenger 7 - Last Name - Alpha characters only with or without space/s\n";
			if (!frmtName.test(strFirstName7))
				error = error + " - Passenger 7 - First Name - Alpha characters only with or without space/s.\n";
			if (strMabuhayClubCardNumber7 != "" && !frmtNum.test(strMabuhayClubCardNumber7))
				error = error + " - Passenger 7 - Mabuhay Miles Card Number - Numeric characters only.\n";
			if (strAge7 != "" && !frmtNumPlus.test(strAge7))
				error = error + " - Passenger 7 - Child's Age or Infant's Birthday - Numeric characters and dash (-) only.\n";
		}

		//CHECK IF VALID CONTACT NAME
		if  (!frmtName.test(strName))
			error = error + " - Contact Person - Name - Alpha characters only with or without space/s.\n";
		//CHECK IF VALID PHONE NUMBERS
		if (! (pal_isNull(strHomePhone) || frmtPhoneNum.test(strHomePhone)) )
			error = error + " - Home Telephone No. - Numeric characters, parentheses (), dash (-), and plus (+) only\n";
		if (! (pal_isNull(strBusinessPhone) || frmtPhoneNum.test(strBusinessPhone)) )
			error = error + " - Business Telephone No. - Numeric characters, parentheses (), dash (-), and plus (+) only\n";

		// CHECK IF VALID EMAIL
		if (pal_checkEmail(strEmail) == "false")
			error = error + " - Email Address\n";

		//CHECK IF VALID COMMENTS/OTHER INFORMATION
		if (! (pal_isNull(strComments) || frmtComments.test(strComments)) )
			error = error + " - Comments/Other Information - Alphanumeric characters, period (.), comma (,), dash (-), @ sign, with or without space/s\n";
			
		if (error != "")
			alert("Please enter valid data for the following:\n\n" + error + "\n\n");
		else {
			// there is a value for itinerary 2, check with previous itinerary date
			if (!pal_isNull(strDayLeaving2) || !pal_isNull(strMonthLeaving2)) 
				if (pal_check2Dates(strDayLeaving1,strMonthLeaving1,strLeavingYear1,strDayLeaving2,strMonthLeaving2,strLeavingYear2) == 1) {
					alert("2nd Itinerary leaving date must be later than 1st Itinerary leaving date");
					error = "1";
				}
				
			if (intItinerary == "4") {	
				// there is a value for itinerary 3, check with previous itinerary date
				if (!pal_isNull(strDayLeaving3) || !pal_isNull(strMonthLeaving3)) 
					if (pal_check2Dates(strDayLeaving2,strMonthLeaving2,strLeavingYear2,strDayLeaving3,strMonthLeaving3,strLeavingYear3) == 1) {
						alert("3rd Itinerary leaving date must be later than 2nd Itinerary leaving date");
						error = "1";
					}
						
				// there is a value for itinerary 4, check with previous itinerary date
				if (!pal_isNull(strDayLeaving4) || !pal_isNull(strMonthLeaving4)) 
					if (pal_check2Dates(strDayLeaving3,strMonthLeaving3,strLeavingYear3,strDayLeaving4,strMonthLeaving4,strLeavingYear4) == 1) {
						alert("3rd Itinerary leaving date must be later than 4th Itinerary leaving date");
						error = "1";
					}
			}
				
			var errNum;
			// check 1st hotel dates
			if (!pal_isNull(strCheckInDay1) || !pal_isNull(strCheckInMonth1) || !pal_isNull(strCheckInYear1) || !pal_isNull(strCheckOutDay1) || !pal_isNull(strCheckOutMonth1) || !pal_isNull(strCheckOutYear1)) {
				errNum = pal_check2Dates(strCheckInDay1,strCheckInMonth1,strCheckInYear1,strCheckOutDay1,strCheckOutMonth1,strCheckOutYear1);
				if (errNum == 1) {
					if (intHotel == "1")
						alert("Hotel Accommodation in "+ strNameTo +" check-out date must be later than check-in date");
					else
						alert("Hotel Accommodation in "+ strNameStopover +" check-out date must be later than check-in date");
					error = "1";
				}
				else if (errNum == 2) {
					if (intHotel == "1")
						alert("Hotel Accommodation in "+ strNameTo +" check-out date must not be more than one month after check-in date");
					else
						alert("Hotel Accommodation in "+ strNameStopover +" check-out date must not be more than one month after check-in date");
					error = "1";
				}
			}
			
			if (intHotel == "3") {			
				// check 2nd hotel dates
				if (!pal_isNull(strCheckInDay2) || !pal_isNull(strCheckInMonth2) || !pal_isNull(strCheckInYear2) || !pal_isNull(strCheckOutDay2) || !pal_isNull(strCheckOutMonth2) || !pal_isNull(strCheckOutYear2)) {
					errNum = pal_check2Dates(strCheckInDay2,strCheckInMonth2,strCheckInYear2,strCheckOutDay2,strCheckOutMonth2,strCheckOutYear2);
					if (errNum == 1) {
						alert("Hotel Accommodation in "+ strNameTo +" check-out date must be later than check-in date");
						error = "1";
					}
					else if (errNum == 2) {
						alert("Hotel Accommodation in "+ strNameTo +" check-out date must not be more than one month after check-in date");
						error = "1";
					}
					else {
						if (!pal_isNull(strCheckInDay1) || !pal_isNull(strCheckInMonth1) || !pal_isNull(strCheckInYear1) || !pal_isNull(strCheckOutDay1) || !pal_isNull(strCheckOutMonth1) || !pal_isNull(strCheckOutYear1)) {
							if (pal_check2Dates(strCheckOutDay1,strCheckOutMonth1,strCheckOutYear1,strCheckInDay2,strCheckInMonth2,strCheckInYear2) == 1) {
								alert("Check-in date for hotel accommodation in "+ strNameTo +" must be later than check-out date for hotel accommodation in "+ strNameStopover);
								error = "1";
							}
						}
					}
				}		// if no 2nd hotel dates
				
				// check 3rd hotel dates
				if (!pal_isNull(strCheckInDay3) || !pal_isNull(strCheckInMonth3) || !pal_isNull(strCheckInYear3) || !pal_isNull(strCheckOutDay3) || !pal_isNull(strCheckOutMonth3) || !pal_isNull(strCheckOutYear3)) {
					errNum = pal_check2Dates(strCheckInDay3,strCheckInMonth3,strCheckInYear3,strCheckOutDay3,strCheckOutMonth3,strCheckOutYear3);
					if (errNum == 1) {
						alert("Hotel Accommodation in "+ strNameStopover +" check-out date must be later than check-in date");
						error = "1";
					}
					else if (errNum == 2) {
						alert("Hotel Accommodation in "+ strNameStopover +" check-out date must not be more than one month after check-in date");
						error = "1";
					}
					else {
						if (pal_check2Dates(strCheckOutDay2,strCheckOutMonth2,strCheckOutYear2,strCheckInDay3,strCheckInMonth3,strCheckInYear3) == 1) {
							alert("Check-in date for hotel accommodation in "+ strNameStopover +" check-in date must be later than check-out date for hotel accommodation in "+ strNameTo);
							error = "1";
						}
					}
				}	 // if no 3rd hotel dates
			} // else inthotel == 3
		}	
			
		if (error == "")
			document.frmTours.submit();
	}
}

function clearToursForm() {
	document.frmTours.reset();
}

// checks if valid date
function checkPALDate(field){
	var mm = field.substr(3,3);
	if (mm == "Jan")
		mm = "01";
	else if (mm == "Feb")
		mm = "02";
	else if (mm == "Mar")
		mm = "03";
	else if (mm == "Apr")
		mm = "04";
	else if (mm == "May")
		mm = "05";
	else if (mm == "Jun")
		mm = "06";
	else if (mm == "Jul")
		mm = "07";
	else if (mm == "Aug")
		mm = "08";
	else if (mm == "Sep")
		mm = "09";
	else if (mm == "Oct")
		mm = "10";
	else if (mm == "Nov")
		mm = "11";
	else if (mm == "Dec")
		mm = "12";
	else
		mm = "13";
		
	var checkstr = "0123456789";
	var DateField = field.substr(0,3) + mm + field.substring(7);
	
	var Datevalue = "";
	var DateTemp = "";
	var seperator = ".";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
	err = 0;
  
	DateValue = DateField;
	/* Delete all chars except 0..9 */
	for (i = 0; i < DateValue.length; i++) 
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0)
			DateTemp = DateTemp + DateValue.substr(i,1);
			
	DateValue = DateTemp;
	/* Always change date to 8 digits - string*/
	/* if year is entered as 2-digit / always assume 20xx */
	if (DateValue.length == 6) 
		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); 
	//if (DateValue.length != 8) 
	//	err = 19; 
	/* year is wrong if year = 0000 */
	year = DateValue.substr(4,4);
	if (year == 0) 
		err = 20;
      
	/* Validation of month*/
	month = DateValue.substr(2,2);
	if ((month < 1) || (month > 12)) 
		err = 21;

	/* Validation of day*/
	day = DateValue.substr(0,2);
	if (day < 1) 
		err = 22;
		
	/* Validation leap-year / february / day */
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0))
		leap = 1;
		
	if ((month == "02") && (leap == 1) && (day > 29)) 
		err = 23;
		
	if ((month == "02") && (leap != 1) && (day > 28)) 
		err = 24;
   
	/* Validation of other months */
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) 
		err = 25;

	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) 
		err = 26;

	/* if 00 is entered, no error, deleting the entry */
	if ((day == 0) && (month == 0) && (year == 00)) 
		err = 0; day = ""; month = ""; year = ""; seperator = "";
 
	return err;
}

// check if date out is later than date in
function pal_check2Dates(dayIn,monthIn,yearIn,dayOut,monthOut,yearOut) {
	var err = 0;
	var dateIn = new Date;
	var dateOut = new Date;
	
	var mm = monthIn;
	if (mm == "Jan" || mm == "1")
		mm = "00";
	else if (mm == "Feb" || mm == "2")
		mm = "01";
	else if (mm == "Mar" || mm == "3")
		mm = "02";
	else if (mm == "Apr" || mm == "4")
		mm = "03";
	else if (mm == "May" || mm == "5")
		mm = "04";
	else if (mm == "Jun" || mm == "6")
		mm = "05";
	else if (mm == "Jul" || mm == "7")
		mm = "06";
	else if (mm == "Aug" || mm == "8")
		mm = "07";
	else if (mm == "Sep" || mm == "9")
		mm = "08";
	else if (mm == "Oct" || mm == "10")
		mm = "09";
	else if (mm == "Nov" || mm == "11")
		mm = "10";
	else if (mm == "Dec" || mm == "12")
		mm = "11";
	else 
		mm = "12";

	dateIn.setDate(dayIn);
	dateIn.setMonth(mm);
	dateIn.setFullYear(yearIn);
	
	mm = monthOut;
	if (mm == "Jan" || mm == "1")
		mm = "00";
	else if (mm == "Feb" || mm == "2")
		mm = "01";
	else if (mm == "Mar" || mm == "3")
		mm = "02";
	else if (mm == "Apr" || mm == "4")
		mm = "03";
	else if (mm == "May" || mm == "5")
		mm = "04";
	else if (mm == "Jun" || mm == "6")
		mm = "05";
	else if (mm == "Jul" || mm == "7")
		mm = "06";
	else if (mm == "Aug" || mm == "8")
		mm = "07";
	else if (mm == "Sep" || mm == "9")
		mm = "08";
	else if (mm == "Oct" || mm == "10")
		mm = "09";
	else if (mm == "Nov" || mm == "11")
		mm = "10";
	else if (mm == "Dec" || mm == "12")
		mm = "11";
	else 
		mm = "12";
	
	dateOut.setDate(dayOut);
	dateOut.setMonth(mm);
	dateOut.setFullYear(yearOut);
	
	diffDays = (Math.round((dateOut - dateIn)/864e5)) - 1;
	
	if(dateIn >= dateOut)
		err = "1";
	else if (diffDays >= 30)
		err = "2";
	
	return err;
}
