ModuloIndique = function(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 mudaImagem(codsisupload, legenda) {
	window.scrollBy(0,1000); 
	document.getElementById('produto_img').innerHTML = '<a href="../../lib/upload/preview.php?codsisupload=' + codsisupload + '" rel="lightbox[gal_' + codsisupload + ']" id="imgProduto"><img src="../../lib/upload/preview.php?codsisupload=' + codsisupload + '" width="395" height="260" alt="' + legenda + '" title="' + legenda + '" /></a>';
}

function atualizaFiltro() {
    var params = "";
    
    // TIPO INDUCAO
    $j("input[tipo_chk=tipoindu]:checked").each(function() {
        params += "&codproduto_inducao[]=" + $j(this).val();
    });
    
    // TIPO VEICULO
    $j("input[tipo_chk=tipoveic]:checked").each(function() {
        params += "&codproduto_tipoveiculo[]=" + $j(this).val();
    });
    
    // PRECO
    params += "&minpreco=" + $j("#preco_range").slider("values", 0);
    params += "&maxpreco=" + $j("#preco_range").slider("values", 1);
    
    // ANO
    params += "&minano=" + $j("#ano_range").slider("values", 0);
    params += "&maxano=" + $j("#ano_range").slider("values", 1);
    
    // KM
    params += "&minkm=" + $j("#km_range").slider("values", 0);
    params += "&maxkm=" + $j("#km_range").slider("values", 1);
    
    // POTENCIA
    params += "&minpotencia=" + $j("#potencia_range").slider("values", 0);
    params += "&maxpotencia=" + $j("#potencia_range").slider("values", 1);
    
    if ($j("#q").val() != "Digite a MARCA, ou MODELO, ou algum DETALHE TÉCNICO do veículo que deseja")
        params += "&q=" + $j("#q").val();
    
    params = "?" + params.substr(1);
    
    GTR_AjaxClick('modulos/produto/lisProduto.php' + params,'conteudo');
}

MascaraMoeda = function(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 == 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;
}
