function onSelectMainImage(target_form_element, name, value) {
	var formObj = document.forms[0];

	formObj.alt.value = name;
	formObj.title.value = name;

	//resetImageData();
	showPreviewImage(formObj.elements[target_form_element].value, false);
}

function showPreviewImage(src, start) {
	var formObj = document.forms[0];

	selectByValue(document.forms[0], 'imagelistsrc', src);

	var elm = document.getElementById('prev');
	var src = src == "" ? src : tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);

	if (!start && tinyMCE.getParam("advimage_update_dimensions_onchange", true))
	resetImageData();

	if (src == "")
	elm.innerHTML = "";
	else
	elm.innerHTML = '<img src="' + src + '" border="0" />'

	getImageData(src);
}

function getImageData(src) {
	preloadImg = new Image();

	tinyMCE.addEvent(preloadImg, "load", updateImageData);
	tinyMCE.addEvent(preloadImg, "error", resetImageData);

	preloadImg.src = src;
}

var tam=12;
function mudaFonte(tipo)
{
	if (tipo=="mais")
	{
		if(tam<18) tam+=2;
	}else
	{
		if(tam>10) tam-=2;
	}
	document.getElementById('selcorpo').style.fontSize=tam+'px' ;
}

function abrejanela(link, nome, w, h, t, l) { //v2.0
	window.open(link,nome,'width='+w+',height='+h+', top='+t+',left='+l+',scrollbars=yes');
}
function adjust_popup()
{
	var w, h, fixedW, fixedH, diffW, diffH;

	if (document.all) {
		fixedW = document.body.clientWidth;
		fixedH = document.body.clientHeight;
		window.resizeTo(fixedW, fixedH);
		diffW = fixedW - document.body.clientWidth;
		diffH = fixedH - document.body.clientHeight;
	} else {
		fixedW = window.innerWidth;
		fixedH = window.innerHeight;
		window.resizeTo(fixedW, fixedH);
		diffW = fixedW - window.innerWidth;
		diffH = fixedH - window.innerHeight;
	}
	w = fixedW + diffW;
	h = fixedH + diffH;
	if (h >= screen.availHeight) w += 16;
	if (w >= screen.availWidth)  h += 16;
	w = Math.min(w,screen.availWidth);
	h = Math.min(h,screen.availHeight);
	window.resizeTo(w,h);
	window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}

function valida_sac(campo)
{
	if (campo.value = '') {
		alert("O campo sacado não pode estar vazio!");
		campo.focus();
		return false;
	}
}
function max(txarea)
{
	Restante = document.getElementById('Restante');
	total = 600;
	tam = txarea.value.length;
	str="";
	str=str+tam;

	Restante.innerHTML = total - str;

	if (tam > total){

		aux = txarea.value;
		txarea.value = aux.substring(0,total);
		Restante.innerHTML = 0
	}
}
function emoticon(text) {
	var txtarea = document.mural.comentario;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	}
	else {
		txtarea.value  += text;
		txtarea.focus();
	}
}
function limita_busca(form_busca)
{
	if (form_busca.search.value.length <= 3)
	{
		alert("O campo Busca deve ter no minimo 4 caracteres !!!")
		form_busca.search.value='';
		form_busca.search.focus()
		return false;
	}
}
function prod_vazio(form_prod)
{
	if (form_prod.prod.value.length == 'P')
	{
		alert("Você deve escolher um produto!!!")
		form_prod.prod.focus()
		return (false);
	}
}
function mOvr(src,clrOver) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
	}
}
function mOut(src,clrIn) {
	if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}
function mClk(src) {
	if(event.srcElement.tagName=='TD')
	src.children.tags('A')[0].click();
}
// -->
function novajanela(link) { //v2.0
	window.open(link,'janela','width=400,height=150,top=150,left=150');
}
function newindow(link) { //v2.0
	window.open(link,'window','width=190,height=100,top=150,left=150');
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}
function clearText(thefield){if(thefield.defaultValue==thefield.value)
thefield.value=""}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}
function fechar_janela(x,y) {
	alert(x)
	window.location.replace(y);

}

