
//coloca o carreando...
function carrega() {
	if (document.getElementById) {  // DOM3 = IE5, NS6
		document.getElementById('esconde').style.visibility = 'hidden';
	}else{
	if (document.layers) {  // Netscape 4
		document.esconde.visibility = 'hidden';
	}else{  // IE 4
		document.all.esconde.style.visibility = 'hidden';
    }
   }
}

stat=new Array(); 
function changeMain(id){
	objParent=document.getElementById(id); 
	objDaughter=document.getElementById('iDMain'+id);
	if (
	  stat[id]!=1) {stat[id]=1; 
	  objDaughter.style.display='block';
  	} else {
		if(stat[id]==1){
		stat[id]=0; 
		objDaughter.style.display='none'; 
		}  
  	}  
}

function ValidaLogin() {
	 Form = document.formLogin;
	 if (Form.email.value.length == 0) {
		 alert("O campo email é obrigatório!");
		Form.email.focus();
		return false;
	 }
	 if (Form.senha.value.length == 0) {
		 alert("O campo senha é obrigatório!");
		Form.senha.focus();
		return false;
	 }
	 Form.submit();
}

function ValidaBusca() {
	 Form = document.formBusca;
	alert(Form.busca.value.length);
	 if (Form.busca.value.length == 0) {
		 alert("O campo busca é obrigatório!");
		Form.busca.focus();
		return false;
	 }
	 Form.submit();
}
//Serve para mascara qualquer coisa

function formatar(src, mask) 
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
	src.value += texto.substring(0,1);
  }
}
/* 
Exemplos:
CEP
OnKeyPress="formatar(this, '#####-###')"
CPF
OnKeyPress="formatar(this, '###.###.###-##')"
DATA
OnKeyPress="formatar(this, '##/##/####')"
*/


//mascara para campos de data e hora
function formData(campo){
	tammax = 11;
	var tcl = event.keyCode;
	if (tcl == 9){return true;}
	ob = document.form;
	obj = eval(ob)[campo];
	vr = eval(ob)[campo].value;
	tam = vr.length;

	if (tam <= tammax && tcl != 8){tam = vr.length + 1;}
	if (tcl == 8 ){tam = tam - 1 ;}
	if ( tcl == 9 || tcl == 8 || tcl >= 48 && tcl <= 57 || tcl >= 96 && tcl <= 105 ){
		if ( tam == 3){eval(obj).value = vr.substr(0,2) + '/';}
		if ( tam == 6){eval(obj).value = vr.substr(0,5) + '/';}
		if(tam >= tammax){event.returnValue=false;}
	}
	else {event.returnValue=false;}	
}
function formHora(campo){
		tammax = 6;
		var tcl = event.keyCode;
		if (tcl == 9){return true;}
		ob = document.form;
		obj = eval(ob)[campo];
		vr = eval(ob)[campo].value;
		tam = vr.length;
	if (tam <= tammax && tcl != 8){tam = vr.length + 1;}
	if (tcl == 8 ){tam = tam - 1 ;}
	if ( tcl == 9 || tcl == 8 || tcl >= 48 && tcl <= 57 || tcl >= 96 && tcl <= 105 ){
		if ( tam == 3){eval(obj).value = vr.substr(0,2) + ':';}
		//if ( tam == 6){eval(obj).value = vr.substr(0,5) + '/';}
		if(tam >= tammax){event.returnValue=false;}
	}
	else {event.returnValue=false;}	
}


//Abre popup com para os detalhes do prod
function Detalhes(url){
	var caminho = 'inc/popups/'+url;
	window.open	(caminho, 'Detalhes', 'width=400, height=450, scrollbars=yes,scrolling=yes,resizeble=no');
}
//Abre popup comum
function Popup(caminho){
	window.open	(caminho, 'Detalhes', 'width=400, height=450, scrollbars=yes,scrolling=yes,resizeble=no');
}
//atualiza quantidade do carrinho
function AtuaQuant(i,vl){
	if (vl == "" || vl == 0){
		alert('Valor inválido!');
	}else{
	  var id = '&id_produto='+i;
	  var valor = '&quantidade=' + vl;
	  window.location = 'default.cfm?pg=carrinho&atualizar=1'+id+valor;
	}
}

