<!--

function clearSubnav(elementNumber)
{
	for (var x=0;x<8;x++)
	{
		document.getElementById('mms-subnav-'+x).style.display='none';
		if (x != elementNumber && 'active' != document.getElementById('nav'+x).childNodes[0].className)
		{
			document.getElementById('nav'+x).childNodes[0].className='';
		}
	}
	
	if (document.getElementById('nav'+elementNumber).childNodes[0].className != 'active')
	{
		document.getElementById('nav'+elementNumber).childNodes[0].className='activehover';
	}
	document.getElementById('mms-subnav-'+elementNumber).style.display='block';
			
}

var activeNav = false;



Event.observe(window, 'load', function()
{
	activeNav = $('subnav-collections');
	// $$('#xwd-main-nav li ul').each(Element.hide);

	$$('#xwd-main-nav>li').each(
		function(anchor)
		{
			Event.observe(anchor, 'mouseover', function()
			{
				if(anchor != activeNav)
				{
					showSubNav(anchor);
					activeNav = anchor.down().next();
				}
			});
		}
	);
	
	$$('.oneclicksubmit').each(
		function(submit)
		{
			Event.observe(submit.form, 'submit', function(evt)
			{
				if ('function' == typeof($(submit).disable)){
					$(submit).disable();
				}else{
					$(submit).writeAttribute({ disabled: 'disabled' }).setOpacity(0.25);
				}
			});
		}
	);
	
})

function showSubNav(nav)
{
	var home = '';
	var members = '\
<ul id="subnav-members" class="xwd-subnav">\
	<li class="first"><a href="/members-login">Login</a></li>\
	<li>| <a href="/login">Become a member</a></li>\
	<li>| <a href="/register-card">Register card</a></li>\
	<li>| <a href="/members">Upgrade your membership</a></li>\
</ul>';
	var destinations = '';
	var collections = '';
	var offers = '\
<ul id="subnav-offers" class="xwd-subnav">\
	<li class="first"><a href="/hotel-offers/united-kingdom">UK &amp; Ireland</a></li>\
	<li>| <a href="/hotel-offers/europe">Europe</a></li>\
	<li>| <a href="/hotel-offers/usa">USA</a></li>\
	<li>| <a href="/hotel-offers/asia">Asia</a></li>\
	<li>| <a href="/hotel-offers/rest-of-world">Rest of the world</a></li>\
</ul>';
	var shop = '\
<ul id="subnav-shop" class="xwd-subnav">\
	<li class="first"><a href="/shop/category/books">Books</a></li>\
	<li>| <a href="/shop/category/music">CDs</a></li>\
	<li>| <a href="/mr-and-mrs-smith-get-a-room-gift-vouchers/product-view">Vouchers</a></li>\
	<li>| <a href="/shop/category/special-offers">Special offers</a></li>\
</ul>';
	var maps = '\
<ul id="subnav-maps" class="xwd-subnav">\
	<li class="first"><a href="/smith-maps?name=United%20Kingdom&lat=53.3309&lng=-1.05469&zoom=5">United Kingdom</a></li>\
	<li>| <a href="/smith-maps?name=United%20States&lat=39.3683&lng=-100.547&zoom=4">United States</a></li>\
	<li>| <a href="/smith-maps?name=Germany&lat=51.5087&lng=10.1953&zoom=4">Europe</a></li>\
	<li>| <a href="/smith-maps?name=South%20Africa&lat=-1.6001&lng=23.3789&zoom=3">Africa</a></li>\
	<li>| <a href="/smith-maps?name=Thailand&lat=15.9613&lng=100.898&zoom=3">Asia</a></li>\
	<li>| <a href="/smith-maps?name=Brazil&lat=-9.79568&lng=-54.1406&zoom=3">South America</a></li>\
	<li>| <a href="/smith-maps?name=Indian%20Ocean&lat=10.67957&lng=75.492&zoom=3">Indian Ocean</a></li>\
	<li>| <a href="/smith-maps?name=Australia&lat=-24.3671&lng=132.363&zoom=4">Australasia</a></li>\
	<li>| <a href="/smith-maps?name=Caribbean&lat=17.0778&lng=-81.8091&zoom=4">Caribbean</a></li>\
</ul>';
	var search = '\
<ul id="subnav-search" class="xwd-subnav">\
	<li class="first"><a href="/hotel-search">I know my hotel\'s name</a></li>\
	<li>| <a href="/hotel-search">I know my destination</a></li>\
	<li>| <a href="/hotel-search">Need ideas?</a></li>\
	<li>| <a href="/late-availability/united-kingdom">Late availability</a></li>\
</ul>';
	
	// $$('#xwd-main-nav li ul').each(Element.hide);
	if(activeNav)
	{
		activeNav.hide();
	}
	ulId = nav.identify().substring(4);
	if(!$('subnav-'+ulId) && eval(ulId) != '')
	{
		nav.innerHTML += eval(ulId);
	}
	if(nav.down().next())
	{
		nav.down().next().show();
		activeNav = nav.down().next();
	}
	else
	{
		activeNav = false;
	}
}

