// JavaScript Document
var conteudoGMapas = "";
conteudoGMapas += '<div id="modulo_gmaps">';
conteudoGMapas += '<a class="close" href="javascript: fechaBox();"><img src="modulos/google_maps/img/btn_janela_close.png" style="width:auto; height:auto" /></a>';

conteudoGMapas += '<iframe name="detGoogleMaps" id="detGoogleMaps" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="modulos/google_maps/detGoogleMaps.php" width="480" height="410" style="overflow-x: hidden; margin-bottom:10px;"></iframe>';
conteudoGMapas += '</iframe>';

conteudoGMapas += '<strong class="name">Acásia Consultoria</strong> - ';
conteudoGMapas += '<span class="street">Av. Rio Branco, 1132 - térreo - Ed. Rio Negro Center</span><br />';
conteudoGMapas += '<span class="city_state">CEP 17502-000 - Marília/SP</span><br />';
conteudoGMapas += '<span class="phone">Fone: +55 (14)2105-3333<br />E-mail: acacia@acaciaconsultoria.com.br</span>';

conteudoGMapas += '</div>';

ModuloIndique = function(args)  {
	if (typeof args == 'undefined') args = "";
	args	= escape(args);
	novoBox('modulos/indique/cadIndique.php?pagina=' + args, '', 400, 346);
}

function applySelectedTo(link, abrir) {
	var ul = document.getElementById("sanfona"); // get the first ul tag on the page
	var allLinks = ul.getElementsByTagName("h3"); // get all the links within that ul
	
	for (var i=0; i<allLinks.length; i++) { // iterate through all those links
		allLinks[i].className = ""; // and assign their class names to nothing
		document.getElementById(allLinks[i].lang).style.display='none';
	}
	link.className = "ativo";  // finally, assign class="selected" to our chosen link
	document.getElementById(abrir).style.display='';
}

function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

// Para usar coloque o comando: "javascript:mudaTamanho('tag_ou_id_alvo', -1);" para diminuir
// e o comando "javascript:mudaTamanho('tag_ou_id_alvo', +1);" para aumentar
 
// Especificando os possíveis tamanhos de fontes, poderia ser: x-small, small...
var tamanhos = new Array('100%','120%','130%','140%','150%');
var tamanhoInicial = 0;
 
function mudaTamanho( idAlvo,acao ){
  if (!document.getElementById) return
  var selecionados = null,tamanho = tamanhoInicial,i,j,tagsAlvo;
  tamanho += acao;
  if ( tamanho < 0 ) tamanho = 0;
  if ( tamanho > 4 ) tamanho = 4;
  tamanhoInicial = tamanho;
  if ( !( selecionados = document.getElementById( idAlvo ) ) ) selecionados = document.getElementsByTagName( idAlvo )[ 0 ];
  
	dives	= document.getElementsByTagName('div');
	for (i=0;i<dives.length;i++)  {
		if (dives[i].id==idAlvo)  {
			dives[i].style.fontSize = tamanhos[ tamanho ];
		}
	}
}

function scrollTop()  {
	window.scroll(0,0); 
}

function voltaBack()  {
	history.back();
}

