// JavaScript Document

//INICIA ACCORDION
window.addEvent('domready', function() 
{
	var myAccordion = new Accordion($$('.toggler'), $$('.element'), {
	display: 0,
	alwaysHide: true,
	duration: 400
	});
})

function Trim(str)
{
	return str.replace(/^\s+|\s+$/g,"");
}

function janela(url, titulo , w, h)
{
	window.open(url, titulo , 'width='+w+',height='+h+',top='+(window.screen.height/2-h/2)+',left='+(window.screen.width/2-w/2)+', scrollbars=yes, toolbar=no, menubar=no, status=no, location=no, resizable=no');
}

//limita um textarea com maxlength
function limiteTexto(objcampo,tamanho,nomeinner) {
	
	var result = true; 
	
	if (objcampo.value.length >= tamanho)
		return false;
		
	if ( nomeinner != '' ) 
	{
		
		if (objcampo.value.length < tamanho)
			document.getElementById( nomeinner ).innerHTML = '';
			document.getElementById( nomeinner ).innerHTML = tamanho - objcampo.value.length;
			
	}
   
}

function isEmail(text){
   var 	arroba = "@",
       	ponto = ".",
	   	posponto = 0,
	   	posarroba = 0;
	
	 if (text =="") return false;
	
	 for (var indice = 0; indice < text.length; indice++){
	 	if (text.charAt(indice) == arroba) {
	 		posarroba = indice;
	      	break;
		 }
	 }
	
	for (var indice = posarroba; indice < text.length; indice++){
		if (text.charAt(indice) == ponto) {
			posponto = indice;
	     	break;
		}
	}
	if (posponto == 0 || posarroba == 0) return false;
	if (posponto == (posarroba + 1)) return false;
	if ((posponto + 1) == text.length) return false;
	return true;
}

function isDate(objeto)
{	
	VarArray=objeto.value.split("/");
	TamanhoArray=VarArray.length;
	if (TamanhoArray!=3)	
	{
		alert("A data deve estar no formato dd/mm/aaaa.");
		objeto.focus();
		return false;
	}
	if ((VarArray[0].length!=2)||(VarArray[1].length!=2)||(VarArray[2].length!=4))
	{
		alert("A data deve estar no formato dd/mm/aaaa.");
		objeto.focus();
		return false; 
	}

	msg = "A data é inválida.";
	if (isNaN(VarArray[0]) || isNaN(VarArray[1]) || isNaN(VarArray[2]))
	{
		alert(msg);
		objeto.focus();
		return false; 
	}
	
	if (VarArray[2] % 4 == 0) {bisexto=true;} else {bisexto=false;}	
	if (VarArray[1] > 12) {alert(msg);objeto.focus();return false;}	
	if (VarArray[1]==2) {
		if (bisexto==true) {
			if ( VarArray[0] > 29 ) {alert(msg);objeto.focus();return false;}}
		else {
			if ( VarArray[0] > 28 ) {alert(msg);objeto.focus();return false;}}
	}
	else if (VarArray[1]==4||VarArray[1]==6||VarArray[1]==9||VarArray[1]==11)	{
		if ( VarArray[0] > 30 ) {alert(msg);objeto.focus();return false;}} 
	else {
		if ( VarArray[0] > 31 ) {alert(msg);objeto.focus();return false;}}

	return true;
}

//FUNÇÃO Q PERMITE APENAS A ENTRADA DE DOUBLES
function teclaFloat(e, campo)
{
	var variavel = campo.value;
	
	var key_code = e.keyCode  ? e.keyCode  :
				   e.charCode ? e.charCode :
				   e.which    ? e.which    : void 0;
				   
	// Habilita números de 0 a 9
	if ( (key_code >= 48)  &&  (key_code <= 57) || (key_code == 8) )
	{
		return true
	}
	else
	{
		if( key_code == 46 ) 
		{
			return true;
		}
		else
		{
			return false;	
		}
	}
}

