function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function XMLHTTPRequest() {
	var tXHR=0;
	if (window.XMLHttpRequest) {
		tXHR=new XMLHttpRequest();
	} else {
		try{ tXHR=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e){
			try { tXHR=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e){ tXHR=false; }
		}
	}
	return tXHR;
}
var tXHR=XMLHTTPRequest();
function carrega(lk,div){
	var conteudo = "";
	if(tXHR){
		conteudo=document.getElementById(""+div+"");
		lk = lk + "&ajax=1&" + Math.ceil ( Math.random() * 100000 );
		conteudo.innerHTML = "<div class='loading'>{carregando}</div>";
		tXHR.open("GET", lk, true);
		tXHR.onreadystatechange=function(){
			if (tXHR.readyState==4){
				if(tXHR.status == 200) {
					repl = /\+/g;
					conteudo.innerHTML = unescape(tXHR.responseText.replace(repl," "));
				}
			}
		}
		tXHR.send(null);
		//setTimeout("hideRecadoBD('')",2000);
	} else {
		alert("Ative as funções de Javascript em seu computador.");
		return false;
	}
}

over = function(tdiv){
	var sfEls = "";
	var sfEls = tdiv;
	if(!sfEls.ok){
		sfEls.ok=1;
		sfEls.onmouseover=function(){
			this.className = this.className + "Over";
		}
		sfEls.onmouseout=function(){
			this.className = this.className.replace(new RegExp("Ativo\\b"), "");
			this.className = this.className.replace(new RegExp("Over\\b"), "");
		}
		sfEls.onmousedown=function(){
			this.className = this.className.replace(new RegExp("Over\\b"), "");
			this.className = this.className + "Ativo";
		}
		sfEls.className += "Over";
	}
};

changeModeSearch = function(mode,t){
	arrModeSearch = new Array("","textos","usuarios");
	for(m=1;m<=t;m++){
		if(m == mode){
			document.getElementById("ms"+m).className = "lkativo";
		} else {
			document.getElementById("ms"+m).className = "lk";
		}
	}
	document.formBusca.modeSearch.value = arrModeSearch[mode];
};



