var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;

var toolTipSTYLE="";

addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

MaskInput = function(f, m){
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        addEvent(f, i, mask);
};

function abrir(url) {
	window.open(url, 'S','resizable=yes,scrollbars=yes');
}

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];}}
}

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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function confirma_exclusao(area,codigo)
{
  if(confirm("Deseja realmente excluir?"))
  {
   window.location = area+'_excluir.asp?codigo='+codigo;
  }
  else
  {
   alert('Exclusão cancelada');
  }
}

function ajustar_cpf(Campo, teclapres)
{
	var retorno = apenas_numero(teclapres);

	if (retorno) {
		if(window.event) {
			var tecla = teclapres.keyCode;
		}
		else {
			var tecla = teclapres.which;
		}
	
		var vr = new String(Campo.value);
		vr = vr.replace(".", "");
		vr = vr.replace(".", "");
		vr = vr.replace("-", "");
		
		tam = vr.length + 1;
		
		if (tecla != 9 && tecla != 8) {
			if (tam > 3 && tam < 7) {
				Campo.value = vr.substr(0,3) + '.' + vr.substr(3, tam);
			}
			if (tam >= 7 && tam < 10) {
				Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
			}
			if (tam >= 10 && tam < 15) {
				Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-7);
			}
		}
	}
	
	return retorno;
}

function ajustar_data(Campo, teclapres)
{
	var retorno = apenas_numero(teclapres);

	if (retorno) {
		if(window.event) {
			var tecla = teclapres.keyCode;
		}
		else {
			var tecla = teclapres.which;
		}
	
		var vr = new String(Campo.value);
		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, 2) + '/' + vr.substr(2, tam);
			}
			if (tam >= 5 && tam <= 10) {
				Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,tam-4);
			}
		}
	}
	
	return retorno;
}

function ampliar_foto(foto) {
	abrir('popup_fotos_produto.asp?foto='+foto);
}

function apaga_valor_campo(destino) {
	destino.value = '';
}

function aparece_outros(obj) {

	var valor_s = obj.value.split('#');
	var ic_qual = valor_s[0];

	if(parseInt(ic_qual)==1) {
		document.getElementById('id_outros').style.display='';
		obj.form.pesquisa_qual.focus();
		ic_pesquisa_qual = 1;
	}
	else {
		document.getElementById('id_outros').style.display='none';
		obj.form.pesquisa_qual.value='';
		ic_pesquisa_qual = 0;
	}
}

function apenasNumero(input) {
	if ((event.keyCode<46)||(event.keyCode>57)||(event.keyCode==47)) {
		event.returnValue = false;
	}
}

