/*	-------------------------------------------------------------
	function getCookie(), setCookie(), deleteCookie()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Yes, these functions are used for handling
					cookies.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
		
		<!--
		function getCookie(CookieName) {
			var start = document.cookie.indexOf(CookieName + '=');
			var len = start + CookieName.length + 1;
			if ((!start) && (CookieName != document.cookie.substring(0,CookieName.length)))
				return null;
			if (start == -1)
				return null;
			var end = document.cookie.indexOf(';',len);
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(len,end));
		}

		function setCookie(CookieName,value,expires,path,domain,secure) {
			document.cookie = CookieName + "=" +escape(value) +
			( (expires) ? ";expires=" + expires : "") +
			( (path) ? ";path=" + path : "") + 
			( (domain) ? ";domain=" + domain : "") +
			( (secure) ? ";secure" : "");
		}

		function deleteCookie(CookieName,path,domain) {
			if (getCookie(CookieName))
				document.cookie =
				CookieName + '=' +
				( (path) ? ';path=' + path : '') +
				( (domain) ? ';domain=' + domain : '') +
				';expires=Thu, 01-Jan-1970 00:00:01 GMT';
		}
		//-->
<!--
function setTextInputValue(inputID,value) {
    var element = document.getElementById(inputID);

    if(element == undefined)
        return;

    element.setAttribute('value',value);
    element.setAttribute('clearedState','prefilled');
}
function clearTextInputValue(inputID) {
    var element = document.getElementById(inputID);

    if(element == undefined)
        return;

    var state = element.getAttribute('clearedState');
    if (state == 'prefilled') {
        element.setAttribute('value','');
        element.removeAttribute('clearedState');
    }
}
setTextInputValue('url','http://');
//-->

/*    -------------------------------------------------------------
    function setLinkAttributes()
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Description:    setLinkAttributes finds ALL anchor links and
                    can set new attributes. The following script
                    specifically finds anchor links labeled as
                    external, and add a terget="_blank". We do
                    in order to validate in XHTML 1.1 Strict.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Credits:        Script found on Site Point (I think)
                    http://www.sitepoint.com
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
    
        <!--
        function setLinkAttributes(switchLinks) {
            if (switchLinks == "true") {
                if (!document.getElementsByTagName) return;
                var anchors = document.getElementsByTagName("a");
                    for (var i=0; i<anchors.length; i++) {
                    var anchor = anchors[i];
                    
                    if (anchor.getAttribute("href") && ( anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "nofollow" ) ) {
                        anchor.target = "_blank";
                    }
                }
            } else {
                if (!document.getElementsByTagName) return;
                var anchors = document.getElementsByTagName("a");
                    for (var i=0; i<anchors.length; i++) {
                    var anchor = anchors[i];
                    
                    if (anchor.getAttribute("href") && ( anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "nofollow" ) ) {
                        anchor.target = "_self";
                    }
                }
            }
        }
        
        function toggleLinkAttributes() {
            var ExpireLongTerm = new Date();
            var ExpireLongTermValue = new Date(ExpireLongTerm.getTime()+(1000 * 60 * 60 * 360000));
            
            if ( getCookie("externalLinks") == "true" ) {
                setLinkAttributes("false");
                setCookie("externalLinks","false",ExpireLongTermValue);
            } else if (getCookie("externalLinks") == "false") {
                setLinkAttributes("true");
                setCookie("externalLinks","true",ExpireLongTermValue);
            } else if ( !getCookie("externalLinks") ) {
                setLinkAttributes("true");
                setCookie("externalLinks","true",ExpireLongTermValue);
            }
        }
        //-->
// unobtrusive
function printClick() {
	if (!document.getElementById) return false;
	if (!document.getElementById("printarticle")) return false;

	var link = document.getElementById("printarticle");
	link.onclick = function() {
		window.print();
		return false;
	}
	link.onkeypress = link.onclick;
}

// onload function (not needed if script called at the end of the page)
// replace with "printClick();" if script called at the end of the page

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}
addLoadEvent(printClick);