window.defaultStatus = "";
function janela(param,nome,w,h) {
	ns = document.layers;
	ie = document.all;
	rs = "yes";
	sc = "yes";
	if(w == "100%"){
		w = screen.width - 20;
		larg = 10;
	}
	if(h == "100%"){
		h = screen.height - 70;
		alt = 10;
	}
	if(!w) w=500;
	larg = ((screen.width - w)/2) - 12;
	if(!h) h=500;
	if(h == "h") {
		h=(screen.height-70);
		if(navigator.userAgent.indexOf("OS") > 0){ alt = 30; } else { alt = 5; }
		rs = "yes";
		sc = "yes";
	} else {
		alt = ((screen.height - h)/2) - 50;
	}
	winvar = window.open(param,nome,"scrollbars="+sc+",location=no,directories=no,status=no,menubar=no,resizable="+rs+",toolbar=no,top="+alt+",left="+larg+",width="+w+",height="+h);
	winvar.focus();
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function amplia1(idimg){
	alert(idimg);
}

function amplia(file){
	restaura();
	document.getElementById("divFoto").style.display = "block";
	document.getElementById("imgAmplia").src = file;
}

function fixPNG(myImage){
    if ((version >= 5.5) && (version < 7) && (document.body.filters)){
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
		var imgTitle = (myImage.title) ? "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' ";
		var imgStyle = "display:inline-block;" + myImage.style.cssText;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + myImage.width 
		+ "px; height:" + myImage.height 
		+ "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
		myImage.outerHTML = strNewHTML;
    }
}


function checkOS(){
	if(navigator.userAgent.indexOf('Linux') != -1){
		var OpSys = "Linux";
	} else { 
		if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('95') != -1)){
			var OpSys = "Win";
		} else{
			if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('98') != -1)){
				var OpSys = "Win";
			} else {
				if(navigator.userAgent.indexOf('Win') != -1){
					var OpSys = "Win";
				} else {
					if(navigator.userAgent.indexOf('Mac') != -1){
						var OpSys = "Macintosh";
					} else {
						var OpSys = "Other";
					}
				}
			}
		}
	}
	return OpSys;
}
var OpSys = checkOS();
var dimin = 0;
var hmin = 0;
function restaura(){
	var myWidth = 0, myHeight = 0;
	if(typeof(window.innerWidth) == 'number'){
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		if(myWidth < 801){ myWidth=788; }
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if(document.getElementById("divFoto")){
		if(typeof(window.scrollTop) == 'number'){
			positionY = window.scrollTop;
		} else if(document.documentElement && (document.documentElement.scrollTop)){
			positionY = document.documentElement.scrollTop;
		} else if(document.body && (document.body.scrollTop)){
			positionY = document.body.scrollTop;
		} else {
			var positionY = document.body.scrollTop;
		}
		wf = myWidth;
		hf = myHeight;
		document.getElementById("divFoto").style.width = wf + "px";
		document.getElementById("divFoto").style.height = hf + "px";
		document.getElementById("divFoto").style.top = positionY + "px";
		document.getElementById("divFoto").style.left = "0px";
	}
}

// FUNCOES SISTEMA EDITORIAL
// #########################

function edInsertLink(myField) {
	var defaultValue = 'http://';
	var URL = prompt('Endereco:' ,defaultValue);
	var URLTemp = URL.substr(7);
	URLText = URLTemp;
	var URLText = prompt('Texto "XXX" que aparece para o leitor:\n<a href="' + URL + '" target="_blank">XXX</a>' ,URLTemp);
	if(URL){
		myValue = '<a href="' + URL + '" target="_blank">' + URLText + '</a>';
		insertAtTexto(myField, myValue);
	}
}

imagemN = 0;
function insertAtTexto(myField, myValue) {
	var selTemp = "";
	if (document.selection) {
		myField.focus();
	    var sel = document.selection.createRange();
		if (sel.text.length > 0) {
			selTemp = sel.text;
		}
		
	} else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		selTemp = myField.value.substring(startPos, endPos);
	}

	if(myValue == "urlInsert"){
		var defaultValue = 'http://';
		var URL = prompt('Endereco:' ,defaultValue);
		if(URL && URL != null){
			if(selTemp == ""){
				var selTemp = URL.substr(7);
				var URLText = prompt('Texto "XXX" que aparece para o leitor:\n<a href="' + URL + '" target="_blank">XXX</a>' ,selTemp);
			} else {
				URLText = selTemp;
			}
			myValue = '<a href="' + URL + '"';
			if(URL.indexOf('http://') != -1) myValue += ' target="_blank"';
			myValue += '>' + URLText + '</a>';
		} else {
			myValue = "";
		}
	}
	if(myValue == "b>" || myValue == "i>"){
		if(selTemp == ""){
			selTemp = prompt('Texto para formatar' ,'');
		}
		myValue = '<' + myValue + '' + selTemp + '</' + myValue;
	}
	
	if(myValue.length > 0){
		if (document.selection) {
			sel.text = myValue;
			myField.focus();
		} else if (myField.selectionStart || myField.selectionStart == '0') {
			myField.value = myField.value.substring(0, startPos)
						  + myValue 
						  + myField.value.substring(endPos, myField.value.length);
			myField.focus();
			myField.selectionStart = startPos + myValue.length;
			myField.selectionEnd = startPos + myValue.length;
		} else {
			myField.value += myValue;
			myField.focus();
		}
	}
}

function countChar(campo, totchar, idval){
	cp = document.getElementById(""+campo+"").value;
	cpt = cp.length;
	numchar = totchar - cpt;
	if(numchar < 0){ numchar = 0; document.getElementById(""+campo+"").value = cp.substring(0,totchar); }
	document.getElementById(""+idval+"").innerHTML = numchar;
}

