//script per il riconoscimento dei browser
var browser=navigator.appName;
var b_version=navigator.appVersion;
//alert(b_version.search('5.5'));

if (browser == "Microsoft Internet Explorer") {
	if (b_version.search('7') > 0)
		document.write("<link rel='stylesheet' type='text/CSS' href='../lib/iefix7.css' media='screen' />"); 
	else 
		document.write("<link rel='stylesheet' type='text/CSS' href='../lib/iefix.css' media='screen' />"); 
}
//fine

//var myTextValue2 = '';

//var myTextValue = new Array(1);
//arr[0] = "";

var i = 0;

//FUNZIONI

function hidediv(id) { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById(id).style.display = 'none'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.id.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.id.style.visibility = 'hidden'; 
} 
} 
}
function showdiv(id) { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById(id).style.display = 'block'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.pof.visibility = 'visible'; 
} 
else { // IE 4 
document.all.pof.style.visibility = 'visible'; 
} 
} 
} 

function ShowHide(id) {
	if(document.getElementById(id).style.display != "block") {
		showdiv(id);
//		alert(document.getElementById(id).style.display+" show");
	}
	else {
		hidediv(id);
//		alert(document.getElementById(id).style.display+" hide");
	}
}

function expsession_popup() {
	window.open ("../editor/edit.php",
"mywindow","menubar=1,resizable=1,width=350,height=250"); 
}

function grande (){
	document.getElementById('testo').style.fontSize = "1.3em";
}
function piccolo (){
	document.getElementById('testo').style.fontSize = "0.7em";
}
function normale (){
	document.getElementById('testo').style.fontSize = "small";
}

function setFocus() {
  var f = null;
  if (document.getElementById) { 
    f = document.getElementById("form");
  } else if (window.form) { 
    f = window.form;
  } 
  f.posted_username.focus();
}

function setFocusTitolo() {
  document.editor.titolo.focus();
}

function formReset(){
 var x=document.forms.msg;
 x.reset();
}

function setFocusTextarea() {
	document.editor.testo.focus();
}

function formReset(){
 var x=document.forms.msg;
 x.reset();
}




function getSelectedText(){
 if (window.getSelection){
 txt = getSelectionInfo();
 }
 else if (document.getSelection) {
 txt = document.getElementById('editor').testo.getSelection();
 }
 else if (document.selection){
 txt = document.selection.createRange().text;
 }
 else return;

 return txt;
}

function setFocus(id) {

document.getElementById('editor').testo.focus();
return;
}

function getSelectionInfo() {
  
	var rv = "";
	var i,x;
	for (i = 0; x = document.getElementsByTagName("textarea")[i]; ++i)
		rv += x.value.substr(x.selectionStart, x.selectionEnd - x.selectionStart);
  
	return rv;

	
	
}


function insTesto (instext) {
	
	var mess = document.editor.testo;
        //IE support
        if (document.selection) {
            mess.focus();
            sel = document.selection.createRange();
            sel.text = instext;
            document.editor.focus();
        }
        //MOZILLA/NETSCAPE support
        else if (mess.selectionStart || mess.selectionStart == "0") {
            var startPos = mess.selectionStart;
            var endPos = mess.selectionEnd;
            var chaine = mess.value;

            mess.value = chaine.substring(0, startPos) + instext + chaine.substring(endPos, chaine.length);

            mess.selectionStart = startPos;
            mess.selectionEnd = startPos + instext.length;
            mess.focus();
			
//            mess.selectionStart = startPos + instext.length;
  //          mess.selectionEnd = startPos + instext.length;
	//		mess.focus();
            
            
        } else {
            mess.value += instext;
            mess.focus();
        }
}

function link() {
	var etichetta = getSelectedText();
	if(link = prompt("inserisci il link", "http://")) {
		var testo = "<link uri=\""+link+"\">"+etichetta+"</link>";
		insTesto(testo);
	}

}

function bold() {
	var selection = getSelectedText();
	var testo = "<bold>"+selection+"</bold>";
	
	insTesto(testo);
	
}

function italic() {
	var selection = getSelectedText();
	var testo = "<italic>"+selection+"</italic>";
	
	insTesto(testo);
	
}

function testa() {
	var selection = getSelectedText();
	var testo = "<testa>"+selection+"</testa>";
	
	insTesto(testo);
	
}

// Funzioni per l'"Annulla" e Ripristina operazioni - non funzionano.
//   nota: se li riabiliti ricordati di decommentare 'var myTextValue = new Array(1)' in testa al file
/*
function doUndo(){
  document.Undo();
}
 
function doRedo(){
  document.execCommand('redo', false, null);
}


function reset_text_value(op){
	myTextValue2 = document.editor.testo.value;
	if (op == 'undo') {
		document.editor.testo.value = myTextValue.pop();
	}
	
}
	
function save_text_value(){
	myTextValue.push(document.editor.testo.value);
	//alert(myTextValue);
}	

function save_text_value2(){
	myTextValue.push(document.editor.testo.value);
	//alert(myTextValue);
}	

*/

