

//TENDENCIAS//////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
var color_actual=null
function abreColor(i,idx,total){
	if(i!=color_actual){
		$("#color"+i).get(0).style.height="0px"
		$("#color"+i).get(0).style.display="block"
		if(color_actual!=null)cierraColor(color_actual)
		var height=$("#color"+i+" .concontx").get(0).offsetHeight+$("#color"+i+" .conconti").get(0).offsetHeight+10
		var height2=$(".conop").get(0).offsetHeight-7
		if(height<height2) height=height2
		
		$("#color"+i).animate({height: height+"px",marginBottom:"9px"}, 300,"swing")
		$("#colorbtn"+i).animate({width:"207px"}, 50,"swing")
		var margintop="7px";
		if(idx==0)margintop="0px"
		$("#colorbtn"+i).animate({paddingBottom: "9px",paddingTop: "9px",marginBottom: "8px",marginTop:margintop}, 300,"swing")
		$("#colorbtn"+i).get(0).style.fontWeight="bold"
		
		color_actual=i
	}else cierraColor(i)
	return false; 
}

function cierraColor(i){
	color_actual=null
	$("#color"+i).animate({height: "0px",marginBottom: "0px"}, 300,"swing")
	$("#colorbtn"+i).animate({width:"198px"}, 50,"swing")
	$("#colorbtn"+i).animate({paddingBottom: "0px",paddingTop: "0px",marginBottom: "2px",marginTop: "0px"}, 300,"swing")
	
	$("#colorbtn"+i).get(0).style.fontWeight="normal"
}


//MOTOR DE RESERVAS//////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
	


//FIN MOTOR DE RESERVAS///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

function CreateBookmarkLink(title,url) {

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }



function arreglaCal()
{

}
//EQUIVALENT ARRAY_SEARCH
function getIdx(vector,k){
	for(i=0;i<vector.length;i++){
		if(vector[i]==k) return i
	}
	return false;
}

var _actual=0
function overMenu(id){
	if(_actual!=0){
		document.getElementById("m_"+_actual).style.display="inline";
		document.getElementById("m_"+_actual+"_on").style.display="none";
	}
	
	document.getElementById("m_"+id).style.display="none";
	document.getElementById("m_"+id+"_on").style.display="block";
	_actual=id;
}
function outMenu(id){
	document.getElementById("m_"+id).style.display="inline";
	document.getElementById("m_"+id+"_on").style.display="none";	
}



function cambiaImg(id, src)
{
	MM_findObj(id).src=src;
}


/*function activaCapa(num, img, img2)
{
	// Activa capa en la home
	if (num!=capaActiva)
	{
		// Desactiva capa antigua
		imgold=imgold.replace("_on","");
		MM_findObj("id"+capaActiva).src=imgold;
		decreceCapa(151,capaActiva);
		MM_findObj("img"+capaActiva).onmouseout=function() {
			var imgt=this.childNodes[0].src;
			imgt=imgt.replace("_on","");
			this.childNodes[0].src=imgt;

		};
		// Actualiza los datos de la capa antigua
		imgon=img;
		imgold=img2;
		capaActiva=num;
		// Activa la capa nueva
		MM_findObj("id"+num).src=img;
		MM_findObj("img"+num).onmouseout=function() {
			this.childNodes[0].src=img;
		};
		creceCapa(0,num);

	}
}*/



function decreceCapa(tam, num)
{
	if (tam!=0)
	{
		tam-=10;
		if (tam<0) tam=0;
		MM_findObj("capa"+num).style.height=(tam/10)+"em";
		setTimeout("decreceCapa("+tam+","+num+")",5);
	}
}

