function ovBG(a){
	var aB = "BG"+a;
	document.getElementById(aB).style.background =  "#eeeeee";
}
function otBG(a){
	var aB = "BG"+a;
	document.getElementById(aB).style.background =  "#FFFFFF";
}


function calcularnoches(){
	var fl = document.getElementById("idfllegada").value;
	var fs = document.getElementById("idfsalida").value;
	if (fl && fs){
	   xajax_calcularnoches(xajax.getFormValues('idform2'));  
	}
}

function disabledtag(d,e){
	var at = document.getElementById(d).value;
	var it = Number(document.getElementById("iditem").value);
	if (at){
		document.getElementById(e).disabled=false;
		xajax_processValorPago(xajax.getFormValues('IDformpago'),it,at); 
	}else{
		document.getElementById(e).disabled=true;
	}
	//document.getElementById('MsnIDformpago').innerHTML = vv;
}

function closetag(d){
  if (document.getElementById){
  obj = document.getElementById(d); 
  djb = document.getElementById('img_'+d); 
  var dimga = "./images/triangulo-on.gif";
  var dimgb = "./images/triangulo-out.gif";
  if (obj.style.display == "none"){ 
     obj.style.display = ""; 
	 djb.src = dimga; 
	 
   }else { 
     obj.style.display = "none"; 
	 djb.src = dimgb; 
  }
 }
}

function openWinImg(URL,w,h,s) {
	window.open(URL,"_blank","top=0,left=0,toolbar=no,width="+w+",height="+h+",status=yes,scrollbars="+s+",resize=no,menubars=no");
}

