/**
 * RegionInfoImages.js
 */
//
function setImage(image, name, to) {
	var img_to = document.getElementById(to);
	var img_name = document.getElementById('image-name');
	img_to.src = image;
	img_name.innerHTML = name;
}

function setImageHB(image) {
	
	var selectors = $('#gallery-big-img');
	selectors.remove();
	

	$('#gallery-big').append('<div id="gallery-big-img" style="background-image:url(' + image + '); background-repeat:no-repeat;"></div>');
	 
}

/* 
	Creamos las url para los formularios del seleccion de la pagina de regiones

	http://localhost/independentrip/39-espana/routes/
	http://www.independentrip.com/39-espana/routes/
	
*/

function crearURL(form){
	var url = form.domain.value +"/"+form.region.value +"/"+form.section.value+"/"+form.idregion[form.idregion.selectedIndex].value+"/";
	form.action = url;
	form.submit();
	}
	
function crearURLHome(form){

	var url = form.domain.value +"/"+form.region[form.region.selectedIndex].value+"/routes/";
	form.action = url;
	form.submit();
	}

function crearURLHostel(form){
	urlHostel = form.idregion[form.idregion.selectedIndex].value;
	var url = "";
	if(urlHostel.indexOf(form.region.value) == -1){
		url = form.domain.value +"/"+form.region.value +"/"+form.idregion[form.idregion.selectedIndex].value;	
	}else{
		url = form.domain.value +"/"+form.idregion[form.idregion.selectedIndex].value;
	}
	
	form.action = url;
	form.submit();
	}
/* Verificamos que se hayan seleccionado al menos dos rutas*/
function getTotalPoint(){
	if(document.forms['fRoute'].totalpoint.value <= 1){
		alert('Debe seleccionar otra ciudad');
		return false;
		}else{
			document.forms['fRoute'].submit();
			}
		return true;
	
	}

function crearURLRoutes(form){
	if(getTotalPoint()){
		var puntos = form.allregion.value;
		puntos = puntos.substring(1);
		puntos = puntos.substring(0,(puntos.length-1));
		
		var url = form.domain.value +"/"+form.region.value +"/"+form.section.value+"/"+puntos+"/";
		form.action = url;
		form.submit();
	}else{
		return false;
	}
}

function remplazarCaracteres(name){
/*  var replaces = new Array( 'Š','š', 'Đ', 'đ', 'Ž', 'ž', 'Č', 'č', 'Ć', 'ć',
        'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É',
        'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô',
        'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß',
        'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é',
        'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó',
        'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ý', 'ý', 'þ',
        'ÿ', 'Ŕ', 'ŕ',' ',"'");
  
  var by = new Array('S', 's', 'Dj', 'dj', 'Z', 'z', 'C', 'c', 'C', 'c',
        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E',
        'E', 'E', 'I', 'I', 'I', 'I', 'N', 'O', 'O', 'O',
        'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'B', 'Ss',
        'a', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e',
        'e', 'e', 'i', 'i', 'i', 'i', 'o', 'n', 'o', 'o',
        'o', 'o', 'o', 'o', 'u', 'u', 'u', 'y', 'y', 'b',
        'y', 'R', 'r','-','-');*/
  

  return text; 
}

