var Ajax = false;
var contador = 0;
var fila=[];
var ifila=0;

function AjaxRequest() {
	Ajax = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
    	Ajax = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        try {
        	Ajax = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            	Ajax = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }		
}

function adicionar_fila(funcao_js){
    fila[fila.length]=[funcao_js];
    if ((ifila+1)==fila.length)ajaxRun();
}

function ajaxRun(){
	var execString = fila[ifila][0];
	setTimeout(execString, 2);
}

function proxima_funcao() {
    if (ifila<fila.length) {
		ifila++;
    	if(ifila<fila.length)setTimeout("ajaxRun()",2);
	}
}

function mostrar_div(div) {
	var d = document.getElementById(div);
	d.style.display = '';
}

function ocultar_div(div) {
	var d = document.getElementById(div);
	d.style.display = 'none';
}

function div_texto(div, texto) {
	var d = document.getElementById(div);
	d.innerHTML = texto;
}

function node_texto(node, def) {
	if (node[0].firstChild) {
		return node[0].firstChild.nodeValue;		
	} else {
		return def;
	}
	
}

function texto_preco(txt) {
	if (txt=='0') {
		return 'consulte';		
	} else {
		return 'R$ ' + txt;
	}
	
}

function trocar_swf(arquivo) {
	var d = document.getElementById('div_swf');
	var texto = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
		'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="547" height="126"> '+
		'      <param name="movie" value="imgs/swf/' + arquivo + '">'+
		'      <param name="quality" value="high">'+
		'      <embed src="imgs/swf/' + arquivo + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="547" height="126"></embed>';
	d.innerHTML = texto;
}

// -------------

   function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

   function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }



// -------------

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

// url_encode version 1.0  
function url_encode(str) {  
        var hex_chars = "0123456789ABCDEF";  
        var noEncode = /^([a-zA-Z0-9\_\-\.])$/;  
        var n, strCode, hex1, hex2, strEncode = "";  

        for(n = 0; n < str.length; n++) {  
            if (noEncode.test(str.charAt(n))) {  
                strEncode += str.charAt(n);  
            } else {  
                strCode = str.charCodeAt(n);  
                hex1 = hex_chars.charAt(Math.floor(strCode / 16));  
                hex2 = hex_chars.charAt(strCode % 16);  
                strEncode += "%" + (hex1 + hex2);  
            }  
        }  
        return strEncode;  
}  


// url_decode version 1.0  
function url_decode(str) {  
        var n, strCode, strDecode = "";  

        for (n = 0; n < str.length; n++) {  
            if (str.charAt(n) == "%") {  
                strCode = str.charAt(n + 1) + str.charAt(n + 2);  
                strDecode += String.fromCharCode(parseInt(strCode, 16));  
                n += 2;  
            } else {  
                strDecode += str.charAt(n);  
            }  
        }  

        return strDecode;  
} 
