
function fnMenu(codcategoria, categoria, codsubcategoria, subcategoria)	{
	var frm = document.frm;
	var aux = "";

	frm.op.value="busca";
	frm.codcategoria.value=codcategoria;
	frm.categoria.value=categoria;
	frm.codsubcategoria.value=codsubcategoria;
	frm.subcategoria.value=subcategoria;
	frm.navpagina.value=1;

	frm.action = "p_lista.php";
	frm.submit();
}

function fnLink(action,target,op)	{
	var frm = document.frm;
	var aux = "";

	frm.op.value = op;
	frm.action = action;
	frm.target = target;
	frm.submit();
}

function fnBusca()	{
	var frm = document.frmBusca;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.busca_campo.value==""){
		alert("Informe algum valor")
		frm.busca_campo.focus();
		return false;
	}

	frm.action = "p_lista.php";
	frm.submit();
}

function fnCadastraNews()	{
	var frm = document.frmNews;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.news_nome.value==""){
		alert("Informe o Nome")
		frm.news_nome.focus();
		return false;
	}

	if (frm.news_email.value==""){
		alert("Informe o E-mail")
		frm.news_email.focus();
		return false;
	}

	if (!reEmail.test(frm.news_email.value)) {
		alert("E-mail inválido : " + frm.news_email.value)
		frm.news_email.focus();
		return false;
	}

	frm.op.value="news";
	frm.action = "index.php";
	frm.submit();
}

function fnContato() {
	var frm = document.frmContato;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.contato_nome.value==""){
		alert("Informe o Nome")
		frm.contato_nome.focus();
		return false;
	}

	if (frm.contato_telefone.value==""){
		alert("Informe o Telefone")
		frm.contato_telefone.focus();
		return false;
	}

	if (frm.contato_email.value==""){
		alert("Informe o E-mail")
		frm.contato_email.focus();
		return false;
	}

	if (!reEmail.test(frm.contato_email.value)) {
		alert("E-mail inválido : " + frm.contato_email.value)
		frm.contato_email.focus();
		return false;
	}

	frm.op.value = "contato";
	frm.action = "";
	frm.target = "";
	frm.submit();
}

function fnLogin() {
	var frm = document.frmLogin;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.login_email.value==""){
		alert("Informe o E-mail")
		frm.login_email.focus();
		return false;
	}

	if (!reEmail.test(frm.login_email.value)) {
		alert("E-mail inválido : " + frm.login_email.value)
		frm.login_email.focus();
		return false;
	}

	if (frm.login_senha.value==""){
		alert("Informe a Senha")
		frm.login_senha.focus();
		return false;
	}

	frm.op.value = "login";
	frm.action = "";
	frm.target = "";
	frm.submit();
}

function fnSenha() {
	var frm = document.frmSenha;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.login_email.value==""){
		alert("Informe o E-mail")
		frm.login_email.focus();
		return false;
	}

	if (!reEmail.test(frm.login_email.value)) {
		alert("E-mail inválido : " + frm.login_email.value)
		frm.login_email.focus();
		return false;
	}

	frm.op.value = "senha";
	frm.action = "";
	frm.target = "";
	frm.submit();
}

function fnFinalizaCarrinho(){
	var frm = document.frm;
	frm.op.value = "finalizar_compra";
	frm.action = "";
	frm.target = "";
	frm.submit()
}

