// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MenuImgPreload() {
  MM_preloadImages(
	  '/immagini/menu_nav/chi_siamo_hover.gif',
	  '/immagini/menu_nav/contatti_hover.gif',
	  '/immagini/menu_nav/corsi_hover.gif',
	  '/immagini/menu_nav/partner_hover.gif',
	  '/immagini/menu_nav/sede_hover.gif',
	  '/immagini/menu_nav/links_hover.gif'
  )
}

function CheckBoxInit() {
	val = document.form_input.soggetto.value;
	if (val) {
		var a = val.split(/\|/);		
		n = a.length;
		for (c=0; c<n; ++c) {
			document.form_input.box_soggetto[a[c]].checked = true;
		}
	}
}

function CheckBoxUpd() {
		n = document.form_input.box_soggetto.length;
		document.form_input.soggetto.value = "";
		for (c=0; c<n; ++c) {
			if (document.form_input.box_soggetto[c].checked == true) {
			document.form_input.soggetto.value = document.form_input.soggetto.value+c+"|";
			}
		}
}

function PopupPic(sPicURL) { 
// dimensioni iniziali finestra prima che si riadatti
 popwidth = 250;
 popheight = 400;
 // apre il popup e passa la url immagine
 window.open( "/popups/pop_fit.html?"+sPicURL, "", 
 "left=" + Math.floor((screen.width - popwidth) / 2) + ",top=" + Math.floor((screen.height - popheight) / 2) +
 "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width="+popwidth+",height="+popheight); 
}

function PopAmico(page) {
popwidth = 500;
popheight = 300;
OpenWin = this.open(page, "PopWin2", "toolbar=no, menubar=no, location=no, scrollbars=no, resizable=no, width="+popwidth+", height="+popheight+", left=" + Math.floor((screen.width - popwidth) / 2) + ", top=" + Math.floor((screen.height - popheight) / 2));
}

function Credits(page) {
popwidth = 300;
popheight = 270;
OpenWin = this.open(page, "PopWin3", "toolbar=no, menubar=no, location=no, scrollbars=no, resizable=no, width="+popwidth+", height="+popheight+", left=" + Math.floor((screen.width - popwidth) / 2) + ", top=" + Math.floor((screen.height - popheight) / 2));
};

function controllo_ricerca(theForm){
	if (theForm.testo_ricerca.value == "") {
    	alert("Per favore inserire l'oggetto della ricerca.\nGrazie.");
    	theForm.testo_ricerca.focus();
    	return (false);
	}
}

function submit_ricerca(theForm){
	if (theForm.testo_ricerca.value == "") {
    	alert("Per favore inserire l'oggetto della ricerca.\nGrazie.");
    	theForm.testo_ricerca.focus();
	} else {
		  theForm.submit()
	}		
}

function check_contatti(theForm){
	if (theForm.nome.value == "") {
    	alert("Per favore inserire proprio il nome, grazie.");
    	theForm.nome.focus();
    	return (false);
	}
	if (theForm.cognome.value == "") {
    	alert("Per favore inserire proprio il cognome, grazie.");
    	theForm.cognome.focus();
    	return (false);
	}
	if (theForm.from.value == "") {
    	alert("Per favore inserire il proprio indirizzo E-Mail, grazie.");
    	theForm.from.focus();
    	return (false);
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(theForm.from.value))) {
		alert("Indirizzo E-Mail non valido, si prega di verificarlo");
		theForm.from.focus();
		return (false);
	}
	if (theForm.messaggio.value == "") {
    	alert("Per favore inserire il testo del messaggio, grazie.");
    	theForm.messaggio.focus();
    	return (false);
	}
	if (!theForm.privacy.checked) {
    	alert("Per favore acconsentire al trattamento dei dati personali, grazie.");
      theForm.privacy.focus();
      return (false);
	}
	if (theForm.code.value == "") {
    alert("Per favore inserire il codice di sicurezza visualizzato, grazie.");
    theForm.code.focus();
    return (false);
	}			
}

