// -- for Internet Explorer - stops background flickering --//
   /*@cc_on 
	@if (@_win32)
	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
	@end
@*/
// -- addLoadEvent function from http://simonwillison.net --//
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

//---- DROPDOWN LIST SYNC ----//
addLoadEvent(filterDestinations);
function hideOpt(opt,select){
  //var opt = document.getElementById(id);
  var sel = select;
  opt && sel && sel.appendChild(opt.cloneNode(true));
}

function showOpt(opt,select){ 
  var dest = select;//document.getElementById('ctl00_FindHotel1_fDestinationselect');
  if (opt) {
    if (dest) {
      dest.appendChild(opt.cloneNode(true));
    }
  }
} 

function moveSelectOption(select,selectcopy,start1,start2) {
    selectcopy.options.length=start2;
    for(i=start1;i<select.length;i++)
	{  //ignore the first please select
       hideOpt(select.options[i],selectcopy);
	}
	select.options.length=start1;
}
function findByValue(select,value){
    var valueToSelect = value;
    var mySelect = select;
    for (var index = 0, roof = mySelect.options.length; index < roof; index++) {
       if (valueToSelect == mySelect.options[index].value) {
          return mySelect.options[index];
       }
    }
}
function filterDestinations(){
    
        if (typeof cIdTempSelectArrayId != 'undefined') 
            {for (var index = 0, roof = cIdTempSelectArrayId.length; index < roof; index++)
                {subFilterDestinations(cIdTempSelectArrayId[index][0],cIdTempSelectArrayId[index][1],cIdTempSelectArrayId[index][2]);}
        } 
    
}

function subFilterDestinations(tempId,mainSelect,subSelect){
  var temp = document.getElementById(tempId);
  var country,dest,selectedValue,mainS,subS;
  
  if (temp) if (mainSelect) country = document.getElementById(mainSelect);
  if (temp) if (mainSelect) dest = document.getElementById(subSelect);
  
  if (temp && country && dest) {
      selectedValue=dest.options[dest.selectedIndex].value;
      if (temp.length == 0 ) moveSelectOption(dest,temp,1,0);
      dest.options.length=1;
      if (country) {
        for (var currObj in CountrySlhDest){
           if (CountrySlhDest[currObj][country.value]) {showOpt(findByValue(temp,CountrySlhDest[currObj][country.value]),dest);}
        }
        if (country.selectedIndex==0) {moveSelectOption(temp,dest,0,1);}
        if (dest.options.length == 1 && (dest.options[0].text=='Please Choose' || dest.options[0].text=='-- Not Applicable --')) dest.options[0].text = '-- Not Applicable --'; else if (dest.options[0].text=='Please Choose' || dest.options[0].text=='-- Not Applicable --') dest.options[0].text='Please Choose';
      }
      var obj=findByValue(dest, selectedValue)
      if (obj) obj.setAttribute('selected',true);  
   }   
}