//verifica a validade do cpf digitado
function valida_CPF(s){
	var i;
	s = limpa_string(s);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		return false;
	}
		return true;
}
//verifica a validade do cgc digitado
function valida_CGC(s){
	var i;
	s = limpa_string(s);
	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) return false;
		d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		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){
		return false;
	}
		return true;
}
///////////////////////////////////////////////////////////
// Mascara CNPJ
function FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}



// valida se sao nros
function valida_numeros(s){
	var i; 
	var dif = 0;
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (!((c >= "0") && (c <= "9"))){
			dif = 1;
		}
	}
	if (dif == 1){
		return false;
	}
	return true;
}
	
function validaemail(pmail){
	var str=pmail
	var filter=/^.+@.+\..{2,3}$/
	var testresults
	if (filter.test(str)){
		testresults = true
	}else{
		testresults=false
	}
	return (testresults)
}
	
// Deixa só os digitos no numero	
function limpa_string(S){
	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}
	}
	return temp
}
//verifica se dois valores sao iguais
function verif_iguais(s){
	var i; 
	var cont = 1;
	s = limpa_string(s);
	for (i = 1; i < s.length; i++){
		 if (s.charAt(i) == s.charAt((i-1))){
			cont = cont + 1; 
		 }
	}
	if (cont == s.length){
	   return true ;
	} 
	return false;
}
//formata um valor monetário
function FormValor(campo,tammax) {
	var tecla = event.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	if ( tecla >= 37 && tecla <= 40 ){return false;}
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	if ( tecla == 8 || tecla == 46 ){	tam = tam - 1 ; }
	if ( tecla == 9 || tecla == 8 || tecla == 46 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tecla == 9 ){
			return true; }
		if ( tam <= 2 ){ 
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 0) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.form[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.form[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
	else {
		event.returnValue=false;
	}	
}

function FormQuant(campo) {
	var tcl = event.keyCode;
	tammax = 10;
	cp = 3;//casas separadas por ponto
	var doc = "document.form.";
	vr = eval(doc+campo).value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	cp1= parseFloat(cp);
	cp2= parseFloat(cp + cp);
	cp3= parseFloat(cp + cp + cp);
	cp4= parseFloat(cp + cp + cp + cp);
	cp5= parseFloat(cp + cp + cp + cp + cp);
	if(tcl >= 35 && tcl <= 40 || tcl == 9 || tcl == 16 || tcl == 17){return true;}
	if (tam < tammax -1 && tcl != 8){ tam = vr.length + 1 ;}
	if (tcl == 8){tam = tam - 1 ;}
	if ( tcl >= 48 && tcl <= 57 || tcl >= 96 && tcl <= 105 || tcl == 8 || tcl == 17 && tam < tammax-1){
		if ( tam <= cp ){ document.form[campo].value = vr ; }
	 	if ( (tam > cp1) && (tam <= cp2) ){
	 		document.form[campo].value = vr.substr( 0, tam - cp1 ) + '.' + vr.substr( tam - cp1, cp ); }
	 	if ( (tam > cp2) && (tam <= cp3) ){
	 		document.form[campo].value = vr.substr( 0, tam - cp2 ) + '.' + vr.substr( tam - cp2, cp ) + '.' + vr.substr( tam - cp1, cp ) ; }
	 	if ( (tam > cp3) && (tam <= cp4) ){
	 		document.form[campo].value = vr.substr( 0, tam - cp3 ) + '.' + vr.substr( tam - cp3, cp ) + '.' + vr.substr( tam - cp2, cp ) + '.' + vr.substr( tam - cp1, cp ); }
	 	if ( (tam > cp4) && (tam <= cp5) ){
	 		document.form[campo].value = vr.substr( 0, tam - cp4 ) + '.' + vr.substr( tam - cp4, cp ) + '.' + vr.substr( tam - cp3, cp ) + '.' + vr.substr( tam - cp2, cp ) + '.' + vr.substr( tam - cp1, cp );}
	}else{event.returnValue=false;}
}

function soNum(){
	var tcl = event.keyCode
	//alert (tcl);
	if(tcl >= 48 && tcl <= 57 || tcl >= 96 && tcl <= 105 || tcl >= 35 && tcl <= 40 || tcl == 8 || tcl == 9 || tcl == 13 || tcl == 46 || tcl == 17){event.returnValue=true;}
	else{event.returnValue=false;}
}

function ContaTexto(cmp, contacmp, limite) {
	if (cmp.value.length > limite){
		cmp.value = cmp.value.substring(0, limite);
	}else{
		contacmp.value = limite - cmp.value.length;
	}
}

function MostraEsconde(id) {
	texto = document.getElementById(id);
	if (texto.style.visibility == "hidden") {
		texto.style.visibility = "visible";
		texto.style.position = "relative";
		texto.style.top = "0";
		texto.style.left = "0";
	}else{
		texto.style.visibility = "hidden";
		texto.style.position = "absolute";
		texto.style.top = "-10000";
		texto.style.left = "-10000";
	}
}
//mostra uma celula ou div escondido
function Mostra(id) {
	texto = document.getElementById(id);
	if (texto.style.visibility == "hidden") {
		texto.style.visibility = "visible";
		texto.style.position = "relative";
		texto.style.top = "0";
		texto.style.left = "0";
	} 
}
function Esconde(id) {
	texto = document.getElementById(id);
	if (texto.style.visibility == "visible") {
		texto.style.visibility = "hidden";
		texto.style.position = "absolute";
		texto.style.top = "-10000";
		texto.style.left = "-10000";
	}
}
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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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];}}
}


