$(document).ready(function(){	
	$('#mycarousel').jcarousel({
		wrap: 'circular',		
		animation: 'slow'
	});
	
	$("#btSuscribe").click(function(){
		var email = $("#nEmail").val();
		var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
		if(email.length > 0){  
				if (filter.test(email)){
					var datos = $("#formSuscribe").serialize();
					$.ajax({
						type: "POST",
						url: "/include/php/newsletter.inc.php",
						data: datos,
						contentType: "application/x-www-form-urlencoded",
						beforeSend: function() {
							$("#status").fadeIn("slow");
							$("#status").html("<img src=/include/imagenes/preload.gif class='img_preload'>");
						},
						dataType: "html",
						success: function(datos){
							var respon = datos.split("/");
				            if(respon[0] == 1){
								$("#status").html(respon[1]);
								$("#nEmail").val("");
								setTimeout(function(){ $("#status").fadeOut("slow") }, 3000);
							}else if(respon[0] == 0){
								$("#status").html(respon[1]);
								setTimeout(function(){ $("#status").fadeOut("slow") }, 3000);
							}else if(respon[0] == 2){
								$("#status").html(respon[1]);
								setTimeout(function(){ $("#status").fadeOut("slow") }, 3000);
							}
						}
					});
				}else{
					var idi = jQuery.url.setUrl(window.location.href).param("idi");				
					if(idi == null){ $("#status").html("Email invalid"); }
					else { $("#status").html("Correo Electronico Invalido"); }
					$("#status").fadeIn("slow");
					setTimeout(function(){ $("#status").fadeOut("slow") }, 3000);
				}
		}else{
			var idi = jQuery.url.setUrl(window.location.href).param("idi");				
			if(idi == null){ $("#status").html("Email Empty"); }
			else { $("#status").html("Debe escribir Correo Electronico"); }
			$("#status").fadeIn("slow");
			setTimeout(function(){ $("#status").fadeOut("slow") }, 3000);
		}
	});	//FIN DE BTSUSCRIBE
	
	$("#btCheck").click(function(){
		var email = $("#cjEmail").val();
		var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
		if(email.length > 0){  
				if (filter.test(email)){
					var datos = $("#formReservation").serialize();
					$.ajax({
						type: "POST",
						url: "/include/php/reservacion.inc.php",
						data: datos,
						contentType: "application/x-www-form-urlencoded",
						beforeSend: function() {
							$("#status").fadeIn("slow");
							$("#status").html("<img src=/include/imagenes/preload.gif class='img_preload'>");
						},
						dataType: "html",
						success: function(datos){
							var respon = datos.split("/");
							if(respon[0] == 1){
								$("#status").html(respon[1]);
								$("#nEmail").val("");
								setTimeout(function(){ $("#status").fadeOut("slow") }, 3000);
							}else if(respon[0] == 0){
								$("#status").html(respon[1]);
								setTimeout(function(){ $("#status").fadeOut("slow") }, 3000);
							}
						}
					});
				}else{
					var idi = jQuery.url.setUrl(window.location.href).param("idi");				
					if(idi == null){ $("#status").html("Email invalid"); }
					else { $("#status").html("Correo Electronico Invalido"); }
					setTimeout(function(){ $("#status").fadeOut("slow") }, 3000);
				}
		}else{
			var idi = jQuery.url.setUrl(window.location.href).param("idi");				
			if(idi == null){ $("#status").html("Email Empty"); }
			else { $("#status").html("Debe escribir Correo Electronico"); }
			setTimeout(function(){ $("#status").fadeOut("slow") }, 3000);
		}
	});	//FIN DE BTSUSCRIBE
	
	$('.op_cal').datePicker();
	$('#AD').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#DD').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#DD').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#AD').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
	
	$("#btEnviar").click(function (){
		var datos = $("#formContact").serialize();
		$.ajax({
			type: "POST",
			url: "/include/php/correo.inc.php",
			data: datos,
			contentType: "application/x-www-form-urlencoded",
			beforeSend: function() {
					$("#btEnviar").val(""); 
					$("#btEnviar").addClass("email"); 
			},
			dataType: "html",
			success: function(datos){
				var respon = datos.split("/");
				if(respon[0] == 1){
					$("#status_email").html(respon[1]);
				}else if(respon[0] == 0){
					$("#status_email").html(respon[1]);
				}
				$("#btEnviar").removeClass("email");
				$("#btEnviar").val("Send"); 
				$("#cjName").val("");
				$("#cjEmail").val("");
				$("#cjSubject").val("");
				$("#cjMessage").val("");
			}
		});
	});
});

function tabs(idC,tam){
	var i;
	for(i = 1; i <= tam; i++){
   		var cad = idC.substring(0,2);
		var m = cad+i;
		if(m == idC){ $('#'+idC).show("slow"); } else { $('#'+m).hide("slow"); }
	}
}
