// JavaScript Document
function objetoAjax(){
        var xmlhttp=false;
        try {
               xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
               try {
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
               } catch (E) {
                       xmlhttp = false;
               }
        }
 
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
               xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
}

// FUNCION PARA CARGAR EL CONTENIDO DE ALOJAMIENTOS EN EL IFRAME CENTRAL
function cargar(url,dest,codTempo, ecotrad, idAloj, idDest){ 
	//parent.document.getElementById('map_aloj').src = "mapa.php?mapa="+idDest;
	parent.document.getElementById('map_aloj').src = "mapas/"+idDest+".gif";
	parent.document.getElementById('nom_destino').innerHTML = dest;
	switch(ecotrad){
		case 'T': parent.document.getElementById('icono1').src = "img/trad.gif"; parent.document.getElementById('icono2').src = "img/gris.gif";
		break;
		case 'E': parent.document.getElementById('icono1').src = "img/eco.gif"; parent.document.getElementById('icono2').src = "img/gris.gif";
		break;
		case 'TE': parent.document.getElementById('icono1').src = "img/eco.gif"; parent.document.getElementById('icono2').src = "img/trad.gif"
		break;
	}
	parent.document.getElementById('info_aloj').src=url;	
	parent.document.getElementById('temp_aloj').src = "http://selos.climatempo.com.br/selos/MostraSelo.php?CODCIDADE="+codTempo;	
	
	divResultado = parent.document.getElementById('fotos')
	divResultado.innerHTML = ""
	ajax=objetoAjax();
	ajax.open("GET", "existen_fotos.php?idAloj="+idAloj,true);
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4){
			   //results = ajax.responseText.split("|");
			   //results = ajax.responseText;
			   divResultado.innerHTML = ajax.responseText
		   }
	}
	ajax.send(null)		
}

// ESTA FUNCION CARGA EL PRIMER ALOJAMIENTO CUANDO SE ENTRA EN LA SECCION POR PRIMERA VEZ
function cargar_prim(url,dest,codTempo, ecotrad, idAloj, idDest){
	//document.getElementById('map_aloj').src = "mapa.php?mapa="+idDest;
	document.getElementById('map_aloj').src = "mapas/"+idDest+".gif";
	document.getElementById('nom_destino').innerHTML = dest;
	switch(ecotrad){
		case 'T': parent.document.getElementById('icono1').src = "img/trad.gif"; parent.document.getElementById('icono2').src = "img/gris.gif";
		break;
		case 'E': parent.document.getElementById('icono1').src = "img/eco.gif"; parent.document.getElementById('icono2').src = "img/gris.gif";
		break;
		case 'TE': parent.document.getElementById('icono1').src = "img/eco.gif"; parent.document.getElementById('icono2').src = "img/trad.gif"
		break;
	}
	document.getElementById('info_aloj').src=url;	
	document.getElementById('temp_aloj').src = "http://selos.climatempo.com.br/selos/MostraSelo.php?CODCIDADE="+codTempo;

	divResultado = document.getElementById('fotos')
	divResultado.innerHTML = "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />"
	ajax=objetoAjax();
	ajax.open("GET", "existen_fotos.php?idAloj="+idAloj,true);
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4){
			   //results = ajax.responseText.split("|");
			   //results = ajax.responseText;

			   divResultado.innerHTML = ajax.responseText
		   }
	}
	ajax.send(null)		
}