//funcao para controle dos campos e selects onde pode-se digitar várias letras e o valor vai sendo encontrado

aE = function( o, e, h ){ o.addEventListener ? o.addEventListener( e, h, false ) : o.attachEvent ? o.attachEvent( 'on' + e, h ) : o[ 'on' + e ] = h; }
cE = function( tN ){ return document.createElement( tN ); }

incrementalSearch = function( input, list ){
	( this.i = input ).iS = this;
	( ( this.c = document.body.appendChild( cE( 'div' ) ) ).iS = this ).c.className = 'container';
	( this.l = list || [] ).sort();
	this.s = { e: null, idx: -1 };
	this.handler = function( evt ){
		var e = /span/i.test( ( e = ( ( e = evt || event ).target || e.srcElement ) ).tagName ) ? e.parentNode : e;
		switch( evt.type ){
			case 'keydown': case 'keyup': with( { k: evt.which || evt.keyCode || 0 } ) /keyup/.test( evt.type ) ? k == 13 ? e.iS.select() : !/40|38/.test( k ) ? e.iS.show() : null : k == 40 ? e.iS.next() : k == 38 ? e.iS.previous() : null; break;
			case 'blur': incrementalSearch.fadeAway( e.iS ); /*e.iS.hide();*/ break;
			case 'click': e.parentNode.iS.select(); break;
			default: e.parentNode.iS.highlite( e );
		}
	}
	for( var i in { keydown:0xa, blur:0xb, keyup:0xc } ) aE( this.i, i, this.handler );
	this.highlite = function( e ){ this.s.e && ( this.s.e.className = 'normal' ); ( this.s.e = e ).className = 'highlite'; this.s.idx = e.getAttribute( 'listIndex' ); }
	this.select = function(){ this.s.e && ( this.i.value = this.l[ this.s.idx ] ); this.hide(); }
	this.hide = function(){ with( this.c ) { style.display = 'none'; while( childNodes.length && removeChild( childNodes[0] ) ); } }
	this.next = function(){ this.s.e && this.s.e.nextSibling && this.highlite( this.s.e.nextSibling ); }
	this.previous = function(){ this.s.e && this.s.e.previousSibling && this.highlite( this.s.e.previousSibling ); }
 	this.show = function(){
	    if( !this.i.value.length ) return;
		var x, y, i, t, found = false;
  		this.hide();
		for( i in this.l )
			if( this.i.value == this.l[i].substr( 0, this.i.value.length ) )
				with( t = this.c.appendChild( cE( 'div' ) ) ) {
					for( x in { click:1,mouseover:3 } ) aE( t, x, this.handler );
					setAttribute( 'listIndex', i );
					!found && i == this.s.idx && ++found && this.highlite( t );
					appendChild( cE( 'span' ) ).appendChild( document.createTextNode( this.i.value ) );
					this.i.value.length < this.l[i].length && appendChild( document.createTextNode( this.l[i].substring( this.i.value.length ) ) );
				}
		with( this.i ) { x = offsetLeft, y = offsetTop + offsetHeight; this.c.style.width = offsetWidth + 'px'; }
		for( t = this.i; t = t.offsetParent; x += t.offsetLeft, y += t.offsetTop );
		with( this.c ) {
			style.left = x + 'px'; style.top = y + 'px';
  			if( childNodes.length ) {
				style.display = 'block';
				style.height = childNodes.length * firstChild.offsetHeight + 'px';
				!found && this.highlite( firstChild );
			} else
				this.hide();
		}
	};
}
incrementalSearch.fadeAway = function( o ){ ( this.list = this.list || [] ) && o ? this.list.push( o ) && setTimeout( "incrementalSearch.fadeAway()", 500 ) : this.list.pop().hide(); }

