// JavaScript Document
/* ESTRAE PARAMETRI DA URL */
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function filtroGup(){
	var referredTo = gup('ref');
//alert(referredTo);
	switch(referredTo){
		case '0':
			// 	HOME PAGE
			//alert("ricevuto");
			leftNavAccordion.openPanel(1);
		break;
		
		case '1':
			// 	SCHEDE PRODOTTI
			var lname = gup( 'l' );
			lname = lname == '1' ? "Linea Austriaca" : lname == '2' ? "Linea Freeland" : lname == '3' ? "Linea Spagnola" : "Linea Tedesca";
			document.getElementById("lineName").innerHTML = lname;
			var product = gup( 'p' );
			document.getElementById("productName").innerHTML = "SCHEDA " + unescape( product ).toUpperCase() + " NON DISPONIBILE";
		break;

		case '2':
			// PRONTUARI
			var lname = gup( 'l' );
			dsProductsLegend.filter(null);
			dsProduct.filter(null);
			switch(lname){
				case "ALL":
					dsProductsLegend.filter(myFF0);
					dsProduct.filter(myFilterFunc0);
					document.getElementById("lineName").innerHTML = "Tutte le linee";
					document.getElementById("productLine").innerHTML = "";
					document.getElementById("producUse").innerHTML = "";
					document.getElementById("productFormulation").innerHTML = "";
					document.getElementById("productReference").innerHTML = "";
					document.getElementById("productNote").innerHTML = "";
					break;
				case "AU":
					dsProductsLegend.filter(myFF1);
					dsProduct.filter(myFilterFunc1);
					document.getElementById("lineName").innerHTML = "Linea Austriaca";
					document.getElementById("productLine").innerHTML = "Austriaca";
					document.getElementById("producUse").innerHTML = "-";
					document.getElementById("productFormulation").innerHTML = "-";
					document.getElementById("productReference").innerHTML = "Opuscolo bianco (Wellness Global System)";
					document.getElementById("productNote").innerHTML = "WGS rappresenta, nell'ambito della sua filosofia, un nuovo modo di pensare e costruire il proprio benessere finalizzato a garantire e mantenere lo stato di salute e farvi fronte in modo adeguato laddove esso sia minacciato.";
					break;
				case "FR":
					dsProductsLegend.filter(myFF2);
					dsProduct.filter(myFilterFunc2);
					document.getElementById("lineName").innerHTML = "Linea Freeland";
					document.getElementById("productLine").innerHTML = "Freeland";
					document.getElementById("producUse").innerHTML = "NUTRACEUTICA - IMMUNONUTRIZIONE";
					document.getElementById("productFormulation").innerHTML = "Frutto intero arricchito con Polisaccaridi";
					document.getElementById("productReference").innerHTML = "";
					document.getElementById("productNote").innerHTML = "";
					break;	
				case "SP":
					dsProductsLegend.filter(myFF3);
					dsProduct.filter(myFilterFunc3);
					document.getElementById("lineName").innerHTML = "Linea Spagnola";
					document.getElementById("productLine").innerHTML = "Spagnola";
					document.getElementById("producUse").innerHTML = "FASE ACUTA E MANTENIMENTO";
					document.getElementById("productFormulation").innerHTML = "Estratto";
					document.getElementById("productReference").innerHTML = "Opuscolo HIFAS Da Terra";
					document.getElementById("productNote").innerHTML = "Linea ricca di polisaccaridi ad alto peso molecolare, in particolare &szlig;-glucani &szlig;-(1,3) &szlig;(1,6)-glucani e Triterpeni: Acido Lucidenico; Acido Ganodermico; Acido Genolucido.";
					break;
				case "TE":
					dsProductsLegend.filter(myFF4);
					dsProduct.filter(myFilterFunc4);
					document.getElementById("lineName").innerHTML = "Linea Tedesca";
					document.getElementById("productLine").innerHTML = "Tedesca";
					document.getElementById("producUse").innerHTML = "FASE ACUTA e SUBACUTA";
					document.getElementById("productFormulation").innerHTML = "Funghi in toto";
					document.getElementById("productReference").innerHTML = "Opuscolo piccolo con foto funghi a colori";
					document.getElementById("productNote").innerHTML = "Linea molto efficace, sicura e bilanciata (con effetto sinergico dovuto all&acute;utilizzo di tutte le parti del fungo).<br />Per l&acute;utilizzo delle formulazioni Mix si consiglia l&acute;uso in abbinatoad altri funghi.";
					break;
			}
		break;
	
	}

}


