
// FUNZIONI GENERICHE non specifiche ad una voce di ADMIN

function occup_mese(mese,anno) {
	page = "admin/calendario_mese/occup_mese.php?mese=" + mese + "&anno=" + anno;
	win = window.open(page);
	if (win) win.focus();
}
function adm_cal_mese_show(mese,anno) {
	ajaxpage("admin/calendario_mese/index.php?mese=" + mese + "&anno=" + anno, "adm_page_id");
}
function showOccup(id) {
	ajaxpage("admin/occupazione/scheda.php?id=" + id, "evento_id");
	document.getElementById("evento_id").style.visibility="visible";
}

function dosub() {
	document.myForm.submit();
}

function adm_id_load(voce, id) {
	noaudio();
	linke_hide();
	hideEvento();
	ajaxpage("admin/" + voce + "/index.php?id=" + id, "adm_page_id");
	// attendo un attimo prima di effettuare l'eventuale
	// scroll della workR per vedere l'elemento checked
	setTimeout("adm_scroll()", 500); // mezzo secondo
}

function dont_doit() {
	document.getElementById("adm_workY_id").style.visibility="hidden";
}

function relo(url) {
	//alert("relo: " + url);
	top.location.href = url;
}

function myReset(voce) {
	// uso ajaxpage per passare opt=reset così da svuotare le $_SESSION
	// dell'eventale doit.php precedente
	ajaxpage("admin/" + voce + "/index.php?opt=reset", "adm_page_id");
}
function help(voce) {
	ajaxpage("admin/" + voce + "/help.php", "adm_help_id");
	if (document.getElementById("adm_help_id").style.visibility == "hidden")
		document.getElementById("adm_help_id").style.visibility="visible";
	else 
		document.getElementById("adm_help_id").style.visibility="hidden";
}
function help_hide() {
	document.getElementById("adm_help_id").style.visibility="hidden";
}

function adm_scroll() {
	if (top.document.getElementById("adm_workR_id")) {
		// distanza in pixel dal top della parent div
		if (top.document.getElementById("scroll_here")) {
			var topPos = top.document.getElementById("scroll_here").offsetTop;
			// ora scrollo per arrivare a vedere questo div
			top.document.getElementById("adm_workR_id").scrollTop = topPos;
		}
	}
}

function adm_doit_index() {
	// SOLO SE $adm_err==0 !!
	if (document.doitForm.err.value > 0)
		ajaxpage("../err.php","adm_workM_id");
	else {
		// scopo: assegnare alla div "adm_page_id" la pagina "index.php"
		// (senza path perchè a fianco del doit.php che la chiama)
		// cambiato il source ajaxpage() originale in modo che cerchi la div
		// nel parent se non la trova nel document (dell'iframe)
		ajaxpage("index.php", "adm_page_id"); 
		// attendo un attimo prima di effettuare l'eventuale
		// scroll della workR per vedere l'elemento checked
		setTimeout("adm_scroll()", 500); // mezzo secondo
	}
}
function adm_doit_reload() {
	// attendo un attimo prima di ricaricare la index.php
	// per essere sicuro che doit.php abbia salvato l'id
	// nella SESSION
	setTimeout("adm_doit_index()", 500); // mezzo secondo
}

function switch_debug() {
	if (document.getElementById("adm_doit_target").style.visibility=="visible") {
		document.getElementById("adm_doit_target").style.height="1px";
		document.getElementById("adm_doit_target").style.visibility="hidden";
	} else {
		document.getElementById("adm_doit_target").style.height="80px";
		document.getElementById("adm_doit_target").style.visibility="visible";
	}
}

