// FORÃ‡A LINKS A ABRIREM EM UMA NOVA JANELA
//******************************************************************************
// A W3C nÃ£o aceita mais o atributo "target" em links (tag <a>) em doctypes XHTML 1.0 Strict
// A funÃ§Ã£o abaixo faz com que todos os links que possuem rel="externo" no link, abram em outra janela conforme no exemplo abaixo:
// EXEMPLO:
//******************************************************************************
//<a href="index.php" title="Link de Exemplo" rel="externo">

/* Para chamar a funÃ§Ã£o, insira no body  == <script type="text/javascript">createExternalLinks();</script>  */
function createExternalLinks() {
    if(document.getElementsByTagName) {
        var anchors = document.getElementsByTagName('a');
        for(var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if(anchor.getAttribute("href") && anchor.getAttribute('rel')=='externo') { // <-- Ã‰ necessÃ¡rio inserir rel="externo" no link
                anchor.target = '_blank';
                var title = anchor.title + ' (Este link abre uma nova janela)'; // <-- Insere este texto no final do Title do link
                anchor.title = title;
            }
        }

        var anchors = document.getElementsByTagName('area');
        for(var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if(anchor.getAttribute("title") && anchor.getAttribute('title')=='externo') { // <-- Ã‰ necessÃ¡rio inserir rel="externo" no link
                anchor.target = '_blank';
                var title = ' (Este link abre uma nova janela)'; // <-- Insere este texto no final do Title do link
                anchor.title = title;
            }
        }

    }
}

function notPopUp(el)
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
  }
    el.style.width='100%';
    el.style.height=(myHeight-2)+'px';
    el.style.height='100%';


    el.style.display='inline';

}
function notPopUpOF(el)
{
el.style.width='0px';
el.style.height='0px';
el.style.display='none'
}

function SomenteNumero(e)
{
if (window.event) //IE
{
tecla = e.keyCode;
}

else if (e.which) //FF
{
tecla = e.which;
}
//techa==8 é para permitir o backspace funcionar para apagar

if ( (tecla >= 48 && tecla <= 57)||(tecla == 8 ) ) {
return true;
}
else {
return false;
}

}


function dominio() {
    el = $('ext');

    //$('busca_2');//nao
    var radio = 0;
    if($('busca_0').checked)//sim
        radio = 1;

    return 'contratarDominio.php?dominio='+$('dominio').value+'&ext='+el.options[el.selectedIndex].value+"&dono="+radio;
}



function init() {
	createExternalLinks();
}

function titulo(el)
{
    carrega('contratarTitulo.php?titulo='+el.value,'exclusive');

}

function displayAlter(blockNone, id)
{
   $(id).style.display =  blockNone;
}

function alterPessoa(atual)
{
   if(atual.value == 1)
   {
        $('CPF_line').style.display='inline';
        $('cada_cpf').value=''

        $('CNPJ_line').style.display='none';
        $('cada_cnpj').value=''
   }

   if(atual.value == 2)
   {
        $('CPF_line').style.display='none';
        $('cada_cpf').value=''

        $('CNPJ_line').style.display='inline';
        $('cada_cnpj').value=''
   }

}

function $() {var e = new Array();for (var i = 0; i < arguments.length; i++) { var E = arguments[i];if (typeof E == 'string'){E = document.getElementById(E);}if (arguments.length == 1){return E;}e.push(E);}return e;}
/*function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}*/



function abas(aba_atual){
//    $('abaInstrucao').className ='contratarAbaTopAbas';
    $('abaTemplate').className ='contratarAbaTopAbas';
    $('abaCores').className ='contratarAbaTopAbas';
    $('abaLogomarca').className ='contratarAbaTopAbas';
    $('abaTitulo').className ='contratarAbaTopAbas';
    $('abaDominio').className ='contratarAbaTopAbas';
    $('abaFormulario').className ='contratarAbaTopAbas';
    $('aba'+aba_atual).className ='contratarAbaTopAbas contratarAbaTopSelect';
}



