// JavaScript Document
var ultimo = new Array(2);
ultimo[0] = -1;

var ultimoCBO = "";


/*****************************************************************************************************
*****								  	 ÁREA ADMINISTRATIVA									 *****
*****************************************************************************************************/
function salvarTexto(obj)
{	
//obj.txttexto.value = document.getElementById('field_body').contentWindow.document.body.innerHTML;
    document.getElementById('txttexto').value = document.getElementById('field_body').contentWindow.document.body.innerHTML;
	return true;
}

function editarTexto()
{	var rte = document.getElementById('field_body');
	var conteudo = document.getElementById('txttexto').value;
	
	rte.contentWindow.document.body.innerHTML = conteudo
}

function limitarTexto(obj)
{	//var limite = 300;

	//if (obj.value.length >= limite)
	//	window.event.returnValue = false;
}




/*****************************************************************************************************
*****									 		 FOTOS											 *****
*****************************************************************************************************/
function verFoto(foto, w, h, op)
{	var pic = window.open('','','width=' + w + ',height=' + h);
	var fotoStr = '';

	if (foto.src.indexOf("aspx") > 0)
	{	var inicio = foto.src.indexOf("=") + 1;
		var fim = foto.src.indexOf("&");
		foto = foto.src.substr(inicio, fim - inicio)
		fotoStr = '<img src="/osgauleses/thumb.aspx?foto=' + foto + '&w=' + w + '&h=' + h + '&op=' + op + '" border="0" alt="Fechar Janela">';
	}
	else
	{	fotoStr = '<img src="' + foto.src.replace('mini/','') + '" border="0" alt="Fechar Janela">';	}
	
	pic.document.write('<html><body onblur="self.close();" topmargin="0" leftmargin="0" oncontextmenu="return false" ondragstart="return false">');
	pic.document.write('<a href="javascript:window.close()">');
	pic.document.write(fotoStr);
	pic.document.write('</a></body></html>');
}

function initFotos()
{	var checks = document.getElementsByTagName("input")

	for (x = 0; x <= checks.length - 1; x++)
	{	with (checks[x])
		{	//var tab = document.getElementById("datalistfotos__ctl" + x + "_tabela" + x)

			try
			{	if (checks[x].id.indexOf("chkfoto") >= 0)
				{	var y = checks[x].id.substring(checks[x].id.indexOf("ctl")+3, checks[x].id.lastIndexOf("_"))
					var tab = document.getElementById("datalistfotos__ctl" + y + "_tabfoto");

					if (checks[x].checked)
					{	tab.className = tab.className + "-sele"; }
					else
					{	tab.className = "tabela-foto"; }
				}
			}
			catch (e) { }
			
		}
	}
}


function validarExtensao(obj)
{	var retorno = 0;
	var arrImagens = new Array(1);
	arrImagens[0] = '.JPG'; //aki vc coloca as extensões que o arquivo pode aceitar
	//arrImagens[1] = '.GIF'; //aki vc coloca as extensões que o arquivo pode aceitar

	var extensao = null;
      
	if (obj.value == '')	//document.forms[0].elements[campo].value == '')
	{	return false; }
	else
	{	extensao = obj.value.substring(obj.value.lastIndexOf(".")).toUpperCase();
		//extensao = document.forms[0].elements[campo].value.substring(document.forms[0].elements[campo].value.lastIndexOf(".")).toUpperCase();
	
		for(i = 0; i < arrImagens.length; i++)
		{	if (extensao == arrImagens[i])
				retorno += 1;
		}     
                                 
  		if (retorno == 0)
		{	alert("Utilize imagens com extensão .JPG");
			document.forms[0].onsubmit = function() { return validarExtensao(obj); };
			obj.select();
			return false; }
		else
		{	return true; }
	}     
}

function validarExtensaoBanners(obj)
{	var retorno = 0;
	var arrImagens = new Array(3);
	arrImagens[0] = '.JPG'; //aki vc coloca as extensões que o arquivo pode aceitar
	arrImagens[1] = '.GIF'; //aki vc coloca as extensões que o arquivo pode aceitar
	arrImagens[2] = '.SWF';

	var extensao = null;
      
	if (obj.value == '')
	{	return false; }
	else
	{	extensao = obj.value.substring(obj.value.lastIndexOf(".")).toUpperCase();
	
		for(i = 0; i < arrImagens.length; i++)
		{	if (extensao == arrImagens[i])
				retorno += 1;
		}     
                                 
  		if (retorno == 0)
		{	alert("Utilize arquivos com extensão .JPG, .GIF ou .SWF");
			document.forms[0].onsubmit = function() { return validarExtensaoBanners(obj); };
			obj.select();
			return false; }
		else
		{	return true; }
	}     
}


function escondeMostra(objID)
{	var obj = document.getElementById(objID);
	var sombra = document.getElementById(objID + "Sombra");
	
	try
	{	if (obj.style.visibility == "hidden" || obj.style.visibility == '')
		{	obj.style.visibility = "visible";
			sombra.style.visibility = "visible";
		}
		else
		{	obj.style.visibility = "hidden";
			sombra.style.visibility = "hidden";
		}	
	}
	catch (e) {}
}

var frente = null;
function destaca(sender, emCima)
{	if (emCima)
	{	frente = sender.style.backgroundColor;
		sender.style.backgroundColor = "#ffffdd"; }
	else
		sender.style.backgroundColor = frente;
}
