
//usado para redimensionar o flash quando sobreposto no conteúdo
//para não invalidar os campos dos forms

function reSizeFlash(layer,size)
{
	document.getElementById(layer).style.height=size;
}

/////////////////////////////////////////

function mousePos(item,menu) 
{
	getMouseXY(window.event);
	var txtalert;
	var screenH=(screen.availHeight-150);
	txtalert=' A posicao do mouse no Y é '+ mousey;
	txtalert+='\r\n A altura da janela é '+screen.availHeight;
	txtalert+='\r\n O limite é '+screenH;
	if (mousey>screenH)
	{
		txtalert+='\r\n O menu está em '+document.getElementById(menu).style.top;
		document.getElementById(menu).style.top=document.getElementById(menu).style.top-150;
		txtalert+='\r\n O menu foi movido para '+document.getElementById(menu).style.top;
		alert(txtalert);
	}
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{ 
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    } 
  }
}



//***************************************
//Muda para endereço novo COMBO
//***************************************

function jumpToURL(URL_List)
{
	var sUrl = URL_List.options[URL_List.selectedIndex].value;

	if (sUrl==""){
		alert("Por favor, selecione o link.");
	}else{
		var win = open(sUrl,'Link_Rapido');
		win.focus();
	}
}				
	


//***************************************
//Abre Janela de Impressão
//***************************************

	function openWindow(url,name,width,height,toolbar,directories,status,menubar,scrollbars,resizable) 
	{
		var win = open(url,name,"width="+width+",height="+height+",toolbar="+toolbar+",directories="+directories+",status="+status+",menubar="+menubar+",scrollbars="+scrollbars+",resizable="+resizable);
		win.focus();
	}

	
	
	function viewPopupPage(img) 
	{
		photo = window.open( "", "favorites","width=300,height=300,status=0,scrollbars=1,resizable=1,screenX=20,screenY=40,left=20,top=40");
		photo.document.write('<html><head><title>Ampliar foto</title></head>');
		photo.document.write('<BODY BGCOLOR=#ffffff>');
	
		photo.document.write (img);
		
		photo.document.write('<div align="right"><br><br><a style="font: bold 11px Verdana,Arial" href="Javascript:window.close();"><b>'+cls+'</b></a></div>');
		photo.document.write('</body></html>');
		photo.document.focus();
		photo.document.close();
	   // If we are on NetScape, we can bring the window to the front
		if (navigator.appName.substring(0,8) == "Netscape") photo.focus();

	}
//***************************************
//Mostra / Oculta os divs da página
//***************************************


function changeArrow(area) 
{
	if(document.getElementById('setaOn'+area).style.display=='none')
	{
		document.getElementById('setaOn'+area).style.display='block';
		document.getElementById('setaOff'+area).style.display='none';
	}
	else
	{
		document.getElementById('setaOn'+area).style.display='none';
		document.getElementById('setaOff'+area).style.display='block';
	}
}

function showDiv(area,init) 
{
	if (init==1) 
	{
		document.getElementById(area).style.display='block';
	} 
	else if (init==0) 
	{
		document.getElementById(area).style.display='none';
	} 
	else 
	{
		if(document.getElementById(area).style.display=='none')
		{
			document.getElementById(area).style.display='block';
		}
		else
		{
			document.getElementById(area).style.display='none';
		}
	}
}

  


//***************************************
//Mostrar e Ocultar itens de uma listagem
//***************************************
function showItem(area,valor,tot) 
{
	//alert(area + valor + tot);
	for (var i=0;i<tot;i++)
		fechaItem(eval(area + (i + 1)));
		abreItem(eval(area + valor));
}
function fechaItem(obj) 
{
	obj.style.display='none';
}
function abreItem(obj) 
{
	obj.style.display='';
}



function changeFont(area,valor,tot) 
{
	for (var i=0;i<tot;i++) 
	{
		var obj=area+(i+1);
		document.getElementById(obj).style.color='transparent';
	}
	var obj=area+valor;
	document.getElementById(obj).style.color='red';
}



//***************************************
//Mostra / Oculta os selects da página
//***************************************
function selectsVisibility(varVisible)
{
	for (j=0 ; j<document.forms.length ; j++)
	{
		for (i=0; i<document.forms[j].elements.length ; i++)
		{
			if (document.forms[j].elements[i].type == 'select-one')
			{
				if(document.forms[j].elements[i].name!='subject' ) 
				{
					if(varVisible==0)
					{
						document.forms[j].elements[i].style.visibility = 'hidden';
					} 
					else if (varVisible==1) 
					{
						document.forms[j].elements[i].style.visibility = 'visible'
					}
				}
			}
		}
	}
}

