var siteLoaded = true;
var IE='\v'=='v';
var ie6='\v'=='v';
var posicX = 0;var posicY = 0;
var timeOut;
var timeoutimage;

jQuery(document).ready(function(){ 
  startImageHeader();	
}).mousemove(function(e){
     posicX = e.pageX;
     posicY = e.pageY;
     if (posicX < 0) {posicX = 0}; 
	 if (posicY < 0) {posicY = 0};
   }); 

function wrapInQuotes(oRegExp,sString)
{
	if(oRegExp.test(sString))
	{
		var aItems = sString.split(",");
		var aux = [];
		var keyword;
		for(var nItem = 0, nItems = aItems.length; nItem < nItems; nItem++)
		{
			keyword = aItems[nItem];
			if(oRegExp.test(keyword))
			{
				keyword = "'"+keyword+"'";
			}
			aux.push(keyword);
		}
		
		sString = aux.join(","); 
	}
	return sString;
}
function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}


function loadPOIPartnerData(label,ID_POI){
jQuery.ajax({
		   type: "POST",
		   url: "/util/async_poipartnerdata.php5",
		   data: "ID_POI="+ID_POI+'&label_id='+label,
		   success: function(msg){
		    	jQuery('#'+label).data('loaded',true).html(msg);
		   }
		 });
}
		

function invertir (elem, indice)
{
	// Contador de elementos de menu
	count = 0;
	while (document.getElementById(elem +"[" + (++count) + "]"));

	for (x = 0; x < count; x++)
	{		
		style = document.getElementById(elem + "[" + x + "]").style;
		style.display = 'none';
		style.visibility = "hidden";
	}
	style = document.getElementById(elem + "[" + indice + "]");		
	if (style == null) return;
	style.style.display = 'block';
	style.style.visibility = "visible";
}

function imprimir (id)
{
	var ficha = document.getElementById (id);
	var date = new Date();

	width = 800;
	height = 600;
	left = Math.floor((screen.width - width) / 2);
	tope  = Math.floor((screen.height - height) / 2);

	var win = window.open(' ', 'popup', 'left=' + left + ' top=' + tope + ' width=' + width + ' height=' + height);
	win.document.writeln ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
	win.document.writeln ('<html>');
	win.document.writeln ('<head>');
	win.document.writeln ('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">');
	win.document.writeln ('<link href="css/css.css" rel="stylesheet" type="text/css">');
	win.document.writeln ('<link href="css/calendar.css" rel="stylesheet" type="text/css">');
	win.document.writeln ('</head>');
	win.document.writeln ('<body topmargin="0" leftmargin="7" style="background-color:#FFFFFF">');
	win.document.writeln ('<table width="900" height="80" border="0" cellpadding="0" cellspacing="0">');
	win.document.writeln ('<tr>');
	win.document.writeln ('<td width="296" align="center" valign="middle">');
	win.document.writeln ('<img src="images/logodark.gif" alt="home" width="262" height="38" border="0">');
	win.document.writeln ('</td>');
	win.document.writeln ('<td align="right">&nbsp;</td>');
	win.document.writeln ('</tr>');
	win.document.writeln ('<tr>');
	win.document.writeln ('<td colspan="2" style="font-family: verdana; font-size: 16px; font-weight: bold">' + date + '</td>');
	win.document.writeln ('</tr>');
	win.document.writeln ('</table>');
	win.document.write( ficha.innerHTML );
	win.document.writeln ('<table width="900" height="80" border="0" cellpadding="0" cellspacing="0">');
	win.document.writeln ('<tr>');
	win.document.writeln ('<td colspan="2" style="font-family: verdana; font-size: 16px; font-weight: bold">' + date + '</td>');
	win.document.writeln ('</tr>');
	win.document.writeln ('</table>');
	win.document.writeln ('</body>');
	win.document.writeln ('</html>');
	win.document.close();
	win.print( );
	win.close();
} 

function rollover (text)
{
	/* Primero se averigua si ya existe un rollover activo, en caso afirmativo se elimina */
	if (obj = document.getElementById('rolloverDiv'))
		obj.parentNode.removeChild(obj);

	var obj = document.createElement ('div');
	
	var correct = 0;
	if(document.all) correct = document.documentElement.scrollTop;
	if(correct > 0) finalPosY = posicY+correct; else finalPosY = posicY;
	
	obj.setAttribute ('id', 'rolloverDiv');
	obj.className = 'rollover';
	obj.innerHTML = text;
	obj.style.left = posicX+'px';
	obj.style.top = finalPosY+'px';
	document.body.appendChild (obj);
}