function agregarPasajero(CantPas){
	var vadulto = document.getElementById("Idadulto").value;
	var vnino = document.getElementById("Idnino").value;
	var vbebe = document.getElementById("Idbebe").value;
	var cantidadPasajeros = Number(vadulto) + Number(vnino) + Number(vbebe);
	
	var listaViaje = document.getElementById("pasajeros");
	//var mybody = getElementsByTagName("tr");
	var trcantidad = listaViaje.getElementsByTagName("tr").length;
	var validcant = cantidadPasajeros - trcantidad;
	if(cantidadPasajeros > 10) cantidadPasajeros = 10;
	if (validcant > 0){
	for(i=1;i<=validcant;i++){
		mycurrent_row = document.createElement("tr");
                
				//Columna 1
				mycurrent_cell1 = document.createElement("td");
				mycurrent_cell1.setAttribute("align","right");
				mycurrent_cell1.setAttribute("width","80");
				mycurrent_cell1.setAttribute("id","cl_nombre[]");

                // creates a text node
				font1 = document.createElement("<font>");
				font1.setAttribute("color","red");
				font1.setAttribute("id","ast_nombre[]");
				currenttext0 = document.createTextNode("*");
				font1.appendChild(currenttext0);
				mycurrent_cell1.appendChild(font1);
				
                currenttext1 = document.createTextNode(" Nombre: ");
                // appends the text node we created into the cell <td>
                mycurrent_cell1.appendChild(currenttext1);
                // appends the cell <td> into the row <tr>
                mycurrent_row.appendChild(mycurrent_cell1);
				
				//Columna 2
				mycurrent_cell2 = document.createElement("td");
				var inputNombre= (IE) ? document.createElement("<input name='nombre[]'>"): document.createElement("input");
			    inputNombre.setAttribute("type","text");
			    inputNombre.setAttribute("id","idnombre[]");
				inputNombre.setAttribute("size","30");
			    mycurrent_cell2.appendChild(inputNombre);
			    mycurrent_row.appendChild(mycurrent_cell2);
				
								//Columna 3
				mycurrent_cell3 = document.createElement("td");
				mycurrent_cell3.setAttribute("align","right");
				mycurrent_cell3.setAttribute("width","80");
                // creates a text node
				
				font2 = document.createElement("<font>");
				font2.setAttribute("color","red");
				font2.setAttribute("id","ast_nombre[]");
				currenttext4 = document.createTextNode("*");
				font2.appendChild(currenttext4);
				mycurrent_cell3.appendChild(font2);
				
                currenttext3 = document.createTextNode(" Tipo: ");
                // appends the text node we created into the cell <td>
                mycurrent_cell3.appendChild(currenttext3);
                // appends the cell <td> into the row <tr>
                mycurrent_row.appendChild(mycurrent_cell3);
				
				//Columna 4
				mycurrent_cell4 = document.createElement("td");
				var selectTipo = document.createElement("select");
			        selectTipo.setAttribute("id","tipoP[]");
					selectTipo.setAttribute("name","tipo[]");
			    var opcion0 = document.createElement("option");
			        opcion0.value = "";
			    var textoOpcion0 = document.createTextNode("---");
			       opcion0.appendChild(textoOpcion0);
			       selectTipo.appendChild(opcion0);
			    var opcion1 = document.createElement("option");
			      opcion1.value = "Adulto";
			    var textoOpcion1 = document.createTextNode("Adulto");
				  opcion1.appendChild(textoOpcion1);
				  selectTipo.appendChild(opcion1);
				var opcion2 = document.createElement("option");
				  opcion2.value = "Ni&ntilde;o";
				var textoOpcion2 = document.createTextNode("Niño");
			      opcion2.appendChild(textoOpcion2);
			      selectTipo.appendChild(opcion2);
			    var opcion3 = document.createElement("option");
			      opcion3.value = "bebe";
			    var textoOpcion3 = document.createTextNode("Bebe");
				 opcion3.appendChild(textoOpcion3);
				 selectTipo.appendChild(opcion3);
			
				mycurrent_cell4.appendChild(selectTipo);
				mycurrent_row.appendChild(mycurrent_cell4);

            
            // appends the row <tr> into <tbody>
         listaViaje.appendChild(mycurrent_row);
		 
	  }
	}else{
		for(e=validcant;e<0;e++){
			//listaViaje.removeChild();
			var d = trcantidad -1;
			listaViaje.removeChild(listaViaje.getElementsByTagName("tr")[d]);

		}
	}
	calcularnoches();
	//document.getElementById('msnpasj').innerHTML = cantidadPasajeros;
}
function CheckLogin(aVid,aVform){
  var msn = "";	
  var lg = document.getElementById("IDLogin").value;
  var numlog = lg.length;
  var ps = document.getElementById("IDPassword").value;
  var numpas = ps.length;
  
  if ((numlog > 5) && (numpas > 5)){
    if (aVid==1){
      xajax_processCheckLogin(xajax.getFormValues(aVform),aVid,"Msn"+aVform); 
    }
  }else{
	  var msn = "<font color=red>Cantidad de caracteres no permitido</font>";
  }
  document.getElementById('Msn'+aVform).innerHTML = msn;
}

function validarForm(i) {
	var msn = "";
	var num = document.getElementById(i).elements.length;
	for (a = 0; a < num;a++){
	  var nmt = document.getElementById(i).elements[a].name;	
	  
	  if (document.getElementById('ast_'+nmt)){
	    var djb = document.getElementById('ast_'+nmt).innerHTML;
	  }else{
		var djb = ""; 
	  }
	  if (djb=="*"){
		 var vlt = document.getElementById('Id'+nmt).value; 
		 if (vlt=="" || vlt==0){
			 var msn = "<font color=#FF9900>Datos Requeridos</font>";
			 var error = 1;
			 document.getElementById('cl_'+nmt).style.color = "#FF9900"
		 }else{
			 document.getElementById('cl_'+nmt).style.color = "#000000"
		 }
	  }
	}
	
	if (!msn){
	  if (i == "IDformregistro"){
		var ag = 1;  
	    xajax_processRegistroAgencia(xajax.getFormValues(i));
	  }
	  if (i == "IDformdatos"){	
	    var ag = 1;
	    xajax_processDatosAgencia(xajax.getFormValues(i));
	  }
	  if (i == "IDformpassword"){
		 numlog = document.getElementById('Idpnuevo').value.length;  
		if (numlog > 5){
	      var ag = 1;
	      xajax_processPasswordAgencia(xajax.getFormValues(i));
		}else{
		  var msn = "<font color=#FF9900>Cantidad minima de caracteres 6 </font>"+numlog;
		  document.getElementById('cl_pnuevo').style.color = "#FF9900";
		  document.getElementById('cl_prepetir').style.color = "#FF9900"
		}
	  }
	  if (i == "IDformanuncio"){	
	    var ag = 1;
	    xajax_processAnuncioAgencia(xajax.getFormValues(i));
	  }
	  if (i == "Idcontacto"){	
	    xajax_processContacto(xajax.getFormValues(i));
	  }
	  if (i == "IDformeditaranuncio"){	
	    var ag = 1;
	    xajax_processEdtAnuncioAgencia(xajax.getFormValues(i));
	  }
	  if (i == "IDformpago"){	
	    var ag = 1;
	    xajax_processPagoAgencia(xajax.getFormValues(i));
	  }
	  if (i == "idform2"){	
	    var ag = 1;
	    xajax_processReservacion(xajax.getFormValues(i));
	  }
	  if (i == "IDformbaja"){	
	    var ag = 1;
	    xajax_processDarsedeBaja(xajax.getFormValues(i));
		msn = "procesando...";
	  }
	  
	  if (!ag){
		 var ar = i.split("ag");
		 var tb = document.getElementById('tabla'+ar[1]).value;
		 xajax_processMsnVisitanteagencia(xajax.getFormValues(i),ar[1],tb);   
	  }
	  
	  
	}
	document.getElementById('Msn'+i).innerHTML = msn;

}