function atualiza_frete(f) {
    
    var obj_frete_encomenda_normal  = document.getElementById('txt_vl_frete_encomenda_normal');
    var obj_frete_sedex             = document.getElementById('txt_vl_frete_sedex');

    var obj_vl_total_produtos       = document.getElementById('vl_total_produtos');
    var obj_vl_total_frete          = document.getElementById('vl_total_frete');
    var obj_vl_total_acumulado      = document.getElementById('vl_total_acumulado');
    
    var qtd_total                   = retorna_qtd_total(f);
    var vl_total                    = retorna_vl_total(f);
    
    if(parseInt(qtd_total)==0) {
        var vl_frete                    = 0;
        var str_frete_encomenda_normal  = "";
        var str_frete_sedex             = "";
    }
    else {
        var opcao_frete = retorna_valor_radio(f.frete);
        if(opcao_frete) {
            if(opcao_frete=='SEDEX') {
                var vl_frete            = qtd_total*20;        
            }
            else {
                var vl_frete            = qtd_total*10;
            }        
        }
        else {
                var vl_frete            = 0;
        }
        var str_frete_encomenda_normal  = "Seu frete é de R$ "+ qtd_total*10 +",00";
        var str_frete_sedex             = "Seu frete é de R$ "+ qtd_total*20 +",00";
    }
    
    var ic_zerou_frete              = false;
    
    for(var i=0; i<f.length; i++) {
        campo_separado = f[i].name.split('#');
        //pega apenas os campos "qtd"
        if(campo_separado.length>1) {
            var cod = campo_separado[1];
            var qtd = f[i].value;
            
            switch (parseInt(cod)) {
	            case 1: //valor ouro
                    if(!ic_zerou_frete) {
                        if(qtd>=3) {
                            str_frete_encomenda_normal  = 'Seu frete é gratuito';
                            str_frete_sedex             = 'Seu frete é gratuito';
                            ic_zerou_frete              = true;
                            vl_frete                    = 0;
                        }
	                }
		            break;
	            case 2: //valor prata
                    if(!ic_zerou_frete) {
                        if(qtd>=6) {
                            str_frete_encomenda_normal  = 'Seu frete é gratuito';
                            str_frete_sedex             = 'Seu frete é gratuito';
                            ic_zerou_frete              = true;
                            vl_frete                    = 0;
                        }
	                }
		            break;
	            case 3: //valor spray
                    if(!ic_zerou_frete) {
                        if(qtd>=6) {
                            str_frete_encomenda_normal  = 'Seu frete é gratuito';
                            str_frete_sedex             = 'Seu frete é gratuito';
                            ic_zerou_frete              = true;
                            vl_frete                    = 0;
                        }
	                }
		            break;
	            case 4: //valor design
                    if(!ic_zerou_frete) {
                        if(qtd>=2) {
                            str_frete_encomenda_normal  = 'Seu frete é gratuito';
                            str_frete_sedex             = 'Seu frete é gratuito';
                            ic_zerou_frete              = true;
                            vl_frete                    = 0;
                        }
	                }
		            break;
	            case 5: //valor trio
                    if(!ic_zerou_frete) {
                        if(qtd>=1) {
                            str_frete_encomenda_normal  = 'Seu frete é gratuito';
                            str_frete_sedex             = 'Seu frete é gratuito';
                            ic_zerou_frete              = true;
                            vl_frete                    = 0;
                        }
	                }
		            break;
	            default:
		            break;
            }

            var vl_total_acumulado = parseInt(vl_total) + parseInt(vl_frete);

            obj_frete_encomenda_normal.innerHTML = str_frete_encomenda_normal;
            obj_frete_sedex.innerHTML            = str_frete_sedex;

            obj_vl_total_produtos.innerHTML      = 'R$ '+ vl_total + ',00';
            obj_vl_total_frete.innerHTML         = 'R$ '+ vl_frete + ',00';
            obj_vl_total_acumulado.innerHTML     = 'R$ '+ vl_total_acumulado + ',00';

        }        
    }
}

function atualiza_preco(obj, codigo) {
    var f           = document.form_sua_compra;
    var qtd         = obj.value;
    var campo_preco = eval('f.preco_unt_'+codigo);
    var campo_total = eval('f.total_'+codigo);

    if( isNaN(qtd) ) {
        alert('Preencha com valores numéricos!');
        campo_total.value = '0';
        obj.select();
        return false;
    }
    if( qtd<0 ) {
        alert('Preencha com valores positivos');
        campo_total.value = '0';
        obj.select();
        return false;
    }
    var preco_atual = campo_preco.value;
    preco_atual = preco_atual.replace(",", ".");
    campo_total.value = qtd * preco_atual;
    
    atualiza_frete(obj.form)
}

function apenas_numero(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	if ((key == 0) || (key == 8)) {
		return true
	}
	else {
		reg = /\d/;
		return reg.test(keychar);
	}  
}

function carrega() {
	document.getElementById("carrega_mensagem").style.display = 'none';
	document.getElementById("corpo").style.display = 'inline';
}

function carrega_define_posicao() {
  var x,y;
  if (self.innerHeight)
  {// all except Explorer
    x = self.innerWidth;
    y = self.innerHeight;
  }
  else 
  if (document.documentElement && document.documentElement.clientHeight)
  {// Explorer 6 Strict Mode
   x = document.documentElement.clientWidth;
   y = document.documentElement.clientHeight;
  }
  else
  if (document.body)
  {// other Explorers
   x = document.body.clientWidth;
   y = document.body.clientHeight;
  }
	var el=document.getElementById('carrega_mensagem');
	if(null!=el)
	{
		var top = (y/2) - 50;
		var left = (x/2) - 200;
		if( left<=0 ) left = 10;

		el.style.left = left + "px"
		el.style.top = top + "px";
		el.style.zIndex = 2;
	}
}

