function showhideFeatures(objFeaturesDivID, AnchorID, ImgID, strShowImgURL, strHideImgURL) {
    //alert('objFeaturesDivID: ' + objFeaturesDivID + '\nAnchorID: ' + AnchorID + '\nImgID: ' + ImgID + '\nstrShowImgURL: ' + strShowImgURL + '\nstrHideImgURL: ' + strHideImgURL);
    var elDIV = document.getElementById(objFeaturesDivID);
    var elIMG = document.getElementById(ImgID);
    var elANC = document.getElementById(AnchorID);
    
    if (elDIV) {
        if (elDIV.className == "expandFeatures_show") {
            elDIV.className = "expandFeatures_hide";
            if (elIMG) {
                elIMG.src = strShowImgURL;
                elIMG.alt = "Show Full Features List";
            }
            if(elANC)
                elANC.alt = "Show Full Features List";
        }
        else {
            elDIV.className = "expandFeatures_show";
            if (elIMG) {
                elIMG.src = strHideImgURL;
                elIMG.alt = "Hide Full Features List";
            }
            if(elANC)   
                elANC.alt = "Hide Full Features List";      
        }
    }
}


function showpolariod(polaroidID, imgURL, bgColour, strTitle) {

    //switch off all polaroiditems
    SwitchOffAllPolaroids();

    //switch on current polaroid
    document.getElementById(polaroidID).style.backgroundColor = bgColour;

    //load the current polaroid image
    document.getElementById('header').style.backgroundImage = "url('" + imgURL + "')";

    updateTitle(strTitle);
}



