
var previous_window_onload = window.onload;
window.onload = window_onload;

/* add any functions that need to run onload in here */
function window_onload()
{
    set_rollovers();
    set_collapsable();
	 link_language();
    if(typeof(previous_window_onload) == 'function')
		{
			previous_window_onload();
		}

}

/*  set_rollovers
    loops through all images looking for class="ro"
    if found, adds onmouseover and onmouseout events

    // PNG rollovers in Opera 7.5 doesn't seem to work
*/
function set_rollovers()
{
    var path, img;

    if(document.getElementsByTagName)
    {
        var isie = /MSIE ((5\.5)|[6789])/.test(navigator.userAgent) && navigator.platform == "Win32" && !/Opera/.test(navigator.userAgent);
        var els = document.getElementsByTagName("IMG");
        for(var i=0,j=els.length;i<j;i++)
        {
            if(els[i].className == "ro")
            {
                // preload image
                path = els[i].src;
                img = new Image();
                img.src = path.substr(0,path.length-4) + '_o.' + path.substr(path.length-3,3);

                // attach event handlers
                els[i].onmouseover = function()
                {
                    var path;
                    if(isie && /\.png'/i.test(this.runtimeStyle.filter)){
                        path = this.runtimeStyle.filter;
                        path = path.substr(56,path.indexOf("'",56) - 56);
                        this.ofilter = this.runtimeStyle.filter;
                        this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft." +
					        "AlphaImageLoader(src='" + path.substr(0,path.length-4) + '_o.' + path.substr(path.length-3,3) + "',sizingMethod='scale')";
                    }else{
                        path = this.src;
                        this.osrc = path;
                        this.src = path.substr(0,path.length-4) + '_o.' + path.substr(path.length-3,3);
                    }

                };
                els[i].onmouseout = function()
                {
                    if(isie && /\.png'/i.test(this.runtimeStyle.filter)){
                        this.runtimeStyle.filter = this.ofilter;
                    }else{
                        if(this.osrc)this.src = this.osrc;
                    }
                };
            }
        }
    }
}


function toggle()
{
	// toggle sections by looping through arguments
	// check if first argument is an object because Mozilla
	// passes it in by default
	if(arguments.length > 0 && typeof(arguments[0]) != 'object')
	{
		// loop through arguments for toggling
		for(var i=0,j=arguments.length;i<j;i++)
		{
			el = document.getElementById(arguments[i]);
			el.style.display == 'none' ? expand(arguments[i]):collapse(arguments[i]);
		}
	}else{
		// if there are no arguments then toggle the next element
		var el = this.nextSibling;
		// if I've got a text node then grab the next element
		if(el.nodeType == 3) el = el.nextSibling;
		if(el.className == 'section collapsed')
		{
			expand(el);
			this.className='expanded';
		}else{
			collapse(el);
			this.className='collapsed';
		}
	}
}

function expand()
{
		for(var i=0,j=arguments.length;i<j;i++)
		{
			el = arguments[i];
			el.className = 'section expanded';
		}
}

function collapse()
{
		for(var i=0,j=arguments.length;i<j;i++)
		{
			el = arguments[i];
			el.className = 'section collapsed';
		}
}


function set_collapsable()
{
	var el = document.getElementById("faqbox");
	if(el!=null)
	{
		var h = el.getElementsByTagName("H2");
		var img,txt;
		for(var i=0,j=h.length;i<j;i++)
		{
			h[i].style.cursor = 'pointer';
			h[i].onclick = toggle;
			h[i].onmouseover = function()
			{
				this.style.backgroundColor = '#EDEDC9';
			}
			h[i].onmouseout = function()
			{
				this.style.backgroundColor = '#F5F5F5';
			}

		}
		var d = el.getElementsByTagName("DIV");
		for(var i=0,j=d.length;i<j;i++)
		{
			if(d[i].className == "section expanded")
			{
				collapse(d[i]);
			}
		}
	}

}




// DF1.1 :: domFunction
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
// GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html
//******************************************************

function domFunction(f, a)
{
	var n = 0;
	var t = setInterval(function()
	{
		var c = true;
		n++;
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
		{
			c = false;
			if(typeof a == 'object')
			{
				for(var i in a)
				{
					if
					(
						(a[i] == 'id' && document.getElementById(i) == null)
						||
						(a[i] == 'tag' && document.getElementsByTagName(i).length < 1)
					)
					{
						c = true;
						break;
					}
				}
			}
			if(!c) { f(); clearInterval(t); }
		}

		if(n >= 60) clearInterval(t);

	}, 20);
};


// French/English link
//==================================

function link_language(){

	var path = window.location.pathname;
	var linky = document.getElementById('language');

	if ((linky != null) && (path.indexOf('/en/') != -1)) {

		linky.href = window.location.href.replace('/en/', '/fr/');

	}
	
	if ((linky != null) && (path.indexOf('/fr/') != -1)) {

		linky.href = window.location.href.replace('/fr/', '/en/');

	} 

	else {
	
		return null;
	
	}
	

}




// Pop Up Window Script
//==================================


var newWin = null;
function popUp(strURL, strHeight, strWidth) {
	var strOptions="";
	strOptions="status,height="+strHeight+",width="+strWidth;
	
	if (newWin) newWin.close();
	
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();
}

