function getbookingform(hotelname, hotelcode, city){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="empowercode/bookingform.cfm?hotelname=" + hotelname + "&hotelcode=" + hotelcode + "&city=" + city;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedBookingForm ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChangedBookingForm(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("bookingform").innerHTML = xmlHttp.responseText;
		Init_Cals();
	}
} 

function checkavailability(frm){
	document.getElementById("searchresults").style.display = 'none';
	document.getElementById("flash").style.display = '';
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="results.cfm?type=checkavailability";
	xmlHttp.open("POST", url, true); 
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;  charset=UTF-8');
	xmlHttp.onreadystatechange=stateChanged;
	poststring = "test=false";
	poststring = poststring + "&hotelname="+frm.hotelname.value;
	poststring = poststring + "&debug="+frm.debug.value;
	poststring = poststring + "&hotelcode="+frm.hotelcode.value;
	poststring = poststring + "&numberofrooms="+frm.numberofrooms.value;
	poststring = poststring + "&StartDateRange="+frm.cal1Date.value;
	poststring = poststring + "&numberofpeopleperroom="+frm.numberofpeopleperroom.value;
	poststring = poststring + "&EndDateRange="+frm.cal1Date2.value;
	//poststring = poststring + "&roomtype="+frm.roomtype.value;
	poststring = poststring + "&stars="+frm.stars.value;
	poststring = poststring + "&city="+frm.city.value;
	poststring = poststring + "&hotelpage="+frm.hotelpage.value;

	poststring = poststring + "&include1="+frm.include1.value;
	poststring = poststring + "&include2="+frm.include2.value;
	poststring = poststring + "&include3="+frm.include3.value;
	poststring = poststring + "&include4="+frm.include4.value;
	poststring = poststring + "&include5="+frm.include5.value;
	poststring = poststring + "&adults1="+frm.adults1.value;
	poststring = poststring + "&adults2="+frm.adults2.value;
	poststring = poststring + "&adults3="+frm.adults3.value;
	poststring = poststring + "&adults4="+frm.adults4.value;
	poststring = poststring + "&adults5="+frm.adults5.value;
	poststring = poststring + "&children1="+frm.children1.value;
	poststring = poststring + "&children2="+frm.children2.value;
	poststring = poststring + "&children3="+frm.children3.value;
	poststring = poststring + "&children4="+frm.children4.value;
	poststring = poststring + "&children5="+frm.children5.value;
	poststring = poststring + "&roomtype1="+frm.roomtype1.value;
	poststring = poststring + "&roomtype2="+frm.roomtype2.value;
	poststring = poststring + "&roomtype3="+frm.roomtype3.value;
	poststring = poststring + "&roomtype4="+frm.roomtype4.value;
	poststring = poststring + "&roomtype5="+frm.roomtype5.value;

	xmlHttp.send(poststring+"&sid="+Math.random());
}

function makebooking(id){
	poststring = "test=false";
	var cnt = document.getElementById(id).elements.length;	
	
	for (i=0; i<cnt; i++){
		stritem = document.getElementById(id).elements[i].id;
		strval = document.getElementById(id).elements[i].value;
		//alert(stritem + " = " + strval);
		poststring = poststring + "&"+stritem+"="+strval;
	}
	//alert(poststring);
	document.getElementById("searchresults").innerHTML = "<br><center><div style='font-family:helvetica, verdana, arial; font-size:18px; font-weight:bold;color:#141B21;'>&nbsp;</div><br><br><img src='calendar/images/loader.gif'></center>";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="results.cfm?type=makebooking";
	xmlHttp.open("POST", url, true); 
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;  charset=UTF-8');
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.send(poststring+"&sid="+Math.random());
}

