var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;

var toolTipSTYLE="";

var TRange=null

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }	
String.prototype.ltrim = function() { return this.replace(/^\s+/, ''); }	
String.prototype.rtrim = function() { return this.replace(/\s+$/, ''); }

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function validaArquivo(ele)
{
	ext = getExtensao(ele.value);
	if (!verificaExtensao(ele.value))
	{
		alert('A extensão ' + ext + ' não é válida!');
		ele.value = '';
		return false;
	}
	else
	{
		return true;
	}
}

function getExtensao(nome_arquivo)
{
	if (nome_arquivo.length > 0)
	{
		var array_nome = nome_arquivo.split('.');
		if (array_nome.length > 1 )
		{
			var ext = array_nome[array_nome.length - 1];
			return ext;
		}
		else
		{ return ""; }			
	}
	else
	{ return ""; }
}

function conteudoFCKeditor(pInstancia) {
	try 
	{
		 var oEditor = FCKeditorAPI.GetInstance(pInstancia);
		descricao = oEditor.GetXHTML();
	}
	catch (ex)
	{
		return "erro";
	}
 
	 // --> Exibe com tag html
	// alert(descricao);
 
	// --> Exibe sem tag html
	// alert(descricao.replace(/<[^>]*>/g, ""));
}

function mudar_class(objHTML, strNovaClasse)
{
	try
	{
		try
		{ objHTML.className = strNovaClasse; }
		catch (ex)
		{
			try
			{ objHTML.setAttribute('class', strNovaClasse); }
			catch (ex)
			{ alert('Erro: \n' + ex.message); }
		}
	}
	catch (ex)
	{ alert('Erro: \n' + ex.message); }
}

// Remover Acentos
String.prototype.accnt = function () {
	var cnt = 0;
	var acnt = this;
	acnt = acnt.split('');
	acntlen = acnt.length;
	var sec = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
	var rep = ['A', 'A', 'A', 'A', 'A', 'A', 'a', 'a', 'a', 'a', 'a', 'a', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'o', 'o', 'o', 'o', 'o', 'o', 'E', 'E', 'E', 'E', 'e', 'e', 'e', 'e', 'e', 'C', 'c', 'D', 'I', 'I', 'I', 'I', 'i', 'i', 'i', 'i', 'U', 'U', 'U', 'U', 'u', 'u', 'u', 'u', 'N', 'n', 'S', 's', 'Y', 'y', 'y', 'Z', 'z'];
	for (var y = 0; y < acntlen; y++) {
		if (sec.indexOf(acnt[y]) != -1) cnt++;
	}
	return cnt;
}
String.prototype.renlacc = function () {
	var torem = this;
	torem = torem.split('');
	toremout = new Array();
	toremlen = torem.length;
	var sec = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
	var rep = ['A', 'A', 'A', 'A', 'A', 'A', 'a', 'a', 'a', 'a', 'a', 'a', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'o', 'o', 'o', 'o', 'o', 'o', 'E', 'E', 'E', 'E', 'e', 'e', 'e', 'e', 'e', 'C', 'c', 'D', 'I', 'I', 'I', 'I', 'i', 'i', 'i', 'i', 'U', 'U', 'U', 'U', 'u', 'u', 'u', 'u', 'N', 'n', 'S', 's', 'Y', 'y', 'y', 'Z', 'z'];
	for (var y = 0; y < toremlen; y++) {
		if (sec.indexOf(torem[y]) != -1) {
			toremout[y] = rep[sec.indexOf(torem[y])];
		} else toremout[y] = torem[y];
	}
	toascout = toremout.join('');
	return toascout;
}

String.prototype.removeAcentos = function () {
	pText = this;
	var countarr = new Array();
	var c = '';
	var text = pText;
	var textout = new Array();
	text = text.replace(/\r/g, '');
	text = text.split('\n');
	var linecnt = text.length;
	for (var x = 0; x < linecnt; x++) {
		countarr[x] = Math.abs(text[x].accnt());
		textout[x] = text[x].renlacc();
	}
	textout = textout.join('\n');
	return textout;
}
	
/* AJAX - Requer o Prototype */

var GlobalErroAjaxLogin;

function PostAjax(action, parametros, funcaoCarregando, funcaoRetorno, funcaoErro)
{	
	GlobalErroAjaxLogin = false;
	
	var metodo = 'post';
	var pars = parametros;
	var url = action;
	var myAjax = new Ajax.Request(
	url, 
	{
		encoding: 'iso-8859-1',
		method: 		metodo, 
		parameters: 	pars,
		onLoad: 		funcaoCarregando,
		onLoading: 		funcaoCarregando, 
		onInteractive:	funcaoCarregando,
		onFailure: 		funcaoErro,
		onComplete: 	funcaoRetorno
	});
}

