/* JavaScript Document */


/* opens a link url in a new window */
function new_window(url)
{
		window.open(url);
		history.go(0);
}

/* creates a popup window of the specified height and width */
function popup(url, width, height, scrollbars_flag, resizeable_flag)
{
	resizeable = "";
	scrollbars = "";
	if (!resizeable_flag)
		resizeable = "=no";
	if (!scrollbars_flag)
		scrollbars = "=no";
	return window.open(url, "", "location=no, menubar=no, resizable" + resizeable + ", status=no, toolbar=no, scrollbars" + scrollbars + ", height=" + height + "px, width=" + width + "px");
}

/* returns true if the url is for an index page */
function is_index(url)
{
	return (url.charAt(url.length -1) == '/' ||
		  url.substring(url.length-11, url.length) == "/index.html" || 
		  url.substring(url.length-10, url.length) == "/index.htm" || 
		  url.substring(url.length-10, url.length) == "/index.php" ||
		  url.substring(url.length-12, url.length) == "/default.asp");
	
}

/* returns the pathname of a url */
function get_path(url)
{
		if (url.charAt(url.length-1) != '/')
		{
			docurl = url.split('/');
			returnvalue = "";
			
			for (i = 0; i < docurl.length-1; i++)
			{
				returnvalue = returnvalue + docurl[i] + '/';
			}
			return returnvalue;		
		}
		else
			return url;
}
/* creates a link to the specified url only if we are not on that page.  
 */
function template_div (url, text)
{
	/* fix this to be an abolute link */
	if (url.charAt(0) == '/')
	{
		/* we'll add the current server info if it's just as absolute link from root */
		url = document.URL.substring(0, document.URL.indexOf('/', 7)) + url;
	}
	else if (url.indexOf("http://") == 0)
	{
		/* do nothing */
	}
	else
	{
			url = get_path(document.URL) + url;
	}
	
//	alert(get_path(document.URL));	
//	alert(url);
//	alert(document.URL + " " + url);
	/* if this is an index page, we need special rules. */
	if ((is_index(url) && is_index(document.URL)) && (get_path(url) != get_path(document.URL)))
	{
		document.write('<div class="template"><a href="' + url + '">' + text + '</a></div>');
	}
	else if ((document.URL != url))
	{
		document.write('<div class="template"><a class="template" href="' + url + '">' + text + '</a></div>');
	}
	else
	{
		document.write('<div id="current"><a  style="text-decoration: none;">' + text + '</a></div>');
	}
}
/* creates a link to the specified url only if we are not on that page.  
 * line break is a boolean value, true to add a line break after the link
 */
function template_link (url, text, line_break)
{
	lb = "";
	if (line_break)
		lb = "<br />";

	/* fix this to be an abolute link */
	if (url.charAt(0) == '/')
	{
		/* we'll add the current server info if it's just as absolute link from root */
		url = document.URL.substring(0, document.URL.indexOf('/', 7)) + url;
	}
	else if (url.indexOf("http://") == 0)
	{
		/* do nothing */
	}
	else
	{
			url = get_path(document.URL) + url;
	}
	
//	alert(get_path(document.URL));	
//	alert(url);
//	alert(document.URL + " " + url);
	/* if this is an index page, we need special rules. */
	if ((is_index(url) && is_index(document.URL)) && (get_path(url) != get_path(document.URL)))
	{
		document.write('<a class="template" href="' + url + '">' + text + '</a>' + lb);
	}
	else if ((document.URL != url))
	{
		document.write('<a class="template" href="' + url + '">' + text + '</a>' + lb);
	}
	else
	{
		document.write('<a id="current" style="text-decoration: none;">' + text + '</a>' + lb);
	}
}


/* creates a TABLED link to the specified url only if we are not on that page. */
function tabled_link (url, text)
{
	
	/* fix this to be an abolute link */
	if (url.charAt(0) == '/')
	{
		/* we'll add the current server info if it's just as absolute link from root */
		url = document.URL.substring(0, document.URL.indexOf('/', 7)) + url;
	}
	else if (url.indexOf("http://") == 0)
	{
		/* do nothing */
	}
	else
	{
			url = get_path(document.URL) + url;
	}
		
	/* if this is an index page, we need special rules. */
	if ((is_index(url) && is_index(document.URL)) && (get_path(url) != get_path(document.URL)))
	{
		document.write('<tr>');
		document.write('	<td>');
		document.write('		<a href="' + url + '">' + text + '</a>');
		document.write('	</td>');
		document.write('</tr>');
	}
	else if ((document.URL != url))
	{
		document.write('<tr>');
		document.write('	<td>');
		document.write('		<a href="' + url + '">' + text + '</a>');
		document.write('	</td>');
		document.write('</tr>');
	}
	else
	{
		document.write('<tr>');
		document.write('	<td id="current">');
		document.write('		<a style="text-decoration: none;">' + text + '</a>');
		document.write('	</td>');
		document.write('</tr>');
	}

}
//cookie functions

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);
}

