/*

Script (2006)

Desenvolvido por Pablo Ferreira Lopes pra Editora Lumierè 
o uso deste código é livre, mas por favor mantenha esse trecho do código
tb mande me um email dizendo obrigado (ou um e-card).

obrigado.

*/
// ============= POR RODRIGO FELIX ===============
function paginar(acao) {
	var nova;
	nova = Number(document.buscar.pg.value) + acao; 
	document.buscar.pg.value = nova;
	document.buscar.submit();
}
function pular(acao) {
	var nova;
	document.buscar.pg.value = acao;
	document.buscar.submit();
}
// DELETAR (SIMPLES)
function deletar (pergunta,destino) {
	resposta = confirm(pergunta);
	if (resposta == true) {document.location = destino;}
}
// Denunciar comentário
function denunciarComent(pergunta,pagina)	{
	/*
	scrolls = 'no';
	var altura = 10;
	var largura = 10;
	var a = (screen.height/2)-(altura/2);
	var l = (screen.width/2)-(largura/2);
	*/
	resposta = confirm(pergunta);
	if (resposta == true) {
		window.open(pagina,'info','width='+largura+',height='+altura+',top='+a+',left='+l+',scrollbars='+scrolls+',statusbar=0,resizable=no');
	}
}
// POP UP CENTRALIZADO
function popCenter(altura,largura,pagina,scrolls)	{
	if (scrolls == 'undefined') {scrolls = 'no';}
	else {scrolls = scrolls;}

	var altura = altura;
	var largura = largura;
	var a = (screen.height/2)-(altura/2);
	var l = (screen.width/2)-(largura/2);
	window.open(pagina,'info','width='+largura+',height='+altura+',top='+a+',left='+l+',scrollbars='+scrolls+',statusbar=0,resizable=no');
}
function popUp(nome,altura,largura,pagina,scrolls)	{
	if (scrolls == 'undefined') {scrolls = 'no';}
	else {scrolls = scrolls;}

	var altura = altura;
	var largura = largura;
	var a = (screen.height/2)-(altura/2);
	var l = (screen.width/2)-(largura/2);
	window.open(pagina,nome,'width='+largura+',height='+altura+',top='+a+',left='+l+',scrollbars='+scrolls+',statusbar=0,resizable=no');
}


function popUpFixo(nome,posX,posY,altura,largura,pagina,scrolls)	{
	if (scrolls == 'undefined') {scrolls = 'no';}
	else {scrolls = scrolls;}

	window.open(pagina,nome,'width='+largura+',height='+altura+',top='+posY+',left='+posX+',scrollbars='+scrolls+',statusbar=0,resizable=no');
}

//CALENDARIOS
	function setInicio(intAno,intMes,intDia,intDiaSem){
		parent.document.getElementById('intAnoIni').value=intAno
		parent.document.getElementById('intMesIni').value=intMes
		parent.document.getElementById('intDiaIni').value=intDia
		parent.document.getElementById('intSemIni').value=intDiaSem
		parent.document.getElementById('dataIni').innerHTML="Início ("+intDia +'/'+ intMes + '/' + intAno+")";
		parent.document.getElementById('dataIni').style.background = '#CCCCCC'
		// Colocando a cor de fundo no dia selecionado
		//document.getElementById('td'+intDia).style.background = '#FF3300';
	}
	
	function setFim(intAno,intMes,intDia,intDiaSem){
		parent.document.getElementById('intAnoFim').value=intAno
		parent.document.getElementById('intMesFim').value=intMes
		parent.document.getElementById('intDiaFim').value=intDia
		parent.document.getElementById('intSemFim').value=intDiaSem
		parent.document.getElementById('dataFim').innerHTML="Fim ("+intDia +'/'+ intMes + '/' + intAno+")";
		parent.document.getElementById('dataFim').style.background = '#CCCCCC'
		// Colocando a cor de fundo no dia selecionado
		// document.getElementById('td'+intDia).style.background = '#FF3300';
	}

// FIM  POR RODRIGO FELIX ============================================================