function RequisicaoAjax(action, parametros, funcaoCarregando, funcaoRetorno, funcaoErro)
{
	
	GlobalErroAjaxLogin = false;
	
	var metodo = 'get';
	var pars = parametros;
	var url = action;
	var myAjax = new Ajax.Request(
	url, 
	{
		method: 		metodo, 
		parameters: 	pars,
		onLoad: 		funcaoCarregando,
		onLoading: 		funcaoCarregando, 
		onInteractive:	funcaoCarregando,
		onFailure: 		funcaoErro,
		onComplete: 	funcaoRetorno
	});
}

function erroAjaxPadrao()
{ GlobalErroAjaxLogin = true; }

/* AJAX - Requer o Prototype */

function findString (str) {
	if (parseInt(navigator.appVersion)<4) return;
	var strFound;
	if (navigator.appName=="Netscape") 
	{
		// NAVIGATOR-SPECIFIC CODE
			
		strFound=self.find(str);
		if (!strFound) 
		{
			strFound=self.find(str,0,1)
			while (self.find(str,0,1)) continue
		}
	}
	if (navigator.appName.indexOf("Microsoft")!=-1 || 1==1)
	{
	
		// EXPLORER-SPECIFIC CODE
		
		if (TRange!=null) 
		{
			TRange.collapse(false)
			strFound=TRange.findText(str)
			if (strFound) TRange.select()
		}
		if (TRange==null || strFound==0) 
		{
			TRange=self.document.body.createTextRange()
			strFound=TRange.findText(str)
			if (strFound) TRange.select()
		}
	}
	if (!strFound) alert ("String '"+str+"' not found!")
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function excluir(form, campo) {
	var campo= eval('document.'+form+'.'+campo);
	var form = eval('document.'+form);
	
	if(checou(campo)) {
		if(confirm("Deseja realmente excluir?")) {
			form.submit();
		}
	}
	else {
		alert('Selecione primeiro o que deseja excluir');
	}
}
function encaminhar(form, campo) {
	var campo= eval('document.'+form+'.'+campo);
	var form = eval('document.'+form);
	
	if(checou(campo)) {
		if(confirm("Deseja realmente marcar esses orçamentos como encaminhado?")) {
			form.submit();
		}
	}
	else {
		alert('Selecione primeiro o que deseja marcar como encaminhado');
	}
}

function abrir(url) {
	window.open(url, 'S','resizable=yes,scrollbars=no');
}

function ampliar_foto(foto) {
	abrir('popup_fotos_produto.asp?foto='+foto);
}

function apaga_valor_campo(destino) {
	destino.value = '';
}

function apenasNumero(input) {
	if ((event.keyCode<46)||(event.keyCode>57)||(event.keyCode==47)) {
		event.returnValue = false;
	}
}

function carrega() {
	document.getElementById("carrega_mensagem").style.display = 'none';
	document.getElementById("corpo").style.display = 'inline';
}

function carrega_define_posicao() {
  var x,y;
  if (self.innerHeight)
  {// all except Explorer
    x = self.innerWidth;
    y = self.innerHeight;
  }
  else 
  if (document.documentElement && document.documentElement.clientHeight)
  {// Explorer 6 Strict Mode
   x = document.documentElement.clientWidth;
   y = document.documentElement.clientHeight;
  }
  else
  if (document.body)
  {// other Explorers
   x = document.body.clientWidth;
   y = document.body.clientHeight;
  }
	var el=document.getElementById('carrega_mensagem');
	if(null!=el)
	{
		var top = (y/2) - 50;
		var left = (x/2) - 200;
		if( left<=0 ) left = 10;

		el.style.left = left + "px"
		el.style.top = top + "px";
		el.style.zIndex = 2;
	}
}

function centraliza_janela(width, height) {
	var width_janela	= eval(width);
	var height_janela	= eval(height);
	var width_tela 		= self.screen.width;
	var height_tela 	= self.screen.height;
	var pos_esquerda 	= (width_tela - width_janela)/2;
	var pos_direita 	= (height_tela - height_janela)/2;

	self.moveTo(pos_esquerda,pos_direita); //centraliza
	self.resizeTo(width_janela, height_janela); //redimensiona
}

function checou(campo) {
	if(campo) {
		if(campo.length) {
			for (var i=0; i<campo.length; i++) {
				if( campo[i].checked ) return true;
			}
			return false;
		}
		else {
			if(campo.checked) return true;
			return false;
		}
	}
	else {
		return false;
	}
}

function conta_checado(campo) {
	var acum = 0;
	if(campo) {
		if(campo.length) {
			for (var i=0; i<campo.length; i++) {
				if( campo[i].checked ) acum++;
			}
		}
		else {
			if(campo.checked) acum++;
		}
	}
	return acum;
}

function valida_campos() {
	var f = document.formulario;
	if (isDate(f.data.value)) {
		return true;
	}
	else {
		alert('Data inválida');
		return false;
	}
}

function isDate(data) {

	if(!data) return false;
	
	var data_separada = data.split('/'); //separa as datas
	if(data_separada.length < 3) return false; //deve possuir a estrutura dd:mm:aaaa
	
	var dia = data_separada[0];
	var mes = data_separada[1];
	var ano = data_separada[2];
	
	//verificando se o dia, o mês e o ano são numéricos
	if( isNaN(dia) ) return false;
	if( isNaN(mes) ) return false;
	if( isNaN(ano) ) return false;
	
	//verificando se a faixa do mês está correta
	if( (mes<0)||(mes>12) ) return false;

	//verificando se o ano possui 4 dígitos
	if( ano.length!=4 ) return false;

	var dia_max;
	
	switch (mes)
	{
		case '1':
		case '01':
		case '3':
		case '03':
		case '5':
		case '05':
		case '7':
		case '07':
		case '8':
		case '08':
		case '10':
		case '12':
		{
			dia_max=31;
			break;
		}
		case '4':
		case '04':
		case '6':
		case '06':
		case '9':
		case '09':
		case '11':
		{
			dia_max=30;
			break;
		}
		case '2':
		case '02':
		{

			if (ano%4==0) {
			//Ano bissexto
				dia_max=29;
			}
			else {
			//Ano não bissexto
				dia_max=28;
			}
			break;
		}
	}
	if( parseInt(dia) > parseInt(dia_max) ) return false;
	
	return true;
}

function aparece()
{
	document.getElementById('foto').style.display='';
}

function some() 
{
	document.getElementById('foto').style.display='none';
}

function confirma_exclusao(area,codigo)
{
  if(confirm("Deseja realmente excluir?"))
  {
   window.location = area+'_excluir.asp?codigo='+codigo;
  }
  else
  {
   alert('Exclusão cancelada');
  }
}

function excluir(form, campo) {
	var campo= eval('document.'+form+'.'+campo);
	var form = eval('document.'+form);
	
	if(checou(campo)) {
		if(confirm("Deseja realmente excluir?")) {
			form.submit();
		}
	}
	else {
		alert('Selecione primeiro o que deseja excluir');
	}
}

function apenas_numero(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	if ((key == 0) || (key == 8)) {
		return true
	}
	else {
		reg = /\d/;
		return reg.test(keychar);
	}  
}


function formata_telefone(obj, e){

    var tecla = e.keyCode;
    if (tecla == 8) {
	    return true;
    }
    else {
	    var retorno = apenas_numero(e);
	    if (retorno) {
		   // if (obj.value.length==1) {
			   // obj.value = "(" + obj.value;
		   // }
		   // if (obj.value.length==3) {
			   // obj.value = obj.value + ") ";
		   // }
		    if (obj.value.length==4) {
			    obj.value = obj.value + "-";
		    }
	    }
	return retorno;
    }
}



function ajustar_data(Campo, teclapres)
{
	var retorno = apenas_numero(teclapres);

	if (retorno) {
		if(window.event) {
			var tecla = teclapres.keyCode;
		}
		else {
			var tecla = teclapres.which;
		}
	
		var vr = new String(Campo.value);
		vr = vr.replace("/", "");
		vr = vr.replace("/", "");
		
		tam = vr.length + 1;
		
		if (tecla != 9 && tecla != 8) {
			if (tam > 2 && tam < 5) {
				Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
			}
			if (tam >= 5 && tam <= 10) {
				Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,tam-4);
			}
		}
	}
	
	return retorno;
}

