PlayInterval = 4000;


/* addDOMLoadEvent
 *
 * (c)2006 Jesse Skinner/Dean Edwards/Matthias Miller/John Resig
 * http://www.thefutureoftheweb.com/blog/adddomloadevent
 *
 * Usage: call addDOMLoadEvent one or more times with functions, ie:
 *
 *    function something() {
 *       // do something
 *    }
 *    addDOMLoadEvent(something);
 *
 */
addDOMLoadEvent=(function(){var e=[],t,s,n,i,o,d=document,w=window,r='readyState',c='onreadystatechange',x=function(){n=1;clearInterval(t);while(i=e.shift())i();if(s)s[c]=''};return function(f){if(n)return f();if(!e[0]){d.addEventListener&&d.addEventListener("DOMContentLoaded",x,false);/*@cc_on@*//*@if(@_win32)d.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");s=d.getElementById("__ie_onload");s[c]=function(){s[r]=="complete"&&x()};/*@end@*/if(/WebKit/i.test(navigator.userAgent))t=setInterval(function(){/loaded|complete/.test(d[r])&&x()},10);o=w.onload;w.onload=function(){x();o&&o()}}e.push(f)}})();


function init() {
	document.body.className += ' jsEnabled';	
	if (document.body.className.indexOf('home') != -1){

		links = document.getElementsBySelector('#faderLinks a');
		for (var i=1, t=links.length; i<t; i++){
			links[i].style.visibility = 'hidden';
		}
		
		addEvent(document.getElementById("faderNext"), "click", fadeNext);
		addEvent(document.getElementById("faderPrev"), "click", fadePrev);		
		addEvent(document.getElementById("fader"), "mouseover", pause);		
		addEvent(document.getElementById("fader"), "mouseout", play);		

		play();
	}
}
addDOMLoadEvent(init);
addDOMLoadEvent(initRollovers);

var timer, currentItem=0, prevItem;


function fadeTo(e,next){

	prevItem = currentItem;
	currentItem = currentItem + next;
	if (currentItem == links.length){currentItem = 0;}
	if (currentItem < 0) {currentItem = links.length-1;}

	// Fadomatic(element, rate, initialOpacity, minOpacity, maxOpacity);
	var enterFade = new Fadomatic(links[currentItem], 5, 0);
	enterFade.fadeIn();

	var exitFade = new Fadomatic(links[prevItem], 5, 100);
	exitFade.fadeOut();	
	/*links[prevItem].style.visibility = 'hidden';*/


	if (e){e.preventDefault();}
}

function fadeNext(e){
	fadeTo(e,1)
}
function fadePrev(e){
	fadeTo(e,-1)	
}

function play(){
	timer = setInterval("fadeNext()", PlayInterval)
}
function pause(){
	timer = clearInterval(timer);
}


function initRollovers(){
	var links = document.getElementsBySelector('a.rollover');
	var tmpImg = [];

	for (var i=0, t=links.length; i<t ;i++){
		var img = links[i].getElementsByTagName('img')[0];

		addEvent(links[i], 'focus', rollOver); /* FIX apply for all links not just images */
		addEvent(links[i], 'blur', rollOut);			

		if (img){
			// Assign over and out events
			addEvent(links[i], 'mouseover', rollOver);
			addEvent(links[i], 'mouseout', rollOut);
			
			// Preload images
			tmpImg[i] = new Image(img.width, img.height);
			tmpImg[i].setAttribute('src', getImg(img, 'over'));
	
			// Where a link has class="selected", apply image with the same name and  "_selected" suffix		
			if (links[i].className.indexOf('selected') != -1){
				img.setAttribute('src', getImg(img, 'selected'));
			}	
		}
	}	
}


function rollOver(e){ 
	if (this.className.indexOf('selected') == -1){
		this.className += ' selected'; 
		var img = this.getElementsByTagName('img')[0];
		if (img){img.src = getImg(img, 'over');}
	}
}