var ua = navigator.userAgent.toLowerCase();
ie = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 
gecko = (ua.indexOf("gecko") != -1);
safari = (ua.indexOf("safari") != -1);
konqueror = (ua.indexOf("konqueror") != -1);

function fctIni(){
	
	if(gecko)rte = document.getElementById('frmEdit').contentDocument;
	
	if(ie) rte = window.frames['frmEdit'].document;

	rte.designMode='on';
	//rte.body.innerHTML='';
	//if(strTexto) rte.body.innerHTML=strTexto
	
}

function fctPut(strTexto){

	idd = window.setInterval("fctPutText('"+strTexto+"')",1000)
	
}

function fctPutText(strTexto){
//alert(strTexto);
	rte.body.innerHTML=strTexto;
	window.clearInterval(idd);
	
}

function cleanTag(strTexto){
	
	tagIni = strTexto.indexOf('<')+1;
	tagFim = strTexto.indexOf('>');
	
	toClean = strTexto.substring(tagIni,tagFim)
	
	//str.replace(/Microsoft/g, "W3Schools")
	
	alert(tagIni)
	
}

function getText(){
	strRteValue = rte.body.innerHTML; 
	document.getElementById('strTexto').value=strRteValue
	//alert(strRteValue)
}

function putText(strTxt){
	//strRteValue = rte.body.innerHTML; 
	//rte.body.innerHTML="strTxt"
	alert(rte.body.innerHTML)
}

//Função de Tag (Conta os caracteres e limpa as tags)
var fctTag = "";

function fctStartTag(){
   fctTag = window.setInterval("fctContaTag()",500);
}

function fctStartTag2(){
   fctTag = window.setInterval("fctContaTag2()",500);
}

function fctContaTag(){
	strRteValue = rte.body.innerHTML;
	/*rte.body.innerHTML = strRteValue.replace(/\<P\>/,"")
	rte.body.innerHTML = strRteValue.replace(/\<\/P\>/,"")*/
	strRteValueReal = strRteValue;
	
	//Pra limpar e contar
	strRteValueReal = strRteValueReal.replace(/&nbsp;/g,"")
	strRteValueReal = strRteValueReal.replace(/\<P\>/g,"")
	strRteValueReal = strRteValueReal.replace(/\<\/P\>/g,"")
	strRteValueReal = strRteValueReal.replace(/\<\/P\>/g,"")
	
	intCaracteres = strRteValueReal.length
	
	if(intCaracteres > 115 && intCaracteres < 256 ){
		strFirstTag = strRteValueReal.substr(0,116);
		document.getElementById('strTags').value = 'T'
	} else if(intCaracteres >= 256){
		strFirstTag = strRteValueReal.substr(0,256);
		document.getElementById('strTags').value = 'T T'
	} else {
		document.getElementById('strTags').value = ''
	}
	
	
	//trRteValueReal.replace(/\<\/P\>/g,"")
   document.getElementById('intCount').value = intCaracteres
  // alert(strRteValueReal)
  
}


function fctContaTag2(){


	objTexto = document.getElementById('strTexto');
	
	intLimit1 = 46;
	intLimit2 = 231;
	intLimit3 = 5000;
	
	intCaracteres = objTexto.value.length;
	strTag1 = objTexto.value.substring(0,intLimit1);
	strTag1End = objTexto.value.substring(0,intLimit2);
	
	strTag2 = objTexto.value.substring(intLimit1-1,intLimit2);
	strTag2End = objTexto.value.substring(intLimit2-20,intLimit3);
	
	if(intCaracteres >= intLimit1 && strTag1End.indexOf("|")<=0){
		
		objTexto.value = objTexto.value.replace(strTag1,strTag1+"|");
		
	} else if(intCaracteres >= intLimit2 && strTag2End.indexOf("|")<=0){
	
		objTexto.value = objTexto.value.replace(strTag2,strTag2+"|");
	
	} else {
	
		document.getElementById('strTags').value = ''
	
	}
	
	
	//trRteValueReal.replace(/\<\/P\>/g,"")
   document.getElementById('intCount').value = intCaracteres
  // alert(strRteValueReal)
  
}

