// JavaScript Document

$(document).ready(function() {
    
    var urlPrxy = "js_proxy.php?acc=";

    $.ajaxSetup ({  
        cache: false  
    });
    
	function buildResult(){
		
	}
	
	function closeResult(){
		$("#li_res").toggle("slow");
		$("#li_items").html("");
	}
	
	function buildCountry(){
		 $.ajax({
		   type: "GET",
		   url: urlPrxy+"li_paises&lang="+language,
		   success: function(msg){
		      msg = '<option value="0">'+country_name+'</option>'+msg;
			 $("#dest_country").html(msg);
		   }
		 });
	}
	
	function buildCity(country){
		 $.ajax({
		   type: "GET",
		   url: urlPrxy+"li_ciudades&ctry="+country+"&lang="+language, 
            success: function(responseText){
                responseText = '<option value="0">'+city_name+'</option>'+responseText;
                $("#dest_city").html(responseText);  
            }
		 });
	}
	
	function searchHotels(){
		var esciudad = $("#dest_city :selected").val();
		if(esciudad>0){
			$.getJSON( urlPrxy + 'li_hoteles&cit=' + $("#dest_city :selected").val()+'&cod='+cod+'&lang='+language ,
			   function(msg){
				  if($("#li_items").html()==""){
					 $("#li_res").toggle("slow");
				 }else{
					 $("#li_items").html("");
				 }
				 
				 $("#li_items").html(msg.hoteles);
				 $("#li_head_title").html(msg.ciudad);
			   }
			);
		}else{
			$.getJSON( urlPrxy + 'li_hoteles_pais&pai=' + $("#dest_country :selected").val()+'&cod='+cod+'&lang='+language ,
			   function(msg){
				  if($("#li_items").html()==""){
					 $("#li_res").toggle("slow");
				 }else{
					 $("#li_items").html("");
				 }
				 
				 $("#li_items").html(msg.hoteles);
				 $("#li_head_title").html(msg.ciudad);
			   }
			);
		}
	}
	
	$("#li_close").click(function(){
		closeResult();
	});
    
    $("#dest_country").change(function(){
			if($(this).val()>0){
				$("#dest_city").attr('disabled','');
			}else{
				$("#dest_city").attr('disabled','disabled');
			}
			buildCity($(this).val());
	});
	$("#langselect").change(function(){
		if( $(this).val()=='es'){
			location.href= ( year == 2012 )? 'MasterCard_2012_es.htm' : 'MasterCard_2011_es.htm';
		}else if( $(this).val()=='pt'){
			location.href = ( year == 2012 )? 'MasterCard_2012_pt.htm' : 'MasterCard_2011_pt.htm';
		}else if( $(this).val()=='en'){
			location.href = ( year == 2012 )? 'MasterCard_2012_en.htm' : 'MasterCard_2011_en.htm';
		}
	});
	$(".btnimg").click(function(){
		searchHotels();
	});
	
    $(".stwa-brandsa-1").click(function(){ document.location.href = 'http://www.starwoodhotels.com/stregis/index.html?language='+lang_Omn+'&'+cod_prom });
    $(".stwa-brandsa-2").click(function(){ document.location.href = 'http://www.starwoodhotels.com/luxury/index.html?language='+lang_Omn+'&'+cod_prom });
    $(".stwa-brandsa-3").click(function(){ document.location.href = 'http://www.starwoodhotels.com/whotels/index.html?language='+lang_Omn+'&'+cod_prom });
    $(".stwa-brandsa-4").click(function(){ document.location.href = 'http://www.starwoodhotels.com/lemeridien/index.html?language='+lang_Omn+'&'+cod_prom });
    $(".stwa-brandsa-5").click(function(){ document.location.href = 'http://www.starwoodhotels.com/westin/index.html?language='+lang_Omn+'&'+cod_prom });
    $(".stwa-brandsa-6").click(function(){ document.location.href = 'http://www.starwoodhotels.com/sheraton/index.html?language='+lang_Omn+'&'+cod_prom });
    $(".stwa-brandsa-7").click(function(){ document.location.href = 'http://www.starwoodhotels.com/alofthotels/index.html?language='+lang_Omn+'&'+cod_prom });
    $(".stwa-brandsa-8").click(function(){ document.location.href = 'http://www.starwoodhotels.com/element/index.html?language='+lang_Omn+'&'+cod_prom });
    $(".stwa-brandsa-9").click(function(){ document.location.href = 'http://www.starwoodhotels.com/fourpoints/index.html?language='+lang_Omn+'&'+cod_prom });
	
    $("#dest_city").attr('disabled','disabled');
    buildCountry();
	$("#langselect option[value='"+language+"']").attr('selected', 'selected');
	
});