function killRollover ()
{
	/* Primero se averigua si ya existe un rollover activo, en caso afirmativo se elimina */
	if (obj = document.getElementById('rolloverDiv'))
		obj.parentNode.removeChild(obj);
}
function clickRollover (day, month, year, ttit, tini, tfin)
{
	killRollover();
	tini = tini.replace(':','');
	tfin = tfin.replace(':','');
	/* Primero se averigua si ya existe un rollover activo, en caso afirmativo se elimina */
	if (obj = document.getElementById('clickRolloverDiv'))
		obj.parentNode.removeChild(obj);
	
	if(day < 10 && day.length < 2 )
		day = '0'+day;
	if(month < 10 && month.length < 2)
		month = '0'+month;

	// Generamos la capa
	var obj = document.createElement ('div');
	obj.setAttribute ('id', 'clickRolloverDiv');
	obj.className = 'clickRollover';
	
	var correct = 0;
	
	if(document.all) correct = document.documentElement.scrollTop;
	if(correct > 0) finalPosY = posicY+correct; else finalPosY = posicY;
	obj.style.left = posicX+'px';
	obj.style.top = finalPosY+'px';
	document.body.appendChild (obj);

	var objClose = document.createElement ('div');
	objClose.className = 'closeRollover';
	objClose.innerHTML = '<table cellpadding="0" cellspacing="0" width="100%"><tr><td width="95%">'+ttit+'</td><td width="10%" align="right" valign="top"><a href="javascript:;" onclick="killClickRollover();"><img border="0" src="/images/ico_close.gif"></a></td></tr></table>';

	// A�adimos texto de entrada
	var tiniObj = document.createElement ('div');
	tiniObj.onclick = function () {killClickRollover('fini', day, month, year)};
	tiniObj.className = 'rollOverButton_ini';
	tiniObj.innerHTML = '<img src="/images/seta2.gif"> '+tini;

	// A�adimos texto de salida
	var tfinObj = document.createElement('div');
	tfinObj.innerHTML = tfin+' <img src="/images/seta1_1.gif">';
	tfinObj.className = 'rollOverButton';
	tfinObj.onclick = function () {killClickRollover('ffin', day, month, year)};
	
	document.getElementById('clickRolloverDiv').appendChild (objClose);
	document.getElementById('clickRolloverDiv').appendChild (tiniObj);
	document.getElementById('clickRolloverDiv').appendChild (tfinObj);
}

function killClickRollover (text, day, month, year)
{
	if (text == 'fini') {
		document.getElementById('varR_IDIA').value = day;
		document.getElementById('varR_IMERGE').value = year+'-'+month;
		mergeDates();
	} else if (text == 'ffin') {
		document.getElementById('varR_FDIA').value = day;
		document.getElementById('varR_FMERGE').value = year+'-'+month;
		mergeDatesFin();
	}
	
	/* Primero se averigua si ya existe un rollover activo, en caso afirmativo se elimina */
	if (obj = document.getElementById('clickRolloverDiv'))
		obj.parentNode.removeChild(obj);
}


var imageWin
var cont=0

function popUpImage(url)
{
	if(cont==1){imageWin.close();imageWin=null}
	imageWin=window.open('','imageWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes')
	imageWin.document.write('<html><head><title>OH BARCELONA</title></head><body onclick="javascript:window.close()" style="" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="yes" onUnload="opener.cont=0"><a href="#"><img src="' + url + '" onLoad="opener.resize(this.width - 2, this.height - 15);" onClick="opener.destroy();" border=0;></a>')
	imageWin.document.close()
	cont++
}

function resize(w,h)
{
    if (w < screen.width) {
	   imageWin.resizeTo(w + 35,h + 60)
	   imageWin.moveTo((screen.width-w)/2,(screen.height-h)/2) //centra la imageWin. Eliminar si no se quiere centrar el popup
	} else {
	   imageWin.resizeTo(screen.width - 100, screen.height - 200);
	} 
}

// Funcion que comprueba si el email es valido o no
function checkEmail(obj)
{
	email = obj.value;
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.@";
	var ok = "yes";
	var temp;
	var arroba = 0;
	var punto = 0;
	for (var i=0; i<email.length; i++) 
	{
		temp = "" + email.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
		if (temp == "@") arroba++;
		if (temp == ".") punto++;
	}
	if ((ok == "no") || (arroba != 1) || (punto < 1))
	{
		//alert("'" + email + "' is an invalid e-mail address");
		//obj.focus();
		//obj.select();
		return false;
	}
	return true;
}

