// JavaScript Document
sfHover = function() {
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		var sfEls = document.getElementById("primaryNav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className = 'sfhover';
				//this.className = this.className + '_sfhover';
			};
			sfEls[i].onmouseout=function() {
				//this.className = this.className.replace('_sfhover','');
				this.className = this.className.replace('sfhover','');
			};	
		}
		//sets fist-child class on the secondary nav for ie as ie 6 doesnt support selector:first-child in css
		var firstLi = document.getElementById('secondaryNav').getElementsByTagName('ul')[0].firstChild;
		firstLi.className = 'first';
	}
	if (document.getElementById('calendar')) {
		setupcalendar();
	}
	

};
window.onload = sfHover;

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
};

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
};

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
};

function eraseCookie(name) {
	createCookie(name,"",-1);
};

function changeStyle(el) {
	var cookie = readCookie('style');
	var newStyle = null;
	var textlink = document.getElementById('textlink');
	
	if ((cookie==null || cookie == 'text') && el != null) {
		createCookie('style','graphical',1);
		newStyle = 'graphical';
		//alert('1')
	} else if (el != null) {
		createCookie('style','text',1);	
		newStyle = 'text';
		//alert('2')
	} else if (cookie==null || cookie == 'graphical') {
		createCookie('style','graphical',1);
		newStyle = 'graphical';
		//alert('3')
	} else {
		createCookie('style','text',1);
		newStyle = 'text';
		//alert('4')
	}
	
	if (document.getElementsByTagName) {
		var links = document.getElementsByTagName('LINK');
		var styles = document.getElementsByTagName('STYLE');
	} else {
		var links = document.all.tags('link'); 
		var styles = document.all.tags('style');  
	}
		
	for (x=0;x<links.length;x++) {
		if (newStyle == 'text') {
			links[x].disabled = true;
			//if (el!=null) {
				textlink.innerHTML = 'graphical version';
			//}
		} else {
			links[x].disabled = false;
			//if (el!=null) {
				textlink.innerHTML = 'text only';
			//}
		}
	}
	  
	for (x=0;x<styles.length;x++) {
		if (newStyle == 'text') {
			styles[x].disabled = true;
		} else {
			styles[x].disabled = false;	
		}
	}
};
