
	/* VALIDATE FUNCTIONS ----------------------------------------------------------------------------------------*/
	function checkfield(obj, regex, required, errmsg){
		//alert(obj.name +  ':' + obj.style.display);
		var result = false;
		//skip not required fields when no value submitted, and if display is not block
		if ((! obj.value && ! required) || (obj.style.display == 'none')) {obj.style.backgroundColor = '{$js_inputscolor_1}'; return true;};//alert('skip this field');
		result = regex.test(obj.value);
		if(result) {
			obj.style.backgroundColor = '#ffffff';
		} else {
			obj.style.backgroundColor = '#ffffcc';
			obj.focus();
			alert(errmsg);
		};
		return result;
	};
	
	function checkselec(obj, errmsg){
		if(obj.value == 'null') {result = false;} else {result = true;};
		if(result) {
			obj.style.backgroundColor = '#ffffff';
		} else {
			obj.style.backgroundColor = '#ffffcc';
			obj.focus();
			alert(errmsg);
		};
		return result;
	};
	/* EOF VALIDATE FUNCTIONS ----------------------------------------------------------------------------------------*/

  //auto;crosshair;default;pointer;move;text;wait;help;e-resize;ne-resize;n-resize;nw-resize;w-resize;sw-resize;s-resize;se-resize;
  //<a href='javascript:void(0);' onClick='cursor_wait()'>cursor_wait</a>
  //<a href='javascript:void(0);' onClick='cursor_clear()'>cursor_clear</a>
  //document.body.style.cursor=(document.body.style.cursor=="wait") ? "default" : "wait";
  function cursor_wait() {
    //document.body.style.cursor = 'wait';
    document.body.style.cursor = "wait";
  };
  
  // Returns the cursor to the default pointer
  function cursor_clear() {
    //document.body.style.cursor = 'default';
    document.body.style.cursor = "default";
  };
  
  function var_dump(obj) {
    if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
    } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
    };
  };

  //used to get tokens
  function queryString( key )
  {
		var re = new RegExp( "[?&]" + key + "=([^&$]*)", "i" );
		var offset = location.search.search( re );
		if ( offset == -1 ) return null;
		return RegExp.$1;
  };
  
  function explode (Input, Delimeter) {
    var myString = new String(Input);
    var myArray = myString.split(Delimeter);
    return myArray;
  };

  function implode (Array, Delimeter) {
    return  Array.join(Delimeter);
  };

	function expand_nav(link)
	{
		var ul = find_enclosing_ul(link)
		if (ul.style.display == 'none' || ul.style.display == '')
		{
			ul.style.display = 'block'
		}
		else
		{
			ul.style.display = 'none'
		}
	};
	
	function find_enclosing_ul(link)
	{
    var search_node = link
		while (true)
		{
			var node = search_node.nextSibling
			if (node && node.nodeName == 'UL')
			{
				break
			}
			else
			{
				search_node = node
			}
		}
    return node	
	};
  
	
	function elem_display ( elem ) {
		if (elem.style.display == 'none') {
			elem.style.display = 'block'
		} else {
			elem.style.display = 'none'
		};
	};
  

	function showTab(branch, button, n, id) {	 /*id is optional, para usar se existirem mais q um tab na mesma pagina e nao ficarem c os mesmos branch names*/
		
		//optional parameters
		if (! id) var id = 'branch';
		
		var objBranch = document.getElementById(branch).style;
		var objButton = document.getElementById(button);
	
		n++;
		for (x=1 ; n>x ; x++) {
			var z = 'link_' + id + x;
			document.getElementById(z).className = 'back';
		};
	
		objButton.className = 'current';
		for (x=1 ; n > x ; x++) {
			var z = id + x;
			document.getElementById(z).style.display = 'none';
		};
		objBranch.display = 'block';
	};

  
  function getBrowserName()
  {
    var lsBrowser = navigator.appName;
    
    if (lsBrowser.indexOf("Microsoft") >= 0)
    {
      lsBrowser = "MSIE";
    }
    else if (lsBrowser.indexOf("Netscape") >= 0)
    {
      lsBrowser = "NETSCAPE";
    }
    else if (lsBrowser.indexOf("Opera") >= 0)
    {
      lsBrowser = "OPERA";
    }
    else if (lsBrowser.indexOf("Konqueror") >= 0)
    {
      lsBrowser = "KONQUEROR";
    }
    else
    {
      lsBrowser = "UNKNOWN";
    }
    return lsBrowser;
  };


  function togglePopupLinks (linknode) {
    
    var BrowserName = getBrowserName();
		
    if (BrowserName == 'MSIE') {
      var div = linknode.nextSibling.nextSibling.nextSibling;
    } else if (BrowserName == 'NETSCAPE') {
      var div = linknode.nextSibling.nextSibling.nextSibling.nextSibling;
    } else if (BrowserName == 'OPERA') {
      var div = linknode.nextSibling.nextSibling.nextSibling.nextSibling;
    } else if (BrowserName == 'KONQUEROR') {
      var div = linknode.nextSibling.nextSibling.nextSibling.nextSibling;
    } else {
      var div = linknode.nextSibling.nextSibling.nextSibling;
    };
    
    if(div.style.display == 'inline') {
      div.style.display = 'none';
    } else {
      div.style.display = 'inline';
    };     
  };

	function butHint(text) {
		elem = document.getElementById("hintbox");
		elem.innerHTML = text;
	};

	function butHintOut() {
		elem = document.getElementById("hintbox");
		elem.innerHTML = '';
	};

  function getid(name) {
    return document.getElementById(name);
  };

  function prev( elem ) {
  do {
    elem = elem.previousSibling;
  } while ( elem && elem.nodeType != 1 );
    return elem;
  };
  

	function next( elem ) {
		do {
			elem = elem.nextSibling;
		} while ( elem && elem.nodeType != 1 );
		return elem;
	};


  function first( elem ) {
    elem = elem.firstChild;
    return elem && elem.nodeType != 1 ? next ( elem ) : elem;
  };
  

  function last( elem ) {
    elem = elem.lastChild;
    return elem && elem.nodeType != 1 ? prev ( elem ) : elem;
  };


  function parent( elem, num ) {
    num = num || 1;
    for ( var i = 0; i < num; i++ )
      if ( elem != null ) elem = elem.parentNode;
    return elem;
  };
  

  // Serialize a set of data. It can take two different types of objects:
  // - An array of input elements.
  // - A hash of key/value pairs
  // The function returns a serialized string
  function serialize(a) {
    // The set of serialize results
    var s = [];
  
    // If an array was passed in, assume that it is an array
    // of form elements
    if ( a.constructor == Array ) {
      // Serialize the form elements
      for ( var i = 0; i < a.length; i++ )
      s.push( a[i].name + "=" + encodeURIComponent( a[i].value ) );
      // Otherwise, assume that it's an object of key/value pairs
    } else {
      // Serialize the key/values
      for ( var j in a )
      s.push( j + "=" + encodeURIComponent( a[j] ) );
    }
    // Return the resulting serialization
    return s.join("&");
  };

  //ajax------------------------------------------------------------------------
  //var http_request = false;

  //http://developer.mozilla.org/en/docs/AJAX:Getting_Started
  function makeRequest(url) {

    http_request = false;
    
    //cursor_wait();
    window.status = 'Requesting Data, Please Wait...';

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
//REMOVED ELSE "junk after document element" appears in firefox
//      if (http_request.overrideMimeType) {
//        http_request.overrideMimeType('text/xml');
//      }
    } else if (window.ActiveXObject) { // IE
      try {
        http_request = new ActiveXObject('Msxml2.XMLHTTP');
      } catch (e) {
        try {
        http_request = new ActiveXObject('Microsoft.XMLHTTP');
        } catch (e) {}
      }
    };

    if (! http_request) {
      alert('Giving up, Cannot create an XMLHTTP instance!');
      return false;
    };
    
    //http_request.onreadystatechange = alert('onreadystatechange');

    http_request.open('POST', url, false);
    //comment gives and error in ff
    http_request.send(null);

    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        //if (http_request.responseText) {
        //  return http_request.responseText; //contains the response text (if no XML document was provided)
        //} else
        //if (http_request.responseXML) {
        //  return http_request.responseXML;  //contains the XML Document (if one was returned)
        //};
        window.status = 'Request Data Done!';
        //cursor_clear();
        return httpData(http_request);
      } else {
        //return 'There was a problem with the request.';
        window.status = 'There was a problem with the request!';
        //cursor_clear();  
        return false;
      };
    };
    return false;
  };

  //Listing 10-10. A Function for Extracting the Correct Data From an HTTP Server Response
  // A function for extracting data from an HTTP reponse
  // It takes two arguments, the XMLHttpRequest object and
  // An optional argument – the type of data that you're expecting from the server
  // Correct values include: xml, script, text, or html – the default is "", which
  // determines what the data type is based upon the content-type header
  function httpData(r, type) {
    // Get the content-type header
    var ct = r.getResponseHeader("content-type");
    // If no default type was provided, determine if some
    // form of XML was returned from the server
    var data = !type && ct && ct.indexOf("xml") >= 0;
    // Get the XML Document object if XML was returned from
    // the server, otherwise return the text contents returned by the server
    data = type == "xml" || data ? r.responseXML : r.responseText;
    // If the specified type is "script", execute the returned text
    // response as if it was JavaScript
    if ( type == "script" )
      eval.call( window, data );
    // Return the response data (either an XML Document or a text string)
    
    return data;
  };
  
  function xmlgetElementValue (res, tagname) {
    var element = res.getElementsByTagName(tagname);
    //alert(tagname);  
    return element[0].firstChild.nodeValue;
  };
