
function FontStyle() {
    var elem = document.getElementById("title")
    var elem2 = document.getElementById("title2")
    var dd = document.getElementById("ddBannerFontSize")
    elem.style.fontSize = dd.value
    elem2.style.fontSize = dd.value
    var dd = document.getElementById("ddBannerFont")
    elem.style.fontFamily = dd.value
    elem2.style.fontFamily = dd.value
    elem = document.getElementById("content")
    dd = document.getElementById("ddTextFontSize")
    elem.style.fontSize = dd.value
    dd = document.getElementById("ddTextFont")
    elem.style.fontFamily = dd.value
}


var triedanother = 0

function resetsubmit() {
    dontdisable = "1"
}


function showcalc(sc, src) {

    if (sc == "YES") {
        var objLeft = (document.body.clientWidth) / 2;
        objLeft -= 118

        if (src != 'flights') {
            objLeft -= 30
        }

        var objTop = 177
        document.write("<div id='wait' style='text-align: center;width=400;height=20;position:absolute;top=" + objTop + ";left=" + objLeft + ";color: white; background-color: #0368B0;border-right: white thin solid;border-top: white thin solid;border-left: white thin solid;border-bottom: white thin solid;'><center><b>Calculating results...</b></center></div>")
    }
}

function hidecalc() {

    var elem = document.getElementById("waitappleboth")
    if (elem) {
        elem.style.visibility = "hidden"
        elem.style.display = "none"
    }

    var elem = document.getElementById("wait")

    if (elem) {
        elem.style.visibility = "hidden"
        elem.style.display = "none"
    }
}

browserName = navigator.appName.substring(0, 8);
browserVer = parseFloat(navigator.appVersion);

var Browser = 0;

if (browserName == 'Microsof' && browserVer < 4) { Browser = 0; }
if (browserName == 'Microsof' && browserVer >= 4) { Browser = 1; }
if (browserName == 'Netscape' && browserVer < 4) { Browser = 0; }
if (browserName == 'Netscape' && browserVer >= 4) { Browser = 2; }

//opens slide window
function slides(propertycode) {

    //close any currently open windows
    if (self.awin && Browser == 1) {
        self.awin.close()
    }

    var url = "http://www.goamerica.co.uk/Furniture/slides.aspx?p=" + propertycode
    var awin
    var popup = window.open(url, 'Slideshow', 'left=0,top=0,toolbar=no,location=no,directories=no,status=no,scrollbars=no,width=330,height=400')
    self.awin = popup

    var submitbutton = document.getElementById(submit)
    submitbutton.disabled = false
    var busyBox = new BusyBox(brow, "BusyBoxDiv", "BusyBoxImg", "busyBox", 12, "http://www.goamerica.co.uk/Furniture/images/Wait/wait_", ".jpg", 50, "MainAvail");
}

//opens map window
function map(propertycode) {

    //close any currently open windows
    if (self.awin && Browser == 1) {
        self.awin.close()
    }

    var url = "http://www.goamerica.co.uk/Furniture/map.aspx?p=" + propertycode
    var awin
    var popup = window.open(url, 'Map', 'left=0, top=0,toolbar=no,location=no,directories=no,status=no,scrollbars=no,width=550,height=415')
    self.awin = popup

    var submitbutton = document.getElementById(submit)

    if (submitbutton) {
        submitbutton.disabled = false
        var busyBox = new BusyBox(brow, "BusyBoxDiv", "BusyBoxImg", "busyBox", 12, "http://www.goamerica.co.uk/Furniture/images/Wait/wait_", ".jpg", 50, "MainAvail");
    }
    else {
        submitbutton = document.getElementById(carsubmit)

        if (submitbutton) {
            submitbutton.disabled = false
            var busyBox = new BusyBox(brow, "BusyBoxDiv", "BusyBoxImg", "busyBox", 12, "http://www.goamerica.co.uk/Furniture/images/Wait/wait_", ".jpg", 50, "MainAvail");
        }
    }

}

//opens reviews window
function reviews(propertycode) {

    //close any currently open windows
    if (self.awin && Browser == 1) {
        self.awin.close()
    }

    var url = "http://www.goamerica.co.uk/Furniture/reviews.aspx?p=" + propertycode
    var awin
    var popup = window.open(url, 'Reviews', 'left=0,top=0,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,width=600,height=600')
    self.awin = popup

    var submitbutton = document.getElementById(submit)
    submitbutton.disabled = false
    var busyBox = new BusyBox(brow, "BusyBoxDiv", "BusyBoxImg", "busyBox", 12, "http://www.goamerica.co.uk/Furniture/images/Wait/wait_", ".jpg", 50, "MainAvail");
}