function showhideGallery(strClass, objDiv, imgURL, strTitle, bgColour, objSourceTabID, strLeftIMG, strCenterIMG, strRightIMG, strLastRightIMG, strFirstLeftIMGSelected, strLeftIMGSelected, strCenterIMGSelected, strRightIMGSelected, strLastRightIMGSelected) {

//alert('objDiv: ' + objDiv + '\nimgURL: ' + imgURL + '\nstrTitle: ' + strTitle + '\nbgColour: ' + bgColour + '\nobjSourceTabID: ' + objSourceTabID + '\nstrLeftIMG: ' + strLeftIMG + '\nstrCenterIMG: ' + strCenterIMG + '\nstrRightIMG: ' + strRightIMG + '\nstrLastRightIMG: ' + strLastRightIMG + '\nstrFirstLeftIMGSelected: ' + strFirstLeftIMGSelected + '\nstrLeftIMGSelected: ' + strLeftIMGSelected + '\nstrCenterIMGSelected: ' + strCenterIMGSelected + '\nstrRightIMGSelected: ' + strRightIMGSelected + '\nstrLastRightIMGSelected: ' + strLastRightIMGSelected);

    if (objSourceTabID == 'forward') {
        if (document.getElementById("forward")) 
            objSourceTabID = document.getElementById("forward").value;
        else
            objSourceTabID = "subtab1";  //if it fails, default to first tab
    }
    if (objSourceTabID == 'back') {
        if (document.getElementById("back"))
            objSourceTabID = document.getElementById("back").value;         
        else
            objSourceTabID = "subtab1";  //if it fails, default to first tab
    }

    //get selected sub tab, turn off the rest, turn on the selected tab
    if (document.getElementById("subtab1a"))
        document.getElementById("subtab1a").style.backgroundImage = "url('" + strLeftIMG + "')";
    if (document.getElementById("subtab1")) {
        document.getElementById("subtab1").style.backgroundImage = "url('" + strCenterIMG + "')";
        document.getElementById("subtab1").className = strClass;
    }
    if (document.getElementById("subtab2a")) {
        if (document.getElementById("subtab2"))
            document.getElementById("subtab2a").style.backgroundImage = "url('" + strRightIMG + "')";
        else
            document.getElementById("subtab2a").style.backgroundImage = "url('" + strLastRightIMG + "')";
    }
    if (document.getElementById("subtab2")) {
        document.getElementById("subtab2").style.backgroundImage = "url('" + strCenterIMG + "')";
        document.getElementById("subtab2").className = strClass;
    }
    if (document.getElementById("subtab3a")) {
        if (document.getElementById("subtab3"))
            document.getElementById("subtab3a").style.backgroundImage = "url('" + strRightIMG + "')";
        else
            document.getElementById("subtab3a").style.backgroundImage = "url('" + strLastRightIMG + "')";
    }
    if (document.getElementById("subtab3")) {
        document.getElementById("subtab3").style.backgroundImage = "url('" + strCenterIMG + "')";
        document.getElementById("subtab3").className = strClass;
    }
    if (document.getElementById("subtab4a")) {
        if (document.getElementById("subtab4"))
            document.getElementById("subtab4a").style.backgroundImage = "url('" + strRightIMG + "')";
        else
            document.getElementById("subtab4a").style.backgroundImage = "url('" + strLastRightIMG + "')";
    }
    if (document.getElementById("subtab4")) {
        document.getElementById("subtab4").style.backgroundImage = "url('" + strCenterIMG + "')";
        document.getElementById("subtab4").className = strClass;
    }
    if (document.getElementById("subtab5a")) {
        if (document.getElementById("subtab5"))     
            document.getElementById("subtab5a").style.backgroundImage = "url('" + strRightIMG + "')";
        else
            document.getElementById("subtab5a").style.backgroundImage = "url('" + strLastRightIMG + "')";
    }
    if (document.getElementById("subtab5")) {
        document.getElementById("subtab5").style.backgroundImage = "url('" + strCenterIMG + "')";
        document.getElementById("subtab5").className = strClass;
    }
    if (document.getElementById("subtab6a")) {
        if (document.getElementById("subtab6"))
            document.getElementById("subtab6a").style.backgroundImage = "url('" + strRightIMG + "')";
        else
            document.getElementById("subtab6a").style.backgroundImage = "url('" + strLastRightIMG + "')";
    }
    if (document.getElementById("subtab6")) {
        document.getElementById("subtab6").style.backgroundImage = "url('" + strCenterIMG + "')";
        document.getElementById("subtab6").className = strClass;
    }
    if (document.getElementById("subtab7a")) {
        document.getElementById("subtab7a").style.backgroundImage = "url('" + strLastRightIMG + "')";
    }

    if (document.getElementById(objSourceTabID)) {
        document.getElementById(objSourceTabID).style.backgroundImage = "url('" + strCenterIMGSelected + "')";
        document.getElementById(objSourceTabID).className = "centersubtabselected";
        if(objSourceTabID == 'subtab1')
            document.getElementById(objSourceTabID + 'a').style.backgroundImage = "url('" + strFirstLeftIMGSelected + "')";
        else
            document.getElementById(objSourceTabID + 'a').style.backgroundImage = "url('" + strLeftIMGSelected + "')";
        
        var x = Right(objSourceTabID, 1);
        var y = (parseInt(x) + 1);
        var z = (parseInt(x) - 1);
        var strLeftID = Left(objSourceTabID, String(objSourceTabID).length - 1);
        var strRightID = strLeftID + y + 'a';
        if (document.getElementById(strLeftID + y)) {
            document.getElementById(strRightID).style.backgroundImage = "url('" + strRightIMGSelected + "')";
        }
        else    {
            document.getElementById(strRightID).style.backgroundImage = "url('" + strLastRightIMGSelected + "')";
        }

        //now update the hidden tags for forward/back...
        if (document.getElementById('forward')) {
            if (objSourceTabID == document.getElementById('lasttab').value)
                document.getElementById('forward').value = 'subtab1';
            else
                document.getElementById('forward').value = strLeftID + y;
        }
        if (document.getElementById('back')) {
            if (z==0) 
                document.getElementById('back').value = document.getElementById('lasttab').value;
            else
                document.getElementById('back').value = strLeftID + z;
        }
        if (document.getElementById('currenttab')) {
            document.getElementById('currenttab').value = objSourceTabID;
        }
        
        objDiv = 'gallerypics' + x;
        if (document.getElementById('tabtitle' + x)) {
            //strTitle = document.getElementById('tabtitle' + x).value;
        }
    }

    //first hide all gallery divs
    var gal1 = document.getElementById('gallerypics1');
    if (gal1)
        gal1.className = 'galleryhideDiv';  
    var gal2 = document.getElementById('gallerypics2');
    if (gal2)
        gal2.className = 'galleryhideDiv';
    var gal3 = document.getElementById('gallerypics3');
    if (gal3)
        gal3.className = 'galleryhideDiv';
    var gal4 = document.getElementById('gallerypics4');
    if (gal4)
        gal4.className = 'galleryhideDiv';
    var gal5 = document.getElementById('gallerypics5');
    if (gal5)
        gal5.className = 'galleryhideDiv';
    var gal6 = document.getElementById('gallerypics6'); 
    if (gal6)
        gal6.className = 'galleryhideDiv';

    //now show the selected gallery
    var el = document.getElementById(objDiv);
    if (el) {
        el.className = 'galleryshowDiv';
        var strHTML = el.innerHTML;
        var stronclick = strHTML.split("onclick");      
        var strIMG = stronclick[1].split("'");
        imgURL = strIMG[3]; 
    }

    document.getElementById('header').style.backgroundImage = "url('" + imgURL + "')";
    SwitchOffAllPolaroids();
    SwitchOnFirstPolaroids(bgColour);
    updateTitle(strTitle);
}

