//******************************************************
//funcao para o menu
function openMenu(obj) {
	var menu = document.getElementById('menuSecundario');
	var itens = menu.getElementsByTagName('div');
	var flg = 0;
	if(obj.parentNode.parentNode.className == 'fechado') flg = 1;
	for(var i=0,len=itens.length;i<len;i++) if(itens[i].className == 'aberto') itens[i].className = 'fechado';
	if(flg) obj.parentNode.parentNode.className = 'aberto';
}

//******************************************************
//funcao para aguardar o carregamento do site
function carregaSite() {
 if (document.getElementById) {  // DOM3 = IE5, NS6
 	document.getElementById('aguarde').style.visibility = 'hidden';
 }
 else {
	 if (document.layers) {  // Netscape 4
	 	document.aguarde.visibility = 'hidden';
 	}
 	else {  // IE 4
       document.all.aguarde.style.visibility = 'hidden';
    }
 }
}


////////////////////////////////////////
function ocultaCampo(selObj){	
	if(document.frmFormulario.sltEstadoCivil.options[selObj.selectedIndex].value == 1 || document.frmFormulario.sltEstadoCivil.options[selObj.selectedIndex].value == '#'){
		//document.frmFormulario.txtConjuge.disabled = true;
		//document.frmFormulario.txtCnpj.maxLength = "14"
		//document.getElementById("spnCnpj").style.display = 'inline';
		document.getElementById("spnEstado").style.display = 'none';
		//document.getElementById("spnCpf").style.display = 'none';
		//document.getElementById("spnCpf").style.display = 'inline';
		//document.frmFormulario.txtEndereco.style.display = '';
	}else{
		document.getElementById("spnEstado").style.display = 'inline';
	}
	
}

//Mascara de valores

function FormataValores(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

//Campo Obrigatorio
//campoObrigatorio(this,'nome')
function campoObrigatorio(field,nomeCampo)
{
	with (field)
	{
		campo = document.getElementById(nomeCampo);
		if (value==null||value=="")
		{
			campo.style.background = "#f2f2f2";
			return false
		}
		else
		{
			campo.style.background = "#ffffff";
			return true
		}
	}
}

//centralizar janela
function centralizarjanela(larg,altu){
	if (navigator.appVersion >= "4") {
		if (screen.width >= "700") {
			var haxis=(window.screen.width-larg)/2;
			var vaxis=(window.screen.height-altu)/2;
			window.moveTo( haxis, vaxis );
		}
	}
}

//Mascara de valores

function FormataValores(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

//mascara de data
function FormataData(Campo,teclapres) 
{
	var tecla = teclapres.keyCode;
	vr = document.frmCadVenda[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 )
	{
		if ( tam > 2 && tam < 5 )
			document.frmCadVenda[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.frmCadVenda[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}

//Instrução de chamada no <input>:
//onkeypress="FormataData('Campo',event,formulario)"

//onkeydown="FormataCampo(this,event,'##/##/####')"
function FormataCampo(Campo,teclapres,mascara){ 
    strtext = Campo.value 
    tamtext = strtext.length 
    tammask = mascara.length 
    arrmask = new Array(tammask)     
    for (var i = 0 ; i < tammask; i++){ 
        arrmask[i] = mascara.slice(i,i+1) 
    } 
    //alert (teclapres.keyCode) 
    //começando o trabalho sujo 
    if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){ 
        if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){ 
            Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)         
        } 
        else{ 
            Detona_Event(Campo,strtext) 
        } 
    } 
    else{
        if ((arrmask[tamtext] == "A"))    { 
            charupper = event.valueOf() 
            Detona_Event(Campo,strtext) 
            masktext = strtext + charupper 
            Campo.value = masktext 
        } 
    } 
} 
function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){ 
    if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){ 
        separador = arrpos 
        masktext = strtext + separador 
        Campo.value = masktext 
    } 
} 
function Detona_Event(Campo,strtext){ 
    event.returnValue = false 
    if (strtext != "") { 
        Campo.value = strtext 
    } 
}

