/*   CREACION DE SUBMITS PARA FORMULARIO  ----------------------------------------------------------------------*/
	var pdf = function(){
		$j('#formReseCont').append('<input type="hidden" name="pdfrecu" value="creapdf" />');
		document.forms[0].submit();
		//~ new Insertion.Top('formReseCont','<input type="hidden" name="pdfrecu" value="creapdf" />');
	}
	var pdf2 = function(){
		$j('#formconfirm').append('<input type="hidden" name="pdfrecu2" value="creapdf2" />');
		document.forms[0].submit();
		//~ new Insertion.Top('formconfirm','<input type="hidden" name="pdfrecu2" value="creapdf2" />');
	}

/*   COLAPSABLES Y APPEARS GENERALES ---------------------------------------------------------------------------*/
var proto = {
	calendario : function(){
		/*$j.map($j(".cale"),function(e){
			$j("#" + e.id).calendar({ autoPopUp: 'both', buttonImageOnly: true,buttonImage: 'https://www.monterilla.cl/templates/default/imag/auxi/auxiCale.gif', buttonText: '&Iacute;cono de calendario para fecha de inicio',firstDay: 1,dayNames: ['D','L','M','M','J','V','S'],monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agoto','Septiembre','Octubre','Noviembre','Diciembre'],currentText:'Hoy',nextText:'Sig&#187;',prevText:'&#171;Ant',closeText:'Cerrar',clearText:'Limpiar'});
		})*/
	},
	queEsVali : function(){
		jQuery('#oculVali').toggle();
	},
	queSkype : function(){
		jQuery('#oculSkype').toggle();
	},
	oculRss : function(){
		jQuery('#oculRss').toggle();
	},
	oculRssGene : function(){
		jQuery('#oculRssGene').toggle();
	},
	vali : function(){
		jQuery('#subValida').toggle();
	},
	linkRese : function(){
		$j('#linkRese').slideToggle();
	},
	verCond : function(){
		if ($j('#oculCond')[0].style.display=='none'){
			if($j('#acepEn').length > 0){
				$j('#linkCond')[0].innerHTML="(Hide conditions)";
			}
			else{
				$j('#linkCond')[0].innerHTML="(Ocultar condiciones)";
			}
		}
		else{
			if($j('#acepEn').length>0){
				$j('#linkCond')[0].innerHTML="(View conditions)";
			}
			else{
				$j('#linkCond')[0].innerHTML="(Ver Condiciones)";
			}
		}
		$j('#oculCond').slideToggle();
	},
	verPoli : function(){
		if ($j('#oculPoli')[0].style.display=='none'){
			$j('#linkPoli')[0].style.display='none';
			$j('#strongPoli')[0].style.display='';
		}
		else{
			$j('#linkPoli')[0].style.display='';
			$j('#strongPoli')[0].style.display='none';
		}
		$j('#oculPoli').slideToggle();
	},
	paso3 : function(){
		if($j('#acep')[0].checked==true){
			$j('#paso3').removeAttr('disabled').addClass('boton').removeClass('botonInac');
		}
		else{
			$j('#paso3').attr('disabled', 'disabled').addClass('botonInac').removeClass('botonInac');
		}
	},
	numePasa : function(responseXMLCli){
		var item=responseXMLCli.responseXML.documentElement.getElementsByTagName('contenido')[0];
		var pasajero=item.getElementsByTagName('pasajero')[0].firstChild.data;
			if(pasajero==0){
				$('numePasa').update('1');
				$('plural').update('');
			}
			if(pasajero==1){
				$('numePasa').update('1');
				$('plural').update('');
			}
			else{
				$('numePasa').update(pasajero);
				$('plural').update('s');
			}
	},
	cm: function (texto) {
		var moneda = "";
		texto = parseInt(texto);
		texto = "" + texto;
		dec=0;
		for ( i=(texto.length-1); i>=0 ; i-- ) {
		if ( dec == 3 ) {
		moneda = "." + moneda;
		dec = 1;
		} else
		dec++;
		moneda = texto.charAt(i) + moneda;
		}
		moneda = moneda;

		return moneda;
	}
	//~ adds:function(){
		//~ if (!$('oferta')){
			//~ $('cargando').hide();

		//~ var F = $('formReseCont').serialize(true);
		//~ var precio=F.habitacion;
		//~ var dolar=F.dolar;
		//~ /*calculamos los dias*/
		//~ var r = F.intime.split("/");
		//~ var e = F.outtime.split("/");
		//~ t = Math.floor((new Date(e[2],e[1],e[0]).getTime() - new Date(r[2],r[1],r[0]).getTime()) / (1000*60*60*24));
		//~ if (t < 0 || !t){ var t=0;}
		//~ //alert(e);
		//~ $('peso').update(proto.cm(precio*t));
 		//~ $('dolar').update(Math.floor( ( (precio*t) / (119/100) ) /dolar ) );
		//~ var h=$('habitacion').selectedIndex;
		//~ var hab=$('habitacion').options[h].text;
		//~ if (hab=="Doble Estándar" ||  hab=="Doble Superior" || hab=="Suite" || hab=="Standard Double" || hab=="Special Double") $('estaPref').show();
		//~ else $('estaPref').hide();
		//~ var pars = 'pasajeros='+hab;
		//~ var url = '/getajax.php';
		//~ var myAjax = new Ajax.Request(
		//~ url,{
			//~ method: "get",
			//~ parameters: pars,
			//~ onComplete: proto.numePasa
		    //~ }
		//~ );
		//~ }
	//~ }
};
/*
	* Función menuCamp
	* Función encargada de paginar los contenidos de campanas y promociones full
	* @param {string} Contienen el elemento [objeto] al que se le ha hecho click
*/
var porid = {
	idname: function(e) {
		if(e.target.id){
			if(eval("this."+e.target.id)!=undefined){
				eval("this."+e.target.id)(e.target);
				}
			}
	},
	menuCont : function(){
		$j(".seccCamp").hide();
		if(document.URL.match(/#n/)){
			url = document.URL.split("#");
			$j("#"+url[1]).show();
			$j("#link-"+url[1]).parent().addClass("acti");
		}
		else{
			$j("#n1").show();
			$j("#link-n1").parent().addClass("acti");
		}
	},
	linkMenuCont : function(e){
		url = e.target.href.split("#");
		$j(".seccCamp").hide();
		$j("#menuCont li").removeClass("acti");
		$j("#"+url[1]).show();
		$j("#"+e.target.id).parent().addClass("acti");
	},
	startImagTop : function(){
		$j('.contImag').innerfade({
			animationtype: 'fade',
			speed: 200,
			timeout: 4000,
			type: 'random_start',
			containerheight: '336px'
		});},
	startPlanTop : function(){
		$j('.contPlan').innerfade({
			animationtype: 'fade',
			speed: 200,
			timeout: 4000,
			type: 'random_start',
			containerheight: '336px'
		});
	},
	stopImagTop : function(e){
		clearTimeout(time);
		$j("#imagThum li").removeClass("acti");
		imag = e.target.id.split("-");
		$j(".contImag li").fadeOut(200)
		$j("#"+imag[1]).fadeIn(200);
		$j("#"+e.target.id).parent().parent().addClass("acti");
	},
	stopPlanTop : function(e){
		clearTimeout(time);
		$j("#planThum li").removeClass("acti");
		imag = e.target.id.split("-");
		$j(".contPlan li").fadeOut(200)
		$j("#"+imag[1]).fadeIn(200);
		$j("#"+e.target.id).parent().parent().addClass("acti");
	}
}

var porclass = {
	boxShow : function(e){
		var id = e.target.id.split("link-");
		$j("#ocul-"+id[1]).fadeIn(500);
	},
	boxHide : function(e){
		var id = e.target.id.split("link-");
		$j("#ocul-"+id[1]).fadeOut(500);
	}
}

/*   DETECCION DE EVENTOS GENERALES  ------------------------------------------------------------------------*/
	var $j = jQuery.noConflict();
	//inicializamos todo
$j(document).ready( function() {

	$j(".hide").hide();

	$j(".cruiOfer").change(function(e){
		$j(this).parents('fieldset').children('input[type=submit]').removeAttr('disabled').removeClass('botonInac').addClass('boton');
		var entrada = e.target.value;
		var r = entrada.split("/");
		var salida =  parseInt(r[0]) + 1 + "/" + r[1]  + "/" +r[2];
		$j('#outtime1').val(salida);
	});

	if( document.getElementById("menuCont") ){
		porid.menuCont();
		porid.startImagTop();
		porid.startPlanTop();
		$j("#menuCont li a").bind("click",function(e){ porid.linkMenuCont(e); return false; });
		$j("#imagThum li a").bind("click",function(e){ porid.stopImagTop(e); return false; });
		$j("#planThum li a").bind("click",function(e){ porid.stopPlanTop(e); return false; });
	}
	$j("select[name=intime]").change(function(e){
		if ( $j(this).val()!='Fecha de Ingreso' ){
			var intime0=$j(this)[0].selectedIndex;
			$j(this).next('select').children('option:eq('+intime0+')').attr('selected', 'selected');
			$j(this).siblings('input[type=submit]').removeAttr('disabled').removeClass('botonInac').addClass('boton');
		}
		else{
			if ( $j.trim( $j(this).val() ) == '' ) {
				$j(this).siblings('input[type=submit]').attr('disabled', 'disabled').addClass('botonInac').removeClass('boton');
			}
		}
/*
		if ($('intime_1').selectedIndex!=0){
			var intime1=$('intime_1').selectedIndex;
			$('outtime_1').selectedIndex= intime1;
			$('oferta_1').disabled=false;
			$('oferta_1').addClassName('boton');
			$('oferta_1').removeClassName('botonInac');

		}
		else{
			$('oferta_1').disabled=true;
			$('oferta_1').addClassName('botonInac');
			$('oferta_1').removeClassName('boton');

		}

		if ($('intime_2').selectedIndex!=0){
			var intime2=$('intime_2').selectedIndex;
			$('outtime_2').selectedIndex= intime2;
			$('oferta_2').disabled=false;
			$('oferta_2').addClassName('boton');
			$('oferta_2').removeClassName('botonInac');
		}
		else{
			$('oferta_2').disabled=true;
			$('oferta_2').addClassName('botonInac');
			$('oferta_2').removeClassName('boton');
		}
		if ($('intime_3').selectedIndex!=0){
			var intime3=$('intime_3').selectedIndex;
			$('outtime_3').selectedIndex= intime3;
			$('oferta_3').disabled=false;
			$('oferta_3').addClassName('boton');
			$('oferta_3').removeClassName('botonInac');
		}
		else{
			$('oferta_3').disabled=true;
			$('oferta_3').addClassName('botonInac');
			$('oferta_3').removeClassName('boton');

		}
*/
	});

			$j('#queBlogA, #queEsVali, #queRssGene').attr('href', 'javascript:;');
			$j('#subValida, #oculCond, #oculPoli, #linkReseOcul').hide();
			if($j('#estaPref').length>0){
				var h=$j('#habitacion')[0].selectedIndex;
				var hab=$j('#habitacion')[0].options[h].text;
				if (hab!="Doble Estándar" &&  hab!="Doble Superior" && hab!="Suite" && hab!="Standard Double" && hab!="Special Double") $j('#estaPref').hide();
			}
	$j('.js').bind("click", function(e){porid.idname(e); return false;});
	$j('.boxShow').mouseover(function(e){porclass.boxShow(e); return false;});
	$j('.boxShow').mouseout(function(e){porclass.boxHide(e); return false;});


	/*proto*/
		$j('#queEsVali, #cerrarVali').click(function(){ proto.queEsVali(); });
		$j('#queSkype, #cerrarSkype').click(function(){ proto.queSkype(); });
		$j('#queBlog, #cerrarRss').click(function(){ proto.oculRss(); });
		$j('#queRssGene, #cerrarRssGene').click(function(){ proto.oculRssGene(); });
		$j('#valida').click(function(){ proto.vali(); });
		$j('#linkCond').click(function(){ proto.verCond(); });
		$j('#linkReseOcul').click(function(){ proto.linkRese(); });
		$j('#linkPoli, #linkPoliSec').click(function(){ proto.verPoli(); });
		$j('#acep').click(function(){ proto.paso3(); });
		$j('#formReseCont')
	/*end proto*/
	/*formularios calculos*/
/*
		if ($('intime')) Event.observe('intime', 'click', newcale0);
		if ($('outtime')) Event.observe('outtime', 'click',newcale1);
		if ($('testdiv0')) Event.observe('testdiv0', 'click', proto.adds);
		if ($('testdiv1')) Event.observe('testdiv1', 'click', proto.adds);
*/
	//~ if ($j('#formReseCont')) new Form.EventObserver($j("#formReseCont")[0], proto.adds);
	/*end formularios calculos*/
		$j('#pdf1').click( function(){ pdf() });
		$j('#pdf2').click( function(){ pdf2() });

		// Deshabilitamos el formulario
		if ( jQuery.trim( jQuery('#intime').val() ) == '' ) {
			jQuery("#paso0, #outtime").attr('disabled','disabled');
		}
		//~ jQuery("#outtime").attr('disabled','disabled');
		//~ jQuery("#habitacion").attr('disabled','disabled');

		jQuery("#intime").datepicker(
		{
			regional: 'es',
			showOn: 'button',
			buttonImage: location.protocol+'//monterilla.cl/templates/default/imag/auxi/auxiCale.gif',
			buttonImageOnly: false,
			dateFormat: "dd/mm/yy",
			minDate: new Date(),
			onSelect: function() {
				jQuery("#outtime").removeAttr('disabled');
				date = jQuery("#intime").val().split("/");
				minimunDate = new Date(date[2],date[1], date[0]);
			}
		});


		jQuery("#outtime").datepicker(
		{
			regional: 'es',
			showOn: 'button',
			buttonImage: location.protocol+'//monterilla.cl/templates/default/imag/auxi/auxiCale.gif',
			buttonImageOnly: false,
			dateFormat: "dd/mm/yy",
			onSelect: function() {
				jQuery("#paso0, #habitacion").removeAttr('disabled');
			}
		});

		//~ jQuery("#habitacion").change(function() {
			//~ if(jQuery("#habitacion :selected").val() != 0)
			//~ {
				//~ jQuery("#paso0").removeAttr('disabled');
			//~ } else {
				//~ jQuery("#paso0").attr('disabled','disabled');
			//~ }
		//~ });

});
