
var test;

function preloadSpacer(){

 
  spacerIMG = new Image();
  spacerIMG.src = "images/spacer.gif";

  //We also load the cursor of the menu
  menuBulletImg = new Image();
  menuBulletImg = "images/menuBullet.jpg";

}


function setSelectDefault(formName,selectName,preSelectedValue){
  var frm = document.forms[formName];
  var indexOfSelectedValue=-1;
    
  //alert("Setting value for " + selectName + " on form " + formName + "\nPre-selected value: " + preSelectedValue);
    
    	for (var i=0;i<frm.elements[selectName].options.length;i++){
                if (frm.elements[selectName].options[i].value == preSelectedValue){
                	indexOfSelectedValue = i;
                	break;		
                }
        }
        
       	if (indexOfSelectedValue >= 0){
       			frm.elements[selectName].selectedIndex = indexOfSelectedValue;
       	}
}

    function openSearchPopUp(){

            //var urlToOpen = "http://www.tophotelchoices.com/searchPopup.html";
            var urlToOpen = "searchPopup.html";
            var searchPopupWindow = window.open(urlToOpen,"THCSearchPopup","width=340,height=375,menubar=no,status=no,scrollbars=no,resizable=no,dependent,titlebar=no");
            searchPopupWindow.focus();
            
   }


function openMaintenance(outageID){

            //var urlToOpen = "http://www.tophotelchoices.com/searchPopup.html";
            var urlToOpen = "outage.jsp?outage=" +  outageID;
            var maintenanceWindow = window.open(urlToOpen,"THCMaintenance","width=340,height=375,menubar=no,status=no,scrollbars=no,resizable=no,dependent,titlebar=no");
            maintenanceWindow.focus();
            
   }


   function closeSearchPopup(){
        searchPopupWindow = window.open("","THCSearchPopup","width=10,height=10");
        searchPopupWindow.close();
    }



function showHideRoomTypeOld(maxNo){
//This function takes as an argument the maximum no of rooms and assumes that there is one 
//more layer, giving details for what customers should do if they want more rooms
//It checks the no rooms selected and if this is less than or equal to maxNo it shows the appropriate layers
//hiding all the rest.  If no rooms selected is greater than maxNo it hides all layers showing only the last one.


    var noRoomsIx = document.forms["hotelSearchForm"].elements["noRooms"].selectedIndex;
    var noRooms = document.forms["hotelSearchForm"].elements["noRooms"].options[noRoomsIx].value;
    var sectionToStartHide = parseInt(noRooms,10)+1;


        if (noRooms > maxNo){

                for (var i=1;i<=maxNo;i++){

                    if (document.getElementById) {
                        document.getElementById(i).style.visibility = "hidden";
                        document.getElementById(i).visibility = "hidden";
                    }
                    else if (document.all) {
                            document.all[i].style.visibility = "hidden";
                    }
                    else {
                            document.layers[i].visibility = "hide";
                    }


                }
                
            if (document.getElementById) {
                document.getElementById(maxNo+1).style.visibility = "visible";
                document.getElementById(maxNo+1).visibility = 'visible';
            }
            else if (document.all) {
                    document.all[maxNo+1].style.visibility = "visible";
            }
            else {
                    document.layers[maxNo+1].visibility = "show";
            }

        }
        else {

                if (document.getElementById) {
                    document.getElementById(maxNo+1).style.visibility = "hidden";
                    document.getElementById(maxNo+1).visibility = 'hidden';
                }
                else if (document.all) {
                        document.all[maxNo+1].style.visibility = "hidden";
                }
                else {
                        document.layers[maxNo+1].visibility = "hide";
                }


                for (var i=1;i<=noRooms;i++){
               
                   if (document.getElementById) {
                        document.getElementById(i).style.visibility = "visible";
                        document.getElementById(i).visibility = "visible";
                    }
                    else if (document.all) {
                            document.all[i].style.visibility = "visible";
                    }
                    else {
                            document.layers[i].visibility = "show";
                    }
                }
                
      

                for (var i=sectionToStartHide;i<=maxNo;i++){
          
                    if (document.getElementById) {
                        document.getElementById(i).style.visibility = "hidden";
                        document.getElementById(i).visibility = "hidden";
                    }
                    else if (document.all) {
                            document.all[i].style.visibility = "hidden";
                    }
                    else {
                            document.layers[i].visibility = "hide";
                    }


                }
        }
}



