function changeTitle (str) {	
	top.document.title = str;
}

function getValueFromQuery (variableName) {
	var query = document.location.search;
	var arr = query.substring(1, query.length).split("&");

	var i = 0;
	while (i < arr.length) {
		var pairArr = arr[i].split("=");

		if (pairArr[0] == variableName) {
			return pairArr[1];
			break;
		}

		i++;
	}
	
	return false;
}

function isIE () {
	var agt = navigator.userAgent.toLowerCase();
	return agt.indexOf("msie") != -1;
}

function isMacIE () {
	var opsys = navigator.platform.toLowerCase();
	var is_mac = opsys.indexOf("mac") != -1;
	
	if (is_mac && isIE()) return true;
	
	return false;
}

function getPrintButton () {
	var str = "<div id=\"printbutton\">";
	
	if (isMacIE()) {
		str += "<span class=\"highlight\">Print Page: Apple + P</span>";
	} else {
		str += "<form><INPUT TYPE=\"button\" value=\"Print Page\" onclick=\"window.print()\"></form>";
	}
	
	str += "</div>";
	
	return str;
}

winIncrement = 0;

function popWin (theURL, w, h, scroll) {
	winIncrement++;
	
	if (scroll == null) scroll = "no";
	
	if (navigator.userAgent.indexOf("Safari") > 0) {
		w = w - 2;
		h = h - 1;
	}
	
	var winl = (screen.width - w) / 2;
	var wint = ((screen.height - h) / 2) - 10;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no';
	
	win = window.open(theURL, winIncrement, winprops);
	
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus(); 
	}
}

function readCookie (name) {
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search);
		if (offset != -1) { 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end));
		}
	}
	return cookieValue;
}

function writeCookie (name, value, hours) {
	var expire = "";
	if (hours != null) {
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + "; " + expire + "; path=/;";
}

function replace (path, htmlStr) {
	document.getElementById(path).innerHTML = htmlStr;
}

function getWindowSize () {
	var winW = 800;
	var winH = 600;

	if (parseInt(navigator.appVersion) > 3) {
		if (navigator.appName == "Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft") != -1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	
	return [winW, winH];
}


var goalY;
var id;
var oldY;
var dY;
var counter = 0;
var dur = 20;

function ease(t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
}

function startScroll(goalY) {
	counter = 0;

	if(document.all) {
		oldY = document.body.scrollTop;
	} else {
		oldY = window.scrollY;
	}
	
	//DON'T SCROLL IF ALREADY SCROLLED PAST 100
	if (oldY > 100) return;
	
	//DON'T SCROLL IF BROWSER WINDOW IS BIG ENOUGH
	var winSize = getWindowSize();
	if (winSize[1] > 750) return;
	
	dY = goalY - oldY;
	id = setInterval("scrollMe()", 30);
}

function scrollMe() {
	counter++
	if(counter <= dur) {
		var newY = ease(counter, oldY, dY, dur);
		window.scrollTo(0, newY);		
	} else {
		clearInterval(id);
	}
}