function rollOut(e){
	el = this;
	el.className = el.className.replace('selected','');

	var img = el.getElementsByTagName('img')[0];	
	if (img){
		if (!linkHasBodyId(el.id) && el.className.indexOf('selected') == -1){
			var imgNormal = img.getAttribute('src').replace('_over.','.')
		} else {
			var imgNormal = img.getAttribute('src').replace('_over.','_selected.')	
		}
		img.src = imgNormal;
	}
}

function getImg(img, status){
	return img.getAttribute('src').replace(/(_over|_selected)?.(gif|jpg|png)/ig, '_' + status + '.$2')	
}

function linkHasBodyId(linkId){
	if (!linkId){return false;}
	bodyId = document.getElementsByTagName("BODY")[0].id;
	linkSection = linkId.split("_");
	if (linkSection.length == 2){linkSection = linkSection[1];} else {linkSection = false;}
	return (linkSection && linkSection == bodyId);
}


// clean css expressions before printing 
// ref http://www.css-discuss.org/mailman/private/css-d/2004-February/020391.html
/* FIX test!!! function window.onbeforeprint() { */

window.onbeforeprint = function(){			

	el = document.getElementById("siteContainer"); 
	el.style.setExpression("width","'auto'");	
	
	el = document.getElementById("siteContainer"); 
	el.style.setExpression("position","'static'");
	
	if (navigator.userAgent.indexOf("IE 5")!=-1){ // only ie5 requires this one
		el = document.getElementById("mainContent");	
		el.style.setExpression("margin-left","'0px'");				
	}

	var para = document.getElementsByTagName("P");					
	for (p=0;para[p];p++){
		el = para[p];
		el.style.setExpression("margin-right","'0'");		
	}	
	document.recalc();
};

window.onafterprint = function(){
	document.location.reload(); 
};










var iframe;

function newPopUp(eventSrc, finalWidth, finalHeight, duration, steps, considerScroll, startPlace, topStart, leftStart, topEnd, leftEnd){
	if (s>0) {
		closeIFrame(); 

	}
	
	pp = initPopUpDiv(eventSrc, finalWidth, finalHeight, duration, steps, considerScroll, startPlace, topStart, leftStart, topEnd, leftEnd);
	
	// HANDLE FORMS	
	if ((eventSrc.tagName == "INPUT") || (eventSrc.tagName == "BUTTON") || (eventSrc.tagName == "FORM")) { 
		while (eventSrc.tagName!="FORM")	{ 
			eventSrc=eventSrc.parentNode;
		}

		pp.targetLink = eventSrc.action;
		pp.targetData = buildQueryString(eventSrc.id);
	
	} 
	// HANDLE LINKS 
	else {
		pp.targetLink = eventSrc.href;
		pp.targetData = "";
	}
	

	if (!pp.iframe){
		pp.iframe = createIframe(pp.div.id, pp.finalWidth, pp.finalHeight); // target parent element, width, height
	}
	pp.iframe.doc.location.replace(pp.targetLink + pp.targetData);
	return false;
}	









function handleIframeLoad(){ // loaded iframe must call this funk 
		parent.document.getElementById("popUp").style.display = "block";
		parent.document.getElementById("popUp").style.visibility = 'visible';
		popUpDiv("popUp");
}


function closeIFrame(){
		document.getElementById("funkIframe").style.display = "none";
		document.getElementById("popUp").style.display = "none";
		IFrameObj = null;
		s=0;
		return false;
}