/********* Element Xpander v 0.2.3 - http://www.thelostviking.com/ ********/
/* call the function toggle to toggle the height of an element(usually of a div)
 * from 0 to the height specified in ems. The element should start with a height of
 * 0. Otherwise, call set_expanded(element_id) to set the element as already
 * expanded, and will cause it to collapse on it's initial click.
 * If you call toggle with a height of greater than MAX_EMS, the function will assume
 * a height in pixels instead of ems.
 */
expanded = [];
/* a lower number for faster speed, higher for slower. this is actually the
 * milliseconds of delay between frames. approx. # of frames = height in ems * 10
 * or height in pixels / 2
 */
speed = 40;
MAX_EMS = 10;

/* sets the speed for this page */
function set_anim_speed(s)
{
	speed = s;
}

/* set an element as already expanded. */
function set_expanded(div)
{
	expanded[expanded.length] = div;
}

/* returns true if the array contains the element */
function array_contains(array, element)
{
	returnvalue = false;
	for (i=0; i < array.length && !returnvalue; i++)
	{
		returnvalue = (array[i] == element);
	}
	return returnvalue;
}

function array_index(array, element)
{
	returnvalue = -1;
	for (i=0; i < array.length && returnvalue < 0; i++)
	{
			if (array[i] == element)
				returnvalue = i;
	}
	return returnvalue;
}

/* resizes a div (or whatever) element to the height specified in size (ems) */
function resize(div, size)
{
	element = document.getElementById(div);
	element.style.height = size + "em";
}

function resize_px(div, size)
{
	element = document.getElementById(div);
	element.style.height = size + "px";
}

//returns true for opened, false for closed
function toggle(div, maxsize)
{
	if (array_contains(expanded, div))
	{
		contract(div, maxsize);
		return false;
	}
	else
	{
		expand(div, maxsize);
		return true;
	}
}

function cookieToggleCookieName(basepage)
{
	return "WVUIT_TOGGLE_"+basepage;	
}
	
/*Toggles, and creates a cookie with the div's name in it for tracking whether or not
  it is open.  The cookie should exist if the div is open.*/

function cookieToggle(div, maxsize, basepage)
{
	eraseCookie(cookieToggleCookieName(basepage));
	if(toggle(div,maxsize))
	{
		createCookie(cookieToggleCookieName(basepage),div,100);	
	}
	
	
}

/* animate & expand the element's height to the specified maxsize in ems or pixels */
function expand (div, maxsize)
{
	if (maxsize <= MAX_EMS)
	{
		for (i = 0; i <= maxsize; i = i + 0.1)
			setTimeout("resize('" + div + "'," + i + ")", i * speed);
		setTimeout("resize('" + div + "', " + maxsize + ")", maxsize * speed);
	}
	else
	{
		for (i = 0; i <= maxsize; i = i + 2)
			setTimeout("resize_px('" + div + "'," + i + ")", i/10 * speed);
		setTimeout("resize_px('" + div + "', " + maxsize + ")", maxsize/10 * speed);
	}
	expanded[expanded.length] = div;
}

/* animate & contract the element's height from maxsize to 0 */
function contract (div, maxsize)
{
	if (maxsize <= MAX_EMS)
	{
		for (i = maxsize; i >= 0; i = i - 0.1)
			setTimeout("resize('" + div + "'," + i + ")", (maxsize-i) * speed);
		setTimeout("resize('" + div + "', 0)", maxsize * speed);
	}
	else
	{
		for (i = maxsize; i >= 0; i = i - 2)
			setTimeout("resize_px('" + div + "'," + i + ")", ((maxsize-i)/10) * speed);
		setTimeout("resize_px('" + div + "', 0)", maxsize/10 * speed);
	}
	expanded.splice(array_index(expanded, div), 1);

}

/* causes a submenu to expand based on the url */
function expand_on_url(url, div, size)
{
	if (document.URL.indexOf(url) > 0)
	{
			expand(div, size);
	}
}
/************************** End Element Xpander Code ********************************/

