/*---Version 1.0 2007-----------------------------------------*/
/////////FUNCIONES/////////////////////////////
/*
  changeTipDrd(buscador)
  getRadioValue(radioObj)
  setTipDrd(buscador)
  WloadData()
 addCharReplace(nStr,car,newcar)
 addOptions(select, options)
 addSepMil(ent, sep)
 airportTipToString(oTip)
 airportTipToStringES(oTip)
 airportTipToStringHT(oTip)
 airportTipToStringMulti(oTip)
 atenua(opacity)
 avpag(id,tipo)
 buscar_codser_codtou(id,simbol,lugar_grid)
 buscarCiudad2(codtse,style)
 cambiaFlecha(left, right, oFrom)
 cargaOficinas(tipo)
 cerrarFicha()
 cerrarFrame(id)
 cerrarMapa()
 charReplace(str,car,newcar)
 checkIdaVue(valor,buscador)
 checkwhere(e)
 clearList(id)
 enviarFormHT()
 escribedescripcorta(desc)
 esNacional(ida,vta)
 esResidenteMini(id)
 estableceCodigo(codigos)
 estableceResidente(id)
 fetchJson(strUrl)
 filtrarSeccion(id)
 formatNumber(num)
 getAjaxObject(url)
 getCheckBoxChecked(param,num)
 getCheckBoxValues(param,num)
 getCheckedId(radioObj)
 getCheckedValue(radioObj)
 getIsoValue(cadena)
 getNumAdu(valor)
 getNumBeb(valor)
 getNumNin(valor)
 getUrlParams(obj)
 gotopag(id,tipo)
 HabilitaCargando(valor)
 hideMe(id)
 initCheck(valor,formulario)
 initialize(obj, zona)
 loadList(id)
 MM_findObj(n, d)
 MM_preloadImages()
 MM_swapImage()
 MM_swapImgRestore()
 mostrarMensaje()
 muestraLoading()
 ocultarIframe(id)
 padNumber(nStr, nLen, sChr)
 peticion(url)
 preSelOfiDes(select)
 redondear(cantidad, decimales)
 referdistri()
 repag(id,tipo)
 resetFilter(tipo)
 seleccionarFrameCiudad(id,nom,codtse)
 sendPaginationAE(id)
 sendPaginationES(id)
 sendPaginationHT(id)
 setRadioCabina(destino)
 showAddress(address, vhotel, zona,sitio,obj)
 SubstringAfter(str, car)
 SubstringBefore(str, car)
 updatecomplete(objJson)
 ValidaForm(buscador)
 validatePassengers(buscador)
 verFicha(src,lugar)
 verMapaDesdeFicha(address, vhotel)
 verubicacion(hotel)
 visualizar(id)
 visualizarHotel(id)
Number.prototype.round 
xmlhttp.onreadystatechange
*/

/****************************************************************************************************************************************************************************************************************************/ 
																		/*VARIABLES*/

/****************************************************************************************************************************************************************************************************************************/ 
/*PROPIEDADES*/

var urlhttps='https://www.unsol.es/';
											/*PRO  https://www.unsol.es/*/
											/*PRE  http://unsol.dome-consulting.com/*/
											/*LOCAL: http://localhost:80/*/


/*Number.prototype.round */
var arrNationalAirport ='ABC;ACE;ALC;AGP;BCN;BJZ;BIO;EAS;FUE;GMZ;GRO;GRX;GIB;IBZ;LCG;LEI;LEN;LEU;LPA;MAD;MAH;MJV;MLN;ODB;OVD;OZP;PMI;PNA;QSA;RJL;SCQ;SDR;SLM;SPC;SVQ;TCI;TFN;TFS;TOJ;VDE;VGO;VIT;VLC;VLL;XRY;TNC;ZAZ';
arrNationalAirport = arrNationalAirport.split(';');
var obj;
var aereoRes = new Array();
    aereoRes[0] = 'PMI';
    aereoRes[1] = 'IBZ';
    aereoRes[2] = 'MAH';
    aereoRes[3] = 'SPC';
    aereoRes[4] = 'LPA';
    aereoRes[5] = 'TFN';
    aereoRes[6] = 'TCI';
    aereoRes[7] = 'TFS';
    aereoRes[8] = 'FUE';
    aereoRes[9] = 'ACE';
    aereoRes[10] = 'MLN'; 
    aereoRes[11] = 'TNC'; 

var aereoResIB = new Array();
   aereoResIB[0] = 'PMI';
   aereoResIB[1] = 'IBZ';
   aereoResIB[2] = 'MAH';
var aereoResCM = new Array();
	aereoResCM[0]='CET';
	aereoResCM[1]='MLN';   
  var aereoResIC = new Array();
   aereoResIC[0] = 'SPC';
   aereoResIC[1] = 'LPA';
   aereoResIC[2] = 'TFN';
   aereoResIC[3] = 'TCI';
   aereoResIC[4] = 'TFS';
   aereoResIC[5] = 'FUE';
   aereoResIC[6] = 'ACE';
   aereoResIC[7] = 'TNC';
   var arrResidente;
   arrResidente='BP#Residente Balear@BI#Residente Interior Balear@RC#Residente Canario@DC#Residente Interior Canario@RM#Residente Ceuta y Melilla';
   arrResidente=arrResidente.split('@');
var xCoord = 0;
var yCoord = 0;
var map = null;
var geocoder = null;
var loader;
/*codigos nacionales*/
var airNat = new Array('ABC','ACE','ALC','AGP','BCN','BJZ','BIO','EAS','FUE','GRO','GRX','IBZ','LCG','LEI','LEN','LEU','LPA','MAD','MAH','MJV','MLN','ODB','OVD','OZP','PMI','PNA','QSA','RJL','SCQ','SDR','SLM','SPC','SVQ','TFN','TFS','TOJ','VGO','VIT','VLC','VLL','XRY','ZAZ','TNC');
/*codigos residentes*/
var airRes = new Array('ACE','FUE','IBZ','LPA','MAH','MLN','PMI','SPC','TFN','TFS','TNC');
var numnoc=0;
/* patrones para formatos de fechas*/
var patron = new Array(2,2,4);
var patronHora = new Array(2,2);
var patron2 = new Array(1,3,3,3,3);
var patronCorto = new Array(2,4);
//var airResIntBP=new Array('PMI','MAH'.'IBZ');
//var airResIntRC=new Array(ACE','FUE','LPA','SPC','TFN','TFS');

/****************************************************************************************************************************************************************************************************************************/ 
																		/*CONTROL DE RADIOS Y COMBOS*/

/****************************************************************************************************************************************************************************************************************************/ 
function initCheck(valor,formulario)
{
	checkIdaVue(valor,formulario);
	var form=document.forms[formulario];
	form.idavue[1].checked=true;
}
/****************************************************************************/
/*habilita o deshabilita la cabina busisness si es SDQ*/
function setRadioCabina(destino)
{
	/*var destinoIn=destino.substr(0,3);			
	if (destinoIn=='SDQ')
		document.getElementById('cabinaBUP').disabled='true';
	else
		document.getElementById('cabinaBUP').disabled='';*/				
}
  /*****************************************************************************/
   /* proceso que a partir de una especialidad filtra el array arrSeccion escogioendo los codigos de seccion encabezados por su codigo de especialidad*/
   function filtrarSeccion(id)
   {
        clearList('resicombinacion');
        loadList(id);        
   }    
  /*****************************************************************************/
    //proceso que limpia las options de la seleccion de secciones cada vez que cambiamos el de especialidad
  function clearList(id)
  {
       var obj = document.getElementById(id);
       if (obj != null)
       {
          while (obj.childNodes.length > 0)
	            obj.removeChild(obj.lastChild);
       }
   }