function ctficha(f,i){
  var vf = document.getElementById("idhficha").value;	
  //document.getElementById(f).className = "texto_pestana_hotel_clic";
  //document.getElementById(vf).className = "texto_pestana_hotel_link";
  //document.getElementById("idhficha").value = f;
    xajax_processFicha(xajax.getFormValues("idform2"),f,i);
  
}

function ctfichaOver(f) {
    
  document.getElementById(f).className = "texto_pestana_hotel_clic";
}

function ctfichaOut(g) {
  var tabIndex = document.getElementById("idhficha").value;	
  if (tabIndex == g){
    document.getElementById(g).className = "texto_pestana_hotel_clic";
  }else{
    document.getElementById(g).className = "texto_pestana_hotel_link";
  } 
   
 }

function pctficha(f,i){
  var vf = document.getElementById("idhficha").value;	
  document.getElementById(f).className = "ptexto_pestana_hotel_clic";
  document.getElementById(vf).className = "ptexto_pestana_hotel_link";
  document.getElementById("idhficha").value = f;
    xajax_processFicha(xajax.getFormValues("idform2"),f,i);
}

function pctfichaOver(f) {
    
  document.getElementById(f).className = "ptexto_pestana_hotel_clic";
}

function pctfichaOut(g) {
  var tabIndex = document.getElementById("idhficha").value;	
  if (tabIndex == g){
    document.getElementById(g).className = "ptexto_pestana_hotel_clic";
  }else{
    document.getElementById(g).className = "ptexto_pestana_hotel_link";
  } 
   
 }


function modPopup(a,w,h,m,r,t,b){
	var i = 1;
	var wh = w-10;
	var name = a;
	var c = getAnchorPosition(name);
	//var vEstado = document.getElementById("idhestado").value;

	//document.getElementById(i).style.background = "#FFFFCC";
	//document.getElementById("Idid").value = i;
	document.getElementById("IDwesq").style.zIndex =  10000;
	document.getElementById("IDwesq").style.display =  "block";
    document.getElementById("wcontbl").innerHTML="<span style='background-color:red;width:78px; padding: 2px 2px 2px 2px;' align=left><font color=#ffffff><b>Cargando...</b></font></span>";
    document.getElementById("hc-window").innerHTML= m;
    document.getElementById("IDwesq").style.width=w+"px";
	document.getElementById("hc-window").style.width=wh+"px";
    document.getElementById("dwindowcontent").style.height=h+"px";
    document.getElementById("dbodycontent").style.height=h+"px";
	document.getElementById("IDwesq").style.padding= c.y+"px 0px 0px "+c.x+"px";
	if(b=="localidades"){
	  xajax_ProcessSelectDestino(xajax.getFormValues("idform2"),m,b,t); 
	}
	if(b=="zonas"){
	  xajax_ProcessSelectZonas(xajax.getFormValues("idform2"),m,b,t); 
	}
	//DivSetVisible(i,w,h,c.x,c.y);
}

