/**
 * Contatti
 *
 * @author			Giovambattista Fazioli
 * @web				http://www.undolog.com
 * @email			g.fazioli@saidmade.com
 * @version			1.0
 * 
 */

var SaidmadeContatti = {
	version		: "1.0",
	filter		: /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i,
	map			: null,
	center		: null,
	win_html	: '<div><strong>Saidmade Srl<\/strong><br /><img src="http://labs.saidmade.com/images/sm-a-80x15.png" /><br/>Via Gregorio Cortese, 10<br />41100 Modena (MO) Italia</div><div class="menu"><a href="http://maps.google.com/maps?f=q&source=s_q&hl=it&geocode=&q=Via+Gregorio+Cortese,+10,+41100+Modena+MO&sll=44.639828,10.941795&sspn=0.011344,0.027895&ie=UTF8&z=16&iwloc=addr">Come arrivare da noi</a></div>',
	marker		: null,
	iconMarker	: null,
	
	init	: function() {
		
		$('input#yourname').focus();

		$('select#subject').change(
			function() {
				switch ( $(this).val() ) {
					case "subject_info":
						SaidmadeContatti.generalInformation();
						break;
					case "subject_marketing":
						SaidmadeContatti.projectPreview(true);
						break;
					case "subject_curriculum":
						SaidmadeContatti.generalInformation();
						SaidmadeContatti.sendCurriculum();
						break;
				}
			}
		);

		$('select#project_type').change(
			function() {
				switch ( $(this).val() ) {
					case "app-iphone":
						SaidmadeContatti.appIPhone();
						break;
					case "app-macos":
						SaidmadeContatti.appMacOS();	
						break;
					case "web":
						SaidmadeContatti.appWeb();
						break;
				}
			}
		);
		$('input:radio[name=web_type]').change(
			function() {
				if($(this).attr('rel') == 'theme') {
					$('p.budget_web').slideDown();
					$('p.budget_app').slideUp();
				} else {
					$('p.budget_web').slideUp();
					$('p.budget_app').slideDown();
				}
			}
		);

		$('form#contacts input#yourname, form#contacts input#email').change(
			function() {
				$(this).data('status', 'ko');
			}
		);


		$('form#contacts').submit(
			function() {

				// Name
				if( $('form#contacts input#yourname').val() == '' ) {
					$('form#contacts input#yourname').css('backgroundColor','#ff742e').stop().animate( {backgroundColor: '#fff'}, {queue:false,duration:1000} ).focus();
					return false;
				}

				// Email
				if( $('form#contacts input#email').val() == '' || !SaidmadeContatti.filter.test( $('form#contacts input#email').val() ) ) {
					$('form#contacts input#email').css('backgroundColor','#ff742e').stop().animate( {backgroundColor: '#fff'}, {queue:false,duration:1000} ).focus();
					return false;
				}

				// Message
				if( $('form#contacts textarea#message').val() == '' ) {
					$('form#contacts textarea#message').css('backgroundColor','#ff742e').stop().animate( {backgroundColor: '#fff'}, {queue:false,duration:1000} ).focus();
					return false;
				}

				if( !$('form#contacts input#check-privacy').is(':checked')  ) {
					alert('ATTENZIONE!!\n\nDevi autorizzare il trattamento dei dati personali!\nLeggi ed autorizza l\'informativa sulla privacy.');
					return false;
				}

				return true;
			}
		);	 
		
		$('form#contacts input.must').blur(
			function() {
				if($(this).data('status') != 'ok') {
					if( $(this)[0].name == "email" ) {
						if (!SaidmadeContatti.filter.test( $(this)[0].value )) {
							$(this).css('backgroundColor','#ff742e').stop().animate({backgroundColor: '#fff'}, {queue:false,duration:1000});
							$(this).data('status', 'ko');
						} else {
							$(this).css('backgroundColor','#af0').stop().animate({backgroundColor: '#fff'}, {queue:false,duration:1000});
							$(this).data('status', 'ok');
						}
						return;
					}

					if( $(this)[0].value == "" ) {
						$(this).css('backgroundColor','#ff742e').stop().animate({backgroundColor: '#fff'});
						$(this).data('status', 'ko');
					} else {
						$(this).css('backgroundColor','#af0').stop().animate({backgroundColor: '#fff'});
						$(this).data('status', 'ok');
					}
				}
			}
		);
	},

	projectPreview: function( show ) {
		if( show ) {
			$('p.project_type, p.phone, p.preferer_call, fieldset.project_type_info').slideDown();
		} else  {

		}
	},

	generalInformation: function() {
		$('p.project_type, p.phone, p.preferer_call, fieldset.project_type_info, p.filename').slideUp();
	},

	sendCurriculum: function() {
		$('p.phone, p.preferer_call, p.filename').slideDown();
	},

	appIPhone: function() {
		$('p.device, p.app_iphone_type, p.budget_app, p.filename').slideDown();
		$('p.app_macos_type, p.web_type, p.budget_web').slideUp();
	},

	appMacOS: function() {
		$('p.app_macos_type, p.budget_app, p.filename').slideDown();
		$('p.device, p.app_iphone_type, p.web_type, p.budget_web').slideUp();
	},

	appWeb: function() {
		$('p.web_type, p.budget_app, p.filename').slideDown();
		$('p.device, p.app_iphone_type, p.app_macos_type, p.budget_web').slideUp();
	}
}; 