function updateTitle(strTitle) {
    var el = document.getElementById('gallerytitle');
    el.innerHTML = strTitle;
}

function showHide(objdiv, imghide, imgshow) {
    var el = document.getElementById(objdiv);
    var elimg = document.getElementById('byvillagearrow');
   
    if ( el.className != 'expandvillage_hide' ) {
        el.className = 'expandvillage_hide';
        elimg.src = imghide;
    }
    else {
        el.className = 'expandvillage_show';
        elimg.src = imgshow;
    }
  
}

function hidebyvillage(objdiv) {
    showHide(objdiv);
}

function ShowFloorplan (objSrc, objAltText, objBedCount, objNewButImg, objImgID, obj1BedOff, obj2BedOff, obj3BedOff, obj4BedOff) {
    //alert('\n1) objSrc:' + objSrc + '\n2) objAltText:' + objAltText + '\n3) objBedCount:' + objBedCount + '\n4) objNewButImg:' + objNewButImg + '\n5) objImgID:' + objImgID + '\n6) obj1BedOff:' + obj1BedOff + '\n7) obj2BedOff:' + obj2BedOff + '\n8) obj3BedOff:' + obj3BedOff + '\n9) obj4BedOff:' + obj4BedOff);

    //first, turn off all buttons as we don't know which is currently turned on
    var onebed = document.getElementById('Onebed');
    if (onebed)
        onebed.src = obj1BedOff;
    var twobed = document.getElementById('Twobed');
    if (twobed)
        twobed.src = obj2BedOff;
    var threebed = document.getElementById('Threebed');
    if (threebed)
        threebed.src = obj3BedOff;
    var fourbed = document.getElementById('Fourbed');
    if (fourbed)
        fourbed.src = obj4BedOff;
    
    //change <A> mouseover/out to defaults
    //var onebed_a = document.getElementById('Onebed_a');
    //onebed_a.onMouseOut = "document.Onebed.src='" + obj1BedOff + "'";
    //var twobed = document.getElementById('Twobed_a');
    //twobed.onMouseOut = "document.Twobed.src='" + obj2BedOff + "'";
    //var threebed = document.getElementById('Threebed_a');
    //threebed.onMouseOut = "document.Threebed.src='" + obj3BedOff + "'";
    //var fourbed = document.getElementById('Fourbed_a');
    //fourbed.onMouseOut = "document.Fourbed.src='" + obj4BedOff + "'";
    
    //Load the new floorplan
    var elimg = document.getElementById('imgFloorplan');
    elimg.src = objSrc;
    elimg.alt = objAltText;

    //now set the current one
    var newbed = document.getElementById(objImgID);
    newbed.src = objNewButImg;
    
    //now set the 'compare accommodation' link to the bedroom count selected
    var compAnc = document.getElementById('CompareAccomm');
    if (compAnc) {
        if (objBedCount == 1)
            compAnc.href = "../By_Bedroom/onebedroom.jsp";
        if (objBedCount == 2)
            compAnc.href = "../By_Bedroom/twobedroom.jsp";
        if (objBedCount == 3)
            compAnc.href = "../By_Bedroom/threebedroom.jsp";
        if (objBedCount == 4)
            compAnc.href = "../By_Bedroom/index.jsp";
    }
    
    //finally the title
    var newtitle = document.getElementById('FloorplanTitle');
    if (objBedCount == 1) 
        newtitle.innerHTML = "Floorplan - " + objBedCount + " Bedroom";
    else
        newtitle.innerHTML = "Floorplan - " + objBedCount + " Bedrooms";    
}