function initPopUpDiv(eventSrc, finalWidth, finalHeight, duration, steps, considerScroll, startPlace, topStart, leftStart, topEnd, leftEnd){
	// some defaults
	
	// Size
	this.finalWidth = finalWidth || 330;
	this.finalHeight = finalHeight || 350;

	// Animation
	this.duration = duration || 100;
	this.steps = steps || 8;

	// steps cannot be larger than (smallest size / 2)
	if (this.steps > ( (this.finalWidth /2) || this.finalHeight /2)){
		if (this.finalWidth < this.finalHeight){
			this.steps = this.finalWidth /2;
		} else {
			this.steps = this.finalHeight /2;	
		}	
	}

	this.considerScroll = considerScroll || true;
	if (startPlace == "sourceEl") {
		var elPos = getPos(eventSrc);
		this.topStart = elPos.top;
		this.leftStart = elPos.left+10;
	} else if (startPlace == "custom") {
		this.topStart = topStart;
		this.leftStart = leftStart;
	} 

	var client = getClientSize();
	var cliendMidX = client.width / 2;
	var cliendMidY = client.height / 2;

	if (!topStart && !startPlace){
		this.topStart = cliendMidY;
		this.leftStart = cliendMidX;
		var topStartWasUndefined = true ;
	}
	if (!topEnd){
		this.topEnd = cliendMidY;
		this.leftEnd = cliendMidX;
	}	

	var currentScroll = getScroll();
	if (this.considerScroll && topStartWasUndefined){
		this.topStart += currentScroll.top;
		this.leftStart += currentScroll.left;
	}
	if (this.considerScroll){
		this.topEnd += currentScroll.top;
		this.leftEnd += currentScroll.left;
	}

	this.stepMoveY = (this.topEnd - this.topStart) / this.steps;
	this.stepMoveX = (this.leftEnd - this.leftStart) / this.steps;

	this.stepDuration = this.duration / this.steps;
	this.stepWidth = this.finalWidth / this.steps;
	this.stepHeight = this.finalHeight / this.steps;

	// CREATE THE CONTAINING DIV	
	var XHTMLNS = "http://www.w3.org/1999/xhtml";
    // add namespace methods to HTML DOM; this makes the script work in both HTML and XML contexts.
    if(!document.createElementNS) {
        document.createElementNS = function(ns,elt) {
            return document.createElement(elt);
        };
    }
	
	this.popId = "popUp";
	if (!document.getElementById(this.popId)) {
		this.div = document.createElementNS(XHTMLNS,"div");
		div.id = this.popId;
		document.getElementsByTagName("BODY")[0].appendChild(div);	
	} else {
		this.div = document.getElementById(this.popId);
	}

	// CONFIG DIV
	div.style.top = this.topStart + "px";
	div.style.left = this.leftStart + "px";


	/* set required properties */
	div.style.display = 'block'; 
	div.style.visibility = 'hidden';
	div.style.overflow = 'hidden';	
	div.style.position = 'absolute';
	div.style.width = 0 + "px";
	div.style.height = 0 + "px";

	return this;
}


var s=0;
var pp;
function popUpDiv(divId){
	/*if (s===0){
		pp = initPopUpDiv(divId);
	} */
	if (pp){
		pp.div.style.width 	=  parseInt(pp.div.style.width.substring(0,pp.div.style.width.length-2)) + pp.stepWidth + "px";
		pp.div.style.height	= parseInt(pp.div.style.height.substring(0,pp.div.style.height.length-2)) + pp.stepHeight + "px";
		pp.div.style.left	= (parseInt(pp.div.style.left.substring(0,pp.div.style.left.length-2)) - pp.stepWidth/2) + pp.stepMoveX + "px";
		pp.div.style.top 	= (parseInt(pp.div.style.top.substring(0,pp.div.style.top.length-2)) - pp.stepHeight/2) + pp.stepMoveY + "px";

		if (s < pp.steps-1){
			var move = setTimeout('popUpDiv()',parseInt(pp.stepDuration));
			s++;
		} else {
			document.getElementById("funkIframe").style.display = "block";
			pp = null;			
		}
	}
	return false;
}




/**************************** 
FIND POSITION OF AN HTML ELEMENT
basado en http://www.xs4all.nl/~ppk/js/findpos.html
****************************/
function getPos(obj){
	var curleft = 0, curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;			
			obj = obj.offsetParent;
		}
	}
	return {	top: curtop,
				left: curleft };
}

/*****************************
get size of the browser canvas
ref: http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=16
*****************************/
function getClientSize() {  
	var myWidth = 0, myHeight = 0;
	if (typeof(window.innerWidth) == 'number') { //NS
    	myWidth = window.innerWidth;
	    myHeight = window.innerHeight;	
	} else {
	    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
		}
	}
	return {	width: myWidth,
				height: myHeight };
}

