// Funcao para validar form de Contato
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.name; if ((val=val.value)!="") {
	  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
		if (p<1 || p==(val.length-1)) errors+='- '+nm+' - Formato Inválido.\n';
	  } else if (test!='R') { num = parseFloat(val);
		if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
		if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
		  min=test.substring(8,p); max=test.substring(p+1);
		  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' - Preenchimento Obrigatorio.\n'; }
  } if (errors) alert('Os seguintes erros ocorreram:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}

/*********************** SERVICOS_MONTAGEM.ASP ***********************/

function abreResp(objPergunta){
	var checkStatus = document.getElementById(objPergunta).style.display;

	if(checkStatus == "none"){
		var setaStatus = "inline";
	}else{
		var setaStatus = "none";
	}
	document.getElementById(objPergunta).style.display = setaStatus;
}

/*********************** /SERVICOS_MONTAGEM.ASP ***********************/

function IEHoverPseudo() {

	var navItems = document.getElementById("primary-nav").getElementsByTagName("li");
	
	for (var i=0; i<navItems.length; i++) {
		if(navItems[i].className == "menuparent") {
			navItems[i].onmouseover=function() { this.className += " over"; }
			navItems[i].onmouseout=function() { this.className = "menuparent"; }
		}
	}

}
/*window.onload = IEHoverPseudo;*/










// Criar objeto XMLHttpRequest para Ajax
function xmlhttp() {
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	}
}
function validaData(str_data) {
	//if (str_data.length != 10) return false;
	var arr_data = str_data.split("/"); if (arr_data.length != 3) return false;
	var _dia = new Number(arr_data[0]); var _mes = new Number(arr_data[1]); _mes--; var _ano = new Number(arr_data[2]);
	var _dat = new Date(_ano, _mes, _dia);
	if ((_dat.getDate() != _dia) || (_dat.getMonth() != _mes) || (_dat.getFullYear() != _ano)) return false;
	return true;
}

// Utilizar para onFocus e onBlur dos campos, facilitar usabilidade
function mudaBack(campo, x) {
	if (x == 1)
		campo.style.backgroundColor = '#EFEFEF';
	else
		campo.style.backgroundColor = '#FFFFFF';
}
function sc_Number(e) { // mais uma SC
	var key = '';
	var len = len2 = 0;
	var strCheck = '0123456789';
	var codigo = (window.Event) ? e.which : e.keyCode;
	if (codigo == 13) 
		return true;  // Tecla Enter
	key = String.fromCharCode(codigo);  // Pega o valor de "key"
	if (strCheck.indexOf(key) == -1)
		return false;  // Nao eh uma tecla valida
}

function sc_FloatNumber(e) { // mais uma SC
	var key = '';
	var len = len2 = 0;
	var strCheck = '0123456789,';
	var codigo = (window.Event) ? e.which : e.keyCode;
	if (codigo == 13) 
		return true;  // Tecla Enter
	key = String.fromCharCode(codigo);  // Pega o valor de "key"
	if (strCheck.indexOf(key) == -1)
		return false;  // Nao eh uma tecla valida
}

function sc_FloatNumberb(e) { // mais uma SC
	var key = '';
	var len = len2 = 0;
	var strCheck = '0123456789,-';
	var codigo = (window.Event) ? e.which : e.keyCode;
	if (codigo == 13) 
		return true;  // Tecla Enter
	key = String.fromCharCode(codigo);  // Pega o valor de "key"
	if (strCheck.indexOf(key) == -1)
		return false;  // Nao eh uma tecla valida
}

function Formatar(src, mask) {
	if (src.value.length > mask.length) {
		src.value = src.value.substring(0,mask.length);
		return false;
	}
	var i = src.value.length;
	var saida = "#";
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida) 
		src.value += texto.substring(0,1);
}

function sc_TelFormat(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Campo.value;
	vr = vr.replace( "-", "" );
	tam = vr.length + 1;
 
	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 4 && tam < 6 )
			Campo.value = vr.substr( 0, tam - 4  ) + '-' + vr.substr( tam - 4, tam );
		if ( tam >= 4 && tam <= 9 )
			Campo.value = vr.substr( 0, 4 ) + '-' + vr.substr( 4, 9 );
	}
}