function centraliza_janela(width, height) {
	var width_janela	= eval(width);
	var height_janela	= eval(height);
	var width_tela 		= self.screen.width;
	var height_tela 	= self.screen.height;
	var pos_esquerda 	= (width_tela - width_janela)/2;
	var pos_direita 	= (height_tela - height_janela)/2;

	self.moveTo(pos_esquerda,pos_direita); //centraliza
	self.resizeTo(width_janela, height_janela); //redimensiona
}

function checou(campo) {
	if(campo) {
		if(campo.length) {
			for (var i=0; i<campo.length; i++) {
				if( campo[i].checked ) return true;
			}
			return false;
		}
		else {
			if(campo.checked) return true;
			return false;
		}
	}
	else {
		return false;
	}
}

function conta_checado(campo) {
	var acum = 0;
	if(campo) {
		if(campo.length) {
			for (var i=0; i<campo.length; i++) {
				if( campo[i].checked ) acum++;
			}
		}
		else {
			if(campo.checked) acum++;
		}
	}
	return acum;
}

function excluir(form, campo) {
	var campo= eval('document.'+form+'.'+campo);
	var form = eval('document.'+form);
	
	if(checou(campo)) {
		if(confirm("Deseja realmente excluir?")) {
			form.submit();
		}
	}
	else {
		alert('Selecione primeiro o que deseja excluir');
	}
}

function formata_data(input) {
	if ((event.keyCode<48)||(event.keyCode>57)) {
		event.returnValue = false;
	}
	else {
		if(input.value.length==2||input.value.length==5) {
			input.value = input.value + "/";
		}
	}
}

function formata_telefone(obj){
   if (obj.value.length==4){
	   obj.value = obj.value + "-";
   }
}

function formata_cpf(obj) {
	if ((event.keyCode<48)||(event.keyCode>57)){
		event.returnValue = false;
		}
	else{
		if((obj.value.length==3)||(obj.value.length==7)){
			obj.value = obj.value + ".";
		}
		else{
			if(obj.value.length==11){
				obj.value = obj.value + "-";
			}
		}
	}
}

function le_ementa(origem, destino) {
	var form    = origem.form;
	var destino = eval("document."+form.name+"."+destino);
	destino.value = ementas[origem.value];
}

function limpa_se_igual(obj, msg) {
	if(obj.value==msg) {
		obj.value='';
	}
}

function mostra_esconde(obj) {
    var obj = document.getElementById(obj);
    if(obj) {
        if(obj.style.display=='') {
            obj.style.display = 'none';
        }
        else {
            obj.style.display = '';
        }
    }
    return false;
}

function move(index,to) {
	var list = document.form_ordenar.list;
	var total = list.options.length-1;
	if (index == -1) return false;
	if (to == +1 && index == total) return false;
	if (to == -1 && index == 0) return false;
	var items = new Array;
	var values = new Array;
	for (i = total; i >= 0; i--) {
		items[i] = list.options[i].text;
		values[i] = list.options[i].value;
	}
	for (i = total; i >= 0; i--) {
		if (index == i) {
			list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
			list.options[i] = new Option(items[i + to], values[i]);
			i--;
		}
		else {
			list.options[i] = new Option(items[i], values[i]);
		}
	}
	list.focus();
}


function move_submit() {
	var list = document.form_ordenar.list;
	var theList = "?";
	// start with a "?" to make it look like a real query-string
	for (i = 0; i <= list.options.length-1; i++) { 
		cod = list.options[i].text.split(',');
		theList += "tL" + "=" + parseInt(cod[0]);
		// a "&" only BETWEEN the items, so not at the end
		if (i != list.options.length-1) theList += "&";
	}
	//alert(theList);
	//alert(theList.length);
	location.href = document.form_ordenar.action + theList;
}

