//======================================
//  FUNZIONE CHE APRE UNA FINESTRA 
//======================================
function apripagina(pagina,dx,dy,rsz,scrl,pos,menub){
	
	var settings, TopPosition, LeftPosition;

	//	screen.width    DIMENSIONE DELLO SCHERMO IN LARGHEZZA	
	//	screen.height  	DIMENSIONE DELLO SCHERMO IN ALTEZZA
	//	dx				DIMENSIONE DELLA FINESTRA IN LARGHEZZA
	//	dy				DIMENSIONE DELLA FINESTRA IN ALTEZZA

	if (pos==""){
		pos = "center";
	}
	if (pos=="center"){
		// allineamento della finestra in mezzo
		TopPosition = ((screen.height) / 2) - (dy/2);
		// allineamento della finestra in mezzo
		LeftPosition = ((screen.width) / 2) - (dx/2);
	}
	if (pos=="right"){
		// allineamento della finestra in alto a destra
		TopPosition = 0;
		// allineamento della finestra a destra
		LeftPosition = (screen.width) - dx -10;
	}
	if (pos=="left"){
		// allineamento della finestra in alto a sinistra
		TopPosition = 0;
		// allineamento della finestra a destra
		LeftPosition = 0;
	}
	
	if (menub==""){
		menub = "yes";
	}
		
	// settaggio delle caratteristiche della finestra da aprire
	settings ='height='+dy+',width='+dx+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrl+',resizable='+rsz+',titlebar=no,menubar='+menub;
	
	// se esite gia' una finestra aperta allora la chiudo e la distruggo;
	//if (win != null){
	//	win.close();
	//	win = null;
	//}
	
	// apro una nuova finestra e le assegno il focus il nome della nuova finestra
	// (secondo campo nell'elenco parametri) non deve contenere nulla ;
	
	win = window.open(pagina,'',settings)
	win.window.focus();
}

//=====================================================
//  FUNZIONE CHE CONTROLLA IL CAMPO EMAIL DI UN FORM
//=====================================================			
function isEmailOk(data) {
  if (data.indexOf(".") != -1) {
      if (data.indexOf("@") != -1)  { 
	      return true;
		  }
		}
	else return false;	  
}

//=============================================================
//  FUNZIONE CHE CONTROLLA IL RIEMPIMENTO DEL CAMPO DI UN FORM
//=============================================================		
function isSpace(data) {
	var contr2=0;
   	for(var i=0; i < data.length; i++){
		if(data.substring(i, i+1) != " ")
	   		contr2=1; 
	}   
	if  (contr2==1)   
		return(false);  
return(true);
}

//=============================================================
//  FUNZIONE CHE CONTROLLA I CAMPI DI UN FORM ( FormN )
//=============================================================			
function checkRequiredFields(lang, tipo) {
		
	var message = new Array();
	var errorLevel;
	
	message[0]  = "";
	
	switch (lang) {
		case "it":
			message[1] = "Inserisci il tuo indirizzo Email";
			message[2] = "Per poter gestire la vostra richiesta di informazioni è necessario il consenso al trattamento dei dati per i fini elencati nell'informativa.";
			break; 
	   	case "uk":
			message[1] = "Insert your Email address.";
			message[2] = "";
			break; 
	   	default :
			message[1] = "Insert your Email address.";
			message[2] = "";
			break; 
	} 
		
	errorLevel = 0;  
	
    if ((errorLevel == 0) && ((document.FormN.email.value.length == 0) || isSpace(document.FormN.email.value))) {
		errorLevel = 1;	
		document.FormN.email.focus();
	}
	if ((errorLevel == 0) && (!(isEmailOk(document.FormN.email.value)))) {
		errorLevel = 1;
		document.FormN.email.focus();
	}
	
	if ((errorLevel == 0) && (!(document.FormN.consenso_privacy_1.checked))) {
		errorLevel = 2;
		document.FormN.consenso_privacy_1.focus();
	}
		
	if (errorLevel > 0 ) { 
		alert(message[errorLevel]); 
		
		if (tipo == 'submit') {
			return false;
		}
	} else{
		if (tipo == 'link') {
			document.FormN.submit();
		} else{
			return true;
		}
	}
}

//=============================================================
//  FUNZIONE CHE GESTISCE LA CLASSE ATTIVO SUI MENU
//=============================================================	
function setMenuAttivo( menuId ) {
	
	$(".soloperhome").hide();
	for (var i = 1; i <= menuItemCounter; i++) {
		document.getElementById('menu-item-' + i).className = '';
	}
	if (menuId > 0) {
		document.getElementById('menu-item-' + menuId).className = 'attivo';
	}
	
	return true;
}

//=============================================================
//  FUNZIONE CHE GESTISCE LA CHIAMATA AJAX SULLA
//  VISUALIZZAZIONE DEI PUNTI VENDITA
//=============================================================	
function viewPuntiVendita( lang ) {
	
	var s = document.getElementById('id_provincia');
	if (s.selectedIndex == 0) {
		if (lang == 'it') {
			alert('Seleziona una provincia!');
		}
		else {
			alert('Select a province!');
		}
	}
	else {
		var id_provincia = s.options[s.selectedIndex].value;
		var ajaxURL = '/' + lang + '/page-punti-vendita-elenco.asp?id_provincia=' + id_provincia;
		//alert(ajaxURL);
		ajaxPageCall(ajaxURL, 'colonnaDx');
		checkScrollDelayed('elenco-punti-vendita2', 'display', 'freccia-su-punti', 'freccia-giu-punti');
	}
	return false;
}

//=============================================================
//  FUNZIONE CHE GESTISCE LA VISUALIZZAZIONE DELLE FRECCE
//=============================================================	
function checkScroll( fixedDivId, contentDivId, arrowUpId, arrowDownId ) {
	
	if (document.getElementById(fixedDivId)) {
		if (document.getElementById(contentDivId).clientHeight < document.getElementById(fixedDivId).clientHeight) {
			document.getElementById(arrowUpId).style.display = 'none';
			document.getElementById(arrowDownId).style.display = 'none';
		}
	}

}

function checkScrollDelayed( fixedDivId, contentDivId, arrowUpId, arrowDownId ) {

	//alert('pippo');
	setTimeout("checkScroll('" + fixedDivId + "', '" + contentDivId + "', '" + arrowUpId + "', '" + arrowDownId + "')", 1000)
	return true;
}
