//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 == 'none')
		showdiv(id);
	else 
		hidediv(id);
}

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 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 red() {
	var selection = getSelectedText();
	var testo = "<red>"+selection+"</red>";
	
	insTesto(testo);
	
}


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);
}	

