// detecta o navegador
var ie=(((navigator.userAgent.indexOf("MSIE")>-1)||(navigator.userAgent.indexOf("Mozilla/5.0")>-1))&&navigator.userAgent.indexOf("Opera")==-1?true:false);
var ns=(navigator.userAgent.indexOf("Netscape")>-1&&navigator.userAgent.indexOf("Opera")==-1?true:false);
var agt=navigator.userAgent.toLowerCase();

function mostra(n, vl) {
    document.getElementById(n).style.visibility="visible";
    document.getElementById(n).style.top=vl;		
}
function oculta(n){
    document.getElementById(n).style.visibility="hidden";
}
function naovazio(campo, nome) {
	if(document.servico.descricao.value == "") {
		alert('N�o preencheu a Descri��o!');
		document.servico.descricao.focus();
		return false;
	} else {
		return true;
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function inteiro(e) {
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape, Firefox
		key = e.which;
	}
	if (key!=8 || key!=9 || key!=127 || (key < 17 || key > 20) || (key < 48 || key > 57)) return (((key > 47) && (key < 58)) || ((key > 16) && (key < 21)) || (key==8) || (key==9) || (key==127));
	{
       return true;
    }
}

function reais(e) {
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape, Firefox
		key = e.which;
	}
	if (key!=8 || key!=9 || key!=127 || (key < 44 || key > 46) || (key < 48 || key > 57)) return (((key > 47) && (key < 58)) || (key==8) || (key==9) || (key==127) || ((key>43) && (key<47)));
	{
       return true;
    }
}

function dinheiro(e) {
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape, Firefox
		key = e.which;
	}
	if (key!=8 || key!=9 || key!=127 || key!=44 || key!=46 || (key < 48 || key > 57)) return (((key > 47) && (key < 58)) || (key==8) || (key==9) || (key==127) || (key==44) || (key==46));
	{
       return true;
    }
}

function documentos(e) {
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape, Firefox
		key = e.which;
	}
	if (key!=8 || key!=9 || (key < 44 || key > 57)) return (((key > 43) && (key < 58)) || (key==8) || (key==9));
	{
       return true;
    }
}

function debcred(fld) {
	var campo1 = objform[fld].value;	
	if(campo1 < 100) {
	   objform[fld].style.color='red'; 
	   document.getElementById(fld).style.color='red';
	} else {
	   document.getElementById(fld).style.color='black';	
	}
}
function sobre_dia_ev(valor) {
valor.style.background='#CCFF00';
valor.style.color='#000000';
valor.style.cursor='pointer';		
}
function fora_dia_ev(valor){
valor.style.background='#FF6600';
valor.style.color='#FFFFFF';
valor.style.cursor='default';
}
function atualizalogin(campoemail, campologin) {
var email= campoemail.value;
document.getElementById(campologin).value=email;
}
function RetiraCaracteresInvalidos(strCampo,tam) {
	nTamanho = strCampo.length;
	szCampo = "";
	j=0;
	for (i = nTamanho-1;i>=0;i--) 
	{
		if (isDigit(strCampo.charAt(i)))	{
			szCampo = strCampo.charAt(i) + szCampo;
			j++;
			if (j > tam) break;
		}
	}
	if (szCampo.length < tam) {
		for (i = szCampo.length;i<tam;i++) 
		{
			szCampo = "0" + szCampo;
		}
	}
    return szCampo;
}
function ContaDigitos(strCampo) {
	nTamanho = strCampo.length;
	szCampo = "";
	j=0;
	for (i = nTamanho-1;i>=0;i--) 
	{
		if (isDigit(strCampo.charAt(i)))	{
			szCampo = strCampo.charAt(i) + szCampo;
			j++;
		}
	}
    return j;
}
function ajustar_data(input, evento)
{
         var BACKSPACE=  8; 
         var DEL=  46; 
         var FRENTE=  39; 
         var TRAS=  37; 
         var tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
         if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS)) {
             return true; 
             }
         if ( tecla == 13 )     return false; 


		if ((tecla<48)||(tecla>57)) {
			evento.returnValue = false; 
			return false;
			} else { 
				if ((input.value.length==2)||(input.value.length==5)) {
				   input.value=input.value + "/" ;
				   }
			}
			//
			//
  return true;			
};

