var agt = navigator.userAgent.toLowerCase();
var is_ie = (agt.indexOf('msie') != -1);
var is_ie5 = (agt.indexOf('msie 5') != -1);

function CreateXmlHttpReq(handler) {
	var xmlhttp = null;
	if (is_ie) {
		var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
		try {
			xmlhttp = new ActiveXObject(control);
			xmlhttp.onreadystatechange = handler;
		} catch(e) {
			alert("You need to enable active scripting and activeX controls");
		}
	} else {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onload = handler;
		xmlhttp.onerror = handler;
	}
		return xmlhttp;
}
function DummyHandler() { }
var uniqnum_counter = (new Date).getTime();
function XmlHttpGET(xmlhttp, url) {
					xmlhttp.open('GET', url, false);
					xmlhttp.send(null);
		
					return xmlhttp.responseText;
			}
function SendRequest(url) {
		var xmlhttp = CreateXmlHttpReq(DummyHandler);
		++uniqnum_counter;
		return XmlHttpGET(xmlhttp, url /*+ "&rand=" + uniqnum_counter*/);
}
function showHelp() {
  obj = document.getElementById("help"); obj.style.display = "block";
  obj = document.getElementById("show_help"); obj.style.display = "none";
}
function hideHelp(iid) {
  obj = document.getElementById("help"); obj.style.display = "none";
  obj = document.getElementById("show_help"); obj.style.display = "block"; 
  SendRequest("SetInfo.aspx?iid=" + iid);
}

function counterUpdate(txtField, contador, tammax) {
  field = document.getElementById(txtField);
  txt_field = document.getElementById(contador);
  txt_field.innerHTML = field.value.length;
  if(field.value.length >= tammax)
	field.value = field.value.substring(0, tammax);
}


/***********************************************
* Floating Top Bar script- © Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 30 //set x offset of bar in pixels
var startY = 90 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function closebar(){
if (persistclose)
document.cookie="remainclosed=1"
document.getElementById("topbar").style.visibility="hidden"
}

function staticbar(){
	barheight=document.getElementById("topbar").offsetHeight
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id){
		var el=d.getElementById(id);
		if (!persistclose || persistclose && get_cookie("remainclosed")=="")
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : iecompattest().scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("topbar");
	stayTopLeft();
}

function MostraEscondeDiv(id_div)
{
   element = document.getElementById(id_div);	
   if(element.style) 
       element.style['display'] = (element.style['display'] == "none") ? "block" : "none";
}

function EscondeDiv(id_div)
{
   element = document.getElementById(id_div);	
   if(element.style) 
       element.style['display'] = "none";
}

function MostraDiv(id_div)
{
   element = document.getElementById(id_div);	
   if(element.style) 
       element.style['display'] = "block";
}

/*
if (window.addEventListener)
window.addEventListener("load", staticbar, false)
else if (window.attachEvent)
window.attachEvent("onload", staticbar)
else if (document.getElementById)
window.onload=staticbar
*/

/*ACENTUACAO + AJAX*/
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;  
}