/*****************************************************************************/
function getCheckedValue(radioObj) 
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	if(radioObj.checked)
		return radioObj.value;
	else
		return "";
	for(var i = 0; i < radioLength; i++)
	 {
		if(radioObj[i].checked) 
			return radioObj[i].value;
	}
	return "";
}       
/*****************************************************************************/
 //proceso que carga la nueva lista de opciones de seccion cada vez que se cambia la especialidad
function loadList(id)
{
	var form= document.getElementById(id);
	var buscaaerori='';
	var buscaaerdes='';
	  if((form.aerori.value.length > 3)&&(form.aerdes.value.length > 3))
	  {
	     buscaaerori = form.autori;
	     buscaaerdes = form.autdes;
	  }
	  else  if((form.aerori.value.length > 3)&&(form.aerdes.value.length == '3'))
	  {
	     buscaaerori = form.autori;
	     buscaaerdes = form.aerdes;
	  }   
  	  else  if((form.aerori.value.length == '3')&&(form.aerdes.value.length > 3))
  	  {
	     buscaaerori = form.aerori;
	     buscaaerdes = form.autdes;
	}
	else
	{
	     buscaaerori = form.aerori;
	     buscaaerdes = form.aerdes;	
	}
	var tipResi=estableceResidente(buscaaerori )+'#'+ estableceResidente(buscaaerdes);
	tipResi=tipResi.split('#');
	tipResi=estableceCodigo(tipResi);
	  var obj =form.resicombinacion;
	  if (obj != null)
	  {
      		 var opt;
		 opt = document.createElement('OPTION');
 		 opt.setAttribute('value', '');
		 opt.innerHTML ='Seleccionar';
		 obj.appendChild( opt );
	       for(y=0;y<tipResi.length;y++)
	       {
			    for (var x = 0; x < arrResidente.length; x++)
		          {  
          			        if(arrResidente[x].split('#')[0]==tipResi[y])
		          	        {
	      		  			 opt = document.createElement('OPTION');
		       	 		 opt.setAttribute('value', arrResidente[x].split('#')[0]);
		    				 opt.innerHTML = arrResidente[x].split('#')[1];
	   					 obj.appendChild( opt );
	   	 			}
		   		}
		}     	 
 	 }
 }
/*****************************************************************************/    
/*proceso que devuelve el valor del radio actualmente seleccionado*/
function  getRadioValue(radioObj) 
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	if(radioObj.checked)
		return radioObj.value;
	else
		return "";
	for(var i = 0; i < radioLength; i++) 
	{
		if(radioObj[i].checked) 
			return radioObj[i].value;
	}
	return "";
} 
/*------------------------------------------------*/
/*proceso que devuelve el id del radio marcado actualmente*/
function getCheckedId(radioObj) 
{
     if(!radioObj)
    		return "";
	 var radioLength = radioObj.length;
       if(radioLength == undefined)
       if(radioObj.checked)
       	  return radioObj.id;
      else
              return "";
     	for(var i = 0; i < radioLength; i++) 
      	{
            if(radioObj[i].checked) 
               return radioObj[i].id;
     	 }
       return "";
}	

/****************************************************************************************************************************************************************************************************************************/ 
																		/*VALIDACIONES*/

/****************************************************************************************************************************************************************************************************************************/ 

/*proceso que valida los parametros antes de la disponibilidad*/
function ValidaForm(buscador)
{	
   var fec1 = fromFecha(document.forms[buscador].fecha_orig.value,0,0,0);
   var fec2 = fromFecha(document.forms[buscador].fecha_dest.value,0,0,0);
   var fec3=new Date();
	var values='';
	var contador=0;

	var ciudad = document.forms[buscador].ori_HT.value;
   if(ciudad ==''){
      alert(msgciuhotel);
      return false;
   }
	if ((hayreguser!=0) && ((document.forms[buscador].codtou.value!='SKT') && (document.forms[buscador].codtou.value!='EPL')))
	{
		values =getCheckBoxChecked('prv_',3);
		values=values.split('#');
		if (values.length >0)	
		{
			for(var x= 0 ; x<values.length;x++)
			{
				if (values[x]=='false')
					contador +=1;
			}
			if (contador=='3')
			{
				alert(msgerrorprv);
				atenua(70);
				return false;
			}
		}
	}
   fec3=makeDateFormat(fec3.getDate(),fec3.getMonth()+1,fec3.getFullYear());
   fec3 = fromFecha(fec3,0,0,0);
	if  (document.forms[buscador].oriHT.value=='')
	{
		alert(msgerror1);
		return false;
	}
	else if  (document.forms[buscador].fecha_orig.value=='')
	{
		alert(msgerror3);
		return false;
	}
	else if  (document.forms[buscador].fecha_dest.value=='')
	{
		alert(msgerror4);
		return false;
	}
	else if(fec2 < fec1)
	{
		alert(msgerror5);
		return false;
	}
	else if(fec1.toString()==fec3.toString())
	{
		alert(msgerror6);
		return false;
	}
	numnoc =days_between(fec2, fec1);
	return true;
}
/*------------------------------------------------*/
/*valida la cantidad de pasajeros*/
function validatePassengers(buscador)
{
	var form=document.getElementById(buscador); 
	var numadu = parseInt(form.num_adu.options[form.num_adu.selectedIndex].value);
	var numbeb = parseInt(form.num_beb.options[form.num_beb.selectedIndex].value);
	var numnin = parseInt(form.num_nin.options[form.num_nin.selectedIndex].value);
	var ok=0;
	if (((numadu + numbeb + numnin) > 9) || (numbeb > numadu) )
	{
		alert(msgpas);
		ok=1;
	}
	if(numbeb > 0 && numadu == 0)
	{
		alert(msgpas2);
		ok=1;
	}
	if (ok == 0)
		return true;
	 else 
		return false;				
 }	
/*----------------------------------------------------------------------------------*/
/*verifica en la carga si es solo ida o ida y vuelta*/
function checkIdaVue(valor,buscador)
{				
	document.forms[buscador].idavue.value = valor;
	if (valor != 'S')
	{
		document.getElementById('fecha_dest').style.visibility = 'hidden';
		document.getElementById('cal_vta').style.visibility = 'hidden'; 
		document.getElementById('timefin_sl').style.visibility = 'hidden';  
		document.getElementById('hora_vue_label').style.visibility='hidden';
		document.getElementById('fecha_vue_label').style.visibility='hidden';
	}
	else
	{			
		document.getElementById('fecha_dest').style.visibility = 'visible';
		document.getElementById('cal_vta').style.visibility = 'visible'; 
		document.getElementById('timefin_sl').style.visibility = 'visible';      
		document.getElementById('hora_vue_label').style.visibility='visible';
		document.getElementById('fecha_vue_label').style.visibility='visible';
	}
}	
/*------------------------------------------------*/
/*marca si es residente o no*/
function  setTipDrd(buscador)
{
	if ((document.forms[buscador].residente.checked) && (document.forms[buscador].resicombinacion.value!=''))
		document.forms[buscador].tipdrd.value =document.forms[buscador].resicombinacion.value;	
	else
	{
		document.forms[buscador].tipdrd.value ='';			
		document.forms[buscador].residente.checked=false;
	}	
}
/*------------------------------------------------*/
/*marca si es residente o no*/
function  changeTipDrd(buscador)
{	
	if (document.forms[buscador].resicombinacion.value!='')
	{
		document.forms[buscador].tipdrd.value =document.forms[buscador].resicombinacion.value;
		document.forms[buscador].residente.checked=true;
	}
	else	
	{
		document.forms[buscador].tipdrd.value ='';
		document.forms[buscador].residente.checked=false;		
	}
}			