function creceCapa(tam, num)
{
	if (tam!=151)
	{
		tam+=10;
		if (tam>151) tam=151;
		MM_findObj("capa"+num).style.height=(tam/10)+"em";
		setTimeout("creceCapa("+tam+","+num+")",5);
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

function iniciaFormularios()
{
	for (var j=0; j<document.forms.length; j++)
	{
		for (var i=0; i<document.forms[j].elements.length; i++)
		{
			var nam=document.forms[j].elements[i].name.substring(0,5);
			if (nam=="fecha")
			{
				var pos=findPos(MM_findObj(document.forms[j].elements[i].name));
				Calendar.setup({
					inputField     :    document.forms[j].elements[i].name,     // id of the input field
					ifFormat       :    "%d/%m/%Y",      // format of the input field
					button         :    "boton_"+document.forms[j].elements[i].name,  // trigger for the calendar (button ID)
					align          :    "Bl",           // alignment (defaults to "Bl")
					singleClick    :    true
				})
			}
		}
	}
	
}

function validaFormCentros()
{
	var d=document.buscentros;
	if (d.codpostal.value!="" && d.codpostal.value.length!=5) 
	{
		bien=false;
		alert(errorCP);
	}
	if (bien) bien=(d.provincia.value!='' || d.codpostal.value!='');
	return bien;
}


var rsson=false;
var buscadon=false;

function fadein(capa)
{
	$(capa).fadeIn(300);
}


function fadeout(capa)
{
	$(capa).fadeOut(300);
}


function abreCapaBuscador(id)
{
	if (document.getElementById(id).style.display=="" || document.getElementById(id).style.display=="none") document.getElementById(id).style.display="inline";
	else	document.getElementById(id).style.display="none";
}

function switchRSS(rsson1,id)
{
	if (rsson1) 
	{
		despliegaMenu(id);
		
	
		rsson=true;
	} else {
		escondeMenu(id);
		rsson=false;
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
 var speed = Math.round(millisec / 100);
 var timer = 0;

 if(opacStart > opacEnd) {
  for(i = opacStart; i >= opacEnd; i--) {
   setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
   timer++;
  }
  
 } else if(opacStart < opacEnd) {
  for(i = opacStart; i <= opacEnd; i++)
   {
   setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
   timer++;
   }
   
 }
}






//Aplica transparencia compatible con la mayoría de navegadores
function changeOpac(opacity, id) {
 var object = document.getElementById(id).style; 
 object.opacity = (opacity / 100);
 object.MozOpacity = (opacity / 100);
 object.KhtmlOpacity = (opacity / 100);
 object.filter = "alpha(opacity=" + opacity + ")";
 
 if(opacity<1) document.getElementById(id).style.display="none";
 if(opacity>1 && document.getElementById(id).style.display=="none") {
  document.getElementById(id).style.display="block";
 }
}

function despliegaMenu(pos)
{
	//setOpacity(MM_findObj("submenu"+pos), 0);
	MM_findObj(pos).style.display='inline';	
	//setTimeout("eval('fadingmenu("+pos+",0)')",200);
}

function escondeMenu(pos)
{
	MM_findObj(pos).style.display='none';
}


	function open_picture(i){
		var fotogal=MM_findObj("link_"+i);
		Shadowbox.open(fotogal);
	}
	

	
	var obligs=Array()
function setFormInputs(idform){
	var form=document.getElementById(idform)
	
	//Array de Obligatorios (campo oculto del formulario)
	if(typeof form.oblig != "undefined") {
		obligs[idform]=form.oblig.value.split(",")	
	}else{
			obligs[idform]=Array()
	}
	
	
	for(i=0;i<form.length;i++){
		
		var c = form[i]
		if(c.type=="select-one" || c.type=="text" || c.type=="textarea") {
			c.onfocus=function(){
				this.style.borderColor="#ffffff"
				
			}
			c.onblur=function(){
			//Comprueba si es un campo obligatorio o no para ponerlo en rojo en caso de estar vacio
				if(getIdx(obligs[idform],this.name)!==false){
					if(this.value=="") this.style.borderColor="#FF9900"
					else this.style.borderColor="#689B00"
				}else{
					this.style.borderColor="#353535"
				}
			}
		}
	
	}
}


function getIdx(vector,k){
	for(i=0;i<vector.length;i++){
		if(vector[i]==k) return i
	}
	return false;
}



function validar_enviar_js(idform){
	form=document.getElementById(idform)
	//alert(idform)
	//Array de Obligatorios (campo oculto del formulario)
	if(typeof form.oblig != "undefined") {
		obligs[idform]=form.oblig.value.split(",")	
	}else{
			obligs[idform]=Array()
	}
	
	var enviar=true
	
	for(var j=0;j<form.length;j++){
		
		var c = form[j]
		if(c.type=="select-one"|| c.type=="text" || c.type=="textarea"){
			
				if(getIdx(obligs[idform],c.name)!==false){
					if(c.value=="") {c.style.borderColor="#CC3300"
					enviar=false}
				}
		}
	}
	
	if(enviar==true)form.submit()
}


function masinfo(id) {
		document.getElementById("resum"+id).style.display='none';
		document.getElementById("mas"+id).style.display='none';
		document.getElementById("menos"+id).style.display='block';
		v="#ampliado"+id;
		$(v).slideDown('slow');
}

function menosinfo(id) {
		v="#ampliado"+id;
		$(v).slideUp('slow');
		document.getElementById("menos"+id).style.display='none';
		document.getElementById("mas"+id).style.display='block';
		v="#resum"+id;
		$(v).slideDown('slow');
}



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&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n) ; return x;
}

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_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_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];
}
}