function DivSetVisible(i,w,h,l,t)
  {
   var hw = eval(h)+30;
   var DivRef = document.getElementById('IDwesq');
   var IfrRef = document.getElementById('DivShim');
   if(i)
   {
    DivRef.style.display = "block";
    IfrRef.style.width = w+"px" ;
    IfrRef.style.height = hw+"px";
    IfrRef.style.top = t;
    IfrRef.style.left = l;
    IfrRef.style.zIndex =  1;
    IfrRef.style.display = "block";
	//IfrRef.style.padding= t+"px 0px 0px "+l+"px";
	
   }
   else
   {
    DivRef.style.display = "none";
    IfrRef.style.display = "none";
   }
 }

function getScrollTop() { 
	self.scroll(0100);
} 

function getScrollBottom(y) { 
 var c = getAnchorPosition(y);
 self.scroll(0,c.y);
	
} 


function enviarrepuesta(q,t,l){
    xajax.$('idbotomsubmit').disabled=true;
    xajax.$('idbotomsubmit').value="por favor espere...";
	document.getElementById("idContenido").value = tinyMCE.getContent();  
	
	if (t=="foro_contenido"){
	  var ed = document.getElementById("idmensaje").value;	
	  var ct = document.getElementById("idContenido").value;
	  if (ed == ""){
	 	    xajax_processEnviarRepuesta(xajax.getFormValues(q),t,l);
	  }else{
		   xajax_processForoMensajeEdt(ed,ct);  
		   //document.getElementById("msnprueba").innerHTML = ct;
	  }
	}
	
	if (t=="foro_temas"){
	  document.getElementById("idContenido").value = tinyMCE.getContent();	
	  document.getElementById(q).submit();
	}
  }
  
  function setBrowserType(){ 
    var aBrowFull = new Array("opera", "msie", "netscape", "gecko", "mozilla"); 
    var aBrowVers = new Array("opera", "msie", "netscape", "rv",    "mozilla"   ); 
    var aBrowAbrv = new Array("op",    "ie",   "ns",       "mo",    "ns"   ); 
    var sInfo = navigator.userAgent.toLowerCase();; 

    sBrowser = ""; 
    for (var i = 0; i < aBrowFull.length; i++){ 
     if ((sBrowser == "") && (sInfo.indexOf(aBrowFull[i]) != -1)){ 
      sBrowser = aBrowAbrv[i]; 
      sVersion = String(parseFloat(sInfo.substr(sInfo.indexOf(aBrowVers[i]) + aBrowVers[i].length + 1))); 
     } 
    } 
   } 

   function getBrowserName(){ 
   setBrowserType();
    return sBrowser; 
   } 

   function getBrowserVersion(){ 
   setBrowserType();
    return sVersion; 
   } 


function openWinDes(URL,w,h,s) {
	//window.open(URL,"_blank","top=0,left=0,toolbar=no,width="+w+",height="+h+",status=no,scrollbars="+s+",resize=no,menubars=no");
    childWindow=open(URL,"_blank","top=0,left=0,toolbar=no,width="+w+",height="+h+",status=no,scrollbars="+s+",resize=no,menubars=no");
    //if (childWindow.opener == null) childWindow.opener = self;
}

//paginadores
function inputpaginadorphp(t,v,i,u,l){
	
    var p = (document.getElementById("IdPagetp").value);
    if (t == "foro_temas"){
	 window.location = 'index.php?mn=foro&vw=2&sf='+v+'&tp='+i+'&ord='+u+'&sort='+l+'&pg='+p+'';  
	}
  }

function inputpaginador(t,v,i,u,l){
    var p = (document.getElementById("IdPagetp").value);
    xajax_processPaginador(xajax.getFormValues(i),t,p,v,u,l);
	  
  }

function vwFotos(m,u){
	document.getElementById('idvwFotos').src = "./images/trans.gif";
	var a = document.getElementById('idaImagen').value;
	xajax_processvwFotos(m,u,a);
}

function outcomentarioimg(m,u){
	document.getElementById('vercomentario').innerHTML = "Comentario de Imagen:";
}

