//  DATA CREAZIONE: 01-07-2003;
//  DATA MODIFICA: 01-07-2003;
//  VERSIONE: 2003.1.0;
//  AUTORE: C.Lanza;

/* Variabile che definisce il tipo di browser
   va così utilizzata

      Netscape 4.x
      if (is.ns4) {

      Internet Explorer 4.x
      if (is.ie4) {

      Internet Explorer 5.x e 6.x
      if (is.ie5) {

      Netscape 6.x e 7.x
      if (is.ns6) {
*/
var is;

// Variabile per la visualizzazione del Menu di destra:
// False (0) - versione semplificata
// True  (1) - versione completa
var menuDestraOK = 0;


// Variabile che definisce l'esistenza o meno del plugin per Flash
var PluginFlash = false;

// Variabile per la gestione sella selezione dei punti vendita dal menu di destra

var DV = new DynamicCombo("PROVINCIA","REGIONE");
    DV.addOptions("0","Tutte","0");
    DV.addOptions("abruzzo","Tutte","0","L'Aquila","aquila","Pescara","pescara","Teramo","teramo","Chieti","chieti");
    DV.addOptions("calabria","Cosenza","cosenza");
    DV.addOptions("campania","Casoria (NA)","casoria","Nola (NA)","nola","Benevento","benevento");
    DV.addOptions("emilia","Tutte","0","Reggio Emilia","reggio","Bologna","bologna","Casalecchio (BO)","casalecchio","Ferrara","ferrara","Forli","savignano","Imola","imola","Parma","parma","Modena","modena","Ravenna","ravenna","Piacenza","piacenza");
    DV.addOptions("friuli","Tutte","0","Trieste","trieste","Udine","tavagnacco");
    DV.addOptions("lazio","Roma","roma");
    DV.addOptions("liguria","Genova","genova");
    DV.addOptions("lombardia","Tutte","0", "Boltiere", "boltiere", "Castelcovati", "castelcovati", "Chiari", "chiari", "Comezzano-Cizzago", "comezzano", "Vobarno", "vobarno","Milano-Via Ornato","ornato","Settala-Via Grandi","settala","Albuzzano","albuzzano","Broni","broni","Casteggio","casteggio","Pavia","pavia","Vigevano","vigevano");
    DV.addOptions("marche","Pesaro","pesaro","Ancona","ancona");
    DV.addOptions("piemonte","Tutte","0","Alessandria", "alessandria","Asti", "asti", "Grugliasco (TO)","grugliasco", "Moncalieri (TO)","moncalieri", "Torino","torino");
    DV.addOptions("puglia","Tutte","0","Bari","bari","Bari San Paolo", "sanpaolo", "Barletta (BA)","barletta", "Lecce","lecce");
    DV.addOptions("sardegna","Tutte","0","Cagliari","cagliari", "Sassari", "sassari");
    DV.addOptions("toscana","Tutte","0","Firenze (hinterland)","firenze_prov","Pisa","pisa","Lucca","lucca","Pistoia","pistoia");
    DV.addOptions("umbria","Tutte","0","Perugia","perugia","Terni","terni");
    DV.addOptions("veneto","Tutte","0","Padova","padova","Albignasego (PD)","albignasego","Treviso","olmi","Venezia","mestre","Verona","sgiovanni","Vicenza","vicenza");
    DV.addOptions("sicilia","Catania","catania");
	DV.addOptions("trentino","Trento","trento");
	
// Inizializzazione - da chiamare in body come OnLoad
function init() {
  is = new browserCheck();

  var theForm = document.forms['selez_pv'];
  DV.init(theForm);

  return true;
}

function init_spalla() {
  is = new browserCheck();

  var theForm = document.forms['selez_pv'];
  DV.init(theForm);

  return true;
}

function init_ecomm() {

  is = new browserCheck();

  return true;
}

function init0() {

  is = new browserCheck();
  
  return true;
}