/****************************************************************************************************************************************************************************************************************************/ 
																		/*CONTROL DE STRINGS*/

/****************************************************************************************************************************************************************************************************************************/   	

function addCharReplace(nStr,car,newcar)
{
	nStr += '';
	x = nStr.split(car);
	x1 = x[0];
	var x2='';
	for(y=0; y < x.length-1; y++) 
		x2 += x.length >1 ? newcar + x[y+1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) 
		x1 = x1.replace(rgx, '$1' + newcar + '$2');
	return x1 + x2;
}
/***********************************************************/
 /* formato que reemplaza un caracter en el formato autocompletar*/
function getIsoValue(cadena)
{	var tmp = cadena.substr(cadena.length-1,1);
	if (tmp=='&')
	{
		cadena=cadena.replace('&','\u00f1');
		return addCharReplace(cadena,'&ntilde;','\u00f1');
	}	
	else	
		return addCharReplace(cadena,'&ntilde;','\u00f1');
}
/*****************************************************************************/
function charReplace(str,car,newcar)
{
	x = str.split(car);
	x1 = x[0];
	for(y=1; y < x.length; y++)
		x1 += newcar + x[y];
	return x1;
}
/*****************************************************************************/
/*colocacion del 0 para las fechas*/	 
function padNumber(nStr, nLen, sChr)
{ 
	var sRes = String(nStr); 
	for (var i = 0; i < nLen - String(nStr).length; i++) 
		sRes = sChr + sRes; 
	return sRes; 
} 
/****************************************************************************/
/*Emulacion del substringafter y before del xsl*/
 function SubstringAfter(str, car) 
 {
	try{
 	 var tmp=  str.substring(str.indexOf(car)+1, str.length);
	 if (tmp.length > 0)
	 	return tmp;
	 else
	 	return str;	
	}catch(e)
	{ return '';}	
}		
/****************************************************************************/
 function SubstringBefore(str, car)
 {
 	try{ 
	   var tmp= str.substring(0, str.indexOf(car));
	 if (tmp.length > 0)
	 	return tmp;
	 else
	 	return str;	 			 	
	 }catch(e)
	 { return '';}	
}	

/****************************************************************************************************************************************************************************************************************************/ 
																		/*CONTROL DE IMAGENES*/

/****************************************************************************************************************************************************************************************************************************/   	

/*funciones para precarga de imagenes*/
function MM_swapImgRestore() 
 { //v3.0
	   var i,x,a=document.MM_sr;
	   for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
		   	x.src=x.oSrc;
  }
/*----------------------------------------------------------------------------------*/
function MM_preloadImages() 
{ //v3.0
	  var d=document; 
	  if(d.images)
	  {
	  	 if(!d.MM_p) 
	  	 	d.MM_p=new Array();
		  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		  for(i=0; i<a.length; i++)
			    if (a[i].indexOf("#")!=0)
			    { 
				    	d.MM_p[j]=new Image; 
				    	d.MM_p[j++].src=a[i];
				}
	}
}
/*----------------------------------------------------------------------------------*/			
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_swapImage() 
{ //v3.0
  	var i,j=0,x,a=MM_swapImage.arguments; 
  	document.MM_sr=new Array; 
  	for(i=0;i<(a.length-2);i+=3)
		   if ((x=MM_findObj(a[i]))!=null)
		   {
		   	document.MM_sr[j++]=x; 
		   	if(!x.oSrc) x.oSrc=x.src; 
			   	x.src=a[i+2];
		   }
}

/****************************************************************************************************************************************************************************************************************************/ 
																		/*CONTROL DE AUTOCOMPLETAR*/

/****************************************************************************************************************************************************************************************************************************/   	

var auto =	new Zapatec.AutoComplete({
	fields: ['aerori','aerdes'],
	dataOnDemand: true,
	callbackSource: WloadData,
	convertTip: airportTipToString,
	width: 'auto'
});  
  /*****************************************************************************/
function airportTipToString(oTip) 
{  
    var buscador=document.forms['multibuscador'];
      	if (buscador==null)
      		buscador=document.forms['minibuscadorAE'];
	if (auto.field.name == 'aerori') {
	  document.getElementById('autori').value=oTip.code;
	if (esResidenteMini(buscador.id))
	{
      				 document.getElementById('resi').style.display='block';
	            document.getElementById('resicombinacion').style.display='block';
	            document.getElementById('resicombinacion').style.visible='visible';
		document.getElementById('residente').style.display='block';					 
		if (tipdrdini!='0')	
			 document.forms[buscador.id].residente.checked=true;
		else
			 document.forms[buscador.id].residente.checked=false;
	}	 
	else
	{			 
		 document.forms[buscador.id].residente.checked=false;	
      				 document.getElementById('resi').style.display='none';
	            document.getElementById('resicombinacion').style.display='none';
	            document.getElementById('resicombinacion').style.visible='hidden';
		document.getElementById('residente').style.display='none';	
	}	 
  } 
  if (auto.field.name == 'aerdes'){
	  document.getElementById('autdes').value=oTip.code;
	if (esResidenteMini(buscador.id))
	{
     				 document.getElementById('resi').style.display='block';
            document.getElementById('resicombinacion').style.display='block';
            document.getElementById('resicombinacion').style.visible='visible';
	document.getElementById('residente').style.display='block';	
	if (tipdrdini!='0')	
		 document.forms[buscador.id].residente.checked=true;
	else
		 document.forms[buscador.id].residente.checked=false;
	}	 
	else
	{			 
		 document.forms[buscador.id].residente.checked=false;	
        	 document.getElementById('resi').style.display='none';
            document.getElementById('resicombinacion').style.display='none';
            document.getElementById('resicombinacion').style.visible='hidden';
		document.getElementById('residente').style.display='none';	
	}	 
  }  
   if ((auto.field.name == 'inputArbol'))
	  document.getElementById('autht').value=oTip.code;
    return getIsoValue(oTip.city);
}
/*****************************************************************************/
 function  WloadData()
   {
	return {
		source:fetchJson(),
    	sourceType: 'json/url'
  	};
  }