function abreLista(strUrl,strDiv,strFrm){
	
	document.getElementById(strDiv).style.visibility="visible";
	document.getElementById(strFrm).src=strUrl
}

function fechaLista(strDiv,strFrm,blnGetCheck){
	
	if(blnGetCheck)	getChk();//pega os valores dos checkbox
	
	document.getElementById(strFrm).src='blank.htm';
	document.getElementById(strDiv).style.visibility="hidden";
	
}

//Pega  lista de check da janela de lista
function getChk(){
	

	if(ie) {
		arrCheck =  window.frames['frmList'].window.document.formLista.chkItem
	}
	
	if(gecko){
		arrCheck = document.getElementById('frmList').contentDocument.getElementById('formLista').chkItem
	}
	
	arrList = "";
	for(var i=0;i<arrCheck.length;i++){

		if(arrCheck[i].checked){
			arrList += arrCheck[i].value + ",";
		}

	}
	//alert(arrList)
	document.getElementById('arrList').value = arrList


}
function fctBold(){
	
	document.getElementById('strTexto').focus();
	strTxtAtual = document.getElementById('strTexto')
	
	if(ie) strSel = document.selection.createRange().text;
	
	if(gecko) strSel = document.getSelection();
	
	if(strSel){
		strTxtAtual.value = strTxtAtual.value.replace(strSel,"[b]" + strSel + "[/b]");
		strSel = "";
	}
	
}

function fctIta(){
	
	document.getElementById('strTexto').focus();
	strTxtAtual = document.getElementById('strTexto')
	
	if(ie) strSel = document.selection.createRange().text;
	
	if(gecko) strSel = document.getSelection();
	
	if(strSel){
		strTxtAtual.value = strTxtAtual.value.replace(strSel,"[i]" + strSel + "[/i]");
		strSel = "";
	}
	
}

function fctLink(){
	
	document.getElementById('strTexto').focus();
	strTxtAtual = document.getElementById('strTexto')
	strLink = prompt("Insira um link (para link externo escrever \"http://\")")
	
	if(ie) strSel = document.selection.createRange().text;
	
	if(gecko) strSel = document.getSelection();
	
	if(strSel){
		strTxtAtual.value = strTxtAtual.value.replace(strSel,"<a href='"+ strLink +"'>" + strSel + "</a>");
		strSel = "";
	}
	
}

function fctPop(pagina,janela,largura,altura,scroll){

	window.open(pagina,janela,'width='+largura+',height='+altura+',toolbar=no,copyhistory=no,location=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no,top=0,left=0');

}
function fctMaisLeiaMais(){
									
	intQtdLeiaMais = document.getElementById('intQtdLeiaMais').value++;
	strInputs='<input type="hidden" name="arrList[]" id="arrList'+intQtdLeiaMais+'" value="">:: Chp <input type="Text" name="arrChapeu[]" id="strChapeu'+intQtdLeiaMais+'" value=""> Título: <input type="Text" name="arrTitulo[]" id="strTitulo'+intQtdLeiaMais+'" value="" size="45">  <input type="button" onclick="fctPop(\'lista.php?strArea=listanoticias&intPass=2&idField='+intQtdLeiaMais+'\',\'listaNews\',\'500\',\'350\',\'yes\');" name="btSalvar" value="*" class="bto"><br/><br/>';
	document.getElementById('divLeiaMais').innerHTML += strInputs;
	
}
function fctMaisVejaTb(){
	intQtdVejaTb = document.getElementById('intQtdVejaTb').value++;
	strInputs='<input type="hidden" name="arrList[]" id="arrList'+intQtdVejaTb+'" value=""> Título: <input type="Text" name="arrTitulo[]" id="strTitulo'+intQtdVejaTb+'" value="" size="30">  <input type="button" onclick="fctPop(\'lista.php?strArea=listagaleria&intPass=2&idField='+intQtdVejaTb+'\',\'listaNews\',\'500\',\'350\',\'yes\');" name="btSalvar" value="*" class="bto"><br/><br/>';
	document.getElementById('divVejaTb').innerHTML += strInputs;
	
}
