function check_rates_info(){
    var ids = document.getElementById('idliststr');
    if(ids != null){
        var idarr = ids.value.split(',');
        var i;
        //alert('Checking rate info.');
        for(i=0; i<=idarr.length; i++){
            var pstr = "price[" + idarr[i] + "]";
            var mpstr = "min_price[" + idarr[i] + "]";
            var p = document.getElementById(pstr);
            var mp = document.getElementById(mpstr);
            if(p != null){
                if(mp != null){
                    if(p.value < mp.value){
                        alert('The room price must be greater than the minimum price.');
                        p.focus();
                        return false;
                    }
                }
            }
        }
    }
    //alert('Rates all seem correct.');
    return true;
}

var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strMonth=dtStr.substring(0,pos1)
    var strDay=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)
    strYr=strYear
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }
    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)
    if (pos1==-1 || pos2==-1){
        alert("The date format should be : mm-dd-yyyy")
        return false
    }
    if (strMonth.length<1 || month<1 || month>12){
        alert("Please enter a valid month")
        return false
    }
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        alert("Please enter a valid day")
        return false
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
        return false
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
        alert("Please enter a valid date")
        return false
    }
return true
}

function validateme(){     
	var f = document.resform;
	var sdate = document.getElementById('check_in');
	var edate = document.getElementById('check_out');
	if((sdate == null) || (edate == null)){
		alert('You must choose an arrival AND departure date.');
		return false;
	}
	if((sdate.value == '') || (edate.value == '')){
		alert('You must choose an arrival AND departure date.');
		return false;
	}
    
      
	if (isDate(sdate.value)==false){
		sdate.focus();
		return false
	}else if (isDate(edate.value)==false){
		edate.focus() ;
		return false
	}
	var startDate  = sdate.value;
	var endDate = edate.value;
	startYear = startDate.substr(6,4) -0;
	startMonth = startDate.substr(0,2) - 1
	startMonth = (startMonth < 0)?0:startMonth;
	startDay = startDate.substr(3,2) - 0;
	startDate = new Date (startYear, startMonth, startDay);
	endYear = endDate.substr(6,4) -0;
	endMonth = endDate.substr(0,2) - 1;
	endMonth = (endMonth < 0)?0:endMonth;
	endDay = endDate.substr(3,2) - 0;
	endDate = new Date (endYear, endMonth, endDay);
if (startDate > endDate){
		alert("Your Departure Date must be greater than the Arrival Date");
		edate.focus() ;  
		return false;
	}
	return true;
}

function selectAll() {
	d = document.roomlistform;
	for (i = 0; i < d.elements.length; i++) {
		if (d.elements[i].type == "checkbox") {
			d.elements[i].checked = true;
		}
	}
}

function deselectAll() {
	d = document.roomlistform;
	for (i = 0; i < d.elements.length; i++) {
		if (d.elements[i].type == "checkbox") {
			d.elements[i].checked = false;
		}
	}
}

function setImage(img){
	var image=img;
	document.getElementById("largeimage").style.visibility="visible"; 
	document.getElementById("largeimage").style.backgroundImage="url("+image+")";
	document.getElementById("largeimage").style.height = "380px";
	document.getElementById("largeimage").style.width = "250px";
}

function resetImage(){
	document.getElementById("largeimage").style.backgroundImage="";
	document.getElementById("largeimage").style.visibility="hidden";
	document.getElementById("largeimage").style.height = "1px";
	document.getElementById("largeimage").style.width = "1px";
}

function dash_replace(f,v){
    //replaces dashes with slashes in input date field(s)
    //alert("Replacing dashes with slashes");
    myString = new String(v);
    rExp = /\//g;
    newString = new String ("-")
    results = myString.replace(rExp, newString)
    f.value = results;
}

function special_pop(){
    //not used - return
    return true;
}

function clearMenuList(){
    	for (var i = 1; i <= 6; i++) {
		var obj = document.getElementById(i);
		if(obj != null){
			obj.style.display = "none";
		}
	}
}

function toggleMenuList(whichLayer){
	clearMenuList();
	if (document.getElementById){
		var obj = document.getElementById(whichLayer);
		// this is the way the standards work
		if(obj != null){
			var style2 = obj.style;
			if(style2.display == 'block'){
				style2.display = "none";
			}else{
				style2.display = "block";
			}
		}
	}else if (document.all){
		// this is the way old msie versions work
		var obj = document.all[whichLayer];
		if(obj != null){
			var style2 = obj.style;
			if(style2.display == 'block'){
				style2.display = "none";
			}else{
				style2.display = "block";
			}
		}
	}else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		if(style2.display == 'block'){
			style2.display = "none";
		}else{
			style2.display = "block";
		}
	}
	return false;
}