function muda_dica(valor, obj) {
    var obj = document.getElementById(obj);
    var str = '';
    if(obj) {
        
        switch (valor) {
	        case "O": //valor ouro
                str += '<img src="imagens/indicacao-ouro.gif" /><br />';
                str += '<div style="padding-top:5px; padding-left:10px;">';
                str += '  <a href="ouro.asp">saiba mais</a> | <a href="faca_sua_compra.asp">compre</a>';
                str += '</div>';
		        break;
	        case "P": //valor prata
                str += '<img src="imagens/indicacao-prata.gif" /><br />';
                str += '<div style="padding-top:5px; padding-left:10px;">';
                str += '  <a href="prata.asp">saiba mais</a> | <a href="faca_sua_compra.asp">compre</a>';
                str += '</div>';
		        break;
	        case "D": //valor design
                str += '<img src="imagens/indicacao-design.gif" /><br />';
                str += '<div style="padding-top:5px; padding-left:10px;">';
                str += '  <a href="#" onclick="javascript: return false;">saiba mais</a> | <a href="faca_sua_compra.asp">compre</a>';
                str += '</div>';
		        break;
	        case "T": //valor trio
                str += '<img src="imagens/indicacao-trio.gif" /><br />';
                str += '<div style="padding-top:5px; padding-left:10px;">';
                str += '  <a href="#" onclick="javascript: return false;">saiba mais</a> | <a href="faca_sua_compra.asp">compre</a>';
                str += '</div>';
		        break;
	        case "S": //valor spray
                str += '<img src="imagens/indicacao-spray.gif" /><br />';
                str += '<div style="padding-top:5px; padding-left:10px;">';
                str += '  <a href="ouro.asp">saiba mais</a> | <a href="faca_sua_compra.asp">compre</a>';
                str += '</div>';
		        break;
	        default:
                str += '';
        }
        obj.innerHTML = str;
    }
    else {
        return false;
    }
}

function muda_estilo(destino, estilo) {
	var obj = document.getElementById(destino);
	obj.className = estilo;
}
	
function MudaFilho(formulario, Pai, Filho, Vetor)	{
	var f=formulario.elements;
	var N=Vetor.length-1;
	var indice=f[Pai].options[f[Pai].selectedIndex].value;
	f[Filho].length=1;
	f[Filho].options[0].text='Selecione';
	f[Filho].options[0].value='';
	if (indice!=0) {  
	  for (var i = 0; i<=N; i++) {
	    if (Vetor[i][0]==indice){
				f[Filho].length=f[Filho].length+1;
				f[Filho].options[f[Filho].length-1] = new Option(Vetor[i][2],Vetor[i][1]);
	    }
	  }
	}
}

function popup_detalhes(codigo) {
	abrir('popup_foto_produto.asp?codigo='+codigo);
}

function retorna_qtd_total(f) {
    var retorno = 0;
    for(var i=0; i<f.length; i++) {
        var campo_separado = f[i].name.split('#');
        //pega apenas os campos "qtd"
        if(campo_separado.length>1) {
            var qtd = f[i].value;
            if( (isNaN(qtd))||(qtd=='') ) {
                qtd = 0;
            }
            retorno += parseInt(qtd);
        }
    }
    return retorno;
}

function retorna_vl_total(f) {
    var retorno = 0;
    for(var i=0; i<f.length; i++) {
        var campo_separado = f[i].name.split('#');
        //pega apenas os campos "qtd"
        if(campo_separado.length>1) {
            var valor = eval( 'f.total_'+campo_separado[1]+'.value' ) ;
            if(!isNaN(valor)) {
                retorno += parseInt(valor);
            }
        }
    }
    return retorno;
}

function retorna_valor_radio(campo) {
  if(campo) {
	  if(campo.length) {
		for (var i=0; i<campo.length; i++) {
		  if( campo[i].checked ) {
			return campo[i].value;
		  }
		}
		return 0;
	  }
	  else {
		if(campo.checked) {
		  return campo.value;
		}
		return 0;
	  }
  }
  else {
  	return 0;
  }
}

function retorna_valor_select(campo) {
	var retorno = "";
	if(campo) {
		if(campo.length) {
			for (var i=0; i<campo.length; i++) {
				if( campo[i].selected ) retorno = campo[i].value;
			}
		}
		else {
			if(campo.selected) retorno = campo.checked;
		}
	}
	else {
		retorno = "";
	}
	return retorno;
}


function muda_tipo_empresa(tipo) {
    var var_tr_cliente      = document.getElementById('tr_cliente');
    var var_tr_fornecedor   = document.getElementById('tr_fornecedor');
    var var_tr_tarso        = document.getElementById('tr_tarso');
    var var_f               = document.form_usuario;
    var var_valor_temp      = "";

    //se não passou o tipo, pega o tipo checado    
    if(!tipo) {
        tipo = retorna_valor_radio(var_f.tipo_empresa2);
    }
    
    if(tipo=='T') {
            var_tr_cliente.style.display      = 'none';
            var_tr_fornecedor.style.display   = 'none';
            var_tr_tarso.style.display        = '';
    }
    else {
        if(tipo=='F') {
            var_tr_cliente.style.display      = 'none';
            var_tr_fornecedor.style.display   = '';
            var_tr_tarso.style.display        = 'none';
        }
        else {
            var_tr_cliente.style.display      = '';
            var_tr_fornecedor.style.display   = 'none';
            var_tr_tarso.style.display        = 'none';
        }
    }
}