function editadata(strCampo,tam) {
    var i;
    var j;
    var nTamanho;
    var szCampo;
	nTamanho = strCampo.length;
	szCampo = "";
	j=0;
	for (i = nTamanho-1;i>=0;i--) 
	{
		if (isDigit(strCampo.charAt(i)))	{
			szCampo = strCampo.charAt(i) + szCampo;
		    j++;
			if (j > tam) break;
        }
	}
	if (szCampo.length < tam) {
		//for (i = szCampo.length;i<tam;i++) 
		//{
		//	szCampo = "0" + szCampo;
		//}
	}
	if (j==0) return "";
    return (szCampo.substr(0,2)+"/"+szCampo.substr(2,2)+"/"+szCampo.substr(4,4));
}

// funcoes do gomes
function categoria_on(obj, valor) {
	var cor = ((valor == 0) ? '#0066FF' : '#9999FF' );
	obj.style.background=cor;
}
function categoria_off(obj, valor) {
	var cor = ((valor == 0) ? '#0000FF' : '#6666FF' );
	obj.style.background=cor;
}

// funcao do menu que exibe o submenu
function menu_on_ajax(obj, id, left, top ) {
	var cor = '#0066FF';
	var subMenu = document.getElementById('subMenu').style;
	subMenu.left = left;
	subMenu.top = top;
	subMenu.visibility="visible";
	obj.style.background=cor;
	xajax_exibeSubMenuTipoProdutos(id);
}
// funcao do menu que oculta o submenu
function menu_off_ajax(obj, id) {
	var cor = '#000099';
	obj.style.background=cor;
	//document.getElementById('subMenu').style.visibility="hidden";
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

// ao chechar permite que entra com valores no campo qtd
function checaproduto(checa, qtd, qtdItens) {
	var idProduto = document.getElementById(checa);
	var qtdProduto = document.getElementById(qtd);
	var remove = 'N';
	if( idProduto.checked == true ) {
		qtdProduto.disabled = false;
		qtdProduto.value = ( qtdProduto.value > 0 ? qtdProduto.value : 1 );
	}
	else {
		qtdProduto.disabled = true;
		qtdProduto.value = 1;
		remove = 'S';
	}

	xajax_addItemCarrinho(idProduto.value, qtdProduto.value, qtdItens, remove);
	return false;
}

// Calcula o valor do produto quando altera a quantidade
function calculavalor(qtd, vu, vt) {
	var vl_unit = document.getElementById(vu).innerHTML
	var vl_total = document.getElementById(vt).innerHTML
	var vl_totalpedido = document.getElementById('totalpedido').innerHTML		
	var total = Number(document.getElementById(qtd).value) * Number(vl_unit.replace(/,/, "."))
	var totalanterior=Number(vl_total.replace(/,/, "."))
	var diferenca=total-totalanterior
	var ttnovo=Number(vl_totalpedido.replace(/,/, "."))+diferenca
	var valor = total.toString();
	var totalnovo= ttnovo.toString();
	if (valor.search(/\./)== -1) {
	   total= valor+",00"
	} else {
    	var divisao=valor.split('.');
	    var reais=divisao[0];
    	var centavos=divisao[1]+"0";
	    var formato_cent=centavos.substring(0,2);
    	total = reais + "," + formato_cent
	}
	if (totalnovo.search(/\./)== -1) {
	   totalnovo= totalnovo+",00"
	} else {
    	var divisao=totalnovo.split('.');
	    var reais=divisao[0];
    	var centavos=divisao[1];
	    var formato_cent=centavos.substring(0,2);
    	totalnovo = reais + "," + formato_cent
	}	
	document.getElementById(vt).innerHTML=total
	document.getElementById('totalpedido').innerHTML=totalnovo	
}

//tos=new Array()
//Mostra o submenu no mouseover
function over(id){
//	if( typeof(tos[id]) != "undefined" ) {
//	clearTimeout( tos[id] );
//	}
	document.getElementById("subMenu_"+id).style.display="block";
}
//Esconde o submenu no mouseout
function out(id){
//	tos[id]=setTimeout('document.getElementById("subMenu_'+id+'").style.display="none"',100);
	document.getElementById("subMenu_"+id).style.display="none";
}