function resetCities(lang)
{
	$('city').update('');	
	$('city').disabled = true;
}

function getCities(lang) {
	resetCities(lang);
	if ($('country').value.blank()) { return true; }
	$('city').disabled = false;
	
	new Ajax.Request('index.php', {
		method:'post',
		parameters:{
			'fx':'getCities',
			'country':$('country').value,
			'language': lang
		},
		onSuccess: function(transport){
			$('city').insert(transport.responseText);
			$('city').firstDescendant().selected = true;
		}
	});
}
function getProperties(lang) {	
    if ($('country').value.blank()) { alert('Please select a country.'); return true; }
	new Ajax.Request('index.php', {
		method:'post',
		parameters: {
			'fx': 'getProperties', 
			'country':$('country').value,
			'city':$('city').value,
			'language': lang
		},
		onLoading: function() {
			//new Effect.BlindUp('banner',{duration:3});
			//$('banner').hide();
			$('content').update('<div style="padding:100px 450px;background: #ffffff; margin: 0px;"><img src="templates/default/assets/images/wait30.gif" /></div>');
			$('content').style.display='block';
		},
		onSuccess: function(transport){
		  $('content').update(transport.responseText);
		  
		  // Vertically center lines that wrap around
		  $$('.percent-off-label').each(function (s) {
			if (s.up().className == 'percent-content-3')
				if (s.getDimensions().height == 32)
					s.style.marginTop = '5px';
		  });
		    		  
		  $('content').style.display='block';
		  $('search-again').show();
		  //select_first_offer();		  
		},
		onFailure: function(){$('content').innerHTML = '<h2>Error connecting to server</h2>';}
	  });	
}

function getAllProperties(lang){
	new Ajax.Request('index.php', {
		method:'post',
		parameters: {
			'fx': 'getAllProperties', 			
			'language': lang
		},
		onLoading: function() {
			//new Effect.BlindUp('banner',{duration:3});
			//$('banner').hide();
			$('content').update('<div style="padding:100px 450px;background: #ffffff; margin: 0px;"><img src="templates/default/assets/images/wait30.gif" /></div>');
			$('content').style.display='block';
		},
		onSuccess: function(transport){
		  $('content').update(transport.responseText);
		  
		  // Vertically center lines that wrap around
		  $$('.percent-off-label').each(function (s) {
			if (s.up().className == 'percent-content-3')
				if (s.getDimensions().height == 32)
					s.style.marginTop = '5px';
		  });
		  
		  $('content').style.display='block';
		  $('search-again').show();
		  //select_first_offer();		  
		},
		onFailure: function(){$('content').innerHTML = '<h2>Error connecting to server</h2>';}
	  });	
}

/*
function loadImage(propID) {
	var thumb = propID.toString()
	$(thumb).setStyle({display:'block'});
}
function unLoadImage(propID) {
	var thumb = propID.toString()
	$(thumb).setStyle({display:'none'});
}
*/

function select_first_offer() {
	var text, matches;
	
	$$('.percent-content-1').each(function(thing) {
		text = thing.down().attributes["onclick"].value;
		// selectOff(1,115,3,'templates/default/assets/images/savenow2.gif','http://www.starwoodhotels.com/sheraton/search/pre_decider_all.html?propertyID=115&language=en-US&IM=LP_LIVEALITTLE_LITTLE_SI_115','Stay one night and enjoy our best available rate - guaranteed!');
		
		text = text.substring(10, (text.length - 2)); // Tried regexp and failed
		
		matches = text.split(',');
		
		matches.each(function(mtch, i) {
			matches[i] = mtch.replace(/^[\s'"]+|[\s'"]+$/g, ""); // Trim whitespace and quotes
		});
		
		selectOff(matches[0], matches[1], matches[2], matches[3], matches[4], matches[5]); // Dynamic type ambiguity
		thing.down().checked = true;
	});
}

function selectOff(loc,id,howMany,booknow,booknow_url,lang,copyId)
{
	$('percent-choice-'+loc+'-'+id).style.background = '#f5f2eb';

	if(loc == 1){
		if ($('percent-choice-2-'+id)) $('percent-choice-2-'+id).style.background = '#dfdbd5';
		if($('percent-choice-3-'+id)) $('percent-choice-3-'+id).style.background = '#dfdbd5';				
	}
	else if(loc == 2)
	{
		if ($('percent-choice-1-'+id)) $('percent-choice-1-'+id).style.background = '#dfdbd5';
		if ($('percent-choice-3-'+id)) $('percent-choice-3-'+id).style.background = '#dfdbd5';		
	}
	else if(loc == 3){
		if ($('percent-choice-1-'+id)) $('percent-choice-1-'+id).style.background = '#dfdbd5';
		if ($('percent-choice-2-'+id)) $('percent-choice-2-'+id).style.background = '#dfdbd5';		
	}	
	
	var percent = loc+1;
	if(loc==2)
	{
		var plus= '+';	
	}
	else {
		var plus=''	
	}
	$('price_' + id).innerHTML = '<p class="offers">'+offerCopy[lang][copyId]+'</p>';
		
	$('price_' + id).innerHTML += '<a href="' + booknow_url + '" class="booknow" target="_blank" style="background: url('+booknow+') no-repeat;"></a>';
}
function photoPopup(url) {
	window.open(url,'photosPopUp','width=600,height=416,resizable=no,scrollbars=no,status=no');
}

function showHeader(){
	new Effect.BlindDown('banner',{duration:2});
	$('search-again').hide();
}

function loadImage(propID) {
	var thumb = propID.toString()
	$(thumb).setStyle({display:'block'});
}

function unLoadImage(propID) {
	var thumb = propID.toString()
	$(thumb).setStyle({display:'none'});
}