function get_states(country) {
	if(country != '')
	{
		new Ajax.Request('index.php', {
			method: 'post',
			parameters: {
				'fx':'get_states',
				'country':country
			},
			onSuccess: function(transport) {
				$('state').update(transport.responseText);
				$('state').show();
				/*get_properties(country,'',lang,iata,brand);*/
			}
		});
	}
}
function get_properties(country,city) {
	if(country != '' && city != '')
	{
	new Ajax.Request('index.php', {
		method:'post',
		parameters: {
			'fx': 'show_properties', 
			'country':country,
			'city':city
		},
		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);
		  $('content').style.display='block';
		  $('search-again').show();
		  select_first_offer();
		},
		onFailure: function(){$('content').innerHTML = '<h2>Error connecting to server</h2>';}
	  });
	}
	else {
		alert('Please select a Country and a City');	
	}
}

/*
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,copy)
{
	$('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">'+copy+'</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();
}