// Funcion que comprueba si es un numero real o no
function checkNumber(obj)
{
	number = obj.value;
	
	var valid = "0123456789,.";
	var ok = true;
	var temp;
	var decimal = 0;
	for (var i=0; i<number.length; i++) 
	{
		temp = "" + number.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = false;
		if ((temp == ".") || (temp == ",")) decimal++;
	}
	if (!ok || (decimal > 1))
	{
		alert("'" + number + "' is an invalid number");
		obj.focus();
		obj.select();
	}
	return false;
}

// Funcion que comprueba si es un numero entero o no
function checkInt(obj)
{
	number = obj.value;
	
	var valid = "0123456789";
	var ok = true;
	var temp;
	for (var i=0; i<number.length; i++) 
	{
		temp = "" + number.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = false;
	}
	if (!ok)
	{
		alert("'" + number + "' is an invalid integer number");
		obj.focus();
		obj.select();
		return false;
	}
	return true;
}

function agregarFavoritos()
{
	if ((IE) && (parseInt(navigator.appVersion)>=4)) {
      	var url="http://www.oh-barcelona.com";
      	var titulo="Barcelona: Accommodation, Spanish Course";
      	window.external.AddFavorite(url,titulo);
   	}
   	else {
      	if(navigator.appName == "Netscape")
        	window.sidebar.addPanel("Barcelona: Accommodation, Spanish Course","http://www.oh-barcelona.com","");
	} 
}

function merge(obj, var1, var2, idia, fdia, fmerge, fmes, fany)
{
	var date = new Array();
	date = obj.value.split("-");
	var1.value = date[0];
	var2.value = date[1];
	
	date = fmerge.value.split("-");
	fmes.value = date[1];
	fany.value = date[0];
	
	if(idia) chkDate(idia, obj, fdia, fmerge, fmes, fany);
}
			
function chkDate(var1, var2, var3, var4, var5, var6)
{
	date1 = var2.value.split("-");
	date2 = var4.value.split("-");

	fecha1=new Date(date1[0], date1[1]-1, var1.value);
	fecha2=new Date(date2[0], date2[1]-1, var3.value);

	if(fecha2<fecha1){
		fin = new Date(fecha1.getTime()+(24*60*60*3*1000));
		year = fin.getFullYear();
		month = fin.getMonth()+1;
		day = fin.getDate();
		if(month < 10) month='0'+month;
		if(day < 10) day='0'+day;
		var3.value = day;
		var4.value = year+'-'+month;
		var5.value = month;
		var6.value = year;
	}
}

function alert_decode (str)
{           
	alert(str);
}

function checkFlag(id)
{	
	var element = 'check_' + id;
	if (document.getElementById(element).checked)
	{
		document.getElementById(id).value = 'yes';
	}
	else
	{
		document.getElementById(id).value = 'no';
	}
}

	function xHeight(e,uH) {
	  if(!(e=$(e)) || (uH && uH<0)) return 0;
	  uH=Math.round(uH);
	  var css=xDef(e.style);
	  if(css && xDef(e.style.height,e.offsetHeight) && typeof(e.style.height)=="string") {
		if(arguments.length>1) xSetCH(e, uH);
		uH=e.offsetHeight;
	  }
	  else if(css && xDef(e.style.pixelHeight)) {
		if(arguments.length>1) e.style.pixelHeight=uH;
		uH=e.style.pixelHeight;
	  }
	  else if(xDef(e.clip) && xDef(e.clip.bottom)) {
		if(arguments.length>1) e.clip.bottom=uH;
		uH=e.clip.bottom;
	  }
	  return uH;
	}
	
	function xDef() {
	  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=="" || typeof(arguments[i])=="undefined") return false;}
	  return true;
	}

	function $(e) {
		return document.getElementById(e);
	}
	
	//Simulacion de trim para javascript