function fnCarrinho(){
 var frm = document.frmCarrinho;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.cadastro_nome.value==""){
		alert("Informe o Nome")
		frm.cadastro_nome.focus();
		return false;
	}

	if (frm.cadastro_endereco.value==""){
		alert("Informe o Endereço")
		frm.cadastro_endereco.focus();
		return false;
	}
	
	if (frm.cadastro_numero.value==""){
		alert("Informe o Número")
		frm.cadastro_numero.focus();
		return false;
	}
	
	if (frm.cadastro_cidade.value==""){
		alert("Informe a sua Cidade")
		frm.cadastro_cidade.focus();
		return false;
	}
	
	if (frm.cadastro_uf.value==""){
		alert("Informe o seu Estado")
		frm.cadastro_uf.focus();
		return false;
	}	
	
	if (frm.cadastro_uf.value==""){
		alert("Informe o seu Estado")
		frm.cadastro_uf.focus();
		return false;
	}

	if (frm.cadastro_cep.value==""){
		alert("Informe o seu CEP")
		frm.cadastro_cep.focus();
		return false;
	}		
	
	if (frm.cadastro_ddd1.value==""){
		alert("Informe o seu DDD")
		frm.cadastro_ddd1.focus();
		return false;
	}
	
	if (frm.cadastro_telefone.value==""){
		alert("Informe o seu Telefone")
		frm.cadastro_telefone.focus();
		return false;
	}		
	
 /*
 
	if (frm.cadastro_email.value==""){
		alert("Informe o E-mail")
		frm.cadastro_email.focus();
		return false;
	}

	if (!reEmail.test(frm.cadastro_email.value)) {
		alert("E-mail inválido : " + frm.cadastro_email.value)
		frm.cadastro_email.focus();
		return false;
	}	
	
	if (frm.cadastro_senha.value==""){
		alert("Informe a sua Senha")
		frm.cadastro_senha.focus();
		return false;
	}
	
	if (frm.cadastro_senha1.value==""){
		alert("Informe a sua confirmação da Senha")
		frm.cadastro_senha1.focus();
		return false;
	}	
	
	if (frm.cadastro_senha.value!=frm.cadastro_senha1.value){
		alert("A Senha e a Confirmação devem ser a mesma")
		frm.cadastro_senha.focus();
		return false;
	}	
	
 
 
	frm.op.value = "cadastro";
	frm.action = "p_cadastro.php";
	frm.target = "";
 
 */
 
	frm.submit();
}

function fnCadastro() {
	var frm = document.frmCadastro;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.cadastro_nome.value==""){
		alert("Informe o Nome")
		frm.cadastro_nome.focus();
		return false;
	}

	if (frm.cadastro_endereco.value==""){
		alert("Informe o Endereço")
		frm.cadastro_endereco.focus();
		return false;
	}
	
	if (frm.cadastro_numero.value==""){
		alert("Informe o Número")
		frm.cadastro_numero.focus();
		return false;
	}
	
	if (frm.cadastro_cidade.value==""){
		alert("Informe a sua Cidade")
		frm.cadastro_cidade.focus();
		return false;
	}
	
	if (frm.cadastro_uf.value==""){
		alert("Informe o seu Estado")
		frm.cadastro_uf.focus();
		return false;
	}	
	
	if (frm.cadastro_uf.value==""){
		alert("Informe o seu Estado")
		frm.cadastro_uf.focus();
		return false;
	}

	if (frm.cadastro_cep.value==""){
		alert("Informe o seu CEP")
		frm.cadastro_cep.focus();
		return false;
	}		
	
	if (frm.cadastro_ddd1.value==""){
		alert("Informe o seu DDD")
		frm.cadastro_ddd1.focus();
		return false;
	}
	
	if (frm.cadastro_telefone.value==""){
		alert("Informe o seu Telefone")
		frm.cadastro_telefone.focus();
		return false;
	}		
	
	if (frm.cadastro_email.value==""){
		alert("Informe o E-mail")
		frm.cadastro_email.focus();
		return false;
	}

	if (!reEmail.test(frm.cadastro_email.value)) {
		alert("E-mail inválido : " + frm.cadastro_email.value)
		frm.cadastro_email.focus();
		return false;
	}	
	
	if (frm.cadastro_senha.value==""){
		alert("Informe a sua Senha")
		frm.cadastro_senha.focus();
		return false;
	}
	
	if (frm.cadastro_senha1.value==""){
		alert("Informe a sua confirmação da Senha")
		frm.cadastro_senha1.focus();
		return false;
	}	
	
	if (frm.cadastro_senha.value!=frm.cadastro_senha1.value){
		alert("A Senha e a Confirmação devem ser a mesma")
		frm.cadastro_senha.focus();
		return false;
	}	
	
	frm.op.value = "cadastro";
	frm.action = "p_cadastro.php";
	frm.target = "";
	frm.submit();
}

function fnProdutoVer(codposter,codmoldura,tamanho,sugestao) {
	var frm = document.frm;

	frm.op.value="produtover";
	frm.codposter.value=codposter;
	frm.codmoldura.value=codmoldura;
	frm.tamanho.value=tamanho;
	frm.sugestao.value=sugestao;

	frm.action = "p_poster.php";
	frm.submit();
}

