	function appendOptionLast(elSel,val) {
			var elOptNew = document.createElement('option');
			elOptNew.text = val
			elOptNew.value = val
			try {
				elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
			} catch(ex) {
				elSel.add(elOptNew); // IE only
			}
		}

		function removeOptionLast(elSel) {
			if (elSel.length > 0) {
				elSel.remove(elSel.length - 1);
			}
		}
		
		function doCompletionAdNi(form, origen){
			var ad = 4;
			var ni = 3;
			var hab = 4;
			//Zonas
			if (origen==null){
				if (document.getElementById(form+':destinos').value==105 || document.getElementById(form+':hoteles').value==316){
					ad=10;
					ni=0;
					hab = 1;
				}
			} 
			if (origen=='dest'){
				if (document.getElementById(form+':destinos').value==105){
					ad=10;
					ni=0;
					hab=1;
				}
			}
			if (origen=='hot'){
				if (document.getElementById(form+':hoteles').value==316){
					ad=10;
					ni=0;
					hab=1;
				}
			}
			
			
			difad = document.getElementById(form+':adultos1').length - ad;
			difni = document.getElementById(form+':ninos1').length - 1 - ni;
			difhab = document.getElementById(form+':habitaciones').length - hab;
			
			//alert (ad+"   ---   "+ni+"      difad : "+difad+"    difni:"+difni)
			if (difhab>0){
				for (i=0;i<difhab;i++){
					removeOptionLast(document.getElementById(form+':habitaciones'));
				}
			}
			if (difhab<0){
				for (i=difhab;i<0;i++){
					appendOptionLast(document.getElementById(form+':habitaciones'),(document.getElementById(form+':habitaciones').length+1));
				}
			}
			if (difad>0){
				for (i=0;i<difad;i++){
					removeOptionLast(document.getElementById(form+':adultos1'));
					removeOptionLast(document.getElementById(form+':adultos2'));
					removeOptionLast(document.getElementById(form+':adultos3'));
					removeOptionLast(document.getElementById(form+':adultos4'));
				}
			}
			if (difad<0){
				for (i=difad;i<0;i++){
					appendOptionLast(document.getElementById(form+':adultos1'),(document.getElementById(form+':adultos1').length+1));
					appendOptionLast(document.getElementById(form+':adultos2'),(document.getElementById(form+':adultos2').length+1));
					appendOptionLast(document.getElementById(form+':adultos3'),(document.getElementById(form+':adultos3').length+1));
					appendOptionLast(document.getElementById(form+':adultos4'),(document.getElementById(form+':adultos4').length+1));
				}
			}

			if (difni>0){
				for (i=0;i<difni;i++){
					removeOptionLast(document.getElementById(form+':ninos1'));
					removeOptionLast(document.getElementById(form+':ninos2'));
					removeOptionLast(document.getElementById(form+':ninos3'));
					removeOptionLast(document.getElementById(form+':ninos4'));
				}
			}
			if (difni<0){
				for (i=difni;i<0;i++){
					appendOptionLast(document.getElementById(form+':ninos1'),(document.getElementById(form+':ninos1').length));
					appendOptionLast(document.getElementById(form+':ninos2'),(document.getElementById(form+':ninos2').length));
					appendOptionLast(document.getElementById(form+':ninos3'),(document.getElementById(form+':ninos3').length));
					appendOptionLast(document.getElementById(form+':ninos4'),(document.getElementById(form+':ninos4').length));
				}
			}
			if (hab == 1){
				document.getElementById('habitacion_2').style.display='none';
				document.getElementById('habitacion_3').style.display='none';
				document.getElementById('habitacion_4').style.display='none';
			}
			//Limpiamos ninos...
			if (ni==0){
				document.getElementById('children').style.display='none';
				document.getElementById('children2').style.display='none';
				document.getElementById('children3').style.display='none';
				document.getElementById('children4').style.display='none';
			} else {
				document.getElementById('children').style.display='block';
				document.getElementById('children2').style.display='block';
				document.getElementById('children3').style.display='block';
				document.getElementById('children4').style.display='block';
			}
			
		}
		
		function doCompletionAdNiOf(form, origen){
			var ad = 4;
			var ni = 3;
			var hab = 4;
			//Zonas
			if (origen==null){
				if (document.getElementById(form+':odestinos').value==105 || document.getElementById(form+':ohoteles').value==316){
					ad=10;
					ni=0;
					hab = 1;
				}
			} 
			if (origen=='dest'){
				if (document.getElementById(form+':odestinos').value==105){
					ad=10;
					ni=0;
					hab=1;
				}
			}
			if (origen=='hot'){
				if (document.getElementById(form+':ohoteles').value==316){
					ad=10;
					ni=0;
					hab=1;
				}
			}
			
			
			difad = document.getElementById(form+':adultos1').length - ad;
			difni = document.getElementById(form+':ninos1').length - 1 - ni;
			
			difhab = document.getElementById(form+':habitaciones').length - hab;
			
			//alert (ad+"   ---   "+ni+"      difad : "+difad+"    difni:"+difni)
			if (difhab>0){
				for (i=0;i<difhab;i++){
					removeOptionLast(document.getElementById(form+':habitaciones'));
				}
			}
			if (difhab<0){
				for (i=difhab;i<0;i++){
					appendOptionLast(document.getElementById(form+':habitaciones'),(document.getElementById(form+':habitaciones').length+1));
				}
			}
			
			if (difad>0){
				for (i=0;i<difad;i++){
					removeOptionLast(document.getElementById(form+':adultos1'));
					removeOptionLast(document.getElementById(form+':adultos2'));
					removeOptionLast(document.getElementById(form+':adultos3'));
					removeOptionLast(document.getElementById(form+':adultos4'));
				}
			}
			if (difad<0){
				for (i=difad;i<0;i++){
					appendOptionLast(document.getElementById(form+':adultos1'),(document.getElementById(form+':adultos1').length+1));
					appendOptionLast(document.getElementById(form+':adultos2'),(document.getElementById(form+':adultos2').length+1));
					appendOptionLast(document.getElementById(form+':adultos3'),(document.getElementById(form+':adultos3').length+1));
					appendOptionLast(document.getElementById(form+':adultos4'),(document.getElementById(form+':adultos4').length+1));
				}
			}

			if (difni>0){
				for (i=0;i<difni;i++){
					removeOptionLast(document.getElementById(form+':ninos1'));
					removeOptionLast(document.getElementById(form+':ninos2'));
					removeOptionLast(document.getElementById(form+':ninos3'));
					removeOptionLast(document.getElementById(form+':ninos4'));
				}
			}
			if (difni<0){
				for (i=difni;i<0;i++){
					appendOptionLast(document.getElementById(form+':ninos1'),(document.getElementById(form+':ninos1').length));
					appendOptionLast(document.getElementById(form+':ninos2'),(document.getElementById(form+':ninos2').length));
					appendOptionLast(document.getElementById(form+':ninos3'),(document.getElementById(form+':ninos3').length));
					appendOptionLast(document.getElementById(form+':ninos4'),(document.getElementById(form+':ninos4').length));
				}
			}
			if (hab == 1){
				document.getElementById('habitacion_2').style.display='none';
				document.getElementById('habitacion_3').style.display='none';
				document.getElementById('habitacion_4').style.display='none';
			}
			//Limpiamos ninos...
			if (ni==0){
				document.getElementById('children').style.display='none';
				document.getElementById('children2').style.display='none';
				document.getElementById('children3').style.display='none';
				document.getElementById('children4').style.display='none';
			} else {
				document.getElementById('children').style.display='block';
				document.getElementById('children2').style.display='block';
				document.getElementById('children3').style.display='block';
				document.getElementById('children4').style.display='block';
			}
			
		}