//opens tour window
function vtour(propertycode) {

    //close any currently open windows
    if (self.awin && Browser == 1) {
        self.awin.close()
    }

    var url = "http://www.goamerica.co.uk/Furniture/tour.aspx?p=" + propertycode
    var awin
    var popup = window.open(url, 'Tour', 'left=0,top=0,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,width=600,height=600')
    self.awin = popup

    var submitbutton = document.getElementById(submit)
    submitbutton.disabled = false
    var busyBox = new BusyBox(brow, "BusyBoxDiv", "BusyBoxImg", "busyBox", 12, "http://www.goamerica.co.uk/Furniture/images/Wait/wait_", ".jpg", 50, "MainAvail");
}

//Trim function - reusable code

function LTrim(str) {

    var whitespace = new String(" \n\r\t")
    var s = new String(str)

    if (whitespace.indexOf(s.charAt(0)) != -1) {
        var j = 0, i = s.length
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
            j++
        }
        s = s.substring(j, i)
    }
    return (s)
}

function RTrim(str) {

    var whitespace = new String(" \t\n\r")
    var s = new String(str)

    if (whitespace.indexOf(s.charAt(s.length - 1)) != -1) {
        var i = s.length - 1
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
            i--
        }
        s = s.substring(0, i + 1)
    }
    return (s)
}

function Trim(str) {
    return RTrim(LTrim(str))
}

function ToggleDisplay(id) {
    var elem = document.getElementById('d' + id);
    var elem2 = document.getElementById('plusminus' + id);
    if (elem) {
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
            elem2.src = "http://www.goamerica.co.uk/Furniture/images/minusicon.jpg"
        }
        else {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
            elem2.src = "http://www.goamerica.co.uk/Furniture/images/plusicon.jpg"
        }
    }
    elem = document.getElementById('r' + id);
    if (elem) {
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
        }
        else {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
        }
    }
}

function ToggleRDisplay(id) {
    var elem = document.getElementById('r' + id);
    if (elem) {
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
        }
        else {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
        }
    }
}

function ToggleCartDetails() {
    var elem = document.getElementById('CartDetails');
    if (elem) {
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
        }
        else {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
        }
    }
}

function ToggleCartRDetails(id, roomqty) {

    for (r = 1; r <= roomqty; r++) {

        var elem = document.getElementById('item' + id + 'RoomDesc' + r);
        var elem2 = document.getElementById('item' + id + 'RoomPrice' + r);
        var elem3 = document.getElementById('hotelgapA' + id);
        var elem4 = document.getElementById('hotelgapB' + id);

        if (elem) {
            if (elem.style.display != 'block') {
                elem.style.display = 'block';
                elem.style.visibility = 'visible';
                elem2.style.display = 'block';
                elem2.style.visibility = 'visible';
                elem3.style.display = 'block';
                elem3.style.visibility = 'visible';
                elem4.style.display = 'block';
                elem4.style.visibility = 'visible';
            }
            else {
                elem.style.display = 'none';
                elem.style.visibility = 'hidden';
                elem2.style.display = 'none';
                elem2.style.visibility = 'hidden';
                elem3.style.display = 'none';
                elem3.style.visibility = 'hidden';
                elem4.style.display = 'none';
                elem4.style.visibility = 'hidden';
            }
        }
    }
}

function ToggleCartFDetails(id, flightqty) {

    for (f = 1; f <= flightqty; f++) {

        var elem = document.getElementById('item' + id + 'FlightDesc' + f);
        var elem2 = document.getElementById('flightgapA' + id);
        var elem3 = document.getElementById('flightgapB' + id);

        if (elem) {
            if (elem.style.display != 'block') {
                elem.style.display = 'block';
                elem.style.visibility = 'visible';
                elem2.style.display = 'block';
                elem2.style.visibility = 'visible';
                elem3.style.display = 'block';
                elem3.style.visibility = 'visible';
            }
            else {
                elem.style.display = 'none';
                elem.style.visibility = 'hidden';
                elem2.style.display = 'none';
                elem2.style.visibility = 'hidden';
                elem3.style.display = 'none';
                elem3.style.visibility = 'hidden';
            }
        }
    }
}