/*****************************************************************************/  
function airportTipToStringMulti(oTip)
{
	if (auto.field.name == 'aerori') 
	  document.getElementById('autori').value=oTip.code;
	else{
		if (auto.field.name == 'aerdes')
			document.getElementById('autdes').value=oTip.code;
		  else{
			if (auto.field.name == 'inputArbol')
				document.getElementById('autht').value=oTip.code;					 
			}
		}
	if (document.getElementById('multcode')){
		document.getElementById('multcode').value = oTip.code;
		if (oTip.czge)
			document.getElementById('multczge').value = oTip.czge;
		else
			document.getElementById('multczge').value = oTip.code;
		document.getElementById('multcity').value = getIsoValue(oTip.city);
	}
	return getIsoValue(oTip.city);
};
/*------------------------------------------------*/
/*proceso del autocomplete para dar formato al dato actual seleccionado leido del json*/
function airportTipToStringHT(oTip) 
{
      	if (auto.field.name == 'ori_HT')
		  document.getElementById('oriHT').value=oTip.code;
     	return getIsoValue(oTip.city);
}
/*------------------------------------------------*/
function airportTipToStringES(oTip) 
{
      	if (auto.field.name == 'ori_ES')
		  document.getElementById('oriES').value=oTip.code;
     	return getIsoValue(oTip.city);
}
/*------------------------------------------------*/
/*lectura del fichero JSON*/   
  function fetchJson(strUrl)
  { 
  	
	 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++ */
	 /*								MODIFICAR LA URL AQUI										*/
	 /*	La url debe apuntar al fichero "ComponenteZonasAE.json"
	 /*	que debe estar en el mismo Dominio que el html desde
	 /* donde se llama a la función.
	 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++ */
	 
	 strUrl = "http://www.viajesikea.com/buscador/ComponenteZonasAE.json"; 
	 
	 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++ */
	 
	  	
   	  return Zapatec.Transport.fetchJsonObj({
        url:  strUrl ,
        reliable: true,
        onLoad: updatecomplete
     	});     
   }
/*------------------------------------------------*/
/*una vez completada la lectura se detiene en este proceso en el cual se filtra por los codigos del fichero leido*/  
function updatecomplete(objJson)  
{
	auto.loadDataJson(objJson);
	var key=document.getElementById(auto.field.id).value; // serÃ¡ origen o destino
	key=key.toUpperCase();
	var j=0;
	for(var i=0; i < auto.data.inputOrigin.length;i++) // recorremos todos los elementos del Json
      {
	      // buscar por cualquiera de los campos, si coincide, se aÃ±ade sÃ³lo una vez
	      var autoword = getIsoValue(auto.data.inputOrigin[i].city.substring(0,key.length).toUpperCase());
	      autoword=autoword.toUpperCase();
       	 if((key== auto.data.inputOrigin[i].code.toUpperCase())||(key== autoword))
      		{	autoword=getIsoValue(auto.data.inputOrigin[i].city.toUpperCase());
		      autoword=autoword.toUpperCase();
		       if (key!=autoword)
		       {
			         auto.data.tips[j]=auto.data.inputOrigin[i]; // aÃ±adimos el tip a partir del dato, se convertirÃ¡ en airportTipToString
			         j+=1;
		       }
	      }       
     }
     document.getElementById(auto.field.id).value=document.getElementById(auto.field.id).value.replace('&ntilde;','\u00f1');
    auto.show();	 // hacer que se muestre el desplegable con los tips
}

/******************************************************************************/
/* @param: tipo , es el objeto autocompletar o el id del form con los datos.
* 
*/

function cargaOficinas(tipo)
{	
	var code = '';
	var city = '';
	var input = '';
	if(typeof tipo == 'object'){
		oTip = tipo;
		code = oTip.code;
		city = getIsoValue(oTip.city);
		input = auto.field.id;
	} else if (typeof tipo == 'string'){
		var form = document.getElementById(tipo);
		code = form.codigo.value;
		city = getIsoValue(form.nombre.value);
		input = form.inputname.value;
	}
	var url = 'http://unsol.es/findoficce.do?codzge=' + code + '&nomzge=' + city;
	var xmldoc = getAjaxObject(url).responseXML;
	var options = dome.Dom.getChildren(dome.Dom.getChild(dome.Dom.getDocumentElement(xmldoc), "options"), 'option');

	if (input == 'inputRC_ofiori'){
		/* Ponemos los option en ambos */
		var ofiori = document.getElementById('sel_ofiori');
		var ofides = document.getElementById('sel_ofides');
		addOptions(ofiori, options);
		addOptions(ofides, options);
		document.getElementById('inputRC_ofiori').value = city;
		document.getElementById('inputRC_ofides').value = city;
	}	else if (input == 'inputRC_ofides'){
		document.getElementById('inputRC_ofides').value = city;
		var ofides = document.getElementById('sel_ofides');
		addOptions(ofides, options);
	}
}

function addOptions(select, options){
	var ofi = new Option('Seleccione oficinas', '', true);
	for (var p = 0; p < select.options.length; p++) select.options[p] = null;
	select.options.length = 0;
	select.options[0] = ofi;
	for (var i = 1; i < options.length; i++){
		var value = dome.Dom.getChildText(options[i], 'value');
		var text = dome.Dom.getChildText(options[i], 'text');
		var op = new Option(text, value);
		select.options[i] = op;
	}
}

function preSelOfiDes(select){
	var idx = select.selectedIndex;
	var selDes = document.getElementById('sel_ofides');
	if (selDes.options.length == select.options.length && selDes.options[idx].value == select.options[idx].value){
		selDes.options[idx].checked = true;
		selDes.selectedIndex = idx;
	}
}

/****************************************************************************************************************************************************************************************************************************/ 
																		/*CONTROL DE DESPEGABLES*/

/****************************************************************************************************************************************************************************************************************************/   	
function buscarCiudad(codtse,style)
{			
	var div = document.getElementById('frameBuscarAeropuertoS');
	//div.src='http://unsol.es/finddestiny.do?codtse=AE&tip=INIT&origen=S';
	
	div.src='http://192.168.1.200/mb/aereoDestinosFrecuentes.html';
	
	setDestinoIframe( 'http://unsol.es/finddestiny.do?tip='+codtse+'&style=' + style);
}				
/*****************************************************************************/
function visualizarHotel(id)
{
	var div = document.getElementById(id);
	div.style.display = 'block';
	div.style.top=175;
	div.style.left=95;				
}					
/*****************************************************************************/
function seleccionarFrameCiudad(id,nom,codtse)
{
	var mini = false;
	var form = document.multibuscador;
	if (form==null)
	{
 		 form = document.minibuscadorHT;
		 if (form) mini=true; 
 	} else {		 
		form.codzge.value = id;
	}
	if(mini)
	{
		document.getElementById('ori_HT').value = nom;
		document.getElementById('oriHT').value = id;		
	}
	else
	{
		var inputArbol = document.getElementById('inputArbol');
		if (inputArbol) inputArbol.value = nom;
		var autht = document.getElementById('autht');
		if (autht) autht.value = id;
		var findoffice = document.getElementById('findoffice');
		if (findoffice){
			findoffice.nombre.value = nom;
			findoffice.codigo.value = id;
			cargaOficinas('findoffice');
		}
	}	
}

/****************************************************************************************************************************************************************************************************************************/ 
																		/*ENVIO DE PARAMETROS*/

/****************************************************************************************************************************************************************************************************************************/   	

/*llamada a la funcion cuando el calendario ya se ha dibujado por primera vez
cambiaFlecha('&lsaquo;', '&rsaquo;',document.getElementById('estructura').nextSibling);
*/

function cambiaFlecha(left, right, oFrom){
	/*
	* Esta funcionalidad esta puesta a pinyon en la libreria de zapatec *
	var from = oFrom;
	if (typeof $ == 'function' && $(".calendar").get()[0]){
		from = $(".calendar").get()[0];
	}

	cambiaFlechaRecursivo(left, right, from);   */

}

