// JavaScript Document
/*------------------------------------------------------------
	Document Text Sizer- Copyright 2003 - Taewook Kang.  All rights reserved.
	Coded by: Taewook Kang (txkang.REMOVETHIS@hotmail.com)
	Web Site: http://txkang.com
	Script featured on Dynamic Drive (http://www.dynamicdrive.com)
	
	Please retain this copyright notice in the script.
	License is granted to user to reuse this code on 
	their own website if, and only if, 
	this entire copyright notice is included.
--------------------------------------------------------------*/

//Specify affected tags. Add or remove from list:

//var tgs = new Array('div','td','tr');
var tgs = new Array('div','tr','td');

//Specify spectrum of different font sizes:
//var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );

var szs = new Array( '10px','12px','14px','16px','18px','20px','22px' );

var startSz = 2;


function tsize( trgt,inc ) {
	if (!document.getElementById)
	{
		return
	}
	
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	//sz += inc;
	sz = inc;
	
	if ( sz < 0 )
	{ 
		sz = 0;
	}
	if ( sz > 6 )
	{
		sz = 6;
	}
	
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) 
	{
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		
		for ( j = 0 ; j < cTags.length ; j++ ) 
		{		
			cTags[ j ].style.fontSize = szs[ sz ];
		}
	}
}

//Style Sheet Switcher version 1.1 Oct 10th, 2006
//Author: Dynamic Drive: http://www.dynamicdrive.com
//Usage terms: http://www.dynamicdrive.com/notice.htm

var manual_or_random="manual" //"manual" or "random"
var randomsetting="3 days" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.

//////No need to edit beyond here//////////////

function getCookie(Name) { 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return null
}

function setCookie(name, value, days) {
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

function deleteCookie(name){
setCookie(name, "moot")
}


function setStylesheet(title, randomize){ //Main stylesheet switcher function. Second parameter if defined causes a random alternate stylesheet (including none) to be enabled
var i, cacheobj, altsheets=[""]
for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
if(cacheobj.getAttribute("rel").toLowerCase()=="alternate stylesheet" && cacheobj.getAttribute("title")) { //if this is an alternate stylesheet with title
cacheobj.disabled = true
altsheets.push(cacheobj) //store reference to alt stylesheets inside array
if(cacheobj.getAttribute("title") == title) //enable alternate stylesheet with title that matches parameter
cacheobj.disabled = false //enable chosen style sheet
}
}
if (typeof randomize!="undefined"){ //if second paramter is defined, randomly enable an alt style sheet (includes non)
var randomnumber=Math.floor(Math.random()*altsheets.length)
altsheets[randomnumber].disabled=false
}
return (typeof randomize!="undefined" && altsheets[randomnumber]!="")? altsheets[randomnumber].getAttribute("title") : "" //if in "random" mode, return "title" of randomly enabled alt stylesheet
}

function chooseStyle(styletitle, days){ //Interface function to switch style sheets plus save "title" attr of selected stylesheet to cookie
if (document.getElementById){
setStylesheet(styletitle)
setCookie("mysheet", styletitle, days)
}
}

function indicateSelected(element){ //Optional function that shows which style sheet is currently selected within group of radio buttons or select menu
if (selectedtitle!=null && (element.type==undefined || element.type=="select-one")){ //if element is a radio button or select menu
var element=(element.type=="select-one") ? element.options : element
for (var i=0; i<element.length; i++){
if (element[i].value==selectedtitle){ //if match found between form element value and cookie value
if (element[i].tagName=="OPTION") //if this is a select menu
element[i].selected=true
else //else if it's a radio button
element[i].checked=true
break
}
}
}
}

if (manual_or_random=="manual"){ //IF MANUAL MODE
var selectedtitle=getCookie("mysheet")
if (document.getElementById && selectedtitle!=null) //load user chosen style sheet from cookie if there is one stored
setStylesheet(selectedtitle)
}
else if (manual_or_random=="random"){ //IF AUTO RANDOM MODE
if (randomsetting=="eachtime")
setStylesheet("", "random")
else if (randomsetting=="sessiononly"){ //if "sessiononly" setting
if (getCookie("mysheet_s")==null) //if "mysheet_s" session cookie is empty
document.cookie="mysheet_s="+setStylesheet("", "random")+"; path=/" //activate random alt stylesheet while remembering its "title" value
else
setStylesheet(getCookie("mysheet_s")) //just activate random alt stylesheet stored in cookie
}
else if (randomsetting.search(/^[1-9]+ days/i)!=-1){ //if "x days" setting
if (getCookie("mysheet_r")==null || parseInt(getCookie("mysheet_r_days"))!=parseInt(randomsetting)){ //if "mysheet_r" cookie is empty or admin has changed number of days to persist in "x days" variable
setCookie("mysheet_r", setStylesheet("", "random"), parseInt(randomsetting)) //activate random alt stylesheet while remembering its "title" value
setCookie("mysheet_r_days", randomsetting, parseInt(randomsetting)) //Also remember the number of days to persist per the "x days" variable
}
else
setStylesheet(getCookie("mysheet_r")) //just activate random alt stylesheet stored in cookie
} 
}