//function formata_telefone(obj){
//   if (obj.value.length==4){
//	   obj.value = obj.value + "-";
//   }
//}

function formata_cpf(obj) {
	if ((event.keyCode<48)||(event.keyCode>57)){
		event.returnValue = false;
		}
	else{
		if((obj.value.length==3)||(obj.value.length==7)){
			obj.value = obj.value + ".";
		}
		else{
			if(obj.value.length==11){
				obj.value = obj.value + "-";
			}
		}
	}
}

function le_ementa(origem, destino) {
	var form    = origem.form;
	var destino = eval("document."+form.name+"."+destino);
	destino.value = ementas[origem.value];
}

function limpa_se_igual(obj, msg) {
	if(obj.value==msg) {
		obj.value='';
	}
}

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 move(index,to) {
	var list = document.form_ordenar.list;
	var total = list.options.length-1;
	if (index == -1) return false;
	if (to == +1 && index == total) return false;
	if (to == -1 && index == 0) return false;
	var items = new Array;
	var values = new Array;
	for (i = total; i >= 0; i--) {
		items[i] = list.options[i].text;
		values[i] = list.options[i].value;
	}
	for (i = total; i >= 0; i--) {
		if (index == i) {
			list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
			list.options[i] = new Option(items[i + to], values[i]);
			i--;
		}
		else {
			list.options[i] = new Option(items[i], values[i]);
		}
	}
	list.focus();
}


