/*!
* jQuery estudio crealia
*/

/* formulario buscador */
jQuery(function($) {

	// validar campo fecha al cambiar contenido
	//$('#hotel').change(function () {
		//if (this.value == 1) {
			//window.location="http://www.itacajerez.com"							  
		//}
	//});

	// obtener fecha hoy;
	milis = $('#cfecha').get(0).value;
	//milisout = $('#cfechaout').get(0).value;
	milistop = $('#cfechatop').get(0).value;
	// fecha inicio
	dia = $('#dia').get(0).value;
	mes = $('#mes').get(0).value - 1;
	anno = $('#anno').get(0).value;
	miFecha = new Date(anno, mes, dia);
	// fecha salida
	//diaout = $('#diaout').get(0).value;
	//mesout = $('#mesout').get(0).value - 1;
	//annoout = $('#annoout').get(0).value;
	//miFechaout = new Date(annoout, mesout, diaout);

	// validar campo fecha al cambiar contenido
	$('.sfecha').change(function () {
		dia = $('#dia').get(0).value;
		mes = $('#mes').get(0).value - 1;
		anno = $('#anno').get(0).value;
		miFecha = new Date(anno, mes, dia);
		
		//diaout = $('#diaout').get(0).value;
		//mesout = $('#mesout').get(0).value - 1;
		//annoout = $('#annoout').get(0).value;
		//miFechaout = new Date(annoout, mesout, diaout);
		//miFecha.setTime(milis);
		//$('#nombre').attr('value', miFecha.getTime());
		diferencia = miFecha.getTime() - milis;
		//tipo = typeof diferencia
		//$('#telefono').attr('value', tipo);
		if (diferencia < 0 || miFecha.getTime() > milistop) {
			//$('#telefono').attr('value', 'hola');
			$('#fechalab').addClass('aviso');
			//$('.sfecha').prevAll('label').addClass('aviso');
			$('.sfecha').addClass('aviso');
		} else {
			$('#fechalab').removeClass('aviso');
			$('.sfecha').removeClass('aviso');
		}
	});

	$('#formreservas').submit(function () {
		$('.sfecha').trigger('change');
		$('.sfechaout').trigger('change');
		var numAvisos = $('.aviso', this).length;
		//$('#aviso-global').remove();
		if (numAvisos) {
			//var listaCampos = [];
			//$('label.aviso').each(function () {
				//listaCampos.push($(this).attr('title'));
			//});
			//if (numAvisos == 1) {
				//var mensajeAviso = 'El campo <strong>' + listaCampos + '</strong> no ha sido rellenado correctamente. Por favor, complételo. ';
			//} else {
				//var mensajeAviso = 'Los campos <strong>' + listaCampos.join('</strong>, <strong>') + '</strong> no han sido rellenados correctamente. Por favor, complételos. ';
			//}
			//$('<div></div>')
				//.attr({
					//'id': 'aviso-global',
					//'class': 'aviexclreser'
				//})
				//.append(mensajeAviso)
				//.hide()
				//.insertAfter('#titreser')
				//.fadeIn('fast');
			return false;
		}
	});

});
