// Function.js

var timerid;

var comuneistat = "0";

/*

function startCicloRefresh() {
   timerid = setInterval("aggiornaPagina()",10000);
}

function stopCicloRefresh() {
   clearTimeout(timerid);
}

function aggiornaPagina() {
  if (window.parent.frames["menu"].SceltaAffluenza) {
    window.parent.frames['content'].location.href	= "aff_" + comuneistat + ".htm";
  }
  else if (window.parent.frames["menu"].SceltaCamera) {
 	 window.parent.frames['content'].location.href	= "cam_" + comuneistat + ".htm";
  }
  else {
    window.parent.frames['content'].location.href	= "sen_" + comuneistat + ".htm";
  }
}  
*/


function getPageFromUrl(pUrl){
	// grab the full url
	var stuff = pUrl;  

  if (stuff.indexOf("\\")>=0){
		// split the url into an array
		arrayOfStuff = stuff.split("\\");  
  } else {
		// split the url into an array
		arrayOfStuff = stuff.split("/");  
	}
	
	// get the last element (array length minus one)
	var pageExt = arrayOfStuff[arrayOfStuff.length - 1];  
	
	return pageExt
}

function getLastDirFromUrl(pUrl){
	// grab the full url
	var stuff = pUrl;  

  if (stuff.indexOf("\\")>=0){
		// split the url into an array
		arrayOfStuff = stuff.split("\\");  
  } else {
		// split the url into an array
		arrayOfStuff = stuff.split("/");  
	}
	
	// get the last element (array length minus one)
	var pageExt = arrayOfStuff[arrayOfStuff.length - 2];  
	
	return pageExt
}

function mostraPrimoTurno() {
   // Imposta il pulsante attivo
   document.getElementById('primoturnobutton').className= "menuattivo";
   document.getElementById('ballottaggiobutton').className = "menu";
   
	//startCicloRefresh();
	
	window.parent.frames["scelta"].location.href="Sceltaprimoturno.htm";
	window.parent.frames["content"].location.href="Sindaci.htm";
   
	window.parent.frames["menu"].SceltaPrimoTurno = true;
	window.parent.frames["menu"].SceltaBallottaggio = false;
	//mostraComune();
	return false;
}

function mostraBallottaggio() {
   // Imposta il pulsante attivo
   document.getElementById('primoturnobutton').className= "menu";
   document.getElementById('ballottaggiobutton').className = "menuattivo";
   
	//startCicloRefresh();
	
	window.parent.frames["scelta"].location.href="Sceltaballottaggio.htm";
	window.parent.frames["content"].location.href="SindaciBall.htm";
   
	window.parent.frames["menu"].SceltaPrimoTurno = false;
	window.parent.frames["menu"].SceltaBallottaggio = true;
	//mostraComune();
	return false;
}

function mostraSezioniScrutinate() {
   // Imposta il pulsante attivo
   document.getElementById('sezioniscrutinatebutton').className= "menuattivo";
   document.getElementById('sindacobutton').className = "menu";
   document.getElementById('listebutton').className = "menu";
   document.getElementById('consigliobutton').className = "menu";   
   
	//startCicloRefresh();
	
	window.parent.frames["content"].location.href="IndexSezioni.htm";
   
	window.parent.frames["scelta"].SceltaSezioniScrutinate = true;
	window.parent.frames["menu"].SceltaSindaco = false;
	window.parent.frames["menu"].SceltaListe = false;
	window.parent.frames["menu"].SceltaConsiglio = false;
	//mostraComune();
	return false;
}

function mostraSindaco() {
   // Imposta il pulsante attivo
   document.getElementById('sezioniscrutinatebutton').className= "menu";
   document.getElementById('sindacobutton').className = "menuattivo";
   document.getElementById('listebutton').className = "menu";
   document.getElementById('consigliobutton').className = "menu";   
   
	//startCicloRefresh();
	
	window.parent.frames["content"].location.href="Sindaci.htm";
   
	window.parent.frames["scelta"].SceltaSezioniScrutinate = false;
	window.parent.frames["menu"].SceltaSindaco = true;
	window.parent.frames["menu"].SceltaListe = false;
	window.parent.frames["menu"].SceltaConsiglio = false;
	//mostraComune();
	return false;
}