// formata um campo de CPF
// usar no input: onKeydown="JavaScript:FormataCPF(this,event);"
function MascaraCPF (Campo, teclapres) {
	 var tecla = teclapres.keyCode;
	 var vr = new String(Campo.value);
	 vr = vr.replace(".", "");
	 vr = vr.replace(".", "");
	 vr = vr.replace(".", "");
	 vr = vr.replace(".", "");
	 vr = vr.replace(".", "");
	 vr = vr.replace("-", "");
	 vr = vr.replace("-", "");
	 vr = vr.replace("-", "");
	 vr = vr.replace("-", "");
	 vr = vr.replace("-", "");
	 tam = vr.length + 1;
	 if (tecla != 9 && tecla != 8) {
	  	if(tam > 3 && tam < 5){
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
	  	}
	  if(tam > 6 && tam < 8) {
	   		Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(6, tam);
	  	}
	  if(tam > 9 && tam < 11) {
	   		Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(6, 3) + '-' + vr.substr(9, 11);
	  	}
	 }
}



// Formata um campo de CNPJ
// usar no input: onKeydown="JavaScript:FormataCNPJ(this,event);"
function FormataCNPJ(Campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
	}
}



function formataTelefone(obj) {
	// Verificacao da string geral
	var checkstr = "0123456789() -";
	// Verificacao apenas dos numeros
	var checkstr2 = "0123456789";
	// Variavel temporaria para guardar
	var temp = '';
	// Loop por toda a string para verificar se e' valida e retorna apenas os itens validos
	for (i = 0; i < obj.value.length; i++) {
		if (checkstr.indexOf(obj.value.substr(i, 1)) >= 0) {
			temp = temp + obj.value.substr(i,1);
		}
	}

	// Salva a string valida no campo
	obj.value = temp;

	// Verifica o tamanho para formatar corretamente
	switch (obj.value.length) {
    	case 1:
	        obj.value = "(" + obj.value;
    	    break;
	    case 3:
    	    obj.value = obj.value + ") ";
        	break;
	    case 9:
    	    obj.value = obj.value + "-";
        	break;
	}

	// Limpa a variavel temporaria para fazer a verificacao final de validade, por posicoes
	temp = '';

	// Loop para verificar a validade de cada posicao
	for (i = 0; i < obj.value.length; i++) {
		if (i==0 && obj.value.substr(i, 1) == '(') {
			temp = temp + obj.value.substr(i,1);
		} else if (i==3 && obj.value.substr(i, 1) == ')') {
			temp = temp + obj.value.substr(i,1);
		} else if (i==4 && obj.value.substr(i, 1) == ' ') {
			temp = temp + obj.value.substr(i,1);
		} else if (i==9 && obj.value.substr(i, 1) == '-') {
			temp = temp + obj.value.substr(i,1);
		} else if (i!=3 && i!=4 && i!=9 && checkstr2.indexOf(obj.value.substr(i, 1)) >= 0) {
			temp = temp + obj.value.substr(i,1);
		}
	}

	// Salva no input
	obj.value = temp;
}



function FormataData(Campo, teclapres) {
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;

	if (tecla != 9 && tecla != 8)
 	{
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
		if (tam >= 5)
			Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
	}
}

function load() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
  }
}

function abreJanela(foto)
{
  url = 'http://uniaodasimobiliarias.com.br/passo_2_pop_up.php?img=http://uniaodasimobiliarias.com.br/imagens/templates/'+foto;
  window.open(url ,'l', 'toolbar=0,menubar=0,scrollbars=yes,resizable=0,status=0,location=0,directories=0,copyhistory=0,width=513,height=600')
}


function verifica_cep(CEP)
{
    if(CEP.length == 8 )
    {
        preencheformulario( 'contratarCeps.php?cep='+CEP );
    }
}


// Formata um campo de CNPJ
// usar no input: onKeydown="JavaScript:FormataCNPJ(this,event);"
function DominioLimit(Campo, teclapres){

	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);

	tam = vr.length  + 1 ;
/*
	'esc':27,
	'escape':27,
	'tab':9,
	'space':32,
	'return':13,
	'enter':13,
	'backspace':8,
*/


	if (tam == 26){
		alert('Limite Máximo de 26 caracteres. ');
	}
}