//***************************************
//Redirecionamento Menu
//***************************************
function menuclick(varlink)
{
//	alert(varlink);
    window.location.replace(varlink);
}


//**************************************
//Função p/ mudar a cor da linha
//**************************************


function mOvr(src,clrOver) 
{
	if (!src.contains(event.fromElement)) 
	{
		src.bgColor = clrOver;
	}
}
function mOut(src,clrIn) 
{
	if (!src.contains(event.toElement)) 
	{
		src.bgColor = clrIn; 
	}
}



//Replicar um valor em outro campo
function Preencher(formFill,formFill2) 
{
	if (formFill2.value == "") 
	{
		formFill2.value = formFill.value;
	}
}


////////////////////////////////////////////////////////////////////
//Valida numeracao com caracteres
////////////////////////////////////////////////////////////////////

function ValidaConteudoCampo(intervalo,caracter)
{ 
	//Autor: João Carlos B. Morgado (Advice Netbisiness) 
	//Data: 23/10/2001 
	//Descrição: Função para barra que seja digitado um conteúdo inválido no campo 
	//intervalo = 'A..Z' ou se tiver mais de um, faz-se: 'A..Z;a..z' 
	//caracter = '-/@!$' 
	//ex.: <input type="text" name="questao1[]" size="1" onkeypress="JavaScript:ValidaConteudoCampo('1..5','NULL');"> 
	var bvalido = false; 
	if(((caracter.toUpperCase) != 'NULL') || (caracter != ''))
	{ 
		if(caracter == "PONTUACAO")
		{
			caracter = 'ãáâéêíîõóôúûçÃÁÂÉÊÍÎÕÓÔÚÛÇ ';
		} 
		for(i=0;i<=(caracter.length);i++)
		{ 
			if((event.keyCode) == (caracter.charCodeAt(i)))
			{ 
				 bvalido = true; 
			} 
		} 
	} 
	if(!bvalido)
	{ 
		var Inicio    = ""; 
		var Fim    = ""; 
		var bRetornaFalso  = false; 
		var bEncontrou  = false; 
		var location   = -1; 
		location = intervalo.indexOf(";"); 
		if((location) > -1)
		{ 
			var restricoes = intervalo.split(";"); 
			for(i=0;i<=(restricoes.length-1);i++)
			{ 
				Inicio  = restricoes[i].substring(0,1); 
				Fim  = restricoes[i].substring(3,4); 
				if((event.keyCode >= Inicio.charCodeAt()) && (event.keyCode <= Fim.charCodeAt()))
				{ //48 57 
					bEncontrou = true; 
					i = restricoes.length; 
				} 
			} 
			if(!bEncontrou)
			{ 
				bRetornaFalso = true; 
			} 
		} 
		else if(intervalo.length == 4)
		{ 
			Inicio  = intervalo.substring(0,1); 
			Fim  = intervalo.substring(3,4); 
			if((event.keyCode >= Inicio.charCodeAt()) && (event.keyCode <= Fim.charCodeAt()))
			{ //48 57 
				bEncontrou = true; 
			} 
			if(!bEncontrou)
			{ 
				bRetornaFalso = true; 
			} 
		} 
		if(bRetornaFalso)
		{ 
			event.returnValue = false; 
		} 
	} 
} 
//***********************************
//Função de validação de CPF
//***********************************

function isCPF(st) 
{
	if (st == "") 
	  return (false);
	l = st.length;
	//alterando para se usuário não digitar os zeros na frente do CPF, completar sozinho
	if ((l == 9) || (l == 8))
	{
		for (i = l ; i < 10; i++)
		{
			st = '0' + st
		}
	}
	l = st.length;
	st2 = "";
	for (i = 0; i < l; i++)
	{
		caracter = st.substring(i,i+1);
		if ((caracter >= '0') && (caracter <= '9'));
			st2 = st2 + caracter;
	}
	if ((st2.length > 11) || (st2.length < 10))
		return (false);
	if (st2.length==10)
		st2 = '0' + st2;
		digito1 = st2.substring(9,10);
		digito2 = st2.substring(10,11);
		digito1 = parseInt(digito1,10);
		digito2 = parseInt(digito2,10);
		sum = 0; mul = 10;
	for (i = 0; i < 9 ; i++) 
	{
    	digit = st2.substring(i,i+1);
	    tproduct = parseInt(digit ,10) * mul;
	    sum += tproduct;
	    mul--;
	}
	dig1 = ( sum % 11 );
	if ( dig1==0 || dig1==1 )
	   dig1=0;
	else
	  dig1 = 11 - dig1;
	if (dig1!=digito1)
	  return (false);
	sum = 0;
	mul = 11;
	for (i = 0; i < 10 ; i++) 
	{
	    digit = st2.substring(i,i+1);
    	tproduct = parseInt(digit ,10)*mul;
	    sum += tproduct;
	    mul--;
	}
	dig2 = (sum % 11);
	if ( dig2==0 || dig2==1 )
		dig2=0;
	else
		dig2 = 11 - dig2;  
	if (dig2 != digito2)
		return (false);
	return (true);
}  


