// Legacy Asacol.com Search
function DoSearch(){
var mbool = "AND";
var mcase = "Insensitive";
if((!document.cssearch.terms.value)||(document.cssearch.terms.value==" search")){
	alert("Please enter your search terms.");
	return false;
	}
else {
	//http://pg-stageweb-a01.isc.savvis.net:4014/cgi-bin/csSearch/csSearch.cgi
  document.cssearch.action="/cgi-bin/hpSearch/csSearch.cgi?command=query&terms="+escape(document.cssearch.terms.value)+"&mbool="+mbool+"&mcase="+mcase;;
	document.cssearch.submit();
	}
}

// Son of Suckerfish Dropdowns
sfHover = function() {
	var sfEls = document.getElementById("sfNav").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"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}
	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);

// grab Elements from the DOM by className
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// Popups for Email to a Friend
function popUpEmail(){
	var aLinks=getElementsByClass('emailFriend');
	for (var iLength=aLinks.length-1;iLength>=0;iLength--){
		aLinks[iLength].onclick=function(){ //match these numbers with newWin line below
			LeftPosition = (screen.width) ? (screen.width-720)/2 : 0;
			TopPosition = (screen.height) ? (screen.height-450)/2 : 0;
			var newWin=window.open(this.href,'popUpEmail','width=720,height=450,top='+TopPosition+',left='+LeftPosition+',location=no,menubar=no,status=yes,toolbar=no,scrollbars=yes,resizable=yes');
			if(window.focus){newWin.focus()}
			return false;
		}
	}
}
addEvent(window,'load',popUpEmail);

// Popups for Printer Friendly Version
function popUpPrint(){
	var aLinks=getElementsByClass('printer');
	for (var iLength=aLinks.length-1;iLength>=0;iLength--){
		aLinks[iLength].onclick=function(){ //match these numbers with newWin line below
			LeftPosition = (screen.width) ? (screen.width-650)/2 : 0;
			TopPosition = (screen.height) ? (screen.height-550)/2 : 0;
			var newWin=window.open(this.href,'popUpPrint','width=650,height=550,top='+TopPosition+',left='+LeftPosition+',location=no,menubar=yes,status=yes,toolbar=no,scrollbars=yes,resizable=yes');
			if(window.focus){newWin.focus()}
			return false;
		}
	}
}
addEvent(window,'load',popUpPrint);

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
*/
var sweetTitles = { 
	xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	tipElements : ['dfn','ins'],			// @Array: Allowable elements that can have the toolTip
	obj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	active : 0,								// @Number: 0: Not Active || 1: Active
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;
		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
				addEvent(current[j],'mouseover',this.tipOver);
				addEvent(current[j],'mouseout',this.tipOut);
				current[j].setAttribute('tip',current[j].title);
				current[j].removeAttribute('title');
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		sweetTitles.tip.style.visibility = 'hidden';
	},
	checkNode : function() {
		var trueObj = this.obj;
		if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		sweetTitles.obj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",50);
		sweetTitles.updateXY(e);
	},
	tipShow : function() {		
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = this.checkNode();
		var addy = '';
		var access = '';
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			addy = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href);
			// var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
		} else {
			addy = anch.firstChild.nodeValue;
		}
		if ( anch.nodeName.toLowerCase() == 'ins' ) {
			this.tip.innerHTML = "<p>" + anch.getAttribute('tip') + "</p>";
		} else {
			this.tip.innerHTML = "<p><span class=\"glossaryTerm\">" + addy + ": </span>" + anch.getAttribute('tip') + "</p>";
		}
		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
			this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		} else {
			this.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
		this.tip.style.visibility = 'visible';
		this.tip.style.opacity = '1';
		this.tipFade(100);
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 80 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",20);
		}
		else { 
			this.tip.style.opacity = '1';
			this.tip.style.filter = "alpha(opacity:100)";
		}
	}
};
function pageLoader() {
	sweetTitles.init();
}
addEvent(window,'load',pageLoader);


//AARF Font Switcher//
a1_off = new Image();
a1_off.src ="../images/btn_a1_off.gif";
a1_on = new Image();
a1_on.src ="../images/btn_a1_on.gif";

a2_off = new Image();
a2_off.src ="../images/btn_a2_off.gif";
a2_on = new Image();
a2_on.src ="../images/btn_a2_on.gif";