//*******************************************************************************
function Abre(width, height, nome) {
var top; var left;
top = ( (screen.height/2) - (height/2) )
left = ( (screen.width/2) - (width/2) )
window.open('',nome,'width='+width+',height='+height+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}

////////////////////////////////////////
function Calendario(strOnde, strDestino, lngInicio, lngFim){
	if(document.all){
		var retorno = showModalDialog(strOnde + 'calendario.asp?txtInicio=' + lngInicio + '&txtFim=' + lngFim + '&txtDestino=' + strDestino, 'calendario', 'resizable: no; help: no; status: no; scroll: no;');
		if(retorno != null){
			window.document.getElementById(strDestino).value = retorno;
		}
		return false;
	}else{
		alert("Não foi possível abrir o calendário\nFavor informar a data no seguinte formato:\n01/12/2004.");
		var obj = window.document.getElementById(strDestino);
		obj.readOnly = false;
		obj.focus();
		obj.select();
		return false;
	}
}

////////////////////////////////////////
function link1()
{
if (document.radiolink.clique)
location='insc_cadastro.asp?id=1'            
}

////////////////////////////////////////
function FSNumeros(strPermissao){
    	var	KeyCode = event.keyCode;
	var strPermitido = " KeyCode != 46 && KeyCode != 37 && KeyCode != 39 && KeyCode != 8 && KeyCode != 9 ";
	if (strPermissao != ""){
		if (strPermissao.indexOf(",") != -1){
			strPermissao = strPermissao.split(",");
			for(i=0; i < strPermissao.length; i++){
				strPermitido += " && KeyCode!= " + parseInt(strPermissao[i]);
			}
		}else{
			strPermitido += " && KeyCode!= " + parseInt(strPermissao);
		}
		strPermitido = eval(strPermitido);
		if ((KeyCode < 48 || KeyCode > 57) && (KeyCode < 96 || KeyCode > 105) && (strPermitido)){
			event.cancelBubble;
			event.returnValue= false;
			return false;
		}
	}else{
		if ((KeyCode < 48 || KeyCode > 57) && (KeyCode < 96 || KeyCode > 105) && (eval(strPermitido))){
			event.cancelBubble;
			event.returnValue= false;
			return false;
		}
	}
	//Valores para AlfaNumerico, Numerico
	//Virgulas 188, 190
	//Pontos 190,194
}

//////////////////Dreamweaver//////////////////////
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(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 Focar(formulario, posicao){
	var obj = eval("document." + formulario);
	obj.elements[posicao].focus();
}

function EmailValidation(obj){
	var objValidation = new RegExp("^([\\w\\.\\-]{1,50})[@]([\\w\\.\\-]{1,125})([\\.]\\w{2,4})$");
	if(! objValidation.test(obj.value)){
		return false;
	}else{
		return true;
	}
}

////////////////////////////////////////#F0F2F9

function EnviarCadastro(){
	var objForm = document.frmCadastro;
	var i;
	var blnErro = false;
	for(i=0;i < objForm.length; i++){
		if(objForm.elements[i].value == "" && objForm.elements[i].disabled == false && (objForm.elements[i].name != "comercial" && objForm.elements[i].name != "celular" && objForm.elements[i].name != "email")){
			alert("Campo com preenchimento obrigatório.");
			objForm.elements[i].style.background="#F0F2F9";
			objForm.elements[i].focus();
			blnErro = true;

			break;
		}else{
			if(objForm.email.value != "" &&  ! EmailValidation(objForm.email)){
				alert("O e-mail informado é inválido.");
				objForm.email.style.background="#F0F2F9";
				objForm.email.style.background="#F0F2F9";
				objForm.email.focus();
				blnErro = true;
				break;
			}else{
				objForm.elements[i].style.background="#FFFFFF";
			}
		}					
	}
	if(! blnErro){
		objForm.submit();
	}
}

////////////////////////////////////////

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
/*function MM_openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  visualizar = window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
  //visualizar = window.open(theURL,winName,features);
  visualizar.focus();
  if (!visualizar.opener) visualizar.opener = self;
}*/

////////////////////////////////////////
function FaleConosco(){
	var objForm = document.frmFale;
	var i;
	var blnErro = false;
	for(i=0;i < objForm.length; i++){
		if(objForm.elements[i].value == "" && objForm.elements[i].disabled == false && (objForm.elements[i].name != "Destinatario" && objForm.elements[i].name != "Email")){
			alert("Campo com preenchimento obrigatório.");
			objForm.elements[i].style.background="#F0F2F9";
			objForm.elements[i].focus();
			blnErro = true;
			break;
		}
	}
	if(! blnErro){
		objForm.submit();
	}
}

function FaleConoscoIndex(){
	var objForm = document.frmFaleIndex;
	var i;
	var blnErro = false;
	for(i=0;i < objForm.length; i++){
		if(objForm.elements[i].value == "" && objForm.elements[i].disabled == false && (objForm.elements[i].name != "Destinatario" && objForm.elements[i].name != "Email")){
			alert("Campo com preenchimento obrigatório.");
			objForm.elements[i].style.background="#F0F2F9";
			objForm.elements[i].focus();
			blnErro = true;
			break;
		}					
	}
	if(! blnErro){
		objForm.submit();
	}
}

function FaleConoscoWeb(){
	var objForm = document.frmFaleWeb;
	var i;
	var blnErro = false;
	for(i=0;i < objForm.length; i++){
		if(objForm.elements[i].value == "" && objForm.elements[i].disabled == false && (objForm.elements[i].name != "Destinatario" && objForm.elements[i].name != "Email")){
			alert("Campo com preenchimento obrigatório.");
			objForm.elements[i].style.background="#F0F2F9";
			objForm.elements[i].focus();
			blnErro = true;
			break;
		}	
	}
	if(! blnErro){
		objForm.submit();
	}
}
