/*--------------------------------------------------------------
* Copyright (c) 2006 TELUS Communications Inc.,
*
* All Rights Reserved.
* This document contains proprietary information that shall be
* distributed or routed only within TELUS, and its authorized
* clients, except with written permission of TELUS.
*
* Description: Default function
*--------------------------------------------------------------*/


///////////////////////////////////////////////////////////////////////////////
// textsize
function SetTextSizeFromCookie()
{
    var size = GetCookie('textsize');
    if(size!=null)
        TextSize(size);
}

function TextSize(name)
{
	var elem;
	if (elem = document.getElementById('textsmall')) {
		elem.className = 'textsmallOff';
	}
	if (elem = document.getElementById('textmedium')) {
		elem.className = 'textmediumOff';
	}
	if (elem = document.getElementById('textbig')) {
		elem.className = 'textbigOff';
	}

    if(name!='big' && name!='medium') { name = 'small'; }

    if (elem = document.getElementById('text' + name)) {
    	elem.className = 'text' +  name + 'On';
	}
    if (elem = document.getElementById('content')) {
    	elem.className = 'content' + name;
	}
}

function SetTextSize(name)
{
    SetCookie('textsize',name,100);
}

///////////////////////////////////////////////////////////////////////////////
// Go to section
function GoToSection()
{
    if(document.Gotoform.Gotosection.options[document.Gotoform.Gotosection.selectedIndex].value!='')
        alert('Go to : '+document.Gotoform.Gotosection.options[document.Gotoform.Gotosection.selectedIndex].value);
}

///////////////////////////////////////////////////////////////////////////////
// cookie
function SetCookie(name,value,days)
{
    var expires = "";

	if (days)
    {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}

	document.cookie = name+"="+value+expires+"; path=/";
}

function GetCookie(name)
{
	name = name + "=";

	var cookie_array = document.cookie.split(';');
	for(var i=0; i < cookie_array.length; i++)
    {
		var c = cookie_array[i];

		while (c.charAt(0)==' ')
            c = c.substring(1,c.length);

		if (c.indexOf(name) == 0)
            return c.substring(name.length, c.length);
	}

	return null;
}

function DeleteCookie(name)
{
	setCookie(name,"",-1);
}

///////////////////////////////////////////////////////////////////////////////
// utility functions

function $(id) {
	return document.getElementById(id);
}

/**
 * @link http://www.snook.ca/archives/javascript/your_favourite_1/
 */
function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function ShowEsrbGuide(a) {
	var esbr = $('esbr_guide');
	var a_pos = findPos(a);
	esbr.style.display = 'block';
	esbr.style.top = (a_pos[0] + 145) + 'px';
	esbr.style.left = (a_pos[1] - 200) + 'px';
}
function HideEsbrGuide() {
	$('esbr_guide').style.display = 'none';
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

