function fnSearchToggle(sType){
	
	if(sType == 'map'){
		document.getElementById('searchform').style.display = 'none';
		document.getElementById('mapsearch').style.display = 'block';
		document.getElementById('form').style.background = '#ECECEC';
		document.getElementById('map').style.background = '#EBF2F7';
		document.getElementById('form').innerHTML = '<a href="/" onclick="javascript:fnSearchToggle(\'\');return false;">Find Accommodation</a>';
		document.getElementById('map').innerHTML = '<span>Map Search</span>';
	}
	else{
		document.getElementById('searchform').style.display = 'block';
		document.getElementById('mapsearch').style.display = 'none';
		document.getElementById('form').style.background = '#EBF2F7';
		document.getElementById('map').style.background = '#ECECEC';
		document.getElementById('map').innerHTML = '<a href="/" onclick="javascript:fnSearchToggle(\'map\');return false;">Map Search</a>';
		document.getElementById('form').innerHTML = '<span>Find Accommodation</span>';
	}
}
function fnShowRegion(sRegion){
	
	if(sRegion != '')
		document.getElementById('regionmap').src = '/images/map-' + sRegion + '.gif';
	else
		document.getElementById('regionmap').src = '/images/map-main.gif';
}
function doPreload(){
//   var the_images = new Array('/images/map-east.gif','/images/map-heart.gif',
//   '/images/map-lakedistrict.gif','/images/map-london.gif','/images/map-northumberland.gif',
//   '/images/map-nwcities.gif','/images/map-peakdistrict.gif','/images/map-southeast.gif',
//   '/images/map-southwest.gif','/images/map-wales.gif','/images/map-ysdales.gif',
//   '/images/map-yswoldsmoorcoast.gif','/images/accommodation-canterbury.jpg', 
//   '/images/accommodation-canterbury2.jpg', '/images/accommodation-canterbury3.jpg');

   var the_images = new Array();
   preloadImages(the_images);
}
function preloadImages(the_images_array){

   for(var loop = 0; loop < the_images_array.length; loop++){
 	var an_image = new Image();
	an_image.src = the_images_array[loop];
   }
}
function thumb(pic,alt)
{	
	document.getElementById('thumb').src = pic;
	document.getElementById('thumb').alt = alt;    
}
function toggleSearchOptions(){
						
	if(document.getElementById('roomtype').style.display == 'block'){
		document.getElementById('roomtype').style.display = 'none';
		document.getElementById('facilities').style.display = 'none';
		document.getElementById('searchoptionstext').innerHTML = 'Advanced';
		document.getElementById('searchoptions').className = '';
	}
	else{
		document.getElementById('roomtype').style.display = 'block';
		document.getElementById('facilities').style.display = 'block';
		document.getElementById('searchoptionstext').innerHTML = 'Standard';
		document.getElementById('searchoptions').className = 'on';
	}

}
// sets up new window link for print friendly version of the page
function externalLinks() {

	if(!document.getElementById('pagetools')) // a page without the print link
		return;

	var x = document.getElementById('pagetools');
	var aAnchors = x.getElementsByTagName('a');
	var anchor = aAnchors[1]; // print friendly anchor
	anchor.target = "_blank";
	anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window)" : "opens in a new window";
}
function fnHideAdvancedForm(){
	if(document.getElementById('roomtype')){
		document.getElementById('roomtype').style.display = 'none';
		document.getElementById('facilities').style.display = 'none';
	}
}

sfHover = function() {
	var sfEls = document.getElementById("globalnav").getElementsByTagName("DD");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
function fnSelectDisable(sDisable,sPage){
		
		var sEnable = 'Accomodations';
		
		if(sDisable == 'Accomodations')
			sEnable = 'Locations';

		document.getElementById('FindAccomodation'+sPage+'_ddl'+sEnable).disabled = false;
		document.getElementById('FindAccomodation'+sPage+'_ddl'+sDisable).disabled = true;
}
function fnInitSelectDisable(){
	// check for presence of the accomm form
	if(document.getElementById('FindAccomodationHome_rbBookTypeAccomodation') || 
	document.getElementById('FindAccomodation_rbBookTypeAccomodation')){
		
		var sPage = ''; // inner page form
		
		if(document.getElementById('FindAccomodationHome_rbBookTypeAccomodation'))
			sPage = 'Home';// home page form
		
		var x = document.getElementById('FindAccomodation'+sPage+'_rbBookTypeLocation');
		x.onfocus = function (){fnSelectDisable('Accomodations',sPage)};
		x.onclick = function (){fnSelectDisable('Accomodations',sPage)};
		
		var y = document.getElementById('FindAccomodation'+sPage+'_rbBookTypeAccomodation');
		y.onfocus = function (){fnSelectDisable('Locations',sPage)};
		y.onclick = function (){fnSelectDisable('Locations',sPage)};
		
		if(document.getElementById('FindAccomodation'+sPage+'_rbBookTypeAccomodation').checked)
			document.getElementById('FindAccomodation'+sPage+'_ddlLocations').disabled = true;
		else
			document.getElementById('FindAccomodation'+sPage+'_ddlAccomodations').disabled = true;
	}
}
function fnReturnFalse(){
	return false
}
function fnDisableContextMenu(){
	/* Disable context menu (IE only) on images in listed divs - avoid IE collapsing bug when user gets image properties */
	if (window.attachEvent){
		for (i=0;i<arguments.length;i++){
			if (document.getElementById(arguments[i])){
				imgs = document.getElementById(arguments[i]).getElementsByTagName("img");
				for (j=0;j<imgs.length;j++){
					imgs[j].attachEvent("oncontextmenu", fnReturnFalse);
				}
			}
		}
	}
}
// replaces link text with a specific class adding '<wbr>' after each character 
// so that the link will wrap inside a container in FireFox
function wraplinks()
{
	if(document.getElementById('hostelinfo')) {
		var links = document.getElementById('hostelinfo').getElementsByTagName('a');
		for(var i=0;i<links.length;i++)
		{
			if (links[i].innerHTML.length > 10 && links[i].className=="linkwrap")
			{
				links[i].innerHTML = generateLinkWrap(links[i].innerHTML);
			}
		}
	}
}
function generateLinkWrap(strLink)
{
	var wrapstr = "<wbr>";
	var tmparr = strLink.split('');
	var tmpstr = tmparr.join(wrapstr);
	return tmpstr;
}


function clickButton(e, buttonid)
{

      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);
      
      if (bt)
      {
          if (evt.keyCode == 13)
          {
               bt.click(); 
               return false;
          }
     }
}

window.addEvent('domready', function() {
	wraplinks();
	fnHideAdvancedForm();
	fnInitSelectDisable();
	externalLinks();
	doPreload();

});

if (window.attachEvent) {
	window.addEvent('domready', function() {
		sfHover();
		fnDisableContextMenu("banner");
	})
}

//function fnRunOnload(){
//	fnHideAdvancedForm();
//	fnInitSelectDisable();
//	externalLinks();
//	doPreload();
//	wraplinks();
//	if (window.attachEvent) window.attachEvent("onload", sfHover);
//	if (window.attachEvent) fnDisableContextMenu("banner")/*list of ids*/;
//}
//window.onload = fnRunOnload;

function toggleValidFromVisibility(sPaymentType)
{
	divValidFrom = document.getElementById("dValidFrom");

	if (sPaymentType == "4" || sPaymentType == "5" || sPaymentType == "6")
	{
		divValidFrom.style.display = "";
	}
	else
	{
		divValidFrom.style.display = "none";
	}
}

function PopWindow(url, windowName, args) {
  window.open(url, windowName, args)
  return false
}