function cambiaFlechaRecursivo(left, right, oFrom)
{
	if (oFrom != null)
	{
		if (oFrom.nodeType == 3 && oFrom.nodeValue == left)
		{
			var flecha = document.createElement('img')
			flecha.setAttribute('src', 'http://unsol.es/zapatec/zpcal/themes/unsol/cal_flecha1.gif');
			oFrom.parentNode.appendChild(flecha);
			oFrom.parentNode.removeChild(oFrom);
		}
		if (oFrom.nodeType == 3 && oFrom.nodeValue == right)
		{
			var flecha = document.createElement('img')
			flecha.setAttribute('src', 'http://unsol.es/zapatec/zpcal/themes/unsol/cal_flecha2.gif');
			oFrom.parentNode.appendChild(flecha);
			oFrom.parentNode.removeChild(oFrom);
		}
		else
		{
			if(oFrom.nextSibling != null)
				cambiaFlechaRecursivo(left, right, oFrom.nextSibling);
			if(oFrom.firstChild != null)
				cambiaFlechaRecursivo(left, right, oFrom.firstChild);
			return document.createTextNode('No trobat');
		}
	}
}
/*****************************************************************************/
function estableceCodigo(codigos)
{
	if (codigos[0]==codigos[1])
	{
		if (codigos[0]=='BP')	
		{
			codigos[0]='BI';
			codigos[1]='NO';
		}	
		else if (codigos[0]=='RC')	
		{
			codigos[0]='DC';
			codigos[1]='NO';			
		}
	}
	return codigos;		
}
/****************************************************************************/
//Envio del formulario del mini buscador
function enviarFormHT()
{
	var form=document.minibuscadorHT;
	formId='minibuscadorHT';
	/* si es buscador de costas */
	if (form.autht && form.inputArbol){
		form.ori_HT.value = form.inputArbol.value;
		form.oriHT.value = form.autht.value;
	} 
	if (ValidaForm(formId)) 
	{	
		form.codele.value = 'impbas';
		form.chkasc.value = 'S';
		form.numrst.value = '';
		form.distri.value =  referdistri();  //proceso que devuelve la cadena de la distribucion del hotel
		form.numnoc.value = numnoc;
		if ((hayreguser!='0') && ((form.codtou.value!='SKT') && (form.codtou.value!='EPL')))
		{
			var temp =  getCheckBoxValues('prv_',3);	
			temp=temp.substr(0,temp.length-1);
			form.codtou.value=temp;		
		}	
		if (form.ori_HT.value.length == 3) 
		   form.codzge.value = form.ori_HT.value;
		 else 
		   form.codzge.value = form.oriHT.value;	      
	var categoria = "[*]codsca##";
		if (document.getElementById('selsca').value){
			categoria = "[*]codsca#=#" + document.getElementById('selsca').value;
		}
		filtraHT='impbas##[*]codral##' + categoria + '[*]codzge##[*]codtou##';
		form.filtra.value=filtraHT;
		form.codsca.value = document.getElementById('selsca').value;
		form.fecini.value = form.fecha_orig.value;
		form.fecfin.value = form.fecha_dest.value;
	} else 	return '';		
	form.submit();
}	

/****************************************************************************************************************************************************************************************************************************/ 
																		/*GOOGLEMAPS*/

/****************************************************************************************************************************************************************************************************************************/   	

function showAddress(address, vhotel, zona,sitio,obj) 
{
address =address .replace('Âº',''); 
address =address .replace('Âª',''); 
var  vsitio=sitio+', '+zona;
   var dire = address + ',  ' + zona;
    initialize(obj, dire); /*por defecto se inicializa en madrid , espana*/
     if (geocoder) 
     {
	    geocoder.getLatLng(dire, function(point) 
		{
	        if (!point) /*Por direccion y localidad*/
	        {
				/* Si no encuentra la direccion lo volvemo a intentar con el hotel y la zona*/
				dire =vhotel+','+zona + '  ' + sitio;
				if (geocoder) 
				{
					//alert('buscamos ' + dire);
					/* Llamamos otra vez a la funcion */
					geocoder.getLatLng(dire,  function(point) 
					{
						if (!point)  /*por nombre de hotel ,localidad y ciudad*/						
						{
							dire=vhotel+',' + vsitio;
							geocoder.getLatLng(dire,  function(point) 
							{
									if (!point) 	/*por nombre de hotel , ciudad y localidad*/					
									{
										dire=address+', ' + sitio;
										geocoder.getLatLng(dire,  function(point) 
										{								
											if (!point) 	/* por direccion y ciudad */
											{
												dire=vsitio;
												geocoder.getLatLng(dire,  function(point) 
												{
												if (!point) /*por ciudad y localidad */										
												{
													document.getElementById('titulo').innerHTML = dire + ' No encontrado <br/> Pruebe con el Buscador';										}
												else
												{
													 document.getElementById('titulo').innerHTML = dire;
													  map.setCenter(point, 15);
													  var marker = new GMarker(point);
													  map.addOverlay(marker);																				}
											});
											}
										else
										{
											 document.getElementById('titulo').innerHTML = dire;
											  map.setCenter(point, 15);
											  var marker = new GMarker(point);
											  map.addOverlay(marker);										
										}	
										});	
									}									
									else
									{
											 document.getElementById('titulo').innerHTML = dire;
											  map.setCenter(point, 15);
											  var marker = new GMarker(point);
											  map.addOverlay(marker);
									}
							});
						}
						else
						{
							document.getElementById('titulo').innerHTML = dire;
							  map.setCenter(point, 15);
							  var marker = new GMarker(point);
							  map.addOverlay(marker);
						}		
					});
				/* Fin segunda llamada a la funcion*/
				}
			}
			else 
			{
	            document.getElementById('titulo').innerHTML = dire;
	            map.setCenter(point, 15);
				var marker = new GMarker(point);
				map.addOverlay(marker);
			}
        });
      }
 }	
 /****************************************************************************/				 
function cerrarMapa()
{
	document.getElementById('mapaHotel').style.display='none';
	onGridLoad();	
}
function initialize(obj, zona)
{
	var pos = Zapatec.Utils.getElementOffset(obj);
	var mapa = document.getElementById('googleMaps');
	mapa.style.top=(pos.y - 250).valueOf() + 'px';
	mapa.style.left=(pos.x - 300).valueOf() + 'px';
   	mapa.style.visibility='visible';
      if (GBrowserIsCompatible()) 
      {
	      	  map = new GMap2(document.getElementById("map_canvas"));			        
       	  map.addControl(new GLargeMapControl());
	         map.addControl(new GMapTypeControl());			         
       	  // bind a search control to the map, suppress result list
	          map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
	         geocoder = new GClientGeocoder();			      
       	  geocoder.getLatLng(zona,  function(point) 
       	  {
		      if (!point) 
				map.setCenter(new GLatLng(37.4419, -122.1419), 15);
		     else
		     		  map.setCenter(point, 15);
	});				         
     }
 }
 /***************************************************************************/
 function hideMe(id){
	document.getElementById(id).style.visibility='hidden';
}

/****************************************************************************************************************************************************************************************************************************/ 
																		/*TRATAMIENTO DE LA DISTRIBUCION*/

/****************************************************************************************************************************************************************************************************************************/   	 