function makebookingchk(id){

	var reference = document.getElementById(id).ResponseReference.value;
	var sequence = document.getElementById(id).SequenceNo.value;
	var adults = document.getElementById(id).adults.value;
	var children = document.getElementById(id).children.value;
	var hotelname = document.getElementById(id).hotelname.value;
	var arrivaldate = document.getElementById(id).arrivaldate.value;
	var departuredate = document.getElementById(id).departuredate.value;
	var roomtype = document.getElementById(id).roomtype.value;
	var numberofrooms = document.getElementById(id).numberofrooms.value;
	var roomsandcodes = document.getElementById(id).roomsandcodes.value;

	var include1 = document.getElementById(id).include1.value;
	var include2 = document.getElementById(id).include2.value;
	var include3 = document.getElementById(id).include3.value;
	var include4 = document.getElementById(id).include4.value;
	var include5 = document.getElementById(id).include5.value;
	var adults1 = document.getElementById(id).adults1.value;
	var adults2 = document.getElementById(id).adults2.value;
	var adults3 = document.getElementById(id).adults3.value;
	var adults4 = document.getElementById(id).adults4.value;
	var adults5 = document.getElementById(id).adults5.value;
	var children1 = document.getElementById(id).children1.value;
	var children2 = document.getElementById(id).children2.value;
	var children3 = document.getElementById(id).children3.value;
	var children4 = document.getElementById(id).children4.value;
	var children5 = document.getElementById(id).children5.value;
	var roomtype1 = document.getElementById(id).roomtype1.value;
	var roomtype2 = document.getElementById(id).roomtype2.value;
	var roomtype3 = document.getElementById(id).roomtype3.value;
	var roomtype4 = document.getElementById(id).roomtype4.value;
	var roomtype5 = document.getElementById(id).roomtype5.value;

	document.getElementById("searchresults").innerHTML = "<br><center><div style='font-family:helvetica, verdana, arial; font-size:18px; font-weight:bold;color:#141B21;'>&nbsp;</div><br><br><img src='calendar/images/loader.gif'></center>";
	poststring = "test=false";
	poststring = poststring + "&SequenceNo="+sequence;
	poststring = poststring + "&ResponseReference="+reference;
	poststring = poststring + "&adults="+adults;
	poststring = poststring + "&children="+children;
	poststring = poststring + "&hotelname="+hotelname;
	poststring = poststring + "&arrivaldate="+arrivaldate;
	poststring = poststring + "&departuredate="+departuredate;
	poststring = poststring + "&Cal1Date="+arrivaldate;
	poststring = poststring + "&Cal1Date2="+departuredate;
	poststring = poststring + "&numberofrooms="+numberofrooms;
	poststring = poststring + "&roomtype="+roomtype;
	poststring = poststring + "&roomsandcodes="+roomsandcodes;
	document.location.href = 'checkavailability.cfm?' + poststring;

}

function payformybooking(){
	var cnt = document.getElementById("payforbooking").elements.length;
	var strval = "";
	var stritem = "";
	poststring = "test=false";
	post = true;

	var firstname = document.getElementById("payforbooking").firstname1.value;
	if (firstname == '' && post == true){
		alert('Please enter your first name');
		post = false;
		document.getElementById("payforbooking").firstname1.focus();
	}

	var surname = document.getElementById("payforbooking").surname1.value;
	if (surname == '' && post == true){
		alert('Please enter your surname');
		post = false;
		document.getElementById("payforbooking").surname1.focus();
	}

	var cardnumber = document.getElementById("payforbooking").cardnumber.value;
	if (cardnumber == '' && post == true){
		alert('Please enter your card number');
		post = false;
		document.getElementById("payforbooking").cardnumber.focus();
	}

	var AddressLine1 = document.getElementById("payforbooking").AddressLine1.value;
	if (AddressLine1 == '' && post == true){
		alert('Please enter your address');
		post = false;
		document.getElementById("payforbooking").AddressLine1.focus();
	}
	
	var city = document.getElementById("payforbooking").city.value;
	if (city == '' && post == true){
		alert('Please enter your city');
		post = false;
		document.getElementById("payforbooking").city.focus();
	}

	var area = document.getElementById("payforbooking").area.value;
	if (area == '' && post == true){
		alert('Please enter your area');
		post = false;
		document.getElementById("payforbooking").area.focus();
	}

	var postcode = document.getElementById("payforbooking").postcode.value;
	if (postcode == '' && post == true){
		alert('Please enter your postal code');
		post = false;
		document.getElementById("payforbooking").postcode.focus();
	}
	
	if (post == true){
		for (i=0; i<cnt; i++){
			stritem = document.getElementById("payforbooking").elements[i].name;
			strval = document.getElementById("payforbooking").elements[i].value;
			poststring = poststring + "&"+stritem+"="+strval;
		}
	
		document.getElementById("searchresults").innerHTML = "<br><center><div style='font-family:helvetica, verdana, arial; font-size:18px; font-weight:bold;'>Sending Payment Details...&nbsp;</div><br><br><img src='calendar/images/loader.gif'></center>";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request");
			return;
		} 
		var url="results.cfm?type=payforbooking";
		xmlHttp.open("POST", url, true); 
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;  charset=UTF-8');
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.send(poststring+"&sid="+Math.random());
	}
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		//alert(xmlHttpImages.responseText);
		document.getElementById("flash").style.display = 'none';
		document.getElementById("searchresults").style.display = '';
		document.getElementById("searchresults").innerHTML = xmlHttp.responseText;
	}
} 