function allowcookies() {
	var cookies = GetCookie("cookies");
	if (cookies.length = 0) {
		cookies = false;
	}
	return cookies;
}

function resetcookies() {
	EraseCookie("cookies");
	EraseCookie("accessibility");
	EraseCookie("navigation");
	alert("Your cookies have been expired");
	document.location.href = document.location.href;
}

function accessibility(n) {
	// Grab the area we want to resize
	e = document.getElementById("body");
	if (e == null) return;

	// set/get cookie
	if (n == null) {
		n = GetCookie("accessibility");
	} else {
		var cookie = false;
		if (allowcookies() == "true") {
			cookie = true;
		} else {
			if (confirm("Would you like your browser to remember this setting?" + 
					"\n\nClick OK to store your options. This will create a cookie on your computer to store your settings. No other information is stored and no information about you or your computer is used by us or passed to a third party." + 
					"\nThis requires cookies to be enabled in your browser settings." + 
					"\n\nClick CANCEL if you do not want the cookie or your settings stored.")) {
				cookie = true;
			}
		}
		
		if (cookie == true) {
			SetCookie("cookies", "true");
			SetCookie("accessibility", n);
		}
	}

	// set default
	if (n == null) {
		n = 0;
	}

	// Set the display to show the cookie info
	if (n == 0) document.getElementById("accessibility1").className = "active"; else document.getElementById("accessibility1").className = "box";
	if (n == 1) document.getElementById("accessibility2").className = "active"; else document.getElementById("accessibility2").className = "box";
	if (n == 2) document.getElementById("accessibility3").className = "active"; else document.getElementById("accessibility3").className = "box";
	if (n == 3) document.getElementById("accessibility4").className = "active"; else document.getElementById("accessibility4").className = "box";

	// Figure out the font size based on the option chosen
	if (n == 4) {
		n = 140;
	} else {
		n = 80 + n * 10;
	}

	// Set anything that can obviously be resized
	e.style.fontSize = n + "%";

	// Find all elements with tsx in the id or the classname
	// saves having to code an incrementor for the id, and
	// keeps compatibilty with older sites that already use the incrementor method
	var inc=0;
	var alltags= e.getElementsByTagName("span")
	
	// change font size of tags that need resizing
	for (i=0; i<alltags.length; i++) {
		if (alltags[i].id.indexOf("tsx") != -1 || alltags[i].className.indexOf("tsx") != -1) {
			alltags[i].style.fontSize = n + "%";
		}
	}
}

function navigation(display) {
	if (display == null) {
		display = GetCookie("navigation");
	}
	
	if (display.length > 0) {
		var cookie = false;
		if (allowcookies() == "true") {
			cookie = true;
		} else {
			if (confirm("Would you like your browser to remember this setting?" + 
					"\n\nClick OK to store your options. This will create a cookie on your computer to store your settings. No other information is stored and no information about you or your computer is used by us or passed to a third party." + 
					"\nThis requires cookies to be enabled in your browser settings." + 
					"\n\nClick CANCEL if you do not want the cookie or your settings stored.")) {
				cookie = true;
			}
		}

		if (cookie == true) {
			SetCookie("cookies", "true");
			SetCookie("navigation", display);
		}

		if (display == "block") {
			document.getElementById('scroller1').style.display = "block";
			document.getElementById('scroller2').style.display = "none";
		} else {
			document.getElementById('scroller1').style.display = "none";
			document.getElementById('scroller2').style.display = "block";
		}
	}
}

function scrollerEmail() {
    var email = window.open('mailto:?subject=' + escape(document.title) + '&body=' + escape('Take a look at this page!\n\n' + document.location.href));
    if (navigator.appVersion.indexOf("MSIE") == -1) {
        email.close();
    }
}

function scrollerBookmark() {
    if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
        window.external.AddFavorite(location.href, document.title); 
    } else {
        alert("Please press <CTRL>+<D> to bookmark this page");
    }
}