/* Miramos el nÂº de adultos que hay seleccionados*/
function getNumAdu(valor) 
{
	var nadu = parseInt(document.getElementById('numadu_' + valor).selectedIndex) + 1;
	return nadu;	
}
/****************************************************************************/
/* proceso que establece la distribucion de la ocupacion de pasajerosque se pasa al refdistri*/		
function referdistri() 
{  
	var distri='';
	var novadistri='';
	var sep = "A"; 					
	var nhabi = document.getElementById('numhab').value;
	if (parseInt(nhabi) == 1) 
		distri = '1' + sep + getNumAdu(nhabi) + getNumNin(nhabi) + getNumBeb(nhabi);
	 else {
		var cont = parseInt(nhabi) + 1;
			for (var i = 1; i < cont; i++) 
			{
				if (i == 1) 
					distri = '1' + sep + getNumAdu(i) + getNumNin(i) + getNumBeb(i);
				 else 
				 {				
					novadistri = '1' + sep + getNumAdu(i) + getNumNin(i) + getNumBeb(i);
					distri += 'D' + novadistri;
				}
			}
		}	
		return distri;
}
/****************************************************************************/
/* Miramos el nÂº de niÃ±os/bebes que hay seleccionados*/
function getNumNin(valor) 
{
     var distriNin ='';	
      var nunmin= document.getElementById('numnin_' + valor).value;
	if (nunmin != '0') 
	{
		  for ( var i = 0; i < nunmin; i++) 
			   distriNin += 'A' + document.getElementById('seled_' + valor + i).value;
      }
     return distriNin;				
}	
/* Miramos el nÂº de niÃ±os/bebes que hay seleccionados*/
function getNumBeb(valor) 
{
     var distriBeb ='';	
   try{
      var nunbeb= document.getElementById('numbeb_' + valor).value;
	if (nunbeb != '0') 
	{
		  for ( var i = 0; i < nunbeb; i++) 
			   distriBeb += 'A1';
      }
      }catch(e){}
     return distriBeb;				
}
/****************************************************************************/
function escribedescripcorta(desc)
{
	var descripcion;
	if (desc.length > 200) 
		descripcion=desc.substring(0,200) + '...';
	 else
		descripcion=desc;
	return descripcion;
}
			
/****************************************************************************************************************************************************************************************************************************/ 
																		/*CONTROL DE NUMEROS*/

/****************************************************************************************************************************************************************************************************************************/   	

function redondear(cantidad, decimales) 
{
	var cantidad = parseFloat(cantidad);
	var decimales = parseFloat(decimales);
	decimales = (!decimales ? 2 : decimales);
	var d=Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);
	return d;
} 	
/****************************************************************************/
/*Extension del proceso de redondeo*/
Number.prototype.round = function(precision) 
{
	   precision = Math.pow(10, precision || 0);
	   return Math.round(this * precision) / precision;
}
			
/****************************************************************************************************************************************************************************************************************************/ 
																		/*CONTROL DE EVENTOS*/

/****************************************************************************************************************************************************************************************************************************/   	

/*Situacion x e y del raton*/
function checkwhere(e) 
{
	if (document.layers)
	{
			xCoord = e.x;
			yCoord = e.y;
			yCoord = e.y;
	}
	else if (document.all)
	{
		xCoord = event.clientX;
		yCoord = event.clientY;
	}
	else if (document.getElementById)
	{
		xCoord = e.clientX;
		yCoord = e.clientY;
	}
}
document.onclick = checkwhere;


/****************************************************************************************************************************************************************************************************************************/ 
																		/*FICHA HOTEL*/

/****************************************************************************************************************************************************************************************************************************/   	

//falta el liscod
function buscar_codser_codtou(id,simbol,lugar_grid)
{
	var hotel_ficha_final='';
	var hotel=id.split('#')[1];
	var hotel_ficha=liscod[hotel];
	var hotel_ficha1=hotel_ficha.split('%')[0];
	var hotel_ficha2=hotel_ficha.split('%')[1];
	hotel_ficha_final +='http://unsol.es/card.do?codser=' + hotel_ficha1+simbol+hotel_ficha2;
	verFicha(hotel_ficha_final,lugar_grid);			
}
/****************************************************************************/		
function verFicha(src,lugar)
{	
	var xCoord2=0;
	var y_med=258/2;
	var x_med=162/2;
   xCoord2=xCoord-170;
	if (lugar==2){
	document.getElementById('ficha').style.top= yCoord + document.body.scrollTop - 260;
	}else if (lugar==1){
	document.getElementById('ficha').style.top= yCoord + document.body.scrollTop - 240;	
	//xCoord2=xCoord-50;				
	}else if (lugar==3){
		document.getElementById('ficha').style.top= yCoord + document.body.scrollTop - 20;	
		  xCoord2=xCoord-200;					
	}else if(lugar==4) {
		document.getElementById('ficha').style.top= yCoord + document.body.scrollTop - 130;	
		//xCoord2=xCoord-70;	
	}else if (lugar==5) {
		document.getElementById('ficha').style.top= yCoord + document.body.scrollTop - 120;	
		//xCoord2=xCoord-70;	
	}else if (lugar==6) {
		document.getElementById('ficha').style.top= yCoord + document.body.scrollTop - 90;	
		//xCoord2=xCoord-50;	
	}
	document.getElementById('ficha').style.left= xCoord2;
	document.getElementById('ficha').src = src;
	document.getElementById('ficha').style.display = '';
}
/****************************************************************************/			
//falta oHoteles
function verubicacion(hotel)
{	
	var src = oHoteles.GetHotelById(hotel).urlimg;
	document.getElementById('ubicacion').style.top= yCoord;
	document.getElementById('ubicacion').style.left= xCoord;
	document.getElementById('ubicacion').src = src;
	document.getElementById('ubicacion').style.display = '';
}
/****************************************************************************/				
function cerrarFicha()
{
	document.getElementById('ficha').style.display = 'none';
	document.getElementById('ubicacion').style.display = 'none';
}
/****************************************************************************/		
function verMapaDesdeFicha(address, vhotel)
{
	cerrarFicha();
	var lugar=3;
	showAddress(address, vhotel,lugar,sitio);
}
/*****************************************************************************/
function estableceResidente(id)
{
	if ((id.name=='aerori')&&(id.value.length >3))       //XISCOSSS
	{
      	        var pais_ida = document.getElementById('autori').value;
	         pais_ida = pais_ida.toUpperCase();
      }
      else if ((id.name=='aerori')&&(id.value.length =='3'))
      { 
	       var pais_ida = document.getElementById('aerori').value;      
      	       pais_ida = pais_ida.toUpperCase();
      }
      else if ((id.name=='aerdes')&&(id.value.length >'3'))
      {
            	   var pais_vta = document.getElementById('autdes').value;
	         pais_vta = pais_vta.toUpperCase();
      }	  
      else if ((id.name=='aerdes')&&(id.value.length =='3'))
      { 
	       var pais_vta = document.getElementById('aerdes').value;      
      	       pais_vta = pais_vta.toUpperCase();
      }
      else if ((id.name=='autori'))
	{
      	        var pais_ida = document.getElementById('autori').value;
	         pais_ida = pais_ida.toUpperCase();
      }
      else if ((id.name=='autdes'))
      { 
	       var pais_vta = document.getElementById('autdes').value;      
      	       pais_vta = pais_vta.toUpperCase();
      }
        for (var i= 0; i < aereoResIB.length; i++) 
        {
	         if (aereoResIB[i] == pais_ida)  
	         return  'BP';
         	  if (aereoResIB[i] == pais_vta) 
      		    return  'BP';
        }
        for (var i= 0; i < aereoResIC.length; i++) 
        {
        	 if (aereoResIC[i] == pais_ida)  
	          return  'RC';
	         if (aereoResIC[i] == pais_vta) 
		          return  'RC';
        } 
        for (var i= 0; i < aereoResCM.length; i++) 
        {
        	 if (aereoResCM[i] == pais_ida)  
	          return  'RM';
	         if (aereoResCM[i] == pais_vta) 
		          return  'RM';
        } 	
       return '';
}
  /*****************************************************************************/