function showHideRoomType(maxNo){
//This function takes as an argument the maximum no of rooms and assumes that there is one 
//more layer, giving details for what customers should do if they want more rooms
//It checks the no rooms selected and if this is less than or equal to maxNo it shows the appropriate layers
//hiding all the rest.  If no rooms selected is greater than maxNo it hides all layers showing only the last one.


    var noRoomsIx = document.forms["hotelSearchForm"].elements["noRooms"].selectedIndex;
    var noRooms = document.forms["hotelSearchForm"].elements["noRooms"].options[noRoomsIx].value;
    var sectionToStartHide = parseInt(noRooms,10)+1;


        if (noRooms > maxNo){

                for (var i=1;i<=maxNo;i++){

                    if (document.getElementById) {
                        document.getElementById(i).style.display = "none";
                        document.getElementById(i).display = "none";

                        document.getElementById("extraBed" +i).style.display = "none";
                        document.getElementById("extraBed" +i).display = "none";


                    }
                    else if (document.all) {
                            document.all[i].style.display = "none";

                            document.all["extraBed" +i].style.display = "none";
                    }
                    else {
                             document.layers[i].display = "none";

                            document.layers["extraBed" +i].display = "none";
                    }


                }
                
            if (document.getElementById) {
                document.getElementById(maxNo+1).style.display = "block";
                document.getElementById(maxNo+1).display = 'block';
            }
            else if (document.all) {
                    document.all[maxNo+1].style.display = "block";
            }
            else {
                    document.layers[maxNo+1].display = "block";
            }

        }
        else {

                if (document.getElementById) {
                    document.getElementById(maxNo+1).style.display = "none";
                    document.getElementById(maxNo+1).display = 'none';
                }
                else if (document.all) {
                        document.all[maxNo+1].style.display = "none";
                }
                else {
                        document.layers[maxNo+1].display = "none";
                }


                for (var i=1;i<=noRooms;i++){
                    
                   if (document.getElementById) {
                        document.getElementById(i).style.display = "block";
                        document.getElementById(i).display = "block";

                        document.getElementById("extraBed" + i).style.display = "block";
                        document.getElementById("extraBed" + i).display = "block";
                    }
                    else if (document.all) {
                            document.all[i].style.display = "block";

                            document.all["extraBed" + i].style.display = "block";
                    }
                    else {
                            document.layers[i].display = "block";

                            document.layers["extraBed" + i].display = "block";
                    }
                }
                
      

                for (var i=sectionToStartHide;i<=maxNo;i++){
          
                    if (document.getElementById) {
                        document.getElementById(i).style.display = "none";
                        document.getElementById(i).display = "none";

                        document.getElementById("extraBed" + i).style.display = "none";
                        document.getElementById("extraBed" + i).display = "none";
                    }
                    else if (document.all) {
                            document.all[i].style.display = "none";

                            document.all["extraBed" + i].style.display = "none";
                    }
                    else {
                            document.layers[i].display = "none";

                            document.all["extraBed" + i].style.display = "none";
                    }


                }
        }
}


function triggerExtraBed(roomIndex){

    var selectedRoomTypeIx = document.forms["hotelSearchForm"].elements["RoomType"+roomIndex].selectedIndex;
    var selectedRoomType = document.forms["hotelSearchForm"].elements["RoomType"+roomIndex].options[selectedRoomTypeIx].value;

    var showExtraBedCheckBox;
    var divToShowOrHide = "extraBed" + roomIndex;
    var checkBoxName ="room" + roomIndex +"ExtraBed";

        if (selectedRoomType != 0){
                showExtraBedCheckBox = (document.forms["hotelSearchForm"].elements[selectedRoomType+ "ExtraBed"].value == "true");
        }
        else {
                showExtraBedCheckBox = false;
        }

        if (showExtraBedCheckBox){
            document.forms["hotelSearchForm"].elements[checkBoxName].disabled = false;
        }
        else {
            document.forms["hotelSearchForm"].elements[checkBoxName].disabled = true;
            document.forms["hotelSearchForm"].elements[checkBoxName].checked = false;
        }   
    
/*
                if (showExtraBedCheckBox){
                    if (document.getElementById) {
                        document.getElementById(divToShowOrHide).style.display = "block";
                        document.getElementById(divToShowOrHide).display = 'block';
                    }
                    else if (document.all) {
                            document.all[divToShowOrHide].style.display = "block";
                    }
                    else {
                            document.layers[divToShowOrHide].display = "block";
                    }
                }
                else {

                    if (document.getElementById) {
                        document.getElementById(divToShowOrHide).style.display = "none";
                        document.getElementById(divToShowOrHide).display = 'none';
                    }
                    else if (document.all) {
                            document.all[divToShowOrHide].style.display = "none";
                    }
                    else {
                            document.layers[divToShowOrHide].display = "none";
                    }


                    document.forms["hotelSearchForm"].elements[checkBoxName].checked = false;
                    

                }
*/
   
}


function getObject(name){


  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }


}


function isObjectVisible(objectName){
//Returns true or false using the Dixtsplay CSS attribute to determine if an object is visible or not
    var curObj = new getObject(objectName);
  
    return curObj.style.display != "none";
}


function changeTextColour(objectName,newColour){

    var curObj = new getObject(objectName);
    curObj.style.color = newColour;

}


function textCounter(field, countfield, maxlimit) {
        //alert("Field length: " + field.value.length);
          if (field.value.length > maxlimit){ // if too long...trim it!
            field.value = field.value.substring(0, maxlimit);
            // otherwise, update 'characters left' counter
          }
          else {
            countfield.value = maxlimit - field.value.length;
          }

}