// Determina il tipo di Brower, caricando la variabile is
function browserCheck() {
  this.ns4 = (document.layers);
  this.ns6 = (!document.all && document.getElementById);
  this.ie4 = (document.all && !document.getElementById);
  this.ie5 = (document.all && document.getElementById);
  return true;
}


// Rende visibile una DIV
function showObject(obj) {

  if (is == null) return true;

  if (is.ns4) {
    this.layer = window.document[obj];
    this.layer.visibility = "show";
  }

  if (is.ie4) {
    this.element = window.document.all[obj];
    this.style = this.element.style;
    this.style.visibility = "visible";
  }

  if (is.ns6 || is.ie5) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.visibility = "visible";
  }

  return true;
}

// Nasconde una DIV
function hideObject(obj) {
  if (is == null) return true;

  if (is.ns4) {
    this.layer = window.document[obj];
    this.layer.visibility = "hide";
  }

  if (is.ie4) {
    this.element = window.document.all[obj];
    this.style = this.element.style;
    this.style.visibility = "hidden";
  }

  if (is.ns6 || is.ie5) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.visibility = "hidden";
  }

  return true;
}


// modifica l'altezza di un oggetto
function resetObject(obj, val_height) {

  if (is == null) return true;

  if (is.ns4) {
    this.layer = window.document[obj];
    this.layer.height = val_height;
  }

  if (is.ie4) {
    this.element = window.document.all[obj];
    this.style = this.element.style;
    this.style.height = val_height;
  }

  if (is.ns6 || is.ie5) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.height = val_height;
  }

  return true;
}


// modifica la posizione di un oggetto
function moveObject(obj, val_top, val_left) {

  if (is == null) return true;

  if (is.ns4) {
    this.layer = window.document[obj];
    this.layer.top = val_top;
    this.layer.left = val_left;
  }

  if (is.ie4) {
    this.element = window.document.all[obj];
    this.style = this.element.style;
    this.style.top = val_top;
    this.style.left = val_left;
  }

  if (is.ns6 || is.ie5) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.top = val_top;
    this.style.left = val_left;
  }

  return true;
}

function setBody(obj,body) {

  if (is == null) return true;

  if (is.ns4) {
    this.layer = window.document[obj];
    for(var i = 0; i < body.length; i++) {
      this.layer.document.writeln(body[i]);
    }
    this.layer.document.close();
  }

  if (is.ie4) {
    this.element = window.document.all[obj];
    this.element.innerHTML = body;
  }

  if (is.ie5 || is.ns6) {
    this.element = document.getElementById(obj);
    this.element.innerHTML = body;
  }

  return true;
}

function changeImage(imgName,imgObj) {
  if (is == null) return true;

  if (is.ns4) {
    eval('this.document.' + imgName + '.src = "' + imgObj + '"');
  }

  if (is.ie4) {
    document.images[imgName].src = imgObj;
  }

  if (is.ie5 || is.ns6) {
    document.images[imgName].src = imgObj;
  }

  return true;
}

// Cambia il pointer in mano
// NOTA : si può fare direttamente dal foglio stile (cursor:hand) salvo le solite incompatibilità...
function mouseMano(obj) {

  if (is == null) return true;

  if (is.ns4) {
    this.layer = window.document[obj];
    this.layer.cursor = "pointer";
  }

  if (is.ie4) {
    this.element = window.document.all[obj];
    this.style = this.element.style;
    this.style.cursor = "hand";
  }

  if (is.ie5) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.cursor = "hand";
  }

  if (is.ns6) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.cursor = "pointer";
  }

  return true;
}

// Cambia il pointer nel default (freccia verso l'alto)
function mouseDef(obj) {

  if (is == null) return true;

  if (is.ns4) {
    this.layer = window.document[obj];
    this.layer.cursor = "default";
  }

  if (is.ie4) {
    this.element = window.document.all[obj];
    this.style = this.element.style;
    this.style.cursor = "default";
  }

  if (is.ie5) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.cursor = "default";
  }

  if (is.ns6) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.cursor = "default";
  }

  return true;
}


