
var isHTMLMode=false;
var isDiv=true;

var tamMaxCom=50;


// POST
var IE = document.all?true:false
var d = document;
function getObj (x) {
  if (d.layers) {
	return d.layers[x];
  } else if (d.all && !d.getElementById) {
	return d.all[x];
  } else {
	return d.getElementById(x);
  }
}

function EnviaDiv(){
	objT = getObj('idText');
	obj = getObj('idContent');

	var ehTexto = (objT.style.visibility=='visible');

	if (obj!=null && !ehTexto) {
		if(isDiv)
			d.envia_htm.texto.value=obj.innerHTML;
		else
		  	d.envia_htm.texto.value=obj.value;
	}
	else {
		d.envia_htm.texto.value=objT.value;
	}

	//testamos para ver se o comentario esta dentro do tamanho-limite
	if(d.envia_htm.texto.value.length<=tamMaxCom){
		d.envia_htm.submit();
		window.close();   /*FECHAMOS A NOSSA JANELA*/
	}
	else
		//alert(d.envia_htm.texto.value.length);
		//alert(tamMaxCom);
		alert("Você excedeu em "+(d.envia_htm.texto.value.length-tamMaxCom)+" caracteres o tamanho máximo permitido.");
}
function EnviaDivSemFechar(){
	obj = getObj('idContent');
	if(isDiv){
	  d.envia_htm.texto.value=obj.innerHTML;
	  }
	else
	  d.envia_htm.texto.value=obj.value;
	//testamos para ver se o comentario esta dentro do tamanho-limite
	if(d.envia_htm.texto.value.length<=tamMaxCom){
		d.envia_htm.submit();
		//window.close();   /*FECHAMOS A NOSSA JANELA*/
	}
	else
		//alert(d.envia_htm.texto.value.length);
		//alert(tamMaxCom);
		alert("Você excedeu em "+(d.envia_htm.texto.value.length-tamMaxCom)+" caracteres o tamanho máximo do comentário");
}

function Enviafechar(){
	d.envia_htm.submit();
	window.close();   /*FECHAMOS A NOSSA JANELA*/

}

// FIM POST

//function tabelacor()
function foreColor()
	{

	var cor = showModelessDialog("/editor_iframe/dialogs/cores.htm",window,"font-family:Verdana; font-size:12; scroll:no; status:no; dialogWidth:500px; dialogHeight:250px");

	alert(cor);

	//return cor;

	}


function button_over(eButton)

       {

       eButton.style.backgroundColor = "threedhighlight";

       eButton.style.borderColor = "threeddarkshadow threeddarkshadow threeddarkshadow threeddarkshadow";

       }

function button_out(eButton)

       {

       eButton.style.backgroundColor = "threedface";

       eButton.style.borderColor = "threedface";

       }

function button_out2(eButton)

       {

       eButton.style.backgroundColor = "threedface";

       eButton.style.borderColor = "black";

       }

function button_down(eButton)

       {

       eButton.style.backgroundColor = "threedlightshadow";

       eButton.style.borderColor = "threeddarkshadow threeddarkshadow threeddarkshadow threeddarkshadow";

       }

function button_up(eButton)

       {

       eButton.style.backgroundColor = "threedhighlight";

       eButton.style.borderColor = "threeddarkshadow threeddarkshadow threeddarkshadow threeddarkshadow";

       }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


function createLink()

       	{
       	idContent.focus();

       	var tr = idContent.document.selection.createRange();
       	var RangeType = idContent.document.selection.type;
	//alert(RangeType);

       	if ((tr.text=='') && (RangeType!='Control'))
       	 {
       	 alert("Por favor, selecione texto ou imagem para poder transformá-lo num link");
         return;
       	 }

       	//var endereco = prompt("Por favor digite o endereço do recurso que você quer associar ao texto selecionado", "http://");
       	//var endereco = showModalDialog("/editor_div/link.htm",tr,"font-family:Verdana; font-size:12; status:no; dialogWidth:30em; dialogHeight:20em");


       	//if(endereco != '')
       	//  idContent.document.execCommand("CreateLink",false,endereco);
	  idContent.document.execCommand("CreateLink");
       	}