function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}
	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}	
	return cadena;
}				
	
	function SetearCookie(cookieName,cookieValue,nDays) {
		var today = new Date();
		var expire = new Date();
		if (nDays==null || nDays==0) nDays=1;
		expire.setTime(today.getTime() + 3600000*24*nDays);
		document.cookie = cookieName+"="+escape(cookieValue)
	                 + ";expires="+expire.toGMTString()+";path=/";
	}

	function showWaiter(x,y){			
		if(IE) changeSelects('hidden');
		jQuery("#CONTAINER_WAITER").show();
	}
	
	function changeSelects(mode){
		var selects = document.getElementsByTagName('select');
		for(x=0;x<selects.length;x++){
			selects[x].style.visibility = mode;
		}
	}
	
	var saleOffice = new popDiv('saleOffice');
	function showSaleOffice(){
		saleOffice.show('.SELECTSO','msg',220,false,'searchButton',-50,-235,true,false,true,false,'','')
	}
	
	function hideLoader(){
	hideMsg();
	}

	var blockTimeout;
	function hideMsg(){
		jQuery('.blockUI').remove().fadeOut().remove();
	}

		function setCookieLang(nompais){
			jQuery('varM_PAIS_ORIGEN').value=nompais;
			SetearCookie('PAIS_ORIGEN',nompais,30);			
			boton=jQuery('searchButton').href.replace('javascript:search','').substr(0,3);	
			saleOffice.hide();	
			
			if (boton=='Hot')
				searchHot('SEARCHO');
				
			else if (boton=='Alo')
				searchAlo('SEARCH');
				
			else if (boton=='htt')
				asignarParams('AVAIL', 'CALCPRECIOS');	
				
			else if (boton=='Aja'){
				document.body.style.cursor = 'wait';
				jQuery('ajax_price_container').innerHTML ='<img src="/images/loadinfo.gif" align="absmiddle">';
				searchAjaxPrice(jQuery('parAL_REF').value,'popup');
			}
			document.body.style.cursor = '';				
		}		

		   
		   function searchAjaxPrice(ref,popup) 
		   {
		   		jQuery('showCalText').style.visibility = 'visible';
				if (document.OH.varM_PAIS_ORIGEN.value != "") {
					document.OH.parAL_REF.value = ref;
					document.getElementById('calendar_container').style.display = "none";
					document.getElementById('ajax_price_container').style.display = "block";
					if (popup=='popup')
						syncreload('RECALCPRICE', 'ajax_price_container');
					else if (popup=='nopopup')
						reload('RECALCPRICE', 'ajax_price_container');
				} else {
					showSaleOffice();
				}	
		   }
		   
		   function findPos3(obj){				
				    x=0; y=0; var el,temp;
					if(typeof obj == "string")
					{
						el = $(obj);
					}else
					{
						el = obj;
					}
				   	
					if(el.offsetParent){
				      temp = el
				      while(temp.offsetParent){ //Looping parent elements to get the offset of them as well
				        temp=temp.offsetParent; 
				        x+=temp.offsetLeft
				        y+=temp.offsetTop;
				      }
				    }
				    x+=el.offsetLeft
				    y+=el.offsetTop				  
				  return [x,y]
				}
				
				
		var newwindow = '';
		function popWin(url,centered,pwidth,pheight) {
			if (pwidth=="")pwidth=450;
			if (pheight=="")pheight=120;
		    if (centered==true){
			    var winl = (screen.width-pwidth)/2;
			    var wint = (screen.height-pheight)/2;
			    if (winl < 0) winl = 0;
			    if (wint < 0) wint = 0;
			    pos='top=' + wint + ',';
			    pos+= 'left=' + winl + ',';
		    }else pos='';
		    if (!newwindow.closed && newwindow.location) {
		        newwindow.location.href = url;
		    }
		    else {
		        newwindow=window.open(url,'SELLANG',pos+'height='+pheight+',width='+pwidth+',location=no,titlebar=yes,toolbar=no,status=no');
		        if (!newwindow.opener) newwindow.opener = self.window;
		    }
		    if (window.focus) {newwindow.focus()}
		    return false;
		}
	
	function showHide(){ 
	    var i, visStr, obj, args = showHide.arguments;
	    if ((obj = $(args[0])) != null) {
	        if (obj.style)   {
	            obj = obj.style;
	            if(args[1] == 'hidden'){ 
	                obj.visibility  = args[1];
	                obj.display     = 'none';
	            }else if(args[1] == 'visible'){ 
	                obj.visibility = args[1];
	                obj.display = 'block';
	            }
	        }
	    }
	}
		
	function findPos(num){				
	    x=0; y=0; var el,temp;
	    el =$("menu"+num);
	    if(el.offsetParent){
	      temp = el
	      while(temp.offsetParent){ //Looping parent elements to get the offset of them as well
	        temp=temp.offsetParent; 
	        x+=temp.offsetLeft
	        y+=temp.offsetTop;
	      }
	    }
	    x+=el.offsetLeft
	    y+=el.offsetTop				  
	  return [x,y]
	}
	