// Cambia la classe di un oggetto
function Classe(obj, cl) {

  if (is == null) return true;


  if (is.ns4) {
    this.layer = window.document[obj];
    this.layer.className = cl;
  }

  if (is.ie4) {
    this.element = window.document.all[obj];
    this.element.className = cl;
  }

  if (is.ie5 || is.ns6) {
    this.element = document.getElementById(obj);
    this.element.className = cl;
  }

  return true;
}

// Cambia la URL della window (in pratica carica una nuova pagina)
function URLwindow(URL) {

  if (is == null) return true;

  if (is.ns4) {
    window.location.replace (URL);
  }

  if (is.ie4) {
    window.location.replace (URL);
  }

  if (is.ie5) {
    window.location.replace (URL);
  }

  if (is.ns6) {
    window.location.replace (URL);
  }

  return true;
}

// Cambia colore di un testo
function changeColor (obj, idcolor) {

  if (is == null) return true;

  if (is.ns4) {
    this.layer = window.document[obj];
    this.layer.color = idcolor;
  }

  if (is.ie4) {
    this.element = window.document.all[obj];
    this.style = this.element.style;
    this.style.color = idcolor;
  }

  if (is.ie5) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.color = idcolor;
  }

  if (is.ns6) {
    this.element = document.getElementById(obj);
    this.style = this.element.style;
    this.style.color = idcolor;
  }

  return true;
}

// Assegna il colore rosso
function rouge(obj) {
  changeColor (obj, '#FFD700');
  return true;
}

// Assegna il colore azzurro
function bluette(obj) {
  changeColor (obj, '#99ccff');
  return true;
}

// Assegna il colore nero
function noire(obj) {
  changeColor (obj, '#ffffff');
  return true;
}

// Assegna il colore bianco
function blanc(obj) {
  changeColor (obj, '#FFFFFF');
  return true;
}

// Assegna il colore rosa
function rosa(obj) {
  changeColor (obj, '#FF9999');
  return true;
}

// Carica il nome della regione in caso di assenza di flash
function setReg (Regione) {
  var t =  '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="105" HEIGHT="16">';
      t += '<TR>'
      t += '<TD>' + Regione + '</TD>';
      t += '</TR>';
      t += '</TABLE>';
  setBody('regione',t);

  return true;
}

// Verifica la presenza del plugin di Flash
// NOTA: per I.E. viene utilizzata una function scritta in VB che deve essere presente nella head
function checkFlash () {

  PluginFlash = false;

  var MM_contentVersion = 6;
  var MM_PluginVersion;

  if (navigator.plugins && navigator.plugins.length >0) {
    if(navigator.plugins["Shockwave Flash"]) {
      var words = navigator.plugins["Shockwave Flash"].description.split(" ");
      for (var i = 0; i < words.length; ++i) {
        if (isNaN(parseInt(words[i]))) continue;
        MM_PluginVersion = words[i];
      }
      PluginFlash = MM_PluginVersion >= MM_contentVersion;
    }
  } else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0  &&
            (navigator.appVersion.indexOf("Win") != -1)) {

    detectActiveXControl(MM_contentVersion);
  }

/* Commentare o scommentare per simulare la presenza o meno del plugin di flash
  (oppure forzare a true o false) */
//  PluginFlash = false;

  return true;
}

