﻿// JavaScript for opening external links in XHTML document

function SetLinkSelected(linkID)
{
    setCookieCickedLink(linkID);
}

function EmailPage()
{
    var strPath = URLencode(document.URL);
    var strTitle = URLencode(document.title);
    var strUrl = '/Email_SendLink.aspx?SendUrl=' + strPath + '&Title=' + strTitle;
    window.open(strUrl,'',
        'height=420,width=390,toolbar=no,scrollbars=yes,status=no,menubar=no,resizable=no,directories=no,location=no');
}

/* Description: escape() encodes most of the stuff you need to encode. It misses single and double 
 * quotes, so you should replace those manually.
 * Params: sStr - The string to be encoded
 * Returns: The encoded string
 */
function URLencode(sStr) {
    return escape(sStr)
       .replace(/\+/g, '%2B')
          .replace(/\"/g,'%22')
             .replace(/\'/g, '%27');
  }

/* Description: This function allows us to indicate links as external using rel="external"
 * instead of the deprecated target="_blank", but achieve the same effect
 */
function externalLinks() {
 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.target = "_blank";
 }
}

// JavaScript for suckerfish drop-downs <http://www.htmldog.com/articles/suckerfish/>
sfHover = function() {
	var sfEls = document.getElementById("navMain").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

/* Description: This function allows us to rotate through the given number of font 
 * sizes.
 * Params: x - The new font size
 */
function fontSize(x) {
	Value = x;
	document.getElementById('fontSizer1').className -= " activeSize";
	document.getElementById('fontSizer2').className -= " activeSize";
	document.getElementById('fontSizer3').className -= " activeSize";
	if(Value == 3){
		newSize = "120%";
		document.getElementById('fontSizer3').className += " activeSize";
	}
	else if(Value == 2){
		newSize = "110%";
		document.getElementById('fontSizer2').className += " activeSize";
	}
	else{
		newSize = "100%";
		document.getElementById('fontSizer1').className += " activeSize";
	}
	document.getElementById('pageContainer').style.fontSize = newSize;
	setCookieFontSize(Value);
}

/* Description: This function stores the font size in a cookie so that it persists
 * across pages and visits to the site on the same computer.
 * Params: name  - The name of the cookie
 *         value - The value of the cookie
 */
function setCookie(name, value)
{
  document.cookie =
    name+"="+escape(value) + ";expires=Tue, 01-Jan-2099 00:00:00 GMT;path=/;";
}

/* Description: This function returns a cookie based on the name requested
 * Params: name - The new font size
 * Returns: The requested cookie
 */
function Get_Cookie( name ) {      
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.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 ) );
}

/* Description: Shorthand for setting the predefined "fontSize" named cookie with a font size value
 * Params: x - The new font size
 */
function setCookieFontSize(x) {
	setCookie("fontSize", x);
}

/* Description: Shorthand for setting the predefined "opt_clickedLink" named cookie with the clicked link value
 * Params: link - The clicked link
 */
function setCookieCickedLink(linkID) {
	setCookie("opt_clickedLinkID", linkID);
}

// JavaScript for loading above functions into the page
var PageInitializer = {
    start : function(){
        PageInitializer.addLoadEvent(function(){
            //Add Functions Here
			sfHover();
			externalLinks();
			if(document.getElementById("navMain")){sfHover();};
			/*if(Get_Cookie("fontSize") != null){
				fontSize(Get_Cookie("fontSize"));
			}*/
        });
    },
    addLoadEvent:function(f){var w=window;var o=w.onload;if(typeof w.onload!='function'){w.onload=f;}else{w.onload=function(){o();f();}}}
}
PageInitializer.start();

