$(function(){	
	
	//Fancy forms
	$('form.fancy, form.ftinsa').jqTransform();
	
	$('form.fancy').validate({
		rules: {
			firstname: {
			  required: true,
			  number: false,
			  minlength: 3
			},
			lastname:{
			  required: true,
			  number: false,
			  minlength: 3
			},
			address:{
			  required: true,
			  minlength: 3
			},
			accept: "required",
			zip: {
			  required: true,
			  number: true,
			  minlength: 5,
			  maxlength: 5
			},
			city: "required",
			state: "required",
			email: {
				required: true,
				email: true
				//remote: "emails.php"
			}
		},
		
		messages: {
			firstname: { required: "Introduzca su nombre.<br /> ", minlength: "Nombre mínimo 3 caracteres.<br /> " },
			lastname:  { required: "Introduzca su(s) apellido(s).<br /> ", minlength: "Apellido(s) mínimo 3 caracteres.<br /> " },
			address: { required: "Introduzca la dirección.<br /> ", minlength: "Mínimo 3 caracteres.<br /> " },
			zip: { required: "Introduzca el código postal.<br /> ", minlength: "C.P. debe tener 5 dígitos.<br /> " },
			city: { required: "Introduzca la localidad.<br /> " },
			state: { required: "Seleccione la provincia.<br /> " },
			email: {
				required: "Introduzca un correo electrónico válido.<br /> ",
				minlength: "Introduzca un correo electrónico válido.<br /> ",
				remote: function() { alert("Remote"); }
			},
			accept: "Acepte las condiciones de uso."
		},
		errorLabelContainer: $("form div.error"),
		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next().next() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.next() );
			else
				error.appendTo( element.parent().next() );
		},
		// specifying a submitHandler prevents the default submit, good for the demo
		submitHandler: function() {
			//alert("submitted!");
			this.submit();
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});
	
	$('form.ftinsa').validate({
		rules: {
			nombre: {
			  required: true,
			  number: false,
			  minlength: 3
			},
			apellidos:{
			  required: true,
			  number: false,
			  minlength: 3
			},
			viapublica1:{
			  required: true,
			  minlength: 3
			},
			accept: "required",
			cp: {
			  required: false,
			  number: true,
			  minlength: 5,
			  maxlength: 5
			},
			poblacion1: "required",
			provincia: "required",
			email: {
				required: false,
				email: true
				//remote: "emails.php"
			}
		},
		
		messages: {
			nombre: { required: "Introduzca su nombre.<br /> ", minlength: "Nombre mínimo 3 caracteres.<br /> " },
			apellidos:  { required: "Introduzca su(s) apellido(s).<br /> ", minlength: "Apellido(s) mínimo 3 caracteres.<br /> " },
			viapublica1: { required: "Introduzca la dirección.<br /> ", minlength: "Mínimo 3 caracteres.<br /> " },
			cp: { required: "Introduzca el código postal.<br /> ", minlength: "C.P. debe tener 5 dígitos.<br /> " },
			poblacion1: { required: "Introduzca la localidad.<br /> " },
			provincia: { required: "Seleccione la provincia.<br /> " },
			/*tipo: { required: "Seleccione su documento de identidad.<br /> " },
			nif: { required: "Introduzca su documento de identidad.<br /> " },*/
			email: {
				required: "Introduzca un correo electrónico válido.<br /> ",
				minlength: "Introduzca un correo electrónico válido.<br /> ",
				remote: function() { alert("Remote"); }
			},
			accept: "Acepte las condiciones de uso."
		},
		errorLabelContainer: $("form div.error"),
		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next().next() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.next() );
			else
				error.appendTo( element.parent().next() );
		},
		// specifying a submitHandler prevents the default submit, good for the demo
		submitHandler: function() {
			//alert("submitted!");
			this.submit();
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});
	/**/
	
	
	
	// DROPDOWN
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.topnav li span").click(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	
	
});//Close Function