//TOOLTIP

	function tooltip_show(tooltipId,  num)
	{
	     if(siteLoaded == true){
		    it = $(tooltipId);
		    img =jQuery('offer_'+num);
		   
		    it.innerHTML= jQuery('offers_'+num).innerHTML ;
	
		    // need to fixate default size (MSIE problem)
		    if (it.style.visibility != 'visible'){
		       it.style.width = it.offsetWidth + 'px';
		       it.style.height = it.offsetHeight + 'px';
		     }
		    posicion=findPos(num);	    		   
		    if(x<0) x = 0;	
		   
		    it.style.top = ((y+18)) + 'px';
		    it.style.left =(x) + 'px';	
			
		    if (it.innerHTML!=''){
		       it.style.visibility = 'visible';
		     }
		} 
	    
	}
	function findPosOfObj(obj) {
	    var curleft = curtop = 0;
	    if (obj.offsetParent) {
	        do {
	            curleft += obj.offsetLeft;
	            curtop += obj.offsetTop;
	        } while (obj = obj.offsetParent);
	    }
	    return [curleft,curtop];
	}
	
	function is_inside(what){
		obj=$(what);
		
		posicion=findPosOfObj(obj);
		
		x_inicial=posicion[0];
		x_final=x_inicial+obj.offsetWidth;       
		y_inicial=posicion[1];
		y_final=y_inicial+obj.offsetHeight;
			
		if (IE) {
	        margen=1;        
	    } else {
	    	margen=3;    	
	    }
	    
		if ((posicY < y_inicial-1) || (posicX < x_inicial+margen) || (posicY+margen > y_final) || ( posicX+margen > x_final ) ){
	        return false;
	    }else{ 
	    	return true;
	    }
		
		  
	
	}
					
	function tooltip_timer_hide(id){
		timeOut=setTimeout('tooltip_hide(\''+id+'\')', 500);
	}
	
	var tooltipInterval = '';
	function tooltip_hide2(){
		if (jQuery('tooltip').style.visibility!='hidden')	
		if (!is_inside('tooltip')){	
			tooltip_hide('tooltip');
			clearInterval(tooltipInterval);
		}
	}
	
	function tooltip_hide(id)
	{
		 if(siteLoaded == true){	       
	       it=$(id);
	       it.style.visibility = 'hidden';
	       
	       it.style.width='';
	       it.style.height='';
	       it.innerHTML=''; 
	      
	      }     
	}
	
function showMaps(){									
						showFullMap();loadMaps();
						showHide('showMapZone','hidden');
						showHide('loadingMaps','visible');				
}
			
function add2Shortlist(ref,product_type,btnImg){

	 jQuery.ajax({
		   type: "POST",
		   url: "/util/manageShortlist.php5",
		   data: "action=add&ref="+ref+"&product_type="+product_type,
		   success: function(msg){
		     updateShortlist(msg);
		     jQuery('#'+btnImg).attr('src','/images/ico_shortlist_sel_'+(jQuery('#CTLLang').val()).toLowerCase()+'.gif').attr('title','').attr('onclick','');
		     showMsg();
		    
		   }
		 });
}
function updateShortlist(msg){
	jQuery('#shortlistTotal,#shortlistTotal2').html(msg);
	if(msg==0){
		 jQuery('#shortlist-img').attr('src','/images/ico_shortlist_top_dis.png');
	}else if(msg==1){
		jQuery('#shortlist-img').attr('src','/images/ico_shortlist_top.gif');
	}
}

function removeFromShortlist(ref){
 jQuery.ajax({
	   type: "POST",
	   url: "/util/manageShortlist.php5",
	   data: "action=remove&ref="+ref,
	   success: function(msg){
	     updateShortlist(msg);
	     jQuery('#item'+ref).remove();
	     if(msg==0){
		     jQuery('#msgNoShortlist').fadeIn();
		     jQuery('#msgShortlist').fadeOut();
		 }
	   }
	 });
}	