function getScroll() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else {
		if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
		} else {
			if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}
		}
	}
	return { 	top: scrOfY,
  				left: scrOfX };		
}


/* IFRAME ************************
	iframe ref	COSTELLO@APPLE:	http://developer.apple.com/internet/javascript/iframe.html 
				COSTELLO: http://glish.com/articles/apple/rs_with_iframe.html
******************************* */
var IFrameObj;

function createIframe(parentElm, alertWidth, alertHeight){	
	alertHeight = 500; // FIX !!!iframe object is not being reinitiated, try newsletter then amigo w/o this
	if (!IFrameObj) {
		var parentEl = document.getElementById(parentElm);	
		var IFrameDoc;
		try {
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id','funkIframe');
			tempIFrame.setAttribute('name','funkIframe');
			tempIFrame.setAttribute('frameborder','0');
			tempIFrame.style.border='0px';
			tempIFrame.style.width= alertWidth + 'px';
			tempIFrame.style.height= alertHeight + 'px';
			tempIFrame.style.position = 'absolute';
			IFrameObj = parentEl.appendChild(tempIFrame);
			if (document.frames) {
				IFrameObj = document.frames['funkIframe'];
			}
		} catch(exception) { // para IE5Win
			var iframeHTML='\<iframe id="funkIframe" style="';
			iframeHTML+='border:0px none #000000;';
			iframeHTML+='width:' + alertWidth + 'px;';
			iframeHTML+='height:' + alertHeight + 'px;';
			iframeHTML+='"><\/iframe>';
			parentEl.innerHTML+=iframeHTML;
			IFrameObj = new Object();
			IFrameObj.document = new Object();
			IFrameObj.document.location = new Object();
			IFrameObj.document.location.iframe = document.getElementById('funkIframe');
			IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			};
		}
	}
	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
		setTimeout('createIframe()',10); // give NS6 a sec to recognize the new IFrame
		return false;
	}

	if (IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = IFrameObj.contentDocument; 
	} else if (IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		// For IE5
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}
	parentEl.firstChild.frameborder="0";
	return {	doc: IFrameDoc,
	 			obj: IFrameObj };
}

function buildQueryString(theFormName) { 
	var theForm = document.forms[theFormName];
	var qs = '';
	for (var e=0;e<theForm.elements.length;e++) {
		if (theForm.elements[e].name!=='' && !(theForm.elements[e].type=='radio' || theForm.elements[e].type=='checkbox')) {
			qs+=(qs==='')?'?':'&';
			qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value);
		} else if (theForm.elements[e].name!=='' && (theForm.elements[e].type=='radio' || theForm.elements[e].type=='checkbox') && theForm.elements[e].checked === true){
			qs+=(qs==='')?'?':'&';
			qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value);
		}
	}
	return qs;
}



timeOutSecs = 5; // luego de 5 segundos, el botón se habilitará de nuevo, 
					// para el caso de que el servidor deje de responder y el usuario 
					// necesite volver a submitir. 

function validateComments(f){
	error_es = new Array();
	error_en = new Array();
	var err = 0;
	if (f.name.value == ""){
		if (error_es.length == 0){f.name.focus();}
		error_es[err] = "- Debe completar su nombre."
		error_en[err] = "- You must enter your name.";
		err++;
	}
	emailPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/i
	if (!emailPattern.test(f.email.value)){
		if (error_es.length == 0){f.email.focus();}		
		error_es[err] = "- Por favor ingrese correctamente su e-mail."
		error_en[err] = "- Please enter your e-mail correctly.";
		err++;		
	}	
	if (f.country.selectedIndex == 0){
		if (error_es.length == 0){f.country.focus();}		
		error_es[err] = "- Por favor seleccione un país."
		error_en[err] = "- Please choose a country.";
		err++;				
	}
	if (f.comment && f.comment.value == ""){
		if (error_es.length == 0){f.comment.focus();}		
		error_es[err] = "- No ha escrito su comentario."
		error_en[err] = "- You haven't typed your comment.";
		err++;				
	}
	if (f.captcha && f.captcha.value == ""){

		if (error_es.length == 0){f.captcha.focus();}		
		error_es[err] = "- Por favor ingrese el número de confirmación."
		error_en[err] = "- Please enter the confirmation number.";
		err++;			
	}
	if (error_es.length == 0){
		formEl = f.Submit;
		formEl.disabled = true; // desactivar botón
		document.body.style.cursor = 'wait'; // relojito
		setTimeout(function(){formEl.disabled = false;document.body.style.cursor = 'default';},timeOutSecs*1000)
		return true;
	} else {
		alert(error_es.join("\n") + "\n\n" + error_en.join("\n") )
		return false;
	}
}