// Adobe Dreamweaver 
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];}
}

//  Global Red 
function swapDisplay(object, displaied){ //v1.1
	var obj = document.getElementById(object);
	if (obj.style.display=='block'){ obj.style.display='none'; } else {	if(displaied){ obj.style.display='block';	} else{ obj.style.display='none'; } }
}
function bodyOffHeight(){ //v1.0
	var h = (document.body.scrollHeight)+'px';
	document.getElementById('body_off').style.height= h;
}
function bodyOff(){ //v1.0
	var w = (document.body.scrollWidth)+'px';
	var h = (document.body.scrollHeight)+'px';
	document.getElementById('body_off').style.width= w;
	document.getElementById('body_off').style.height= h;
}
function centerWindow(object) { //v1.0
	var obj = document.getElementById(object);
	if (typeof window.innerWidth != 'undefined'){
       var w = window.innerWidth;
       var h = window.innerHeight;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
        var w =document.documentElement.clientWidth;
        var h =document.documentElement.clientHeight;
    }else{
        var w = document.getElementsByTagName('body')[0].clientWidth;
        var h =document.getElementsByTagName('body')[0].clientHeight;
    }
	var left = Math.max((w/2)-200); // Ya que el tamaño del div es 400
	var top = Math.max((h/2)-100);
	obj.style.left = left+'px';
	obj.style.top = top+'px';
}


