/* placeholder */function cargarPlaceHollder(sel){jQuery(sel).jLabel();}
/* Codigo Idioma */ function getCodigoIdioma(){ return jQuery('#codigoIdioma').val();}
/* Hover para nuestros hoteles */function getHover(exp){var $lis = jQuery(exp);if($lis){$lis.hover(function (){var el = jQuery(this).toggleClass('hover');});}}
function mostrarDestinos(e){var $el =  jQuery(this).next('ul');	if($el){ 	e.preventDefault();$el.slideToggle();} 	return ;}
/*  */
function getStatic(){ return jQuery('#stcsrv').val()}
function borrarEmail(){	jQuery('#mail').val('');}
function mailDefault(){	if(!jQuery('#mail').val()){	jQuery('#mail').val(jQuery('#mailDef').val());}}
function swapLanguage(){var $url = jQuery('#idiomasCabecera').val();if(typeof($url) != 'undefined'){window.location.href= getStatic()+$url;}}
function getUrl(){ return window.location.href;}
function agregarAFavoritos(sel){
	var onClickFav = function(e){
        e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
        var bookmarkUrl = this.href;
        var bookmarkTitle = this.title;
       if (window.sidebar) { // For Mozilla Firefox Bookmark
                window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
        } else if( window.external || document.all) { // For IE Favorite
                window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
        } else if(window.opera) { // For Opera Browsers
                jQuery("a.jQueryBookmark").attr("href",bookmarkUrl);
                jQuery("a.jQueryBookmark").attr("title",bookmarkTitle);
                jQuery("a.jQueryBookmark").attr("rel","sidebar");
        } else { // for other browsers which does not support
                 alert('Tu navegador no acepta bookmarks');
                 return false;
        }
};
	jQuery(sel).click(onClickFav);
	return;
}

/* De calendario */
function cargarCalendario(idIn , idOut)
{
	var fechas = jQuery( '#'+idIn).datepicker({		
		defaultDate: 0,
		minDate:0,		
		numberOfMonths: 2,		
		//buttonImage: geturllocal()+'public/images/ico-calendar.png',
		//showOn: "button",
		//buttonImageOnly: true,
		dateFormat:'dd-mm-yy',	
		onSelect: calculcarCheckOut
	});
	jQuery('#'+idOut).datepicker({dateFormat:'dd-mm-yy'});
	jQuery('#'+idOut).change(calculcarNoches);	
	//jQuery('#cNoches').change(calculcarNoches);	
}
function calculcarCheckOut()
{
	var n = jQuery('#cNoches').val();	
	var date1 = jQuery('#in').datepicker( "getDate" );
	var date = new Date( Date.parse( date1 ) ); 
	var suma = parseInt(date.getDate()) + parseInt(n);
	date.setDate(suma);	
	var out = jQuery.datepicker.formatDate( 'dd-mm-yy', date);
	jQuery('#out').val(out);
	return out;
}

function calculcarNoches()
{
	$in = jQuery('#in').val();
	$out = jQuery('#out').val();
	date = $in.split("-");
	d1 = date[2]+"-"+date[1]+"-"+date[0];
	date = $out.split("-");
	d2 = date[2]+"-"+date[1]+"-"+date[0];
	cn = daysBetween(d1,d2);
	//if(cn>35){cn=35;}
	if(cn>9){cn=9;}
	jQuery('#cNoches').val(cn);
	calculcarCheckOut();
	return true;
}

function daysBetween(date1, date2){
   if (date1.indexOf("-") != -1) { date1 = date1.split("-"); } else if (date1.indexOf("/") != -1) { date1 = date1.split("/"); } else { return 0; }
   if (date2.indexOf("-") != -1) { date2 = date2.split("-"); } else if (date2.indexOf("/") != -1) { date2 = date2.split("/"); } else { return 0; }
   if (parseInt(date1[0], 10) >= 1000) {
       var sDate = new Date(date1[0]+"/"+date1[1]+"/"+date1[2]);
   } else if (parseInt(date1[2], 10) >= 1000) {
       var sDate = new Date(date1[2]+"/"+date1[0]+"/"+date1[1]);
   } else {
       return 0;
   }
   if (parseInt(date2[0], 10) >= 1000) {
       var eDate = new Date(date2[0]+"/"+date2[1]+"/"+date2[2]);
   } else if (parseInt(date2[2], 10) >= 1000) {
       var eDate = new Date(date2[2]+"/"+date2[0]+"/"+date2[1]);
   } else {
       return 0;
   }
   var one_day = 1000*60*60*24;
   var daysApart = Math.abs(Math.ceil((sDate.getTime()-eDate.getTime())/one_day));
   return daysApart;
}
function cargarFormBusqueda() {	jQuery.datepicker.setDefaults(jQuery.datepicker.regional[getCodigoIdioma()]);cargarCalendario('in' , 'out');}

/* --------------------------------------------- */
jQuery.noConflict();
getHover('input[type=submit]');
cargarFormBusqueda()
