// JavaScript Document
function verRis () {
	var altezza = window.screen.height;
	if (altezza == 600) {
		document.getElementById('ris800-600').selected = true;
	}
	else {
		document.getElementById('ris1024-768').selected = true;
	}
}

function visualizza(id, tipo, img){
	if(document.getElementById){
		var el = document.getElementById(id);
		el.style.display = (el.style.display == tipo) ? "none" : tipo;
		if (img == 1) {
			var img = document.getElementById('img_' + id);
			img.src = (img.src == "http://www.vulkania.net/immagini/home/linkUno.gif") ? "http://www.vulkania.net/immagini/home/linkDue.gif" : "http://www.vulkania.net/immagini/home/linkUno.gif";	
		}		
	}
}

function mostra(id, tipo){
	if(document.getElementById){
		var el = document.getElementById(id);
		if (el.style.display != tipo) {
			el.style.display = tipo;
		}
	}
}

function creaOrologio() {
	var div = document.createTextNode('');
	document.getElementById("orologio").appendChild(div);
}

function apri(url, nome, attributi) {
	window.open (url,nome, attributi);
}

function nuova() {
	window.open('http://www.vulkania.net/index.php', 'login', 'toolbar=no, menubar=no, location=no, status=no, resizable=yes, fullscreen=yes, scrollbars=yes');
}

function conta(maxchars, testo, display) {
	var el = document.getElementById(testo);
	var disp = document.getElementById(display);
	var chars = el.value
	if (chars.length > maxchars) {
		el.value = chars.substr(0,maxchars);
	}
	var valore = maxchars - el.value.length;
	disp.firstChild.nodeValue = valore;
}

function spunta(idThis) {
	var azione = (document.getElementById(idThis).checked == true) ? true : false;
	var elementi = document.getElementsByTagName("input");
	for (var indice = 0; indice < elementi.length; indice++) {
		if (elementi.item(indice).type.toUpperCase() == "CHECKBOX") {
			elementi.item(indice).checked = azione;
		}
	}
}

function tag(testo, bottone) {
	var el = document.getElementById(testo);
	var btn = document.getElementById(bottone);
	el.value = el.value + btn.value;
	var controllo = btn.value.search(/\[\//);
	if (controllo == -1) {
		btn.value = btn.value.replace('[','[/');		
	}
	else {
		btn.value = btn.value.replace('[/','[');
	}
	el.focus();
}

function ordina(valore) {
	document.forms['ricerca'].action = '../anagrafe/anagrafe.php?ordine=' + valore;
	document.forms['ricerca'].submit();
}

function aggiungiPersonaggio(tabella) {
	var valore = parseInt(document.getElementById('idStart').value);
	var contenitore = document.createElement("tr");
	for (var indice = 1; indice <= 6; indice++) {
		var cella = document.createElement("td");
		contenitore.appendChild(cella);
		
		switch (indice) {
			case 1 :
				var size = 18;
				var name = 'nome';
				var maxchr = 10;
			break;
			case 2 :
				var size = 5;
				var name = 'exp';
				var maxchr = 3;
			break;
			case 3 :
				var size = 5;
				var name = 'frz';
				var maxchr = 2;
			break;
			case 4 :
				var size = 5;
				var name = 'int';
				var maxchr = 2;
			break;
			case 5 :
				var size = 5;
				var name = 'dxt';
				var maxchr = 2;
			break;
			case 6 :
				var size = 5;
				var name = 'denaro';
				var maxchr = 4;
			break;
		}
		if (indice != 1) {
			var negativo = document.createElement("input");
			negativo.setAttribute("type", "checkbox");
			negativo.setAttribute("name", name + "Neg" + valore);
			negativo.setAttribute("id", name + "Neg" + valore);
			negativo.setAttribute("title", "Negativo");
			negativo.setAttribute("onclick", "return avverti('" + name + "Neg"  + valore + "')");
			cella.appendChild(negativo);
		}
		
		var contenuto = document.createElement("input");
		contenuto.setAttribute("type", "text");
		contenuto.setAttribute("name", name + valore);
		contenuto.setAttribute("id", name + valore);
		contenuto.setAttribute("size", size);
		contenuto.setAttribute("maxlength", maxchr);
		if (indice != 1) {
			contenuto.setAttribute("value", '0');
		}
		cella.appendChild(contenuto);
		
	}
	document.getElementById('idStart').value = valore + 1;
	document.getElementById(tabella).appendChild(contenitore);
}

function espandi() {
	var finestra = document.getElementById('navDes');
	var larghezza = finestra.style.width;
	if (larghezza == "200px") {
		document.getElementById('navDes').style.width = "25px";
		document.getElementById('navDes').style.overflow = "hidden";
	}
	else {
		document.getElementById('navDes').style.width = "200px";
		document.getElementById('navDes').style.overflow = "auto";
	}
}

function avvisa(tipo) {
	var frase;
	switch (tipo) {
		case 1 : frase = 'Stai cancellando la chat. Vuoi procedere?';
		break;
		case 2 : frase = 'Stai eliminando alcuni messaggi. Vuoi procedere?';
		break;
		case 3 : frase = 'Stai eliminando un messaggio. Vuoi procedere?';
		break;
		case 4 : frase = 'Stai eliminando un extra. Vuoi procedere?';
		break;
		case 5 : frase = 'Stai eliminando una discussione. Vuoi procedere?';
		break;
		case 6 : frase = 'Stai sospendendo una discussione. Vuoi procedere?';
		break;
		case 7 : frase = 'Stai ripristinando una discussione. Vuoi procedere?';
		break;
		case 8 : frase = 'Stai eliminando un messaggio. Vuoi procedere?';
		break;
		case 9 : frase = 'Stai sospendendo un messaggio. Vuoi procedere?';
		break;
		case 10 : frase = 'Stai ripristinando un messaggio. Vuoi procedere?';
		break;
		case 11 : frase = 'Stai riponendo un oggetto. Vuoi procedere?';
		break;
	}
	return confirm(frase);
}

function controlla(opzioni) {
	var controllo = false;
	var okTipo = true;
	for (var i = 0; i < opzioni; i++) {
		if (okTipo){
			if(document.fato.tipo[i].checked) {
				okTipo = false;	
			}
		}
		else {
			break;
		}
	}
	if(document.fato.tipo[1].checked) {
		if (document.fato.nome.value == "") {
			controllo = true;
			frase = "Non hai inserito alcun nome";
		}
		else if (document.fato.razza.selectedIndex == 0) {
			controllo = true;
			frase = "Non hai specificato alcuna razza.";
		}
		else if (document.fato.sesso.selectedIndex == 0) {
			controllo = true;
			frase = "Non hai specificato alcun sesso.";
		}
		else if (document.fato.condizione.selectedIndex == 0) {
			controllo = true;
			frase = "Non hai specificato alcuna araldica.";
		}
	}
	if (document.fato.testo.value == "" || (document.fato.tipo[0].checked && document.fato.testo.value == "%")) {
			controllo = true;
			frase = "Non hai inserito alcun testo.";
	}
	if(okTipo){
		controllo = true
		frase = "Non hai selezionato il tipo di messaggio.";
	}
	if(controllo) {
		alert(frase);
		return false;
	}
}

function avverti(tipo) {
	var el = document.getElementById(tipo);
	if (el.checked) {
		var frase = "Stai mettendo valori negativi. Vuoi procedere?";	
	}
	else {
		var frase = "Stai mettendo valori positivi. Vuoi procedere?";
	}
	return confirm(frase)	
}