//Limpar um campo
function Limpar(formClear) 
{
	if (formClear.value == "PROCURAR") 
	{
		formClear.value = "";
	}
}





//<script LANGUAGE="JavaScript">


function imgOn(image,imgName,dir) 
{
	document[image].src = dir + '/' + [imgName];
}
function imgOff(image,imgName,dir) 
{
	document[image].src = dir + '/' + [imgName];
}


  
  ////////////////////////////////////////////////////////////////////////////
  // NOME : valida_numeros()
  // Descrição : Valida Apenas Números *****Deve ser usado do evento KeyPress
  // Parametros
///////////////////////////////////////////////////////////////////////////

function valida_numero() 
{
	if (event.keyCode < 45 || event.keyCode > 57) 
	event.returnValue = false;
}
function valida_data(obj) 
{
	if (event.keyCode < 48 || event.keyCode > 57) 
		event.returnValue = false;
	else 
	{
		if ((len(obj.value) == 3 && obj.value.substring(3,1) == '/') ||  (len(obj.value) == 6 && obj.value.substring == '/'))
		event.returnValue = false;
	} 
}
////////////////////////////////////////////////////////////////////////////
// NOME : valida_alfanum()
// Descrição : Valida Apenas Alfa Númericos *****Deve ser usado do evento KeyPress
// Parametros
///////////////////////////////////////////////////////////////////////////

function valida_alfanum() 
{
	if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97))
		event.returnValue = false;
}

////////////////////////////////////////////////////////////////////////////
// NOME : valida_alfanum1()
// Descrição : Valida Apenas Alfa Númericos *****Deve ser usado do evento KeyPress
// Parametros
///////////////////////////////////////////////////////////////////////////

function valida_alfanum1() 
{
	if (event.keyCode == 39)
		event.returnValue = false;
}

////////////////////////////////////////////////////////////////////////////
// NOME : ignoraEspaco()
// Descrição : Tirar os espaços da String 
// Parametros Entrada :String com Espaçoss
//            Saída   :String sem Espaços
//
///////////////////////////////////////////////////////////////////////////

function ignoraEspaco(string) 
{
	var temp = "";
	string = '' + string;
	splitstring = string.split("  ");
	for(i = 0; i < splitstring.length; i++)
		temp += splitstring[i];
	return temp;
}  

////////////////////////////////////////////////////////////////////////////
// NOME : Bloquear Input 
// Descrição : <input ... readonly >
///////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
// NOME : inicialMaisculo
// Descrição :Converte as Letras Iniciais para Maisculo
// Parametro Entra: str que será convertida para maisculo
//           Saída: String que returna a string convertida
///////////////////////////////////////////////////////////////////////////

function inicialMaisculo(str) 
{
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = str.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)  
	{
		for (index = 0; index < strLen; index++)  
		{
			if (index == 0)  
			{
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,strLen);
				tmpStr = tmpChar + postString;
			}
			else 
			{
				tmpChar = tmpStr.substring(index, index+1);
				if (tmpChar == " " && index < (strLen-1))   
				{
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);                    
					postString = tmpStr.substring(index+2,strLen);                      
					tmpStr = preString + tmpChar + postString;
				}
			}
		}
	}
	return tmpStr;
}

////////////////////////////////////////////////////////////////////////////
// NOME : mascara_data
// Descrição :
// Parametro 
///////////////////////////////////////////////////////////////////////////

function mascara_data(obj) 
{ 
	var mydata = ''; 
	mydata = mydata + obj.value; 
	if (mydata.length == 2)
	{ 
		mydata = mydata + '/'; 
		obj.value = mydata; 
	} 
	if (mydata.length == 5)
	{ 
		mydata = mydata + '/'; 
		obj.value = mydata; 
	} 
} 

