$(document).ready(function(){	

	$("#btnBooking").click(function(){
		$dtEntrada = $('input[name="dtEntrada"]').val();
		$dtSalida = $('input[name="dtSalida"]').val();
		if ( $dtEntrada !='' && $dtSalida!='' ) {
			$url= 'http://80.38.51.109:5900/WebReservas/default.aspx?dtEntrada=' + $dtEntrada.substring(0, 8) + '&dtSalida='+ $dtSalida.substring(0, 8);
			$(this).attr('href', $url).attr("target", "_blank");
			return true;
		}
	});	

	$(function() {
		var fechas = $( "#de, #hasta" ).datepicker({			
			monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
			dayNamesMin: ['D','L','M','X','J','V','S'],
			firstDay: 1,
			showOn: "button",
			buttonImage: "images/calendar_icon.gif",
			buttonImageOnly: true,			
			buttonText: 'seleccionar fecha',
			dateFormat: 'dd/mm/y',
			minDate: 0,
			defaultDate: "+1w",
			numberOfMonths: 1,
			onSelect: function( selectedDate ) {
				var option = this.id == "de" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				fechas.not( this ).datepicker( "option", option, date );
			}
		});
	});

	$(function() {
		var dates = $( "#from, #to" ).datepicker({			
			monthNames: ['Janaury','Febraury','March','April','May','June','July','August','September','October','November','December'],
			dayNamesMin: ['S','M','T','W','T','F','S'],
			firstDay: 0,
			showOn: "button",
			buttonImage: "images/calendar_icon.gif",
			buttonImageOnly: true,			
			buttonText: 'select date',
			dateFormat: 'dd/mm/y',
			minDate: 0,
			defaultDate: "+1w",
			numberOfMonths: 1,
			onSelect: function( selectedDate ) {
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	});

	
	$(".sHuman").hide();

	$("a").focus(function() {
	  $(this).blur();
	});

	var $currentPage = $('body').attr('class');
	$('#menu a.' + $currentPage).addClass('current');

	if ( $('body').attr('class') != 'contact' ) {
	
	$('.slider').nivoSlider({
		effect:'fade', 
		slices:10,
		animSpeed:750, 
		pauseTime:2750,
		startSlide:0,
		pauseOnHover:false,
		directionNav:false,
		directionNavHide:true, 
		controlNav:true
		});
	}

	$(".choose-slider a").click(function(e){
		e.preventDefault();
		$(this).blur();
		$('.slider').hide();
		var slide = $(this).attr('href');
		$('#'+slide).show();
		$('.choose-slider * a').removeClass('current');
		$(this).addClass('current');
		//return false;
	});


	//external link in new window
	var h = window.location.host.toLowerCase();
	$("a[href^='http']:not([href^='http://" + h + "']):not([href^='http://www." + h + "']), a[href$='.pdf']").attr("target", "_blank");


	//smooth scroll
	$('a[href*=#]').click(function() {

	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {        
			var $target = $(this.hash);            
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');            
			if ($target.length) {            
				var targetOffset = $target.offset().top;                
				$('html,body').animate({scrollTop: targetOffset}, 850);                    
				return false;                
			}            
		}        
	});
	
	$("#slider").easySlider({
		auto: true, 
		continuous: true,
		controlsShow: false
	});	

});	

//end jquery


function isLegal(txt){
var invalids = "#$^&*~<>/\|"
	for(i=0; i<invalids.length; i++) {
		if(txt.indexOf(invalids.charAt(i)) >= 0 ) {
		return false;}
	 }
return true;
}

function validarReserva(){
	var data1 = document.getElementById("de").value;
	var data2 = document.getElementById("hasta").value;

	if (data1 == "") { 
		alert("Debes indicar una fecha de entrada.");
		document.frmReserva.from.focus();
		return false;
	}
			

	if (data1 != "" ) { 
		var filter = /^\d{1,2}\/\d{2}\/\d{2}$/;
		if (!filter.test(data1)) {
			alert("Formato de fecha incorrecto, debe ser: dd/mm/aa");
			document.frmReserva.from.focus();
			return false;
		}
	}
	if (data2 == "") { 
		alert("Debes indicar una fecha de salida.");
		document.frmReserva.to.focus();
		return false;
	}
			

	if (data2 != "" ) { 
		var filter = /^\d{1,2}\/\d{2}\/\d{2}$/;
		if (!filter.test(data2)) {
			alert("Formato de fecha incorrecto, debe ser: dd/mm/aa");
			document.frmReserva.to.focus();
			return false;
		}
	}


	return true;
	
}

function validateReserva(){
	var data1 = document.getElementById("from").value;
	var data2 = document.getElementById("to").value;

	if (data1 == "") { 
		alert("You must indicate a check in date.");
		document.frmReserva.from.focus();
		return false;
	}
			

	if (data1 != "" ) { 
		var filter = /^\d{2}\/\d{1,2}\/\d{2}$/;
		if (!filter.test(data1)) {
			alert("Wrong date format, must be: dd/mm/yy");
			document.frmReserva.from.focus();
			return false;
		}
	}
	if (data2 == "") { 
		alert("You must indicate a check out date");
		document.frmReserva.to.focus();
		return false;
	}
			

	if (data2 != "" ) { 
		var filter = /^\d{2}\/\d{1,2}\/\d{2}$/;
		if (!filter.test(data2)) {
			alert("Wrong date format, must be: dd/mm/yyyy");
			document.frmReserva.to.focus();
			return false;
		}
	}


	return true;
}


function validarFrm(){
	var nom = document.getElementById("name").value;
	var mail = document.getElementById("email").value;
	var assumpte = document.getElementById("subject").value;
	var texte = document.getElementById("message").value;

	if (nom == "") { 
		alert("Debes indicar un nombre.");
		document.frmContact.name.focus();
		return false;
	}

	if (nom != "" ) { 
		if (isLegal(nom)==false) {
			alert("Caracteres no permitidos: #$^&*~<>/\|");
			document.frmContact.name.focus();
			return false;
		}
	}


	if (mail == "") { 
		alert("Debes indicar una dirección de correo electrónico.");
		document.frmContact.email.focus();
		return false;
	}
			

	if (mail != "" ) { 
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(mail)) {
			alert("Formato de correo electrónico incorrecto.");
			document.frmContact.email.focus();
			return false;
		}
	}

	if (assumpte != "") {
		if (isLegal(assumpte)==false) {
		alert("Caracteres no permitidos: #$^&*~<>/\|");
		document.frmContact.subject.focus();
		return false;
		}
	}


	if (texte == "") {
		alert("Debes especificar una consulta.");
		document.frmContact.message.focus();
		return false;
	}
	
	if (texte != "") {
		if (isLegal(texte)==false) {
		alert("Caracteres no permitidos: #$^&*~<>/\|");
		document.frmContact.message.focus();
		return false;
		}
	}


	if (document.frmContact.terms.checked  == false) {
		alert("Debes aceptar los términos legales.");
		document.frmContact.terms.focus();
		return false;
	}
	

	return true;
}

function validateFrm(){
	var nom = document.getElementById("name").value;
	var mail = document.getElementById("email").value;
	var assumpte = document.getElementById("subject").value;
	var texte = document.getElementById("message").value;

	if (nom == "") { 
		alert("You must enter a name.");
		document.frmContact.name.focus();
		return false;
	}

	if (nom != "" ) { 
		if (isLegal(nom)==false) {
			alert("Characters not allowed: #$^&*~<>/\|");
			document.frmContact.name.focus();
			return false;
		}
	}


	if (mail == "") { 
		alert("You must enter a email address.");
		document.frmContact.email.focus();
		return false;
	}
			

	if (mail != "" ) { 
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(mail)) {
			alert("Incorrect email format.");
			document.frmContact.email.focus();
			return false;
		}
	}

	if (assumpte != "") {
		if (isLegal(assumpte)==false) {
		alert("Characters not allowed: #$^&*~<>/\|");
		document.frmContact.subject.focus();
		return false;
		}
	}


	if (texte == "") {
		alert("Please specify a query.");
		document.frmContact.message.focus();
		return false;
	}
	
	if (texte != "") {
		if (isLegal(texte)==false) {
		alert("Characters not allowed: #$^&*~<>/\|");
		document.frmContact.message.focus();
		return false;
		}
	}


	if (document.frmContact.terms.checked  == false) {
		alert("You must accept the legal terms.");
		document.frmContact.terms.focus();
		return false;
	}
	

	return true;
}
