/**
 * @author batman
 */
$(document).ready(

	function(){
		
		$("ul.sf-menu").superfish(); 

		$('#azienda_gallery div:first').cycle();
		
		
		

		// tolgo il link all'ultima carta top
		$('.linee_carta_top_last').click(
			function() {
				return false;
			}
		);


		// lightbox singolo suilla foto principale del prodotto
		$('.prodotto_lightbox').fancybox(
			{
				'hideOnContentClick': true,
				'zoomSpeedIn': 500,
				'zoomSpeedOut': 500,
				'imageScale': true,
				'titlePosition': 'inside'
 			}
		);
		
		// lo tolgo per l'industriale
		$('.prodotto_lightboxx').click(
			function() {
				return false;
			}
		);
		

		$('#polinlive_gallery a').fancybox(
			{
				'hideOnContentClick': true,
				'zoomSpeedIn': 500,
				'zoomSpeedOut': 500,
				'frameWidth': 640,
				'frameHeight': 364
 			}
		);
		
		// skjdfh skdfhj 
		$(document).ready(function(){
		    $(document).bind("contextmenu",function(e){
		        return false;
		    });
		});
		
		$('.is_selected').next('ul').delay(300).slideToggle(1000);
		
		// ritocchi artigianale
		$('.sotto_menu_ver_1:first').css("border", "none");
		$('.is_aperto').next('ul').css("padding-bottom", "10px");
		
		// installazioni verniciatura
		$('.installazioni').fancybox();
		
		// scroller installazioni
		$('#installazioni_scroller').cycle(
			{
				'fx': 'scrollHorz',
		    'next': '#next',
				'prev': '#prev',
				'timeout': 0 
			}
		);
		

	}

);




function poptastic(url) {
	var newwindow=window.open(url,'name','height=400,width=600,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

/*
Da Precedente WebMaster => non funziona il controllo sul formato email!!!!
*/
/*
$('#contatti_form input').keypress(
			function() {
				$(this).removeClass("campo_obbligatorio");			
			}
		);
		
		$('#contatti_form').submit(
			function() {
				fields = Array(
					Array("#nomeragsoc", ""),
					Array("#cognome", ""),
					Array("#email", ""),
					Array("#paese", ""),
					Array("#citta", ""),
					Array("#telefono", "")					
				);

				for(i=0; i<fields.length; i++) {
					if($(fields[i][1]=="email") && !controllaEmail($(fields[i][0]).val())){
						campoFasullo(fields[i][0]);
						return false;	
					}
				}
				return true;				
			}
		);
		
		$('#login_form').submit(
			function() {
				$.ajax(
					{
						type: "GET",
						url: $('#ajax_dir').val()+'/artigianale/ajax/checklogin.php',
						data: 'usr='+$('#main_username').val()+'&pwd='+$.md5($('#main_password').val()),
						success: function(msg) {
							if(msg>0) {
								location.href='/polin/artigianale/index.php';	
							}
							else {
								alert('Accesso negato.\nUsername e/o password errate.');
							}
						}
					}
				);
				return false;
			}
		);
function campoFasullo(campo) {
	$(campo).addClass("campo_obbligatorio");
	alert('compilare correttamente il campo evidenziato' + campo);
	$(campo).focus();
	return false;					
}

function controllaEmail(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);var res=1;if (str.indexOf(at)==-1){
		res=0;
	}
	else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		res=0;
	}
	else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		res=0;
	}
	else if (str.indexOf(at,(lat+1))!=-1){
		res=0;
	}
	else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		res=0;
	}
	else if (str.indexOf(dot,(lat+2))==-1){
		res=0;
	}
	else if (str.indexOf(" ")!=-1){
		res=0;
	}
	if(res==1) {
		return true;
	}
	else {
		return false;
	}					
}
*/

/* Controllo sul submit form */
function autoSelect(selectTarget) {
 	if(selectTarget != null && ((selectTarget.childNodes.length == 1
      && selectTarget.childNodes[0].nodeName == "#text") || (selectTarget.tagName == "INPUT"
      && selectTarget.type == "text"))) {
  		if(selectTarget.tagName == 'TEXTAREA' || (selectTarget.tagName == "INPUT" && selectTarget.type == "text")) {
  			 selectTarget.select();
  		} 
		
 	}
}
function confermaCampo(entered1,entered2, alertbox) {
 with (entered1,entered2){
		if (entered1.value != entered2.value){
			if (alertbox!="") {
				alert(alertbox);
			} return false;
			}else {
				return true;
			}
	}
}

function emailvalidation(entered, alertbox){
	with (entered){
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;
			if (apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2) 
			{
				if (alertbox) {
					alert(alertbox);
				} return false;
			}else {
				return true;
			}
	}
}
function emptyvalidation(entered, alertbox){
	with (entered){
		if (value==null || value=="" || value.search("Seleziona") != -1){
			if (alertbox!="") {
				alert(alertbox);
			} return false;
			}else {
				return true;
			}
	}
}
function checkboxvalidation(entered, alertbox){
	with (entered){
		if (checked == false){
			if (alertbox!="") {
				alert(alertbox);
			} return false;
			}else {
				return true;
			}
		}
	}
function checkradio(entered, alertbox) {
	myOption = -1;
	for (i=entered.length-1; i > -1; i--) {
		if (entered[i].checked) {
			myOption = i; 
			i = -1;
		}
	}
	if (myOption == -1) {
		alert(alertbox);
		return false;
	}else {
		return true;
	}
}



/* ################################# */
function validaForm1(thisform){
	with (thisform){
		if (checkradio(infotype,"Selezionare Tecnico o Commerciale")==false) {
			 return false;
		}
		if (emptyvalidation(nomeragsoc,"!!! Compilare i campi obbligatori !!!")==false) {
			autoSelect(nomeragsoc); return false;
		}
		if (emptyvalidation(cognome,"!!! Compilare i campi obbligatori !!!")==false) {
			autoSelect(cognome); return false;
		}
		if (emailvalidation(email,"!!! Compilare i campi obbligatori !!!")==false) {
			autoSelect(email); return false;
		}
		if (emptyvalidation(paese,"!!! Compilare i campi obbligatori !!!")==false) {
			autoSelect(paese); return false;
		}
		if (emptyvalidation(citta,"!!! Compilare i campi obbligatori !!!")==false) {
			autoSelect(citta); return false;
		}
		if (emptyvalidation(telefono,"!!! Compilare i campi obbligatori !!!")==false) {
			autoSelect(telefono); return false;
		}
		if (checkboxvalidation(privacy,"!!! Compilare i campi obbligatori !!!")==false) {
			autoSelect(privacy); return false;
		}
		
	}
}