function suja_se_vazio(obj, msg) {
	if(obj.value=='') {
		obj.value=msg;
	}
}

function verifica_form_arquivo() {
	var f = document.form_usuario;
	if(f.nome.value==0) {
		alert('Por favor, informe o nome da peça!');
		f.nome.focus();
		return false;
	}
	if(f.versao.value==0) {
		alert('Por favor, informe a versão!');
		f.versao.focus();
		return false;
	}
	if(!checou(f.tipo_empresa)) {
		alert('Por favor, escolha o tipo da empresa!');
		return false;
	}
	
	var tipo = retorna_valor_radio(f.tipo_empresa);
	
	if(tipo=='C') {
	    if(f.cd_cliente.value==0) {
		    alert('Por favor, escolha o cliente!');
		    f.cd_cliente.focus();
		    return false;
	    }
	}
	else {
	    if(tipo=='F') {
	        if(f.cd_fornecedor.value==0) {
		        alert('Por favor, escolha o fornecedor!');
		        f.cd_fornecedor.focus();
		        return false;
	        }
	    }
	}
	if(f.arquivo.value==0) {
		alert('Por favor, informe o arquivo!');
		f.arquivo.focus();
		return false;
	}
	
	return ProgressBar();
}

function verifica_form_contato() {
    var f = document.form_contato;
    if(f.nome.value==0) {
	    alert('Preencha o nome');
	    f.nome.focus();
	    return false;
    }
    if(f.email.value==0) {
	    alert('Preencha o email');
	    f.email.focus();
	    return false;
    }
    if(f.assunto.value==0) {
	    alert('Escolha o assunto');
	    f.assunto.focus();
	    return false;
    }
    if(f.mensagem.value==0) {
	    alert('Preencha a mensagem');
	    f.mensagem.focus();
	    return false;
    }
    return true;
}

