// JavaScript Document
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxx AJAX xxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
createXMLHttpRequest = function() {
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxx RASTREADORES xxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   array $ (string id)
**   Recebe varias ids(strings) e retorna uma array contendo os elementos referentes ao ids passados.
*/
$ = function() {
	var elements = new Array();
	
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		
		if (typeof element == 'string')
			element = document.getElementById(element);
		
		if (arguments.length == 1) 
			return element;
		
		elements.push(element);
	}
	
	return elements;
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   array $(string id)
**   Recebe uma tag(string) e retorna um array contendo os elementos referentes a tag passados.
*/
tag = function() {
	return document.getElementsByTagName(arguments[0]);
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxx STRINGS xxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   string stripTags(string tag)
**   Recebe uma string com tags html e retorna a string sem as tags html.
** Ex.: "<div>Wilton</div>".stripTags() retornará "Wilton";
*/
String.prototype.stripTags = function() {
    return this.replace(/<\/?[^>]+>/gi, '');
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   string trim(string string)
**   Recebe uma string e remove os espaços em branco no inicio e no final.
*/
String.prototype.trim = function() {
   return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   Recebe uma string(classe) e retorna um arrau com todos os elementos que contem aquela classe.
*/
document.getElementsByClassName = function(className) {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = new Array();
	
	for (var i = 0; i < children.length; i++) {
		var child = children[i];
		var classNames = child.className.split(' ');
		
		for (var j = 0; j < classNames.length; j++) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	
	return elements;
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxx EFEITOS xxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   hide(string id)
**   Recebe um id e seta a propriedade diplay do elemeneto para none.
*/
hide = function() {
	for (var i = 0; i < arguments.length; i++) {
		var element = $(arguments[i]);
		element.style.display = 'none';
	}
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
//hide.prototype = new hide;
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   show(string id)
**   Recebe um id e seta a propriedade diplay do elemeneto para block.
*/
show = function() {
	for (var i = 0; i < arguments.length; i++) {
		var element = $(arguments[i]);
		element.style.display = 'block';
	}
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   toggle(string id)
**   Recebe varios ids e inverte a propriedade diplay de todos os elemenetos.
*/
toggle = function() {
	for (var i = 0; i < arguments.length; i++) {
		var element = $(arguments[i]);
		element.style.display = (element.style.display == 'block' || element.style.display == ' ') ? 'none' : 'block';
	}
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxx FORMULÁRIOS xxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   bool inArray (array haystack, mixed needle)
**   Recebe um array de strings e uma string a ser procurada no array, 
**   retorna true caso encontre e false se a string não for encontrada.
*/
inArray = function () {
	
	var args = inArray.arguments;
	var ids = args[0];
	//alert(ids);
	if(ids.length == 0)
		return false;
		
	for(var i = 0; i < ids.length; i++) {
		if(ids[i] == args[1])
			return true;
	}
	
	return false;
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   Array formSerialize (string formID, array IDs)
**	 Recebe o ID do form e um array de strings contendo os ids dos campos que não podem ser retornados no array final;
**   Retorna uma array com todos os elementos do formulario.
*/
formSerialize = function() {
	
	var args = formSerialize.arguments;
	var elementos = new Array();
	var e = $(args[0]).elements;
	
	for(var i = 0; i < e.length; i++) {
		if(!inArray(args[1],e[i].id))
			elementos.push($(e[i].id));
	}
	
	return elementos;
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   bool isNum ()
**	 Utiliza-se no evento onKeyPress de um campo TEXT capturando o eventKeyCode das teclas pressionadas,
**   se o evento gerado pela tecla pressinada estiver entre os numeros de 0 a 9 retorna true,
**   caso contrario retorna um eventKeyCode = 0
*/
isNum = function(e) {
      return /\d/.test(String.fromCharCode(e.key));
}

/*
*/
isNumber = function() {
	var pattern = new RegExp(/\d/);
	var a = String.fromCharCode(event.keyCode);
	
	if(!pattern.test(a))
		event.keyCode = 0;
	else
		return true;
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   bool isNum ()
**	 Utiliza-se no evento onKeyPress de um campo TEXT capturando o eventKeyCode das teclas pressionadas,
**   se o evento gerado pela tecla pressinada estiver entre os numeros de 0 a 9 retorna true,
**   caso contrario retorna um eventKeyCode = 0
*/
isEmpty = function () {
		
	var args = isEmpty.arguments;
	var retorno = true;
	var id = args[0] ;
	var list = args[1] ;
	//return false;
	//var id = this.id;//isVazio.arguments;
	//var list = this.list;
	//alert(this.id);
	//alert(this.list);
	//alert(Array('0','1','2','3'));
	//var e = formSerialize(this.id,this.list);
	var e = formSerialize(id,list);
	var pattern = new RegExp(/\s+/);
	
	for(var i = 0; i < e.length; i++) {
		
		if(e[i].value == "") {
			alert('O campo '+ e[i].title + ' é de preenchimento obrigatório'+ e[i].id);
			e[i].focus();
			retorno = false;
			break;
		}
	}
	//alert(retorno);
	return retorno;//$(id).submit();/
}

/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   bool isVazio (string formId, )
**   Utilização : no evento onSubmit do formulario.
**	 Verifica se os campos de um formulario estão vasios.
**   Caso algum campo esteja vazio emite um alerta sobre o preenchimento do campo.
**   coloca o foco no campo que está vazio e retorna false ao metodo onSubmit do formulario.
*/
/*
*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxx EVENT LISTENERS xxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
**   addEvent (object o, string e, function f, s(parameters))
**   Ex.: b = $('myId');
**   addEvent (b,'click', myfunction, {myvar: xxx, myvar2:yyy})
*/
/*
addEvent = function(o, e, f, s){
	var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a;
	r[r.length] = [f, s || o], o[e] = function(e){
		try{
			(e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			e.target || (e.target = e.srcElement || null);
			e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		}catch(f){}
		for(f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? a.call(o, e) : (o._ = a, o._(e), o._ = null)));
		e = null;
	}
};
*/
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
removeEvent = function(o, e, f, s){
	for(var i = (e = o["_on" + e] || []).length; i;)
		if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
			return delete e[i];
	return false;
};
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/

/*
   Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
   of Simon Willison (see comments by Simon below).

   Description:
   	
   	Uses css selectors to apply javascript behaviours to enable
   	unobtrusive javascript in html documents.
   	
   Usage:   
   
	var myrules = {
		'b.someclass' : function(element){
			element.onclick = function(){
				alert(this.innerHTML);
			}
		},
		'#someid u' : function(element){
			element.onmouseover = function(){
				this.innerHTML = "BLAH!";
			}
		}
	};
	
	Behaviour.register(myrules);
	
	// Call Behaviour.apply() to re-apply the rules (if you
	// update the dom, etc).

   License:
   
   	This file is entirely BSD licensed.
   	
   More information:
   	
   	http://ripcord.co.nz/behaviour/
   
*/   





var Behaviour = {
	list : new Array,
	
	register : function(sheet){
		Behaviour.list.push(sheet);
	},
	
	start : function(){
		Behaviour.addLoadEvent(function(){
			Behaviour.apply();
		});
	},
	
	apply : function(){
		for (h=0;sheet=Behaviour.list[h];h++){
			for (selector in sheet){
				list = document.getElementsBySelector(selector);

				
				if (!list){
					continue;
				}

				for (i=0;element=list[i];i++){
					sheet[selector](element);
				}
			}
		}
	},
	
	addLoadEvent : function(func){
		var oldonload = window.onload;
		
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
}

Behaviour.start();

/*
   The following code is Copyright (C) Simon Willison 2004.

   document.getElementsBySelector(selector)
   - returns an array of element objects from the current document
     matching the CSS selector. Selectors can contain element names, 
     class names and ids and can be nested. For example:
     
       elements = document.getElementsBySelect('div#main p a.external')
     
     Will return an array of all 'a' elements with 'external' in their 
     class attribute that are contained inside 'p' elements that are 
     contained inside the 'div' element which has id="main"

   New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
   See http://www.w3.org/TR/css3-selectors/#attribute-selectors

   Version 0.4 - Simon Willison, March 25th 2003
   -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
   -- Opera 7 fails 
*/

function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
}

document.getElementsBySelector = function(selector)
{
	// Attempt to fail gracefully in lesser browsers
	if (!document.getElementsByTagName) {
		return new Array();
	}

	// Split selector in to tokens around commas, for Grouped Selectors
	var ungrouped = selector.split(/,/);

	var finalContext = new Array();
	for (var r = 0; r < ungrouped.length; r++)
	{
		// Split selector in to tokens
		var tokens = ungrouped[r].split(/ /);
		var currentContext = new Array(document);

		for (var i = 0; i < tokens.length; i++)
		{
			token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');

			if (token.indexOf('#') > -1)
			{
				// Token is an ID selector
				var bits = token.split('#');
				var tagName = bits[0];
				var id = bits[1];
				var element = document.getElementById(id);
				if (tagName && element.nodeName.toLowerCase() != tagName)
				{
					// tag with that ID not found, return false
					//return new Array();
					currentContext = new Array();
					continue;
				}
				// Set currentContext to contain just this element
				currentContext = new Array(element);
				continue; // Skip to next token
			} // end of id selector

			if (token.indexOf('.') > -1)
			{
				//alert(token);
				// Token contains a class selector
				var bits = token.split('.');
				var tagName = bits[0];
				var className = bits[1];
				if (!tagName)
				{
					tagName = '*';
				}
				// Get elements matching tag, filter them for class selector
				var found = new Array;
				var foundCount = 0;
				for (var h = 0; h < currentContext.length; h++)
				{
					var elements;
					if (tagName == '*') {
						elements = getAllChildren(currentContext[h]);
					} else {
						elements = currentContext[h].getElementsByTagName(tagName);
					}
					for (var j = 0; j < elements.length; j++)
					{
						found[foundCount++] = elements[j];
					}
				}
				currentContext = new Array;
				var currentContextIndex = 0;
				for (var k = 0; k < found.length; k++)
				{
					if (found[k].className && found[k].className.match(new RegExp('(\\s+|^)' + className + '(\\s+|$)') ))
					{
						currentContext[currentContextIndex++] = found[k];
					}
				}
				continue; // Skip to next token
			} // end of class selector

			// Code to deal with attribute selectors
			if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/))
			{
				var tagName = RegExp.$1;
				var attrName = RegExp.$2;
				var attrOperator = RegExp.$3;
				var attrValue = RegExp.$4;
				if (!tagName) {
					tagName = '*';
				}
				// Grab all of the tagName elements within current context
				var found = new Array;
				var foundCount = 0;
				for (var h = 0; h < currentContext.length; h++)
				{
					var elements;
					if (tagName == '*') {
						elements = getAllChildren(currentContext[h]);
					} else {
						elements = currentContext[h].getElementsByTagName(tagName);
					}
					for (var j = 0; j < elements.length; j++)
					{
						found[foundCount++] = elements[j];
					}
				}
				currentContext = new Array;
				var currentContextIndex = 0;
				var checkFunction; // This function will be used to filter the elements
				switch (attrOperator)
				{
					case '=': // Equality
						checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
						break;
					case '~': // Match one of space seperated words 
						checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
						break;
					case '|': // Match start with value followed by optional hyphen
						checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
						break;
					case '^': // Match starts with value
						checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
						break;
					case '$': // Match ends with value - fails with "Warning" in Opera 7
						checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
						break;
					case '*': // Match ends with value
						checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
						break;
					default :
					// Just test for existence of attribute
						checkFunction = function(e) { return e.getAttribute(attrName); };
				}
				currentContext = new Array;
				var currentContextIndex = 0;
				for (var k = 0; k < found.length; k++)
				{
					if (checkFunction(found[k])) {
						currentContext[currentContextIndex++] = found[k];
					}
				}
				continue; // Skip to next token
			} // end of attribute selectors
    
			if (!currentContext[0]){
				//alert('returning');
				return;
			}
    
			// If we get here, token is JUST an element (not a class or ID selector)
			tagName = token;
			var found = new Array;
			var foundCount = 0;
			for (var h = 0; h < currentContext.length; h++)
			{
				var elements = currentContext[h].getElementsByTagName(tagName);
				for (var j = 0; j < elements.length; j++) {
					found[foundCount++] = elements[j];
				}
			}
			currentContext = found;
		} // end of tokens for-loop

		// if there are no tokens, DO NOT add currentContext to finalContext
		if (tokens.length < 1)
			continue;

		//alert("token: " + token + " length: " + currentContext.length);
		// move members of currentContext to finalContext
		while (currentContext.length > 0)
		{
			finalContext.push(currentContext.pop());
		}

	} // ungrouped for-loop

	return finalContext;
}

/* That revolting regular expression explained 
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
  \---/  \---/\-------------/    \-------/
    |      |         |               |
    |      |         |           The value
    |      |    ~,|,^,$,* or =
    |   Attribute 
   Tag
*/