function adm_numCh() {
  var max = 2000;
  var i = max - document.myForm.descr.value.length;
  if (i<0) document.getElementById("adm_numch").innerHTML = 
		'(max ' + max + ' caratteri, <b>togline' + (i * -1) + '</b>)';
  else if (i==0) document.getElementById("adm_numch").innerHTML = 
		'(max ' + max + ' caratteri, <b>fermati</b>)';
  else if (i==1) document.getElementById("adm_numch").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>solo uno</b>)';
  else if (i==max) document.getElementById("adm_numch").innerHTML =  
		'(max ' + max + ' caratteri)';
  else document.getElementById("adm_numch").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>' + i + '</b>)';
}
function adm_numCh2() {
  var max = 2000;
  var i = max - document.myForm.note.value.length;
  if (i<0) document.getElementById("adm_numch2").innerHTML = 
		'(max ' + max + ' caratteri, <b>togline' + (i * -1) + '</b>)';
  else if (i==0) document.getElementById("adm_numch2").innerHTML = 
		'(max ' + max + ' caratteri, <b>fermati</b>)';
  else if (i==1) document.getElementById("adm_numch2").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>solo uno</b>)';
  else if (i==max) document.getElementById("adm_numch2").innerHTML =  
		'(max ' + max + ' caratteri)';
  else document.getElementById("adm_numch2").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>' + i + '</b>)';
}
function adm_numCh3() {
  var max = 1000;
  var i = max - document.myForm.testo.value.length;
  if (i<0) document.getElementById("adm_numch3").innerHTML = 
		'(max ' + max + ' caratteri, <b>togline' + (i * -1) + '</b>)';
  else if (i==0) document.getElementById("adm_numch3").innerHTML = 
		'(max ' + max + ' caratteri, <b>fermati</b>)';
  else if (i==1) document.getElementById("adm_numch3").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>solo uno</b>)';
  else if (i==max) document.getElementById("adm_numch3").innerHTML =  
		'(max ' + max + ' caratteri)';
  else document.getElementById("adm_numch3").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>' + i + '</b>)';
}
function adm_numCh4() {
  var max = 4000;
  var i = max - document.myForm.testo.value.length;
  if (i<0) document.getElementById("adm_numch4").innerHTML = 
		'(max ' + max + ' caratteri, <b>togline' + (i * -1) + '</b>)';
  else if (i==0) document.getElementById("adm_numch4").innerHTML = 
		'(max ' + max + ' caratteri, <b>fermati</b>)';
  else if (i==1) document.getElementById("adm_numch4").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>solo uno</b>)';
  else if (i==max) document.getElementById("adm_numch4").innerHTML =  
		'(max ' + max + ' caratteri)';
  else document.getElementById("adm_numch4").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>' + i + '</b>)';
}
function adm_numCh5() {
  var max = 1000;
  var i = max - document.myForm.testo.value.length;
  if (i<0) document.getElementById("adm_numch5").innerHTML = 
		'(max ' + max + ' caratteri, <b>togline' + (i * -1) + '</b>)';
  else if (i==0) document.getElementById("adm_numch5").innerHTML = 
		'(max ' + max + ' caratteri, <b>fermati</b>)';
  else if (i==1) document.getElementById("adm_numch5").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>solo uno</b>)';
  else if (i==max) document.getElementById("adm_numch5").innerHTML =  
		'(max ' + max + ' caratteri)';
  else document.getElementById("adm_numch5").innerHTML =  
		'(max ' + max + ' caratteri, ancora <b>' + i + '</b>)';
}


function adm_menu(voce,param) {

	noaudio();
	linke_hide();
	hideEvento();
	document.getElementById("adm_help_id").style.visibility="hidden";
	prev_a = "adm_" + document.getElementById("cur_page").value;
	if (document.getElementById(prev_a)) {
		document.getElementById(prev_a).className="defl";
		document.getElementById(prev_a).setAttribute("class", "defl"); // standard CSS
		document.getElementById(prev_a).setAttribute("className", "defl"); // IE sucks!
	}

	next_a = "adm_" + voce;
	if (document.getElementById(next_a)) {
		document.getElementById(next_a).setAttribute("class", "curr"); // standard CSS
		document.getElementById(next_a).setAttribute("className", "curr"); // IE sucks!
		document.getElementById("cur_page").value = voce;
	
		ajaxpage("admin/" + voce + "/index.php?opt=" + param, "adm_page_id");
		setTimeout('field_focus()', 300);
	}
}
	
function adm_entrata() {
	// attendo un attimo per essere sicuro
	// che main.php sia caricato
	setTimeout("adm_menu('storico')", 1000); // 1 secondo
}

function verify(value) {
	var ok=0;
	for (i=0;i<value.length;i++)
		if (value.charAt(i) != ' ')
			ok=1;
	return ok;
}
	
function admin_login(id) {
		
	if (id>0) {
		fld = eval('document.myForm.pass' + id);
		ver = verify(fld.value);
			
		if (ver == 0) {
			url = "sub/admin.php?err_id=" + id;
			ajaxpage(url, "page_id");
			setTimeout("field_focus()", 500);
			return;
		}
			
		if (ajaxR_pass(id,fld.value)) {
			// true: pass corretta
			url = "admin/main.php?id=" + id;
			ajaxpage(url, "main_id");
			adm_entrata();
			return;
		}
			
		// false: pass sbagliata
		url = "sub/admin.php?err_id=9";
		ajaxpage(url, "page_id");
		setTimeout("field_focus()", 500);
		return;
						
	}
		
	// chiamo ajaxR_pass
	// giusto per aprire la sessione
	ajaxR_pass(0,'none')
	url = "admin/main.php?id=" + id;
	ajaxpage(url, "main_id");
	adm_entrata();
}