function submitSearch()
{
	
	if ($('country_select').value != '')
	{
		 return true;
	}
	else 
	{
		alert('Please select a country to continue'); 
		return false;
	}
}

function submitSearchDestDate()
{
	if ($('date_from').value != '' && $('date_from').value != 'yyyy-mm-dd')
	{
		if ($('nights_select').value < 1)
		{
			alert('Please select number of nights');
			return false;
		}
		if ($('adults').value < 1)
		{
			alert('Please select number of adults');
			return false;
		}		
	}
	
	return true;
}


var smith_offer_active = false;

function toggle_smith_offer_box(layer) 
{
	if (layer == null)
		layer = 'popup-content';
	if (smith_offer_active)
	{
		Effect.Fade(layer, {duration:0.4, queue:'end'});
		//Effect.Fade('popup-bg', {duration:0.2, from:0.5, to:0, queue:'end'});
		smith_offer_active = false;
	}
	else
	{
		//Effect.Appear('popup-bg', {duration:0.2, from:0, to:0.5, queue:'end'});
		Effect.Appear(layer, {duration:0.4, queue:'end'});
		smith_offer_active = true;
	}

	return false
}

var why_book_active = false;

function toggle_why_book()
{
	if (why_book_active)
	{
		Effect.BlindUp('why-book-detail', {duration:0.4, queue:'end'});
		Effect.Fade('why-book-bg', {duration:0.2, from:0.5, to:0, queue:'end'});
		why_book_active = false;
	}
	else
	{
		Effect.Appear('why-book-bg', {duration:0.2, from:0, to:0.5, queue:'end'});
		Effect.BlindDown('why-book-detail', {duration:0.4, queue:'end'});
		why_book_active = true;
	}

	return false;
}



function bookmarker22() 
{
title = "Mr and Mrs Smith - Boutique Hotels"; 
url = "http://www.mrandmrssmith.com";
if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");
} else if( window.external ) { // IE Favorite
window.external.AddFavorite( url, title); }
else if(window.opera && window.print) { // Opera Hotlist
return true; }
}





function getObj(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 if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}


function getref (obj)
{	
    var ref;
    
    if (obj.contentDocument) // For NS6
    {
        ref = obj.contentDocument;
    } 
    
    else if (obj.contentWindow) // For IE5.5 and IE6
    {
        ref = obj.contentWindow.document;
    } 
    
    else if (obj.document) // For IE5
    {
        ref = obj.document;
    }
    else ref = 'error';
    
    return ref;
}


function get_object(id)
{
	if(document.getElementById) 
	{
		return document.getElementById(id);
	}
	else 
	{
		return document.all[id];	
	}
}

function start_late_search()
{
		var indicator_div = get_object('search_indicator'); 
		indicator_div.style.display = 'block';
}

function start_date_search(link)
{
	start_late_search();
	location.href = link;
	return false;
}

function bookmarksite(title,url)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

/*
function textCounter(field, maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
}
*/

function textCounter(field, countfield, maxlimit) {
	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;
}

function check_delete(msg) 
{
	var ok=confirm(msg);
	if (ok)
	  return true;
	else
	  return false;
}