// RETRIVE INFO FOR SCHEDEPRODOTTI HEADER
function readLoginResult(){
	var referredTo = gup('lr');
//alert(referredTo);
	switch(referredTo){
		case '0':
			// 	BAD LOGIN
			//document.getElementById("loginResult").innerHTML = "Siamo spiacenti Username e password non valide, nessuna corrispondenza trovata.";
			document.getElementById("loginResult").innerHTML ='<b><font color="#FF0000" size="+1">Attenzione!<br>Username e Password non valide.<br />Nessuna corrispondenza trovata.</font></b><br /><br />'
			//loginTabForm.openPanel(0);
		break;
	}
}


// RETRIVE INFO FOR ADMIN SECTION PAGES
function readAdminSectionPage(){
	var referredTo = gup('sp');
//alert(referredTo);
	switch(referredTo){
		case '1':
			getExt('settings.php', 'mainPanel','Settaggi e Impostazioni');
		break;
		case '2':
			var actVal=gup('act');
			var userVal=gup('username');
			var kurl = "authuser.php?act=" + actVal + "&username=" + userVal;
			getExt(kurl, 'mainPanel','Gestione Utenti');
		break;
		case '3':
			getExt('authgroup.php', 'mainPanel','Gestione Gruppi');
		break;
	}
	

}

// OPEN PANEL LOGIN FROM PRODUCT TAB
function readSPParam(){
	var referredTo = gup('op');
	switch(referredTo){
		case '0':
			loginTabForm.openPanel(-1);
		break;
		case '1':
			loginTabForm.openPanel(0);
		break;
	}
	
}


/*

function leggi_variabile(variabile) { 
//<a href="../prontuario.html?line=austriaca" target="_self">Linea Austriaca</a>
//http://localhost:8888/myfreeland/prontuario.html?line=austriaca&

	var indirizzo = window.location.toString() + "&"; 
//alert(indirizzo);

	var posizione_nome = indirizzo.indexOf(variabile + "="); 
//alert(posizione_nome);	
	
	if (posizione_nome==-1) return ""; 
	
	var sottostringa = indirizzo.substring(posizione_nome); 
//alert(sottostringa);

	var inizio=sottostringa.indexOf("="); 
	var fine=sottostringa.indexOf("&"); 
	var variabile=sottostringa.substring(inizio + 1, fine); 
	return variabile;
}


function filtro(type){
	
	var lname = gup( 'l' );
	switch(lname){
		case '1': lname = "Linea Austriaca"; break;
		case '2': lname = "Linea Freeland"; break;
		case '3': lname = "Linea Spagnola"; break;
		case '4': lname = "Linea Tedesca"; break;
	}
	document.getElementById("lineName").innerHTML = lname;
	
	//var str = unescape( type ).toUpperCase();
	var str = gup( 'p' );
	document.getElementById("productName").innerHTML = "SCHEDA " + unescape( str ).toUpperCase() + " NON DISPONIBILE";
}

function start(){
var linea = leggi_variabile("p");
if(linea != ""){
	filtro(linea);
	}
}


// esegue un controllo sul browser del client e richiama start();
var alreadyrunflag=0 //flag to indicate whether target function has already been run

if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; start()}, false)
else if (document.all && !window.opera){
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete"){
      alreadyrunflag=1
      start()
    }
  }
}

window.onload=function(){
  setTimeout("if (!alreadyrunflag) start()", 0)
}

if(/Safari/i.test(navigator.userAgent)){ //Test for Safari
  var _timer=setInterval(function(){
  if(/loaded|complete/.test(document.readyState)){
    clearInterval(_timer);
    start() ;// call target function
  }}, 5)
}


*/

