var Ok = false;
var name =  navigator.appName;
var version =  parseFloat(navigator.appVersion);
var platform = navigator.platform;


if (platform == "Win32" && name == "Microsoft Internet Explorer" && version >= 4){
	Ok = true;
} else {
	Ok= false;
}


function initToolBar(ed,campo,qualiframe) {
	var eb = campo;
	if (ed!=null) {
		eb._editor = window.frames[qualiframe];
	}
}

function doFormat(what,oiframe) {
	oiframe.focus();
	 oiframe.document.execCommand(what,false,arguments[2]);
}

function EscreveDesc(Texto,campo){
	var eb = campo;
	eb._editor.EscreveTexto(Texto)
}

function ApagaTexto(campo,campovazio,oiframe){
	var eb = campo;
	eb._editor.initEditor(oiframe,campovazio)
}

function copiardesc(oiframe,campovai) {
	campovai.value = oiframe.document.body.innerHTML;
}

function validacampoiframe(campovai,textoalert){
	if((campovai.value == "") || (campovai.value == "<P id=para></P>")){
		alert(textoalert);
		return false;
	}
	return true;
}



// Default format is WYSIWYG HTML
var format="HTML"

// Set the focus to the editor

function setFocus(oiframe) {
	oiframe.focus()
}


function quebralinha(oiframe){
	var txt = oiframe.document.body.innerHTML;
	oiframe.para.insertAdjacentHTML("beforeEnd","<br>")
}


function insereimagem(oiframe,texto){
	var txt = oiframe.document.body.innerHTML
	oiframe.focus();
	var str=prompt(texto, "http:\/\/")
	if ((str!=null) && (str!="http://")) {
		ima = str;
		oiframe.document.execCommand("InsertImage",false,ima);
	}
}



function texto(oiframe){
	return oiframe.document.body.innerHTML;
}


function EscreveTexto(texto,oiframe) {
	   oiframe.document.open()
	   oiframe.document.write(texto)	  
	   oiframe.document.close()
}


function _handleKeyDown () {
var ev = this.parentWindow.event

if(ev.keyCode == 13) {
var sel=iframe_texto.document.selection.createRange();
sel.pasteHTML("<BR>");
sel.select();
ev.returnValue=false;
ev.cancelBubble=true;
}
}

// Selects all the text in the editor

function selectAllText(oiframe){
	var edit = oiframe.document;
	edit.execCommand('SelectAll');
	oiframe.focus();
}



// Initialize the editor with an empty document

function initEditor(oiframe,campovazio) {
	var htmlString = campovazio.value;
	oiframe.document.designMode="On";
	oiframe.document.open();
	oiframe.document.write(htmlString);	
	oiframe.document.close();
	oiframe.document.body.style.fontFamily = "arial";
    oiframe.document.body.style.fontSize ="10pt";
    oiframe.document.onkeydown = _handleKeyDown;
}


/*
function createLink(oiframe) {
if (!bMode) {
displayError()
return
}
var isA = getEl("A",oiframe.createRange().parentElement())
var str=prompt("Para aonde voçe quer direccionar o texto seleccionado? (http:\/\/www.mercadolivre.com\/) ",isA ? isA.href : "http:\/\/")
if ((str!=null) && (str!="http://")) {
if ((idEdit.document.selection.type=="None") && (!isA)) {
var sel=idEdit.document.selection.createRange()
sel.pasteHTML("<A HREF=\""+str+"\">"+str+"</A> ")
sel.select()
}
else
format("CreateLink",str)
}
else
idEdit.focus()
}
*/