function toggleMenu(id) {
	var className = "";
    menuId = id.substring(4,id.length);
    if (document.getElementById('submenu'+menuId).style.display == "none") {
    	className = document.getElementById(id).className;
    	className = "folder_hide" + className.substring(11,className.length);
    	
    	document.getElementById(id).className = className;
    	document.getElementById('submenu'+menuId).style.display = "block";
    } else {
    	className = document.getElementById(id).className;
    	className = "folder_show" + className.substring(11,className.length);
    	
    	document.getElementById(id).className = className;
        document.getElementById('submenu'+menuId).style.display = "none";
    }
}



var slideTime1 = 700, topMargin1;
var slideTime2 = 0, topMargin2;

function winOnResize() {
    // xMoveTo('scroller1', xPageX('main')+xWidth('main')+20, topMargin);
    xShow('scroller1');
    xShow('scroller2');
    winOnScroll(); // initial slide
}

function winOnScroll() {
    xSlideTo('scroller1', xLeft('scroller1'), xScrollTop() + topMargin, slideTime1);
    xSlideTo('scroller2', xLeft('scroller2'), xScrollTop() + topMargin, slideTime2);
}

function scrollLoad() {
    topMargin = xPageY('scroller1')
    topMargin = xPageY('scroller2')
    // winOnResize();
    xAddEventListener(window, 'resize', winOnResize, false);
    xAddEventListener(window, 'scroll', winOnScroll, false);
    return;
}

//Document Text Resizer script (May 14th, 08'): By JavaScript Kit: http://www.javascriptkit.com

var documenttextsizer={

prevcontrol: '', //remember last control clicked on/ selected
existingclasses: '',

setpageclass:function(control, newclass){
	if (this.prevcontrol!='')
			this.css(this.prevcontrol, 'selectedtoggler', 'remove') //de-select previous control, by removing 'selectedtoggler' from it
	document.documentElement.className=this.existingclasses+' '+newclass //apply new class to document
	this.css(control, 'selectedtoggler', 'add') //select current control
	this.setCookie('pagesetting', newclass, 5) //remember new class added to document for 5 days
	this.prevcontrol=control
},

css:function(el, targetclass, action){
	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
	if (action=="check")
		return needle.test(el.className)
	else if (action=="remove")
		el.className=el.className.replace(needle, "")
	else if (action=="add")
		el.className+=" "+targetclass
},

getCookie:function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
},

setCookie:function(name, value, days){
	if (typeof days!="undefined"){ //if set persistent cookie
		var expireDate = new Date()
		var expstring=expireDate.setDate(expireDate.getDate()+days)
		document.cookie = name+"="+value+"; path=/; expires="+expireDate.toGMTString()
	}
	else //else if this is a session only cookie
		document.cookie = name+"="+value
},

setup:function(targetclass){
	this.existingclasses=document.documentElement.className //store existing CSS classes on HTML element, if any
	var persistedsetting=this.getCookie('pagesetting')
	var alllinks=document.getElementsByTagName("a")
	for (var i=0; i<alllinks.length; i++){
		if (this.css(alllinks[i], targetclass, "check")){
			if (alllinks[i].getAttribute("rel")==persistedsetting) //if this control's rel attribute matches persisted doc CSS class name
				this.setpageclass(alllinks[i], alllinks[i].getAttribute("rel")) //apply persisted class to document
			alllinks[i].onclick=function(){
				documenttextsizer.setpageclass(this, this.getAttribute("rel"))
				return false
			}
		}
	}
}

}

// Cookie javascript include

function SetCookie(sName, sValue, iDays) {
	if (iDays) {
		var date = new Date();
		date.setTime(date.getTime() + (iDays*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	} else {
		// default = 31 days
		var date = new Date();
		date.setTime(date.getTime() + (31*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
		//var expires = "";
	}
	document.cookie = sName + "=" + sValue + expires + "; path=/";
}

function SetCookie2(sName, sValue, iDays) {
	var exp=new Date();
	exp.setTime(exp.getTime()+31536000000);
	document.cookie = sName + "=" + escape(sValue) + "; expires=" + exp.toGMTString() + ";";
}

function GetCookie(sName) {
  // cookies are separated by semicolons
    var strRetValue = "";
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++) 	{
		// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]) {
			strRetValue = UnEscape(aCrumb[1]);
			if (strRetValue == null || strRetValue == "undefined")
				strRetValue = "";
			break;
		}
	}
    return strRetValue;
}

function EraseCookie(sName) {
	SetCookie(sName, "", -1);
}

function UnEscape (strData) {
    var result = unescape(strData);
    result = result.replace(/\+/g, " ");
    return result;
}