function mostraListe() {
   // Imposta il pulsante attivo
   document.getElementById('sezioniscrutinatebutton').className= "menu";
   document.getElementById('sindacobutton').className = "menu";
   document.getElementById('listebutton').className = "menuattivo";
   document.getElementById('consigliobutton').className = "menu";   
   
	//startCicloRefresh();
	
	window.parent.frames["content"].location.href="Liste.htm";
   
	window.parent.frames["scelta"].SceltaSezioniScrutinate = false;
	window.parent.frames["menu"].SceltaSindaco = false;
	window.parent.frames["menu"].SceltaListe = true;
	window.parent.frames["menu"].SceltaConsiglio = false;
	//mostraComune();
	return false;
}

function mostraConsiglio() {
   // Imposta il pulsante attivo
   document.getElementById('sezioniscrutinatebutton').className= "menu";
   document.getElementById('sindacobutton').className = "menu";
   document.getElementById('listebutton').className = "menu";
   document.getElementById('consigliobutton').className = "menuattivo";   
   
	//startCicloRefresh();
	
	window.parent.frames["content"].location.href="IndexConsiglio.htm";
   
	window.parent.frames["scelta"].SceltaSezioniScrutinate = false;
	window.parent.frames["menu"].SceltaSindaco = false;
	window.parent.frames["menu"].SceltaListe = false;
	window.parent.frames["menu"].SceltaConsiglio = true;
	//mostraComune();
	return false;
}

function mostraSezioniScrutinateBall() {
   // Imposta il pulsante attivo
   document.getElementById('sezioniscrutinatebutton').className= "menuattivo";
   document.getElementById('sindacobutton').className = "menu";
   
	//startCicloRefresh();
	
	window.parent.frames["content"].location.href="IndexSezioniBall.htm";
   
	window.parent.frames["scelta"].SceltaSezioniScrutinate = true;
	window.parent.frames["menu"].SceltaSindaco = false;
	//mostraComune();
	return false;
}

function mostraSindacoBall() {
   // Imposta il pulsante attivo
   document.getElementById('sezioniscrutinatebutton').className= "menu";
   document.getElementById('sindacobutton').className = "menuattivo";
   
	//startCicloRefresh();
	
	window.parent.frames["content"].location.href="SindaciBall.htm";
   
	window.parent.frames["scelta"].SceltaSezioniScrutinate = false;
	window.parent.frames["menu"].SceltaSindaco = true;
	//mostraComune();
	return false;
}

function cambiaComune() {
   
  var url_comune="";
  url_comune=document.getElementById('comune').value;

  var ballottaggio=window.parent.frames["menu"].SceltaBallottaggio;
  
 	//window.parent.frames["menu"].location.href="../"+url_comune+"/"+getPageFromUrl(window.parent.frames["menu"].location.href);
 	//window.parent.frames["scelta"].location.href="../"+url_comune+"/"+getPageFromUrl(window.parent.frames["scelta"].location.href);
 	//window.parent.frames["content"].location.href="../"+url_comune+"/"+getPageFromUrl(window.parent.frames["content"].location.href);
 	window.parent.frames["menu"].location.href="../"+url_comune+"/"+"Menu.htm";
	window.parent.frames["scelta"].location.href="../"+url_comune+"/"+"Sceltaprimoturno.htm";
	window.parent.frames["content"].location.href="../"+url_comune+"/"+"Sindaci.htm";
	//if (ballottaggio){
	//	mostraBallottaggio();
	//} else {
	//	mostraPrimoTurno();
	//}
	  
	//mostraComune();
	return false;
}