function sc_CFOPFormat(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Campo.value;
	vr = vr.replace( ".", "");
	tam = vr.length + 1;
	
	if ( tecla != 9 && tecla != 8 ) {
		if ( tam > 0 && tam < 5 )
			Campo.value = vr.substr( 0, tam - 1 ) + '.' + vr.substr( tam -1, tam );
		if ( tam >= 1 && tam <= 5 )
			Campo.value = vr.substr( 0, 1 ) + '.' + vr.substr( 1, 5 );
	}
}

function sc_TimeNumber(e) {
	var key = ''
	var len = len2 = 0;
	var strCheck = '0123456789:';
	var codigo = (window.Event) ? e.which : e.keyCode;
	if (codigo == 13)
		return true;
	key = String.fromCharCode(codigo);
	if (strCheck.indexOf(key) == -1)
		return false;
}
function sc_TimeFormat(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Campo.value;
	vr = vr.replace( ":", "" );
	//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, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
		if ( tam >= 5 )
			Campo.value = vr.substr( 0, 2) + ':' + vr.substr(2,2);
	}
}
function sc_TimeValidate(string) {
	hora = string;
	if (hora.length != 5) { return ' - A hora deve ser no formato HH:MM.\n' }
	else {
		if (hora.substring(0,3).indexOf(':') == 2) {
			hor = hora.substring(0,2);
			minu = hora.substring(3,5);
			if (hor < 0 || hor > 24) { return ' - Hora inválida.\n'; }
			if (minu < 0 || minu > 59) { return ' - Minuto inválido.\n'; }
		} else {
			return ' - Horário inválido.\n';
		}
	}
	return true;
}

function sc_DateFormat(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Campo.value;
	vr = vr.replace( ".", "" );
	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, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}

function sc_DateValidate(string) {
bissexto = ''
data = string
if (data.length != 10) { return ' - A data deve ser no formato DD/MM/AAAA' }
    else {
 if (data.substring(0,4).indexOf('/') == 2) {
  if (data.substring(3,8).indexOf('/') == 2) {
   dia = data.substring(0,2)
   mes = data.substring(3,5)
   ano = data.substring(6,10)
   if (mes < 0 || mes > 12) { return '#- Mês inválido'; }
   if (ano < 1890 || ano > 2100) { return '#- Ano inválido'; }
   if (mes == 01 || mes == 03 || mes == 05 || mes == 07 || mes == 08 || mes == 10 || mes == 12) { n_dias = 31 }
    else if (mes == 04 || mes == 06 || mes == 09 || mes == 11) { n_dias = 30 }
//     else if (mes == 02) { if (ano % 4 == 0 && ano % 100 != 0 && ano % 400 == 0 ) { n_dias = 29 ; bissexto = 'Sim'} else { n_dias = 28 } }
     else if (mes == 02) { if (ano % 4 == 0) { n_dias = 29 ; bissexto = 'SIM'} else { n_dias = 28 } }
   if (dia < 0 || dia > n_dias) { return '#- Dia inválido'; }
   if (bissexto == '') bissexto = 'NÃO'
//   alert('DIA: ' + dia + '\nMÊS: ' + mes + '\nANO: ' + ano + '\nBISSEXTO: ' + bissexto)
   return 'true';
  }
 }
    }
}

function sc_DateValidateN(data) {
	var bissexto = false;
	var n_dias = 31;

	if ( data.length != 10 )
		return false;
	if ( data.charAt(2) == '/' )
		if ( data.charAt(5) == '/' ) {
			dia = data.substring(0,2);
			mes = data.substring(3,5);
			ano = data.substring(6,10);
			if ( mes < 0 || mes > 12)
				return false; //mês inválido
			if ( ano < 1890 || ano > 2100 )
				return false; //ano inválido
			bissexto = ( ano % 4 == 0);
			switch (mes) {
				case '02' : if ( bissexto ) n_dias = 29; else n_dias = 28; break;
				case '04' : n_dias = 30; break;
				case '06' : n_dias = 30; break;
				case '09' : n_dias = 30; break;
				case '11' : n_dias = 30; break;
				default : n_dias = 31;
			}
		} else // '/' mes
			return false;
	else // '/' dia
		return false;
	if ( dia == 0 || dia == '0' || dia > n_dias )
		return false;

	return true;
}