function GetXmlHttpObject(){ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
} 

function showresults(){
	checkavailability(document.SearchForm);
}

function showcustomerdetails(){
	document.getElementById("searchresults").style.display = 'none';
	document.getElementById("customerdetails").style.display = '';
}

function changeprice(optionnumber,type,basis,price,code,id,chkbox,numberofpeople,form,roomcode){
	//alert(document.getElementById(form).totalcost.value);
	var totalcost = Number(document.getElementById(form).totalcost.value);
	var totaltoadd = 0;
	var costtoadd = 0;
	var totaltosubtract = 0;
	var costtosubtract = 0;
	//alert(basis);
	//alert(price);
	//alert(code);
	//alert(id);
	//alert(chkbox.checked);
	if (chkbox.checked){
		if (basis == 'PP'){
			costtoadd = Number(numberofpeople) * Number(price);
		} else if (basis == 'PU'){
			costtoadd = Number(price);
		}
		var totalcost = Number(totalcost) + Number(costtoadd);
		document.getElementById(id).innerHTML = (Number(totalcost.numberFormat("0.00"))) + "&euro;";	
		document.getElementById("main" + id).innerHTML = (Number(totalcost.numberFormat("0.00"))) + "&euro;";	
		document.getElementById(form).totalcost.value = Number(totalcost.numberFormat("0.00"));
		//alert('<input type="hidden" id="' + optionnumber + '" value="' + type + '|' + code + '|' + roomcode + '" name="' + optionnumber + '>');
		
		var n = document.createElement("input");
		n.value = type + '|' + code + '|' + roomcode;
		n.type = 'hidden';
		n.id = optionnumber;
		n.name = optionnumber;
		//alert(n.id);
		var frm = document.getElementById(form);
		frm.appendChild(n)
		//alert(document.getElementById(n.id).value);
		//document.getElementById(form).innerHTML = document.getElementById(form).innerHTML + '<input type="hidden" id="' + optionnumber + '" value="' + type + '|' + code + '|' + roomcode + '" name="' + optionnumber + '>';
	} else {
		if (basis == 'PP'){
			costtosubtract = Number(numberofpeople) * Number(price);
		} else if (basis == 'PU'){
			costtosubtract = Number(price);
		}
		totaltosubtract = Number(totalcost) - Number(costtosubtract);
		document.getElementById(id).innerHTML = (Number(totaltosubtract.numberFormat("0.00"))) + "&euro;";	
		document.getElementById("main" + id).innerHTML = (Number(totaltosubtract.numberFormat("0.00"))) + "&euro;";	
		document.getElementById(form).totalcost.value = Number(totaltosubtract.numberFormat("0.00"));
		var htmltoremove = '<input type="hidden" id="' + optionnumber + '" value="' + type + '|' + code + '" name="' + optionnumber + '" value="' + type + '|' + code + '">';
		
		var n = document.getElementById(optionnumber);
		var frm = document.getElementById(form);
		frm.removeChild(n)
		//alert(frm.innerHTML);
		
		
		//myinput=document.getElementById(optionnumber);
		//myform=document.getElementById(form);
		//alert(myform.id);
		//myform.removeChild(myinput);		
	}
	//alert(document.getElementById(form).innerHTML);
}

// Replaces all instances of the given substring.
String.prototype.replaceAll = function(
	strTarget, // The substring you want to replace
	strSubString // The string you want to replace in.
){
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
	 
	// Keep looping while an instance of the target string
	// still exists in the string.
	while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strText = strText.replace( strTarget, strSubString )
		 
		// Get the index of any next matching substring.
		intIndexOfMatch = strText.indexOf( strTarget );
	}
	 
	// Return the updated string with ALL the target strings
	// replaced out with the new substring.
	return( strText );
}
	
// Abbreviations: LODP = Left Of Decimal Point, RODP = Right Of Decimal Point
Number.formatFunctions = {count:0};

// Constants useful for controlling the format of numbers in special cases.
Number.prototype.NaN         = 'NaN';
Number.prototype.posInfinity = 'Infinity';
Number.prototype.negInfinity = '-Infinity';

Number.prototype.numberFormat = function(format, context) {
    if (isNaN(this) ) {
        return Number.prototype.NaNstring;
    }
    else if (this == +Infinity ) {
        return Number.prototype.posInfinity;
    }
    else if ( this == -Infinity) {
        return Number.prototype.negInfinity;
    }
    else if (Number.formatFunctions[format] == null) {
        Number.createNewFormat(format);
    }
    return this[Number.formatFunctions[format]](context);
}

