	//init variables
	var isIE;
	var isGecko;
	var isSafari;
	var isKonqueror;
	
	//PREPARA EDITOR
	//window.onload = editorIni;
	function editorIni(target, valueIni){
		targetName = target;
		this["viewSource" + targetName] = false;
		
		//VERICA BROWSER
		var ua 			= navigator.userAgent.toLowerCase();
		isIE 			= ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 
		isGecko 		= (ua.indexOf("gecko") != -1);
		isSafari 		= (ua.indexOf("safari") != -1);
		isKonqueror 	= (ua.indexOf("konqueror") != -1);
		
		//TORNA O CAMPO EDITAVEL
		setTimeout(function(){editable(target, valueIni)}, 10);
		setTimeout(function(){addInIframe(target, valueIni)}, 100);
	}
	
	
	
	//TORNA O CAMPO EDITAVEL
	function editable(target, valueIni){
		if (document.all)	var fTarget = frames[target].document;
		else				var fTarget = document.getElementById(target).contentDocument;
		
		fTarget.designMode = "on";

		//fTarget.onmouseup = setRange;
		if (document.all){
			fTarget.onmouseup  = function(){redimension(target)};
			fTarget.onkeypress = function(){redimension(target)};
			document.getElementById(target).style.overflow 	= "hidden";
			document.getElementById(target).style.height 	= "300px";
		}
	}

	//REDIMENSIONA IFRAME
	function redimension(target){
		
		var target = document.getElementById(target);
			 if (target.contentDocument) 	iframe = target.contentWindow; 			// For NS6
		else if (target.contentWindow) 		iframe = target.contentWindow.document; // For IE5.5 and IE6
		else if (target.document) 			iframe = target.document;				// For IE5
		else return false;
		  
		if (iframe.innerHeight && iframe.scrollMaxY) {// Firefox
			yWithScroll = iframe.innerHeight + iframe.scrollMaxY;
		} else if (iframe.document.body.scrollHeight > iframe.document.body.offsetHeight){ // all but Explorer Mac
			yWithScroll = iframe.document.body.scrollHeight;
		} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
			yWithScroll = iframe.document.body.offsetHeight;
 	 	}
		
		target.style.height = yWithScroll + "px";
	}

	//INSERI COMANDO
	function insertCommand(target, command, option) {
		var target;
		//RETORNA TARGET
		if (document.all)	var target = frames[target];
		else 				var target = document.getElementById(target).contentWindow;
		
		try {
			target.focus();
			target.document.execCommand(command, false, option);
			target.focus();
		} catch (e) {
			alert("Não foi possivel editar o texto");
		}
	}

	//MARCA SELEÇÃO
	function setRange(target) {
		var target = "iframe";
		//function to store range of current selection
		if (document.all) {
			var target = frames[target];
			var selection = target.document.selection; 
			if (selection != null) rng = selection.createRange();
		} else {
			var target = document.getElementById(target).contentWindow;
			var selection = target.getSelection();
			rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
		}
	}
	
	//INSERI TABELA
	function AddTable() {
		var widthType = (document.tableForm.widthType.value == "pixels") ? "" : "%";
		var html = '<table border="' + document.tableForm.border.value + '" cellpadding="' + document.tableForm.padding.value + '" ';
		
		html += 'cellspacing="' + document.tableForm.spacing.value + '" width="' + document.tableForm.width.value + widthType + '">\n';
		for (var rows = 0; rows < document.tableForm.rows.value; rows++) {
			html += "<tr>\n";
			for (cols = 0; cols < document.tableForm.columns.value; cols++) {
				html += "<td>&nbsp;</td>\n";
			}
			html+= "</tr>\n";
		}
		html += "</table>\n";
		
		insertHTML(html);
	}

	//INSERI HTML
	function insertHTML(html) {
		//RETORNA TARGET
		if (document.all)	var target = frames[parent.target];
		else 				var target = document.getElementById(parent.target).contentWindow;
		
		target.focus();
		if (document.all)	target.document.selection.createRange().pasteHTML(html);
		else				target.document.execCommand('insertHTML', false, html);
	}
	
	//ADICIONA IMAGEM
	function addImage(target) {
		var urlImg = document.getElementById("urlImg").value;
		if (document.all) {
			//retrieve selected range
			var fTarget = frames[target].document.selection; 
			if (fTarget != null) {
				var newRng = fTarget.createRange();
				newRng = rng;
				newRng.select();
			}
		}
		
		if ((urlImg != "") && (urlImg != "http://")){
			insertCommand(target, 'InsertImage', urlImg);
		}
	}
	
	function seachValueInRadio(name){
		var elements = document.getElementsByName(name);
		for (var i=0; i<elements.length; i++) {
			if (elements[i].checked){
				return elements[i].value;
			}
		}
		return false;
	}
	
	
	//ADICIONA LINK
	function insertLink(target) {
		var urlLink = document.getElementById("urlLink").value;
	
		if (!urlLink){
			urlLink = seachValueInRadio("PAGELINK");
			if (urlLink) urlLink = "javascript:loadPage('pageIntarn.php','pageContent','pageid=" + urlLink + "')";
		}
		
		if (document.all) {
			//retrieve selected range
			var fTarget = frames[target].document.selection; 
			if (fTarget != null) {
				var newRng = fTarget.createRange();
				newRng = rng;
				newRng.select();
			}
		}
		
		if ((urlLink != "") && (urlLink != "http://")){
			try {
				insertCommand(target, "Unlink", null);
				insertCommand(target, "CreateLink", urlLink);
			} catch (e) {
				//do nothing
			}
		}
	}
	
	//INSERI COR
	function setColor(target, command, color, teste) {		
		if (document.all) {
			//retrieve selected range
			var fTarget = frames[target].document.selection; 
			if (command == "hilitecolor") command = "backcolor";
			if (fTarget != null) {
				var newRng = fTarget.createRange();
				newRng = rng;
				newRng.select();
			}
		}
		insertCommand(target, command, color);
	}

	
	//MOSTRA OPÇÕES
	function showHideOption(field){
		var target = document.getElementById(field);
		if (target.style.display == "none" || !target.style.display) target.style.display = "block";
		else														 target.style.display = "none";
		setRange('iframe');
	}
	
	//VISUALIZA CODIGO FONTE
	function addInIframe(target, value) {
		targetName = target;
		
		if (document.all) 	var target = frames[target].document;
		else 				var target = document.getElementById(target).contentWindow.document;
		
		
		if (target.body) {
			target.body.innerHTML = value;
		} else {
			setTimeout(function(){addInIframe(targetName, value);}, 100);
		}
	}
	
	function removeObsolutURL(content, prefix){
		var location = document.location.href;
		location = location.split("adm");
		/*---*/
		var local = location[0];
		var strReplaceAll 	= content;
		var intIndexOfMatch = strReplaceAll.indexOf(local);
		while (intIndexOfMatch != -1){
			strReplaceAll 	= strReplaceAll.replace(local,"");
			intIndexOfMatch = strReplaceAll.indexOf(local);
		}
		
		/*---*/
		var local = "adm/";
		var intIndexOfMatch = strReplaceAll.indexOf(local);
		while (intIndexOfMatch != -1){
			strReplaceAll 	= strReplaceAll.replace(local,prefix);
			intIndexOfMatch = strReplaceAll.indexOf(local);
		}
		return strReplaceAll;
	}
	
	//VISUALIZA CODIGO FONTE
	function viewSource(target, checked) {
		targetName = target;
		
		if (document.all) 	var target = frames[target].document;
		else 				var target = document.getElementById(target).contentWindow.document;
		
		if (checked) {
			if (document.all) {
				target.body.innerText = target.body.innerHTML;
			} else {
				var htmlSrc = target.createTextNode(target.body.innerHTML);
				target.body.innerHTML = "";
				target.body.appendChild(htmlSrc);
			}
			this["viewSource" + targetName] = true;
		} else {
			if (document.all) {
				//fix for IE
				var output = escape(target.body.innerText);
				output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
				output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");

				//TROCA ENDEREÇO ABSOLUTO DAS IMAGENS
				output = removeObsolutURL(unescape(output), "../");
				
				target.body.innerHTML = output;
			} else {
				var htmlSrc = target.body.ownerDocument.createRange();
				htmlSrc.selectNodeContents(target.body);
				target.body.innerHTML = htmlSrc.toString();
			}
			this["viewSource" + targetName] = false;
		}
	}
	
	function addToTextarea(target, textarea){
		targetName = target;
		if (this["viewSource" + targetName]){
			viewSource(target, false);
		}
		
		if (document.all) 	var target = frames[target].document;
		else 				var target = document.getElementById(target).contentWindow.document;
		
		//SUBSTITUI QUANQUER REGISTRO COM ESSE ENDEREÇO
		var content = target.body.innerHTML;
		
		//TROCA ENDEREÇO ABSOLUTO DAS IMAGENS
		content = removeObsolutURL(content, "");
		
		textarea = document.getElementById(textarea);
		
		if (document.all) {
			textarea.innerText = content;
		} else {
			var htmlSrc = target.createTextNode(content);
			textarea.innerHTML = "";
			textarea.appendChild(htmlSrc);
		}
	}