function esNacional(ida,vta)
{
     var okida=0;
     var okvta=0;
	for(var x=0;x<arrNationalAirport.length;x++)
	{
		if (arrNationalAirport[x]==ida)
				okida='1';
		if(arrNationalAirport[x]==vta)		
				okvta='1';
	}
	if ((okida=='1')&&(okvta=='1'))
		return true;
	else
		return false;
}
  /*****************************************************************************/
   /*Miramos si es residente segï¿½ origen el destino*/
   //miramos si es residente segï¿½ origen el destino
   function esResidenteMini(id)
   { 	     
     filtrarSeccion(id);
     var form = document.getElementById(id);
     document.getElementById('resi').style.display='none';
           document.getElementById('resicombinacion').style.display='none';
           document.getElementById('resicombinacion').style.visible='hidden';
     document.getElementById('residente').style.display='none';
     var pais_ida ='';
           var pais_vta=''; 
  if((form.aerori.value.length > 3)&&(form.aerdes.value.length > 3))
  {
      pais_ida = form.autori.value;
      pais_vta = form.autdes.value;
  }
  else  if((form.aerori.value.length > 3)&&(form.aerdes.value.length == '3'))
  {
      pais_ida = form.autori.value;
      pais_vta = form.aerdes.value;
  }   
 	  else  if((form.aerori.value.length == '3')&&(form.aerdes.value.length > 3))
 	  {
      pais_ida = form.aerori.value;
      pais_vta = form.autdes.value;
}
else
{
      pais_ida = form.aerori.value;
      pais_vta = form.aerdes.value;	
}
     pais_ida = pais_ida.toUpperCase();
     pais_vta = pais_vta.toUpperCase();
    if ((pais_ida!='') && (pais_vta!=''))		     
    {
	     if (esNacional(pais_ida,pais_vta))
	     {
		     for (var i =0 ; i<aereoRes.length;i++)
		     {
			      	if (pais_ida==aereoRes[i] || pais_vta==aereoRes[i] )
			      	{
				       document.getElementById('resi').style.display='block';
				       document.getElementById('resicombinacion').style.display='block';
        			               document.getElementById('resicombinacion').style.visible='visible';
					document.getElementById('residente').style.display='block';					       
				       return true;
			      }
		     }
	    }		     
    }	    
     return false;
}

/****************************************************************************************************************************************************************************************************************************/ 
																		/*DIV CARGANDO...*/

/****************************************************************************************************************************************************************************************************************************/   	

/*****************************************************************************/
function HabilitaCargando(valor)
{
	muestraLoading();
}	

function muestraLoading()
{
	var loading = document.getElementById('loading');
	loading.style.display='block';
	loading.style.position = 'absolute'
	loading.style.top = '0px'
	var cue = document.getElementById('cuerpo');
	if (!cue) cue = document.getElementById('cuerpo2');
	var dim;
	if (cue) {dim = Zapatec.Utils.getElementOffset(cue)}
	if (dim ) {loading.style.height = dim.height + 'px'}
	else {loading.style.height = '1200px'}
	
}

function muestraLoadingES()
{
	var loading = document.getElementById('loading');
	loading.style.display='block';
	loading.style.position = 'absolute';
	loading.style.top = '0px';
	loading.style.height = '1200px';
}

function ocultaLoadingES(){
	var loading = document.getElementById('loading');
	loading.style.display='none';
}

/*****************************************************************************/
function visualizar(id)
{
	var div = document.getElementById(id);
	div.style.width = '460';
	div.style.display = 'block';
}
/*******************************************************************************************/
function ocultarIframe(id)
{
	var div = document.getElementById(id);
	div.style.display = 'none';
}
/****************************************************************************/
// Va atenuando el div de "Cargando". El id de este debe ser "loading"
function atenua(opacity)
{
	//window.scrollTo(0,0);
	var object = 	document.getElementById('loading').style;
	if (opacity > 0){
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
		var op = opacity - 5;
		setTimeout("atenua(" + op + ");", 50);
	}
	else{
		object.opacity = (70 / 100);
		object.MozOpacity = (70 / 100);
		object.KhtmlOpacity = (70 / 100);
		object.filter = "alpha(opacity=70)";
		object.display='none';	
	 } 	 
	 precarga=true;	
}
/****************************************************************************/
function cerrarFrame(id){
	document.getElementById(id).style.display='none';
}

/****************************************************************************************************************************************************************************************************************************/ 
																		/*PAGINACION*/

/****************************************************************************************************************************************************************************************************************************/   	

function sendPaginationAE(id)
{
		document.getElementById('paginacion').innerHTML='';
		document.getElementById('paginacion2').innerHTML='';
		document.getElementById('contenedorGrid').innerHTML='';		
		var form =document.getElementById('formPaginaAE');
		form.indpag.value=id;
		var paramspagination=getUrlParams(form);
		var url='http://unsol.es/booking.do?'+paramspagination;
		peticion(url);
		window.scrollTo(0,0);
}   

 /*****************************************************************************/
      	function gotopag(id,tipo){
			if (tipo == 'ES'){
				/*muestraLoadingES();*/
			} else {
				HabilitaCargando(true);
			}
			var npag = id;
			if (tipo=='AE')
				setTimeout("sendPaginationAE(" + npag + ")", 50);
			else if (tipo=='ES')
				setTimeout("sendPaginationES(" + npag + ")", 50);
			else if (tipo=='ESHT')
				setTimeout("sendPaginationESHT(" + npag + ")", 50);
			else	
				setTimeout("sendPaginationHT(" + npag + ")", 50);
      }
/*****************************************************************************/          
             function avpag(id,tipo){
				if (tipo == 'ES'){
				/*muestraLoadingES();*/
				} else {
					HabilitaCargando(true);
				}
              var npag;
              if (parseInt(id) + 9 >= totpag && tipo != 'ES'){
              	  npag = totpag;
              }else{
           	 	  npag = parseInt(id);
             	}
            if (tipo=='AE')
				setTimeout("sendPaginationAE(" + npag + ")", 50);
			else if (tipo=='ES')
				setTimeout("sendPaginationES(" + npag + ")", 50);
			else if (tipo=='ESHT')
				setTimeout("sendPaginationESHT(" + npag + ")", 50);
			else	
				setTimeout("sendPaginationHT(" + npag + ")", 50);
}
/*****************************************************************************/                     
             function repag(id,tipo){
				if (tipo == 'ES'){
				/*muestraLoadingES();*/
				} else {
					HabilitaCargando(true);
				}
				var npag;
				if (parseInt(id) - 9 <=0){
					npag = 0;
				}else{
					npag = parseInt(id)-9;
				}
			if (tipo=='AE')
				setTimeout("sendPaginationAE(" + npag + ")", 50);
			else if (tipo=='ES')
				setTimeout("sendPaginationES(" + npag + ")", 50);
			else if (tipo=='ESHT')
				setTimeout("sendPaginationESHT(" + npag + ")", 50);
			else	
				setTimeout("sendPaginationHT(" + npag + ")", 50);
             }       