// Title: Fadomatic
// Version: 1.2
// Homepage: http://chimpen.com/fadomatic
// Author: Philip McCarthy <fadomatic@chimpen.com>

// Fade interval in milliseconds
// Make this larger if you experience performance issues
Fadomatic.INTERVAL_MILLIS = 50;

// Creates a fader
// element - The element to fade
// speed - The speed to fade at, from 0.0 to 100.0
// initialOpacity (optional, default 100) - element's starting opacity, 0 to 100
// minOpacity (optional, default 0) - element's minimum opacity, 0 to 100
// maxOpacity (optional, default 0) - element's minimum opacity, 0 to 100
function Fadomatic (element, rate, initialOpacity, minOpacity, maxOpacity) {
  this._element = element;
  this._intervalId = null;
  this._rate = rate;
  this._isFadeOut = true;

  // Set initial opacity and bounds
  // NB use 99 instead of 100 to avoid flicker at start of fade
  this._minOpacity = 0;
  this._maxOpacity = 99;
  this._opacity = 99;

  if (typeof minOpacity != 'undefined') {
    if (minOpacity < 0) {
      this._minOpacity = 0;
    } else if (minOpacity > 99) {
      this._minOpacity = 99;
    } else {
      this._minOpacity = minOpacity;
    }
  }

  if (typeof maxOpacity != 'undefined') {
    if (maxOpacity < 0) {
      this._maxOpacity = 0;
    } else if (maxOpacity > 99) {
      this._maxOpacity = 99;
    } else {
      this._maxOpacity = maxOpacity;
    }

    if (this._maxOpacity < this._minOpacity) {
      this._maxOpacity = this._minOpacity;
    }
  }
  
  if (typeof initialOpacity != 'undefined') {
    if (initialOpacity > this._maxOpacity) {
      this._opacity = this._maxOpacity;
    } else if (initialOpacity < this._minOpacity) {
      this._opacity = this._minOpacity;
    } else {
      this._opacity = initialOpacity;
    }
  }

  // See if we're using W3C opacity, MSIE filter, or just
  // toggling visiblity
  if(typeof element.style.opacity != 'undefined') {

    this._updateOpacity = this._updateOpacityW3c;

  } else if(typeof element.style.filter != 'undefined') {

    // If there's not an alpha filter on the element already,
    // add one
    if (element.style.filter.indexOf("alpha") == -1) {

      // Attempt to preserve existing filters
      var existingFilters="";
      if (element.style.filter) {
        existingFilters = element.style.filter+" ";
      }
      element.style.filter = existingFilters+"alpha(opacity="+this._opacity+")";
    }

    this._updateOpacity = this._updateOpacityMSIE;
    
  } else {

    this._updateOpacity = this._updateVisibility;
  }

  this._updateOpacity();

}

// Initiates a fade out
Fadomatic.prototype.fadeOut = function () {
  this._isFadeOut = true;
  this._beginFade();
}

// Initiates a fade in
Fadomatic.prototype.fadeIn = function () {
  this._isFadeOut = false;
  this._beginFade();
}

// Makes the element completely opaque, stops any fade in progress
Fadomatic.prototype.show = function () {
  this.haltFade();
  this._opacity = this._maxOpacity;
  this._updateOpacity();
}

// Makes the element completely transparent, stops any fade in progress
Fadomatic.prototype.hide = function () {
  this.haltFade();
  this._opacity = 0;
  this._updateOpacity();
}