function changeType() {
if( (document.editor.tipo.value == "cf") || (document.editor.tipo.value == "ca") ) {	
	document.getElementById('numero').style.display = 'none';
	document.editor.napp.disabled = true;
//	document.editor.napp.style.backgroundColor = 'grey';
	document.getElementById('codice').style.display = 'none';
	document.editor.codicep.disabled = true;
//	document.editor.codicep.style.backgroundColor = 'grey';
}else {
	document.getElementById('numero').style.display = 'table-row';
	document.editor.napp.disabled = false;
//	document.editor.napp.style.backgroundColor = 'white';
	document.getElementById('codice').style.display = 'table-row';
	document.editor.codicep.disabled = false;
//	document.editor.codicep.style.backgroundColor = 'white';
}

}

function controllo(){
with(document.editor) {
	if(tipo.value=="") {
	alert("Errore: compilare il campo Tipo");
	tipo.focus();
	return false;
	}
	if( (tipo.value == "af") || (tipo.value == "ve") ) {
		if(napp.value=="") {
		alert("Errore: compilare il campo Appartamento N");
		napp.focus();
		return false;
		}
	}
	if( (tipo.value == "af") || (tipo.value == "ve") ) {
		if(codicep.value=="" && posti.value == "") {
		alert("Errore: compilare il campo Codice periodo o Posti");
		codicep.focus();
		return false;
		}
	}else {
		if(posti.value=="" && codicep.value == "") {
		alert("Errore: compilare il campo Posti");
		posti.focus();
		return false;
		}
	}
	if(giorno.value=="") {
	alert("Errore: compilare il campo Giorno");
	giorno.focus();
	return false;
	}
	if(mese.value=="") {
	alert("Errore: compilare il campo Mese");
	mese.focus();
	return false;
	}
	if(anno.value=="") {
	alert("Errore: compilare il campo Anno");
	anno.focus();
	return false;
	}
	if(giorno1.value=="") {
	alert("Errore: compilare il campo Giorno");
	giorno1.focus();
	return false;
	}
	if(mese1.value=="") {
	alert("Errore: compilare il campo Mese");
	mese1.focus();
	return false;
	}
	if(anno1.value=="") {
	alert("Errore: compilare il campo Anno");
	anno1.focus();
	return false;
	}	
	if(nome.value=="") {
	alert("Errore: compilare il campo NOME");
	nome.focus();
	return false;
	}
	if(cognome.value=="") {
	alert("Errore: compilare il campo COGNOME");
	cognome.focus();
	return false;
	}
	if(indirizzo.value=="") {
	alert("Errore: compilare il campo Indirizzo");
	indirizzo.focus();
	return false;
	}
	if(tel.value=="") {
	alert("Errore: compilare il campo Telefono");
	tel.focus();
	return false;
	}
/*	if(mail.value=="") {
	alert("Errore: compilare il campo mail");
	giorno.focus();
	return false;
	}
	*/
}

return true;
} 

function controllo_richiesta(){
with(document.richiesta) {
	if(nome.value=="") {
	alert("Errore: compilare il campo Nome");
	nome.focus();
	return false;
	}
	if(cognome.value=="") {
	alert("Errore: compilare il campo Cognome");
	cognome.focus();
	return false;
	}
	if(indirizzo.value=="") {
	alert("Errore: compilare il campo Indirizzo");
	indirizzo.focus();
	return false;
	}
	if(cap.value=="") {
	alert("Errore: compilare il campo CAP");
	cap.focus();
	return false;
	}
	if(citta.value=="") {
	alert("Errore: compilare il campo Citta");
	citta.focus();
	return false;
	}
	if(provincia.value=="") {
	alert("Errore: compilare il campo Provincia");
	provincia.focus();
	return false;
	}
	if(tel.value=="") {
	alert("Errore: compilare il campo Telefono");
	tel.focus();
	return false;
	}
	if(cell.value=="") {
	alert("Errore: compilare il campo Cellulare");
	cell.focus();
	return false;
	}
	if(mail.value=="") {
	alert("Errore: compilare il campo Mail");
	mail.focus();
	return false;
	}
	if(napp.value=="") {
	alert("Errore: compilare il campo Appartamento N");
	napp.focus();
	return false;
	}	
	if(codicep.value=="") {
	alert("Errore: compilare il campo Codice Periodo");
	codicep.focus();
	return false;
	}
	
}

return true;
} 

function controllo_utente(){
with(document.editor) {
	if(user.value=="") {
	alert("Errore: compilare il campo username");
	user.focus();
	return false;
	}
	if(pwd.value != r_pwd.value) {
	alert("la password non è stata digitata correttamente");
	pwd.focus();
	return false;
	}
	if(privilegi.value=="") {
	alert("Errore: compilare il campo privilegi");
	privilegi.focus();
	return false;
	}
	
}

return true;
} 