// FUNCION PARA CARGAR EL CONTENIDO DE DESTINOS EN EL IFRAME CENTRAL
function cargar_destino(url,dest,codTempo, ecotrad, idDest, verEcoturismo, tiene_iti){ 
	//parent.document.getElementById('map_aloj').src = "mapa.php?mapa="+idDest;
	parent.document.getElementById('fotos').innerHTML = "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />"
	parent.document.getElementById('map_aloj').src = "mapas/"+idDest+".gif";
	parent.document.getElementById('nom_destino').innerHTML = dest;
	switch(ecotrad){
		case 'T': parent.document.getElementById('icono1').src = "img/trad.gif"; parent.document.getElementById('icono2').src = "img/gris.gif";
		break;
		case 'E': parent.document.getElementById('icono1').src = "img/eco.gif"; parent.document.getElementById('icono2').src = "img/gris.gif";
		break;
		case 'TE': parent.document.getElementById('icono1').src = "img/eco.gif"; parent.document.getElementById('icono2').src = "img/trad.gif"
		break;
	}
	
	parent.document.getElementById('info_dest').src=url;	
	parent.document.getElementById('temp_aloj').src = "http://selos.climatempo.com.br/selos/MostraSelo.php?CODCIDADE="+codTempo;

	parent.document.getElementById('botones').innerHTML = "<button type='button' style='border:0; width:124px; height:31px;' onClick='view_aloj("+idDest+","+verEcoturismo+","+tiene_iti+");'><img border='0' src='img/alojamientos.gif' width='124' height='31' /></button>"
	if (verEcoturismo == 0){
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "&nbsp;<button type='button' style='border:0; visibility:hidden; width:124px; height:31px;' onClick='view_excur("+idDest+","+verEcoturismo+","+tiene_iti+");'><img border='0' src='img/excursiones.gif' width='124' height='31' /></button>"
	}else{
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "&nbsp;<button type='button' style='border:0; visibility:visible; width:124px; height:31px;' onClick='view_excur("+idDest+","+verEcoturismo+","+tiene_iti+");'><img border='0' src='img/excursiones.gif' width='124' height='31' /></button>"		
	}
	if (tiene_iti == 1){
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "&nbsp;<button type='button' style='border:0; width:124px; height:31px;' onClick='view_itir("+idDest+","+verEcoturismo+","+tiene_iti+");'><img border='0' src='img/itinerarios.gif' width='124' height='31' /></button>"
	}		
}

// ESTA FUNCION CARGA EL PRIMER DESTINO CUANDO SE ENTRA EN LA SECCION POR PRIMERA VEZ
function cargar_prim_dest(url,dest,codTempo, ecotrad, idDest, verEcoturismo, tiene_iti, busqueda){
	//document.getElementById('map_aloj').src = "mapa.php?mapa="+idDest;	
	document.getElementById('fotos').innerHTML = "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />"
	document.getElementById('map_aloj').src = "mapas/"+idDest+".gif";
	document.getElementById('nom_destino').innerHTML = dest;
	switch(ecotrad){
		case 'T': parent.document.getElementById('icono1').src = "img/trad.gif"; parent.document.getElementById('icono2').src = "img/gris.gif";
		break;
		case 'E': parent.document.getElementById('icono1').src = "img/eco.gif"; parent.document.getElementById('icono2').src = "img/gris.gif";
		break;
		case 'TE': parent.document.getElementById('icono1').src = "img/eco.gif"; parent.document.getElementById('icono2').src = "img/trad.gif"
		break;
	}
	document.getElementById('info_dest').src=url;	
	document.getElementById('temp_aloj').src = "http://selos.climatempo.com.br/selos/MostraSelo.php?CODCIDADE="+codTempo;
	
	parent.document.getElementById('botones').innerHTML = "<button type='button' style='border:0; width:124px; height:31px;' onClick='view_aloj("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+");'><img border='0' src='img/alojamientos.gif' width='124' height='31' /></button>"
	if (verEcoturismo == 0){
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "&nbsp;<button type='button' style='border:0; visibility:hidden; width:124px; height:31px;' onClick='view_excur("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+");'><img border='0' src='img/excursiones.gif' width='124' height='31' /></button>"
	}else{
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "&nbsp;<button type='button' style='border:0; visibility:visible; width:124px; height:31px;' onClick='view_excur("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+");'><img border='0' src='img/excursiones.gif' width='124' height='31' /></button>"		
	}
	if (tiene_iti == 1){
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "&nbsp;<button type='button' style='border:0; width:124px; height:31px;' onClick='view_itir("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+");'><img border='0' src='img/itinerarios.gif' width='124' height='31' /></button>"
	}
	if (busqueda == 1){
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "<br><br><a href='#' onclick='window.history.back(-1);'><img src='img/btn_volver_res.gif' border='0'></a>";
	}	
}


function cargar_info_aloj(url, idDest, idAloj, verEcoturismo, busqueda, tiene_iti){ 
	parent.document.getElementById("info_dest").src=url; 
	divResultado = parent.document.getElementById('fotos')
	divResultado.innerHTML = ""
	ajax=objetoAjax();
	ajax.open("GET", "existen_fotos.php?idAloj="+idAloj,true);
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4){
			   //results = ajax.responseText.split("|");
			   //results = ajax.responseText;
			   divResultado.innerHTML = ajax.responseText
		   }
	}
	ajax.send(null)
	parent.document.getElementById('botones').innerHTML = "<button type='button' style='border:0; width:124px; height:31px;' onClick='window.history.back(-1), repone_boton_volver("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+")''><img border='0' src='img/volver.gif' width='124' height='31' /></button>";
}



