/*------------------------+
| TRIM                    |
+------------------------*/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); }    
String.prototype.ltrim = function() { return this.replace(/^\s+/, ""); }
String.prototype.rtrim = function() { return this.replace(/\s+$/, ""); }

/*---------------------+
| LPAD                 |
+---------------------*/
function padLeft(s,len,c){
  c=c || "0";
  while(s.length< len) s= c+s;
  return s;
}

/*-------------------------+
| Somente Números          |
+-------------------------*/
function num(dom){       
  dom.value=dom.value.replace(/\D/g,"");
}
//Sintaxe HTML: onkeyup="num(this);"

//Interface HTML JQUERY ----------------------------
function fun_html(p_url, p_par, p_div){
  $(document).ready(function(){
    $.ajax({ type: "POST",
      dataType: "html",
	  cache: false,
	  url: p_url,
	  data: p_par,
	  beforeSend: function(){
        $("#"+p_div).html("<img src='images/carregando.gif' />");
      },
      success: function(resp){
        document.getElementById(p_div).innerHTML = resp;
        //$("#"+p_div).html(resp);
        fun_pos_html(p_url, p_div);
      },
      error: function (xhr, ajaxOptions, thrownError){
        $("#"+p_div).html(xhr.statusText);
	  }
    });
  });
}

//Interface XML JQUERY -----------------------------
function fun_xml(p_url, p_par){ 
  $(document).ready(function(){ 
    $.ajax({ type: "POST", 
      dataType: "html", 
      cache: false, 
      url: p_url, 
      data: p_par,
      beforeSend: function(){
        if (p_url == "acesso_admin.php"){
          $("#div_msg").html("<img src='images/carregando.gif' />");
        }
      },
      success: function(html){
        if (html.indexOf("<dados>") == -1 || html.indexOf("<dados>") > 0){
          if (p_url == "acesso_admin.php"){
            $("#div_msg").html(html);
          } else {
            alert(html);
            return false;
          }
        } 
        fun_xml_pos(html, p_url); 
      }, 
      error: function (xhr, ajaxOptions, thrownError){ 
        alert(xhr.statusText + xhr.responseText); 
      } 
    }); 
  }); 
} // ----------------------------------------------

//Componente XML -------------------------------------------------------
/*------------------------------------+
| Conversao Doc. String para Doc. XML |
| Type: XML (Doc.String to DOc.XML)   |
+------------------------------------*/
jQuery.createXMLDocument = function(string){
 var browserName = navigator.appName;
 var doc;
 if (browserName == "Microsoft Internet Explorer"){
   doc = new ActiveXObject("Microsoft.XMLDOM");
   doc.async = "false"
   doc.loadXML(string);
 } else {
   doc = (new DOMParser()).parseFromString(string, "text/xml");
 }
 return doc;
} // --------------------------------------------------------------------

//Valida CNPJ -------------------------------------------------------
function fun_valida_cnpj(cnpj){
  var a = [];
  var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
  var dig_1 = new Number;
  var dig_2 = new Number;
            
  for(i=0;i<14;i++){
    a[i] = cnpj.charAt(i);
    if(i < 12){ dig_1 += a[i] * c[i+1]; }
    if(i < 13){ dig_2 += a[i] * c[i]; }
    }
    if ((dig_1 % 11) < 2) { dig_1 = 0; } else { dig_1 = 11 - (dig_1 % 11); } 
    if ((dig_2 % 11) < 2) { dig_2 = 0; } else { dig_2 = 11 - (dig_2 % 11); } 
            
    if (dig_1 != a[12]){ 
      v_ret = false; 
    } else {
      if(dig_2 != a[13]){
        v_ret = false; 
      } else {
        v_ret = true;
      }
    }
    return(v_ret);
  }

//Verifica Enter ---------------------------------------
function OnEnter(evt){
  var key_code = evt.keyCode  ? evt.keyCode  :
                 evt.charCode ? evt.charCode :
                 evt.which    ? evt.which    : void 0;


  if (key_code == 13){
    return true;
  }
}// ---------------------------------------------------

//Envia Formulário ------------------------------------
function EnviaFormulario(e, func){
  if(OnEnter(e)){
    eval(func);
    return false;
  } else {
    return true;
  }
}// --------------------------------------------------

function checkMail(mail){
  var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
  if(typeof(mail) == "string"){
    if(er.test(mail)){ return true; }
  }else if(typeof(mail) == "object"){
    if(er.test(mail.value)){ 
      return true; 
    }
  }else{
    return false;
  }
}

$(document).ready(function(){
  $("#banner_2").css('display', 'block');
  $("#banner_3").css('display', 'block');
  $("#banner_4").css('display', 'block');
  $("#banner_5").css('display', 'block');
  $("#banner_6").css('display', 'block');
});

