// Textarea WYSIWYG
    
 function AttivaFrame(iFrameID){
   if ($(iFrameID).contentDocument){  
 //Mozilla
     return $(iFrameID).contentDocument;
   } else {
 //Internet Explorer
     return document.frames[iFrameID].document;
    }
  }
  
function applicaComando(iFrameID, cmdStr,valCmdStr){
	AttivaFrame(iFrameID).execCommand(cmdStr,false,valCmdStr);
}
var codeAttivo = false;
function applicaCode(iFrameID, button){
	if(codeAttivo){
		AttivaFrame('editArea').body.innerHTML += '[/code]';
		button.value = 'CODE';
		codeAttivo = false;
	}
	else {
		AttivaFrame('editArea').body.innerHTML += '[code]';
		button.value += '*';
		codeAttivo = true;
	}
}
function aggiungiLink(iFrameID){
	var linkURL = prompt("Inserisci il link da aggiungere:", "");
	applicaComando(iFrameID, 'createLink', linkURL);
}
	
	

function salvaTesto(iFrameID, tipo, id_ling, id_cat, nome, descr, testo, id_oggetto){
	var testo = AttivaFrame(iFrameID).body.innerHTML;
	var req = new Ajax($('server_home').value + 'moduli/linguaggi/ajax/salvaTesto.php');
	req.data.push('id_linguaggio='+id_ling);
	req.data.push('id_categoria='+id_cat);
	req.data.push('nome='+nome);
	req.data.push('descrizione='+descr);
	req.data.push('testo='+testo);
	req.method = "post";
	req.json = true;
	req.data.push('testo=' + testo);
	req.data.push('tipo=' + tipo);
	req.data.push('id_oggetto=' + id_oggetto);
	req.onload = function(text){
		$('evErrori').className = text.classe;
		$('evErrori').innerHTML = text.msg;
		
		if(text.error == 0 && tipo == 'nuovo'){
			location.href = $('server_home').value + 'language/' + id_ling + '/cat/' + id_cat + '/show=' + text.id + '';
		}
	}
	req.send();
}