
document.getById = function(strId) {
    if (document.getElementById)
        return document.getElementById(strId);
    else if (document.all)
        return document.all[strId];
    else if (document[strId])
        return document[strId];
    else if (document.layers && document.layers[strId])
        return document.layers[strId];
}

if (String && String.prototype) {
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, "");
    }
}

function Cookies() {
    var arrCookies = new Object();
    if (document.cookie && document.cookie.length != 0) {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; ++i) {
            var arrCookie = cookies[i].split('=');
            if (arrCookie.length != 2)
                continue;
            arrCookies[unescape(arrCookie[0]).trim()] = unescape(arrCookie[1]).trim();
        }
    }

    this.getCookie = function(strName) {
        return arrCookies[strName];
    }

    this.setCookie = function(strName, strValue, expDate) {
        var strCookie = escape(strName) + "=" + escape(strValue) + ";";
        if (expDate)
            strCookie += "expires=" + expDate.toGMTString() + ";";
        strCookie += "path=/";
        document.cookie = strCookie;
        arrCookies[strName] = strValue;
    }

    this.deleteCookie = function(strName) {
        var oDate = new Date();
        oDate.setDate(oDate.getDate() - 1);
        document.cookie = escape(strName) + "=; expires=" + oDate.toGMTString() +
            "; path=/";
        arrCookies[strName] = null;
    }
}

document.cookies = new Cookies();

function setContentSize(iCont) {
    var iSize = 12;
    switch (iCont) {
        case 1:
            iSize = 10;
            break;
        case 2:
            iSize = 12;
            break;
        case 3:
            iSize = 14;
            break;
        case 4:
            iSize = 16;
            break;
    }

    var oContent = document.getById("page_content");
    if (oContent) {
        oContent.style.fontSize = iSize + "px";
        var expDate = new Date();
        expDate.setFullYear(expDate.getFullYear() + 1);
        document.cookies.setCookie("ContentSize", iCont, expDate);
    }
}

function showHideSection(secId) {
    var oSection = document.getById(secId);
    if (oSection) {
        oSection.style.display = (oSection.style.display == "none") ? "block" : "none";
    }
}

function jumpTo(url) {
    if (url.trim().length == 0)
        return;
    if ((url.indexOf('.cattle.ca') != -1 && url.indexOf("qsh/qsh") == -1)) {
        location.href = url;
    }
    else {
        window.open(url, "_blank");
    }
}

window.onload = function(){
	var sCookie = document.cookies.getCookie("ContentSize");
	if(sCookie){
		try{
			var iSize = parseInt(sCookie);
			setContentSize(iSize);
		}catch(e){}
	}
	if(window.initNewsTimer){
		initNewsTimer();
	}
	if(window.Shadowbox){
		Shadowbox.init();
	}
}
