﻿function goToSearch(continent_id)
{
    var location = "search.aspx?search="+continent_id+"&type=3";    
    window.location = location;
}

//Habría que inicializarlo con Prototype una vez que tengamos fotos en la base
var photoIndex_index = 1;

function getPrevImage(){
    if(photoIndex_index == 1)
    {
    photoIndex_index = 3;
    }
    else
    {
    photoIndex_index = photoIndex_index - 1;
    }
    document.getElementById('photoIndex').src = 'images/photoIndex_'+photoIndex_index+'.jpg';
    
    document.getElementById('img_cont').innerHTML = photoIndex_index;
}

function getNextImgae(){
    if(photoIndex_index == 3){photoIndex_index = 0;}
    photoIndex_index = photoIndex_index + 1;
    document.getElementById('photoIndex').src = 'images/photoIndex_'+photoIndex_index+'.jpg';
    
    document.getElementById('img_cont').innerHTML = photoIndex_index;
} 

function changeImg(link, img) 
{
    link.src = img;
}


function createTip(continent_id, continent_name){ 
    var menu = '<table style="cursor:pointer;"><tr><td onclick="printMostRankingHotels('+continent_id+',\''+continent_name+'\')">View Top-ranked hotels</td></tr><tr><td onclick="printMostRankingCities('+continent_id+',\''+continent_name+'\')">View Top-ranked cities</td></tr><tr><td onclick="printMostRankingRegions('+continent_id+',\''+continent_name+'\')">View Top-ranked regions</td></tr><tr><td onclick="printCountries('+continent_id+',\''+continent_name+'\')">View all countries</td></tr></table>';
    Tip(menu, STICKY, true, DURATION, 5000,FADEIN, 500,CLICKCLOSE, true, SHADOW, true, TITLE, continent_name, PADDING, 9);
}


function printCountries(continent_id,continent_name){
    
    $Ajax("controllers/index.aspx?method=getCountries", {
        cache: false,
        metodo: $metodo.POST,            
        parametros: {"continent_id":continent_id},
        onfinish:function(paises){ 
            var resultTable = '<table class="table_resul_tooltip"><tr><td class="header_resul_tooltip">Countries in '+continent_name+'</td></tr>';
            for(var i=0;i<paises.length;i++){        
                resultTable += '<tr class="tr_resul_tooltip"><td class="td_resul_tooltip" onclick="window.location = \'search.aspx?search='+paises[i].countryName+'&type=1\'"><img src="images/boolet_td_tooltip.gif" width="10" height="6" /> '+paises[i].countryName+'</td></tr>';
            }
            resultTable += '</table>';
            
            $('targetMap').innerHTML = resultTable;            
        }, 
        tipoRespuesta:$tipo.JSON});
    
}


function printMostRankingHotels(continent_id,continent_name){
    $Ajax("controllers/index.aspx?method=getMostRankedHotels", {
        cache: false,
        metodo: $metodo.POST,            
        parametros: {"continent_id":continent_id},
        onfinish:function(hoteles){ 
            var resultTable = '<table class="table_resul_tooltip"><tr><td class="header_resul_tooltip">Top-ranked hotels in '+continent_name+'</td></tr>';
            for(var i=0;i<hoteles.length;i++){        
                resultTable += '<tr class="tr_resul_tooltip"><td class="td_resul_tooltip" onclick="window.location=\''+hoteles[i].url+'\'" ><img src="images/boolet_td_tooltip.gif" width="10" height="6" /> <b>'+unescape(hoteles[i].name)+'</b>, '+hoteles[i].cityName+', '+hoteles[i].countryName+'</td></tr>';                
            }
            resultTable += '</table>';
           
            $('targetMap').innerHTML = resultTable;
        }, 
        tipoRespuesta:$tipo.JSON}); 

}


function printMostRankingCities(continent_id,continent_name){
    $Ajax("controllers/index.aspx?method=getMostRankedCities", {
        cache: false,
        metodo: $metodo.POST,            
        parametros: {"continent_id":continent_id},
        onfinish:function(cities){ 
            var resultTable = '<table class="table_resul_tooltip"><tr><td class="header_resul_tooltip">Top-ranked cities in '+continent_name+'</td></tr>';
            for(var i=0;i<cities.length;i++){        
                resultTable += '<tr class="tr_resul_tooltip"><td class="td_resul_tooltip" onclick="window.location = \''+cities[i].url+'\'" ><img src="images/boolet_td_tooltip.gif" width="10" height="6" /> <b>'+cities[i].name+'</b>, '+cities[i].regionName+', '+
                cities[i].countryName+'</td></tr>';
            }
            resultTable += '</table>';
           
            $('targetMap').innerHTML = resultTable; 
        }, 
        tipoRespuesta:$tipo.JSON});

}