function view_aloj(idDest, ecoT, tiene_iti, busqueda){	
	parent.document.getElementById("info_dest").src="aloj_por_dest.php?idDest="+idDest+"&busqueda="+busqueda;
	parent.document.getElementById('botones').innerHTML = "<button type='button' style='border:0; width:124px; height:31px;' onClick='window.history.back(-1), repone_botones("+idDest+","+ecoT+","+tiene_iti+","+busqueda+")'><img border='0' src='img/volver.gif' width='124' height='31' /></button>";	
}

function view_excur(idDest, ecoT, tiene_iti, busqueda){
	parent.document.getElementById("info_dest").src="excur_por_dest.php?idDest="+idDest; 
	parent.document.getElementById('botones').innerHTML = "<button type='button' style='border:0; width:124px; height:31px;' onClick='window.history.back(-1), repone_botones("+idDest+","+ecoT+","+tiene_iti+","+busqueda+")'><img border='0' src='img/volver.gif' width='124' height='31' /></button>";
}

function view_itir(idDest, ecoT, tiene_iti, busqueda){
	parent.document.getElementById("info_dest").src="itin_por_dest.php?idDest="+idDest; 
	parent.document.getElementById('botones').innerHTML = "<button type='button' style='border:0; width:124px; height:31px;' onClick='window.history.back(-1), repone_botones("+idDest+","+ecoT+","+tiene_iti+","+busqueda+")'><img border='0' src='img/volver.gif' width='124' height='31' /></button>";
}

function repone_botones(idDest, verEcoturismo, tiene_iti, busqueda){
	parent.document.getElementById('botones').innerHTML = "<button type='button' style='border:0; width:124px; height:31px;' onClick='view_aloj("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+");'><img border='0' src='img/alojamientos.gif' width='124' height='31' /></button>"
	if (verEcoturismo == 0){
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "&nbsp;<button type='button' style='border:0; visibility:hidden; width:124px; height:31px;' onClick='view_excur("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+");'><img border='0' src='img/excursiones.gif' width='124' height='31' /></button>"
	}else{
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "&nbsp;<button type='button' style='border:0; visibility:visible; width:124px; height:31px;' onClick='view_excur("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+");'><img border='0' src='img/excursiones.gif' width='124' height='31' /></button>"		
	}
	if (tiene_iti == 1){
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "&nbsp;<button type='button' style='border:0; width:124px; height:31px;' onClick='view_itir("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+");'><img border='0' src='img/itinerarios.gif' width='124' height='31' /></button>"
	}
	if (busqueda == 1){
		parent.document.getElementById('botones').innerHTML = parent.document.getElementById('botones').innerHTML + "<br><br><a href='#' onclick='window.history.back(-1);'><img src='img/btn_volver_res.gif' border='0'></a>";
	}
}

function repone_boton_volver(idDest, verEcoturismo, tiene_iti, busqueda){
		parent.document.getElementById('fotos').innerHTML = "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />"
		parent.document.getElementById('botones').innerHTML = "<button type='button' style='border:0; width:124px; height:31px;' onClick='window.history.back(-1), repone_botones("+idDest+","+verEcoturismo+","+tiene_iti+","+busqueda+")'><img border='0' src='img/volver.gif' width='124' height='31' /></button>";
}

// **************   FUNCIONES DEL POP-UP CON FOTOS DE ALOJAMIENTOS  *******************************
function popOpen(id) {
	var topOffset = 1;
	setSize(topOffset);
	var overShade = document.getElementById(id);
	var topPad =  pos+topOffset;
	//height-padding = div height
	overShade.style.height = (ph - topPad) + 'px'; /* remove topPad from height */	
	overShade.style.width = pw + 'px';	
	//overShade.style.left = '135px';	
	overShade.style.paddingTop = topPad + 'px';	
	overShade.style.display = 'block';
	if (document.all && !navigator.appVersion.match(/MSIE 7.0/)) {
		coverSelects(overShade);
	}
}