function verifica_form_sua_compra() {
    var f = document.form_sua_compra;
    if(!checou(f.frete)) {
	    alert('Escolha o frete');
	    return false;
    }
	if (f.nome.value=="") {
		alert("Preencha o nome !");
		f.nome.focus();
		return false;
	}
	var conteudo_nome = f.nome.value;
	var i;
	var bandeira_nome_1=0;
	var bandeira_nome_2=0;
	for (i = 0; i < conteudo_nome.length; i++) {  
		var c = conteudo_nome.charAt(i);
		if (c == 1||c == 2||c == 3||c == 4||c == 5||c == 6||c == 7||c == 8||c == 9) {bandeira_nome_1=1;}
		if (c == " "){bandeira_nome_2=1;}
	}
	if (bandeira_nome_1==1||bandeira_nome_2==0) {
		alert("O campo nome não está correto !\n\nLembre-se de digitar seu nome completo !");
		f.nome.focus();
		return false;
	}
	/*if(f.cpf.value.length<11) {
	    alert("Preencha o CPF !");
	    f.cpf.focus();
	    return false;
	}*/
	if (f.email.value=="") {
		alert("Preencha o email !");
		f.email.focus();
		return false;
	}
	if ( (f.email.value.indexOf ('@',0) == -1) || (f.email.value.indexOf ('.',0) == -1) ) {
		alert("Seu e-mail está incorreto\n\nPor favor digite corretamente !");
		f.email.focus();
		return false;
	}
	if ((f.dt_nascimento.value.length<10)||(f.dt_nascimento.value=='dd/mm/aaaa')) {
		alert("Preencha a data de nascimento no formato dd/mm/aaaa !");
		f.dt_nascimento.focus();
		return false;
	}
	if ( (f.ddd_residencial.value=="")&&(f.ddd_comercial.value=="") ) {
		alert("É necessário preencher o campo telefone fixo !");
		return false;
	}
	if (f.ddd_residencial.value!="") {
	    if (f.telefone_residencial.value=="") {
		    alert("Informe o telefone FIXO, instalado no endereço de entrega!");
		    f.telefone_residencial.focus();
		    return false;
	    }	
	    if ( (f.telefone_residencial.value.substring(0,1)=="8") || (f.telefone_residencial.value.substring(0,1)=="9") || (f.telefone_residencial.value.substring(0,1)=="7") ) {
		    alert("Por medida de segurança, o telefone deve ser fixo no local de entrega para futura conferência de endereço!");
		    f.telefone_residencial.select();
		    return false;
	    }
	}
	if (f.ddd_comercial.value!="") {
	    if (f.telefone_comercial.value=="") {
		    alert("Informe o telefone FIXO, instalado no endereço de entrega!");
		    f.telefone_comercial.focus();
		    return false;
	    }	
	    if ( (f.telefone_comercial.value.substring(0,1)=="8") || (f.telefone_comercial.value.substring(0,1)=="9") || (f.telefone_comercial.value.substring(0,1)=="7") ) {
		    alert("Por medida de segurança, o telefone deve ser fixo no local de entrega para futura conferência de endereço!");
		    f.telefone_comercial.select();
		    return false;
	    }
	}

	if (f.cep_1.value.length<5) {
		alert("É necessário preencher o campo CEP !");
		f.cep_1.focus();
		return false;
	}
	if (f.cep_2.value.length<3) {
		alert("É necessário preencher o campo CEP !");
		f.cep_2.focus();
		return false;
	}
	if (f.rua.value==""){
		alert("É necessário preencher o campo rua/avenida/praça !");
		f.rua.focus();
		return false;
	}
	if (f.numero.value==""){
		alert("É necessário preencher o campo numero!");
		f.numero.focus();
		return false;
	}
	if (f.bairro.value==""){
		alert("É necessário preencher o campo bairro !");
		f.bairro.focus();
		return false;
	}
	if (f.cidade.value==""){
		alert("É necessário preencher o campo cidade !");
		f.cidade.focus();
		return false;
	}
	if (f.uf.value==""){
		alert("É necessário preencher o campo uf !");
		f.uf.focus();
		return false;
	}
	if (f.pesquisa.value==0){
		alert("É necessário informar como você conheceu a 3 Praias !");
		return false;
	}
	if(parseInt(ic_pesquisa_qual)==1) {
	    if (f.pesquisa_qual.value==""){
		    alert("É necessário informar como você conheceu a 3 Praias !");
		    f.pesquisa_qual.focus();
		    return false;
	    }
	}
    return true;
}

function verifica_form_tipo() {
	var f = document.form_tipo;
	if(f.tipo_nome.value==0) {
		alert('Por favor, informe o nome!');
		f.tipo_nome.focus();
		return false;
	}
	if(f.tipo_abreviacao.value==0) {
		alert('Por favor, informe a abreviação!');
		f.tipo_abreviacao.focus();
		return false;
	}
	return true;
}

function verifica_form_cidade() {
	var f = document.form_cidade;
	if(f.estado_codigo.value==0) {
		alert('Por favor, selecione o estado!');
		f.estado_codigo.focus();
		return false;
	}
	if(f.cidade_nome.value==0) {
		alert('Por favor, informe o nome!');
		f.cidade_nome.focus();
		return false;
	}
	if(f.cidade_abreviacao.value==0) {
		alert('Por favor, informe a abreviação!');
		f.cidade_abreviacao.focus();
		return false;
	}
	return true;
}

function verifica_form_empresa() {
	var f = document.form_empresa;
	if(f.nome.value==0) {
		alert('Por favor, informe o nome da empresa!');
		f.nome.focus();
		return false;
	}
	if(f.tipo.value==0) {
		alert('Por favor, informe o tipo da empresa!');
		f.tipo.focus();
		return false;
	}
/*	if(f.ddd_telefone.value==0) {
		alert('Por favor, informe o telefone!');
		f.ddd_telefone.focus();
		return false;
	}
	if(f.telefone.value==0) {
		alert('Por favor, informe o telefone!');
		f.telefone.focus();
		return false;
	}*/
	return true;
}

function verifica_form_area_campo(url, tira_validacao) {
	var f = document.form_area_campo;
	if(!tira_validacao) {
		if(f.area_campo_nome.value==0) {
			alert('Por favor, informe a Área / Campo!');
			f.area_campo_nome.focus();
		}
		else {
			f.action = url;
			f.submit();
		}
	}
	else {
		f.action = url;
		f.submit();
	}
}