//var list = [ '192.168.0.1', '192.168.0.2', '192.168.0.3', '192.168.1.1', '192.168.1.2', '192.168.1.3', '200.168.0.1', '200.168.0.2', '200.168.0.3', '200.168.1.1', '200.168.1.2', '200.168.1.3' ];
//new incrementalSearch( document.forms[0].ip, list );
//new incrementalSearch( document.forms[0].ip2, list.slice(0,4) );

//document.write( 'Lista: ', list.join( '<br />' ) );
function ValidaEmail2(campo_mail)

{
	if (campo_mail.value != '') 
	{
  	  var emailok = 0;
	  var checkStr = campo_mail.value;
	  var priaroba = checkStr.indexOf('@');
	  var ultponto = checkStr.lastIndexOf('.');

	  if (checkStr.indexOf('@') > 0 ) 
	  {
	    if (checkStr.lastIndexOf('@') == checkStr.indexOf('@')) 
		{
	      if (checkStr.lastIndexOf('.') > 0 ) 
		  {
	        if ( checkStr.lastIndexOf('.') != checkStr.length - 1) 
			{
	          if ( ultponto > priaroba ) 
			  { var emailok = 1; }
	        }
	      }
	    }
	  }
	  if (emailok != 1) 
	  {
  	    alert('E-mail inválido!');
	    campo_mail.focus();
	    return (false);
	  }
	}
} 
function janelinha(URL,largura,altura,toolbar,scrollbars,location,status,menubar,resizable) {
dia = new Date();
id = dia.getTime();
eval("pagina" + id + " = window.open(URL, '" + id + "', 'toolbar="+toolbar+",scrollbars="+scrollbars+",location="+location+",status="+status+",menubar="+menubar+",resizable="+resizable+",width="+largura+",height="+altura+"');"); }

// Função para dar reload nas paginas levando a variavel que voce precisa
function MM_jumpMenu(targ,selObj,restore){ //v3.0 
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
	if (restore) selObj.selectedIndex=0; 
	} 

