/*
19/11/2008
Eurosarda application JS file
author: Alessandro Chinazzo
*/

$(document).ready(function(){
	$('#header ul li').hover(function(){
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	if ( $('#map').length > 0 ) {
		load('it');
		$('#torino').click(function() {
			load('to');
		});
	
		$('#sassari').click(function() {
			load('ss');
		});
	
		$('#milano').click(function() {
			load('mi');
		});
	
		$('#cagliari').click(function() {
			load('ca');
		});
	}
	
	$(".input_field").before("<span class=\"inputfield-left\"></span>");
	$(".input_field").after("<span class=\"inputfield-right\"></span>");
	
	/*$("textarea").before("<span class=\"textarea-left\"></span>");
	$("textarea").after("<span class=\"textarea-right\"></span>");*/
	
	if ( $("form.contatti").length > 0 ) {
	$("form.contatti").validate({
		submitHandler: function(form) {
			form.submit();
		},
		errorPlacement: function(error, element) {
			if (element.attr("id") == 'input_message') {
				error.insertAfter(element);
			} else if (element.attr("id") == 'checkbox_privacy') {
				error.insertAfter(element.parent("label"));
			} else {
				error.insertAfter(element.next("span.inputfield-right"));
			}
		},
			messages: {
				checkbox_privacy: "<br />E' necessario autorizzare il trattamento dei dati personali."
			}
	});
	}
	
	
	if ( $("form.preventivo").length > 0 ) {
	$("form.preventivo").validate({
		errorPlacement: function(error, element) {
			if (element.attr("id") == 'checkbox_privacy') {
				error.insertAfter(element.parent("label"));
			} else {
				error.insertAfter(element.next("span.inputfield-right"));
			}
		},
			messages: {
				input_packages_number: {
					number: "Il valore deve essere numerico."
				},
				checkbox_privacy: "<br />E' necessario autorizzare il trattamento dei dati personali."
			}
	});
	}
	
});

$(document).unload(function(){
	GUnload();
});