// Halts any fade in progress
Fadomatic.prototype.haltFade = function () {

  clearInterval(this._intervalId);
}

// Resumes a fade where it was halted
Fadomatic.prototype.resumeFade = function () {

  this._beginFade();
}

// Pseudo-private members

Fadomatic.prototype._beginFade = function () {

  this.haltFade();
  var objref = this;
  this._intervalId = setInterval(function() { objref._tickFade(); },Fadomatic.INTERVAL_MILLIS);
}

Fadomatic.prototype._tickFade = function () {

  if (this._isFadeOut) {
    this._opacity -= this._rate;
    if (this._opacity < this._minOpacity) {
      this._opacity = this._minOpacity;
      this.haltFade();
    }
  } else {
    this._opacity += this._rate;
    if (this._opacity > this._maxOpacity ) {
      this._opacity = this._maxOpacity;
      this.haltFade();
    }
  }

  this._updateOpacity();
}

Fadomatic.prototype._updateVisibility = function () {
  
  if (this._opacity > 0) {
    this._element.style.visibility = 'visible';
  } else {
    this._element.style.visibility = 'hidden';
  }
}

Fadomatic.prototype._updateOpacityW3c = function () {
  
  this._element.style.opacity = this._opacity/100;
  this._updateVisibility();
}

Fadomatic.prototype._updateOpacityMSIE = function () {
  
  this._element.filters.alpha.opacity = this._opacity;
  this._updateVisibility();
}

Fadomatic.prototype._updateOpacity = null;





/*
addEvent(element, type, handler)
  ie: addEvent(window, "load", init);
  Includes removeEvent, preventDefault and stopPropagation.
  Source: http://therealcrisp.xs4all.nl/upload/addEvent_dean.html
*/
function addEvent(element, type, handler)
{
	if (element.addEventListener){
		element.addEventListener(type, handler, false);
	}else
	{
		if (!handler.$$guid) {handler.$$guid = addEvent.guid++;}
		if (!element.events) {element.events = {};}
		var handlers = element.events[type];
		if (!handlers)
		{
			handlers = element.events[type] = {};
			if (element['on' + type]){ handlers[0] = element['on' + type];}
			element['on' + type] = handleEvent;
		}
	
		handlers[handler.$$guid] = handler;
	}
}
addEvent.guid = 1;

function removeEvent(element, type, handler)
{
	if (element.removeEventListener){
		element.removeEventListener(type, handler, false);
	}else if (element.events && element.events[type] && handler.$$guid){
		delete element.events[type][handler.$$guid]; }

}

function handleEvent(event)
{
	event = event || fixEvent(window.event);
	var returnValue = true;
	var handlers = this.events[event.type];

	for (var i in handlers)
	{
		if (!Object.prototype[i])
		{
			this.$$handler = handlers[i];
			if (this.$$handler(event) === false){ returnValue = false;}
		}
	}

	if (this.$$handler) {this.$$handler = null;}

	return returnValue;
}

function fixEvent(event)
{
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
}
fixEvent.preventDefault = function()
{
	this.returnValue = false;
}
fixEvent.stopPropagation = function()
{
	this.cancelBubble = true;
}

// This little snippet fixes the problem that the onload attribute on the body-element will overwrite
// previous attached events on the window object for the onload event
if (!window.addEventListener)
{
	document.onreadystatechange = function()
	{
		if (window.onload && window.onload != handleEvent)
		{
			addEvent(window, 'load', window.onload);
			window.onload = handleEvent;
		}
	}
}




/*
document.getElementsBySelector(selector) 
  ie: elements = document.getElementsBySelect('div#main p a.external')
  Source: http://simon.incutio.com/archive/2003/03/25/getElementsBySelector
  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
  var tokens = selector.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();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // 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('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // 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];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }
    // 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;
  }
  return currentContext;
}

/* That revolting regular expression explained 
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
  \---/  \---/\-------------/    \-------/
    |      |         |               |
    |      |         |           The value
    |      |    ~,|,^,$,* or =
    |   Attribute 
   Tag
*/