function rcdetails(ratecodeno, itemno) {

    var elem = document.getElementById('ratecodedesc' + ratecodeno + '-' + itemno);

    if (elem) {
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
        }
        else {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
        }
    }
}

function pickupdetails() {

    var elem = document.getElementById('pickupdepot');

    if (elem) {
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
        }
        else {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
        }
    }
}

function dropoffdetails() {

    var elem = document.getElementById('dropoffdepot');

    if (elem) {
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
        }
        else {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
        }
    }
}

function max1flight() {

    var elem = document.getElementById("flightdivHelpText")

    if (elem) {
        if (triedanother == 1) {
            alert("Sorry, you can only have one flight itinerary in your basket. Either remove the existing itinerary or create another after booking the current itinerary.")
        }
    }
}

function copyhidden() {

    for (i = 0; i < pcount; i++) {
        var elem = document.getElementById(hiddenArray[i]);
        var elem2 = document.getElementById('HiddenProperty' + i);
        //don't calculate initial price if added to basket
        //we want it to reflect whatever selection the user made
        if (elem2) {
            if (basketadd != i) {
                elem.value = elem2.value
            }
        }
    }
}

function copyrchidden() {

    for (i = 0; i < rccount; i++) {
        var elem = document.getElementById(hiddenArray[i]);
        var elem2 = document.getElementById('HiddenRate' + i);
        //don't calculate initial price if added to basket
        //we want it to reflect whatever selection the user made
        if (elem2) {
            if (basketadd != i) {
                elem.value = elem2.value
            }
        }
    }
}

//this goes through hidden textboxes and selects right radio buttons
//otherwise will default back to first option
function selectrightrcradios() {

    if (basketadd != "x") {

        for (p = 0; p < rccount; p++) {

            var hiddenelem = document.getElementById(hiddenArray[p])
            hiddenelem = hiddenelem.value
            var req = hiddenelem

            var elem = eval("document.forms[0].Rate" + p)
            //match selected option and set appropriate radio button to checked
            //but not needed if only one option

            if (elem) {

                if (elem.length > 1) {

                    for (o = 0; o < elem.length; o++) {

                        if (elem[o].value == req) {
                            //alert("OK")    
                            elem[o].checked = true
                            break
                        }
                    }
                }
            }

            calcrcprice(p)
        }
    }
}


//this goes through hidden textboxes and selects right radio buttons
//otherwise will default back to first option
function selectrightradios() {

    if (basketadd != "x") {

        //loop through properties on this page
        //for(p=0;p<pcount;p++){
        for (p = p_start; p < p_end; p++) {

            var hiddenelem = document.getElementById(hiddenArray[p])
            hiddenelem = hiddenelem.value
            var reqsplit = hiddenelem.split("]")

            //loop through rooms
            for (r = 1; r <= rcount; r++) {
                var req = reqsplit[r - 1]

                var elem = eval("document.forms[0].Property" + p + "Room" + r)
                //match selected option and set appropriate radio button to checked
                //but not needed if only one option

                if (elem) {

                    if (elem.length > 1) {

                        for (o = 0; o < elem.length; o++) {

                            if (elem[o].value == req) {
                                //alert("OK")    
                                elem[o].checked = true
                                break
                            }
                        }
                    }
                }
            }
            calcprice(p)
        }
    }
}

var theproperty

//sets no of latest property that the user has tried to add to basket
function getClicked(propertyno) {
    theproperty = propertyno
}