// Determina sistema operativo, tipo di browser e versione
// in vista della visualizzaizone del Menu di destra
function sniffaMenu () {

  // Determino il sistema operativo (Windows o Mac)
  var SOWIN = (navigator.userAgent.toLowerCase().indexOf("win") > -1) ? 1: 0;
  if(navigator.userAgent.toLowerCase().indexOf("opera") > -1) SOWIN = 0;
  var SOMAC = (navigator.userAgent.toLowerCase().indexOf("mac") > -1) ? 1: 0;

  // Ipotesi di lavoro - il menu completo è solo per
  // Windows con Internet Explorer 5.5 o superiori, oppure Netscape 6.0 o superiori
  menuDestraOK = 0;
  var versione;
  if (SOWIN) {
     var ind = navigator.userAgent.indexOf("MSIE");
     if (ind > -1 &&
         navigator.userAgent.indexOf("Opera") == -1) {
       // Internet Explorer
       versione = parseInt(navigator.userAgent.substr(ind+5));
       if(versione >= 5) menuDestraOK = 1;

     } else if (navigator.appName.indexOf("Netscape") > -1) {
       // Netscape
       versione = parseInt(navigator.appVersion);
       if(versione > 4) menuDestraOK = 1;
     }
  }

  return true;
}



// Scrittura voci menu di destra
function menuDestra (descr, url, id) {

  document.write('<TR>');

  if (menuDestraOK) {
    document.write('<TD WIDTH="229" HEIGHT="18" CLASS="vocemenu" ID="' + id + '"');
    document.write('  ONMOUSEOVER="Classe(\'' + id + '\',\'vocemenuon\');mouseMano(\'' + id + '\');"');
    document.write('  ONMOUSEOUT ="Classe(\'' + id + '\',\'vocemenu\');"');
    document.write('  ONCLICK="URLwindow(\'' + url + '\');">');
    document.write(descr + '</TD>');
  } else {
    document.write('<TD WIDTH="229" HEIGHT="18" CLASS="vocemenu">');
    document.write('<A HREF="' + url + '" CLASS="vocemenuA">');
    document.write(descr + '</A></TD>');
  }
  document.write('</TR>');

  return true;
}

// Scrittura voci menu di destra con voce attiva
function menuDestraOn (descr, url, id) {

  document.write('<TR>');

  if (menuDestraOK) {
    document.write('<TD WIDTH="229" HEIGHT="18" CLASS="vocemenuon" ID="' + id + '"');
    document.write('  ONMOUSEOVER="mouseMano(\'' + id + '\');"');
    document.write('  ONCLICK="URLwindow(\'' + url + '\');">');
    document.write(descr + '</TD>');
  } else {
    document.write('<TD WIDTH="229" HEIGHT="18" CLASS="vocemenuon">');
    document.write('<A HREF="' + url + '" CLASS="vocemenuA">');
    document.write(descr + '</A></TD>');
  }
  document.write('</TR>');

  return true;
}


// Scrittura voci menu di destra - voce "home"
function menuDestraHome () {

  document.write('<TR>');

  if (menuDestraOK) {
    document.write('<TD WIDTH="229" HEIGHT="20" CLASS="vocemenuh" ID="menuhome"');
    document.write('    ONMOUSEOVER="Classe(\'menuhome\',\'vocemenuhon\');mouseMano(\'menuhome\');"');
    document.write('    ONMOUSEOUT="Classe(\'menuhome\',\'vocemenuh\');"');
    document.write('    ONCLICK="URLwindow(\'/home.html\');">');
    document.write('Media World home</TD>');
  } else {
    document.write('<TD WIDTH="229" HEIGHT="20" CLASS="vocemenuh">');
    document.write('<A HREF="/home.html" CLASS="vocemenuA">');
    document.write('Media World home</A></TD>');
  }
  document.write('</TR>');

  return true;
}

// Scrittura voci menu di destra - voce descrittiva corrispondenti a quella attiva
function menuDestraDescr (descr) {

  document.write('<TR>');
  document.write('<TD WIDTH="229" HEIGHT="18" CLASS="vocemenuon">');
  document.write(descr + '</TD>');
  document.write('</TR>');

  return true;
}