function hotelGalPostBack()
{
// window.opener.document.getElementById("date15_date").value=document.getElementById("date15_date").value;
// window.opener.document.getElementById("date15_month").value=document.getElementById("date15_month").value;
// window.opener.document.getElementById("date15_year").value=document.getElementById("date15_year").value;
window.opener.document.getElementById("date_from").value=document.getElementById("date_from").value;
window.opener.document.getElementById("nights").value=document.getElementById("nights").value;
window.opener.document.getElementById("adults").value=document.getElementById("adults").value;
window.opener.document.getElementById("children").value=document.getElementById("children").value;
window.opener.document.forms['right-bar-booking'].submit();
window.close();
return false;
}

function reviewSetIds(id)
{
	var ids = id.split('~');
	$('review_id').value = ids[0];
	$('review_hotel_id').value = ids[1];
}


function state_to_us(formname, usstate)
{
	if (usstate != "")
		document.forms[formname].country.value = "US";
		
}

function check_country(formname, country)
{
	if (country != "US")
		document.forms[formname].state.value = "";
		
}

function show_field(selected_value,test,show)
{
	if (selected_value == test)
		document.getElementById(show).style.display = "block";
	else
		document.getElementById(show).style.display = "none";					
}

function submitReviewAnswer(answer)
{
	if (1 == answer)	
		document.getElementById('review_survey_answer').value = 'Yes';
	else
		document.getElementById('review_survey_answer').value = 'No';	
		
	$('review_survey_form').submit();	
	return false;
}

function load_survey_page(curr, hide1, hide2)
{
	var currObj 				= document.getElementById(curr);
	var hidefirstObj 			= document.getElementById(hide1);	
	var hidesecondObj 			= document.getElementById(hide2);		
	currObj.style.display 		= "block";
	hidefirstObj.style.display 	= "none";
	hidesecondObj.style.display = "none";
	return false;
}


function checkSurveyForm( theForm )
{
	var form 		= document.getElementById(theForm);	
	tempRadioName 	= '';
	groupCount 		= 0;
	checkedCount 	= 0;
	var subInputs 	= form.getElementsByTagName('input');	
	for (var i=0; i<subInputs.length; i++) // Loops through everything on the form
	{
		obj = subInputs[i];
		if (obj.type == "radio") //if its a radio button
		{
			if(obj.checked == true)	checkedCount = checkedCount + 1;
			else
				x = obj.name;
			if(tempRadioName != obj.name)//if a new group update tempRadioName and count
			{
				groupCount = groupCount + 1;
				tempRadioName = obj.name;
			}
			
		}
	}
	
	if(groupCount != checkedCount)
	{
		alert('Please answer all the items in the survey form.');
		return false;
	}
	else if ('bs-survey-p3' == theForm)
	{
		if (document.getElementById('first_name').value.length < 1) 
		{
			alert('Please enter your first name');
			return false;
		}
		if (document.getElementById('last_name').value.length < 1) 
		{
			alert('Please enter your last name');
			return false;
		}
		if (document.getElementById('email').value != document.getElementById('email2').value) 
		{
			alert('Please confirm your email');
			return false;
		}	
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value))	
		{
			/* do nothing */
		}
		else
		{
			alert('Please enter a valid email address');
			return false;		
			
		}
		
		$('bs-survey-form').submit(); // submit survey form		
	}
	else
	{
		switch (theForm)
		{
			case 'bs-survey-p1':
				load_survey_page('bs-survey-p2', 'bs-survey-p1', 'bs-survey-p3');			
			break;
			case 'bs-survey-p2':
				load_survey_page('bs-survey-p3', 'bs-survey-p1', 'bs-survey-p2');			
			break;
		}		

	}	

}

function checkFormText( theForm, ext )
{
	var form 		= document.getElementById(theForm);	
	var entries 	= 0; 	
	var str_search 	= "email_";
	for (var i=0; i < form.elements.length; i++)
	{
		if (ext)
		{
			var curr_id = form.elements[i].id;
			if ( form.elements[i].type == "text" && form.elements[i].value != "" && curr_id.search(str_search) !=-1 )
			{			
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.elements[i].value)) entries++;			
			}						
		}
		else
		{
			if ( form.elements[i].type == "text" && form.elements[i].value != "" )
			{			
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.elements[i].value)) entries++;			
			}
		}
	}	
	
	if (entries > 0)
	{
		form.submit();	
	}
	else
		alert("Please enter at least one valid email address");
	return false;
}