function sc_CnpjFormat(Campo,teclapres) {
 var tecla = teclapres.keyCode;
 vr = Campo.value;
 tam = vr.length+1;
 	if (tecla!=8){
//		alert(vr.substr(0,2));
		if ((vr.substr(2,1)!=".")&&(tam>3)){
			vr = vr.substr(0,2) + "." + vr.substr(2,tam);
		}
		if ((vr.substr(6,1)!=".")&&(tam>7)){
			vr = vr.substr(0,6) + "." + vr.substr(6,tam);
		}
		if ((vr.substr(10,1)!="/")&&(tam>11)){
			vr = vr.substr(0,10) + "/" + vr.substr(10,tam);
		}
		if ((vr.substr(15,1)!="-")&&(tam>16)){
			vr = vr.substr(0,15) + "-" + vr.substr(15,tam);
		}
	}
	if (tam>19){
		vr = vr.substr(0,18)
	}
	Campo.value = vr;
}
function sc_CpfFormat(Campo,teclapres) {
 var tecla = teclapres.keyCode;
 vr = Campo.value;
 tam = vr.length+1;
 	if (tecla!=8){
//		alert(vr.substr(0,2));
		if ((vr.substr(3,1)!=".")&&(tam>4)){
			vr = vr.substr(0,3) + "." + vr.substr(3,tam);
		}
		if ((vr.substr(7,1)!=".")&&(tam>8)){
			vr = vr.substr(0,7) + "." + vr.substr(7,tam);
		}
		if ((vr.substr(11,1)!="-")&&(tam>12)){
			vr = vr.substr(0,11) + "-" + vr.substr(11,tam);
		}

	}
	if (tam>15){
		vr = vr.substr(0,14)
	}
	Campo.value = vr;
}
function sc_CepFormat(Campo){
 if (Campo.value.length == 5)
	 Campo.value = Campo.value + '-';
} 

//=============================================================
//==Funções relativas ao Menu==================================
//=============================================================
function menuOver(x){
	var el = document.getElementById(x);

	if(el.style.display=='none'){
		el.style.display='block';
	}
	else{
		el.style.display='none'
	}
}

//=============================================================

//=============================================================
//Script do Mouseover das listagens

function activeLine(line){
	element = document.getElementById(line);
	element.className = 'SC_trActive';
}
function desactiveLine(line, class_name){
	element = document.getElementById(line);
	element.className = class_name;
}
// a função recebe como parâmetro uma variável string
function sc_CpfValidate (CPF2) {
	var CPF;
	CPF = '';
	for (i=0;i<CPF2.length; i++){
	  if ( (CPF2.charAt(i)!='.') && (CPF2.charAt(i)!='-') )
		CPF = CPF + CPF2.charAt(i);
	}
	//alert(CPF);

 if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
  CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
  CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
  CPF == "88888888888" || CPF == "99999999999")
  return false;
 soma = 0;
 for (i=0; i < 9; i ++)
  soma += parseInt(CPF.charAt(i)) * (10 - i);
 resto = 11 - (soma % 11);
 if (resto == 10 || resto == 11)
  resto = 0;
 if (resto != parseInt(CPF.charAt(9)))
  return false;
 soma = 0;
 for (i = 0; i < 10; i ++)
  soma += parseInt(CPF.charAt(i)) * (11 - i);
 resto = 11 - (soma % 11);
 if (resto == 10 || resto == 11)
  resto = 0;
 if (resto != parseInt(CPF.charAt(10)))
  return false;
 return true;
 } 
 
 //-------------------------------------------------------------------------------
function sc_CnpjValidate(CNPJ) 
{ 
	while (CNPJ.length>CNPJ.replace('.','').length){
		CNPJ = CNPJ.replace('.','');
	}
	
	while (CNPJ.length>CNPJ.replace('-','').length){
		CNPJ = CNPJ.replace('-','');
	}
	
	while (CNPJ.length>CNPJ.replace('/','').length){
		CNPJ = CNPJ.replace('/','');
	}
	g=CNPJ.length-2; 
	if(RealTestaCNPJ(CNPJ,g) == 1){ 
		g=CNPJ.length-1; 
		if(RealTestaCNPJ(CNPJ,g) == 1){ 
			return(true); 
		} 
		else{ 
			return(false); 
		} 
	} 
	else{ 
		return(false); 
	} 
} 
function RealTestaCNPJ(CNPJ,g)  // Função auxiliar da validação de CNPJ
 { 
 var VerCNPJ=0; 
 var ind=2; 
 var tam; 
 for(f=g;f>0;f--) 
  { 
  VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind; 
  if(ind>8) 
   { 
   ind=2; 
   } 
  else 
   { 
   ind++; 
   } 
  } 
  VerCNPJ%=11; 
  if(VerCNPJ==0 || VerCNPJ==1) 
   { 
   VerCNPJ=0; 
   } 
  else 
   { 
   VerCNPJ=11-VerCNPJ; 
   } 
 if(VerCNPJ!=parseInt(CNPJ.charAt(g))) 
  { 
  return(0); 
  } 
 else 
  { 
  return(1); 
  } 
 } 
 
 