function SwitchOnFirstPolaroids(bgColour) {

    if (document.getElementById("polaroid11"))
        document.getElementById("polaroid11").style.backgroundColor = bgColour;
    if (document.getElementById("polaroid21"))
        document.getElementById("polaroid21").style.backgroundColor = bgColour;
    if (document.getElementById("polaroid31"))
        document.getElementById("polaroid31").style.backgroundColor = bgColour;
    if (document.getElementById("polaroid41"))
        document.getElementById("polaroid41").style.backgroundColor = bgColour;
    if (document.getElementById("polaroid51"))
        document.getElementById("polaroid51").style.backgroundColor = bgColour;
    if (document.getElementById("polaroid61"))
        document.getElementById("polaroid61").style.backgroundColor = bgColour;
}

function SwitchOffAllPolaroids() {

    if (document.getElementById("polaroid11"))
        document.getElementById("polaroid11").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid12"))
        document.getElementById("polaroid12").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid13"))
        document.getElementById("polaroid13").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid14"))
        document.getElementById("polaroid14").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid15"))
        document.getElementById("polaroid15").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid16"))
        document.getElementById("polaroid16").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid17"))
        document.getElementById("polaroid17").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid18"))
        document.getElementById("polaroid18").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid21"))
        document.getElementById("polaroid21").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid22"))
        document.getElementById("polaroid22").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid23"))
        document.getElementById("polaroid23").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid24"))
        document.getElementById("polaroid24").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid25"))
        document.getElementById("polaroid25").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid26"))
        document.getElementById("polaroid26").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid27"))
        document.getElementById("polaroid27").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid28"))
        document.getElementById("polaroid28").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid31"))
        document.getElementById("polaroid31").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid32"))
        document.getElementById("polaroid32").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid33"))
        document.getElementById("polaroid33").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid34"))
        document.getElementById("polaroid34").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid35"))
        document.getElementById("polaroid35").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid36"))
        document.getElementById("polaroid36").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid37"))
        document.getElementById("polaroid37").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid38"))
        document.getElementById("polaroid38").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid41"))
        document.getElementById("polaroid41").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid42"))
        document.getElementById("polaroid42").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid43"))
        document.getElementById("polaroid43").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid44"))
        document.getElementById("polaroid44").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid45"))
        document.getElementById("polaroid45").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid46"))
        document.getElementById("polaroid46").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid47"))
        document.getElementById("polaroid47").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid48"))
        document.getElementById("polaroid48").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid51"))
        document.getElementById("polaroid51").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid52"))
        document.getElementById("polaroid52").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid53"))
        document.getElementById("polaroid53").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid54"))
        document.getElementById("polaroid54").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid55"))
        document.getElementById("polaroid55").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid56"))
        document.getElementById("polaroid56").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid57"))
        document.getElementById("polaroid57").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid58"))
        document.getElementById("polaroid58").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid61"))
        document.getElementById("polaroid61").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid62"))
        document.getElementById("polaroid62").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid63"))
        document.getElementById("polaroid63").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid64"))
        document.getElementById("polaroid64").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid65"))
        document.getElementById("polaroid65").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid66"))
        document.getElementById("polaroid66").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid67"))
        document.getElementById("polaroid67").style.backgroundColor = '#ffffff';
    if (document.getElementById("polaroid68"))
        document.getElementById("polaroid68").style.backgroundColor = '#ffffff';
}


function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}

function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}