// ----------------------------------------------------------------------------
// HasClassName
//
// Description : returns boolean indicating whether the object has the class name
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function HasClassName(objElement, strClass) {

	// if there is a class
	if ( objElement.className ) {
	
		// the classes are just a space separated list, so first get the list
		var arrList = objElement.className.split(' ');
		
		// get uppercase class for comparison purposes
		var strClassUpper = strClass.toUpperCase();
		
		// find all instances and remove them
		for ( var i = 0; i < arrList.length; i++ ) {		
			// if class found
			if ( arrList[i].toUpperCase() == strClassUpper ) {
				// we found it
				return true;		
			}		
		}
	
	}
	
	// if we got here then the class name is not there
	return false;

}
// 
// HasClassName
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// AddClassName
//
// Description : adds a class to the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function AddClassName(objElement, strClass, blnMayAlreadyExist) {

	// if there is a class
	if ( objElement.className ) {
	
		// the classes are just a space separated list, so first get the list
		var arrList = objElement.className.split(' ');
		
		// if the new class name may already exist in list
		if ( blnMayAlreadyExist ) {
		
			// get uppercase class for comparison purposes
			var strClassUpper = strClass.toUpperCase();
			
			// find all instances and remove them
			for ( var i = 0; i < arrList.length; i++ ) {			
				// if class found
				if ( arrList[i].toUpperCase() == strClassUpper) {				
					// remove array item
					arrList.splice(i, 1);					
					// decrement loop counter as we have adjusted the array's contents
					i--;				
				}			
			}		
		}
		
		// add the new class to end of list
		arrList[arrList.length] = strClass;
		
		// add the new class to beginning of list
		//arrList.splice(0, 0, strClass);
		
		// assign modified class name attribute
		objElement.className = arrList.join(' ');
	
	} else {
		// if there was no class
		
		// assign modified class name attribute      
		objElement.className = strClass;	
	}
}
// 
// AddClassName
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// RemoveClassName
//
// Description : removes a class from the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to remove
//
function RemoveClassName(objElement, strClass) {

	// if there is a class
	if ( objElement.className ) {
	
		// the classes are just a space separated list, so first get the list
		var arrList = objElement.className.split(' ');
		
		// get uppercase class for comparison purposes
		var strClassUpper = strClass.toUpperCase();
		
		// find all instances and remove them
		for ( var i = 0; i < arrList.length; i++ ) {		
			// if class found
			if ( arrList[i].toUpperCase() == strClassUpper ) {		
				// remove array item
				arrList.splice(i, 1);		
				// decrement loop counter as we have adjusted the array's contents
				i--;		
			}		
		}
		
		// assign modified class name attribute
		objElement.className = arrList.join(' ');
	
	}
	// if there was no class
	// there is nothing to remove
}
// 
// RemoveClassName
// ----------------------------------------------------------------------------

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.which) ? e.which : e.keyCode;
    
    if (whichCode == 13) return true;
	if (whichCode == 8) return true;
	if (whichCode == 9) return true;
	if (whichCode == 46) 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 buscaCep(cep) {
	cep = cep.replace("-","");
	gtr_makeRequest_cep("modulos/clientes/buscaCep.php?cep=" + cep,"cep_loading");
}

/* AJAX CONVENCIONAL - BUSCA CEP */
var gtr_http_request	= false;
var gtr_dive			= "";
function gtr_makeRequest_cep(url, div) {
	gtr_dive	= div;
	document.getElementById(gtr_dive).innerHTML = htmlAjaxLoader;
	gtr_http_request = false;
	// document.getElementById('principal').innerHTML = "Carregando...";
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		gtr_http_request = new XMLHttpRequest();
		if (gtr_http_request.overrideMimeType) {
			gtr_http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			gtr_http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				gtr_http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!gtr_http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	var ran_number= Math.random(); 
	if ( url.indexOf("?") < 0 )  {
		url += "?rnd=" + ran_number;
	}
	else  {
		url += "&rnd=" + ran_number;
	}
	gtr_http_request.onreadystatechange = gtr_alertContents_cep;
	gtr_http_request.open('GET', url, true);
	gtr_http_request.send(null);
}

function gtr_alertContents_cep() {

	if (gtr_http_request.readyState == 4) {
		if (gtr_http_request.status == 200) {
			retorno = gtr_http_request.responseText;
			if (retorno == "ERR") {
				alert('Preencha o campo CEP');
				document.getElementById("nn_descep").focus();
			} else if (retorno == "NAO_ENC") {
				document.getElementById("nn_deslogradouro").focus();
			} else {
				retorno = retorno.split("|");				
				document.getElementById("nn_deslogradouro").value = retorno[0];
				document.getElementById("nn_desbairro").value = retorno[1];
				document.getElementById("nn_codestado").value = retorno[2];
				document.getElementById("combo_filho_estado").innerHTML = retorno[3];
				document.getElementById("nn_desnumero").focus();
			}
			document.getElementById(gtr_dive).innerHTML = '';
		} else {
			alert('Não foi possível utilizar o GTRAjax Convencional para trazer esta página.');
		}
	}

}

function maxLength(textAreaField, limit) {
	var ta = document.getElementById(textAreaField);

 	if (ta.value.length >= limit) {
		ta.value = ta.value.substring(0, limit-1);
	}
}