function move_submit() {
	var list = document.form_ordenar.list;
	var theList = "?";
	// start with a "?" to make it look like a real query-string
	for (i = 0; i <= list.options.length-1; i++) { 
		cod = list.options[i].text.split(',');
		theList += "tL" + "=" + parseInt(cod[0]);
		// a "&" only BETWEEN the items, so not at the end
		if (i != list.options.length-1) theList += "&";
	}
	//alert(theList);
	//alert(theList.length);
	location.href = document.form_ordenar.action + theList;
}

function muda_estilo(destino, estilo) {
	var obj = document.getElementById(destino);
	obj.className = estilo;
}
	
function MudaFilho(formulario, Pai, Filho, Vetor)	{
	var f=formulario.elements;
	var N=Vetor.length-1;
	var indice=f[Pai].options[f[Pai].selectedIndex].value;
	f[Filho].length=1;
	f[Filho].options[0].text='Selecione';
	f[Filho].options[0].value='';
	if (indice!=0) {  
	  for (var i = 0; i<=N; i++) {
	    if (Vetor[i][0]==indice){
				f[Filho].length=f[Filho].length+1;
				f[Filho].options[f[Filho].length-1] = new Option(Vetor[i][2],Vetor[i][1]);
	    }
	  }
	}
}

function retorna_valor_select(campo) {
	var retorno = "";
	if(campo) {
		if(campo.length) {
			for (var i=0; i<campo.length; i++) {
				if( campo[i].selected ) retorno = campo[i].value;
			}
		}
		else {
			if(campo.selected) retorno = campo.checked;
		}
	}
	else {
		retorno = "";
	}
	return retorno;
}

function suja_se_vazio(obj, msg) {
	if(obj.value=='') {
		obj.value=msg;
	}
}


	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 initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}
function toolTip(msg, fg, bg)
{
  if(toolTip.arguments.length < 1) // hide
  {
    if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
  }
  else // show
  {
    if(!fg) fg = "#204373";
    if(!bg) bg = "#D7DBE7";
    var content =
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '"><td>' +
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + bg + 
    '"><td align="center" style="font-family:Verdana; font-size:9px;"><font color="' + fg +
    '">&nbsp\;' + msg +
    '&nbsp\;</font></td></table></td></table>';
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
  }
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }
  toolTipSTYLE.left = x + offsetX;
  toolTipSTYLE.top = y + offsetY;
  return true;
}


function mmLoadMenus() {
   if (window.mm_menu_0804092726_0) return;
  window.mm_menu_0804092726_0 = new Menu("root",149,15,"Tahoma",10,"#ffffff","#ffffff","#FAA400","#F89C59","Left","middle",3,0,500,-5,7,true,true,true,0,true,true);
  mm_menu_0804092726_0.addMenuItem("Clientes","location='clientes.asp'");
  mm_menu_0804092726_0.addMenuItem("Portfolio","location='portfolio.asp'");
  mm_menu_0804092726_0.fontWeight="bold";
  mm_menu_0804092726_0.hideOnMouseOut=true;
  mm_menu_0804092726_0.bgColor='#FFFFFF';
  mm_menu_0804092726_0.menuBorder=1;
  mm_menu_0804092726_0.menuLiteBgColor='#FFFFFF';
  mm_menu_0804092726_0.menuBorderBgColor='#FFFFFF';

    
   mm_menu_0804092726_0.writeMenus();

}
