/* 
* ============================================================================
* ==  ARQUIVO DE SCRIPTS UTILIZADO NOS SISTEMAS DA INTRANET CREDICOM		==
* ============================================================================
* == 	@ Desenvolvedores: Célio Henrique 								    ==
* ==	    			   Paulo Francis                                    ==
* ============================================================================
*/

function ExibeFlash(ID){
	if (ID == 1){ //menu
		document.write('<embed src="images/menu.swf" quality="high" type="application/x-shockwave-flash" width="706" height="89"  wmode="transparent"></embed>');
	}
	
	else if (ID == 2){ //banner
  		document.write('<embed src="banner/bannertopo.swf" quality="high" type="application/x-shockwave-flash" width="980" height="209" wmode="transparent"></embed>');
	}
	
	else if (ID == 3){ //clientes pequeno
  		document.write('<embed src="images/algclientes.swf" quality="high" type="application/x-shockwave-flash" width="619" height="53" wmode="transparent"></embed>');
	}
	else if (ID == 4){ //clientes grande
  		document.write('<embed src="images/algclientesGd.swf" quality="high" type="application/x-shockwave-flash" width="550" height="400" wmode="transparent"></embed>');
	}	
	
  
  
}
 
/* EXIBE E ESCONDE DIV */
function ExibeDIV (ID){

   if (document.getElementById(ID).style.display == "none") {   
      document.getElementById(ID).style.display= ""; 
   }
   else {  
      document.getElementById(ID).style.display = "none";
   }
}

/* FORMATA VALOR */
function currencyFormat(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;
}

/* ACEITA APENAS NUMERO NO CAMPO, SEM ALERT */
function somente_numero(campo){
   var digits="0123456789"
   var campo_temp
   for (var i=0; i<campo.value.length; i++){
      campo_temp = campo.value.substring(i,i+1)
      if (digits.indexOf(campo_temp)==-1){
         campo.value = campo.value.substring(0,i);
      }
    }
}

/* ACEITA APENAS NUMERO NO CAMPO, COM ALERT */
function SoNumeros(){
   var carCode = event.keyCode;

   if (carCode == 13){
   }
   else if ((carCode < 48) || (carCode > 57)){
      alert('Por favor, digite apenas números!');
      event.cancelBubble = true
      event.returnValue = false;
   }
}

/* FORMATA O CAMPO DA MENEIRA QUE DESEJAR */
function FormataValorDefaultText(strNMCampo, formato, intOnFocus){
	var strNull = '';
	if (intOnFocus == 1) {
		if (window.document.forms["form1"].elements[strNMCampo].value + '' == formato) {
			window.document.forms["form1"].elements[strNMCampo].value = '';
		}
	}
	if (intOnFocus == 0) {
		if (window.document.forms["form1"].elements[strNMCampo].value + '' == '') {
			window.document.forms["form1"].elements[strNMCampo].value = formato;
		}
	}
}

/* ADICIONA MASCARA DE CNPJ NO CAMPO */
function MascaraCNPJ(cnpj){
    if(mascaraInteiro(cnpj)==false){
        event.returnValue = false;
    }
    return formataCampo(cnpj, '00.000.000/0000-00', event);
}

/* ADICIONA MASCARA DE DATA NO CAMPO */
function MascaraData(data){
    if(mascaraInteiro(data)==false){
        event.returnValue = false;
    }
    return formataCampo(data, '00/00/0000', event);
}

/* ADICIONA MASCARA DE CPF NO CAMPO */
function MascaraCPF(cpf){
    if(mascaraInteiro(cpf)==false){
        event.returnValue = false;
    }
    return formataCampo(cpf, '000.000.000-00', event);
}

/* FORMATA CC NO FORMATO 000000000-0 */
function FormataContaCorrente(strNMCampo){

	var vr = window.document.forms["form1"].elements[strNMCampo].value;
	vr = vr.replace("-", "");
	vr = Number(vr);
	vr = String(vr);

	//Coloca formatação
	var zeros = "";
	for (var x = vr.length; x < 9; x++) {
		zeros += "0";
	}

	window.document.forms["form1"].elements[strNMCampo].value = zeros + vr.substr(0, vr.length - 1) + '-' + vr.substr(vr.length - 1, 1);
}

/* CONFIRMA EXCLUSAO COM A PERGUNTA: 'Deseja realmente excluir?' */
function pergunta(frase){
	var resposta = window.confirm(frase);
        if(resposta)
			return true;
        else
			return false;
}

/* VALIDA NUMERO INTEIRO COM MASCARA */
function mascaraInteiro(){
    if (event.keyCode < 48 || event.keyCode > 57){
        event.returnValue = false;
        return false;
    }
    return true;
}

/* FORMATA CAMPO DE FORMA GENERICA - 01 */
function FormataCampo(strNMCampo, formato, intOnFocus, nomeForm){

	var strNull = '';

	if (intOnFocus == 1) {
		if (window.document.forms[nomeForm].elements[strNMCampo].value + '' == formato) {
			window.document.forms[nomeForm].elements[strNMCampo].value = '';
		}
	}

	if (intOnFocus == 0) {
		if (window.document.forms[nomeForm].elements[strNMCampo].value + '' == '') {
			window.document.forms[nomeForm].elements[strNMCampo].value = formato;
		}
	}

}

/* FORMATA CAMPO DE FORMA GENERICA - 02 */
function formataCampo(campo, Mascara, evento){
    var boleanoMascara;

    var Digitato = evento.keyCode;
    exp = /\-|\.|\/|\(|\)| /g
    campoSoNumeros = campo.value.toString().replace( exp, "" );

    var posicaoCampo = 0;
    var NovoValorCampo="";
    var TamanhoMascara = campoSoNumeros.length;;

    if (Digitato != 8) { // backspace
        for(i=0; i<= TamanhoMascara; i++) {
            boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
                                || (Mascara.charAt(i) == "/"))
            boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(")
                                || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " "))
            if (boleanoMascara) {
                NovoValorCampo += Mascara.charAt(i);
                  TamanhoMascara++;
            }else {
                NovoValorCampo += campoSoNumeros.charAt(posicaoCampo);
                posicaoCampo++;
              }
          }
        campo.value = NovoValorCampo;
          return true;
    }else {
        return true;
    }
}