function cargarcomentarioimg(m,u){
	var f = document.getElementById('id'+m).value;
	xajax_cargarcomentarioimg(f,m,u);
}

function vwComentario(m){
	document.getElementById('idcom'+m).style.display = "block";
	if (m != "SelectForo"){
	  document.getElementById('id'+m).focus();
	}else{
		var va = document.getElementById('idforo_tipot').value;
		var tm = document.getElementById('idforo_temas').value;
		if( va != ""){
			xajax_processModeradorAct('foro_temas',tm,'movido',va);
			//document.getElementById('msnprueba').innerHTML = tm;
		}
	}
}

function getElement() {
		var d2 = document.getElementById('einmput');
	    var num = d2.childNodes.length;
		for (i=1;i< num;i++){
			d2.removeChild(d2.childNodes[i]);
  		}
		document.getElementById('hc-window').innerHTML = num;
}


function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

//Contador de caracteres.
function Contar(entrada,salida,texto,caracteres) {  
 var entradaObj=getObject(entrada);  
 var salidaObj=getObject(salida);  
 var longitud=caracteres - entradaObj.value.length;  
 if(longitud <= 0) {  
   longitud=0;  
   texto='<b><font color="#008000">Ya puedes enviar el mensaje!</font></b>';  
   salidaObj.innerHTML = texto;  
 }  
 else {  
 salidaObj.innerHTML = texto.replace("{CHAR}",longitud);  
 }  
} 





function OcultarCantidades(i,m,n) {
	if (n==1){ 
	   st="block";
	   mm = "<span onclick=\"OcultarCantidades('"+i+"','"+m+"','2')\" onMouseOver=\"this.style.color='#AABBDD'; this.style.cursor='pointer'\" onMouseOut=\"this.style.color='#000000';\">Ocultar Tama&ntilde;os</span>";
	 }
	if (n==2){
		st="none";
		mm = "<span onclick=\"OcultarCantidades('"+i+"','"+m+"','1')\" onMouseOver=\"this.style.color='#AABBDD'; this.style.cursor='pointer'\" onMouseOut=\"this.style.color='#000000';\">Mostrar Tama&ntilde;os</span>";
	}
	
  for (a=1;a<=i;a++){
    var tr = "TR"+a+"-"+m;
	var ct = "idcant"+a+"-"+m;
	var c = Number(document.getElementById(ct).value);
	if (c < 1){
     document.getElementById(tr).style.display = st;
	}
  }
  document.getElementById("mmc"+m).innerHTML = mm;
}

function CalcularPrecio(i,m,n) {
	var p  = "idprecio"+i+"-"+m;
	var tp = "idtprecio"+i+"-"+m;
	var c  = "idcant"+n+"-"+m;
	document.getElementById(tp).value = (document.getElementById(p).value) * (document.getElementById(c).value);
	xajax_processCantidadOrden(m,i,(document.getElementById(c).value),(document.getElementById(p).value));
	
}

function agregarfotos(c) {
	  	var cs = document.getElementById("idform2").elements.length;
		if (c){
		  checked = false;
		  boton = true;
		  document.getElementById('selectfoto').innerHTML =  '<input name="agregar" type="button" value="Seleccionar todos"  onClick="agregarfotos(\'\')">';
		}else{
		  checked = true;
		  boton = false;
		  document.getElementById('selectfoto').innerHTML =  '<input name="agregar" type="button" value="Desmarcar todos" onClick="agregarfotos(\'1\')">';
		}
         for (var i = 0; i < cs; i++) {
			 if(document.getElementById("idform2").elements[i].type == "checkbox") 
	          document.getElementById("idform2").elements[i].checked = checked;
         }
		 
		 document.getElementById("btagregar").disabled = boton;
}

function checkboton() {
	  	var cs = document.getElementById("idform2").elements.length;
		var c = 0;
		for (var i = 0; i < cs; i++) {
	       if (document.getElementById("idform2").elements[i].checked==true){
		     boton = false;
			 c = 1; 
		   }
         }
		if (c == 0){
		  boton = true;
		}
		 document.getElementById("btagregar").disabled = boton;
		 
}

