// JavaScript Document
function pagamento() {
	if(document.getElementById().value=='')	{
		alert('ALERTA: Por favor escolha uma forma de pagamento!');
		return false;
	}
	
}
//Soma valor do elemento
function MaisUm(elemento) {
	var valoratual = document.getElementById(elemento).value;
	document.getElementById(elemento).value = ++valoratual;
}
function MenosUm(elemento) {
	var valoratual = document.getElementById(elemento).value;
	if(valoratual > 1) {
		document.getElementById(elemento).value = (valoratual-1);
	} else {
		document.getElementById(elemento).value = 1;
	}
}

//Ver elemento escondido
function see(i){
  i = document.getElementById(i);
  if(!i){
	return false;
  }else{
	if(i.style.display=='' || i.style.display=='none'){
		i.style.display = 'block';
 	}else{
		i.style.display = 'none';
  	}
  }
}

//Sumir elemento
function sumir(i){
  i = document.getElementById(i);
  if(!i){
	return false;
  }else{
	if(i.style.display == 'block'){
		i.style.display = 'none';
 	}
  }
}

//Aparecer elemento
function aparecer(i){
  i = document.getElementById(i);
  if(!i){
	return false;
  }else{
	if(i.style.display == 'none'){
		i.style.display = 'block';
 	}
  }
}

function Limpar(valor, validos) {
		// retira caracteres invalidos da string
		var result = "";
		var aux;
		for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
		result += aux;
		}
		}
		return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function Formata(campo,tammax,teclapres,decimal) {
			var tecla = teclapres.keyCode;
			vr = Limpar(campo.value,"0123456789");
			tam = vr.length;
			dec=decimal
			
			if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
			
			if (tecla == 8 )
			{ tam = tam - 1 ; }
			
			if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
			{
			
			if ( tam <= dec )
			{ campo.value = vr ; }
			
			if ( (tam > dec) && (tam <= 5) ){
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
			if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
			}
			if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
			if ( (tam >= 12) && (tam <= 14) ){
			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 - dec, tam ) ; }
			if ( (tam >= 15) && (tam <= 17) ){
			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 ) ;}
			} 

}



function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function format_cep(){
			if(document.getElementById('cep').value.length == 5 ){
							document.getElementById('cep').value += "-";
			}
		
}

function format_cpf(){
			if(document.getElementById('cpf').value.length == 3 || document.getElementById('cpf').value.length == 7){
							document.getElementById('cpf').value += ".";
			}else{
					if(document.getElementById('cpf').value.length == 11){
						document.getElementById('cpf').value += "-";
						}	
				}
			
}

function format_cep(campo){
			if(document.getElementById(campo).value.length == 5 ){
							document.getElementById(campo).value += "-";
			}
		
}

//COLOCANDO OS TIPOS DE NAVEGADORES EM VARIAVEIS
	var navegador = navigator.appName.toLowerCase();
	var mozilla = navegador.indexOf("netscap")+1;

	function numerico(event){
		//VERIFICANDO QUAL NAVEGADO ESTA SENDO USADO
		var tecla = mozilla ? event.which : event.keyCode;
		if(!(tecla >= 48 && tecla <= 57 || tecla == 0 || tecla == 8 || tecla == 40 || tecla == 41)){
			return false;
			}
	}

//Pop-up
function popup(url,janela,w,h,scrol){
	window.open(url,janela,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrol + ',resizable=yes,width=' + w + ',height=' + h + ''); return false;
}