function printMostRankingRegions(continent_id,continent_name){
    $Ajax("controllers/index.aspx?method=getMostRankedRegions", {
        cache: false,
        metodo: $metodo.POST,            
        parametros: {"continent_id":continent_id},
        onfinish:function(region){ 
            var resultTable = '<table class="table_resul_tooltip"><tr><td class="header_resul_tooltip">Top-ranked regions in '+continent_name+'</td></tr>';
            for(var i=0;i<region.length;i++){        
                resultTable += '<tr class="tr_resul_tooltip"><td class="td_resul_tooltip" onclick="window.location = \''+region[i].url+'\'" ><img src="images/boolet_td_tooltip.gif" width="10" height="6" /> <b>'+region[i].name+'</b>, '+region[i].countryName+'</td></tr>';
            }
            resultTable += '</table>';
           
            $('targetMap').innerHTML = resultTable; 
        }, 
        tipoRespuesta:$tipo.JSON});

}
//----->
function AddQuickPhoto(url){
    
    checkAutentication(url); 
    return false;
    
}

//----->

function setHotelsCombo(){
	setEcoContest();
    $Ajax("controllers/index.aspx?method=getComboHotels", {
        cache: false,
        metodo: $metodo.POST,    
        onfinish:function(hotels){
            loadDropDownComboInGroups("cmbHotels", hotels, "Select Hotel");                        
        }, 
        tipoRespuesta:$tipo.JSON});

}

var cmbHotelWait;
//Funcion q llena las opciones de el combo de id suministrado agrupando
function loadDropDownComboInGroups(cmbID, collection, selectone)
{
    var groupId;
    //$(cmbID).innerHTML = "";
    if(selectone){
    var opcion = new Option(selectone, "0");
    $(cmbID).options[$(cmbID).options.length] = opcion;
    }
    for(var i=0;i<collection.length;i++)
    {        
        var item = collection[i];
        if(groupId !=  unescape(item.groupId)){
            groupId = item.groupId;
            var group = document.createElement('optgroup');
            group.label = item.groupName;
            
            $(cmbID).appendChild(group);
        }
        var opc = new Option(item.detail, item.id); 
        opc.label = item.detail; //para q se vea la opcion en IE7
        opc.innerHTML = item.detail; //para q se vea la opcion en IE6
        group.appendChild(opc);
    }
    //----->
    Effect.Fade('divLoadingHotelsCombo', { duration: 1.0 });
    cmbHotelWait = setTimeout(showHotelsCombo, 1500);
}

//----->
function AddQuickHtlSelectedReview(){
    if($("cmbHotels") != null)
    {    
        if($("cmbHotels").value != "0")
        {   
        $("divCmbHotelsEmpty").innerHTML = "";
        //----->
        $Ajax("controllers/index.aspx?method=setSessionQuickHotel", {
            cache: false,
            metodo: $metodo.POST,    
            parametros: {"htlId":parseFriendlyQS($("cmbHotels").value)},
            onfinish:function(ok){
                if(ok == "1")
                checkAutentication("Hotels/AddQuickReview.aspx");           
            }, 
            tipoRespuesta:$tipo.JSON});        
        }
        else
        {            
            $("divCmbHotelsEmpty").innerHTML = "Please select a hotel";
        }
    }
    return false;
}
//----->
function goSelectedHotel()
{
    if($("cmbHotels") != null)
    {
        $("divCmbHotelsEmpty").innerHTML = "";
        if($("cmbHotels").value != "0")
        {
            window.location.href = $("cmbHotels").value;
        }    
        else
        {
            $("divCmbHotelsEmpty").innerHTML = "Please select a hotel";
        }    
    }    
   
    return false;
}
//----->
function goHotelPhotos()
{
    if($("cmbHotels") != null)
    {
        $("divCmbHotelsEmpty").innerHTML = "";
        if($("cmbHotels").value != "0")
        {
            var photoLoc = $("cmbHotels").value.replace("/eco-hotel-summary","/eco-hotel-photos");
            window.location.href =  photoLoc;
        }
        else
        {
            $("divCmbHotelsEmpty").innerHTML = "Please select a hotel";
        }
    }
    
    return false;
}
//----->
function showHotelsCombo()
{
    Effect.Appear('divHotelsCombo', { duration: 1.0 });
    if(cmbHotelWait !=null)
    clearTimeout(cmbHotelWait);
}

function UploadQuickPhoto()
{
    checkAutentication("Photos/QuickUpload.aspx"); 
}

function setEcoContest()
{
    if($("divEcoContest") != null)
    {
        $("divEcoContest").innerHTML = "";
        
        var newEcoContainer = document.createElement("div");
	    newEcoContainer.id = "contEcoContest";
        $("divEcoContest").appendChild(newEcoContainer);
        
        var FlashVars = {ecoUrl:$F("currEcoContest")};
        var ObjParams = {allowScriptAccess: "always"};
        var ObjAtts = {id: "EcoContestObject"};
        swfobject.embedSWF(basepath + "SwfObjects/320x120.swf","contEcoContest", "320", "120", "8", null, FlashVars, ObjParams, ObjAtts);
        
        if($("divEcoContest").innerHTML == "")
        $("divEcoContest").innerHTML = "You need Flash player 8+ and JavaScript enabled to view this video.";        
    }
}