var menuskin = "skin1";
var display_url = 0;
function showmenuie5() {
	var rightedge = document.body.clientWidth-event.clientX;
	var bottomedge = document.body.clientHeight-event.clientY;
	if (rightedge < ie5menu.offsetWidth)
	ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth;
	else
	ie5menu.style.left = document.body.scrollLeft + event.clientX;
	if (bottomedge < ie5menu.offsetHeight)
	ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight;
	else
	ie5menu.style.top = document.body.scrollTop + event.clientY;
	ie5menu.style.visibility = "visible";
	return false;
}
function hidemenuie5() {
	ie5menu.style.visibility = "hidden";
}
function highlightie5() {
	if (event.srcElement.className == "menuitems") {
		event.srcElement.style.backgroundColor = "highlight";
		event.srcElement.style.color = "white";
		if (display_url)
		window.status = event.srcElement.url;
	}
}
function lowlightie5() {
	if (event.srcElement.className == "menuitems") {
		event.srcElement.style.backgroundColor = "";
		event.srcElement.style.color = "black";
		window.status = "";
	}
}
function jumptoie5() {
	if (event.srcElement.className == "menuitems") {
		if (event.srcElement.getAttribute("target") != null)
		window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
		else
		window.location = event.srcElement.url;
	}
}

function prod_vazio(form_prod)
{
	if (input.value.length == '')
	{
		alert("Você deve escolher um produto!!!")
		input.focus()
		return (false);
	}
}

function fechar_janela(x,y) {
	alert(x)
	window.location.replace(y);

}

function confirmar()
{
	if (confirm ("Você deseja mesmo excluir o registro?"))
	return true
	else
	return false
}

function validaChar(obj,e){
	var keypress = window.event.keyCode;
	if ((keypress != 13 && keypress < 48) || keypress > 57 )
	return false;

	return true;
}

function validaForm(){
	if (        document.form_login.ddd.value.length<2
	||        document.form_login.numero.value.length<8
	||        document.form_login.senha.value.length<4
	)
	return false;

	return true;
}


// Script Tab automatico para formularios//
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;

}
function abreCaptcha(){
	//popConfirmacao = window.open("checa.php", "AntiSpam", 'width=360, height=130');
	alert("A sessão Mural foi desabilitada para manutenção. Obrigado pela compreenção!");
	return false;
}
function valida_captcha(resposta)
{
	var codigo = document.getElementById("minhaPalavra");
	if (codigo.value == "")
	{
		window.alert("O preenchimento do campo é obrigatório!");
		return (false);
	}
	if (resposta == codigo.value)
	{
		window.opener.document.getElementById("mural").action = "mural.php";
		window.opener.document.getElementById("mural").onSubmit();
		window.opener.document.getElementById("mural").submit();
		alert(opener.document.getElementById("mural").method);
		self.close();
		return(false);
	}
	else
	{
		alert("Imagem não confere, tente mais uma vez!");
		//self.location.reload(true);
	}
}
function enviaTorpedo()
{

	var codigo = document.getElementById("minhaPalavra");
	var captcha = window.opener.document.mural.captcha;
	var frmTorpedo = window.opener.document.getElementById("mural");


	if (codigo == null)
	{
		codigo = document.frmCaptcha.minhaPalavra;
		// nao pode dar falha, se ocorrer nao pode continuar
		if (codigo == null)
		{
			window.alert("falha de javascript (imgcod)");
			return false;
		}
	}


	/*if (captcha == null)
	window.alert("falha de javascript (captcha)");*/


	if (frmTorpedo == null)
	{
		frmTorpedo = window.opener.document.mural;
	}

	if (codigo.value == "")
	{
		window.alert("O preenchimento do campo é obrigatório!");
		return (false);
	}
	//passou

	captcha.value = codigo.value;
	frmTorpedo.action = "mural.php";
	frmTorpedo.onSubmit();
	frmTorpedo.submit();

	self.close();

	return(false);
}