function fnProdutoComprar(codposter,codmoldura,tamanho,quantidade,sugestao,valorunitario,valormoldura, valorpeso) {
	var frm = document.frm;

	/*alert(valorpeso);*/
	
	frm.op.value="produtocomprar";
	frm.codposter.value=codposter;
	frm.codmoldura.value=codmoldura;
	frm.tamanho.value=tamanho;
	frm.quantidade.value=quantidade;
	frm.sugestao.value=sugestao;
	frm.valorunitario.value=valorunitario;
	frm.valormoldura.value=valormoldura;
	frm.codposter.value=codposter;
	frm.peso.value=valorpeso;
	frm.action = "p_carrinho.php";
	frm.target = "";
	frm.submit();
}

function fnProdutoExcluir(codvenda,codvendaposter,cod) {
	var frm = document.frm;

	frm.op.value = "produtoexcluir";
	frm.codvenda.value = codvenda;
 frm.codposter.value = cod;
	frm.codvendaposter.value = codvendaposter;
	frm.action = "p_carrinho.php";
	frm.target = "";
	frm.submit();
}

function fnProdutoQuantidade(codvenda,codvendaposter,obj, cod) {
	var frm = document.frm;

	if(obj.value==''){
		obj.value='1';
	}

	frm.op.value = "produtoquantidade";
	frm.codvenda.value = codvenda;
	frm.codvendaposter.value = codvendaposter;
	frm.quantidade.value = obj.value;
 frm.codposter.value = cod;
 
	frm.action = "p_carrinho.php";
	frm.target = "";
	frm.submit();
}

function fnProdutoFundo(cor) {
	var obj = document.getElementById("principal-imagem");

	obj.style.backgroundColor = cor;
}

function fnNavega(navpagina) {
	var frm = document.frm;

	frm.navpagina.value = navpagina;
	frm.action = "";
	frm.submit();
}

function fnCompraFrete() {
	var frm = document.frm;
	var cep=document.getElementById("carrinhocep").value;
    var ser=document.getElementById("_aux_sedex_correio").value; 
	frm.op.value = "frete";
	frm.cep.value = cep;
	frm.sedex_correio.value=ser;
	frm.action = "";
	frm.target = "";
	frm.submit();
}

function fnCompraFinalizar(codvenda,valorsomatorio,valorvenda,valorfrete) {
	var frm = document.frm;

	frm.op.value = "finalizar";
	frm.codvenda.value = codvenda;
	frm.valorsomatorio.value = valorsomatorio;
	frm.valorvenda.value = valorvenda;
	frm.valorfrete.value = valorfrete;
	frm.action = "p_finalizar.php";
	frm.submit();
}

function fnAjustaPagina(){
	var aux;
	var dif_h;
	var pag_h = fnReturnSize("h");
	var div_h = document.getElementById("conteudo-principal").offsetHeight;

	if (div_h>(pag_h-250)){
		dif_h = 0;
	}else{
		dif_h = pag_h - div_h -260;
	}
	aux = (div_h+dif_h) + "px";

	//alert(pag_h);//alert(pag_h);alert(aux);
	document.getElementById("conteudo-principal").style.height = aux;
}

// FUNÇÕES GERAIS

function fnAutoLimpa (obj) {
	obj.value="";
}

function fnReturnSize (type){
	var type = (type)? type : "";

	if (document.all)
	{
			//pegando o Altura tela no IE.
			if (!document.documentElement.clientHeight)
					var height = document.body.clientHeight;                                                
			else
					var height = document.documentElement.clientHeight;             
					
			//pegando a Largura tela no IE.                         
			if (!document.documentElement.clientWidth)
					var width = document.body.clientWidth;                                          
			else
					var width = document.documentElement.clientWidth;                                               
	}
	else
	{
			//pegando a Altura tela no FF.                  
					var height = window.innerHeight;
			//pegando a Largura tela no FF.                 
					var width  = window.innerWidth;                         
	}       

	if (type.toLowerCase()=="w")
	{
			return width;
	}
	else if (type.toLowerCase()=="h")
	{
			return height;
	}
	else
	{
			var arr = new Array(2);
			arr[0] = width;
			arr[1] = height;                        
			return arr;
	}       
}

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];}}
}

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_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];}
}