var blockTimeout;
function hideMsg(){
	jQuery('.blockUI').fadeOut().remove();
}
function showMsg(msg){
 			jQuery.blockUI({showOverlay: false,  message: '<span class="black" style="font:16px Arial;font-weight:bold"><img src="/images/ico-ok.gif" class="middle">&nbsp;'+tradStart.add2Shortlist+'</span><div class="v-sp">&nbsp;</div><input type="button" value="aceptar" onclick="hideMsg()">' });
}

	function readLinked() { 
			
			if(this.id == 'day-arrival'){
			var arYearMonth = String(jQuery("#varR_IMERGE").val()).split('-');	
			var fecha =  arYearMonth[1] + "-" + jQuery("#varR_IDIA").val() + "-" +  arYearMonth[0];
			}else{
			var arYearMonth = String(jQuery("#varR_FMERGE").val()).split('-');
			var fecha = arYearMonth[1] + "-" + jQuery("#varR_FDIA").val() + "-" +  arYearMonth[0];	
			}
		    jQuery("#"+this.id).val(fecha); 
		    return {};
	} 
					 
	// Update three select controls to match a date picker selection 
	function updateLinked(date) { 
	    if(this.id == 'day-arrival'){
		    updateDateIni(date,true);
	    }else{
		    updateDateFin(date);
	    }								    
	}
	
	function updateDateIni(date)
	{
			jQuery("#varR_IDIA").val(date.substring(3, 5)); 
		    jQuery("#varR_IMES").val(date.substring(0, 2));
		    jQuery("#varR_IANY").val(date.substring(6, 10));
		    jQuery("#varR_IMERGE").val(date.substring(6, 10)+'-'+date.substring(0, 2));	
		     chkDateIni();
	}
	
	function updateDateFin(date){
	 		jQuery("#varR_FMERGE").val(date.substring(6, 10)+'-'+date.substring(0, 2));	
		    jQuery("#varR_FDIA").val(date.substring(3, 5)); 
		    jQuery("#varR_FMES").val(date.substring(0, 2));
		    jQuery("#varR_FANY").val(date.substring(6, 10));
	}

var accomodationDataTimeout=false;
function loadAccomodationDataTimeout(id,id_item,ref,cod_item,from_search){
jQuery.ajax({
		   type: "POST",
		   url: "/util/async_accomodationdata.php5",
		   data: "ref="+ref+"&cod_item="+cod_item+"&id_item="+id_item+"&label_id="+id+"&from_search="+from_search,
		   success: function(msg){
		    	jQuery('#'+id).data('loaded',true).html(msg);
		    	jQuery('#'+id+' .tooltip_desc').tooltip({showURL: false});   
		   }
		 });
accomodationDataTimeout=false;;
}

function loadAccomodationData(id,id_item,ref,cod_item,from_search)
{
	if(accomodationDataTimeout)
		clearTimeout(accomodationDataTimeout);
	if(!jQuery('#'+id).data('loaded')){
		accomodationDataTimeout =  setTimeout('loadAccomodationDataTimeout("'+id+'","'+id_item+'","'+ref+'","'+cod_item+'","'+from_search+'")',200);
	}else{
		loadAccomodationDataTimeout(id,id_item,ref,cod_item,from_search)
	}
}		

var POIDataTimeout=false;
function loadPOIData(label,ID_POI,cod_item,a_cat,from_search){
jQuery.ajax({
		   type: "POST",
		   url: "/util/async_poidata.php5",
		   data: "ID_POI="+ID_POI+"&cod_item="+cod_item+"&a_cat="+a_cat+"&label_id="+label+"&from_search="+from_search,
		   success: function(msg){
		    	jQuery('#'+label).data('loaded',true).html(msg);
		    	jQuery('#'+label+' .tooltip_desc').tooltip({showURL: false});   
		   }
		 });
POIDataTimeout=false;;
}

var intervalLoadDatesAP = null;