function esNum(e) {
var charCode
if (navigator.appName == "Netscape") // Veo si es Netscape o Explorer (mas adelante lo explicamos)
charCode = e.which // leo la tecla que ingreso
else
charCode = e.keyCode // leo la tecla que ingreso
status = charCode
if (charCode > 31 && (charCode < 48 || charCode > 57)) { // Chequeamos que sea un numero comparandolo con los valores ASCII
  alert("Caracter no permitido...")
  return false
}

return true
}

function esNumDe(e) {
var charCode
if (navigator.appName == "Netscape") // Veo si es Netscape o Explorer (mas adelante lo explicamos)
charCode = e.which // leo la tecla que ingreso
else
charCode = e.keyCode // leo la tecla que ingreso
status = charCode
if (charCode > 31 && (charCode < 48 || charCode > 57)) { // Chequeamos que sea un numero comparandolo con los valores ASCII
  if (charCode == 46){
    return true
  }else{
	  alert("Caracter no permitido...")
     return false
  }
}

return true
}

function IsNumeric(valor) 
{ 
var log=valor.length; var sw="S"; 
for (x=0; x<log; x++) 
{ v1=valor.substr(x,1); 
v2 = parseInt(v1); 
//Compruebo si es un valor numérico 
if (isNaN(v2)) { sw= "N";} 
} 
if (sw=="S") {return true;} else {return false; } 
} 

var primerslap=false; 
var segundoslap=false; 
function formateafecha(fecha) 
{ 
var long = fecha.length; 
var dia; 
var mes; 
var ano; 

if ((long>=2) && (primerslap==false)) { dia=fecha.substr(0,2); 
if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { fecha=fecha.substr(0,2)+"/"+fecha.substr(3,7); primerslap=true; } 
else { fecha=""; primerslap=false;} 
} 
else 
{ dia=fecha.substr(0,1); 
if (IsNumeric(dia)==false) 
{fecha="";} 
if ((long<=2) && (primerslap=true)) {fecha=fecha.substr(0,1); primerslap=false; } 
} 
if ((long>=5) && (segundoslap==false)) 
{ mes=fecha.substr(3,2); 
if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4); segundoslap=true; } 
else { fecha=fecha.substr(0,3);; segundoslap=false;} 
} 
else { if ((long<=5) && (segundoslap=true)) { fecha=fecha.substr(0,4); segundoslap=false; } } 
if (long>=7) 
{ ano=fecha.substr(6,4); 
if (IsNumeric(ano)==false) { fecha=fecha.substr(0,6); } 
else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { fecha=fecha.substr(0,6); } } } 
} 

if (long>=10) 
{ 
fecha=fecha.substr(0,10); 
dia=fecha.substr(0,2); 
mes=fecha.substr(3,2); 
ano=fecha.substr(6,4); 
// Año no viciesto y es febrero y el dia es mayor a 28 
if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { fecha=fecha.substr(0,2)+"/"; } 
} 
return (fecha); 
} 

function checkdisclaimer(){
   var allok=true;
   var radgrp1=document.login.cond1;
   var alertext="";
   if (document.login.email.value.length<1) {alertext=alertext+"- Por favor, escribe tu dirección de correo electrónico \n"; allok= false;}
   if (document.login.pass.value.length<1) {alertext=alertext+"- Por favor, escríbe tu contraseña \n"; allok= false;}
   if (allok==false){alert("Atención: \n"+alertext);}
   return allok;
}


function uno(src,color_entrada) { 
    src.bgColor=color_entrada;src.style.cursor="hand"; 
} 
function dos(src,color_default) { 
    src.bgColor=color_default;src.style.cursor="default"; 
} 

function closeit(CT){
 if (CT=="AL"){
    
	var IfrRef = document.getElementById('DivShim');
	IfrRef.style.display = "none";
    document.getElementById("IDwesq").style.display="none";
	
 }
 
 if (CT=="IM"){
     document.getElementById("IDwesq").style.display="none";
     //xajax_AgregarLocalidad(xajax.getFormValues("IDFormLocalidad"),CT);   
 }
 
 if (CT=="salir"){
   //xajax_processSalir();
 }
}  