if(Browser == undefined)
{
    var Browser = {
        isIE: function(){ return (window.ActiveXObject && document.all && navigator.userAgent.toLowerCase().indexOf("msie") > -1  && navigator.userAgent.toLowerCase().indexOf("opera") == -1) ? true : false; }
    };
}

var Flash = function(movie, id, width, height, initParams)
{
    this.html = "";
    
    this.variables = new Array();
    
    this.flashversion = (typeof initParams != "undefined" && typeof initParams.flashversion != "undefined") ? initParams.flashversion : "7,0,0,0";
    
    this.attributes = {
        "classid": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
        "codebase": "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=" + this.flashversion,
        "type": "application/x-shockwave-flash"
    };
    
    this.params = { "pluginurl": "http://www.macromedia.com/go/getflashplayer" };
    
    if(movie)
    {
        this.addAttribute("data", movie);
        this.addParameter("movie", movie);
    }
    
    if(id && id != null && (this.id = id)) 
    {
        this.addAttribute("id", this.id);
        this.addAttribute("name", this.id);
    }
    else
    {
        this.id = null;
    }
    
    if(width) this.addAttribute("width", width);
    if(height) this.addAttribute("height", height);
    
    if(initParams != undefined)
    {
        for(var i in initParams) this.addParameter(i.toString(), initParams[i]);
    }
};
Flash.version = "v1.8";

Flash.prototype.getObject = function()
{
    if(this.id == null) return null;
    try
    {
        if(window.document[this.id])
        {
            return window.document[this.id];
        }
        else
        {
            return document.getElementById(window.document[this.id]);
        }
    }
    catch(e) { return null; }
};

Flash.getObjectByExceptions = function(obj, excep)
{
    var tempObj = {};
    for(var i in obj)
    {
        var EOF = false;
        for(var j=0; j<excep.length; j++) if(excep[j] == i.toString()) { EOF = true; break; };
        if(!EOF) tempObj[i] = obj[i];
    }
    return tempObj;
};

Flash.prototype.addAttribute = function(prop, val){ this.attributes[prop] = val; };
Flash.prototype.addParameter = function(prop, val){ this.params[prop] = val; };
Flash.prototype.addVariable = function(prop, val){ this.variables.push([prop, val]); };

Flash.prototype.getFlashVars = function()
{
    for(var i=0, tempString = new Array(); i<this.variables.length; i++) tempString.push(this.variables[i].join("="));
    return tempString.join("&");
};
Flash.prototype.toString = function()
{
    this.params.flashVars = this.getFlashVars();
    if(Browser.isIE())
    {
        //IE
        this.html = "<ob" + "ject";
        var attr = Flash.getObjectByExceptions(this.attributes, ["type", "data"]);
        for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
        this.html += "> ";
        var params = Flash.getObjectByExceptions(this.params, ["pluginurl", "extend"]);
        for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
        this.html += " </obj" + "ect>";
    }
    else
    {
        //non-IE
        this.html = "<!--[if !IE]> <--> <obj" + "ect";
        var attr = Flash.getObjectByExceptions(this.attributes, ["classid", "codebase"]);
        for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
        this.html += "> ";
        var params = Flash.getObjectByExceptions(this.params, ["extend"]);
        for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
        this.html += " </obj" + "ect> <!--> <![endif]-->";
    }
    return this.html;
};
Flash.prototype.write = Flash.prototype.writeIn = function(w)
{
    if(typeof w == "string" && (w = document.getElementById(w)));
    if( w != null ) { w.innerHTML = this.toString(); }
    else if( w == undefined ) { document.write( this.toString() ); }
        else { return false; }
};

//automatization functions...
Flash.correctAll = function()
{
    if(!/msie/.test(navigator.userAgent.toLowerCase()) || !document.getElementsByTagName) return false;
    for (var i = 0, objects = document.getElementsByTagName("OBJECT"); i < objects.length;
        (objects[i].outerHTML ? (objects[i].outerHTML = objects[i].outerHTML, objects[i].style.visibility = "visible") : null), i++);
};
Flash.automatic = function(r)
{
    if(r && window.attachEvent)
    {    
        for (var i = 0, objects = document.getElementsByTagName("OBJECT"); i < objects.length; (objects[i].style.visibility = "hidden"), i++);
        window.attachEvent("onload", Flash.correctAll);
        window.attachEvent("onunload", function(){ window.detachEvent("onload", Flash.correctAll); });
    }
    else
    {
        Flash.correctAll();
    }
};