////////////////////////////////////////////////////////////////////////////
// NOME : verifica_data
// Descrição :
// Parametro :
///////////////////////////////////////////////////////////////////////////


function verifica_data (obj,msg) 
{ 
	dia = (obj.value.substring(0,2)); 
	mes = (obj.value.substring(3,5)); 
	ano = (obj.value.substring(6,10)); 
	situacao = ""; 
	// verifica o dia valido para cada mes 
	if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) 
	{ 
		situacao = "falsa"; 
	} 
	// verifica se o mes e valido 
	if (mes < 01 || mes > 12 ) 
	{ 
		situacao = "falsa"; 
	} 
	// verifica se e ano bissexto 
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) 
	{ 
		situacao = "falsa"; 
	}     
	if (obj.value == "") 
	{ 
	     situacao = "falsa"; 
	} 
	if (situacao == "falsa") 
	{ 
		alert(msg); 
		obj.value ='';
		obj.focus(); 
		return false;
	} 
	return true;
} 






////////////////////////////////////////////////////////////////////////////
// NOME : mascara_hora
// Descriçã- xxxxxxxxxxxxxo :
// Parametro :
///////////////////////////////////////////////////////////////////////////

function mascara_hora(hora) 
{ 
	var myhora = ''; 
	myhora = myhora + hora; 
	if (myhora.length == 2) 
	{ 
		myhora = myhora + ':'; 
		document.forms[0].hora.value = myhora; 
	} 
	if (myhora.length == 5) 
	{
		verifica_hora(); 
	} 
} 

////////////////////////////////////////////////////////////////////////////
// NOME : verifica_hora
// Descrição :
// Parametro :
///////////////////////////////////////////////////////////////////////////

function verifica_hora() 
{ 
	hrs = (document.forms[0].hora.value.substring(0,2)); 
	min = (document.forms[0].hora.value.substring(3,5)); 
	alert('hrs '+ hrs); 
	alert('min '+ min); 
	situacao = ""; 
	// verifica data e hora 
	if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59))
	{ 
		situacao = "falsa"; 
	} 
	if (document.forms[0].hora.value == "") 
	{ 
		situacao = "falsa"; 
	} 
	if (situacao == "falsa") 
	{ 
		alert("Hora inválida!"); 
		document.forms[0].hora.focus(); 
	} 
} 
////////////////////////////////////////////////////////////////////////////
// NOME : formataMoeda
// Descrição :
// Parametro :
///////////////////////////////////////////////////////////////////////////

function formataMoeda(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
			cents = "0" + cents;
			for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
				num = num.substring(0,num.length-(4*i+3))+','+
				num.substring(num.length-(4*i+3));
				return (((sign)?'':'-') + 'R$' + num + '.' + cents);
}

//////////////////////////////////////////////////////////////////////////
// NOME        : ValidaIntervalo
// Descricao   : Valida intervalo entre datas
// Parametros  : Data1 - data inicial
//               Data2 - data final
///////////////////////////////////////////////////////////////////////////

function ValidaIntervalo(Data1, Data2) 
{
	var DataValorInicial = Data1;
	pos0 = DataValorInicial.indexOf("/");
	pos1 = DataValorInicial.indexOf("/", pos0 + 1);

	dia = DataValorInicial.substring(0,pos0);
	mes = DataValorInicial.substring(pos0 + 1, pos1);
	ano = DataValorInicial.substring(pos1 + 1, DataValorInicial.length);
	DataInicial = ano + mes + dia;

	var DataValorFinal = Data2;
	pos0 = DataValorFinal.indexOf("/");
	pos1 = DataValorFinal.indexOf("/", pos0 + 1);

	dia = DataValorFinal.substring(0,pos0);
	mes = DataValorFinal.substring(pos0 + 1, pos1);
	ano = DataValorFinal.substring(pos1 + 1, DataValorFinal.length);
	DataFinal = ano + mes + dia;

	if(DataFinal < DataInicial) 
	{
		return false
	}	
	return true;	
}
//////////////////////////////////////////////////////////////////////////
// NOME        : VeriPreench
// Descricao   : Verifica se o campo foi preenchido
// Parametros  : Campo - campo do formulário
///////////////////////////////////////////////////////////////////////////