function toggleLayer(whichLayer, onoff){
	// onoff = "" - hide layer
	// onoff = "block" = show layer
	if (document.getElementById){
		// this is the way the standards work
		if(document.getElementById(whichLayer) != null){
			var style2 = document.getElementById(whichLayer).style;
			style2.display = onoff;
		}
	}else if (document.all){
		// this is the way old msie versions work
		if(document.all[whichLayer] != null){
			var style2 = document.all[whichLayer].style;
			style2.display = onoff;
		}
	}else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = onoff;
	}
}

function deactivateBlock(obj){
	if(obj.type == "select"){
		obj.options.selectedIndex = 0;
	}else{
		obj.value = "";
	}
	obj.disabled = true;
}

function activateBlock(obj){
	obj.disabled = false;
}

function setReportFormBlocks(oForm, reportType){
	if(reportType == "resnumber"){
		deactivateBlock(oForm.guest_name);
		deactivateBlock(oForm.year);
		deactivateBlock(oForm.month);
		deactivateBlock(oForm.day);
		activateBlock(oForm.res_number);
	}else if(reportType == "guestname"){
		deactivateBlock(oForm.year);
		deactivateBlock(oForm.month);
		deactivateBlock(oForm.day);
		deactivateBlock(oForm.res_number);
		activateBlock(oForm.guest_name);
	}else{
		deactivateBlock(oForm.res_number);
		deactivateBlock(oForm.guest_name);
		activateBlock(oForm.year);
		activateBlock(oForm.month);
		activateBlock(oForm.day);
		oForm.year.options.selectedIndex = oForm.thisYYYY.value;
		oForm.day.options.selectedIndex = oForm.thisDD.value;
		oForm.month.options.selectedIndex = oForm.thisMM.value;
	}
}

function setFields(oValue){
	if(oValue == "buyonegetonefree"){
		toggleLayer('freenightField','block');
		toggleLayer('numdaysField','none');
	}else if(oValue == "fixed"){
		toggleLayer('numdaysField','block');
		toggleLayer('freenightField','none');
	}else{
		toggleLayer('numdaysField','none');
		toggleLayer('freenightField','none');
	}
}

function Navigate(choice) {
        var spot=choice.options[choice.selectedIndex].value;
        if (spot != 'choose') {
                location.href = spot;
        }
}

/*================================================================================================*/

/*

This routine checks the credit card number. The following checks are made:

1. A number has been provided
2. The number is a right length for the card
3. The number has an appropriate prefix for the card
4. The number has a valid modulus 10 number check digit if required

If the validation fails an error is reported.

The structure of credit card formats was gleaned from a variety of sources on the web, although the 
best is probably on Wikepedia ("Credit card number"):

  http://en.wikipedia.org/wiki/Credit_card_number

Parameters:
            cardnumber           number on the card
            cardname             name of card as defined in the card list below

Author:     John Gardner
Date:       1st November 2003
Updated:    26th Feb. 2005      Additional cards added by request
Updated:    27th Nov. 2006      Additional cards added from Wikipedia
Updated:    18th Jan. 2008      Additional cards added from Wikipedia
Updated:    26th Nov. 2008      Maestro cards extended
Updated:    19th Jun. 2009      Laser cards extended from Wikipedia
Updated:    11th Sep. 2010      Typos removed from Diners and Solo definitions (thanks to Noe Leon)

*/

/*
   If a credit card number is invalid, an error reason is loaded into the global ccErrorNo variable. 
   This can be be used to index into the global error  string array to report the reason to the user 
   if required:
   
   e.g. if (!checkCreditCard (number, name) alert (ccErrors(ccErrorNo);
*/

var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {
     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types as follows.
  
  //  Name:         As in the selection box of the form - must be same as user's
  //  Length:       List of possible valid lengths of the card number for the card
  //  prefixes:     List of possible prefixes for the card
  //  checkdigit:   Boolean to say whether there is a check digit
  
  cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "MasterCard", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,16", 
               prefixes: "305,36,38,54,55",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305",
               checkdigit: true};
  cards [4] = {name: "AmEx", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011,622,64,65",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "16", 
               prefixes: "35",
               checkdigit: true};
  cards [7] = {name: "enRoute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
  cards [8] = {name: "Solo", 
               length: "16,18,19", 
               prefixes: "6334,6767",
               checkdigit: true};
  cards [9] = {name: "Switch", 
               length: "16,18,19", 
               prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
               checkdigit: true};
  cards [10] = {name: "Maestro", 
               length: "12,13,14,15,16,18,19", 
               prefixes: "5018,5020,5038,6304,6759,6761",
               checkdigit: true};
  cards [11] = {name: "VisaElectron", 
               length: "16", 
               prefixes: "417500,4917,4913,4508,4844",
               checkdigit: true};
  cards [12] = {name: "LaserCard", 
               length: "16,17,18,19", 
               prefixes: "6304,6706,6771,6709",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardnumber = cardnumber.replace (" ", "");
  
  // Check that the number is numeric
  var cardNo = cardnumber
  var cardexp = /^[0-9]{13,19}$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the length if all else was 
  // hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}
/*================================================================================================*/


