/**************************************************************************************************/
/***
/***	Generic Javascript
/***	-----------------------------------------------------------------------
/***	Written by Matthew Praetzel. Copyright (c) 2006-2008 Matthew Praetzel.
/***	-----------------------------------------------------------------------
/***	Use any script at will. thanks.
/***
/**************************************************************************************************/

/*                                   **************************                                   */
/************************************   INITIALZE VARIABLES    ************************************/
/*                                   **************************                                   */
var timeOut = new Array();
/*                                   **************************                                   */
/************************************    BROWSER FUNCTIONS     ************************************/
/*                                   **************************                                   */
function getBrowserType()
{
	var browser_array = new Array("MSIE","NETSCAPE","FIREFOX","SAFARI");
	for(i=0;i<browser_array.length;i++)
	{
		var browserReg = new RegExp(browser_array[i],"");
		if(browserReg.test(navigator.userAgent.toUpperCase()))
		{
			var browser = browser_array[i];
			break;
		}
		else
		{
			var browser  = "other";
		}
	}
	return browser;
}
/*                                   **************************                                   */
/************************************     WINDOW FUNCTIONS     ************************************/
/*                                   **************************                                   */
function closeWindow()
{
	if(self.close())
	{
		self.close();
	}
	else
	{
		window.close();
	}
}
function openWindow(thisUrl,thisName,thisFeatures,width,height,x,y)
{
	thisFeatures = thisFeatures + ",width=" + width + ",height=" + height;
	if(winName = window.open(thisUrl,thisName,thisFeatures))
	{
		if(x.length < 1)
		{
		 	winName.moveTo((screen.availWidth-width)/2,(screen.availHeight-height)/2);
		}
		else
		{
			winName.moveTo(x,y);
		}
	}
	else
	{
		alert('There has been an error opening this window. Is your browser blocking pop-ups?');
	}
}
function popupWithPostAsUrl(thisUrl,thisName,width,height,postVariables)
{
	var urlQuery = compileUrlQueryOfPostVariables(postVariables);
	thisUrl = thisUrl + urlQuery;
	//
	var thisFeatures = width + ',' + height;
	//
	if(winName = window.open(thisUrl,thisName,thisFeatures))
	{
		 winName.moveTo((screen.availWidth-width)/2,(screen.availHeight-height)/2);
	}
	else
	{
		alert('There has been an error opening this window. Is your browser blocking pop-ups?');
	}
}
function getLocationWithUrlQuery(thisUrl,postVariables,otherVariables)
{
	var urlQuery = compileUrlQueryOfPostVariables(postVariables);
	urlQuery = urlQuery + otherVariables;
	var this_url = thisUrl + urlQuery
	//
	location.replace(this_url);
}
function resize(this_width,this_height,x,y)
{
	var this_size = getWindowSize();
	var screen_size = getScreenSize();
	//
	this_width = this_width > screen_size[0] ? screen_size[0] : this_width;
	this_height = this_height.length < 1 ? screen_size[1] : this_height;
	this_height = this_height > screen_size[1] ? screen_size[1] : this_height;
	//
	x = x.length < 1 ? (screen_size[0]-this_width)/2 : x;
	y = y.length < 1 ? (screen_size[1]-this_height)/2 : y;
	//
	if(this_width >= screen_size[0]-50 && this_height >= screen_size[1]-50)
	{
	}
	else if(this_size[0] > this_width && this_size[1] > this_height)
	{
	}
	else
	{
		if(this_width < this_size[0])
		{
			this_width = this_size[0];
		}
		if(this_height < this_size[1])
		{
			this_height = this_size[1];
		}
		//
		window.moveTo(x,y);
		window.resizeTo(this_width,this_height);
	}
}
function getWindowSize()
{
	var this_size = new Array();
	if(window.innerWidth)
	{
		this_size[0] = window.innerWidth;
		this_size[1] = window.innerHeight;
	}
	else if(document.body.clientWidth)
	{
		this_size[0] = document.body.clientWidth;
		this_size[1] = document.body.clientHeight;
	}
	else if(document.body.offsetWidth)
	{
		this_size[0] = document.body.offsetWidth;
		this_size[1] = document.body.offsetHeight;
	}
	return this_size;
}
function getScreenSize()
{
	var screen_size = new Array();
	if(screen.availWidth)
	{
		screen_size[0] = screen.availWidth;
		screen_size[1] = screen.availHeight;
	}
	else if(screen.width)
	{
		screen_size[0] = screen.width;
		screen_size[1] = screen.width;
	}
	return screen_size;
}
function getScrollTop()
{
	var scrollTop;
	if(scrollTop = window.pageYOffset)
	{
		scrollTop = window.pageYOffset;
	}
	else if(scrollTop = document.body.scrollTop)
	{
		scrollTop = document.body.scrollTop;
	}
	else if(scrollTop = document.documentElement.scrollTop)
	{
		scrollTop = document.documentElement.scrollTop;
	}
	else
	{
		scrollTop = 0;
	}
	return scrollTop;
}
/*                                   **************************                                   */
/************************************     URL FUNCTIONS        ************************************/
/*                                   **************************                                   */
function compileQuery(postVariables)
{
	var queryItems = postVariables.split(",");
	var urlQuery = "";
	//
	for(i=0;i<queryItems.length;i++)
	{
		var thisValue = document.getElementById(queryItems[i]).value;
		urlQuery = urlQuery == "" ? queryItems[i] + "=" + thisValue : urlQuery + "&" + queryItems[i] + "=" + thisValue;
	}
	urlQuery = urlQuery != "" ? "?" + urlQuery : "";
	return urlQuery;
}
function replaceVariableName(query,variable_name,new_name)
{
	query = query.substring(0,query.indexOf(variable_name)) + new_name + query.substring(query.indexOf(variable_name)+variable_name.length);
	//
	return query;
}
function addToUrlQuery(urlQuery,variable,value)
{
	urlQuery = urlQuery + "&" + variable + "=" + value;
	return urlQuery;
}
function getUrl(url)
{
	location.replace(url);
}
/*                                   **************************                                   */
/************************************     FORM FUNCTIONS       ************************************/
/*                                   **************************                                   */
function submitForm(thisForm)
{
	thisForm.submit();
}
/*                                   **************************                                   */
/************************************    MESSAGE FUNCTIONS     ************************************/
/*                                   **************************                                   */
function underCon()
{
	alert("This functionality is currently under construction.");
}
function sendMessage(message)
{
	alert(message);
}
/*                                   **************************                                   */
/************************************    ROLLOVER FUNCTIONS    ************************************/
/*                                   **************************                                   */
function doRollover(whichTag,src)
{
	var rollTag = document.getElementById(whichTag);
	if(rollTag.getElementsByTagName('a').item(0))
	{
		var rollLink = rollTag.getElementsByTagName('a').item(0);
		var rollImage = rollLink.getElementsByTagName('img').item(0);
	}
	else
	{
		var rollImage = rollTag.getElementsByTagName('img').item(0);
	}
	//
	var rollSRC = rollImage.src;
	if(src == rollSRC)
	{
	}
	else
	{
		var newImage = document.createElement('img');
		newImage.setAttribute('src',''+src);
		newImage.setAttribute('border','0');
		if(rollTag.getElementsByTagName('a').item(0))
		{
			rollLink.replaceChild(newImage,rollImage);
		}
		else
		{
			rollTag.replaceChild(newImage,rollImage);
		}
	}
}
/*                                   **************************                                   */
/************************************     CLASS FUNCTIONS      ************************************/
/*                                   **************************                                   */
function changeClass(whichElement,classname)
{
	if(typeof(whichElement) == "string")
	{
		if(classname.type == 'select-one')
		{
			classname = classname.options[classname.selectedIndex].value;
		}
		if(document.getElementById(whichElement).setAttribute('class',classname))
		{
			document.getElementById(whichElement).setAttribute('class',classname);
		}
		else
		{
			document.getElementById(whichElement).className = classname;
		}
	}
	else
	{
		if(classname.type == 'select-one')
		{
			classname = classname.options[classname.selectedIndex].value;
		}
		if(whichElement.className)
		{
			whichElement.className = classname;
		}
		else
		{
			whichElement.setAttribute('class',classname);
		}
	}
}
function changeAlignment(whichElement,alignment)
{
	if(typeof(whichElement) == "string")
	{
		if(alignment.type == 'select-one')
		{
			alignment = alignment.options[alignment.selectedIndex].value;
		}
		if(document.getElementById(whichElement).setAttribute('align',alignment))
		{
			document.getElementById(whichElement).setAttribute('align',alignment);
		}
		else
		{
			document.getElementById(whichElement).align = alignment;
		}
	}
	else
	{
		if(alignment.type == 'select-one')
		{
			alignment = alignment.options[alignment.selectedIndex].value;
		}
		if(whichElement.alignment)
		{
			whichElement.alignment = alignment;
		}
		else
		{
			whichElement.setAttribute('align',alignment);
		}
	}
}
function changeBackgroundColor(whichElement,color)
{
	if(document.getElementById(whichElement).bgColor)
	{
		document.getElementById(whichElement).bgColor = color;
	}
	else
	{
		document.getElementById(whichElement).setAttribute('bgcolor',color);
	}
}
function hideElement(whichElement)
{
	if(document.getElementById)
	{
		document.getElementById(whichElement).style.visibility = 'hidden';
	}
	else
	{
		if(document.layers)
		{
			document.whichElement.visibility = 'hidden';
		}
		else
		{
			document.all.whichElement.style.visibility = 'hidden';
		}
	}
}
function showElement(whichElement)
{
	clearTimeOut(whichElement);
	if(document.getElementById)
	{
		document.getElementById(whichElement).style.visibility = 'visible';
	}
	else
	{
		if(document.layers)
		{
			document.whichElement.visibility = 'visible';
		}
		else
		{
			document.all.whichElement.style.visibility = 'visible';
		}
	}
}
function switchView(which_element)
{
	if(isVisible(which_element))
	{
		hideElement(which_element);
	}
	else
	{
		showElement(which_element);
	}
}
function isVisible(which_element)
{
	if(document.getElementById)
	{
		if(document.getElementById(which_element).style.visibility =='visible')
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		if(document.layers)
		{
			if(document.whichElement.visibility =='visible')
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			if(document.all.whichElement.style.visibility =='visible')
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}
function setStyle(whichElement,style_property,style_value)
{
	var browser = getBrowserType();
	if(style_property == "align")
	{
		whichElement.setAttribute("align",style_value);
	}
	else
	{
		if(whichElement.style[style_property])
		{
			whichElement.style[style_property] = style_value;
		}
		else if(browser == "MSIE")
		{
			eval("whichElement.style."+style_property+"='"+style_value+"'");
		}
		else if(whichElement.style.setProperty(style_property,style_value,null))
		{
			whichElement.style.setProperty(style_property,style_value,null);
		}
	}
}
function getStyle(whichElement,style_property)
{
	var browser = getBrowserType();
	var this_value = false;
	//
	if(style_property == "align")
	{
		this_value = whichElement.getAttribute("align");
	}
	else
	{
		if(browser == "MSIE")
		{
			this_value = eval("whichElement.style."+style_property);
		}
		else if(whichElement.style[style_property])
		{
			this_value = whichElement.style[style_property];
		}
		else if(whichElement.style.getPropertyValue(style_property))
		{
			this_value = whichElement.style.getPropertyValue(style_property);
		}
	}
	//
	return this_value;
}
function convertRGBToHex(rgb)
{
	var color = rgb.replace("rgb(","");
	color = color.replace(")","");
	var colors = color.split(",");
	//
	var first = convertToHex(colors[0]);
	var second = convertToHex(colors[1]);
	var third = convertToHex(colors[2]);
	//
	var hex_color = first + second + third;
	return hex_color;
}
function convertToHex(number)
{
	var hex_characters = new Array ("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
	var character1 = Math.floor (number / 16);
	var character2 = number - (character1 * 16);
	var hex_number = hex_characters[character1] + hex_characters[character2];
	return (hex_number);
}
/*                                   **************************                                   */
/************************************    POSITION FUNCTIONS    ************************************/
/*                                   **************************                                   */
function calculateXPos(whichTag,offset)
{
	var rollLink,rollImage;
	//
	var rollTag = document.getElementById(whichTag);
	if(rollTag.nodeName == "IMG")
	{
		rollImage = rollTag;
	}
	else if(rollLink = rollTag.getElementsByTagName('a').item(0))
	{
		rollImage = rollLink.getElementsByTagName('img').item(0);
	}
	else
	{
		rollImage = rollTag.getElementsByTagName('img').item(0);
	}
	//
	var imageW = rollImage.width;
	var thisX = 0;
	//
	if (rollImage.offsetParent)
	{
		while (rollImage.offsetParent)
		{
			thisX += rollImage.offsetLeft
			rollImage = rollImage.offsetParent;
		}
	}
	else if (rollImage.x)
	{
		thisX += rollImage.x;
	}
	//
	if(offset == 'x')
	{
		thisX = thisX + imageW;
	}
	return thisX;
}
function calculateYPos(whichTag,offset)
{
	var rollTag = document.getElementById(whichTag);
	if(rollTag.getElementsByTagName('a').item(0))
	{
		var rollLink = rollTag.getElementsByTagName('a').item(0);
		var rollImage = rollLink.getElementsByTagName('img').item(0);
	}
	else
	{
		var rollImage = rollTag.getElementsByTagName('img').item(0);
	}
	var imageH = rollImage.height;
	//
	var thisY = 0;
	//
	if (rollImage.offsetParent)
	{
		while (rollImage.offsetParent)
		{
			thisY += rollImage.offsetTop
			rollImage = rollImage.offsetParent;
		}
	}
	else if (rollImage.y)
	{
		thisY += rollImage.y;
	}
	//
	if(offset == 'y')
	{
		thisY = thisY + imageH;
	}
	return thisY;
}
function moveElement(whichElement,x,y)
{
	document.getElementById(whichElement).style.left = x;
	document.getElementById(whichElement).style.top = y;
}
function moveElementByPlace(whichElement,placement,offset)
{
	thisX = calculateXPos(placement,offset);
	thisY = calculateYPos(placement,offset);
	//
	document.getElementById(whichElement).style.left = thisX;
	document.getElementById(whichElement).style.top = thisY;
}
/*                                   **************************                                   */
/************************************   PLACEMENT FUNCTIONS    ************************************/
/*                                   **************************                                   */
function removeChildren(whichElement)
{
	if(typeof(whichElement) == "string")
	{
		whichElement = document.getElementById(whichElement);
	}
	if(whichElement.hasChildNodes)
	{
		var length = whichElement.childNodes.length;
		for(i=0;i<length;i++)
		{
			whichElement.removeChild(whichElement.childNodes[0]);
		}
	}
}
function replaceElement(thisElement,oldElement,whichPlace)
{
	var where = document.getElementById(whichPlace);
	where.replaceChild(oldElement,thisElement);
}
function placeElement(tagType,source,width,height,whichPlace)
{
	var thisElement = document.createElement(tagType);
	thisElement.setAttribute('src',source);
	thisElement.setAttribute('width',width);
	thisElement.setAttribute('height',height);
	var where = document.getElementById(whichPlace);
	where.appendChild(thisElement);
}
/*                                   **************************                                   */
/************************************     OBJECT FUNCTIONS     ************************************/
/*                                   **************************                                   */
function isIEObject(which_object)
{
	if(isObject(which_object) && typeof(which_object.constructor != 'function'))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function isArray(which_array)
{
	if(isObject(which_array) && which_array.constructor == Array)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function isObject(which_object)
{
	if((typeof which_object == 'object' && !!which_object) || isFunction(which_object))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function isFunction(which_function)
{
	return typeof which_function == 'function';
}
function isNode(which_element)
{
	return (isObject(which_element) && (typeof which_element.tagName != 'undefined' || typeof which_element.nodeName != 'undefined'));
}
/*                                   **************************                                   */
/************************************   ATTRIBUTE FUNCTIONS    ************************************/
/*                                   **************************                                   */
function setHref(whichElement,href)
{
	if(whichElement.href = href)
	{
		whichElement.href = href;
	}
	else
	{
		whichElement.setAttribute("href",href);
	}
}
/*                                   **************************                                   */
/************************************     TIMER FUNCTIONS      ************************************/
/*                                   **************************                                   */
function setTimeOut(whichFunction,milliseconds,variable)
{
	timeOut[variable] = setTimeout(whichFunction,milliseconds);
}
function clearTimeOut(variable)
{
	clearTimeout(timeOut[variable]);
}
/*                                   **************************                                   */
/************************************     STRING FUNCTIONS     ************************************/
/*                                   **************************                                   */
function replaceAllOccurrencesOfString(this_string,sub_string,replacement_string)
{
	for(var i=0;i<this_string.length;i++)
	{
		if(this_string.indexOf(sub_string) != -1)
		{
			this_string = this_string.substring(0,this_string.indexOf(sub_string)) + replacement_string + this_string.substring(this_string.indexOf(sub_string)+sub_string.length);
		}
		else
		{
			break;
		}
	}
	//
	return this_string;
}
function replaceFirstOccurrenceOfString(this_string,sub_string,replacement_string)
{
	if(this_string.indexOf(sub_string) != -1)
	{
		this_string = this_string.substring(0,this_string.indexOf(sub_string)) + replacement_string + this_string.substring(this_string.indexOf(sub_string)+sub_string.length);
	}
	//
	return this_string;
}
/*                                   **************************                                   */
/************************************     MISC. FUNCTIONS      ************************************/
/*                                   **************************                                   */
function changeText(whichElement,text)
{
	var thisText = document.createTextNode(text);
	var element = document.getElementById(whichElement);
	var whichReplace = element.childNodes[0];
	element.replaceChild(thisText,whichReplace);
}
function removeSubString(this_string,sub_string)
{
	this_string = this_string.substring(0,this_string.indexOf(sub_string)) + this_string.substring(this_string.indexOf(sub_string)+sub_string.length);
	return this_string;
}