/*****************************************************************************/                                  
function sendPaginationHT(id)
{
	document.getElementById('paginacionHT').innerHTML='';
	document.getElementById('paginacionHT2').innerHTML='';
	document.getElementById('contenedorGridHT').innerHTML='';
//		document.getElementById('CabeceraDelGrid').innerHTML='';		
	var form =document.getElementById('formPaginaHT');
	form.indpag.value=id;
	var paramspagination=getUrlParams(form);
	var url = 'http://unsol.es/booking.do?' + paramspagination;
	peticion(url);
	window.scrollTo(0,0);
}         

function sendPaginationESHT(id)
{
	document.getElementById('paginacionHT').innerHTML='';
	document.getElementById('paginacionHT2').innerHTML='';
	document.getElementById('contenedorGridHT').innerHTML='';
//		document.getElementById('CabeceraDelGrid').innerHTML='';		
	var form =document.getElementById('formPaginaHT');
	form.indpag.value=id;
	form.tipser.value='ES';
	var paramspagination=getUrlParams(form);
	var url = 'http://unsol.es/bookingescapadas.do?' + paramspagination;
	peticion(url);
	window.scrollTo(0,0);
}      
 
function sendPaginationES(id){
	/*var form = document.getElementById('formPaginaES');
	form.indpag.value=id;
	form.submit();*/
	var DOMDome = dome.Dom;
	var filter = '';
	var form = document.getElementById("formPaginaES");
	form.indpag.value = id;
	form.filtra.value = filter;
	form.codacc.value = 'DIS';
	var res = getUrlParams(form);
	var url = document.location.href.split('?')[0] + '?' + res;
	var xmldoc = getAjaxObject(url).responseXML;
	/* enganchamos los hoteles en su sitio */
	var response = DOMDome.getChildText(DOMDome.getDocumentElement(xmldoc), "tablaHoteles");
	document.getElementById("contenedorGridHT").innerHTML = response;

}
 
/****************************************************************************************************************************************************************************************************************************/ 
																		/*PETICION AJAX*/

/****************************************************************************************************************************************************************************************************************************/   	
	/* Hace una peticion ajax sincrona, y devuelve el objeto*/
  var xmlhttp;	
function getAjaxObject(url){
  var xmlhttp=false;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
      xmlhttp = new XMLHttpRequest();
  } else if (window.ActiveXObject) { // IE
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
		/* se hace la peticion sincrona para que pare la ejecucion del programa hasta que se obtenga la respuesta */
		xmlhttp.open("GET", url, false);
		xmlhttp.send(null);
		return xmlhttp;
	}
	/**********************************************************************/

   function peticion(url)
   {
  xmlhttp=false;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
      xmlhttp = new XMLHttpRequest();
  } else if (window.ActiveXObject) { // IE
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  // se hace la peticion sincrona para que pare la ejecucion del programa hasta que se obtenga la respuesta 
  xmlhttp.onreadystatechange=function() {
   try {
    if (xmlhttp.readyState==4) 
     return xmlhttp;
   } catch  (e) {
    alert(e.message + ' ' + e.type);
   }
  }
  xmlhttp.open("GET", url, false);
  xmlhttp.send(null);
  //return xmlhttp;
 mostrarMensaje();
 }
/*****************************************************************************/       
  function mostrarMensaje()
  {
		var xmldoc = xmlhttp.responseXML;
		var  tipo=DOMDome.getChildText(DOMDome.getDocumentElement(xmldoc), "tiposer");
		var obj='';
		if (tipo=='AE')
			obj = document.getElementById("contenedorGrid");
		else if(tipo=='RC')	   
			obj = document.getElementById("contenedorGridRC");
		else
			obj = document.getElementById("contenedorGridHT");
		obj.innerHTML =DOMDome.getChildText(DOMDome.getDocumentElement(xmldoc), "gridHtml");
		newidetra=DOMDome.getChildText(DOMDome.getDocumentElement(xmldoc), "idetra");	   
		atenua(70);
		if (tipo=='AE')
			setTimeout('initZapatec()',1000);
}   
/*****************************************************************************/  
  function getUrlParams(obj) {
      var getstr = "";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") 
         {
            if (obj.childNodes[i].type == "text" || obj.childNodes[i].type == "hidden") 
               getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
	   }
	  } 
	 return getstr;
   }
/*****************************************************************************/     
function resetFilter(tipo)
{
	var form='';
	  if (tipo=='AE')
	  {
			document.getElementById('contenedorGrid').innerHTML='';
		 	form= document.getElementById('formFiltraAE');
	  }	 	
	  else
	  {
			document.getElementById('contenedorGridHT').innerHTML='';		
		 	form= document.getElementById('formFiltraHT');
	  }
	if (tipo =='AE')
		form.filtra.value=filtraAE;          
	else	 
		form.filtra.value=filtraHT;          
	var params =getUrlParams(form); 
	var url='http://unsol.es/booking.do?'+params;
	peticion(url);	  		 	
	if (tipo=='AE')
	{
			document.getElementById('paginacion').innerHTML='';
			document.getElementById('paginacion2').innerHTML='';
	}
	else
	{		
			document.getElementById('paginacionHT').innerHTML='';
			document.getElementById('paginacionHT2').innerHTML='';
//			document.getElementById('CabeceraDelGrid').innerHTML='';
	}		
}
/*****************************************************************************/     
function getCheckBoxChecked(param,num)
{
	var arrValues='';
	var combo= '';
	for(var x=0 ; x<num;x++)
	{
		combo =param + x;
		arrValues +=document.getElementById(combo).checked+'#';
	}			
	return arrValues;
}
/*****************************************************************************/     
function getCheckBoxValues(param,num)
{
	var arrValues='' ;
	var combo= '';
	for(var x=0 ; x<num;x++)
	{
		combo =param + x;
		if (document.getElementById(combo).checked)
				arrValues +=document.getElementById(combo).value+'#';
	}			
	return arrValues;
}
/*****************************************************************************/     
function formatNumber(num){
	var strNum;
	if (typeof(num) == 'number'){
		strNum = num.toFixed(2).toString();
	} else {
		strNum = num;
	}
	var sepDec;
	var sepMil;
	var ent;
	var dec;
	if (strNum.length - (strNum.lastIndexOf(',') + 1) == 2){
		sepDec = ',';
		sepMil = '.';
	}
	else if (strNum.length - (strNum.lastIndexOf('.') + 1) == 2){
		strNum = strNum.replace('.',',');
		sepDec = ',';
		sepMil = '.';
	}	
	dec = strNum.substring(strNum.lastIndexOf(sepDec) + 1, strNum.length);
	ent = strNum.substring(0, strNum.lastIndexOf(sepDec));
	
	
	return addSepMil(ent, sepMil) + sepDec + dec;
}
/*****************************************************************************/     
function addSepMil(ent, sep){
	if (ent.length < 4) return ent;
	var ent1 = ent.substring(0, ent.length - 3);
	var ent2 = ent.substring(ent.length - 3, ent.length);
	if (ent1.length < 4){
		return ent1 + sep + ent2;
	} else {
		return addSepMil(ent1, sep) + sep + ent2;
	}
}

function toProperCase(s){
  var str = s.toLowerCase().replace(/^(.)|\s+(.)|-(.)/g, 
		  function($1) { return $1.toUpperCase(); });
	str = str.replace(/\s(Y)\s/g, 
		  function($1) { return $1.toLowerCase(); });
	return str
}

   
