//MUESTRA ELEMENTOS DEL DOM DE HTML QUE FUERON OCULTADOS
function MostrarElemento(id) 
{
	var elemento = document.getElementById(id);
	if(navigator.appName.indexOf("Microsoft") > -1)
	{
		var visible = 'block'
	}
	else
	{
		var visible = '';
	}
	elemento.style.display = visible;
}

//OCULTA ELEMENTOS DEL DOM DE HTML
function OcultarElemento(id) 
{
	var elemento = document.getElementById(id);
	elemento.style.display = 'none';
}

//FUNCION PARA ABRIR VENTANA EMERGENTE
var previa;
function VentanaEmergente(url,parametros,nomb_ventana,atributos)
{
//	previa=window.open('ventana_detalle_pre.php?id_inmueble='+id_inmueble+'&pais=<? echo $_POST['pais'] ?>&in='+valor,'previa','status=no,resizable=no,width=780,height=550'); 
	previa=window.open(url+parametros,nomb_ventana,atributos); 
}

//FUNCION PARA CAMBIAR COLOR DE LETRAS
function cambia_color(name,fg)
{
	name.style.color = fg;
}
//FUNCION PARA CAMBIAR FONDO DE COLOR
function cambia_fondo(name,bg)
{
	name.style.background= bg;
}
//FUNCION PARA VALIDAR UN CORREO
function ValidarEmail(cadena){
var email;
	var ind1, ind2, ind3;
	var plant 
	plant = /(^[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*)@([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$/
	ind1 = cadena.indexOf('@');//SE BUSCA EL PRIMER ARROBA DE IZQUIERDA A DERECHA
	ind2 = cadena.indexOf('.');//SE BUSCA EL PRIMER PUNTO DE IZQUIERDA A DERECHA
	ind3 = cadena.lastIndexOf('@');
	ind4 = cadena.lastIndexOf('.');
	ind5 = cadena.length;
	if(plant.test(cadena)){
		email=1;
		return email;
	}else{
		email=0;
		return email;
	}
}

//FUNCION PARA QUITAR LOS ESPACIOS EN BLANCO DE LA IZQUIERDA
function lTrim(sStr){ 
	while (sStr.charAt(0) == " ") 
	sStr = sStr.substr(1, sStr.length - 1); 
	return sStr; 
	} 
																		
//FUNCION PARA QUITAR LOS ESPACIOS EN BLANCO DE LA DERECHA
function rTrim(sStr){  
	while (sStr.charAt(sStr.length - 1) == " ") 
	sStr = sStr.substr(0, sStr.length - 1); 
	return sStr; 
} 

//FUNCION PARA QUITAR LOS ESPACIOS EN BLANCO DE LA IZQUIERDA Y DERECHA
function allTrim(sStr){  
	 return rTrim(lTrim(sStr)); 
} 
//FUNCION PARA ESCRIBIR SOLO NUMEROS EN UN CAMPO DE TEXTRO
function only_num(){
	var tecla = window.event.keyCode; 
	if(tecla<48 || tecla > 57) 
	{
	window.event.keyCode=0;
	}
}
//FUNCION PARA VALIDAR CAMPOS OBLIGATORIOS Y CORREOS ELECTRONICOS
function val_campos(campo){
	
	var trozos = campo.split (","); // SE DIVIDE LA CADENA EN UNA MATRIZ 
	//OCULTA TODO LOS CAMPOS 
	for (i=0; i < trozos.length ; i++)
	{
		var sub_trozos = trozos[i].split("="); // CADA ELEMENTO DE LA MATRIZ CABLE SE SUBDIVIDE NUEVAMENTE
		var elemento = document.getElementById(sub_trozos[0]);	
		OcultarElemento("err_"+sub_trozos[0]);
	}
	for (i=0; i < trozos.length ; i++)
	{
		var sub_trozos = trozos[i].split("="); // CADA ELEMENTO DE LA MATRIZ CABLE SE SUBDIVIDE NUEVAMENTE
		if(sub_trozos[1]==0){
			var elemento = document.getElementById(sub_trozos[0]);	
			elemento.value = allTrim(elemento.value); // SE QUITAN LOS ESPACIOS EN BLANCO
			if(elemento.value.length==0){//VALIDA QUE EL CAMPO NO ESTE VACIO
				MostrarElemento("err_"+sub_trozos[0]);
				elemento.focus();
				break;
			}else{//EN CASO QUE NO ESTE VACIO EL CAMPO
				OcultarElemento("err_"+sub_trozos[0]);
			}
			
		}else{//EN CASO QUE SEA CAMPO DE CORREO ELECTRONICO
			var elemento = document.getElementById(sub_trozos[0]);	
			elemento.value = allTrim(elemento.value); // SE QUITAN LOS ESPACIOS EN BLANCO
			if(elemento.value.length==0){//VALIDA QUE EL CAMPO NO ESTE VACIO
				MostrarElemento("err_"+sub_trozos[0]);
				elemento.focus();
				break;
			}else{//EN CASO QUE NO ESTE VACIO EL CAMPO
				OcultarElemento("err_"+sub_trozos[0]);
				var email = ValidarEmail(elemento.value);// VALIDA EL CORREO ELECTRONICO
					if (email==0){
						MostrarElemento("err_"+sub_trozos[0]);
						elemento.focus();
						break;
					}else{
						OcultarElemento("err_"+sub_trozos[0]);
					}
			}	
		}
	} 
	//VERIFICA QUE ESTEN VALIDADOS TODOS LOS CAMPOS PARA HACER EL ENVIO
	if(i==trozos.length)
	{
	 	return	true;
	}else{
		return	false;	
	}
}

//FUNCION PARA MARCAR O DESMARCAR CHECKBOX
function chk_accion(nomb_chk,cont){
	for (n=0; n <cont; n++) 
	{ 
		eval("document.frm_principal."+nomb_chk+"["+n+"]"+".checked=true");
	} 
}

// FORMATEAR NUMEROS Objeto oNumero
function oNumero(numero)
{
	//Propiedades 
	this.valor = numero || 0
	this.dec = -1;
	//Métodos 
	this.formato = numFormat;
	this.ponValor = ponValor;
	//Definición de los métodos 
	function ponValor(cad)
	{
		if (cad =='-' || cad=='+') return
		if (cad.length ==0) return
		if (cad.indexOf(',') >=0)
			this.valor = parseFloat(cad);
		else 
			this.valor = parseInt(cad);
	} 
	function numFormat(dec, miles)
	{
		var num = this.valor, signo=3, expr;
		var cad = ""+this.valor;
		var ceros = "", pos, pdec, i;
		for (i=0; i < dec; i++)
			ceros += '0';
		pos = cad.indexOf(',')
		if (pos < 0)
			cad = cad+","+ceros;
		else
		{
			pdec = cad.length - pos -1;
			if (pdec <= dec)
			{
				for (i=0; i< (dec-pdec); i++)
				cad += '0';
			}
			else
			{
				num = num*Math.pow(10, dec);
				num = Math.round(num);
				num = num/Math.pow(10, dec);
				cad = new String(num);
			}
		}
		pos = cad.indexOf(',')
		if (pos < 0) pos = cad.lentgh
		if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') 
		   signo = 4;
		if (miles && pos > signo)
			do
			{
				expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
				cad.match(expr)
				cad=cad.replace(expr, RegExp.$1+'.'+RegExp.$2)
			}
		while (cad.indexOf('.') > signo)
		if (dec<0) cad = cad.replace(/\./,'')
			return cad;
	}
}
//Fin del objeto oNumero:

//*******************************FUNCIONES AJAX****************************
function GetSarissaDocumentFromXml( obj )
{
	//activa el uso de XPath y el manejo de namespaces en el dom de XML
	
	var namespace = "xmlns:xsl=''";
	var xmlDoc = (new DOMParser()).parseFromString( Sarissa.serialize(obj), "text/xml");
	xmlDoc.setProperty("SelectionNamespaces", namespace );
	xmlDoc.setProperty("SelectionLanguage", "XPath");
	return xmlDoc;
}
function emptyList(obj)
{
	for (i=obj.length;i > -1; i--){
		obj.options[i] = null;
	}
}
//FUNCION AJAX PARA DESPLEGAR LISTA DE DESTINOS A PARTIR DE UN PAIS FORM PAQUETE
function paisDestino(tipo,id_pais,campo02){
	/*
	tipo = Tipo de consulta en el php
	cate = Objeto game
	ruta = Donde se encuentran los archivos
	lang = Idioma
	*/
	if (id_pais.value==0){
		emptyList(campo01);
		var campo02 = document.getElementById('campo02');
		emptyList(campo02);
		return false;
	}
	http = new XMLHttpRequest();//DEFINICION DEL HTTPrequest
	http.open("POST", "buscar_ajax.php");
	http.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	http.onreadystatechange = function(){requestpaisDestino(tipo,id_pais,campo02)};
	http.send("tipo="+tipo+"&id_pais="+id_pais.value);
} 

//FUNCION DE RESPUESTA DE LA CARGA DE LAS CIUDADES
function requestpaisDestino(tipo,id_pais,campo02){
	
	if (http.readyState == 1){ 
		video_category.options[0]=new Option('Loading...',0);
       	video_category.disabled = true;
    }
	
    if (http.readyState == 4){
		//alert (http.responseText);
		var domXml = GetSarissaDocumentFromXml(http.responseXML);
		//selectNodes SELECCIONA LOS NODOS
		var nodes = domXml.selectNodes("//item");
		//SE VACIA LA LISTA
		emptyList(campo02);
		var j=0;
		for( var i = 0; i < nodes.length;  i++ )
		{
			//getText TRAE EL VALOR DEL NODO
			var nom_pais = Sarissa.getText(nodes[i].selectSingleNode("./nombre"));
			var id_pais = Sarissa.getText(nodes[i].selectSingleNode("./codigo"));
			campo02.options[j]=new Option(nom_pais,id_pais);
			j = j + 1;
		}
		campo02.disabled = false;
		
		
	}
}
//***FUNCION AJAX PARA CARGAR TABLA DE ACTIVIDADES e INCLUYES
function cargarTabla(tipo,id_incluye,id_paquete,id_td,tipo_incluye){
	//alert (tipo_incluye);
	//alert (id_paquete.value);
	http = new XMLHttpRequest();//DEFINICION DEL HTTPrequest
	http.open("POST", "buscar_ajax.php");
	http.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	http.onreadystatechange = function(){requestcargarTabla(id_incluye,id_paquete,id_td)};
	http.send("tipo="+tipo+"&id_incluye="+id_incluye.value+"&tipo_incluye="+tipo_incluye.value+"&id_paquete="+id_paquete.value);
} 

//FUNCION DE RESPUESTA DE LA CARGA DE LAS CIUDADES
function requestcargarTabla(id_incluye,id_paquete,id_td){
	
	if (http.readyState == 1){ 
		video_category.options[0]=new Option('Loading...',0);
       	video_category.disabled = true;
    }
	
    if (http.readyState == 4){
		//alert (http.responseText);
    	var domXml = GetSarissaDocumentFromXml(http.responseXML);
		//selectNodes SELECCIONA LOS NODOS
		var nodes = domXml.selectNodes("//item");
		//SE VACIA LA LISTA
		//emptyList(campo02);
		var j=0;
		document.getElementById('tabla_incluye').innerHTML = http.responseText;
		/*for( var i = 0; i < nodes.length;  i++ )
		{
			//getElementbyId = InnerHtml.responseText;
			//getText TRAE EL VALOR DEL NODO
			//var nom_pais = Sarissa.getText(nodes[i].selectSingleNode("./nombre"));
			//var id_pais = Sarissa.getText(nodes[i].selectSingleNode("./codigo"));
			//campo02.options[j]=new Option(nom_pais,id_pais);
			j = j + 1;
		}
		campo02.disabled = false;*/
		
		
	}
}
//********FUNCION PARA ELIMINAR ACTIVIDAD ASSOCIADA
function delActividad(tipo,id_relacion_incluye,id_paquete,tipo_incluye){
	http = new XMLHttpRequest();//DEFINICION DEL HTTPrequest
	http.open("POST", "buscar_ajax.php");
	http.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	http.onreadystatechange = function(){requestdelActividad(id_relacion_incluye,id_paquete)};
	http.send("tipo="+tipo+"&tipo_incluye="+tipo_incluye+"&id_relacion_incluye="+id_relacion_incluye+"&id_paquete="+id_paquete);
} 

//FUNCION DE RESPUESTA DE LA CARGA DE LAS CIUDADES
function requestdelActividad(id_incluye,id_paquete,id_td){
	
	if (http.readyState == 1){ 
		video_category.options[0]=new Option('Loading...',0);
       	video_category.disabled = true;
    }
	
    if (http.readyState == 4){
		//alert (http.responseText);
    	var domXml = GetSarissaDocumentFromXml(http.responseXML);
		//selectNodes SELECCIONA LOS NODOS
		var nodes = domXml.selectNodes("//item");
		//SE VACIA LA LISTA
		//emptyList(campo02);
		var j=0;
		document.getElementById('tabla_incluye').innerHTML = http.responseText;
		/*for( var i = 0; i < nodes.length;  i++ )
		{
			//getElementbyId = InnerHtml.responseText;
			//getText TRAE EL VALOR DEL NODO
			//var nom_pais = Sarissa.getText(nodes[i].selectSingleNode("./nombre"));
			//var id_pais = Sarissa.getText(nodes[i].selectSingleNode("./codigo"));
			//campo02.options[j]=new Option(nom_pais,id_pais);
			j = j + 1;
		}
		campo02.disabled = false;*/
	}
}

//***************FUNCIONES DEL FRONTNAME BBORRAR LAS OTRAS OOOOJJJOOOOOOO*************************
//******FUNCION AJAX PARA CARGA DE EDADES*******************
function cargarTabla(tipo,num,id_td){
	//alert (num.value);
	//alert (id_td);
	http = new XMLHttpRequest();//DEFINICION DEL HTTPrequest
	http.open("POST", "buscar_ajax.php");
	http.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	http.onreadystatechange = function(){requestcargarTabla(num,id_td)};
	http.send("tipo="+tipo+"&num="+num.value+"&id_td="+id_td.value);
} 

//FUNCION DE RESPUESTA DE LA CARGA DE EDADES
function requestcargarTabla(num,id_td){
	
	if (http.readyState == 1){ 
		video_category.options[0]=new Option('Loading...',0);
       	video_category.disabled = true;
    }
	
    if (http.readyState == 4){
		//alert (http.responseText);
		var j=0;
		document.getElementById('edades_pasajeros').innerHTML = http.responseText;

		
		
	}
}
//******FUNCION AJAX PARA CARGA DE EDADES NOMBRE Y APELLIDO*******************
function cargarTabla2(tipo,num,id_td){
	//alert (num.value);
	//alert (id_td);
	http = new XMLHttpRequest();//DEFINICION DEL HTTPrequest
	http.open("POST", "buscar_ajax.php");
	http.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	http.onreadystatechange = function(){requestcargarTabla2(num,id_td)};
	http.send("tipo="+tipo+"&num="+num.value+"&id_td="+id_td.value);
} 

//FUNCION DE RESPUESTA DE LA CARGA DE EDADES NOMBRE Y APELLIDO*************
function requestcargarTabla2(num,id_td){
	
	if (http.readyState == 1){ 
		video_category.options[0]=new Option('Loading...',0);
       	video_category.disabled = true;
    }
	
    if (http.readyState == 4){
		//alert (http.responseText);
		var j=0;
		document.getElementById('edades_pasajeros').innerHTML = http.responseText;

		
		
	}
}