//FUNÇÃO Q PERMITE APENAS A ENTRADA DE INTEIROS
function teclaNumber(e, campo)
{
	var key_code = e.keyCode  ? e.keyCode  :
				   e.charCode ? e.charCode :
				   e.which    ? e.which    : void 0;
				   
	// Habilita números de 0 a 9
	if ( (key_code >= 48)  &&  (key_code <= 57) || (key_code == 8) )
	{
		return true
	}

	return false;
		
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = e.keyCode  ? e.keyCode  :
					e.charCode ? e.charCode :
					e.which    ? e.which    : void 0;

    if (whichCode == 13 || whichCode == 8) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function retornaValorBancoRS( strValor )
{
	var texto = strValor;
	
	texto = texto.toString().replace( ".", "" );
	texto = texto.toString().replace( ".", "" );
	texto = texto.toString().replace( ".", "" );
	texto = texto.toString().replace( ".", "" );
	texto = texto.toString().replace( ".", "" );
	texto = texto.toString().replace( ".", "" );
	texto = texto.toString().replace( ".", "" );
	texto = texto.toString().replace( ".", "" );
	texto = texto.toString().replace( ",", "." );
	
	return Number( texto );
}

function retornaValorBancoUS( strValor )
{
	var texto = strValor;
	
	texto = texto.toString().replace( ",", "" );
	texto = texto.toString().replace( ",", "" );
	texto = texto.toString().replace( ",", "" );	
	texto = texto.toString().replace( ",", "" );
	
	return Number( texto );
}

function formataValorRS( dValor )
{ 
    var vValor       = dValor.split(".");
	var str          = vValor[0];
    var nLenValor    = str.length; 
	var strValResult = "";
	
	if ( vValor[1] == null || vValor[1] == "" )
		vValor[1] = "";
		
    if ( nLenValor > 3 )
	{ 
        var t = 0;
		var v_Valor = new Array( nLenValor );
		
        while ( t + 1 <= nLenValor )
		{ 
			str = vValor[0];
			
            v_Valor[t] = str.substr( t , 1 ); 
            t++;     
        }    
		
		t--;
		
		var v     = 0;
		var cont  = 0;
		var t_aux = t;
		
        while ( v <= t_aux )
		{ 
            if ( cont == 3 )
			{ 
                strValResult = "." + ( v_Valor[t] == null ? "" : v_Valor[t] )  + strValResult; 
                cont = 0; 
            } 
			else 
                strValResult = ( v_Valor[t] == null ? "" : v_Valor[t] ) + strValResult; 
   
            cont++; 
            t--; 
            v++; 
        }  
        strValResult = strValResult + "," + vValor[1]; 
    } 
	else 
	{ 
        strValResult = vValor[0] + "," + vValor[1]; 
    } 
	
	if ( vValor[1] == "" )
		strValResult = strValResult + "00";
	else
	{
		str = vValor[1];
		
		if ( str.length == 1 )
			strValResult = strValResult + "0"; 
	
	}
	
    if ( strValResult.substr( 0, 1) == "," )
        strValResult = "0" + strValResult; 
     
    return strValResult;     
} 

function formataValorUS( dValor )
{ 
    var vValor       = dValor.split(".");
	var str          = vValor[0];
    var nLenValor    = str.length; 
	var strValResult = "";
	
	if ( vValor[1] == null || vValor[1] == "" )
		vValor[1] = "";
		
    if ( nLenValor > 3 )
	{ 
        var t = 0;
		var v_Valor = new Array( nLenValor );
		
        while ( t + 1 <= nLenValor )
		{ 
			str = vValor[0];
			
            v_Valor[t] = str.substr( t , 1 ); 
            t++;     
        }     
		
		t--;
		
		var v     = 0;
		var cont  = 0;
		var t_aux = t;
		
        while ( v <= t_aux )
		{ 
            if ( cont == 3 )
			{ 
                strValResult = ( v_Valor[t] == null ? "" : v_Valor[t] + "," )  + strValResult; 
                cont = 0; 
            } 
			else 
                strValResult = ( v_Valor[t] == null ? "" : v_Valor[t] ) + strValResult; 
   
            cont++; 
            t--; 
            v++; 
        }  
        strValResult = strValResult + "." + vValor[1]; 
    } 
	else 
	{ 
        strValResult = vValor[0] + "." + vValor[1]; 
    } 
	
	if ( vValor[1] == "" )
		strValResult = strValResult + "00";
	else
	{
		str = vValor[1];
		
		if ( str.length == 1 )
			strValResult = strValResult + "0"; 
	
	}
	
    if ( strValResult.substr( 0, 1) == "." )
        strValResult = "0" + strValResult; 
     
    return strValResult;     
} 

function validaCNPJ( strCNPJ ) 
{
	if ( strCNPJ.length < 14 )
		return false;
		
	if ( Trim( strCNPJ ) == "00000000000000" )
		return false;


	strCNPJ = strCNPJ.replace(".","");
	strCNPJ = strCNPJ.replace(".","");
	strCNPJ = strCNPJ.replace("-","");
	strCNPJ = strCNPJ.replace("/","");
	
	var nonNumbers = /\D/;
	
	if ( strCNPJ.length > 14 )
		return false;
	
	if ( nonNumbers.test(strCNPJ) ) 
		return false;
	
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	
	for (i=0; i<12; i++)
	{
		a[i] = strCNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	
	if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	
	b = 0;
	
	for (y=0; y<13; y++) 
	{
		b += (a[y] * c[y]); 
	}
	
	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	
	if ( (strCNPJ.charAt(12) != a[12]) || (strCNPJ.charAt(13) != a[13]) )
	{
		return false;
	}

	return true;
}

function abrePagHome( strUF ) 
{		
	document.location.href = "index.php?UF=" + strUF;
}	

function abrePag( strUF ) 
{		
	document.location.href = "?UF=" + strUF;
}

function zeraTpVal( ) 
{		
	document.getElementById("valor").value = "0,00";
}

//AJAX FORM SITE***********************************************************************
//***********************************************************************
//***********************************************************************
//***********************************************************************
//***********************************************************************
//NEWSLETTER
function enviaNews( metodo, modo )
{

	//aqui eu pego o valor do campo text    
	var nome  = document.getElementById('frmFormCad').nomeNews.value;
	var email = document.getElementById('frmFormCad').emailNews.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	if( Trim( nome ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "NewsLetter :: &Eacute; necess&aacute;rio preencher o Nome.";
		return false;
	}
	
	if( Trim( email ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = "NewsLetter :: &Eacute; necess&aacute;rio preencher o E-mail.";
		return false;
	}
	else
	{
		if( !isEmail( Trim( email ) ) )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML = "NewsLetter :: E-mail n&atilde;o &eacute; v&aacute;lido.";
			return false;
		}
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";	
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncEnviaNews.php?submit=1&nome=" + nome + "&email=" + email, metodo, modo );
    
	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;
	
	//LIMPA OS CAMPOS
	document.getElementById('frmFormCad').nomeNews.value = "";
	document.getElementById('frmFormCad').emailNews.value = "";
}

//INDICACAO
function enviaIndicacao( metodo, modo )
{

	//aqui eu pego o valor do campo text    
	var nome  = document.getElementById('frmEnviaIndic').nome.value;
	var email = document.getElementById('frmEnviaIndic').email.value;
	
	var emailindic1 = document.getElementById('frmEnviaIndic').emailindic1.value;	
	var emailindic2 = document.getElementById('frmEnviaIndic').emailindic2.value;
	var emailindic3 = document.getElementById('frmEnviaIndic').emailindic3.value;
	var emailindic4 = document.getElementById('frmEnviaIndic').emailindic4.value;
	var emailindic5 = document.getElementById('frmEnviaIndic').emailindic5.value;
	
	var codigo  = document.getElementById('frmEnviaIndic1').codigo.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	if( Trim( nome ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Indica&ccedil;&atilde;o :: &Eacute; necess&aacute;rio preencher o Seu Nome.";
		return false;
	}
	
	if( Trim( email ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = "Indica&ccedil;&atilde;o :: &Eacute; necess&aacute;rio preencher o Seu E-mail.";
		return false;
	}
	else
	{
		if( !isEmail( Trim( email ) ) )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML = "Indica&ccedil;&atilde;o :: Seu E-mail n&atilde;o &eacute; v&aacute;lido.";
			return false;
		}
	}
	
	//********  EMAILS DE INDICACAOES
	
	if( Trim( emailindic1 ) == "" && Trim( emailindic2 ) == "" && Trim( emailindic3 ) == "" && Trim( emailindic4 ) == "" && Trim( emailindic5 ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = "Indica&ccedil;&atilde;o :: &Eacute; necess&aacute;rio preencher pelo menos 1 (um) E-mail para Indica&ccedil;&atilde;o.";
		return false;
	}
	
	if( Trim( emailindic1 ) != "" )
	{
		if( !isEmail( Trim( emailindic1 ) ) )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML = "Indica&ccedil;&atilde;o :: Indica&ccedil;&atilde;o E-mail 1 n&atilde;o &eacute; v&aacute;lido.";
			return false;
		}
	}
	
	if( Trim( emailindic2 ) != "" )
	{
		if( !isEmail( Trim( emailindic2 ) ) )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML = "Indica&ccedil;&atilde;o :: Indica&ccedil;&atilde;o E-mail 2 n&atilde;o &eacute; v&aacute;lido.";
			return false;
		}
	}	
	
	if( Trim( emailindic3 ) != "" )
	{
		if( !isEmail( Trim( emailindic3 ) ) )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML = "Indica&ccedil;&atilde;o :: Indica&ccedil;&atilde;o E-mail 3 n&atilde;o &eacute; v&aacute;lido.";
			return false;
		}
	}
	
	if( Trim( emailindic4 ) != "" )
	{
		if( !isEmail( Trim( emailindic4 ) ) )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML = "Indica&ccedil;&atilde;o :: Indica&ccedil;&atilde;o E-mail 4 n&atilde;o &eacute; v&aacute;lido.";
			return false;
		}
	}
	
	if( Trim( emailindic5 ) != "" )
	{
		if( !isEmail( Trim( emailindic5 ) ) )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML = "Indica&ccedil;&atilde;o :: Indica&ccedil;&atilde;o E-mail 5 n&atilde;o &eacute; v&aacute;lido.";
			return false;
		}
	}	
	

	if( Trim( codigo ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Indica&ccedil;&atilde;o :: &Eacute; necess&aacute;rio digitar o c&oacute;digo de confirma&ccedil;&atilde;o.";
		return false;
	}	
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";	
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncEnviaIndicacao.php?submit=1&nome=" + nome + "&email=" + email + "&emailindic1=" + 
							    emailindic1 + "&emailindic2=" + emailindic2 + "&emailindic3=" + emailindic3 + "&emailindic4=" + 
								emailindic4 + "&emailindic5=" + emailindic5 + "&code=" + codigo, metodo, modo );
	
	if( Trim( envia ) == "" )
	{
		location='enviaIndicacao.php?strNomeRem=' + nome + '&strEmail=' + email + '&bIndicOk=1';
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;	
	}
}

//FALE CONOSCO
function enviaFale( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var nome       = document.getElementById('frmFormFale1').nome.value;
	var email      = document.getElementById('frmFormFale1').email.value;
	var uf         = document.getElementById('frmFormFale1').uf.value;	
	var ntpassunto = document.getElementById('frmFormFale1').tpassunto.value;
	
	var obj          = document.getElementById('frmFormFale1').tpassunto;
	var strtpassunto = obj.options[obj.selectedIndex].text;
	
	var assunto    = document.getElementById('frmFormFale1').assunto.value;
	var message    = document.getElementById('frmFormFale2').message.value;	
	var codigo     = document.getElementById('frmFormFale3').codigo.value;

	var strErro = "";
	var strCampos = "";
	
	document.getElementById("midErro").innerHTML = "";
	
	//NOME COMPLETO
	if( Trim( nome ) == "" )
	{
		strErro =  "Fale Conosco :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";		 
	}
	else
	{
		strCampos = "&nome=" + Trim( nome );
	}
		
	//EMAIL
	if( Trim( email ) == "" )
	{
		strErro =  "Fale Conosco :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}
	else
	{
		if( !isEmail( Trim( email ) ) )
		{
			strErro = "Fale Conosco :: E-mail n&atilde;o &eacute; v&aacute;lido.";
		}
		else
		{
			strCampos += "&email=" + Trim( email );
		}
	}	

	//UF
	if( Trim( uf ) == "-" || Trim( uf ) == "" )
	{
		strErro =  "Fale Conosco :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&uf=" + Trim( uf );
	}
	
	//ASSUNTO
	if( Trim( assunto ) == "" )
	{
		strErro =  "Fale Conosco :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&assunto=" + Trim( assunto );
	}	
	
	//DESCRICAO
	if( Trim( message ) == "" )
	{
		strErro =  "Fale Conosco :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&desc=" + Trim( message );
	}
	
	//TIPO DO ASSUNTO
	strCampos += "&ntpassunto=" + Trim( ntpassunto );
	
	//DESCRICAO TIPO DO ASSUNTO
	strCampos += "&strtpassunto=" + Trim( strtpassunto );	
	
	//TIPO ENVIO
	strCampos += "&tpenvio=FALE";		

	if( Trim( strErro ) == "" )
	{
		if( Trim( codigo ) == ""  )
		{
			strErro =  "Fale Conosco :: &Eacute; necess&aacute;rio digitar o c&oacute;digo de confirma&ccedil;&atilde;o.";
		}
		else
		{
			strCampos += "&code=" + Trim( codigo );
		}
	}
	
	if( Trim( strErro ) != "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;
		return false;	
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncEnviaEmail.php?submit=1" + strCampos, metodo, modo );

	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;

	//LIMPA OS CAMPOS
	document.getElementById('frmFormFale1').nome.value = "";
	document.getElementById('frmFormFale1').email.value = "";
	document.getElementById('frmFormFale1').assunto.value = "";
	document.getElementById('frmFormFale2').message.value = "";
	document.getElementById('frmFormFale3').codigo.value = "";
}

//CADASTRO DE EMPRESAS
function enviaCadEmpr( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var nomecomp   = document.getElementById('frmFormCadEmpr1').nomecomp.value;
	var nomeresum  = document.getElementById('frmFormCadEmpr1').nomeresum.value;
	var contato    = document.getElementById('frmFormCadEmpr1').contato.value;
	var cnpj       = document.getElementById('frmFormCadEmpr1').cnpj.value;
	var categ      = document.getElementById('frmFormCadEmpr1').categ.value;
	var ddd        = document.getElementById('frmFormCadEmpr1').ddd.value;
	var tel1       = document.getElementById('frmFormCadEmpr1').tel1.value;
	var tel2       = document.getElementById('frmFormCadEmpr1').tel2.value;
	var tel3       = document.getElementById('frmFormCadEmpr1').tel3.value;
	var fax        = document.getElementById('frmFormCadEmpr1').fax.value;
	var telgratis  = document.getElementById('frmFormCadEmpr1').telgratis.value;
	var endereco   = document.getElementById('frmFormCadEmpr1').endereco.value;
	var bairro     = document.getElementById('frmFormCadEmpr1').bairro.value;
	var cidade     = document.getElementById('frmFormCadEmpr1').cidade.value;
	var uf         = document.getElementById('frmFormCadEmpr1').uf.value;
	var cep        = document.getElementById('frmFormCadEmpr1').cep.value;
	var email      = document.getElementById('frmFormCadEmpr1').email.value;
	var url        = document.getElementById('frmFormCadEmpr1').url.value;
	var indic      = document.getElementById('frmFormCadEmpr1').indicacao.value;
	var obs        = document.getElementById('frmFormCadEmpr2').obs.value;
	var login      = document.getElementById('frmFormCadEmpr3').login.value;
	var senha      = document.getElementById('frmFormCadEmpr3').senha.value;
	var resenha    = document.getElementById('frmFormCadEmpr3').resenha.value;
	var cktermo    = document.getElementById('frmFormCadEmpr5').cktermo.value;
	
	var strErro = "";
	var strCampos = "";
	
	document.getElementById("midErro").innerHTML = "";
	
	//NOME COMPLETO
	if( Trim( nomecomp ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";		
	}
	else
	{
		strCampos = "&nomecomp=" + Trim( nomecomp );
	}
	
	//NOME RESUMIDO
	if( Trim( nomeresum ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&nomeresum=" + Trim( nomeresum );
	}

	//CONTATO
	if( Trim( contato ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&contato=" + Trim( contato );
	}	
	
	//CNPJ
	if( Trim( cnpj ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		if( !validaCNPJ( Trim( cnpj ) ) )
		{
			strErro =  "Cadastro :: CNPJ da empresa inv&aacute;lido. <BR>";
		}
		else
		{
			strCampos += "&cnpj=" + Trim( cnpj );
		}
	}
	
	//TIPO DE ASSESSORIA
	strCampos += "&categ=" + Trim( categ );	
	
	//DDD
	if( Trim( ddd ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&ddd=" + Trim( ddd );
	}
	
	//TEL1
	if( Trim( tel1 ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&tel1=" + Trim( tel1 );
	}
	
	//TEL2
	strCampos += "&tel2=" + Trim( tel2 );
	
	//TEL3
	strCampos += "&tel3=" + Trim( tel3 );
	
	//FAX
	strCampos += "&fax=" + Trim( fax );	
	
	//0800
	strCampos += "&telgratis=" + Trim( telgratis );		
	
	//ENDERECO
	if( Trim( endereco ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&endereco=" + Trim( endereco );
	}
	
	//BAIRRO
	if( Trim( bairro ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&bairro=" + Trim( bairro );
	}
	
	//CIDADE
	if( Trim( cidade ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&cidade=" + Trim( cidade );
	}	

	//UF
	if( Trim( uf ) == "-" || Trim( uf ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&uf=" + Trim( uf );
	}

	//CEP
	if( Trim( cep ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&cep=" + Trim( cep );
	}
	
	//EMAIL
	if( Trim( email ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}
	else
	{
		if( !isEmail( Trim( email ) ) )
		{
			strErro = "Cadastro :: E-mail n&atilde;o &eacute; v&aacute;lido. <BR>";
		}
		else
		{
			strCampos += "&email=" + Trim( email );
		}
	}
	
	//URL
	strCampos += "&url=" + Trim( url );	
	
	//INDICACAO
	strCampos += "&indic=" + Trim( indic );		
	
	//OBS
	strCampos += "&obs=" + Trim( obs );	
	
	if( Trim( strErro ) == "" )
	{

		//LOGIN
		if( Trim( login ) == "" )
		{
			strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
		}	
		else
		{
			strCampos += "&login=" + Trim( login );
		}
		
		if( Trim( login ).length < 6 )
		{
			strErro =  "Cadastro :: M&iacute;nimo de 6 caracteres para o campo Login !";
		}
		
		//SENHA
		if( Trim( senha ) == "" )
		{
			strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
		}	
		else
		{
			strCampos += "&senha=" + Trim( senha );
		}
		
		if( Trim( senha ).length < 6 )
		{
			strErro =  "Cadastro :: M&iacute;nimo de 6 caracteres para o campo Senha !";
		}		
		
		//RE SENHA
		if( Trim( resenha ) == "" )
		{
			strErro =  "Cadastro :: Re-digite a senha.";
		}	
		else
		{
			if( resenha != senha )
			{
				strErro =  "Cadastro :: Erro ao re-digitar a senha.";
			}
		}	
		
		var cktermo    = document.getElementById('frmFormCadEmpr5').cktermo.checked;	
		
		if( !cktermo )
		{
			strErro =  "Cadastro :: &Eacute; necess&aacute;rio ler e confirmar o Termo de Uso.";
		}
		
	}
	
	if( Trim( strErro ) != "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;
		
		location='#top';
		
		return false;	
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncCadEmpresa.php?submit=1" + strCampos, metodo, modo );
    
	//SE O RETORNO FOR VAZIO SIGNIFICA QUE FOI TUDO OK , CASO CONTRÁRIO INFORMA O QUE HÁ NO RETORNO.
	if( Trim( envia ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = "Cadastro :: Empresa cadastrada com sucesso. <BR> Enviamos um e-mail para confirma&ccedil;&atilde;o.";
		
		//LIMPA OS CAMPOS
		document.getElementById('frmFormCadEmpr1').nomecomp.value = "";
		document.getElementById('frmFormCadEmpr1').nomeresum.value = "";
		document.getElementById('frmFormCadEmpr1').contato.value = "";
		document.getElementById('frmFormCadEmpr1').cnpj.value = "";
		document.getElementById('frmFormCadEmpr1').ddd.value = "";
		document.getElementById('frmFormCadEmpr1').tel1.value = "";
		document.getElementById('frmFormCadEmpr1').tel2.value = "";
		document.getElementById('frmFormCadEmpr1').tel3.value = "";
		document.getElementById('frmFormCadEmpr1').fax.value = "";
		document.getElementById('frmFormCadEmpr1').telgratis.value = "";
		document.getElementById('frmFormCadEmpr1').endereco.value = "";
		document.getElementById('frmFormCadEmpr1').bairro.value = "";
		document.getElementById('frmFormCadEmpr1').cidade.value = "";
		document.getElementById('frmFormCadEmpr1').cep.value = "";
		document.getElementById('frmFormCadEmpr1').email.value = "";
		document.getElementById('frmFormCadEmpr1').url.value = "";
		document.getElementById('frmFormCadEmpr2').obs.value = "";
		document.getElementById('frmFormCadEmpr3').login.value = "";
		document.getElementById('frmFormCadEmpr3').senha.value = "";
		document.getElementById('frmFormCadEmpr3').resenha.value = "";
		
		alert('Empresa cadastrada com sucesso.\nPara darmos continuidade, confirme o cadastro no e-mail cadastrado.');
		
		location='#top';
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
		
		location='#top';
	}
}

//CADASTRO DE FILIAIS
function enviaCadFilial( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var contato    = document.getElementById('frmnewfilial').contato.value;
	var cnpj       = document.getElementById('frmnewfilial').cnpj.value;
	var ddd        = document.getElementById('frmnewfilial').ddd.value;
	var tel1       = document.getElementById('frmnewfilial').tel1.value;
	var tel2       = document.getElementById('frmnewfilial').tel2.value;
	var fax        = document.getElementById('frmnewfilial').fax.value;
	var endereco   = document.getElementById('frmnewfilial').endereco.value;
	var bairro     = document.getElementById('frmnewfilial').bairro.value;
	var cidade     = document.getElementById('frmnewfilial').cidade.value;
	var cep        = document.getElementById('frmnewfilial').cep.value;
	
	var strErro = "";
	var strCampos = "";
	
	document.getElementById("midErro").innerHTML = "";
	
	//CONTATO
	if( Trim( contato ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&contato=" + Trim( contato );
	}	
	
	//CNPJ
	if( Trim( cnpj ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		if( !validaCNPJ( Trim( cnpj ) ) )
		{
			strErro =  "Filiais :: CNPJ da Filial inv&aacute;lido. <BR>";
		}
		else
		{
			strCampos += "&cnpj=" + Trim( cnpj );
		}
	}	
	
	//DDD
	if( Trim( ddd ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&ddd=" + Trim( ddd );
	}
	
	//TEL1
	if( Trim( tel1 ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&tel1=" + Trim( tel1 );
	}
	
	//TEL2
	strCampos += "&tel2=" + Trim( tel2 );
	
	//FAX
	strCampos += "&fax=" + Trim( fax );	
	
	//ENDERECO
	if( Trim( endereco ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&endereco=" + Trim( endereco );
	}
	
	//BAIRRO
	if( Trim( bairro ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&bairro=" + Trim( bairro );
	}
	
	//CIDADE
	if( Trim( cidade ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&cidade=" + Trim( cidade );
	}	
	
	//CEP
	if( Trim( cep ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&cep=" + Trim( cep );
	}
	
	if( Trim( strErro ) != "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;
		return false;	
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncFilialCad.php?submit=1" + strCampos, metodo, modo );
    
	//SE O RETORNO FOR VAZIO SIGNIFICA QUE FOI TUDO OK , CASO CONTRÁRIO INFORMA O QUE HÁ NO RETORNO.
	if( Trim( envia ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = "Filiais :: Filial cadastrada com sucesso.";
		
		//LIMPA OS CAMPOS
		document.getElementById('frmnewfilial').contato.value = "";
		document.getElementById('frmnewfilial').cnpj.value = "";		
		document.getElementById('frmnewfilial').ddd.value = "";
		document.getElementById('frmnewfilial').tel1.value = "";
		document.getElementById('frmnewfilial').tel2.value = "";
		document.getElementById('frmnewfilial').fax.value = "";
		document.getElementById('frmnewfilial').endereco.value = "";
		document.getElementById('frmnewfilial').bairro.value = "";
		document.getElementById('frmnewfilial').cidade.value = "";
		document.getElementById('frmnewfilial').cep.value = "";
		
		document.getElementById('frmnewfilial').contato.focus();
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;	
	}
}

//ALTERACAO DE FILIAIS
function enviaUpdateFilial( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var filial     = document.getElementById('frmupdfilial').filial.value;
	var contato    = document.getElementById('frmupdfilial').contato.value;
	var ddd        = document.getElementById('frmupdfilial').ddd.value;
	var tel1       = document.getElementById('frmupdfilial').tel1.value;
	var tel2       = document.getElementById('frmupdfilial').tel2.value;
	var fax        = document.getElementById('frmupdfilial').fax.value;
	var endereco   = document.getElementById('frmupdfilial').endereco.value;
	var bairro     = document.getElementById('frmupdfilial').bairro.value;
	var cidade     = document.getElementById('frmupdfilial').cidade.value;
	var cep        = document.getElementById('frmupdfilial').cep.value;
	
	var strErro = "";
	var strCampos = "";
	
	document.getElementById("midErro").innerHTML = "";
	
	//CODIGO DA FILIAL
	strCampos += "&idfilial=" + Trim( filial );

	//CONTATO
	if( Trim( contato ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&contato=" + Trim( contato );
	}	
	
	//DDD
	if( Trim( ddd ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&ddd=" + Trim( ddd );
	}
	
	//TEL1
	if( Trim( tel1 ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&tel1=" + Trim( tel1 );
	}
	
	//TEL2
	strCampos += "&tel2=" + Trim( tel2 );
	
	//FAX
	strCampos += "&fax=" + Trim( fax );	
	
	//ENDERECO
	if( Trim( endereco ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&endereco=" + Trim( endereco );
	}
	
	//BAIRRO
	if( Trim( bairro ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&bairro=" + Trim( bairro );
	}
	
	//CIDADE
	if( Trim( cidade ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&cidade=" + Trim( cidade );
	}	
	
	//CEP
	if( Trim( cep ) == "" )
	{
		strErro =  "Filiais :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&cep=" + Trim( cep );
	}	
	
	if( Trim( strErro ) != "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;
		return false;	
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncFilialUpdate.php?submit=1" + strCampos, metodo, modo );
    
	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;
}

//DELETA FILIAL
function enviaDelFilial( metodo, modo, idfilial, idcliente )
{	
	document.getElementById("midErro").innerHTML = "";
	
	if( !confirm( 'Tem certeza que deseja excluir esta Filial ?' ) )
	{
		return false;
	}
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncFilialDel.php?submit=1&idfilial=" + idfilial + "&idcliente=" + idcliente, metodo, modo );
	
	if( Trim( envia ) == "" )
	{
		location='filialList.php';		
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
	}
}

//CONFIRMAÇÃO DE CADASTRO
function enviaCadConfirm( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var uid     = document.getElementById('frmFormConfirm').uid.value;
	var codigo  = document.getElementById('frmFormConfirm').codigo.value;
	var nomeresum  = document.getElementById('frmFormConfirm').nomeresum.value;
	var email  = document.getElementById('frmFormConfirm').email.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	if( Trim( codigo ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Cadastro :: &Eacute; necess&aacute;rio digitar o c&oacute;digo de confirma&ccedil;&atilde;o.";
		return false;
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncConfirmCad.php?submit=1&uid=" + uid + "&code=" + codigo + "&nomeresum=" + nomeresum + "&email=" + email, metodo, modo );
    
	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;
	
	alert('Cadastro confirmado com sucesso.\nFoi enviado um e-mail sobre seu Painel de Controle. Boa Sorte !.');
}

//PREENCHE A COMBO DE PARCELAS
function enviaComboParcelas( metodo, modo )
{
	//aqui eu pego o valor do campo text    	
	var tpsimul   = document.getElementById("tpsimul").value;
	var valor     = document.getElementById("valor").value;
	var tpemp     = document.getElementById("tpemp").value;
	var uf        = document.getElementById("uf").value;
		
		//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncTpEmprParc.php?submit=1&nTpEmp=" + tpemp + "&strUF=" + uf, metodo, modo );

    if( Trim( envia ) == "" )
	{
		location = 'index.php?strTpSimul=' + tpsimul + '&strValor=' + valor + '&nTpEmp=' + tpemp;
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
	}
}

//SIMULACAO
function enviaSimulacao( )
{
	var obj = null;
	
	var tpsimul      = document.getElementById('tpsimul').value;	
	
	//PEGA O CONTEUDO DA TEXT BOX
	obj              = document.getElementById('tpsimul');
	var strtpsimul   = obj.options[obj.selectedIndex].text;
	
	var valor        = document.getElementById('valor').value;
	var tpemp        = document.getElementById('tpemp').value;
	
	//PEGA O CONTEUDO DA TEXT BOX
	obj              = document.getElementById('tpemp');
	var strtpemp     = obj.options[obj.selectedIndex].text;	
	
	var numparc      = document.getElementById('numparc').value;
	var uf           = document.getElementById('uf').value;
	
	document.getElementById("midErro").innerHTML = "";	
	
	if( Trim( valor ) == "" ||  Math.round( retornaValorBancoRS( valor ) ) == 0 )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Simula&ccedil;&atilde;o :: &Eacute; necess&aacute;rio digitar um Valor.";
		return false;
	}	
	
	if( Trim( tpemp ) == 0 )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Simula&ccedil;&atilde;o :: &Eacute; necess&aacute;rio escolher um Tipo de Empr&eacute;stimo.";
		return false;
	}
	
	if( Trim( numparc ) == 0 )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Simula&ccedil;&atilde;o :: &Eacute; necess&aacute;rio escolher uma Parcela.";
		return false;
	}	
	
	/*if( Trim( uf ) == "" ||  Trim( uf ) == "-" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Simula&ccedil;&atilde;o :: Para Simular &eacute; necess&aacute;rio escolher uma Localidade.";
		return false;
	}*/	

	document.getElementById('strtpsimul').value = strtpsimul;
	document.getElementById('strtpemp').value = strtpemp;

	return true;
}

function enviaEmailSolicitEmpr( metodo, modo )
{
	//aqui eu pego o valor do campo text			
	var nTpEmail     	= document.getElementById('frmenvioemail').tpemail.value;
	var nIdCliente      = document.getElementById('frmenvioemail').idcliente.value;
	var strNomeResum    = document.getElementById('frmenvioemail').nomeresum.value;
	var strTpSimul      = document.getElementById('frmenvioemail').tpsimul.value;
	var strValTpSimul   = document.getElementById('frmenvioemail').valtpsimul.value;
	var nTpEmp       	= document.getElementById('frmenvioemail').tpemp.value;
	var strTpEmp     	= document.getElementById('frmenvioemail').valtpemp.value;
	var nParc         	= document.getElementById('frmenvioemail').parc.value;
	var dValorDig       = document.getElementById('frmenvioemail').valordig.value;
	var nColoc      	= document.getElementById('frmenvioemail').coloc.value;
	var dValorRet  	    = document.getElementById('frmenvioemail').valorret.value;
	
	var strContato     	= document.getElementById('frmenvioemail').contato.value;
	var strEmailContato = document.getElementById('frmenvioemail').email.value;
	var strDDD          = document.getElementById('frmenvioemail').ddd.value;
	var strTel          = document.getElementById('frmenvioemail').tel1.value;
	var strBairo        = document.getElementById('frmenvioemail').bairro.value;
	var strCidade      	= document.getElementById('frmenvioemail').cidade.value;
	var strUF       	= document.getElementById('frmenvioemail').uf.value;
	
	var strMsg          = document.getElementById('frmenvioemail2').mensagem.value;
	var codigo          = document.getElementById('frmenvioemail3').codigo.value;
	
	var strErro = "";
	var strCampos = "";
	
	document.getElementById("midErro").innerHTML = "";
	

	//CONTATO
	if( Trim( strContato ) == "" )
	{
		strErro =  "Envio de E-mail :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&strContato=" + Trim( strContato );
	}	
	
	//EMAIL
	if( Trim( strEmailContato ) == "" )
	{
		strErro =  "Envio de E-mail :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}
	else
	{
		if( !isEmail( Trim( strEmailContato ) ) )
		{
			strErro = "Envio de E-mail :: E-mail n&atilde;o &eacute; v&aacute;lido. <BR>";
		}
		else
		{
			strCampos += "&strEmailContato=" + Trim( strEmailContato );
		}
	}	

	//DDD
	if( Trim( strDDD ) == "" )
	{
		strErro =  "Envio de E-mail :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&strDDD=" + Trim( strDDD );
	}
	
	//TEL1
	if( Trim( strTel ) == "" )
	{
		strErro =  "Envio de E-mail :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&strTel=" + Trim( strTel );
	}
	
	//BAIRRO
	if( Trim( strBairo ) == "" )
	{
		strErro =  "Envio de E-mail :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&strBairo=" + Trim( strBairo );
	}	
	
	//CIDADE
	if( Trim( strCidade ) == "" )
	{
		strErro =  "Envio de E-mail :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&strCidade=" + Trim( strCidade );
	}	

	//UF
	if( Trim( strUF ) == "-" || Trim( strUF ) == "" )
	{
		strErro =  "Envio de E-mail :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&strUF=" + Trim( strUF );
	}	
	
	//MENSAGEM
	if( Trim( strMsg ) == "" )
	{
		strErro =  "Envio de E-mail :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		if( strMsg.length > 350 )
		{
			strErro =  "Envio de E-mail :: O Campo Mensagem ultrapassou de 350 caracteres !<br /> Atualmente ele se encontra com " + strMsg.length + " caraceters.";
		}
		else
		{
			strCampos += "&strMsg=" + Trim( strMsg );
		}
	}
	
	strCampos += "&nTpEmail=" 		+ Trim( nTpEmail );
	strCampos += "&nIdCliente=" 	+ Trim( nIdCliente );
	strCampos += "&strNomeResum=" 	+ Trim( strNomeResum );
	strCampos += "&strTpSimul=" 	+ Trim( strTpSimul );
	strCampos += "&strValTpSimul=" 	+ Trim( strValTpSimul );
	strCampos += "&nTpEmp=" 		+ Trim( nTpEmp );
	strCampos += "&strTpEmp=" 		+ Trim( strTpEmp );
	strCampos += "&nParc=" 			+ Trim( nParc );
	strCampos += "&dValorDig=" 		+ Trim( dValorDig );
	strCampos += "&nColoc=" 		+ Trim( nColoc );
	strCampos += "&dValorRet=" 		+ Trim( dValorRet );

	if( Trim( strErro ) == "" )
	{
		if( Trim( codigo ) == ""  )
		{
			strErro =  "Envio de E-mail :: &Eacute; necess&aacute;rio digitar o c&oacute;digo de confirma&ccedil;&atilde;o.";
		}
		else
		{
			strCampos += "&code=" + Trim( codigo );
		}
	}
	
	if( Trim( strErro ) != "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;
		
		location='#top';
		
		return false;	
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	alert( strCampos );
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncEnviaEmailSolicitacao.php?submit=1" + strCampos, metodo, modo );
    
	//SE O RETORNO FOR VAZIO SIGNIFICA QUE FOI TUDO OK , CASO CONTRÁRIO INFORMA O QUE HÁ NO RETORNO.
	if( Trim( envia ) == "" )
	{
		alert('Por favor, confirme os dados de envio no E-mail cadastrado.\nCaso deixe de confirmar, em 72 horas iremos excluir seu e-mail antes de ser enviado !');
		
		location='index.php';
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
		
		location='#top';
	}
}

function enviaClickLinkBanner( metodo, modo, idbanner, idcliente, tipo, obj, url, target )
{	
	document.getElementById("midErro").innerHTML = "";
	document.getElementById("midErro").style.display = "none";	
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncGravaViewClick.php?submit=1&nIDBanner=" + idbanner + "&nIDCliente=" + idcliente + "&strTipo=" + tipo, metodo, modo );
	
	if( Trim( envia ) == "" )
	{
		obj.target = target;
		obj.href   = url;	
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
	}	
}

//******************************PAINEL DO CLIENTE**************************************************************
//******************************
//******************************
//******************************
//******************************
//******************************

//VERIFICAÇÃO DE LOGIN
function enviaLogin( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var login     = document.getElementById('frmlogin').login.value;
	var senha     = document.getElementById('frmlogin').senha.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	if( Trim( login ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Login :: Campo Login &eacute; obrigat&oacute;rio.";
		return false;
	}
	
	if( Trim( senha ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Login :: Campo Senha &eacute; obrigat&oacute;rio.";
		return false;
	}	
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncLogin.php?submit=1&login=" + login + "&pass=" + senha, metodo, modo );
	
	if( Trim( envia ) == "" )
	{
		location='default.php';
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
	}
}

//ENVIO PARA O EMAIL SOBRE INSTRUCOES DA RECUPERAÇÃO DE SENHA
function enviaRecoverPass( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var cnpj     = document.getElementById('frmrecad').cnpj.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	if( Trim( cnpj ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: &Eacute; necess&aacute;rio digitar o CNPJ cadastrado.";
		return false;
	}	
	else
	{
		if( !validaCNPJ( Trim( cnpj ) ) )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML =  "Re-Cadastro :: CNPJ inv&aacute;lido.";
			return false;			
		}
	}	
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncEnviaInstRecover.php?submit=1&cnpj=" + cnpj, metodo, modo );
    
	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;
}

//ENVIO PARA O EMAIL SOBRE INSTRUCOES DA RECUPERAÇÃO DE SENHA
function enviaConfirmRecover( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var cnpj     = document.getElementById('frmreconfirm').cnpj.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	if( Trim( cnpj ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Reenvio de Confirma&ccedil;&atilde;o :: &Eacute; necess&aacute;rio digitar o CNPJ cadastrado.";
		return false;
	}	
	else
	{
		if( !validaCNPJ( Trim( cnpj ) ) )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML =  "Reenvio de Confirma&ccedil;&atilde;o :: CNPJ inv&aacute;lido.";
			return false;			
		}
	}	
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncReenviaConfirmCad.php?submit=1&cnpj=" + cnpj, metodo, modo );
    
	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;
}

//RECADASTRO DE DADOS
function enviaRecadPass( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var login      = document.getElementById('frmrecad').login.value;
	var senha      = document.getElementById('frmrecad').senha.value;
	var resenha    = document.getElementById('frmrecad').resenha.value;
	var codigo     = document.getElementById('frmrecad').codigo.value;
	var loginOld   = document.getElementById('frmrecad').uid.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	if( Trim( loginOld ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: Sess&atilde;o inv&aacute;lida.<BR>Tente Novamente.";
		return false;	
	}
	
	//LOGIN
	if( Trim( login ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: &Eacute; necess&aacute;rio preencher o Login.";
		return false;		
	}	
	
	if( Trim( login ).length < 6 )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: M&iacute;nimo de 6 caracteres para o campo Login !";	
		return false;
	}	
	
	//SENHA
	if( Trim( senha ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: &Eacute; necess&aacute;rio preencher a Senha.";
		return false;
	}	
	
	if( Trim( senha ).length < 6 )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: M&iacute;nimo de 6 caracteres para o campo Senha !";	
		return false;
	}
		
	//RE SENHA
	if( Trim( resenha ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: Re-digite a senha.";
		return false;		
	}	
	else
	{
		if( resenha != senha )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML =  "Re-Cadastro :: Erro ao re-digitar a senha.";
			return false;				
		}
	}	
	
	if( Trim( codigo ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: &Eacute; necess&aacute;rio digitar o c&oacute;digo de confirma&ccedil;&atilde;o.";
		return false;
	}	
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncPassRecad.php?submit=1&login=" + login + "&senha=" + senha + "&code=" + codigo + "&uid=" + loginOld, metodo, modo );
    
	if( Trim( envia ) == "" )
	{
		location='index.php';
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
		
		document.getElementById('frmrecad').login.value = "";
		document.getElementById('frmrecad').senha.value = "";
		document.getElementById('frmrecad').resenha.value = "";
		document.getElementById('frmrecad').codigo.value = "";
		document.getElementById('frmrecad').uid.value = "";
	}
}

//ALTERACAO DE SENHA
function enviaUpdatePass( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var senhaold   = document.getElementById('frmupdpass').senhaold.value;
	var senhanew   = document.getElementById('frmupdpass').senhanew.value;
	var resenha    = document.getElementById('frmupdpass').resenha.value;
	var codigo     = document.getElementById('frmupdpass').codigo.value;
	var nid        = document.getElementById('frmupdpass').uid.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	//SENHA ATUAL
	if( Trim( senhaold ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: &Eacute; necess&aacute;rio preencher a Senha Atual.";
		return false;
	}
	
	
	//SENHA
	if( Trim( senhanew ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: &Eacute; necess&aacute;rio preencher a Nova Senha.";
		return false;
	}	
	
	if( Trim( senhanew ).length < 6 )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: M&iacute;nimo de 6 caracteres para o campo Senha !";
		return false;
	}
	
	//RE SENHA
	if( Trim( resenha ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: Re-digite a senha.";
		return false;		
	}	
	else
	{
		if( resenha != senhanew )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML =  "Re-Cadastro :: Erro ao re-digitar a senha.";
			return false;				
		}
	}	
	
	if( Trim( codigo ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "Re-Cadastro :: &Eacute; necess&aacute;rio digitar o c&oacute;digo de confirma&ccedil;&atilde;o.";
		return false;
	}	
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncPassUpdate.php?submit=1&senhaold=" + senhaold + "&senhanew=" + senhanew + "&code=" + codigo + "&uid=" + nid, metodo, modo );
    
	if( Trim( envia ) == "" )
	{
		location='logout.php';
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
		
		document.getElementById('frmupdpass').senhaold.value = "";
		document.getElementById('frmupdpass').senhanew.value = "";
		document.getElementById('frmupdpass').resenha.value = "";
		document.getElementById('frmupdpass').codigo.value = "";
	}
}

//FALE SUPORTE
function enviaSuporte( metodo, modo )
{
	var ntpassunto = document.getElementById('frmfale').tpassunto.value;
	
	var obj          = document.getElementById('frmfale').tpassunto;
	var strtpassunto = obj.options[obj.selectedIndex].text;
	
	var assunto    = document.getElementById('frmfale').assunto.value;
	var message    = document.getElementById('frmfale2').message.value;	

	var strErro = "";
	var strCampos = "";
	
	document.getElementById("midErro").innerHTML = "";
	
	//ASSUNTO
	if( Trim( assunto ) == "" )
	{
		strErro =  "Suporte :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&assunto=" + Trim( assunto );
	}	
	
	//DESCRICAO
	if( Trim( message ) == "" )
	{
		strErro =  "Suporte :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&desc=" + Trim( message );
	}
	
	//TIPO DO ASSUNTO
	strCampos += "&ntpassunto=" + Trim( ntpassunto );
	
	//DESCRICAO TIPO DO ASSUNTO
	strCampos += "&strtpassunto=" + Trim( strtpassunto );	
	
	//TIPO ENVIO
	strCampos += "&tpenvio=SUPORTE";	
	
	if( Trim( strErro ) != "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;
		return false;	
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncEnviaSuporte.php?" + strCampos, metodo, modo );

	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;

	//LIMPA OS CAMPOS
	document.getElementById('frmfale').assunto.value = "";
	document.getElementById('frmfale2').message.value = "";
}

//ALTERACAO DE EMPRESAS
function enviaUpdateCad( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var nomecomp   = document.getElementById('frmupdcad').nomecomp.value;
	var nomeresum  = document.getElementById('frmupdcad').nomeresum.value;
	var contato    = document.getElementById('frmupdcad').contato.value;
	var categ      = document.getElementById('frmupdcad').categ.value;	
	var ddd        = document.getElementById('frmupdcad').ddd.value;
	var tel1       = document.getElementById('frmupdcad').tel1.value;
	var tel2       = document.getElementById('frmupdcad').tel2.value;
	var tel3       = document.getElementById('frmupdcad').tel3.value;
	var fax        = document.getElementById('frmupdcad').fax.value;
	var telgratis  = document.getElementById('frmupdcad').telgratis.value;
	var endereco   = document.getElementById('frmupdcad').endereco.value;
	var bairro     = document.getElementById('frmupdcad').bairro.value;
	var cidade     = document.getElementById('frmupdcad').cidade.value;
	var uf         = document.getElementById('frmupdcad').uf.value;
	var cep        = document.getElementById('frmupdcad').cep.value;
	var url        = document.getElementById('frmupdcad').url.value;
	var indic      = document.getElementById('frmupdcad').indicacao.value;
	
	var strErro = "";
	var strCampos = "";
	
	document.getElementById("midErro").innerHTML = "";
	
	//NOME COMPLETO
	if( Trim( nomecomp ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";		
	}
	else
	{
		strCampos = "&nomecomp=" + Trim( nomecomp );
	}
	
	//NOME RESUMIDO
	if( Trim( nomeresum ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&nomeresum=" + Trim( nomeresum );
	}

	//CONTATO
	if( Trim( contato ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&contato=" + Trim( contato );
	}	
	
	//TIPO DE ASSESSORIA
	strCampos += "&categ=" + Trim( categ );		
	
	//DDD
	if( Trim( ddd ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&ddd=" + Trim( ddd );
	}
	
	//TEL1
	if( Trim( tel1 ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&tel1=" + Trim( tel1 );
	}
	
	//TEL2
	strCampos += "&tel2=" + Trim( tel2 );
	
	//TEL3
	strCampos += "&tel3=" + Trim( tel3 );
	
	//FAX
	strCampos += "&fax=" + Trim( fax );	
	
	//0800
	strCampos += "&telgratis=" + Trim( telgratis );	
	
	//ENDERECO
	if( Trim( endereco ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&endereco=" + Trim( endereco );
	}
	
	//BAIRRO
	if( Trim( bairro ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&bairro=" + Trim( bairro );
	}
	
	//CIDADE
	if( Trim( cidade ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&cidade=" + Trim( cidade );
	}	

	//UF
	if( Trim( uf ) == "-" || Trim( uf ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&uf=" + Trim( uf );
	}

	//CEP
	if( Trim( cep ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&cep=" + Trim( cep );
	}
	
	//URL
	strCampos += "&url=" + Trim( url );	
	
	//INDICACAO
	strCampos += "&indic=" + Trim( indic );		
	
	if( Trim( strErro ) != "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;
		return false;	
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncEmpresaUpdate.php?submit=1" + strCampos, metodo, modo );
    
	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;
}

//DESATIVAR CADASTRO
function enviaCancelCad( metodo, modo )
{
	//aqui eu pego o valor do campo text 
	var motivo     = document.getElementById('frmcancelcad2').motivo.value;	
	var codigo     = document.getElementById('frmcancelcad3').codigo.value;
	
	var strErro = "";
	var strCampos = "";	
	
	document.getElementById("midErro").innerHTML = "";
	
	//DESCRICAO
	if( Trim( motivo ) == "" )
	{
		strErro =  "Cadastro :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&motivo=" + Trim( motivo );
	}
	
	if( Trim( strErro ) == "" )
	{
		if( Trim( codigo ) == ""  )
		{
			strErro =  "Cadastro :: &Eacute; necess&aacute;rio digitar o c&oacute;digo de confirma&ccedil;&atilde;o.";
		}
		else
		{
			strCampos += "&code=" + Trim( codigo );
		}
	}
	
	if( Trim( strErro ) != "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;
		return false;	
	}	
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncEmpresaCancel.php?submit=1" + strCampos, metodo, modo );
    
	if( Trim( envia ) == "" )
	{
		location='logout.php';
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
	}
}

//CONFIGURAÇÕES DO CADASTRO
function enviaConfigUpdate( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var idcliente         = document.getElementById('frmconfig').idcliente.value;
	var bexbebannertuf    = document.getElementById('frmconfig').bexbebannertuf.checked 	? 1 : 0;
	var bexbeemailsimul   = document.getElementById('frmconfig').bexbeemailsimul.checked 	? 1 : 0;
	var bexbelinksptrc    = document.getElementById('frmconfig').bexbelinksptrc.checked 	? 1 : 0;
	var bexbeservtuf      = document.getElementById('frmconfig').bexbeservtuf.checked 		? 1 : 0;
	var bexbeiconoferta   = document.getElementById('frmconfig').bexbeiconoferta.checked 	? 1 : 0;
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncConfigUpdate.php?submit=1&nIDCliente=" + idcliente + "&bExbeBannerTUf=" + bexbebannertuf + "&bExbeEmailSimul=" + bexbeemailsimul + "&bExbeLinksPtrc=" + bexbelinksptrc + "&bExbeServTUF=" + bexbeservtuf + "&bExbeIconOferta=" + bexbeiconoferta, metodo, modo );
    
	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;
}

//MONTA TRIPA FATORES
function enviaTripaFator( metodo, modo, tpcad, indice )
{
	//aqui eu pego o valor do campo text    
	var tpemp      = document.getElementById('frmnewfator').ntpemp.value;
	var parcela    = document.getElementById('frmnewfator').parcela.value;
	var fator      = document.getElementById('frmnewfator').fator.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	if( tpcad == "I" )
	{
		//TIPO DE EMPRÉSTIMO
		if( Trim( tpemp ) == "" )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML =  "Fatores :: &Eacute; necess&aacute;rio escolher o Tipo de Empr&eacute;stimo.";
			return false;
		}
		
		
		//PARCELA
		if( Trim( parcela ) == "" )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML =  "Fatores :: &Eacute; necess&aacute;rio preencher a Parcela";
			return false;
		}
		
		if( Trim( parcela ) > 150 )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML =  "Fatores :: A quantidade m&aacute;xima de parcelas &eacute; de 150.";
			return false;
		}	
		
		//FATOR
		if( Trim( fator ) == "" ||  retornaValorBancoUS( Trim( fator ) ) == 0 )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML =  "Fatores :: &Eacute; necess&aacute;rio preencher o Fator";
			return false;
		}
		
		if( Trim( fator ).indexOf( "." ) == -1 )
		{
			document.getElementById("midErro").style.display = "block";
			document.getElementById("midErro").innerHTML =  "Fatores :: &Eacute; necess&aacute;rio preencher um Fator v&aacute;lido";
			return false;
		}	
	
		//LIMPA O CAMPO DE MSGS
		document.getElementById("midErro").innerHTML = "";
	}
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncFatorMntTripa.php?submit=1&tpcad=" + tpcad + "&indice=" + indice + "&tpemp=" + tpemp + "&parc=" + parcela + "&fator=" + retornaValorBancoUS( fator ), metodo, modo );
	
	if( Trim( envia ).indexOf( "Fatores ::" ) == -1 )
	{
		document.getElementById("midErro").innerHTML = "";
		document.getElementById("midErro").style.display = "none";
		
		document.getElementById("tbfator").innerHTML = envia;		
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
	}
	
	document.getElementById('frmnewfator').parcela.value = "";
	document.getElementById('frmnewfator').fator.value = "";
}

//CADASTRA OS FATORES
function enviaCadFator( metodo, modo )
{	
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncFatorCad.php?submit=1", metodo, modo );
	
	if( Trim( envia ) == "" )
	{
		location='factoryList.php';		
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
	}
}

//CADASTRA OS FATORES
function enviaDelFator( metodo, modo, tpemp, idcliente )
{	
	document.getElementById("midErro").innerHTML = "";
	
	if( !confirm( 'Tem certeza que deseja excluir todas suas Parcelas ?' ) )
	{
		return false;
	}
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncFatorDel.php?submit=1&tpemp=" + tpemp + "&idcliente=" + idcliente, metodo, modo );
	
	if( Trim( envia ) == "" )
	{
		location='factoryList.php';		
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
	}
}

//ANUNCIOS GRATIS
function enviaBuscaAnuncio( )
{
	var obj = null;
	
	var pchave      = document.getElementById('frmbuscaanunc').key.value;	
	
	document.getElementById("midErro").innerHTML = "";	
	
	if( Trim( pchave ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "An&uacute;ncios Gr&aacute;tis :: &Eacute; necess&aacute;rio digitar uma Palavra-Chave.";
		return false;
	}

	return true;
}

function enviaClickViewsAnuncios( metodo, modo, idanunc, tipo, obj, url, target )
{	
	document.getElementById("midErro").innerHTML = "";
	document.getElementById("midErro").style.display = "none";	
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncGravaViewClickAnuncios.php?submit=1&nIDAnuncio=" + idanunc + "&strTipo=" + tipo, metodo, modo );
	
	if( Trim( envia ) == "" )
	{
		obj.target = target;
		obj.href   = url;	
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
	}	
}


function enviaCadAnunc( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var titulo     	= document.getElementById('frmanuncnew').titulo.value;
	var email      	= document.getElementById('frmanuncnew').email.value;
	var contato    	= document.getElementById('frmanuncnew').contato.value;
	var categ      	= document.getElementById('frmanuncnew').categ.value;
	var ddd        	= document.getElementById('frmanuncnew').ddd.value;
	var tel1       	= document.getElementById('frmanuncnew').tel1.value;
	var cidade     	= document.getElementById('frmanuncnew').cidade.value;
	var uf         	= document.getElementById('frmanuncnew').uf.value;
	var url        	= document.getElementById('frmanuncnew').url.value;
	var indic      	= document.getElementById('frmanuncnew').indicacao.value;
	var descricao  	= document.getElementById('frmanuncnew2').descricao.value;
	var ckexbeemail = document.getElementById('frmanuncnew3').ckexbeemail.value;
	var cktermo    	= document.getElementById('frmanuncnew3').cktermo.value;
	var codigo      = document.getElementById('frmanuncnew4').codigo.value;
	
	var strErro = "";
	var strCampos = "";
	
	document.getElementById("midErro").innerHTML = "";
	
	//NOME COMPLETO
	if( Trim( titulo ) == "" )
	{
		strErro =  "An&uacute;ncios Gr&aacute;tis :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";		
	}
	else
	{
		strCampos = "&titulo=" + Trim( titulo );
	}
	
	//EMAIL
	if( Trim( email ) == "" )
	{
		strErro =  "An&uacute;ncios Gr&aacute;tis :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}
	else
	{
		if( !isEmail( Trim( email ) ) )
		{
			strErro = "An&uacute;ncios Gr&aacute;tis :: E-mail n&atilde;o &eacute; v&aacute;lido. <BR>";
		}
		else
		{
			strCampos += "&email=" + Trim( email );
		}
	}	

	//CONTATO
	if( Trim( contato ) == "" )
	{
		strErro =  "An&uacute;ncios Gr&aacute;tis :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&contato=" + Trim( contato );
	}	
	
	//TIPO DE ASSESSORIA
	strCampos += "&categ=" + Trim( categ );	
	
	//DDD
	if( Trim( ddd ) == "" )
	{
		strErro =  "An&uacute;ncios Gr&aacute;tis :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&ddd=" + Trim( ddd );
	}
	
	//TEL1
	if( Trim( tel1 ) == "" )
	{
		strErro =  "An&uacute;ncios Gr&aacute;tis :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&tel1=" + Trim( tel1 );
	}
	
	//CIDADE
	if( Trim( cidade ) == "" )
	{
		strErro =  "An&uacute;ncios Gr&aacute;tis :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&cidade=" + Trim( cidade );
	}	

	//UF
	if( Trim( uf ) == "-" || Trim( uf ) == "" )
	{
		strErro =  "An&uacute;ncios Gr&aacute;tis :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		strCampos += "&uf=" + Trim( uf );
	}
	
	//URL
	strCampos += "&url=" + Trim( url );	
	
	//INDICACAO
	strCampos += "&indic=" + Trim( indic );		
	
	//DESCRICAO
	if( Trim( descricao ) == "" )
	{
		strErro =  "An&uacute;ncios Gr&aacute;tis :: Existem Campos Obrigat&oacute;rios n&atilde;o Preenchidos !";
	}	
	else
	{
		if( descricao.length > 350 )
		{
			strErro =  "An&uacute;ncios Gr&aacute;tis :: O Campo Descri&ccedil;&atilde;o do An&uacute;ncio ultrapassou de 350 caracteres !<br /> Atualmente ele se encontra com " + descricao.length + " caraceters.";
		}
		else
		{
			strCampos += "&descricao=" + Trim( descricao );
		}
	}	
	
	//EXIBE EMAIL NO ANUNCIO
	strCampos += "&ckexbeemail=" + ( document.getElementById('frmanuncnew3').ckexbeemail.checked ? 1 : 0 );	
	
	if( Trim( strErro ) == "" )
	{
		if( Trim( codigo ) == ""  )
		{
			strErro =  "An&uacute;ncios Gr&aacute;tis :: &Eacute; necess&aacute;rio digitar o c&oacute;digo de confirma&ccedil;&atilde;o.";
		}
		else
		{
			strCampos += "&code=" + Trim( codigo );
		}
	}
	
	if( Trim( strErro ) == "" )
	{	
		var cktermo    = document.getElementById('frmanuncnew3').cktermo.checked;	
		
		if( !cktermo )
		{
			strErro =  "An&uacute;ncios Gr&aacute;tis :: &Eacute; necess&aacute;rio ler e confirmar o Termo de Uso.";
		}
	}
	
	if( Trim( strErro ) != "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;
		
		location='#top';
		
		return false;	
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncCadAnuncio.php?submit=1" + strCampos, metodo, modo );
    
	//SE O RETORNO FOR VAZIO SIGNIFICA QUE FOI TUDO OK , CASO CONTRÁRIO INFORMA O QUE HÁ NO RETORNO.
	if( Trim( envia ) == "" )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = "An&uacute;ncio cadastrado com sucesso. <BR> Enviamos um e-mail para confirma&ccedil;&atilde;o.";
		
		//LIMPA OS CAMPOS		
		document.getElementById('frmanuncnew').titulo.value = "";
		document.getElementById('frmanuncnew').email.value = "";
		document.getElementById('frmanuncnew').contato.value = "";
		document.getElementById('frmanuncnew').ddd.value = "";
		document.getElementById('frmanuncnew').tel1.value = "";
		document.getElementById('frmanuncnew').cidade.value = "";
		document.getElementById('frmanuncnew').url.value = "";
		document.getElementById('frmanuncnew2').descricao.value = "";
		document.getElementById('frmanuncnew4').codigo.value = "";
		
		//LIMPA VISUALIZACOES
		document.getElementById("dvTitulo").innerHTML 	= '';
		document.getElementById("dvDesc").innerHTML   	= '';
		document.getElementById("dvContato").innerHTML  = '';
		document.getElementById("dvCateg").innerHTML  	= '';
		document.getElementById("dvTel").innerHTML    	= '';
		document.getElementById("dvCidade").innerHTML 	= '';
		document.getElementById("dvUF").innerHTML     	= '';
		document.getElementById("dvEmail").innerHTML  	= '';
		document.getElementById("dvURL").innerHTML    	= '';		
		
		alert('Cadastro efetuado com sucesso.\nPara darmos continuidade, confirme seu cadastro no E-mail cadastrado.\nCaso deixe de confirmar, em 72 horas iremos excluir seu cadastro !');
		
		location='#top';
	}
	else
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = envia;
		
		location='#top';
	}
}

//CONFIRMAÇÃO DE CADASTRO
function enviaAnuncConfirm( metodo, modo )
{
	//aqui eu pego o valor do campo text    
	var uid      = document.getElementById('frmanuncconfirm').uid.value;
	var codigo   = document.getElementById('frmanuncconfirm').codigo.value;
	var email    = document.getElementById('frmanuncconfirm').email.value;
	var contato  = document.getElementById('frmanuncconfirm').contato.value;
	
	document.getElementById("midErro").innerHTML = "";
	
	if( Trim( codigo ) == ""  )
	{
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML =  "An&uacute;ncios Gr&aacute;tis :: &Eacute; necess&aacute;rio digitar o c&oacute;digo de confirma&ccedil;&atilde;o.";
		return false;
	}
	
	//LIMPA O CAMPO DE MSGS
	document.getElementById("midErro").innerHTML = "";
	
	//estancio o ajax
    remoto    = new ajax();
	
	//envio os dados para uma pagina php passando os parametros texto = valor do campo text
    envia     = remoto.enviar( "fncConfirmAnuncio.php?submit=1&uid=" + uid + "&code=" + codigo + "&email=" + email + "&contato=" + contato, metodo, modo );
    
	document.getElementById("midErro").style.display = "block";
	document.getElementById("midErro").innerHTML = envia;
}

//VISUALIZACAO DO ANUNCIO
function enviaViewAnunc( )
{
	var obj = null;
	
	var titulo      = document.getElementById('frmanuncnew').titulo.value;	
	var email       = document.getElementById('frmanuncnew').email.value;
	var contato     = document.getElementById('frmanuncnew').contato.value;
	
	obj             = document.getElementById('frmanuncnew').categ;
	var strcateg    = obj.options[obj.selectedIndex].text;
	
	var ddd         = document.getElementById('frmanuncnew').ddd.value;
	var tel1        = document.getElementById('frmanuncnew').tel1.value;
	var cidade      = document.getElementById('frmanuncnew').cidade.value;
	
	obj             = document.getElementById('frmanuncnew').uf;
	var struf       = obj.options[obj.selectedIndex].text
	
	var url         = document.getElementById('frmanuncnew').url.value;
	var descricao   = document.getElementById('frmanuncnew2').descricao.value;
	
	//DESCRICAO
	if( descricao.length > 350 )
	{
		var strErro =  "An&uacute;ncios Gr&aacute;tis :: O Campo Descri&ccedil;&atilde;o do An&uacute;ncio ultrapassou de 350 caracteres !<br /> Atualmente ele se encontra com " + descricao.length + " caraceters.";
		
		document.getElementById("midErro").style.display = "block";
		document.getElementById("midErro").innerHTML = strErro;	
		
		location='#top';
		
		return false;
	}		
	
	document.getElementById("viewAnunc").style.display = "block";
	
	document.getElementById("dvTitulo").innerHTML 	= '<em><u>' + titulo + '</u></em>';
	document.getElementById("dvDesc").innerHTML   	= descricao.replace(/(\r\n|\r|\n)/igm, '<br/>');
	document.getElementById("dvContato").innerHTML  = '<span style="font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#000000"><strong>' + contato + '</strong></span>';
	document.getElementById("dvCateg").innerHTML  	= '<span style="font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#000000"><strong>' + strcateg + '</strong></span>';
	document.getElementById("dvTel").innerHTML    	= '(' + ddd + ') ' + tel1;
	document.getElementById("dvCidade").innerHTML 	= cidade;
	document.getElementById("dvUF").innerHTML     	= struf;
	document.getElementById("dvEmail").innerHTML  	= email;
	document.getElementById("dvURL").innerHTML    	= url;

	return true;
}
