  jQuery(document).ready(function(){
    DefVar("#formapackage");
    jQuery(".rbxDateFrom").each(function(){
      jQuery(this).datepick({
        dateFormat: FormatO,
        showOnFocus: true,
        //defaultDate: +7,
        selectDefaultDate: true,
        minDate:0,
        maxDate:"+1y",
        monthsToShow: 2,
        //showTrigger: "#CalFrom",
        onSelect: customRange
      });
    });

    jQuery(".rbxDateTo").each(function(){
      jQuery(this).datepick({
        dateFormat: FormatO,
        showOnFocus: true, 
        //defaultDate: +14,
        selectDefaultDate: true,
        minDate:+3,
        maxDate:"+1y +1d",
        monthsToShow: 2,
        //showTrigger: "#CalTo",
        onSelect: customRange
      });
    });
    newControls(".cal");
    jQuery(".extra #formapackage").submit(function(){
      var tempForm=jQuery(this).attr('id');
	  if(ValidaPackageAvion("#"+tempForm)!=false)
	  {
		  /*$("#general #der #frame").css('display', 'block');
		  $("#general #der #frame ~ div").css('display', 'none');*/
		   $("#general #frame").css('display', 'block');
		  $("#general #izq").css('display', 'none');
		  $("#general #der").css('display', 'none');
		  return (true);
	  }
	  else
	      return(false);
      //return(ValidaPackageAvion("#"+tempForm));
    });
    jQuery(".extra #formaflight").submit(function(){
      var tempForm=jQuery(this).attr('id');
	  if(ValidaPackageAvion("#"+tempForm)!=false)
	  {
		   $("#general #frame").css('display', 'block');
		  $("#general #izq").css('display', 'none');
		  $("#general #der").css('display', 'none');		  		  		  		  
		  return (true);
	  }
	  else
	      return(false);
      //return(ValidaPackageAvion("#"+tempForm));
    });
    jQuery(".extra #formahotel").submit(function(){
      var tempForm=jQuery(this).attr('id');
      if (jQuery().val("#"+tempForm + " #txtCityName")=="" || jQuery("#"+tempForm + " #txtCityName").val()==MsjDestinO)
      {
        alert(AltMsjDestinO);
        return(false);
      }
      if(ValidaFechaS("#"+tempForm)!=false)
	  {
		   $("#general #frame").css('display', 'block');
		  $("#general #izq").css('display', 'none');
		  $("#general #der").css('display', 'none');		  		  		  		  
		  return (true);
	  }
	  else
	      return(false);
	  //return(ValidaFechaS("#"+tempForm));
    });
    jQuery(".extra #formacar").submit(function(){
      var tempForm=jQuery(this).attr('id');
	  if(ValidaFechaS("#"+tempForm)!=false)
	  {
		   $("#general #frame").css('display', 'block');
		  $("#general #izq").css('display', 'none');
		  $("#general #der").css('display', 'none');		  		  		  		  
		  return (true);
	  }
	  else
	      return(false);
      //return(ValidaFechaS("#"+tempForm));
    });
    jQuery(".extra #formatransfers").submit(function(){
  	  $("#general #frame").css('display', 'block');
  	  $("#general #izq").css('display', 'none');
  	  $("#general #der").css('display', 'none');		  		  		  		  
  	   return (true);
      });
    jQuery(".extra #formatour").submit(function(){
    	  $("#general #frame").css('display', 'block');
    	  $("#general #izq").css('display', 'none');
    	  $("#general #der").css('display', 'none');		  		  		  		  
    	   return (true);
        });
    
    
  });
  function customRange(dates) { 
    var FormA=jQuery(this).parent(0).parent(1).attr('id');
    var xFchA=jQuery(this).attr('class');
    var xCDTGn='#'+FormA+" .rbxDateTo"; //xCalendarDateToGeneric 
    var xCDFGn='#'+FormA+" .rbxDateFrom"; //xCalendarDateFromGeneric 
    var xOCDTGn=jQuery(xCDTGn);
    var xOCDFGn=jQuery(xCDFGn);
    xCDTGn=xOCDTGn.val();
    xCDFGn=xOCDFGn.val();
  //ESTA SECCI�N IDENTIFICA A QUE CALENDARIO SE LE DA CLICK
    if (xFchA.indexOf('rbxDateFrom')>=0){
      var DatesFromDateFrm=jQuery(this).val();
      var DatesFromDateTo=xCDTGn;
      var date = new Date(dates[0]); 
      jQuery.datepick.add(date,'+3', 'd'); 
      DatesFromDateTo==""?xOCDTGn.val(jQuery.datepick.formatDate(date)):xOCDTGn.val(xOCDTGn.val());
      var tempDFrm=DatesFromDateFrm.split("/");
      //alert(tempDFrm);
      var tempDTo=DatesFromDateTo.split("/");
      var tempNewDFrm=tempDFrm[2]+"/"+tempDFrm[1]+"/"+tempDFrm[0];
      var tempNewDTo=tempDTo[2]+"/"+tempDTo[1]+"/"+tempDTo[0];
      tempNewDFrm>=tempNewDTo ? xOCDTGn.val(jQuery.datepick.formatDate(date)) : xOCDTGn.val(xOCDTGn.val()) ;
      var DateFrmx=jQuery.datepick.formatDate(dates[0]);
      var DateTox=xOCDTGn.val();
      var ArrayDateFrmx=DateFrmx.split("/");
      var ArrayDateTox=DateTox.split("/");
      //ELEMENTOS CALENDARIO ANTERIOR FROM
        //Dia
        jQuery("#"+FormA+' input[name=dia_desde]').val(ArrayDateFrmx[IndexDD]);
        //Mes
        jQuery("#"+FormA+' input[name=mes_desde]').val(ArrayDateFrmx[IndexMM]);
        //Anio
        jQuery("#"+FormA+' input[name=anio_desde]').val(ArrayDateFrmx[2]);
      //ELEMENTOS CALENDARIO ANTERIOR TO
        //Dia
        jQuery("#"+FormA+' input[name=dia_hasta]').val(ArrayDateTox[IndexDD]);
        //Mes
        jQuery("#"+FormA+' input[name=mes_hasta]').val(ArrayDateTox[IndexMM]);
        //Anio
        jQuery("#"+FormA+' input[name=anio_hasta]').val(ArrayDateTox[2]);
    }
    else
    {
      var DatesFromDateFrm=xCDFGn; 				//Fecha de Salida
      var DatesFromDateTo=jQuery(this).val();		//Fecha de Regreso
      var date = new Date(dates[0]); 
      jQuery.datepick.add(date,'-3', 'd'); 
      xOCDFGn.val()=="" ? xOCDFGn.val(jQuery.datepick.formatDate(date)):xOCDFGn.val(xOCDFGn.val());
      var tempDFrm=DatesFromDateFrm.split("/");
      var tempDTo=DatesFromDateTo.split("/");
      var tempNewDFrm=tempDFrm[2]+"/"+tempDFrm[1]+"/"+tempDFrm[0];
      var tempNewDTo=tempDTo[2]+"/"+tempDTo[1]+"/"+tempDTo[0];
      tempNewDTo<=tempNewDFrm ? xOCDFGn.val(jQuery.datepick.formatDate(date)): xOCDFGn.val(xOCDFGn.val());
      var DateFrmx=xOCDFGn.val();
      var DateTox= jQuery.datepick.formatDate(dates[0]);
      var ArrayDateFrmx=DateFrmx.split("/");
      var ArrayDateTox=DateTox.split("/");
      //ELEMENTOS CALENDARIO ANTERIOR FROM
        //Dia
        jQuery("#"+FormA+' input[name=dia_desde]').val(ArrayDateFrmx[IndexDD]);
        //Mes
        jQuery("#"+FormA+' input[name=mes_desde]').val(ArrayDateFrmx[IndexMM]);
        //Anio
        jQuery("#"+FormA+' input[name=anio_desde]').val(ArrayDateFrmx[2]);
      //ELEMENTOS CALENDARIO ANTERIOR TO
        //Dia
        jQuery("#"+FormA+' input[name=dia_hasta]').val(ArrayDateTox[IndexDD]);
        //Mes
        jQuery("#"+FormA+' input[name=mes_hasta]').val(ArrayDateTox[IndexMM]);
        //Anio
        jQuery("#"+FormA+' input[name=anio_hasta]').val(ArrayDateTox[2]);
    }
  }
  function newControls(obj){
    obj=obj+",.datepick-nav a";
    jQuery(obj).bind('click',function (){
      dtpkmes=jQuery('.datepick-month.first .datepick-month-header :nth-child(1) option:selected').html();
      dtpkanio=jQuery('.datepick-month.first .datepick-month-header :nth-child(2) option:selected').html();
      month2=jQuery('.datepick-month.last .datepick-month-header').html();
      dtpkclose="X";
      jQuery("#datepick-nav,#datepick-month-header").remove();
      jQuery('.datepick div:first').hide();
      jQuery('.datepick-month .datepick-month-header').hide();
      jQuery('.datepick-month-row').before('<div class="datepick-month-header" id="datepick-month-header"><div class="leftmnt"><span id="dtpkmes">'+dtpkmes+' </span><span id="dtpkanio"> '+dtpkanio+'</span></div><div class="rgtmnt">'+month2+'<a id="dtpkclose" href="javascript:void(0)">'+dtpkclose+'</a></div></div>');
      jQuery('#dtpkclose').live('click',function(){jQuery('.datepick-cmd.datepick-cmd-close').click();});
      jQuery('.datepick-ctrl').hide();
      jQuery('.datepick-ctrl').before('<div class="datepick-nav" id="datepick-nav"><a class="datepick-cmd datepick-cmd-prev" id="datepick-prev" href="javascript:void(0)">&lt;Ant</a><a class="datepick-cmd datepick-cmd-today" id="datepick-today" href="javascript:void(0)">Hoy</a><a class="datepick-cmd datepick-cmd-next" id="datepick-next" href="javascript:void(0)">Sig&gt;</a></div>');
      jQuery('.datepick-nav a').html('');
    });
  }
  function newControls(obj){
    obj=obj+",.datepick-nav a";
    jQuery(obj).bind('click',function (){
      dtpkmes=jQuery('.datepick-month.first .datepick-month-header :nth-child(1) option:selected').html();
      dtpkanio=jQuery('.datepick-month.first .datepick-month-header :nth-child(2) option:selected').html();
      month2=jQuery('.datepick-month.last .datepick-month-header').html();
      dtpkclose="X";
      jQuery("#datepick-nav,#datepick-month-header").remove();
      jQuery('.datepick div:first').hide();
      jQuery('.datepick-month .datepick-month-header').hide();
      jQuery('.datepick-month-row').before('<div class="datepick-month-header" id="datepick-month-header"><div class="leftmnt"><span id="dtpkmes">'+dtpkmes+' </span><span id="dtpkanio"> '+dtpkanio+'</span></div><div class="rgtmnt">'+month2+'<a id="dtpkclose" href="javascript:void(0)">'+dtpkclose+'</a></div></div>');
      jQuery('#dtpkclose').live('click',function(){jQuery('.datepick-cmd.datepick-cmd-close').click();});
      jQuery('.datepick-ctrl').hide();
      jQuery('.datepick-ctrl').before('<div class="datepick-nav" id="datepick-nav"><a class="datepick-cmd datepick-cmd-prev" id="datepick-prev" href="javascript:void(0)">&lt;Ant</a><a class="datepick-cmd datepick-cmd-today" id="datepick-today" href="javascript:void(0)">Hoy</a><a class="datepick-cmd datepick-cmd-next" id="datepick-next" href="javascript:void(0)">Sig&gt;</a></div>');
      jQuery('.datepick-nav a').html('');
    });
  }
  jQuery('#datepick-prev').live('click',function(){
      newControls('#datepick-prev');
      jQuery('.datepick div:first .datepick-cmd.datepick-cmd-prev').click();
  });
  jQuery('#datepick-today').live('click',function(){
    newControls('#datepick-today');
    jQuery('.datepick div:first .datepick-cmd.datepick-cmd-today').click();
  });
  jQuery('#datepick-next').live('click',function(){
    newControls('#datepick-next');
    jQuery('.datepick div:first .datepick-cmd.datepick-cmd-next').click();
  });
  var MsjAirport,altMsjAirport,altMsjAirportr,altMsjDate,NFOrigen,NFDestino,PosadaAllIclusive,FalseHotel,FormatO,IndexMM,IndexDD,MsjAllInclusive,MsjHotel,IDioMA,MsjDestinO;
  function DefVar(obj)
  {
    if(jQuery(obj+" input[name=Idioma]").val().toUpperCase()=="ESP")
    {
      MsjDestinO="Especifique una ciudad";
      AltMsjDestinO="Por favor especifique una ciudad";
      MsjAirport="Ciudad o Aeropuerto";
      altMsjAirport="Por favor seleccione un aeropuerto de origen.";
      altMsjAirportr="Por favor seleccione un aeropuerto de llegada.";
      altMsjDate="Debe Seleccionar una Fecha de Salida";
      NFOrigen="Por favor seleccione un aeropuerto de origen.";
      NFDestino="Por favor seleccione un aeropuerto de destino."
      PosadaAllIclusive="Puede seleccionar como m\u00E1ximo 4 personas por habitaci\u00F3n.";
      FalseHotel="Por favor seleccione un hotel";
      FormatO="dd/mm/yyyy";
      IndexMM=1;
      IndexDD=0;
      MsjAllInclusive="M\u00E1ximo 4 personas por habitaci\u00F3n, incluyendo ni\u00F1os.";
      MsjHotel="Seleccione un hotel por favor.";
      IDioMA="es";
    }
    if(jQuery(obj+" input[name=Idioma]").val().toUpperCase()=="POR")
    {
      MsjDestinO="Introduza uma cidade";
      AltMsjDestinO="Por favor introduza uma cidade";
      MsjAirport="Cidade ou Aeroporto";
      altMsjAirport="Por favor seleccione um aeroporto de partida.";
      altMsjAirportr="Por favor seleccione um aeroporto de chegada.";
      altMsjDate="Voc� deve selecionar uma data de partida";
      NFOrigen="Digite o aeroporto de partida.";
      NFDestino="Especificar Retorno aeroporto";
      PosadaAllIclusive="Voc\u00EA deve selecionar at\u00E9 quatro pessoas por quarto.";
      FalseHotel="Por favor, seleccione um hotel";
      FormatO="dd/mm/yyyy";
      IndexMM=1;
      IndexDD=0;
      MsjAllInclusive="Maximum 4 persons per room, including children.";
      MsjHotel="Please select a hotel.";
      IDioMA="pt";
    }
    if(jQuery(obj+" input[name=Idioma]").val().toUpperCase()=="ING")
    {
      MsjDestinO="Enter a city";
      AltMsjDestinO="Please enter a city";
      MsjAirport="City or Airport";
      altMsjAirport="Please select a departure airport.";
      altMsjAirportr="Please select an arrival airport.";
      altMsjDate="You must select a Departure Date";
      NFOrigen="Enter the departure airport.";
      NFDestino="Specify airport Return";
      PosadaAllIclusive="You must select up to four people per room.";
      FalseHotel="Please select a hotel";
      FormatO="mm/dd/yyyy";
      IndexMM=0;
      IndexDD=1;
      MsjAllInclusive="M\u00E1ximo de 4 pessoas por quarto, incluindo crian\u00E7as.";
      MsjHotel="Por favor, seleccione um hotel.";
      IDioMA="en";
    }
  }
  function ValidaPackageAvion(formulario)
  {
    if(jQuery(formulario+" input[name=Leavingfrom]").val()=="" || jQuery(formulario+" input[name=Leavingfrom]").val()==MsjAirport)
    {
      alert(altMsjAirport);
      return (false);
    }
    if(jQuery(formulario+" input[name=ciudades]").val()=="" || jQuery(formulario+" input[name=ciudades]").val()==MsjAirport)
    {
      alert(altMsjAirportr);
      return (false);
    }
    if (ValidaFechaS(formulario)==false){return(false);}
  }
  function ValidaFechaS(obj)
  {
    if(jQuery(obj+" .rbxDateFrom").val()=="" || jQuery(obj+" .rbxDateTo").val()=="")
    {
      alert(altMsjDate);
      return (false);
    }
  }