function cmdExec(cmd,opt)

       {

       if(!idContent.focussed) idContent.focus();
       idContent.document.execCommand(cmd,"",opt);
       idContent.focus();

       }


function insertImage()

       {

       //var sImgSrc=prompt("Insert Image File (You can use your local image file) : ", "http://www.aspalliance.com/Yusuf/Article10/sample.jpg");

		var sImgSrc = showModalDialog("/Editor_Div/CxImg.asp","","font-family:Verdana; font-size:12; status:no; dialogWidth:30em; dialogHeight:20em");

       if(sImgSrc!=null) cmdExec("InsertImage",sImgSrc);

       }


function html()

       {

	objD = getObj('idContent');
	objT = getObj('idText');
	objbtn = getObj('mode');


	if (objT.style.visibility!='visible'){
	       objT.style.visibility = 'visible';
	       objT.value = objD.innerHTML;
	       objbtn.src = '/imagens/Editor_Peq/btn_edit.gif';
	}
	else{
    	       objT.style.visibility = 'hidden';
	       objD.innerHTML = objT.value;
	       objbtn.src = '/imagens/Editor_Peq/btn_html.gif';
	}

       	}


function insertImage()

	{
	var sImgSrc = showModalDialog("/editor_div/dialogs/CxImg.htm","","font-family:Verdana; font-size:12; scroll:no; status:no; dialogWidth:650px; dialogHeight:520px");

	if(sImgSrc!=null) cmdExec("InsertImage",sImgSrc);

	}



function ImagemExt()

       {

	   var sImgSrc = showModalDialog("/Editor_Div/ImgExt.asp","","font-family:Verdana; font-size:12; status:no; dialogWidth:32em; dialogHeight:30em");

       if(sImgSrc!=null) cmdExec("InsertImage",sImgSrc);

       }

function xforeColor(){
	var sColor = tabelacor();
	if (sColor != null){
		if (sColor.length < 6) {
			var sTempString = "000000".substring(0,6-sColor.length);
			sColor = sTempString.concat(sColor);
		}
		cmdExec("ForeColor",sColor);
	}
}

//function foreColor()
//
//       {
//
//       var CaixaCor = getObj("CaixaDlgCor");
//       var CorRet = CaixaCor.ChooseColorDlg();
//       CorRet = CorRet.toString(16);
//       if (CorRet.length < 6) {
//         inc = 127;
//         var tmp = "000000".substring(0,6-CorRet.length);
//         CorRet = tmp.concat(CorRet);
//       }
//
//       //var arr = showModalDialog("selcolor.htm","","font-family:Verdana; font-size:12; dialogHeight:50em" );
//
//       if (CorRet != null) cmdExec("ForeColor",CorRet);
//
//       }
//

function doOnKeyPress()
{

	if (event.keyCode==13)   //significa que  a tecla em questao é ENTER
	{
		if (event.shiftKey==false)
		{
			var oSel = document.selection.createRange();
			oSel.pasteHTML('<br>');
			event.cancelBubble = true;
			event.returnValue = false;
			oSel.select();
			oSel.moveEnd("character", 1);
			oSel.moveStart("character", 1);
			oSel.collapse(false);
			return false;
		}
		else
			return event.keyCode=13;
	}
}

function TestaIE55(){

    // converte todos os caracteres para caixa baixa
    var agt=navigator.userAgent.toLowerCase();

    // *** 	VERSAO DO BROWSER ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

    var is_ie3    = (is_ie && (is_major < 4));
	var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
	var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);

    if(!is_ie5_5up)
      alert("Esta página só funcionará normalmente se\nfor vista com o programa Internet Explorer\nversao 5.5 ou superior");
}


function inicializa(numChar)
{
	tamMaxCom=numChar; // especificamos o tamanho maximo do comentario
  	//document.getElementById('idContent').contentDocument.designMode = "on";
  	idContent.document.onkeypress = doOnKeyPress;
  	// TestaIE55();
}