function NewWindow(theURL, hauteur, largeur) 
{
var winl = (screen.width - largeur) / 2;
var wint = (screen.height - hauteur) / 2;
winprops = 'height='+hauteur+',width='+largeur+',top='+wint+',left='+winl+',scrollbars=0'
win = window.open(theURL, "", winprops)
}

function NewWindowScroll(theURL, hauteur, largeur) 
{
var winl = (screen.width - largeur) / 2;
var wint = (screen.height - hauteur) / 2;
winprops = 'height='+hauteur+',width='+largeur+',top='+wint+',left='+winl+',scrollbars=1'
win = window.open(theURL, "", winprops)
}

function NewWindowScrollResize(theURL, hauteur, largeur) 
{
var winl = (screen.width - largeur) / 2;
var wint = (screen.height - hauteur) / 2;
winprops = 'height='+hauteur+',width='+largeur+',top='+wint+',left='+winl+',scrollbars=1,resizable=1'
win = window.open(theURL, "", winprops)
}

function obtieneInfo(url)
{
	var html = $.ajax({
                  url: url,
                  async: false
                 }).responseText;
    return html;
}

function muestra_amplia(ida,ver)
{
	if(ver==1)
	{
		document.getElementById('ampliar'+ida).style.display='inline';
	}else{
		document.getElementById('ampliar'+ida).style.display='none';
	}
}

//Pasa a la serie de miniaturas que se le dice
//La variable slide indica el ancho de la galería
function openGal(num){
	if(_actual!=null){$("#gal"+_actual).fadeOut(300)};
	var gal=document.getElementById("gal"+num).style;
	$("#gal"+num).fadeIn(300)
	
	updateArrows(num)
	_actual=num;
}

function openGalSlide(num,slide){
	if(_actual!=null){
		$("#gal"+_actual).animate({marginLeft: -slide}, 500,"swing")//mueve la galería
	};
	var gal=document.getElementById("gal"+num).style;
	gal.marginLeft=slide+"px"
	gal.display="block"
	$("#gal"+num).animate({marginLeft: 0}, 500,"swing")

	updateArrows(num)
	_actual=num;
}

//Mueve la galeria de num posiciones
function changeGal(num,slide){
	if(typeof slide!="undefined")openGalSlide(_actual+num,slide*num)
	else openGal(_actual+num)
}

//Hace aparecer o desaparecer las flechas
function updateArrows(num){
	if(num==0) prev.style.display="none"
	else {if(prev.style.display!="block")opacity(prev.id, 0,100,200)}
	if(num==gals) next.style.display="none"
	else {if(next.style.display!="block")opacity(next.id, 0,100,200)}
}

function pngFIX(){
 var arVersion = navigator.appVersion.split("MSIE")
 var version = parseFloat(arVersion[1])
 if ((version >= 5.5) && (document.body.filters)) 
 {
    for(var i=0; i<document.images.length; i++)
    {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (img.className=="pngfix" )
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
    }
 }
}

function esconde_selects() {
		if ($.browser.msie && parseInt($.browser.version)<7)	$('#cjreservas_hotel select').hide();
}

function muestra_selects() {
	if ($.browser.msie && parseInt($.browser.version)<7)	$('#cjreservas_hotel select').show();
}