// Scrittura voci menu di destra formato "Lavoro"
function menuDestraLav (descr, url, id) {

  document.write('<TR>');

  if (menuDestraOK) {
    document.write('<TD WIDTH="229" HEIGHT="23" CLASS="vocemenulav" ID="' + id + '"');
    document.write('  ONMOUSEOVER="Classe(\'' + id + '\',\'vocemenulavon\');mouseMano(\'' + id + '\');"');
    document.write('  ONMOUSEOUT ="Classe(\'' + id + '\',\'vocemenulav\');"');
    document.write('  ONCLICK="URLwindow(\'' + url + '\');">');
    document.write(descr + '</TD>');
  } else {
    document.write('<TD WIDTH="229" HEIGHT="18" CLASS="vocemenulav">');
    document.write('<A HREF="' + url + '" CLASS="vocemenuA">');
    document.write(descr + '</A></TD>');
  }
  document.write('</TR>');

  return true;
}


// Apertura pagina Credits
function ApriCredits () {
  window.open("/credits/credits.html","credits","width=400,height=296,scrollbars=no,resizable=no");
}

// Apertura pagina MW Europa
function ApriMWEuropa () {
  window.open("http://www.mediamarkt.com/");
}

// Verifica che nel radio button sia stato selezionato un valore
function CheckRadioB (ValRadio) {
  var ln = ValRadio.length;
  var CountRadio;
  for (CountRadio=0; CountRadio<ln; CountRadio++) {
        if(ValRadio[CountRadio].checked) return(true);
  }
  return (false);
}

// Verifica che nel radio button sia stato selezionato il valore richiesto
function CheckRadioB1 (ValRadio, CountRadio) {
  if(ValRadio[CountRadio].checked) {
    return (true);
  } else {
    return (false);
  }
}


// Gestione Combo Dinamici
function DynamicCombo() {
	if (arguments.length < 2) { alert("Not enough arguments in DynamicCombo()"); }
	// nome del combo dinamico
	this.target = arguments[0];
	// imposta i combo dai quali il combo dinamico dipende
	this.dependencies = new Array();
	for (var i=1; i<arguments.length; i++) {
		this.dependencies[this.dependencies.length] = arguments[i];
		}
	// la form a cui appartiene il combo
	this.form = null;
	// crea nuovi oggetti per il combo
	this.dependentValues = new Object();
	// valore di default
	this.defaultValues = new Object();
	// oggetto per i valori del combo
	this.options = new Object();
	// delimitatore dei valori da usare nel combo
	this.delimiter = "|";
	// la stringa più lunga delle "options" (per Netscape)
	this.longestString = "";
	// Il numero delle "options" da visualizzare (per Netscape)
	this.numberOfOptions = 0;
	// mapping dei metodi
	this.addOptions = DynamicCombo_addOptions;
	this.populate = DynamicCombo_populate;
	this.setDelimiter = DynamicCombo_setDelimiter;
	this.setDefaultOption = DynamicCombo_setDefaultOption;
	this.printOptions = DynamicCombo_printOptions;
	this.init = DynamicCombo_init;
}

// cambia il delimitatore tra le varie "option"
function DynamicCombo_setDelimiter(val) {
	this.delimiter = val;
}

// imposta il valore di default del combo
function DynamicCombo_setDefaultOption(condition, val) {
	this.defaultValues[condition] = val;
}

// mappa la form per popolare i combo
function DynamicCombo_init(theform) {
	this.form = theform;
	this.populate();
}

// aggiunge le "options" al combo
function DynamicCombo_addOptions(dependentValue) {
	if (typeof this.options[dependentValue] != "object") { this.options[dependentValue] = new Array(); }
	for (var i=1; i<arguments.length; i+=2) {
		// rintraccia la stringa più lunga
		if (arguments[i].length > this.longestString.length) {
			this.longestString = arguments[i];
			}
		this.numberOfOptions++;
		this.options[dependentValue][this.options[dependentValue].length] = arguments[i];
		this.options[dependentValue][this.options[dependentValue].length] = arguments[i+1];
	}
}