function loadDatesAP(lang){	
		var endday  =  	new Date(); 
		var endday 	= 	new Date(endday.setDate(endday.getDate()+548));
		var startday  =  new Date(); 
		var startday 	= new Date(startday.setDate(startday.getDate()+1));
		
		var today 	= new Date();
		  
		  
		if(typeof jQuery.fn.datepicker == "undefined")
		{
			intervalLoadDatesAP = setInterval(function(){
				if(typeof jQuery.fn.datepicker != "undefined")
				{
					clearInterval(intervalLoadDatesAP);
					createDatePicker();
				}
			},200);
		}else
		{
			createDatePicker();
		}
		function createDatePicker()
		{
			jQuery("#day-arrival, #day-departure").datepicker(jQuery.extend({}, 
				{ 
				    dateFormat: "mm-dd-yy", 
				    duration: "", 											    
				    minDate: startday, 
				    firstDay: 1,
			        changeFirstDay: false, 
		    		maxDate: endday, 
				    defaultDate: startday,
		    		beforeShow: readLinked, 
		    		onSelect: updateLinked, 
		    		numberOfMonths: 2,
					showButtonPanel: true,		    		
				    showOn: "both",											    
				    buttonImage: "/images/calendar_icon.gif", 
				    buttonImageOnly: true,
				    maxDate: '+1y'
				})); 
		}
            
	} 
	
	function updateDatesHotel(){
	
	var arYearMonthIni = String(jQuery("#varR_IMERGE").val()).split('-');	
	var arYearMonthFin = String(jQuery("#varR_FMERGE").val()).split('-');
	
	updateDateIni(arYearMonthIni[1]+'-'+jQuery("#varR_IDIA").val()+'-'+arYearMonthIni[0]);		
	updateDateFin(arYearMonthFin[1]+'-'+jQuery("#varR_FDIA").val()+'-'+arYearMonthFin[0]);	
	
	var iDia = jQuery("#varR_IDIA").val();
	var iMes = jQuery("#varR_IMES").val();
	var iAnyo= jQuery("#varR_IANY").val();
	
	var fDia = jQuery("#varR_FDIA").val();
	var fMes = jQuery("#varR_FMES").val();
	var fAnyo= jQuery("#varR_FANY").val();
	
	mergeDates();
	mergeDatesFin();
	
	if(!valFechas(iDia, arYearMonthIni[1], arYearMonthIni[0], fDia, arYearMonthFin[1], arYearMonthFin[0])){
		return false;
	}else{
			jQuery("#varR_HIDIA").val(iDia); 
		    jQuery("#varR_HIMES").val(iMes);
		    jQuery("#varR_HIANY").val(iAnyo);		    
		    jQuery("#varR_HIMERGE").val( jQuery("#varR_IMERGE").val());	
			jQuery("#varR_HFMERGE").val(jQuery("#varR_FMERGE").val());	
		    jQuery("#varR_HFDIA").val(fDia); 
		    jQuery("#varR_HFMES").val(fMes);
		    jQuery("#varR_HFANY").val(fAnyo);
		return true;
	}
	}
	function mergeDates(){
	
	if(jQuery('#varR_IDIA').attr('id') == 'varR_IDIA')
	merge(
		document.getElementById('varR_IMERGE'), 
		document.getElementById('varR_IANY'), 
		document.getElementById('varR_IMES'), 
		document.getElementById('varR_IDIA'), 
		document.getElementById('varR_FDIA'), 
		document.getElementById('varR_FMERGE'), 
		document.getElementById('varR_FMES'), 
		document.getElementById('varR_FANY')
	);
	
	if(jQuery('#varR_HIDIA').attr('id') == 'varR_HIDIA')
	merge(
		document.getElementById('varR_HIMERGE'), 
		document.getElementById('varR_HIANY'), 
		document.getElementById('varR_HIMES'), 
		document.getElementById('varR_HIDIA'), 
		document.getElementById('varR_HFDIA'), 
		document.getElementById('varR_HFMERGE'), 
		document.getElementById('varR_HFMES'), 
		document.getElementById('varR_HFANY')
	);
	}
	function mergeDatesFin(){
	if(jQuery('#varR_IDIA').attr('id') == 'varR_IDIA')
	merge(
		document.getElementById('varR_IMERGE'), 
		document.getElementById('varR_IANY'), 
		document.getElementById('varR_IMES'), 
		document.getElementById('varR_IDIA'), 
		document.getElementById('varR_FDIA'), 
		document.getElementById('varR_FMERGE'), 
		document.getElementById('varR_FMES'), 
		document.getElementById('varR_FANY')
	);
	
	if(jQuery('#varR_HIDIA').attr('id') == 'varR_HIDIA')
	merge(
		document.getElementById('varR_HIMERGE'), 
		document.getElementById('varR_HIANY'), 
		document.getElementById('varR_HIMES'), 
		document.getElementById('varR_HIDIA'), 
		document.getElementById('varR_HFDIA'), 
		document.getElementById('varR_HFMERGE'), 
		document.getElementById('varR_HFMES'), 
		document.getElementById('varR_HFANY')
	);
	}
	
	function chkDateIni(){
		if(jQuery('#varR_IDIA').attr('id') == 'varR_IDIA')
			chkDate(document.getElementById('varR_IDIA'), document.getElementById('varR_IMERGE'), document.getElementById('varR_FDIA'), document.getElementById('varR_FMERGE'), document.getElementById('varR_FMES'), document.getElementById('varR_FANY'));
		else
			chkDate(document.getElementById('varR_HIDIA'), document.getElementById('varR_HIMERGE'), document.getElementById('varR_HFDIA'), document.getElementById('varR_HFMERGE'), document.getElementById('varR_HFMES'), document.getElementById('varR_HFANY'));
	}

	
	function setSearchCacheID(){
	var searchCacheID = new Date();
	   jQuery('#varSEARCH_CACHE_ID').val(searchCacheID.getTime());
	}
	
	function changeVis(visId,controlId,drop){
	if(jQuery('#'+controlId).css('display')!='none'){				
		if(jQuery('#'+visId+'-html').html() != '' && drop != 'drop'){ 
			jQuery('#'+visId).show();
			jQuery('#'+visId+'-arrow').removeClass('arrow-down').addClass('arrow-left');
		}else{
			jQuery('#'+visId+'-arrow').removeClass('arrow-drop-sel').addClass('arrow-drop');
		};
		
		jQuery('#'+controlId).hide();
		jQuery(document).click().unbind('click');
	}else{
		jQuery('#'+visId).hide();
		
		if(drop == 'drop'){
			jQuery('#'+visId+'-arrow').removeClass('arrow-drop').addClass('arrow-drop-sel');
			var results 		= jQuery('#select-'+visId);
			var offset 			= results.offset();
			var topButton 		= (offset.top+10);
			var leftButton 		= (offset.left-10);
			var widthButton 	= results.width();
			jQuery('#'+controlId).css({
				'position':'absolute',
				'top':topButton-120,
				'left':Number(leftButton+widthButton)-130
			}
			).fadeIn("slow",function(){jQuery(document).bind('click',function(){jQuery('#'+visId+'-arrow').removeClass('arrow-drop-sel').addClass('arrow-drop');jQuery('#'+controlId).hide();jQuery(document).unbind('click');if(jQuery('#'+visId+'-html').html() != ''  && drop != 'drop'){ jQuery('#'+visId).show()};});});
		}else{
			jQuery('#'+controlId).slideToggle();
			jQuery('#'+visId+'-arrow').removeClass('arrow-left').addClass('arrow-down');
		}
	}
}



