function setTheStyle(styleVal)
{
	var index = 1;
	if (styleVal == 'medium')
		index = 2
	else if (styleVal == 'large')
		index = 3;

	switch(index)
	{
	case 1:
		$('regular').className = 'underline';
		$('medium').className = '';
		$('large').className = '';
		break    
	case 2:
		$('medium').className = 'underline';
		$('regular').className = '';
		$('large').className = '';
		break
	case 3:
		$('large').className = 'underline';
		$('medium').className = '';
		$('regular').className = '';
		break
	}
	currentStylesheet = styleVal;
}

function switchStylestyle(styleName)
{
	for(i=0; (a=document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
		{
			a.disabled = true;

			if(a.getAttribute("title") == styleName)
			{
				a.disabled = false;
			}
		}
	}

	setTheStyle(styleName);
	createCookie('style', styleName, 365);
}

/*
function switchStylestyle(styleName)
{

	$('link[@rel*=style][@title]').each(function(i) 
	{
		this.disabled = true;
		if (this.getAttribute('title') == styleName)
		{
				this.disabled = false;
				//alert('enabled: '+this.href);
		}
	});
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	 if(a.getAttribute("rel").indexOf("style") != -1
		&& a.getAttribute("title")) {
	   a.disabled = true;
	   if(a.getAttribute("title") == styleName) a.disabled = false;
	 }
   }
	setTheStyle(styleName);
	createCookie('style', styleName, 365);
}
*/

// cookie functions http://www.quirksmode.org/js/cookies.html
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);
}
// /cookie functions

function setWebTrendsCookie() {
	var webtrends = readCookie("WEBTRENDS_BI");
  var title = webtrends ? webtrends : createCookie("WEBTRENDS_BI", hexIt()+hexIt()+hexIt()+hexIt()+hexIt()+hexIt()+hexIt()+hexIt(), 365);
}

function hexIt() {
	return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}

function leaveSite( newURL ) {
	var result = confirm('You have selected a link to a website that exists outside of the SecondChancesStudy.com Web site.  Boehringer Ingelheim Pharmaceuticals, Inc. provides access to these sites as a service to SecondChancesStudy.com visitors, and is not responsible or liable for the content and information presented within any external site.');
	if (result)
		window.open(newURL);
	return false;
}

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", 2) &&
	   ((anchor.getAttribute("href", 2).indexOf('http://') == 0) || anchor.getAttribute("href", 2).indexOf('https://') == 0))
	 {
		 if (anchor.getAttribute("href", 2).indexOf('boehringer') < 0)
		 {
			 anchor.target = "_blank";
			 anchor.onclick = function() {
			 			logClick(this.href);
						return leaveSite(this.href); 
						}
		 }
	 }
 }
}

function doAjax(url)
{
	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") {
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  http = new XMLHttpRequest();
	}
   
	http.open("GET", url);
	http.onreadystatechange=function() {
	  if(http.readyState == 4) {
		//alert(http.responseText);
	  }
	}
	http.send(null);
}

function logClick(url)
{
	if (url == 'http://www.iian.ibeam.com/events/webx001/26356')
	{
		var url = "/view-discussion-webcast.html";
		doAjax(url);
	}
}

function setActive(item) {$$('#nav li.'+item)[0].toggleClass('active');}
function doActive(item) {window.addEvent('domready', function(){setActive(item); externalLinks();});}
sfHover = function() { var sfEls = document.getElementById("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length; i++) { sfEls[i].onmouseover=function() { this.className+=" sfhover";this.style.zIndex=120; }; sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); };}}
if (window.attachEvent) window.attachEvent("onload", sfHover);

setWebTrendsCookie();