function abrejanela(link, nome, w, h, t, l) { //v2.0
	window.open(link,nome,'width='+w+',height='+h+', top='+t+',left='+l+',scrollbars=yes');
}
function adjust_popup()
{
	var w, h, fixedW, fixedH, diffW, diffH;

	if (document.all) {
		fixedW = document.body.clientWidth;
		fixedH = document.body.clientHeight;
		window.resizeTo(fixedW, fixedH);
		diffW = fixedW - document.body.clientWidth;
		diffH = fixedH - document.body.clientHeight;
	} else {
		fixedW = window.innerWidth;
		fixedH = window.innerHeight;
		window.resizeTo(fixedW, fixedH);
		diffW = fixedW - window.innerWidth;
		diffH = fixedH - window.innerHeight;
	}
	w = fixedW + diffW;
	h = fixedH + diffH;
	if (h >= screen.availHeight) w += 16;
	if (w >= screen.availWidth)  h += 16;
	w = Math.min(w,screen.availWidth);
	h = Math.min(h,screen.availHeight);
	window.resizeTo(w,h);
	window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}

function valida_sac(campo)
{
	if (campo.value = '') {
		alert("O campo sacado não pode estar vazio!");
		campo.focus();
		return false;
	}
}
function emoticon(text) {
	var txtarea = document.mural.comentario;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	}
	else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function prod_vazio(form_prod)
{
	if (form_prod.prod.value.length == 'P')
	{
		alert("Você deve escolher um produto!!!")
		form_prod.prod.focus()
		return (false);
	}
}
function mOvr(src,clrOver) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
	}
}
function mOut(src,clrIn) {
	if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}
function mClk(src) {
	if(event.srcElement.tagName=='TD')
	src.children.tags('A')[0].click();
}
// -->
function novajanela(link) { //v2.0
	window.open(link,'janela','width=400,height=150,top=150,left=150');
}
function newindow(link) { //v2.0
	window.open(link,'window','width=190,height=100,top=150,left=150');
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}
function clearText(thefield){if(thefield.defaultValue==thefield.value)
thefield.value=""}

function fechar_janela(x,y) {
	alert(x)
	window.location.replace(y);

}

var menuskin = "skin1";
var display_url = 0;
function showmenuie5() {
	var rightedge = document.body.clientWidth-event.clientX;
	var bottomedge = document.body.clientHeight-event.clientY;
	if (rightedge < ie5menu.offsetWidth)
	ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth;
	else
	ie5menu.style.left = document.body.scrollLeft + event.clientX;
	if (bottomedge < ie5menu.offsetHeight)
	ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight;
	else
	ie5menu.style.top = document.body.scrollTop + event.clientY;
	ie5menu.style.visibility = "visible";
	return false;
}
function hidemenuie5() {
	ie5menu.style.visibility = "hidden";
}
function highlightie5() {
	if (event.srcElement.className == "menuitems") {
		event.srcElement.style.backgroundColor = "highlight";
		event.srcElement.style.color = "white";
		if (display_url)
		window.status = event.srcElement.url;
	}
}
function lowlightie5() {
	if (event.srcElement.className == "menuitems") {
		event.srcElement.style.backgroundColor = "";
		event.srcElement.style.color = "black";
		window.status = "";
	}
}
function jumptoie5() {
	if (event.srcElement.className == "menuitems") {
		if (event.srcElement.getAttribute("target") != null)
		window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
		else
		window.location = event.srcElement.url;
	}
}

function prod_vazio(form_prod)
{
	if (input.value.length == '')
	{
		alert("Você deve escolher um produto!!!")
		input.focus()
		return (false);
	}
}

function fechar_janela(x,y) {
	alert(x)
	window.location.replace(y);

}

function confirmar()
{
	if (confirm ("Você deseja mesmo excluir o registro?"))
	return true
	else
	return false
}

function validaChar(obj,e){
	var keypress = window.event.keyCode;
	if ((keypress != 13 && keypress < 48) || keypress > 57 )
	return false;

	return true;
}

function validaForm(){
	if (        document.form_login.ddd.value.length<2
	||        document.form_login.numero.value.length<8
	||        document.form_login.senha.value.length<4
	)
	return false;

	return true;
}


// Script Tab automatico para formularios//
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;

}