/// JQUERY /// 

$(document).ready(function(){
	
	var div_lenguajes = false;
	var div_login = false;
	var div_info = null;

	
	$(".menuLng").click(function(e) {
		if(div_info!=null){
			$(div_info).fadeOut(700);
			div_info=null;
		}		
		
		switch(e.target.id){
		case "win_lng1":    
            $(".lng").fadeIn(700);  
            div_lenguajes=true;
            return false;
        break;
		default:
			return true;
		break;
		}
	});
	
	
	$(".menuLogin").click(function(e) {
		if(div_info!=null){
			$(div_info).fadeOut(700);
			div_info=null;
		}
		switch(e.target.id){
		case "win_login1":    
            $(".login").fadeIn(700);  
            div_login=true;
            return false;
        break;
		default:
			return true;
		break;
		}
	});
	
	
	function ocultar_login(){
		$(".login").fadeOut(700);
		div_login=false;
	}
	$("#cerrar_login").click(function () {
		ocultar_login();  
		}
	);
	
	
	function ocultar_lenguajes(){
		$(".lng").fadeOut(700);
		div_lenguajes=false;
	}
	$("#cerrar").click(function () {
			ocultar_lenguajes();  
		}
	);

	// RV STEP 2
	$(".more_info").click(
			function() {
				$(this).prevAll(".win").fadeIn(200);
				return false;
			}	   
		);

	
	$("a.tarifa_mas_info").click(function(e) {
		if(div_lenguajes)ocultar_lenguajes();
		if(div_info!=null)$(div_info).fadeOut(700);
		div_info = "#d_"+e.target.id;
		
		$("#d_"+e.target.id).fadeIn(700);  
        return false;
	});
	
	$("a.habitacion_mas_info").click(function(e) {
		if(div_lenguajes)ocultar_lenguajes();
		if(div_info!=null)$(div_info).fadeOut(700);
		div_info = "#d_"+e.target.id;
		
		$("#d_"+e.target.id).fadeIn(700); 
        return false;
	});
	
	
	$("a.tarifa_mas_info_cerrar").click(function(e) {
		$("#d"+e.target.id).fadeOut(700);  
		div_info = 	null;
        return false;
	});
	
	$("a.habitacion_mas_info_cerrar").click(function(e) {
		$("#d"+e.target.id).fadeOut(700);
		div_info = 	null;
        return false;
	});
	
	
	$(document).click(function(e) {
		if(div_lenguajes)ocultar_lenguajes();
		if(div_info!=null)$(div_info).fadeOut(700);
		
		if(div_login){
			if(e.target.id!='i_header:form_mis_res:loc_localizador' && e.target.id!='i_header:form_mis_res:loc_mail')
				ocultar_login();
		}
		
	});
	// Win Close
	$(".win .close").click(
		function() {
			$(this).parent().parent(".win").fadeOut(500);
			return false;
		}
	);

});