a3_off = new Image();
a3_off.src ="../images/btn_a3_off.gif";
a3_on = new Image();
a3_on.src ="../images//btn_a3_on.gif";

    /* Determines the browser name and browser version */
    var brow = ((navigator.appName));
	var verStr=navigator.appVersion, app=navigator.appName, version = parseFloat(verStr);
	var agt=navigator.userAgent.toLowerCase();
	var is_mac =  (agt.indexOf("mac")!=-1);
    
	/* reassign variable depending on the browser */
        var nav = false
        var iex = false
    
	if (brow == "Netscape") {nav = true}
		else if (brow == "Microsoft Internet Explorer") {iex = true} 
			else if (brow.indexOf(0) == "M") {iex = true} 
				else {
					nav = false 
					iex = false}
    var docObj,styleObj
        if (iex){
            docObj = 'document.all'
            styleObj = '.style'
            nav = false
        }
        
        if (nav){
            docObj = 'document'
            styleObj = ''
            nav = true
        }

// Specify affected tags. Add or remove from list:
// args:
// i - element id
// inc - increment

function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0; 
while (i < clen) {
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}

//set cookie function//
function SetCookie (name, value,exp) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString()));

}

function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);   
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

//font size switch
function ts(i, inc) {  	 
	sz = inc;
	if ( sz == 1 ) sz = 1, imageswap('a1','a2','a3', '1'); 
	if ( sz == 2 ) sz = 2, imageswap('a1','a2','a3', '2');
	if ( sz == 3 ) sz = 3, imageswap('a1','a2','a3', '3');
	SetCookie('fontSize',sz,exp);
}

 
 // IMAGESWAP: The font resizing and image-swapping Function. 
function imageswap(imgName, imgName2, imgName3, sz) {
   imgName = eval(docObj+'.'+imgName)	
   imgName2 = eval(docObj+'.'+imgName2)		
   imgName3 = eval(docObj+'.'+imgName3)		
	switch (sz){
	 case '1' :	
	 	if (iex&&is_mac){
			getElementsByclassname("transaction").setStyle("fontSize","80%");}
		else {
			setStyleById("transtable","fontSize","9px");}
			window.fontVariable = "sml";
			imgName.src = a1_on.src;	
		  	imgName2.src = a2_off.src;
			imgName3.src = a3_off.src;
	  break;
	 case '2' :
		if (iex&&is_mac){
			getElementsByclassname("transaction").setStyle("fontSize","100%");}
		else {
			setStyleById("transtable","fontSize","11px");}
			window.fontVariable = "med";
			imgName.src = a1_off.src;	
		  	imgName2.src = a2_on.src;
			imgName3.src = a3_off.src;
	 break;
	case '3' :
		if (iex&&is_mac){
			getElementsByclassname("transaction").setStyle("fontSize","105%");}
		else {
			setStyleById("transtable","fontSize","13px");}
			window.fontVariable = "lrg";
			imgName.src = a1_off.src;	
		  	imgName2.src = a2_off.src;
			imgName3.src = a3_on.src;
	break;
	default : 
		if (iex&&is_mac){
			getElementsByclassname("transaction").setStyle("fontSize","100%");}
		else {
			setStyleById("transtable","fontSize","11px");}
			window.fontVariable = "med";
			imgName.src = a1_off.src;	
		  	imgName2.src = a2_on.src;
			imgName3.src = a3_off.src;
	 }
 }


//The setStyleById function is being used for changing the font size on all browsers other than Mac IE.
// setStyleById: given an element id, style property and value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
this.w3c = (document.getElementById);
x = (this.w3c)?document.getElementById(i):document.all[i];
x.style[p] = v;
}

// getElementByclassname: This is used to change the font sizes in Mac IE.
function getElementsByclassname(classname,container)  {    
	container = container||document;   
	var all = container.all||container.getElementsByTagName("span");    
	var arr = [] ;   
	for(var k=0;k<all.length;k++)      
		if(all[k].getAttribute("classname") == classname) arr[arr.length] = all[k];    
		return arr  } 
	
	Array.prototype.setStyle = function(propName,val) {   
		for(var k=0;k<this.length;k++)
		this[k].style[propName] = val 
} 

function firstLoad(){
var firstSize = GetCookie('fontSize');


if (firstSize!=null){

ts('transtable',firstSize);

}else{

SetCookie('fontSize',2);
ts('transtable',2);

}
}