function sc_convFloat(x){
	var resultado = '';
	/*if ( isNaN(x) )
		return x;*/

	for (ind=0; ind<x.length; ind++){
		if (x.charAt(ind)!='.')
			resultado += x.charAt(ind);
	}
	resultado = resultado.replace(',','.');
	if (resultado=='')
		return 0;

	return parseFloat(resultado);
}



function formatNumber(x, casas){
	var virgula = false;
	var cont = 0;
	var resultado = parseInt(sc_convFloat(x) * 100);
	var valor='';
	
	if (x==0)
		return '0,00';


	resultado = parseFloat(resultado) / 100;
	resultado = '' + resultado;

	for (ind_f=0;ind_f<resultado.length; ind_f++){
		if (virgula){
			cont = cont + 1
		}
		if (resultado.charAt(ind_f)!='.'){
			valor = valor + resultado.charAt(ind_f);
		}
		else{
			valor = valor + ',';
			virgula=true;
		}
	}
	if (cont==0){
		valor = valor + ',00';
		cont = 3;
	} else if (cont==1){
		valor = valor + '0';
	}
	
	resultado = '';
	cont = 0
	for (ind_f=(valor.length-4); ind_f>=0; ind_f--){
		if (cont==3){
			resultado = '.' + resultado;
			cont = 0;
		}
		resultado = valor.charAt(ind_f) + resultado;
		cont++;
	}
	return resultado + valor.substring(valor.length-3,valor.length);
}

function sc_formatNumber(valor, casas) {
	var multiplicador = 0;
	var aux = 0;
	var resultado = '';
	var virgula = false;
	var posicao = 0; //casas após a vírgula

	if (valor == 0) {
		resultado = '0,';
		for (ind=1;ind<=casas;ind++)
			resultado += '0';
		return resultado;
	}

	multiplicador = Math.pow(10, casas);
	aux = Math.round( parseFloat(valor) * multiplicador );
	aux = parseFloat(aux / multiplicador);
	aux = String(aux).replace('.',','); //transforma em string e troca ponto por vírgula
	for (m=0;m<aux.length;m++) {
		if ( posicao == casas )
			break;
		resultado += aux.charAt(m);
		if ( virgula )
			posicao++;
		if ( aux.charAt(m) == ',' )
			virgula = true
	}

	if ( posicao == 0 ) resultado += ',';
	for (m=posicao;m<casas;m++)
		resultado += '0';

	tamanho = resultado.length - (casas + 1); //tamanho do rsultado - tudo após a vírgula
	posicao = 0;
	for (ind=tamanho-1;ind>=0;ind--) { //string começa na posição 0
		if ( posicao == 3 ) {
			resultado = resultado.substr( 0, ind+1 ) + '.' + resultado.substr( ind + 1, resultado.length );
			posicao = 0;
		}
		posicao++;
	}

	return resultado;
}

function sc_replace(x,a,b) 
{ 
	var resultado = '' + x;
	while (resultado!=resultado.replace(a,b)){
		resultado = resultado.replace(a,b);
	}
	
	return resultado
}

/////////SUBMENU////////////////
function menuOn(id) {
   	document.getElementById(id).style.display = "block";
   }
   
   function menuOff(id) {
   	document.getElementById(id).style.display = "none";
   }
   
/////////////////////////////
function IEHoverPseudo() {

    var navItems = document.getElementById("primary-nav").getElementsByTagName("li");
    
    for (var i=0; i<navItems.length; i++) {
        if(navItems[i].className == "menuparent") {
            navItems[i].onmouseover=function() { this.className += " over"; }
            navItems[i].onmouseout=function() { this.className = "menuparent"; }
        }
    }

}
window.onload = IEHoverPseudo;

