// Init Scavolini Store
$(function(){
		init_mailto();
		$('form').append('<input type="hidden" name="can_submit" value="' + Math.random() + '" />');
		$('#info_privacy').hide();
		PulisciInput("input.autoclean");
		$('#menu a[href$=' + location.pathname + location.search + ']').addClass('on');
		$('.fancy').fancybox({'titleShow':false});
		if(jQuery.datepicker){
			$.datepicker.regional['it'] = {
				closeText: 'Chiudi',
				prevText: '&#x3c; Prec',
				nextText: 'Succ &#x3e;',
				currentText: 'Oggi',
				monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno',
				'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
				monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu',
				'Lug','Ago','Set','Ott','Nov','Dic'],
				dayNames: ['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Venerd&#236','Sabato'],
				dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
				dayNamesMin: ['Do','Lu','Ma','Me','Gio','Ve','Sa'],
				dateFormat: 'dd/mm/yy', firstDay: 1,
				isRTL: false};
			$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['it']));

			$('.datepicker').datepicker({
					changeMonth: true,
					changeYear: true,
					dateFormat: 'dd/mm/yy',
					minDate: new Date(),
					yearRange: 'c-0:c+1'
				});
		
			}
	})

function init_mailto(){
		$('a.mailto').each(function(){
			var e=$(this).attr('href').replace('##','@').replace('#','').split('').reverse().join('');
			$(this).attr('href','mailto:' + e);
			$(this).html(e);
		});
	}
function frm_richiesta_info(){
	var self=this;
	self.show_hide = function (){document.getElementById('d_frm_richiesta_info').style.display=(document.getElementById('d_frm_richiesta_info').style.display=='block'?'none':'block');}
	self.checkMail = function (te)
	{
		var x = te;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) return true;
		else return false;
	}	
	self.validate = function (){
		var message="";
		var the_form=document.getElementById('frm_richiesta_info');
		if (the_form.nominativo.value.length==0){
			message+="Riempire il campo obbligatorio \"Nome e Cognome\"!\n";
		}
		if (1==0 && the_form.telefono.value.length==0){
			message+="Riempire il campo obbligatorio \"telefono\"!\n";
		}
		if (!self.checkMail(the_form.email.value)){
			message+="Riempire il campo obbligatorio \"email\" con un indirizzo di posta valido!\n";
		}
		if (the_form.richiesta.value.length==0){
			message+="Riempire il campo obbligatorio \"richiesta\"!\n";
		}
		if (!the_form.condizioni_privacy.checked){
			message+="E' obbligatorio accettare le condizioni della privacy spuntando la casella \"Accetto le condizioni sulla privacy\"!\n";
		}
		if(message.length){alert(message); return false;}
		return true;
	}

	self.validate_prenota = function (){
		var message="";
		var the_form=document.getElementById('frm_richiesta_info');
		if (the_form.nominativo.value.length==0){
			message+="Riempire il campo obbligatorio \"Nome e Cognome\"!\n";
		}
		if (1==0 && the_form.telefono.value.length==0){
			message+="Riempire il campo obbligatorio \"telefono\"!\n";
		}
		if (!self.checkMail(the_form.email.value)){
			message+="Riempire il campo obbligatorio \"email\" con un indirizzo di posta valido!\n";
		}
		if (1==0 && the_form.richiesta.value.length==0){
			message+="Riempire il campo obbligatorio \"richiesta\"!\n";
		}
		if (!the_form.condizioni_privacy.checked){
			message+="E' obbligatorio accettare le condizioni della privacy spuntando la casella \"Accetto le condizioni sulla privacy\"!\n";
		}
		if(message.length){alert(message); return false;}
		return true;
	}

	return self;
}
var frm_r_info = new frm_richiesta_info();

function PulisciInput(arr_input) {
	$(arr_input).each(function(){
			if($(this).length){
				$(this)[0].tmp_input_val=$(this).val();
			}
			$(this).focus( function () {
										if (this.value==this.tmp_input_val) {
											this.value='';
										}
									}						  
						  );
			$(this).blur( function () {
								if (this.value=='') {
									this.value=this.tmp_input_val;
								}
							}
						  );
							   
		});
}
/* Slideshow in home page */
($)(function(){$('#home').each(function(){
		var s = 'http://www.scavolini.com/scavolini_store_common/slideshow_js.asp?a=b';
		$.getScript(s, function(data, textStatus){
  				slideshow_js();
			});							 
		});
	});
