// JavaScript Document
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}
window.onload = function() {
	externalLinks();
}

function trim(str){
		return str.replace(/^\s+|\s+$/g,"");
}

function chkNews(){
	var aux = document.getElementById("formNews")
//	aux.target = "Auxiliar";
	
	if (trim(aux.nome.value) == ""){
		alert("Por Favor Coloque Seu Nome.");
		aux.nome.focus();
		aux.nome.select();
		return;
	}
	if (aux.email.value == ""){
		alert("Por Favor Coloque Seu E-mail.");
		aux.email.focus();
		return;
	}
	if (aux.email.value.indexOf('@', 0) == -1){
		alert("Por Favor Coloque Seu E-mail Corretamente.");
		aux.email.focus();
		return;
	}
	aux.submit();
}

function chkContato(){
	var aux = document.getElementById("formContato")
//	aux.target = "Auxiliar";
	
	if (trim(aux.nome.value) == ""){
		alert("Por Favor Coloque Seu Nome.");
		aux.nome.focus();
		aux.nome.select();
		return;
	}
	if (aux.email.value == ""){
		alert("Por Favor Coloque Seu E-mail.");
		aux.email.focus();
		return;
	}
	if (aux.email.value.indexOf('@', 0) == -1){
		alert("Por Favor Coloque Seu E-mail Corretamente.");
		aux.email.focus();
		return;
	}
	if (aux.mensagem.value == ""){
		alert("Por Favor Escreva uma Mensagem.");
		aux.mensagem.focus();
		return;
	}
	aux.submit();
}

//MASCARA DE VALORES

function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

/*if (objeto.value.length == objeto.getAttribute('maxlength')){
	alert("Entrou");
	alert(objeto.tabIndex);
	var auxCampo = document.forms[0].element[objeto.tabIndex];
	alert(auxCampo.value);		
}*/

if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} 
else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
	} 
else if(document.getElementById) { // FireFox
nTecla = evtKeyPress.which;
	} 
else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatao que
    // j estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }
	
    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas nmeros...
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { // qualquer caracter...
        return true;
      } 
    }
    else {
      return true;
    }
	alert(objeto.maxlength);
  }
function validateKey (bloqCtrl)   
    {
        if (bloqCtrl.keyCode == '17')  
         {  
            alert(unescape("Fun%e7%e3o Desabilitada Nesse Campo!"));  
             return false  
         }  
         return true  
    }  

function btDireito(bloquear) 
{
	if (bloquear.button==2||bloquear.button==3)
	{	
		bloqMouse();
		alert(unescape("Fun%e7%e3o Desabilitada Nesse Campo!"));
		liberaMouse();
	}
}  

function bloqMouse(){
	document.oncontextmenu = new Function("return false;")
}

function liberaMouse(){
	document.oncontextmenu = new Function("return true;")
}

function ObjAjax(){
  try{return new XMLHttpRequest()}
  catch(e){try{return new ActiveXObject("Msxml2.XMLHTTP")}
  catch(e){return new ActiveXObject("Microsoft.XMLHTTP")}}
  return null;
}

function ChamaGoogleMaps(page){
  ajax = new ObjAjax();
  var div = document.getElementById("div_google_maps");

  ajax.onreadystatechange = function(){
    if(ajax.readyState == 1){div.innerHTML="Carregando...";}
    if(ajax.readyState == 4){div.innerHTML=ajax.responseText;}

  }
  ajax.open("GET",page,true);
  ajax.send(null);
}