function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("input");
    for(var i=0;i<els.length;i++)
        if(re.test(els[i].className) && els[i].style.display=='inline')
	    break;
    return els[i];
}


function Set_Cookies(form)
{
    var temp = 0;
    temp = parseInt(form.fd.selectedIndex)+parseInt(1);
    document.cookie = "arrivalDate=" + temp + "-" + document.DateSelect.fm.options[document.DateSelect.fm.selectedIndex].text + "-" + document.DateSelect.fy.options[document.DateSelect.fy.selectedIndex].text;
    temp = parseInt(form.coutfd.selectedIndex)+parseInt(1);
    document.cookie = "departureDate=" + temp + "-" + document.DateSelect.coutfm.options[document.DateSelect.coutfm.selectedIndex].text  + "-" + document.DateSelect.coutfy.options[document.DateSelect.coutfy.selectedIndex].text;
}

function Get_Cookie(name) {

	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}



  /******************************
  * Editable section -- Start --
  ******************************/
  // DATE SETTINGS - EDIT AS REQUIRED
  var daysinAdvance = 1; // Sets default days in advance from current date
  var numberNights = 1;  // Sets default number of nights
  var numberYears = 2; // Sets default number of years to display in year select list
  var numberNightsMin = 1; // Sets minimum number of nights accepted
  var imgDir = "images/"; // Directory for the dynamic calendar script and images. Trailing slash must be included.

  // FLAG SETTINGS ON/OFF - SET TO 1 FOR ON & 0 FOR OFF
  var wdDisplay = 1; //weekday display
  var numberNightsDisplay = 0; //number of nights display
  var departDateDisplay = 0; //departure dates display
  var departDateUpdate = 0; //auto update departure date

  // WEEK DAY AND NUMBER NIGHTS TEXT - EDIT TEXT AS REQUIRED
  var wdArray = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
  var nightTxt = " Night";
  var nightsTxt = " Nights";


  /**************************************************
  * DO NOT CHANGE JAVASCRIPT SETTINGS BELOW THIS LINE
  **************************************************/
  //Days in each month Array
  var aNumDays = new Array (31,0,31,30,31,30,31,31,30,31,30,31);

    //Update form with selected dates
  function updateDates(form, loadDates) {
    //check Leap Year
    if(form.fm.selectedIndex==1)  {
      var leapYear  = new Date (form.fy.options[form.fy.selectedIndex].text,form.fm.selectedIndex+1,1);
      var leapYear  = new Date (leapYear  - (24*60*60*1000));
      var numDaysInMonth = leapYear.getDate();
    }else{
      var numDaysInMonth = aNumDays[form.fm.selectedIndex];
     }
    
    if(form.fd.selectedIndex+1 > numDaysInMonth) {
      alert("Invalid Date!");
      form.fd.selectedIndex = numDaysInMonth-1;
    }
  }
  
    function updateDatesCOut(form, loadDates) {
    //check Leap Year
    if(form.coutfm.selectedIndex==1)  {
      var leapYear  = new Date (form.coutfy.options[form.coutfy.selectedIndex].text,form.coutfm.selectedIndex+1,1);
      var leapYear  = new Date (leapYear  - (24*60*60*1000));
      var numDaysInMonth = leapYear.getDate();
    }else{
      var numDaysInMonth = aNumDays[form.coutfm.selectedIndex];
     }
    
    if(form.coutfd.selectedIndex+1 > numDaysInMonth) {
      alert("Invalid Date!");
      form.coutfd.selectedIndex = numDaysInMonth-1;
    }
  }


   function setWkd(form, calendar) {
    // change form object if returned from calendar
    if(calendar) form = document.forms[form];
    for (var i = 0; i < form.fy.length; i++) {
      if (form.fy.options[i].selected) var fyear = form.fy.options[i].text;
      if (departDateDisplay == 1 && form.ty.options[i].selected) var tyear = form.ty.options[i].text;
    }
    var checkinDate = new Date(fyear,form.fm.selectedIndex,form.fd.selectedIndex+1);
    if (departDateDisplay == 1) var checkoutDate = new Date(tyear,form.tm.selectedIndex,form.td.selectedIndex+1);
    var numNights = Math.round((checkoutDate - checkinDate) / 86400000);
    if (numNights == 1) numNights += nightTxt;
    else numNights += nightsTxt;
    //Set Days of the week display
    if(wdDisplay == 1 && document.getElementById) {
      document.getElementById('inWd').firstChild.nodeValue = '(' + wdArray[checkinDate.getDay()] + ')';
      if (departDateDisplay == 1) document.getElementById('outWd').firstChild.nodeValue = '(' + wdArray[checkoutDate.getDay()] + ')';
    }
    //Set number of nights display
    if(numberNightsDisplay == 1 && document.getElementById) document.getElementById('lengthStay').firstChild.nodeValue = numNights;
  }
  
  function setWkdCOut(form, calendar) {
    // change form object if returned from calendar
    if(calendar) form = document.forms[form];
    for (var i = 0; i < form.coutfy.length; i++) {
      if (form.coutfy.options[i].selected) var fyear = form.coutfy.options[i].text;
    }
    var checkinDate = new Date(fyear,form.coutfm.selectedIndex,form.coutfd.selectedIndex+1);
    //Set Days of the week display
    if(wdDisplay == 1 && document.getElementById) {
      document.getElementById('outWd').firstChild.nodeValue = '(' + wdArray[checkinDate.getDay()] + ')';
    }
    //Set number of nights display
    if(numberNightsDisplay == 1 && document.getElementById) document.getElementById('lengthStay').firstChild.nodeValue = numNights;
  }

   //Load current dates on form load
  function LoadDates(form) {
    var curDate = new Date();
    var setDate = new Date(curDate.getTime() + (daysinAdvance * 86400000));
    var setDay = setDate.getDate();
    var setMonth = setDate.getMonth();
    var setYear = setDate.getFullYear() - form.fy.options[0].text;
    // Set Arrival Dates
    form.fd.selectedIndex = setDay-1;
    form.fm.selectedIndex = setMonth;
    form.fy.selectedIndex = setYear;
    // Set the Departure Dates
    updateDates(form, departDateDisplay);
    if(wdDisplay == 1 || numberNightsDisplay == 1) setWkd(form);
  }

  function LoadDatesCOut(form) {
    var curDate = new Date();
    var setDate = new Date(curDate.getTime() + ((daysinAdvance + 1) * 86400000));
    var setDay = setDate.getDate();
    var setMonth = setDate.getMonth();
    var setYear = setDate.getFullYear() - form.coutfy.options[0].text;
    // Set Arrival Dates
    form.coutfd.selectedIndex = setDay-1;
    form.coutfm.selectedIndex = setMonth;
    form.coutfy.selectedIndex = setYear;
    // Set the Departure Dates
    updateDatesCOut(form, departDateDisplay);
    if(wdDisplay == 1 || numberNightsDisplay == 1) setWkdCOut(form);
  }

 
  //Generate years options for year select list
  function year_option(form){
    curDate = new Date();
    curYear = curDate.getFullYear();
    for(i = curYear ; i <= curYear+(numberYears-1) ; i++ ){
      document.write('<option value="' + i + '">' + i + '</option>');
    }
  }
  
  
  errMessage = "";
  
  function checkDates(arrivalDateString,departureDateString){   
    var monArray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec");
    var DDMMYY = arrivalDateString.split('-');
    var arrivalDate = new Date();
    var i = 0;
    for(i=0;i<11;i++){
     if(monArray[i]==DDMMYY[1]){
       break;
      }
    }
    arrivalDate.setFullYear(DDMMYY[2],i,DDMMYY[0]);
    DDMMYY = departureDateString.split('-');
    var departureDate = new Date();
    for(i=0;i<11;i++){
     if(monArray[i]==DDMMYY[1]){
       break;
      }
    }
    departureDate.setFullYear(DDMMYY[2],i,DDMMYY[0]);
    var today = new Date();
    if(arrivalDate<today){
	errMessage = "Arrival Date cannot be prior to Today";
	return false;
    }
    else if(departureDate<arrivalDate){
	errMessage = "Departure Date cannot be prior to Arrival Date"
	return false;
    }
   return true;
  }

function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      errMessage = "Please Enter a Valid Email Address";
      return false;
   }
  return true;
}
  
  
  function validateInquiry(form){
    var rValue = false;
    if(form.txtFirstName.value==""){
	errMessage = "Please Enter Your First Name";
    }
    else if(form.txtArrivalDate.value==""){
	errMessage = "Please Enter the Date of Arrival";
    }
    else if(form.txtDepartureDate.value==""){
	errMessage = "Please Enter the Date of Departure";
    }
    else if(!checkDates(form.txtArrivalDate.value,form.txtDepartureDate.value)){
	rValue = false;
    }
    else if(!validateEmail(form.txtEmail.value)){
        rValue = false;
    }
    else{
	rValue = true;
    }
    if (!rValue){
    alert(errMessage);
    }
    return rValue;
  }