function verifica_form_usuario() {
	var f = document.form_usuario;	
	if(f.nome.value==0) {
		alert('Por favor, informe o nome!');
		f.nome.focus();
		return false;
	}
	if(f.email.value==0) {
		alert('Por favor, informe o email!');
		f.email.focus();
		return false;
	}
	if(!checou(f.tipo_empresa)) {
		alert('Por favor, escolha o tipo da empresa!');
		return false;
	}
	
	var tipo = retorna_valor_radio(f.tipo_empresa);
	
	if(tipo=='C') {
	    if(f.cd_cliente.value==0) {
		    alert('Por favor, escolha o cliente!');
		    f.cd_cliente.focus();
		    return false;
	    }
	}
	else {
	    if(tipo=='F') {
	        if(f.cd_fornecedor.value==0) {
		        alert('Por favor, escolha o fornecedor!');
		        f.cd_fornecedor.focus();
		        return false;
	        }
	    }
	}
	
	if(f.login.value==0) {
		alert('Por favor, informe o login!');
		f.login.focus();
		return false;
	}
	if(f.senha.value==0) {
		alert('Por favor, informe a senha!');
		f.senha.focus();
		return false;
	}
	return true;
}

function verifica_form_orgao(url, tira_validacao) {
	var f = document.form_orgao;
	if(!tira_validacao) {
		if(f.orgao_nome.value==0) {
			alert('Por favor, informe o Órgão!');
			f.orgao_nome.focus();
		}
		else {
			f.action = url;
			f.submit();
		}
	}
	else {
		f.action = url;
		f.submit();
	}
}

function verifica_form_tema(url, tira_validacao) {
	var f = document.form_tema;
	if(!tira_validacao) {
		if(f.tema_nome.value==0) {
			alert('Por favor, informe o Tema!');
			f.tema_nome.focus();
		}
		else {
			f.action = url;
			f.submit();
		}
	}
	else {
		f.action = url;
		f.submit();
	}
}

function verifica_upload_sansouth(lang) {
	var f = document.form_upload_sansouth;
	if(lang=='en') {
		var msg = 'Please, select the file!';
	}
	else {
		var msg = 'Por favor, selecione o arquivo!';
	}
	if(f.arquivo.value==0) {
		alert(msg);
		f.arquivo.focus();
		return false;
	}
	return true;
}

	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
	found = true;
	else
	index++;
	return found;
	}
	function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
	}
	return true;
	}

function verifica_motoboy(obj) {
	var f = eval('document.'+obj.form.name);
	var iframe = document.getElementById('iframe_verifica_motoboy');
	verificou_motoboy = false;
	
	if( (f.cep1.value.length<5)||(f.cep2.value.length<3) ) {
		alert('Preencha corretamente o CEP!');
		f.cep1.focus();
		obj.checked = false;
	}
	else {
		iframe.src = 'iframe_verifica_motoboy.asp?cep1='+f.cep1.value+'&cep2='+f.cep2.value;		
	}
	
}

/*
#############################################
##Início das Funções referentes ao ToolTip ##
#############################################
*/

function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}
function toolTip(msg, fg, bg)
{
  if(toolTip.arguments.length < 1) // hide
  {
    if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
  }
  else // show
  {
    if(!fg) fg = "#204373";
    if(!bg) bg = "#D7DBE7";
    var content =
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '"><td>' +
    '<table border="0" cellspacing="0" cellpadding="15" bgcolor="' + bg + 
    '"><td align="justify" style="font-family:Verdana; font-size:9px;"><font color="' + fg +
    '">' + msg +
    '&nbsp\;</font></td></table></td></table>';
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
  }
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }
  toolTipSTYLE.left = x + offsetX;
  toolTipSTYLE.top = y + offsetY;
  return true;
}

/*
#############################################
### Fim das Funções referentes ao ToolTip ###
#############################################
*/


/*
#############################################
##Início das Funções referentes ao Autotab ##
#############################################
*/

	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
	found = true;
	else
	index++;
	return found;
	}
	function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
	}
	return true;
	}

/*
#############################################
### Fim das Funções referentes ao Autotab ###
#############################################
*/