//checks that (HB) properties haven't run out of availability for any of the rooms selected
//when a property is added to basket
function validate() {
    var hiddenelem = document.getElementById(hiddenArray[theproperty])

    if (hiddenelem) {

        var allvals = hiddenelem.value
        var splitvals = allvals.split("]")
        var splitval
        var splitval2
        var avail
        var availused

        for (i = 0; i < splitvals.length - 1; i++) {
            splitval = splitvals[i].split("|")
            avail = splitval[3]
            availused = 1

            for (s = 0; s < splitvals.length - 1; s++) {
                //availused=1

                if (i != s) {
                    splitval2 = splitvals[s].split("|")

                    if (splitval2[0] == splitval[0]) {
                        availused += 1

                        if (availused > avail) {
                            alert("Sorry, there is insufficient availability to meet your room requests for this property. Please amend.")
                            return false
                            break
                        }
                    }
                }
            }

        }

        //checks that (HB) properties have the same board type for all rooms
        //when a property is added to basket
        var thisboardtype

        for (i = 0; i < splitvals.length - 1; i++) {
            splitval = splitvals[i].split("|")

            thisboardtype = splitval[4]

            //only for HB - FW board type is used to store rate plan code
            if (thisboardtype.length == 2) {

                for (s = 0; s < splitvals.length - 1; s++) {
                    //availused=1

                    if (i != s) {
                        splitval2 = splitvals[s].split("|")

                        if (splitval2[4] != splitval[4]) {
                            alert("This hotel requires an overall board type to be submitted for all rooms within an individual request. Please amend so that all rooms either include or exclude breakfast. If you really want to have different board types, please request availability and add each room individually, so that they appear as different items in your basket.")
                            return false
                            break
                        }
                    }
                }

            }
        }
    }
    return true
}

function calcprice(propertyno) {

    var hiddenelem = document.getElementById(hiddenArray[propertyno])
    var total = 0
    var totalf = 0

    if (hiddenelem) {
        hiddenelem.value = ""
    }

    for (r = 1; r <= rcount; r++) {

        var elem = eval("document.forms[0].Property" + propertyno + "Room" + r)

        var fullstring
        var splitstring

        if (elem) {

            if (elem.length > 1) {

                for (o = 0; o < elem.length; o++) {

                    if (elem[o].checked) {
                        //update hidden server control with what has been selected for this property
                        hiddenelem.value += elem[o].value + "]"
                        //update total price for this property
                        fullstring = elem[o].value
                        splitstring = fullstring.split("|")
                        total += parseInt(splitstring[2])
                        totalf += parseInt(splitstring[6])
                    }
                }

            }
            else {
                hiddenelem.value += elem.value + "]"
                fullstring = elem.value
                splitstring = fullstring.split("|")
                total += parseInt(splitstring[2])
                totalf += parseInt(splitstring[6])
            }
        }
    }

    var pricespan = document.getElementById('total' + propertyno)

    if (pricespan) {
        pricespan.innerHTML = "<FONT color='red'><B>" + total + "</B></FONT>"
    }

    pricespan = document.getElementById('pricewithflights' + propertyno)

    if (pricespan) {
        //var discount_total=total - Math.floor(((total/100)*2))
        //pricespan.innerHTML="<FONT color='red'><B>" + discount_total + "</B></FONT>"
        pricespan.innerHTML = "<FONT color='red'><B>" + totalf + "</B></FONT>"
    }

}

function selectOption(property, room, option) {
    var elem = eval("document.forms[0].Property" + property + "Room" + room)

    if (elem) {

        if (elem.length > 1) {
            elem[option].checked = true
            calcprice(property)
        }
    }
}

function selectrcOption(rate, option) {
    var elem = eval("document.forms[0].Rate" + rate)

    if (elem) {

        if (elem.length > 1) {
            elem[option].checked = true
            calcrcprice(rate)
        }
    }
}

function selectSearchOption(option) {

    var elem = eval("document.forms[0].radioAC")

    if (elem) {

        if (elem.length > 1) {
            elem[option].checked = true
            showAccomCar()
        }
    }
}