function normalize(text)
{  
  text = text.toLowerCase();
  text = text.toString();
  
  text = text.replace(/[ñ]/g, 'n');
  
  text = text.replace(/[š]/g, 'n');
  text = text.replace(/[đ]/g, 'dj');
  text = text.replace(/[ž]/g, 'z');
  text = text.replace(/[þ]/g, 'b');
  text = text.replace(/[ŕ]/g, 'r');
  
  text = text.replace(/[áàäâåæ]/g, 'a');
  text = text.replace(/[éèëê]/g, 'e');
  text = text.replace(/[íìïî]/g, 'i');
  text = text.replace(/[ðóòõöôø]/g, 'o');
  text = text.replace(/[úùüû]/g, 'u');
  text = text.replace(/[ýÿ]/g, 'y');
  text = text.replace(/[čçć]/g, 'c');
  text = text.replace(/['"]/g, '');
  text = text.replace(/\s+/g, '-');
  text = text.replace(/[ ]/g, '-');
  text = text.replace(/[`]/g, '-');
 
  return text;
}
function permalink(text)
{  
	text = text.toLowerCase();
	text = text.toString();
  //var text = document.getElementById(origen).value.toLowerCase(); // without 'prototype' library 
  //var text = $(origen).value.toLowerCase(); // with 'prototype' library
  text = text.replace(/[ñ]/gi, 'n');
  text = text.replace(/[áàäâå]/g, 'a');
  text = text.replace(/[éèëê]/g, 'e');
  text = text.replace(/[íìïî]/g, 'i');
  text = text.replace(/[óòöô]/g, 'o');
  text = text.replace(/[úùüû]/g, 'u');
  text = text.replace(/[ýÿ]/g, 'y');
  text = text.replace(/[ç]/g, 'c');
  text = text.replace(/['"]/g, '');
  /*text = text.replace(/[^a-zA-Z0-9-]/g, ' '); //text = text.replace(/\W/g, ' ');*/
  text = text.replace(/\s+/g, '-');
  /*text = text.replace(/(_)$/g, '');
  text = text.replace(/^(_)/g, '');  */

  //document.getElementById(destino).value = text; // without 'prototype' library 
  //$(destino).value = text; // with 'prototype' library
  return text;
}

function cargarPublicidad(divid, zona, lang){

	var d = new Date();
    var url = 'public/Publicidad/cargar-publicidad.php?zona=' + zona + '&lang='+ lang + '&nocache='+ d.getMilliseconds() ;
	
	$('#ads-header').load(url);
	
}

// FUNCION PARA CARGAR EL HOTEL SELECCIONADO 
function cambiarHotel(idhotel,lang,lat,long){
	// Cargamos los datos del hotel 
	$('#load-hotel').load('public/Hoteles/cargando.php');
	var d = new Date();
    var url = 'public/Hoteles/display.php?idhotel=' + idhotel + '&lang='+ lang +'&nocache='+ d.getMilliseconds() ;
	// Actualizamos el centro del mapa
	if(lat!='' && long != ''){
		center = new GLatLng( lat, long );
		map.setCenter(center, map.getZoom());
	}
   	$('#load-hotel').load(url);
	
	cambiarCSSHotel(idhotel);
}
	
// FUNCION PARA MOSTRAR LAS PESTAÑAS DE LOS HOTELES
function cambiarOpcionHotel(idopcion){
	
	$('#info-extra').hide();
	$('#info-mapa').hide();
	$('#info-reviews').hide();
	
	$("#li_info-extra").removeClass('actual');
	$("#li_info-mapa").removeClass('actual');
	$("#li_info-reviews").removeClass('actual');
	$("#a_info-extra").removeClass('actual');
	$("#a_info-mapa").removeClass('actual');
	$("#a_info-reviews").removeClass('actual');
	
	$("#li_"+idopcion).addClass('actual');
	$("#a_"+idopcion).addClass('actual');
	
	$("#"+idopcion).show();

}

function cambiarCSSHotel(idhotel){
	
	
	$("div[id^='hotel_']").css({
		'background-color':'#fff'
		});

	$("div#hotel_"+idhotel ).css({
		'background-color':'#add1f3'
		});
}
	
function cambiarCSSRutaTransporte(ruta , transporte){
	
	/*
	$("a[id^='link']").css({
		'color': '#fff',
		'background':'url(css/images/api-route-link.png) repeat-x top left'}
		);
	
	$("#link_"+ruta + transporte).css({
		'color': '#142d45',
		'background':'url(css/images/api-route-link-over.png) repeat-x top left'}
		);
	*/
	
	$("h2[id^='route_']").css({
		'background-color':'#fff'
		});

	$("h2#route_"+ruta ).css({
		'background-color':'#add1f3'
		});

}	

/*********************************************************
VOTOS
**********************************************************/
// JavaScript Document
function sumaVotosQueVer(idquever, subdominio) {
	
	var d = new Date();
    var url = 'http://'+ subdominio + '.independentrip.com/public/Que-Ver/votos.php?idquever=' + idquever + '&nocache='+ d.getMilliseconds() ;
	
	if($('#votosNum_'+idquever).load(url)){
		$('#votosBot_'+idquever).hide();		
		}

	
}



function sumaVotosQueVerCriticas(idcritica, subdominio) {
	
	var d = new Date();
    var url = 'http://'+ subdominio + '.independentrip.com/public/Que-Ver/votos-critica.php?idcritica=' + idcritica + '&nocache='+ d.getMilliseconds() ;
	
	
	if($('#quever-display-critica-votanum_'+idcritica).load(url)){
		$('#quever-display-critica-votabot_'+idcritica).hide();		
		}


}


function sumaVotosRegionCriticas(idcritica, subdominio) {
	
	var d = new Date();
    var url = 'http://'+ subdominio + '.independentrip.com/public/RegionInfo/regioninfo-votos-critica.php?idcritica=' + idcritica + '&nocache='+ d.getMilliseconds() ;
	
	
	if($('#region-info-critica-votanum_'+idcritica).load(url)){
		$('#region-info-critica-votabot_'+idcritica).hide();		
		}


}


function sumaVotosViajeDia(idroute, subdominio) {
	var d = new Date();
    var url = 'http://'+ subdominio + '.independentrip.com/public/ViajesDia/route-votos.php?idroute=' + idroute + '&nocache='+ d.getMilliseconds() ;
	
	if($('#votosNum_'+idroute).load(url)){
		$('#votosBot_'+idroute).hide();		
		}

}


function sumaVotosMejorViaje(idmejorviaje, subdominio) {
	
	var d = new Date();
    var url = 'http://'+ subdominio + '.independentrip.com/public/MejoresViajes/mejoresviajes-votos.php?idmejorviaje=' + idmejorviaje + '&nocache='+ d.getMilliseconds() ;
	
	if($('#votosNum_'+idmejorviaje).load(url)){
		$('#votosBot_'+idmejorviaje).hide();		
		}

	
}


function sumaVotosMoverseCriticas(idcritica, subdominio) {
	
	var d = new Date();
    var url = 'http://'+ subdominio + '.independentrip.com/public/ComoMoverse/comomoverse-votos-critica.php?idcritica=' + idcritica + '&nocache='+ d.getMilliseconds() ;
	
	
	if($('#quever-display-critica-votanum_'+idcritica).load(url)){
		$('#quever-display-critica-votabot_'+idcritica).hide();		
		}


}


function sumaVotosDatosPracticosCriticas(idcritica, subdominio) {
	
	var d = new Date();
    var url = 'http://'+ subdominio + '.independentrip.com/public/DatosPracticos/datospracticos-votos-critica.php?idcritica=' + idcritica + '&nocache='+ d.getMilliseconds() ;
	
	
	if($('#quever-display-critica-votanum_'+idcritica).load(url)){
		$('#quever-display-critica-votabot_'+idcritica).hide();		
		}


}

function sumaVotosMejoresViajes(idcritica, subdominio){

	var d = new Date();
    var url = 'http://'+ subdominio + '.independentrip.com/public/MejoresViajes/votos-critica.php?idcritica=' + idcritica + '&nocache='+ d.getMilliseconds() ;
	
	
	if($('#quever-display-critica-votanum_'+idcritica).load(url)){
		$('#quever-display-critica-votabot_'+idcritica).hide();		
		}

}

function sumaVotosViajesDia(idcritica, subdominio){

	var d = new Date();
    var url = 'http://'+ subdominio + '.independentrip.com/public/ViajesDia/votos-critica.php?idcritica=' + idcritica + '&nocache='+ d.getMilliseconds() ;
	
	
	if($('#quever-display-critica-votanum_'+idcritica).load(url)){
		$('#quever-display-critica-votabot_'+idcritica).hide();		
		}

}

function sumaVotosRoutesCriticas(idcritica){

	var d = new Date();
    var url = 'votos-critica.php?idcritica=' + idcritica + '&nocache='+ d.getMilliseconds() ;
	
	
	if($('#route-info-critica-votanum_'+idcritica).load(url)){
		$('#route-info-critica-votabot_'+idcritica).hide();		
		}

}
/**
 * layers.js
 *
 * javascript div management functions
 */

function showLayer(layer_id, absolute) {
	if (absolute == undefined) {
		absolute = false;
	}
	var layer = document.getElementById(layer_id);
	layer.style.display = 'block';
	if (absolute == true) {
		layer.style.position = 'absolute';
	}
}

function hideLayer(layer_id, absolute) {
	if (absolute == undefined) {
		absolute = false;
	}
	var layer = document.getElementById(layer_id);
	layer.style.display = 'none';
	if (absolute == true) {
		layer.style.position = 'absolute';
	}
}

function showHideLayer(layer_id, absolute) {
	if (absolute == undefined) {
		absolute = false;
	}
	var layer = document.getElementById(layer_id);
	if (layer.style.display == 'none') {
		layer.style.display = 'block';
	} else if (layer.style.display == 'block') {
		layer.style.display = 'none';
	}
	if (absolute == true) {
		layer.style.position = 'absolute';
	}
}

function viewLayer(layer_id, visible) {
	var layer = document.getElementById(layer_id);
	
	if (visible) {
		layer.style.visibility = "visible";
	} else {
		layer.style.visibility = "hidden";
	}
}

function centerLayer(layer_id) {
	var layer = document.getElementById(layer_id);
	
	// centering of layer
	layer.style.position = "absolute";
	
	//Opera doesn't accept top percent positions
	layer.style.top = (document.body.clientHeight /2) + "px";
	layer.style.left = "50%";
	layer.style.marginLeft = "-" + (layer.offsetWidth / 2) + "px";
	layer.style.marginTop = "-" + (layer.offsetHeight/ 2) + "px";
}


/**
 * showLanguage
 * manages language layers
 */
function showLanguage() {
	var langIsoCode = document.getElementById('lang');
	var id;
	// gets all div elements
	var divs = document.getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++) {
		if (divs[i].id == 'langSection_' + langIsoCode.value) {
			showLayer('langSection_' + langIsoCode.value);
		} else {
			id = divs[i].id;
			if (id.indexOf('langSection') >= 0) {
				hideLayer(divs[i].id);
			}
		}
	}
}

function copyValue(value, destinyField, force) {
	if (force == undefined) {
		force = false;
	}
	var destiny = document.getElementById(destinyField + '_es');
	if (destiny.value == "" || force) {
		destiny.value = value;
	}
}
