// Modifica la data da:  11 Gennaio 2005 in 11.1.2005
//Scroll orari ( thx andbin )
var scroll_enable = true;
var scroll_move = 2;
var scroll_time = 100;

function scroll_update ()
{
    var obj = document.getElementById ("scroll_oggialcinema");

    if (scroll_enable)
    {
        if ((obj.scrollTop + scroll_move) < (obj.scrollHeight - obj.clientHeight))
            obj.scrollTop += scroll_move;
        else
            obj.scrollTop = 0;
    }

    setTimeout (scroll_update, scroll_time);
}


// *** By mackey , funzione aggiungi preferiti
function addFavorite(url,title) {
    if(!url) url = location.href;
    if(!title) title = document.title || url.replace(/^(.+):\/\//,"").replace(/\/$/,"").replace(/\//g,"_");
    if(typeof(window.external)!="undefined" && typeof(window.external.addFavorite)!="undefined") {
        window.external.addFavorite(url,title);
        return true;
    }
    else try {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
        var b = Components.classes["@mozilla.org/browser/bookmarks-service;1"].getService();
        b = b.QueryInterface(Components.interfaces.nsIBookmarksService);
        b.addBookmarkImmediately(url,title,0,null);
        return true;
    } catch(e) {
        if(typeof(window.sidebar)!="undefined" && typeof(window.sidebar.addPanel)!="undefined") {
            window.sidebar.addPanel(title,url,"");
            return true;
        }
        else
            return false;
    }
}

function addHomePage(url) {
    if (document.all) {
      document.body.style.behavior='url(#default#homepage)';
      document.body.setHomePage(window.location.href);
   } else {
      alert("Per aggiugere questa pagina come homepage aggiungerlo tramite le opzioni del browser"); 
   }
}
// END


function cambia_focus (nome) {
	var num_campo = nome.substr(-1);
	var new_campo = nome.substr(0,(nome.length-1)) + (eval(num_campo) + 1);
	document.getElementById(new_campo).focus();
}
function svuota(valore) {
	if (valore == "La Tua E-Mail" ) { return ""; } 
	return valore;
}

function toglidivpop() {
	document.getElementById('divpop').style.display='none';
}
function controlla_utente() {
utente = document.form1;
if (utente.pwd.value != utente.pwd_r.value && utente.pwd.value != " ") {
    alert("La password non è uguale nei due campi!");
}else {
    utente.submit();
}
}
function ctrlnl () {
	var val = document.form_newsletter.email_nl.value;
	if (val == "" || val == " " ||val == "La Tua E-Mail") { alert ("E-mail non valida") ; return false; } 
	return true;
}
 
function format_trailer () {
	var type = prompt('QuickTime = qt, WMP = wmp, GoogleVideo = google, Tube= tube, altrimenti vuoto','');
	var url = prompt ('Inserisci l\'url del file','');
	document.form1.trailer.value = "index.php?page=player&mode=play&type="+ type +"&url=" + url;
}

function attore(nome, valore) {
	lungsrcl = document.form1.attori.options.length;
	document.form1.attori.options[lungsrcl] = new Option(nome, valore );

}

function explivelli (){
      for (b=0; b<document.form1.livello.options.length; b++) {
		document.form1.exp_livello.value = document.form1.exp_livello.value + document.form1.livello.options[b].value + ";";	 	
   	
      }
	  
}

function livello(nome, valore) {
	lungsrcl = document.form1.livello.options.length;
	document.form1.livello.options[lungsrcl] = new Option(nome, valore );

}

function dellivello() {
	 for (b=0; b<document.form1.livello.options.length; b++) {
		 for (b=0; b<document.form1.livello.options.length; b++) {
			if (document.form1.livello.options[b].selected ) {
				document.form1.livello.options[b] = null;
				break;
			}
		
		  }
	 }
}
 
function add_taglie() {
	lungsrcl = document.form1.taglie.options.length;
	var tipo = prompt("Inserisci Taglia","");
	document.form1.taglie.options[lungsrcl] = new Option(tipo, tipo );

}

function generi(nome, valore) {
	lungsrcl = document.form1.generi.options.length;
	document.form1.generi.options[lungsrcl] = new Option(nome, valore );

}

function exptaglie(){
      for (b=0; b<document.form1.taglie.options.length; b++) {
		document.form1.exp_taglie.value = document.form1.exp_taglie.value + document.form1.taglie.options[b].value + ";";	 	
   	
      }
}
function deltaglia() {
	 for (b=0; b<document.form1.taglie.options.length; b++) {
		 for (b=0; b<document.form1.taglie.options.length; b++) {
			if (document.form1.taglie.options[b].selected ) {
				document.form1.taglie.options[b] = null;
				break;
			}
		
		  }
	 } 
}


function expattori(){
      for (b=0; b<document.form1.attori.options.length; b++) {
		document.form1.exp_attori.value = document.form1.exp_attori.value + document.form1.attori.options[b].value + ";";	 	
   	
      }
	  for (b=0; b<document.form1.generi.options.length; b++) {
		document.form1.exp_generi.value = document.form1.exp_generi.value + document.form1.generi.options[b].value + ";";	 	
   	
      }
}

function delattore() {
	 for (b=0; b<document.form1.attori.options.length; b++) {
		 for (b=0; b<document.form1.attori.options.length; b++) {
			if (document.form1.attori.options[b].selected ) {
				document.form1.attori.options[b] = null;
				break;
			}
		
		  }
	 }
}

function delgenere() {
	 for (b=0; b<document.form1.generi.options.length; b++) {
		 for (b=0; b<document.form1.generi.options.length; b++) {
			if (document.form1.generi.options[b].selected ) {
				document.form1.generi.options[b] = null;
				break;
			}
		
		  }
	 }
}



function dataformato(data) {
var dataold = data;
var mesi = new Array(12);
mesi[0] = "Gennaio";
mesi[1] = "Febbraio";
mesi[2] = "Marzo";
mesi[3] = "Aprile";
mesi[4] = "Maggio";
mesi[5] = "Giugno";
mesi[6] = "Luglio";
mesi[7] = "Agosto";
mesi[8] = "Settembre";
mesi[9] = "Ottobre";
mesi[10] = "Novembre";
mesi[11] = "Dicembre";

for (i = 0;i<12;i++) {
	if (dataold.match(mesi[i]) != null) {
		dataold = dataold.replace(mesi[i],i+1);
	} 
}
dataold = dataold.replace(" ","-");
dataold = dataold.replace(" ","-");
datagiornomese = dataold.split("-");

document.form1.data.value = datagiornomese[2] + "-" + datagiornomese[1] + "-" + datagiornomese[0];
}

function viewdomande(valore) {
	nomicampi = new Array();
	nomicampi[0] = "domanda0";
	nomicampi[1] = "domanda1";
	nomicampi[2] = "domanda2";
	nomicampi[3] = "domanda3";
	nomicampi[4] = "domanda4";
	nomicampi[5] = "domanda5";
	nomicampi[6] = "domanda6";
	nomicampi[7] = "domanda7";
	for (x = 0;x < 8;x++) {
		document.getElementById(nomicampi[x]).style.display="none"; 
	}
	for (x = 0;x < valore;x++) {
		document.getElementById(nomicampi[x]).style.display="block"; 
	}
}

function vuoto (nomeform,nomecampo) {
sduhduf = document.form1.nome.value;
if (sduhduf == "") {
	window.alert("Completa tutti i campi!!");
	return false;
	
}
else {
	return true;
	
}
}

function vuoto2 () {
sduhduf = document.form1.email.value;
sduhduf2 = document.form1.nome.value;
if (sduhduf == "" || sduhduf2 == "") {
	window.alert("Completa tutti i campi!!");
	return false;
}
else {
	return true;
}
}

function visual(nome) {
	if (document.getElementById(nome).style.display == "block") {
		document.getElementById(nome).style.display = "none";
	}
	else {
	document.getElementById(nome).style.display="block";
	}
}

function popup(page, xval, yval, scroll) {
		if(scroll=='undefined') {
			var scroll=2;
		}
		var popupwindw=window.open(page,'pop','scrollbars='+ scroll +' ,width='+ xval +', height='+ yval);
		popupwindw.creator=self;
	}
	
function oraformato (valore) {
	var stringa = "";
	stringa = valore;
	var lunghezza = stringa.length;
	var ora,minuti;
	/*for (;;) {
		if (stringa.indexOf(' ') != -1) {
			stringa = stringa.replace(" ","");
		}
		else { 
			break;
		}
	}*/
	if (stringa.indexOf(" ") != -1) {
		ora = stringa.substr(0,2);
		minuti = stringa.substr(3,5);
	}
	else if (stringa.indexOf(".") != -1) {
		ora = stringa.substr(0,2);
		minuti = stringa.substr(3,5);
	}
	else if (stringa.indexOf(":") != -1) {
		ora = stringa.substr(0,2);
		minuti = stringa.substr(3,5);
	}
	else if (lunghezza == 2) {
		ora = stringa.substr(0,2);
		minuti = "00";
	}
	else if (lunghezza == 1) {
		ora = stringa.substr(0,1);
		minuti = "00";
	}
	else if (lunghezza == 4) {
		ora = stringa.substr(0,2); 
		minuti = stringa.substr(2,4);
	}
	else if (lunghezza == 3) {
		if (stringa.substr(0,2) > 0 && stringa.substr(0,2) < 24) {
			ora = stringa.substr(0,2)
		}
		if (stringa.substr(2,3) > 0 && stringa.substr(2,3) < 60) {
			minuti = stringa.substr(2,3)
		}
	}
	else if (stringa == "") {
		ora = "";
		minuti = "";
	}
	return (ora + ":" + minuti);
	
}
function getMouseXY(e) {
	var tempX = 0
var tempY = 0
var IE = document.all?true:false
  if (!IE) document.captureEvents(Event.MOUSEMOVE)
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY

  document.getElementById('aiuto').style.left = tempX + "px";
  document.getElementById('aiuto').style.top =  tempY +"px";
  return false
}
function appari (nome, num) {



	if (document.getElementById(nome).style.display == "block") {
		document.getElementById(nome).style.display = "none";
		
	}
	else {
		document.getElementById(nome).style.display="block";
		document.form12.spitorari.focus();
		document.form12.aiuto2.value = num;
		document.form12.spitorari.value = "";
		document.onmousemove = getMouseXY;
		
	}
	
}



function slpitta() { 
	var numelemg;
	var numelemo;
	var temp = document.form12.spitorari.value;
	var num = document.form12.aiuto2.value;
	
	
	var temp2 = temp.split(" ");
	temp2[1] = temp2[1].replace(":","");
	temp2[2] = temp2[2].replace("",""); 
	temp2[2] = temp2[2].replace(".",":");  

	if (temp2[2].indexOf('--') == -1) {
		var datafilm = temp2[1].split(".");
		if (datafilm[0].length == 1) {
			datafilm[0] = "0" +  datafilm[0]; 
		}
		if (datafilm[1].length == 1) { 
			datafilm[1] = "0" +  datafilm[1]; 
		}
		if (datafilm[2].length == 2) {
			datafilm[2] = "20" +  datafilm[2]; 
		}
		var datafinale = datafilm[0] + "." + datafilm[1] + "." + datafilm[2];
		for (i = 0;i<document.form1.elements.length;i++) {
			if (document.form1.elements[i].name == "giorno" + num) {
				numelemg = i;	
			}
			if (document.form1.elements[i].name == "orain" + num) {
				numelemo = i;	
			}
		}   
		var wval = true;
		while  (wval == true) {
				if (temp2.length > 3) {  
					for (i = 0;i<((temp2.length)-2);i++) { 
						temp2[i+2] = temp2[i+2].replace(".",":");  
						temp2[i+2] = temp2[i+2].replace(",","");  
						document.form1.elements[numelemo].value = temp2[i+2];
						numelemo = eval(numelemo) + 4; 
					}
					wval = false;
				} 
				else {
				 temp2[2] = temp2[2].substr(-5,temp2[2].length);
				 document.form1.elements[numelemo].value = temp2[2];
				 wval = false;
				}
		}
				
		 
		// document.getElementById('giorno'+num).selectedIndex  = 3; 
		 //alert(document.getEleme ntById('giorno'+num).options[0].value); 
 
		var templen = temp2.length-2; 
		
		for (a = 0;a < templen;a++) {
			for (i = 0;i<29;i++) {
				var tempgi = document.getElementById('giorno'+num).options[i].value;
				var tempgi2 = datafilm[2]+"-"+datafilm[1]+"-"+datafilm[0];
				
				if (tempgi == tempgi2) { 
						document.getElementById('giorno'+num).selectedIndex  = i;
						break; 
				} 
			}
			
			 
		
			if (temp2.length> 3) { 
			
				num++;
				
			} 
			else { 
				break;
			}  
		
			if (a > templen) {
				//alert("aa2"); 
				break;
				
			}  
			
			// alert("aa");
			
		}
		
	} 
		
	 
	
}


function check_all(nome,nome2) {
    testo_str = "";
    for (x = 0;x < nome.elements.length;x++) {
          if (nome.elements[x].type  == "checkbox") {
              nome.elements[x].checked = true;
              testo_str += nome.elements[x].value + ";";
          }
    }
    nome2.value = testo_str;
}
function uncheck_all(nome,nome2) {
  
    for (x = 0;x < nome.elements.length;x++) {
          if (nome.elements[x].type  == "checkbox") {
              nome.elements[x].checked = false;
            
          }
    }
    nome2.value = "";
    
}
function check_checked (nome,nome2) {
    testo_str = "";
    for (x = 0;x < nome.elements.length;x++) {
          if (nome.elements[x].checked  == true) {
              testo_str += nome.elements[x].value + ";";
            
          }
    }
    nome2.value = testo_str;
}
function segnalaTutti(num) {
    var testo = prompt("Testo da inserire");
    for (x = 0;x < num;x++) {
          document.getElementById('testo_segnala'+x).value = testo;
          document.getElementById('segnala'+x).checked = true;
    }
}