function setMapVars(ref,type,foto,city,linkf,preciodesde,numdorm,title)
{
	jQuery('#parGoogleMapsRef').val(ref);
	jQuery('#parGoogleMapsPType').val(type);
	jQuery('#parGoogleMapsInfo_image').val(foto);
	jQuery('#parGoogleMapsInfo_city').val(city);
	jQuery('#parGoogleMapsInfo_linkf').val(linkf);
	jQuery('#parGoogleMapsInfo_preciodesde').val(preciodesde);
	jQuery('#parGoogleMapsInfo_numdorm').val(numdorm);
	jQuery('#parGoogleMapsInfo_title').val(title);
}

function popDialogMap(title,callback){
	if(jQuery('#popUpMapContainer').attr('id') != 'popUpMapContainer'){
		var map = document.createElement('div');
		var map_content = document.createElement('div');
		map.id = 'popUpMapContainer';
		map_content.id = 'popUpMapContainerContent';
		map.appendChild(map_content);
		document.body.appendChild(map);
	}
	
	jQuery('#popUpMapContainer').attr('title',title).dialog({'width':560,'height':600,'position':['center',40]});
	jQuery('#popUpMapContainer').dialog('open');
	reload('SHOWGMAPSING','popUpMapContainerContent',false,callback);
}

/* slides up page scroll to a given element
 * @param htmlId - class or id, preceded of a jQuery selector (typically # or .)
 * @param millis - in milliseconds, animation duration
 */
function slideUp( htmlId, millis ){
    if( _id = jQuery(htmlId) ) // if the id exists
	{
		//get the top offset of the target anchor
	    var target_offset = _id.offset();
	    var target_top = target_offset.top;
	
	    //goto that anchor by setting the body scroll top to anchor top
	    jQuery('html, body').animate({scrollTop:target_top}, millis );				
	}
}