function showAccomCar() {

    var elem = eval("document.forms[0].radioAC")
    var elemA = document.getElementById("ASearch")
    var elemC = document.getElementById("CSearch")
    var elemF = document.getElementById("FSearch")

    if (elem) {

        for (o = 0; o < elem.length; o++) {

            if (elem[o].checked) {

                if (o == 0) {
                    elemF.style.visibility = "visible"
                    elemF.style.display = "block"
                    elemA.style.visibility = "hidden"
                    elemA.style.display = "none"
                    elemC.style.visibility = "hidden"
                    elemC.style.display = "none"
                    flightcomboload()
                    var elem2 = document.getElementById("divHelp")
                    elem2.style.visibility = "hidden"
                    elem2.style.display = "none"
                    elem2 = document.getElementById("cardivHelp")
                    elem2.style.visibility = "hidden"
                    elem2.style.display = "none"
                }

                if (o == 1) {
                    elemA.style.visibility = "visible"
                    elemA.style.display = "block"
                    elemC.style.visibility = "hidden"
                    elemC.style.display = "none"
                    elemF.style.visibility = "hidden"
                    elemF.style.display = "none"
                    comboload()
                    var elem2 = document.getElementById("cardivHelp")
                    elem2.style.visibility = "hidden"
                    elem2.style.display = "none"
                    elem2 = document.getElementById("flightdivHelp")
                    elem2.style.visibility = "hidden"
                    elem2.style.display = "none"
                }

                if (o == 2) {
                    elemA.style.visibility = "hidden"
                    elemA.style.display = "none"
                    elemF.style.visibility = "hidden"
                    elemF.style.display = "none"
                    elemC.style.visibility = "visible"
                    elemC.style.display = "block"
                    carcomboload()
                    var elem2 = document.getElementById("divHelp")
                    elem2.style.visibility = "hidden"
                    elem2.style.display = "none"
                    elem2 = document.getElementById("flightdivHelp")
                    elem2.style.visibility = "hidden"
                    elem2.style.display = "none"
                }

                break
            }
        }
    }
    var submitbutton = document.getElementById(submit)
    submitbutton.disabled = false
    submitbutton = document.getElementById(carsubmit)
    submitbutton.disabled = false
    submitbutton = document.getElementById(flightsubmit)
    submitbutton.disabled = false
    var busyBox = new BusyBox(brow, "BusyBoxDiv", "BusyBoxImg", "busyBox", 12, "http://www.goamerica.co.uk/Furniture/images/Wait/wait_", ".jpg", 50, "MainAvail");

}

function calcrcprice(rateno) {

    var hiddenelem = document.getElementById(hiddenArray[rateno])

    if (hiddenelem) {
        hiddenelem.value = ""

        var elem = eval("document.forms[0].Rate" + rateno)

        var fullstring
        var splitstring

        if (elem) {

            if (elem.length > 1) {

                for (o = 0; o < elem.length; o++) {

                    if (elem[o].checked) {
                        //update hidden server control with what has been selected for this property
                        hiddenelem.value = elem[o].value
                    }
                }

            }
            else {
                hiddenelem.value = elem.value
            }
        }
    }
}

var dontdisable = "0"

function disableform() {

    var theform = document.forms[0]

    if (dontdisable == "0") {

        if (document.all || document.getElementById) {
            var submitbutton = document.getElementById(submit)
            if (submitbutton) {
                submitbutton.disabled = true
            }
        }
    }
    dontdisable = "0"
}

function disablecarform() {

    var theform = document.forms[0]

    if (dontdisable == "0") {

        if (document.all || document.getElementById) {
            var submitbutton = document.getElementById(carsubmit)

            if (submitbutton) {
                submitbutton.disabled = true
            }
        }
    }
    dontdisable = "0"
}

function disableflightform() {

    var theform = document.forms[0]

    if (dontdisable == "0") {

        if (document.all || document.getElementById) {
            var submitbutton = document.getElementById(flightsubmit)

            if (submitbutton) {
                submitbutton.disabled = true
            }
        }
    }
    dontdisable = "0"
}

function loadPics() {

    var splitstring
    var picspan

    if (picsFound > -1) {

        for (p = 0; p <= picsFound; p++) {
            splitstring = picsArray[p].split("|")
            //get the relevant span to put the pic in
            picspan = document.getElementById('pic' + splitstring[0])

            if (picspan) {

                //don't pass size parameters if a BV pic
                if (splitstring[2] == "0") {
                    picspan.innerHTML = "<img src='" + splitstring[1] + "'>"
                }
                else {
                    picspan.innerHTML = "<img src='" + splitstring[1] + "' width='" + splitstring[2] + "' height='" + splitstring[3] + "'>"
                }

            }
            else {
                break
            }

        }

    }

}

function formtype() {

    var txtFT = document.getElementById(txtFormType)

    if (txtFT) {
        if (txtFT.value == "Car") {
            selectSearchOption(2)
        }
        if (txtFT.value == "Accom") {
            selectSearchOption(1)
        }
        if (txtFT.value == "Flights") {
            selectSearchOption(0)
        }
    }
    showAccomCar()

}


function getres() {
    var elem = document.getElementById(txtWidth)
    elem.value = window.screen.width
    elem = document.getElementById(txtHeight)
    elem.value = window.screen.height
}