//solo per netscape
function DynamicCombo_printOptions() {
    if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) <= 4)){
		var ret = "";
		for (var i=0; i<this.numberOfOptions; i++) { 
			ret += "<OPTION>";
		}
		ret += "<OPTION>"
		for (var i=0; i<this.longestString.length; i++) {
			ret += "_";
		}
		document.writeln(ret);
	}
}

// popola il combo
function DynamicCombo_populate() {
	var theform = this.form;
	var i,j,obj,obj2;
	// ottien  i valori correnti di tutte le combo da cui il combo dinamico dipende
	this.dependentValues = new Object;
	var dependentValuesInitialized = false;
	for (i=0; i<this.dependencies.length;i++) {
		var sel = theform[this.dependencies[i]];
		var selName = sel.name;
		// se è la prima combo dipendente semplicemente la riempio
		if (!dependentValuesInitialized) {
			dependentValuesInitialized = true;
			for (j=0; j<sel.options.length; j++) {
				if (sel.options[j].selected) {
					this.dependentValues[sel.options[j].value] = true;
				}
			}
		}
		// altrimenti aggiungo una nuova "option"
		else {
			var tmpList = new Object();
			var newList = new Object();
			for (j=0; j<sel.options.length; j++) {
				if (sel.options[j].selected) {
					tmpList[sel.options[j].value] = true;
				}
			}
			for (obj in this.dependentValues) {
				for (obj2 in tmpList) {
					newList[obj + this.delimiter + obj2] = true;
				}
			}
			this.dependentValues = newList;
		}
	}

	var targetSel = theform[this.target];
		
	// memorizzo la voce selezionata 
	var targetSelected = new Object();
	for (i=0; i<targetSel.options.length; i++) {
		if (targetSel.options[i].selected) {
			targetSelected[targetSel.options[i].value] = true;
		}
	}

	targetSel.options.length = 0; // cancello tutte le "option"
		
	for (i in this.dependentValues) {
		if (typeof this.options[i] == "object") {
			var o = this.options[i];
			for (j=0; j<o.length; j+=2) {
				var text = o[j];
				var val = o[j+1];
				targetSel.options[targetSel.options.length] = new Option(text, val, false, false);
				if (this.defaultValues[i] == val) {
					targetSelected[val] = true;
				}
			}
		}
	}
	targetSel.selectedIndex=0;
	
	// seleziono le voci che erano selezionate prima
	for (i=0; i<targetSel.options.length; i++) {
		if (targetSelected[targetSel.options[i].value] != null && targetSelected[targetSel.options[i].value]==true) {
			targetSel.options[i].selected = true;
		}
	}
}

// Attivazione Pagina PV dal menu si destra
function SceltaPV() {

  if(document.selez_pv.REGIONE.value == "0") {
        document.selez_pv.method = 'get';
        document.selez_pv.action = '/dove/index.html';

  } else {
    if(document.selez_pv.PROVINCIA.value == "0" || 
        document.selez_pv.PROVINCIA.value == "milano" ||
        document.selez_pv.PROVINCIA.value == "firenze_prov" ||        
        document.selez_pv.PROVINCIA.value == "roma") {
//      alert (document.selez_pv.REGIONE.value); 
        if(document.selez_pv.PROVINCIA.value == "0") {
           document.selez_pv.action = '/dove/' + document.selez_pv.REGIONE.value + '.html';
        } else {
           document.selez_pv.action = '/dove/' + document.selez_pv.PROVINCIA.value + '.html';
        }
        document.selez_pv.method = 'get';
     } else {
//      alert (document.selez_pv.PROVINCIA.value); 
        document.selez_pv.PV.value = document.selez_pv.PROVINCIA.value;
        document.selez_pv.action= '/cgi-bin/dove/puntivendita.pl';
     }
  }

   document.selez_pv.submit();
  
   return true;

}