function VerPreench(Campo,MSG) 
{
	if (Campo.value.length==0) 
	{
		window.alert(MSG);
		return false;
	}
	else 
	{
		return true;
	}
}
///////////////////////////////////////////////////////////////////////////
// NOME        : ChecaMail
// Descricao   : Verificar consistencia de e-mail
// Parametros  : eMail -> Campo eMail do formulario
//               MSG   -> Mensagem de erro
///////////////////////////////////////////////////////////////////////////
function ChecaMail(eMail,MSG) 
{
	if (eMail == "") 
	{ 
		alert(MSG);
		eMail.focus();
		return(false); 
	}
	var Temp   = eMail;
	var AtSym  = Temp.value.indexOf('@');
	var Period = Temp.value.lastIndexOf('.');
	var Space  = Temp.value.indexOf(' ');
	var Length = Temp.value.length - 1;
	if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1)) 
	{ 
		alert(MSG);
		Temp.focus();
		return(false);
	}
}
///////////////////////////////////////////////////////////////////////////
// NOME       : chkCount
// Descricao  : Retorna o número de checkbox selecionados
// Parametros : obj -> objeto checkbox a ser verificado
///////////////////////////////////////////////////////////////////////////

function chkCount(obj) 
{
	var c
	c = 0;
	if (typeof(obj.length)=="undefined")
	{
		if (obj.checked) 
			c=c+1;
	}
	else 
	{
		for(i=0;i<obj.length;i++)
		{
			if (obj[i].checked)
				c=c+1;   
		}
	}
	return c;
}

///////////////////////////////////////////////////////////////////////////
// NOME       : chkSel
// Descricao  : Concatena os valores dos checkbox selecionados
// Parametros : obj -> objeto checkbox a ser verificado
///////////////////////////////////////////////////////////////////////////

function chkSel(obj) 
{
	var str
	str = "";
	if (typeof(obj.length)=="undefined")
	{
		if (obj.checked) 
			str=obj.value+";";
	}
	else 
	{
	for(i=0;i<obj.length;i++) 
	{
		if (obj[i].checked)
			str=str+obj[i].value + ";";
		}    
	}
	return str;
}

//-->




//////////////////////////////////////////////////////////////////
//   Formatação de CPF / CNPJ   //////////////////////////////////
//////////////////////////////////////////////////////////////////

function validaCPF_CNPJ(field) 
{
	var erro1 = ""
	var erro2 = ""
	var i2; 
	f2 = field.value; 
	s2 = limpa_string(f2); 
	var c2 = s2.substr(0,9); 
	var dv2 = s2.substr(9,2); 
	var d12 = 0; 
	for (i2 = 0; i2 < 9; i2++) 
	{ 
		d12 += c2.charAt(i2)*(10-i2); 
	} 
	if (d12 == 0) 
	{ 
		//alert("CPF Invalido") 
		//return false; 
	} 
	d12 = 11 - (d12 % 11); 
	if (d12 > 9) d12 = 0; 
	if (dv2.charAt(0) != d12) 
	{ 
		erro2=1;
		//alert("CPF Invalido") 
		//return false; 
	} 
	d12 *= 2; 
	for (i2 = 0; i2 < 9; i2++) 
	{ 
		d12 += c2.charAt(i2)*(11-i2); 
	} 
	d12 = 11 - (d12 % 11); 
	if (d12 > 9) d12 = 0; 
	if (dv2.charAt(1) != d12) 
	{ 
		erro2=1;
		//alert("CPF Invalido") 
		//return false; 
	} 

	var i;
	s = limpa_string(field.value); 
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++) 
	{
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0) 
	{ 
		//alert("CNPJ Invalido1"); 
		//return false; 
	} 
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1) 
	{
		erro1=1;
		//alert("CNPJ Invalido") ;
		//return false;
	}
	d1 *= 2;
	for (i = 0; i < 12; i++) 
	{
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) 
	{
		erro1=1;
		//alert("CNPJ Invalido");
		//return false;
	}
	if ((erro1=="") || (erro2=="")) 
	{
		return true;
	} 
	else 
	{
		field.value="";
		alert ("CPF ou CNPJ Inválido");
		field.focus();
		return false;
	}
}
//*****************************************************
//** Checar e formata CPF / CNPJ
//*****************************************************

function limpa_string(S)
{
	// Deixa so' os digitos no numero
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	for (var i=0; i<S.length; i++)	
	{
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0)	
		{
			temp=temp+digito
		}
	} //for
	return temp
}