function checkboxAsRadio(FormName, FieldName, CheckValue)
{
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		for(var i = 0; i < countCheckBoxes; i++)
		{
			if ( CheckValue.value == objCheckBoxes[i].value )
				objCheckBoxes[i].checked = CheckValue;
			else
				objCheckBoxes[i].checked = false;	
		}	
}

var activeNav = false;

// move the selected options up one location in the select list

function moveOptionsUp(selectId) {
 var selectList = document.getElementById(selectId);
 var selectOptions = selectList.getElementsByTagName('option');
 for (var i = 1; i < selectOptions.length; i++) {
  var opt = selectOptions[i];
  if (opt.selected) {
   selectList.removeChild(opt);
   selectList.insertBefore(opt, selectOptions[i - 1]);
     }
    }
}

// move the selected options down one location in the select list

function moveOptionsDown(selectId) {
 var selectList = document.getElementById(selectId);
 var selectOptions = selectList.getElementsByTagName('option');
 for (var i = selectOptions.length - 2; i >= 0; i--) {
  var opt = selectOptions[i];
  if (opt.selected) {
   var nextOpt = selectOptions[i + 1];
   opt = selectList.removeChild(opt);
   nextOpt = selectList.replaceChild(opt, nextOpt);
   selectList.insertBefore(nextOpt, opt);
     }
    }
}


function selAll(obj) {
	obj = (typeof obj == "string") ? document.getElementById(obj) : obj;
	if (obj.tagName.toLowerCase() != "select")
		return;
	for (var i=0; i<obj.length; i++) {
		obj[i].selected = true;
	}
}

function toggleOpenInput(element) {
	
	if ($(element).value == 'open_input')
	{
		if($(element).visible())
		{
			$(element).hide();
			$('open_input').show();
		}
		else
		{
			$(element).show();
			$('open_input').hide();
		}
	}
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


/* JS Overlay */

function toggleOverLay(div_id) {
		var el = document.getElementById(div_id);
		if ( el.style.display == 'none' ) {	el.style.display = 'block';}
		else {el.style.display = 'none';}
	}
	function blanket_size(popUpDivVar) {
		if (typeof window.innerWidth != 'undefined') {
			viewportheight = window.innerHeight;
		} else {
			viewportheight = document.documentElement.clientHeight;
		}
		if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
			blanket_height = viewportheight;
		} else {
			if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
				blanket_height = document.body.parentNode.clientHeight;
			} else {
				blanket_height = document.body.parentNode.scrollHeight;
			}
		}
		var blanket = document.getElementById('blanket');
		blanket.style.height = blanket_height + 'px';
		var popUpDiv = document.getElementById(popUpDivVar);
		popUpDiv_height=blanket_height/2-300;
		popUpDiv.style.top = popUpDiv_height + 'px';
	}
	function window_pos(popUpDivVar, top) {
		if (typeof window.innerWidth != 'undefined') {
			viewportwidth = window.innerHeight;
		} else {
			viewportwidth = document.documentElement.clientHeight;
		}
		if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
			window_width = viewportwidth;
		} else {
			if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
				window_width = document.body.parentNode.clientWidth;
			} else {
				window_width = document.body.parentNode.scrollWidth;
			}
		}
		var popUpDiv = document.getElementById(popUpDivVar);
		window_width=window_width/2-300;
		popUpDiv.style.left = window_width + 'px';
		var setTop = top - 30;
		popUpDiv.style.top = setTop + 'px';

		
	}
	function popup(the_img, eL) {
		document.getElementById('the-img').src = the_img;		
		blanket_size('popUpDiv');
		if (typeof eL === 'undefined')
			elTop = document.getElementById('main_content').offsetTop;
		else
			elTop = document.getElementById(eL).offsetTop;
		window_pos('popUpDiv', elTop);
		toggleOverLay('blanket');
		toggleOverLay('popUpDiv');		
	}

/* END JS Overlay */

//-->