function check_iscr_corsi(theForm){
	if (theForm.nome.value == "") {
    	alert("Per favore inserire proprio il nome, grazie.");
    	theForm.nome.focus();
    	return (false);
	}
	if (theForm.cognome.value == "") {
    	alert("Per favore inserire proprio il cognome, grazie.");
    	theForm.cognome.focus();
    	return (false);
	}
	if (theForm.telefono.value == "") {
    	alert("Per favore inserire il proprio numero di telefono, grazie.");
    	theForm.telefono.focus();
    	return (false);
	}
	if (theForm.from.value == "") {
    	alert("Per favore inserire il proprio indirizzo E-Mail, grazie.");
    	theForm.from.focus();
    	return (false);
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(theForm.from.value))) {
		alert("Indirizzo E-Mail non valido, si prega di verificarlo");
		theForm.from.focus();
		return (false);
	}
	if (theForm.tipo_cont.value == "") {
    	alert("Per favore scegliere la tipologia contrattuale, grazie.");
    	theForm.tipo_cont.focus();
    	return (false);
	}
	if (theForm.rag_soc_azi.value == "") {
    	alert("Per favore inserire la ragione sociale dell'azienda, grazie.");
    	theForm.rag_soc_azi.focus();
    	return (false);
	}
	if (theForm.indirizzo_azi.value == "") {
    	alert("Per favore inserire l'indirizzo dell'azienda, grazie.");
    	theForm.indirizzo_azi.focus();
    	return (false);
	}
	if (theForm.citta_azi.value == "") {
    	alert("Per favore inserire la cittą in cui ha sede l'azienda, grazie.");
    	theForm.citta_azi.focus();
    	return (false);
	}
	if (theForm.provincia_azi.value == "") {
    	alert("Per favore inserire la provincia in cui ha sede l'azienda, grazie.");
    	theForm.provincia_azi.focus();
    	return (false);
	}
	if (theForm.tel_azi.value == "") {
    	alert("Per favore inserire il numero di telefono dell'azienda, grazie.");
    	theForm.tel_azi.focus();
    	return (false);
	}
	if (theForm.attivita_azi.value == "") {
    	alert("Per favore inserire l'attivitą svolta dall'azienda, grazie.");
    	theForm.attivita_azi.focus();
    	return (false);
	}	
	if (!theForm.privacy.checked) {
    	alert("Per favore acconsentire al trattamento dei dati personali, grazie.");
      theForm.privacy.focus();
      return (false);
	}
	if (theForm.code.value == "") {
    alert("Per favore inserire il codice di sicurezza visualizzato, grazie.");
    theForm.code.focus();
    return (false);
	}			
}

function URLEncode(s)
{
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = s;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	
	return encoded;
};

function URLDecode(s)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = s;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   
   return plaintext;
};

/*

var aumentoDimensioneTesto = location.search.substring(location.search.indexOf("STB=")+4, (location.search.substr(location.search.indexOf("STB=")+4).indexOf(";"))+(location.search.indexOf("STB=")+4));

dimensionamentoTesto();

function writeIcoText(){
  if(aumentoDimensioneTesto!="BIG"){
		document.write('<a href="javascript:manualTextResize()"><img src="/immagini/azioni/txt_big.gif" border="0" alt="Ingrandisci il testo" name="icoTextResize" hspace="3" align="absmiddle"></a>');
  }
  else{
		document.write('<a href="javascript:manualTextResize()"><img src="/immagini/azioni/txt_small.gif" border="0" alt="Riduci il testo" name="icoTextResize" hspace="3" align="absmiddle"></a>');
  }
}

function manualTextResize(){
	  if(document.all){	  
				if(aumentoDimensioneTesto!="BIG"){
					  aumentoDimensioneTesto = 'BIG';	  
					  styleFile.href="/css/stili_fabbrica_grandi.css";
					  document.images['icoTextResize'].src = "/immagini/azioni/txt_small.gif"
					  document.images['icoTextResize'].alt = "Riduci il testo";
				}
				else{
					  aumentoDimensioneTesto = '';
					  styleFile.href="/css/stili_fabbrica.css";
					  document.images['icoTextResize'].src = "/immagini/azioni/txt_big.gif";
					  document.images['icoTextResize'].alt = "Ingrandisci il testo";	  
				}	
	  } else {
					 if(aumentoDimensioneTesto!="BIG"){
						  if (location.href.indexOf("?") <= 0) {
								location.href = location.href + "?STB=BIG;";
						  } else {
								location.href = location.href + "&STB=BIG;";
						  }
					}else{
							location.href = location.href.substr(0, location.href.indexOf("STB=") - 1);
					}
	  }	
}

function dimensionamentoTesto(){
  if(aumentoDimensioneTesto=="BIG"){
		if(document.all){
		  document.write('<link id="styleFile" rel="stylesheet" href="/css/stili_fabbrica_grandi.css">');
		}
		else{
		  document.write('<link rel="stylesheet" href="/css/stili_fabbrica_grandi.css">');
		}
  }
  else{
		if(document.all){
		  document.write('<link id="styleFile" rel="stylesheet" href="/css/stili_fabbrica.css">');
		}
		else{
		  document.write('<link rel="stylesheet" href="/css/stili_fabbrica.css">');
		}
  }
}

*/