//AJAX
function createXMLHTTP() {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			alert(ajax);
		}	
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
		return ajax;
	}

	var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP","Microsoft.XMLHTTP"];

	for (var i=0; i < arrSignatures.length; i++) {
		try {
	  	var oRequest = new ActiveXObject(arrSignatures[i]);
  	  return oRequest;
		} 
		catch (oError) {
		}
	}
	throw new Error("MSXML is not installed on your system.");
} 

/** Scripts TALTO Informática **/
//
// Especifica mascara para o campo. Deve ser usada no evento onkeyup.
// NOVA FUNÇÃO DE MÁSCARA PARA O CAMPO: INCORPORADA PARA CARACTERES DO TIPO HEXADECIMAL
//
// Exemplo:
// Mask( this, "(99) 9999-9999", event ); /* Mascara para número de telefone */
// Mask( this, "AAA-9999", event ); /* Mascara para placa de carro */
// Mask( this, "#####-#####-#####-#####-#####", event ); /* Mascara para número serial */
// Mask( this, "%%.%%.%%.%%.%%.%%", event ); /* Mascara para tipo de dado addr */
//
// Onde:
// A = Somente letras [a-zA-Z]
// 9 = Somente números [0-9]
// # = Caracteres alfanumericos em geral
// % = Caracteres hexadecimais \w
//
function Mask(Field, Mask, e) {
 var Value = Field.value.replace( /\W/gi, "" ),i;
 for (i = 0; i < Value.length; i ++) {
  if (!/[#A9%]/.test(Mask.charAt(i))) {
   Value = Value.splice(i, 1, Mask.charAt(i) + Value.charAt(i));
  } else if ((Mask.charAt(i) == "A" && !/[a-z]/i.test(Value.charAt(i))) ||
             (Mask.charAt(i) == "9" && !/[0-9]/.test(Value.charAt(i))) ||
             (Mask.charAt(i) == "%" && !/[0-9a-fA-F]/.test(Value.charAt(i))) ||
             (Mask.charAt(i) == "#" && !/\w/.test(Value.charAt(i)))) {
   Value = Value.splice(i, 1);
  }
 }
 Field.value = Value.substr(0, Mask.length);
}

function CPFCNPJ(Field, e){
 var l = $(Field).value;
 if ((l.length > 7) && (l.length < 14)){
  Mask(Field, '999.999.999-99', e);
 }
 if (l.length > 14){
  Mask(Field, '99.999.999/9999-99', e);
 } 

}

/*

1.2 A Função 'splice'

    Está função tem o mesmo objetivo da função splice para arrays, porém esta é para manipular caracteres de uma string.
    
    1.2.1 Parametros
    
          - i      : índice a ser removido
          - offset : comprimento a ser removido a partir do índice
          - str    : string a ser colocada no lugar
          
    1.2.2 Retorno
    
          A função retorna uma string com o resultado a partir dos parametros passados a ela.

*/
String.prototype.splice = function (i, offset, str) {
 if (i < 0)
  i = this.length + i;

 return this.substr(0, i) + (str || "") + this.substr(i + offset, this.length)
}
 function checkForm(f){
 msg = '';
 for(i=0; i<f.elements.length; i++){
  a = f.elements[i];
  err = $(a).readAttribute('notnull');
  if(err){   
   if (($(a).value == '') || (($(a).readAttribute('fk') == 'fk') && ($(a).value == '0'))){
    msg = $(a).readAttribute('desc');
    if (msg==null){
     msg = $(a).id;
    }
    msg = 'O campo "' + msg + '" é obrigatório.'; 
    alert(msg);
    $(a).focus();
    i = f.elements.length + 1; // sai do for 
   }
  }
 }
 return (msg == '');
}
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);
  }
}

//Formata número tipo moeda usando o evento onKeyDown
function ffMoney(campo,tammax,ev,decimal) {
var tecla = ev.keyCode;
var vr = campo.value.replace(/\D/g,"");
var tam = vr.length;
var dec=decimal;
if (tammax == vr.length)return;
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 ) ;}
}

}