/* covers select form elements with iframe in IE 6&< so they do not show through the popup */
function coverSelects(par) {		
		var covHeight = document.body.scrollHeight+"px"; // add the negative margin to the heigh
		var covWidth = document.body.scrollWidth+"px";
		var coverFrame = "<IFRAME id='popup-cover' style='";
		coverFrame = coverFrame + "height:"+covHeight+"; width:"+covWidth+"; border:solid #FFFF00;' ";
		coverFrame = coverFrame + "src='javascript:false;' frameBorder='1' scrolling='no'></IFRAME>";
		par.insertAdjacentHTML("afterEnd",coverFrame); // create new iframe that is the size of the popup window
		//par.innerHTML = coverFrame;
}

function popClose(id) {
	
	var fObj = document.getElementById(id);
	fObj.style.display = "";
	//end Added by Sarun
	if (document.all && !navigator.appVersion.match(/MSIE 7.0/)) {
		document.getElementById("popup-cover").outerHTML = "";
	}
		
}

// image gallery scripts; changes images and current number
var curGal = 0;
var curSrc = "";
function nextImg() {
	if (curGal < theGallery.length-1) {
		curGal = curGal+1;
		}
	else {
		curGal = 0;
		}
	curSrc = theGallery[curGal];
	//document.getElementById('testsrc').innerHTML = curSrc; //for testing
	document.getElementById('curNum').innerHTML = curGal+1;
	document.getElementById('galleryImage').src = curSrc;
}

function prevImg() {
	if (curGal != 0) {
		curGal = curGal-1;
	}
	else {
		curGal = theGallery.length-1;
	}
	curSrc = theGallery[curGal];
	//document.getElementById('testsrc').innerHTML = curSrc; //for testing						
	document.getElementById('curNum').innerHTML = curGal+1;
	document.getElementById('galleryImage').src = curSrc;
}

function setSize(topOffset) { /* sets size of shade */	
	if (window.pageYOffset != null) { /* moz and safari */
		pos = window.pageYOffset;
		ph = document.documentElement.scrollHeight;
		pw = document.documentElement.scrollWidth;
		if (document.body.scrollHeight > document.documentElement.scrollHeight) {
			ph = document.body.scrollHeight;
			pw = document.body.scrollWidth;
		}
	} else if (document.documentElement.scrollTop > document.body.scrollTop) { /* ie, catch if Standards compliance mode */		
		pos = document.documentElement.scrollTop;
		ph = document.documentElement.scrollHeight;
		pw = document.documentElement.scrollWidth;		
		if (document.documentElement.clientHeight > document.documentElement.scrollHeight) {
			ph = document.documentElement.clientHeight;
		}
	} else if (document.body != null) { /* if IE 5.5 */		
		pos = document.body.scrollTop;
		ph = document.body.scrollHeight;
		pw = document.body.scrollWidth;
		if (document.documentElement.scrollHeight > document.body.scrollHeight) {
			ph = document.documentElement.scrollHeight;
		}
		ph = ph + pos + topOffset; /* fix box model */
		

	}
}	

// ***********************  FIN DE FUNCIONES DEL POP-UP CON FOTOS DE ALOJAMIENTOS  ****************************

function checkdatos(form) {

   var email = /^(.+\@.+\..+)$/
   var kk = /^([0-9]|-)+(\d*[0-9]|-*)$/

		if (!(contacto.apellido.value)) {
            		alert ('Por favor, ingrese su apellido.')
            		contacto.apellido.focus();
            		return false;
      	}

		else if  (!(contacto.nombre.value)) {
            		alert ('Por favor, ingrese su nombre.')
            		contacto.nombre.focus();
            		return false;
      	}
		else if (!(contacto.email.value)) {
            		alert ('Por favor, complete su email.')
            		contacto.email.focus();
            		return false;
      	}
              		else if(!email.test(contacto.email.value)){
			alert("Ingrese un email válido.")
			contacto.email.focus()
            		return false;
        }
        	else
        {
			return true;
        }
}

function ventana(file) {
if (navigator.appVersion.indexOf('4') != -1) {
// Esto es para centrar la ventana en los Navegadores 4
var w = 270;
var h = 270;
x4 = screen.width/2 - (w/2);
y4 = screen.height/2 - (h/2) - 20;
win = window.open(file, "view", 'height='+h+',width='+w+',scrollbars=0,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + x4 + ',top=' + y4 + '');
} else {
win = window.open(file, "view", 'height=270,width=270,scrollbars=0,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=250,top=250');
}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}
