//Watch out: jQuery namespace is already used for Prototype

ICON_SPAN = 16;

jQuery(function() {
    
    jQuery("#hide1 > li:last,#hide2 > li:last").addClass("no-border");
    
    jQuery(".navigaPerSettore, .navigaPerImpianto").click(function(){
        jQuery(this).next().slideToggle("fast");
    });

    jQuery("div.label").each(function () {
        var me = this;
        jQuery(":input", this).focus(function () {
            me.css({
                "backgroundColor": "#efefef",
                "color": "#000"
            }).find("span").css({"color": "#000"});
        }).blur(function () {
            me.css({
                "backgroundColor": "#fff",
                "color": "#000"
            }).find("span").css({"color": "#fff"});
        });
        me = null;
    });
});



/**
 * This function is not used anymore
 */

function Popup(url, nome, caratteristiche) {

	x = (screen.width/2)-350;
	y = (screen.height/2)-190;

    finestra = window.open(url, nome, caratteristiche+',screenX='+x+',screenY='+y+',top='+y+',left='+x);

}

function smodal(url, width, height){
    jQuery("<div style=\"width:"+(width+ICON_SPAN)+"px; background-color: #ffffff;\"><iframe src=\""+url+"\" frameborder=\"0\" style=\"width: "+width+"px; height: "+height+"px;\">Iframe non supportati. Spiacenti.</iframe></div>").modal({
        overlayCss:{
            backgroundColor: "#000000",
            cursor: "pointer"
        },
        opacity: 80,
        close: true,
        overlayClose: true
    });
//    console.log(width,height);
}

function popup(url, caratteristiche, width, height){
    if(jQuery){
        if(!jQuery.modal){
            jQuery.getScript('/js/jquery.simplemodal.1.4.1.min.js', function(){
                smodal(url, width, height);
            });
        }else{
            smodal(url, width, height);
        }
    }else{
    
        x = (screen.width/2)-375;
        y = (screen.height/2)-190;
    
        finestra = window.open(url, "",caratteristiche + ",width="+width+",height="+height+",screenX="+x+",screenY="+y+",top="+y+",left="+x);
    }
} 


function ChkCampi() {
	if (document.forms[0].nome.value  == ""){
		alert("Il campo \"Nome\" non puņ essere vuoto");
		document.forms[0].nome.focus();
		return false;
	}
	
	if (document.forms[0].cognome.value  == ""){
		alert("Il campo \"Cognome\" non puņ essere vuoto");
		document.forms[0].cognome.focus();
		return false;
	}
	
	if (document.forms[0].telefono.value  == ""){
		alert("Il campo \"Telefono\" non puņ essere vuoto");
		document.forms[0].telefono.focus();
		return false;
	}
	
	if (document.forms[0].email.value  == ""){
		alert("Il campo \"E-mail\" non puņ essere vuoto");
		document.forms[0].email.focus();
		return false;
	}
	
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(document.forms[0].email.value)){
		alert("L\'indirizzo e-mail inserito non č in un formato corretto");
		document.forms[0].email.focus();
		return false;
	}
	
	if (document.forms[0].richiesta.value  == ""){
		alert("Il campo \"Richiesta\" non puņ essere vuoto");
		document.forms[0].richiesta.focus();
		return false;
	}
	
	if (!document.forms[0].chk_privacy.checked) {
		alert("E\' necessario accettare accettare la clausola sulla privacy");
		document.forms[0].chk_privacy.focus();
		return false;
	}
	
	return true;
	
}
