//-------------------------------------------------------------------------------------------------------------------VARIABLES GLOBALES
var VGfileServer="./php/consGeoEcuTur.php";
var VGnomContenedor="contIzquierda"; //define el nombre del div contenedor

var VGnomContenedorPopup="contPopup"; //define el nombre del div contenedor en el popup

var VGdivContenedor; //Contiene VGnomContenedor
var VGMsjCarga="<img src='./img/loading2.gif'> Cargando, por favor espere...";
var VGMsjVoto="<img src='./img/loading2.gif'> Procesando su voto, por favor espere...";
var VGMsjComentario="<img src='./img/loading2.gif'> Procesando su comentario, por favor espere...";
var VGMsjContinuar="Continuar";
var VGNavegador;
//-------------------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------------------FUNCIONES GLOBALES

function setContenedor()
{
    VGdivContenedor=document.getElementById(VGnomContenedor);
}

function soportaAjax()
{
	//Identificar el nabegador
	var nom = navigator.appName;
	if (nom == "Microsoft Internet Explorer")
		VGNavegador="IE";
	else
		VGNavegador="NOIE";

	//Navegadores diferentes a IE (Firefox, Netscape, Opera, Safari y Opera)
	if (window.XMLHttpRequest)
		request=new XMLHttpRequest();
	else if (window.ActiveXObject) //Navegadores IE
	{
		request=new ActiveXObject("Msxml2.XMLHTTP");
		if(!request)
		{
			request=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
    
	if(!request)
	{
		alert("Su navegador no permite el uso de todas las funcionalidades de esta aplicación, por lo que podria comportarse de manera inesperada.");
		return false;
	}
	else
	{        
		return true;
	}
}

function nuevoAjax()
{ 
  var xmlhttp=false; 
  try { 
   // Creación del objeto ajax para navegadores diferentes a Explorer 
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
  } catch (e) { 
   // o bien 
   try { 
     // Creación del objet ajax para Explorer 
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { 
     xmlhttp = false; 
   } 
  } 

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
   xmlhttp = new XMLHttpRequest(); 
  } 
  return xmlhttp; 
} 

//-------------------------------------------------------------------------------------------------------------------

//PARA PAGING
//Paging con base de datos
function paginar(p,l,path,campoFiltro,valorFiltro)
{
	var ajax=nuevoAjax();
	ajax.onreadystatechange=function()
	{
		if(ajax.readyState==4)
			VGdivContenedor.innerHTML=ajax.responseText;
		else
			VGdivContenedor.innerHTML=VGMsjCarga;
	};
	ajax.open('post',path, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(retornarDatosPaginar(p,l,campoFiltro,valorFiltro));
}

function retornarDatosPaginar(pa,li,cam,val)
{
    var cad='';  
    cad='pag='+encodeURIComponent(pa)+'&lin='+encodeURIComponent(li)+'&'+cam+'='+encodeURIComponent(val);
    return cad;  
}

function ejecutarFuncion(string_funcion)
{
    var i=0;
    var funcion = new Array(2);
    funcion = string_funcion.split('(');
    //funcion[0] esta el nombre de la funcion
    //funcion[1] estan los parametros, si existen, pero con el ')'
        
    var argumentos = new Array(2);
    var argumentos = funcion[1].split(')');
    //argumentos[0] estan los parametros, si existen
        
    var parametros = new Array();
    parametros = argumentos[0].split(',');
                    
    for(i=0; i<parametros.length; i++)
    {    
        if(!isNaN(parametros[i]))
            parametros[i]=parseInt(parametros[i]);
        else
            parametros[i]=parametros[i].toString();
    }
        
    eval(funcion[0]).apply(null,parametros);
}

//Lmitar numero de caracteres en un campo, borra el ultimo caracter si sobrepasa el limite.
function maximaLongitud(texto,maxlong) {
    var tecla, in_value, out_value;

    if (texto.value.length > maxlong) 
    {
        in_value = texto.value;
        out_value = in_value.substring(0,maxlong);
        texto.value = out_value;
        return false;
    }
    return true;
}

///////////////////////////////////Para panel o div mobil con efecto
/*function resizeDatos()
{
    //modifico el div q contiene el mapa
    if(document.getElementById("derecha").style.left != 0+'px')
    {
        document.getElementById("derecha").style.left=0+'px';
        map.div.style.left = document.getElementById("derecha").style.left; //map es var "global"
        map.updateSize();
    }
    else
    {
        document.getElementById("derecha").style.left=((screen.width)*37)/100+'px';
        map.div.style.left = document.getElementById("derecha").style.left;
        map.updateSize();
    }
}*/

function resizeMapa() //amplio el mapa, ocultando los datos
{
    //modifico el div q contiene el mapa
    /*if(document.getElementById("derecha").style.left != 3+'px') //si el mapa  no esta full screen
    {
        document.getElementById("derecha").style.left=3+'px'; //mapa full secreen
        document.getElementById("izquierda").style.width=0+'px'; //ocultar datos
        map.div.style.left = document.getElementById("derecha").style.left; //map es var "global"
        map.updateSize();
    }
    else
    {   //volver a mostrar datos
        document.getElementById("derecha").style.left=((screen.width)*37.4)/100+'px';
        document.getElementById("izquierda").style.width=((screen.width)*36.8)/100+'px';
        map.div.style.left = document.getElementById("derecha").style.left;
        map.updateSize();
    }
    */
    if(document.getElementById("mapa").style.left != 0+'px') //si el mapa  no esta full screen
    {
        document.getElementById("mapa").style.left=0+'px'; //mapa full secreen, 18px=3px left + 12px width division + 3px padding
	document.getElementById("datos").style.width=0+'px'; //ocultar datos
	document.getElementById("datos").style.padding=0+'px'; //ocultar datos
	document.getElementById("datos").style.border=0+'px'; //ocultar datos
	document.getElementById("division").style.left=0+'px'; //desplazar "division"
	document.getElementById("centrar").innerHTML="&#187;";
        map.div.style.left = document.getElementById("mapa").style.left; //map es var "global"
        map.updateSize();
    }
    else
    {   //volver a mostrar datos
        document.getElementById("mapa").style.left=((screen.width)*30.6)/100+'px';
        document.getElementById("datos").style.width=((screen.width)*30)/100+'px';
	document.getElementById("datos").style.padding=3+'px';
	/////////////////document.getElementById("datos").style.border=1+'px '+'solid #D8D8D8';
	document.getElementById("division").style.left=((screen.width)*30.6)/100+'px';
	document.getElementById("centrar").innerHTML="&#171;";
        map.div.style.left = document.getElementById("mapa").style.left;
        map.updateSize();
    }
}

function resizeDatos() //amplio los datos, ocultando el mapa
{
    if(document.getElementById("derecha").style.left != ((screen.width)*99.8)/100+'px') //si el mapa no esta full screen
    {
        document.getElementById("izquierda").style.width=((screen.width)*99)/100+'px'; //datos full screen
        //document.getElementById("derecha").style.left = ((screen.width)*99.9)/100+'px'; //ocultar mapa
        document.getElementById("derecha").style.left = ((screen.width)*99.8)/100+'px'; //ocultar mapa
    }
    else
    {   //volver a mostrar mapa
        document.getElementById("izquierda").style.right=((screen.width)*63.2)/100+'px';
        document.getElementById("izquierda").style.width=((screen.width)*36.8)/100+'px';
        document.getElementById("derecha").style.left=((screen.width)*37.4)/100+'px';
    }
}

//************************************************Para menus
/*function mouseSobre()
{
	// Si el evento no se produjo en la pestaña seleccionada...	
	if(this.className!='tabOn')
	{
		// Cambio el color de fondo de la pestaña
		this.className='tabHover';		
	}
}

function mouseFuera()
{
	// Si el evento no se produjo en la pestaña seleccionada...
	if(this.className!='tabOn')
	{
		// Cambio el color de fondo de la pestaña
		this.className='tabOff';
	}
}
*/
function mouseSobre()
{
	document.getElementById("btnReservar").className='btnActivo';
}

function mouseFuera()
{
	document.getElementById("btnReservar").className='btnInactivo';
}

//*****************************************************************
function leerObjeto(id,pa,at,ap,fe,ev,ho)
{
	var ajaxLeeObj=nuevoAjax(); 	
	ajaxLeeObj.open('post','./php/leerObjeto.php', true);
	ajaxLeeObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajaxLeeObj.send(returnLeeObj(id,pa,at,ap,fe,ev,ho));
} 
function returnLeeObj(idi,pai,atr,ape,fes,eve,hos)
{
    var cad='';
    cad='idiomaId='+encodeURIComponent(idi)+'&paisId='+encodeURIComponent(pai)+'&atractivoId='+encodeURIComponent(atr)+'&actividadpeId='+encodeURIComponent(ape)+'&festivoId='+encodeURIComponent(fes)+'&eventoId='+encodeURIComponent(eve)+'&hospedajeId='+encodeURIComponent(hos);
    return cad;  
}

//*****************************************************************
function visible(id){
	if(id=="atractivo")
	{
		document.getElementById("atractivo").style.visibility="visible";
		document.getElementById("menuAtractivo").style.background="#EBEBEB";
		document.getElementById("menuAtractivo").style.fontWeight="normal";			
		document.getElementById("menuAtractivo").style.borderTop="1px solid #D9D9D9";
		document.getElementById("menuAtractivo").style.borderLeft="1px solid #D9D9D9";
		document.getElementById("menuAtractivo").style.borderRight="1px solid #D9D9D9";
		
		document.getElementById("festivo").style.visibility="hidden";
		document.getElementById("menuFestivo").style.background="#FFFFFF";
		document.getElementById("menuFestivo").style.fontWeight="bold";
		document.getElementById("menuFestivo").style.border="0px";
		document.getElementById("evento").style.visibility="hidden";
		document.getElementById("menuEvento").style.background="#FFFFFF";
		document.getElementById("menuEvento").style.fontWeight="bold";
		document.getElementById("menuEvento").style.border="0px";
		document.getElementById("hotel").style.visibility="hidden";
		document.getElementById("menuHotel").style.background="#FFFFFF";
		document.getElementById("menuHotel").style.fontWeight="bold";
		document.getElementById("menuHotel").style.border="0px";
	}
	if(id=="festivo")
	{
		document.getElementById("atractivo").style.visibility="hidden";
		document.getElementById("menuAtractivo").style.background="#FFFFFF";
		document.getElementById("menuAtractivo").style.fontWeight="bold";		
		document.getElementById("menuAtractivo").style.border="0px";
		
		document.getElementById("festivo").style.visibility="visible";
		document.getElementById("menuFestivo").style.background="#EBEBEB";
		document.getElementById("menuFestivo").style.fontWeight="normal";		
		document.getElementById("menuFestivo").style.borderTop="1px solid #D9D9D9";
		document.getElementById("menuFestivo").style.borderLeft="1px solid #D9D9D9";
		document.getElementById("menuFestivo").style.borderRight="1px solid #D9D9D9";
		
		document.getElementById("evento").style.visibility="hidden";
		document.getElementById("menuEvento").style.background="#FFFFFF";
		document.getElementById("menuEvento").style.fontWeight="bold";
		document.getElementById("menuEvento").style.border="0px";
		document.getElementById("hotel").style.visibility="hidden";
		document.getElementById("menuHotel").style.background="#FFFFFF";
		document.getElementById("menuHotel").style.fontWeight="bold";
		document.getElementById("menuHotel").style.border="0px";
	}
	if(id=="evento")
	{
		document.getElementById("atractivo").style.visibility="hidden";
		document.getElementById("menuAtractivo").style.background="#FFFFFF";
		document.getElementById("menuAtractivo").style.fontWeight="bold";
		document.getElementById("menuAtractivo").style.border="0px";
		document.getElementById("festivo").style.visibility="hidden";
		document.getElementById("menuFestivo").style.background="#FFFFFF";
		document.getElementById("menuFestivo").style.fontWeight="bold";
		document.getElementById("menuFestivo").style.border="0px";
		
		document.getElementById("evento").style.visibility="visible";
		document.getElementById("menuEvento").style.background="#EBEBEB";
		document.getElementById("menuEvento").style.fontWeight="normal";	
		document.getElementById("menuEvento").style.borderTop="1px solid #D9D9D9";
		document.getElementById("menuEvento").style.borderLeft="1px solid #D9D9D9";
		document.getElementById("menuEvento").style.borderRight="1px solid #D9D9D9";
		
		document.getElementById("hotel").style.visibility="hidden";
		document.getElementById("menuHotel").style.background="#FFFFFF";
		document.getElementById("menuHotel").style.fontWeight="bold";
		document.getElementById("menuHotel").style.border="0px";
	}
	if(id=="hotel")
	{
		document.getElementById("atractivo").style.visibility="hidden";
		document.getElementById("menuAtractivo").style.background="#FFFFFF";
		document.getElementById("menuAtractivo").style.fontWeight="bold";
		document.getElementById("menuAtractivo").style.border="0px";
		document.getElementById("festivo").style.visibility="hidden";
		document.getElementById("menuFestivo").style.background="#FFFFFF";
		document.getElementById("menuFestivo").style.fontWeight="bold";
		document.getElementById("menuFestivo").style.border="0px";
		document.getElementById("evento").style.visibility="hidden";
		document.getElementById("menuEvento").style.background="#FFFFFF";
		document.getElementById("menuEvento").style.fontWeight="bold";
		document.getElementById("menuEvento").style.border="0px";
		
		document.getElementById("hotel").style.visibility="visible";
		document.getElementById("menuHotel").style.background="#EBEBEB";
		document.getElementById("menuHotel").style.fontWeight="normal";
		document.getElementById("menuHotel").style.borderTop="1px solid #D9D9D9";
		document.getElementById("menuHotel").style.borderLeft="1px solid #D9D9D9";
		document.getElementById("menuHotel").style.borderRight="1px solid #D9D9D9";
	}
	
}

/*****************************************************************************

Para scroll de eventos y festivos en cabContenido de cada Municipio/Destino

***********************************************************************************/

/*var Marquee = function(j,s,w) {
    var self = this;
    var jTarget = j;
    var strText = s;
    var intWidth = w;
    var intPaddingLeft = 60;
    var jText,intTextWidth;
    var update = function() {
        intPaddingLeft -= 2;
        if (intPaddingLeft < -intTextWidth) {
            intPaddingLeft += intTextWidth;
        }
        jText.css({'left':intPaddingLeft + 'px'});
    };
    var setup = function() {
        jText = $('<div class="scrollingtext"></div>').text(strText);
        jTarget.append(jText);
        jTarget.append($('<div class="fader"></div>').html('&nbsp;'));
	jTarget.append($('<div class="fader left"></div>').html('&nbsp;'));
        intTextWidth = $(jTarget).find('.scrollingtext').width();
        jTarget.width(intWidth);
        jText.text(strText + " " + strText);
        update();
    };
    setup();
    setInterval(update,30);
    return self;
};
*/