Number.createNewFormat = function(format) {
    var funcName = "format" + Number.formatFunctions.count++;
    Number.formatFunctions[format] = funcName;
    var code = "Number.prototype." + funcName + " = function(context){\n";

    // Decide whether the function is a terminal or a pos/neg/zero function
    var formats = format.split(";");
    switch (formats.length) {
        case 1:
            code += Number.createTerminalFormat(format);
            break;
        case 2:
            code += "return (this < 0) ? this.numberFormat(\""
                + String.escape(formats[1])
                + "\", 1) : this.numberFormat(\""
                + String.escape(formats[0])
                + "\", 2);";
            break;
        case 3:
            code += "return (this < 0) ? this.numberFormat(\""
                + String.escape(formats[1])
                + "\", 1) : ((this == 0) ? this.numberFormat(\""
                + String.escape(formats[2])
                + "\", 2) : this.numberFormat(\""
                + String.escape(formats[0])
                + "\", 3));";
            break;
        default:
            code += "throw 'Too many semicolons in format string';";
            break;
    }
    eval(code + "}");
}

Number.createTerminalFormat = function(format) {
    // If there is no work to do, just return the literal value
    if (format.length > 0 && format.search(/[0#?]/) == -1) {
        return "return '" + String.escape(format) + "';\n";
    }
    // Negative values are always displayed without a minus sign when section separators are used.
    var code = "var val = (context == null) ? new Number(this) : Math.abs(this);\n";
    var thousands = false;
    var lodp = format;
    var rodp = "";
    var ldigits = 0;
    var rdigits = 0;
    var scidigits = 0;
    var scishowsign = false;
    var sciletter = "";
    // Look for (and remove) scientific notation instructions, which can be anywhere
    m = format.match(/\..*(e)([+-]?)(0+)/i);
    if (m) {
        sciletter = m[1];
        scishowsign = (m[2] == "+");
        scidigits = m[3].length;
        format = format.replace(/(e)([+-]?)(0+)/i, "");
    }
    // Split around the decimal point
    var m = format.match(/^([^.]*)\.(.*)$/);
    if (m) {
        lodp = m[1].replace(/\./g, "");
        rodp = m[2].replace(/\./g, "");
    }
    // Look for %
    if (format.indexOf('%') >= 0) {
        code += "val *= 100;\n";
    }
    // Look for comma-scaling to the left of the decimal point
    m = lodp.match(/(,+)(?:$|[^0#?,])/);
    if (m) {
        code += "val /= " + Math.pow(1000, m[1].length) + "\n;";
    }
    // Look for comma-separators
    if (lodp.search(/[0#?],[0#?]/) >= 0) {
        thousands = true;
    }
    // Nuke any extraneous commas
    if ((m) || thousands) {
        lodp = lodp.replace(/,/g, "");
    }
    // Figure out how many digits to the l/r of the decimal place
    m = lodp.match(/0[0#?]*/);
    if (m) {
        ldigits = m[0].length;
    }
    m = rodp.match(/[0#?]*/);
    if (m) {
        rdigits = m[0].length;
    }
    // Scientific notation takes precedence over rounding etc
    if (scidigits > 0) {
        code += "var sci = Number.toScientific(val,"

            + ldigits + ", " + rdigits + ", " + scidigits + ", " + scishowsign + ");\n"
            + "var arr = [sci.l, sci.r];\n";
    }
    else {
        // If there is no decimal point, round to nearest integer, AWAY from zero
        if (format.indexOf('.') < 0) {
            code += "val = (val > 0) ? Math.ceil(val) : Math.floor(val);\n";
        }
        // Numbers are rounded to the correct number of digits to the right of the decimal
        code += "var arr = val.round(" + rdigits + ").toFixed(" + rdigits + ").split('.');\n";
        // There are at least "ldigits" digits to the left of the decimal, so add zeros if needed.
        code += "arr[0] = (val < 0 ? '-' : '') + String.leftPad((val < 0 ? arr[0].substring(1) : arr[0]), "
            + ldigits + ", '0');\n";
    }
    // Add thousands separators
    if (thousands) {
        code += "arr[0] = Number.addSeparators(arr[0]);\n";
    }
    // Insert the digits into the formatting string.  On the LHS, extra digits are copied
    // into the result.  On the RHS, rounding has chopped them off.
    code += "arr[0] = Number.injectIntoFormat(arr[0].reverse(), '"
        + String.escape(lodp.reverse()) + "', true).reverse();\n";
    if (rdigits > 0) {
        code += "arr[1] = Number.injectIntoFormat(arr[1], '" + String.escape(rodp) + "', false);\n";
    }
    if (scidigits > 0) {
        code += "arr[1] = arr[1].replace(/(\\d{" + rdigits + "})/, '$1" + sciletter + "' + sci.s);\n";
    }
    return code + "return arr.join('.');\n";
}

Number.toScientific = function(val, ldigits, rdigits, scidigits, showsign) {
    var result = {l:"", r:"", s:""};
    var ex = "";
    // Make ldigits + rdigits significant figures
    var before = Math.abs(val).toFixed(ldigits + rdigits + 1).trim('0');
    // Move the decimal point to the right of all digits we want to keep,
    // and round the resulting value off
    var after = Math.round(new Number(before.replace(".", "").replace(
        new RegExp("(\\d{" + (ldigits + rdigits) + "})(.*)"), "$1.$2"))).toFixed(0);
    // Place the decimal point in the new string
    if (after.length >= ldigits) {
        after = after.substring(0, ldigits) + "." + after.substring(ldigits);
    }
    else {
        after += '.';
    }
    // Find how much the decimal point moved.  This is #places to LODP in the original
    // number, minus the #places in the new number.  There are no left-padded zeroes in
    // the new number, so the calculation for it is simpler than for the old number.
    result.s = (before.indexOf(".") - before.search(/[1-9]/)) - after.indexOf(".");
    // The exponent is off by 1 when it gets moved to the left.
    if (result.s < 0) {
        result.s++;
    }
    // Split the value around the decimal point and pad the parts appropriately.
    result.l = (val < 0 ? '-' : '') + String.leftPad(after.substring(0, after.indexOf(".")), ldigits, "0");
    result.r = after.substring(after.indexOf(".") + 1);
    if (result.s < 0) {
        ex = "-";
    }
    else if (showsign) {
        ex = "+";
    }
    result.s = ex + String.leftPad(Math.abs(result.s).toFixed(0), scidigits, "0");
    return result;
}

Number.prototype.round = function(decimals) {
    if (decimals > 0) {
        var m = this.toFixed(decimals + 1).match(
            new RegExp("(-?\\d*)\.(\\d{" + decimals + "})(\\d)\\d*$"));
        if (m && m.length) {
            return new Number(m[1] + "." + String.leftPad(Math.round(m[2] + "." + m[3]), decimals, "0"));
        }
    }
    return this;
}

Number.injectIntoFormat = function(val, format, stuffExtras) {
    var i = 0;
    var j = 0;
    var result = "";
    var revneg = val.charAt(val.length - 1) == '-';
    if ( revneg ) {
       val = val.substring(0, val.length - 1);
    }
    while (i < format.length && j < val.length && format.substring(i).search(/[0#?]/) >= 0) {
        if (format.charAt(i).match(/[0#?]/)) {
            // It's a formatting character; copy the corresponding character
            // in the value to the result
            if (val.charAt(j) != '-') {
                result += val.charAt(j);
            }
            else {
                result += "0";
            }
            j++;
        }
        else {
            result += format.charAt(i);
        }
        ++i;
    }
    if ( revneg && j == val.length ) {
        result += '-';
    }
    if (j < val.length) {
        if (stuffExtras) {
            result += val.substring(j);
        }
        if ( revneg ) {
             result += '-';
        }
    }
    if (i < format.length) {
        result += format.substring(i);
    }
    return result.replace(/#/g, "").replace(/\?/g, " ");
}

Number.addSeparators = function(val) {
    return val.reverse().replace(/(\d{3})/g, "$1,").reverse().replace(/^(-)?,/, "$1");
}

String.prototype.reverse = function() {
    var res = "";
    for (var i = this.length; i > 0; --i) {
        res += this.charAt(i - 1);
    }
    return res;
}

String.prototype.trim = function(ch) {
    if (!ch) ch = ' ';
    return this.replace(new RegExp("^" + ch + "+|" + ch + "+$", "g"), "");
}

String.leftPad = function (val, size, ch) {
    var result = new String(val);
    if (ch == null) {
        ch = " ";
    }
    while (result.length < size) {
        result = ch + result;
    }
    return result;
}

String.escape = function(string) {
    return string.replace(/('|\\)/g, "\\$1");
}



function scrollbox(){
	if (document.documentElement.scrollTop > 360) {
		var top = document.documentElement.scrollTop - 380;
	} else {
		var top = 5;
	}
	document.getElementById('rgtsearchform').style.top = top + 'px';
}

YAHOO.util.Event.onAvailable('rgtsearchform', function() {window.onscroll=scrollbox;});