// SET CLASSNAME FOR RANDOM ACTIONS
function colorChange(ele) { 
	var dink = document.getElementById (ele.id + "_dink");
	dink.className = ele.checked ? "highlighted" : "normal";
	}
function setColorChange(ele) { 
	var e = ele + "_dink";
	var dink = document.getElementById(e);
	dink.className = ( document.getElementById(ele).checked == true ) ? "highlighted" : "normal";
	}

// ADD/REMOVE CLASSNAMES (used with methods: onclick, onfocus, etc.)
// hasClass is a utility function... addClass and removeClass are the dealios
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
	}

function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
	}

function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,'');
		}
	}

function unsetClass(ele,ele2,cls) {
	// var c = document.getElementById(ele).className;
	// var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
	var e = document.getElementById(ele);
	var e2 = document.getElementById(ele2);
	if (hasClass(e,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		e.className=e.className.replace(reg,'');
		}
	if( e2 ) {
		if (hasClass(e2,cls)) {
			var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
			e2.className=e2.className.replace(reg,'');
			}
		}
	// document.getElementById(ele).className=document.getElementById(ele).className.replace(cls,'');
	}

function setClass(ele,ele2,cls) {
	// var c = document.getElementById(ele).className;
	// var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
	var e = document.getElementById(ele);
	var e2 = document.getElementById(ele2);
	if (!hasClass(e,cls)) e.className += " "+cls;
	if( e2 ) {
		if (!hasClass(e2,cls)) e2.className += " "+cls;
		}
	}

// ADD/REMOVE FIELD VALUES (used with methods: onclick, onfocus, etc.)
// hasValue is a utility function... setValue and removeValue are the dealios
function hasValue(ele,vlu) {
	return ele.value.match(new RegExp('(\\s|^)'+vlu+'(\\s|$)'));
	}

function setLabel(ele,vlu) {
	if (ele.value=='') ele.value=vlu;
	}

function removeLabel(ele,vlu) {
	if (hasValue(ele,vlu)) {
		var reg = new RegExp('(\\s|^)'+vlu+'(\\s|$)');
		ele.value=ele.value.replace(reg,'');
		}
	}

// SHOW/HIDE DIV EFFECTS
function flip(ele,mode) {
	if(!mode)mode='block';
	var style = document.getElementById(ele).style;
	current=(style.display == mode) ? 'none' : mode;
	style.display = current;
	}

function ctoggle(ele,target,mode) {
	if(ele.checked==true)show(target,mode);
	if(ele.checked==false)hide(target);
	}

function crtoggle(ele,target,mode) {
	if(ele.checked==false)show(target,mode);
	if(ele.checked==true)hide(target);
	}

function cflip(ele,target,target2,mode,mode2) {
	if(ele.checked==true) {
		show(target,mode);
		hide(target2);
		}
	if(ele.checked==false) {
		hide(target);
		show(target2,mode2);
		}
	}

function show(ele,mode) {
	if(!mode)mode='block';
	document.getElementById(ele).style.display = mode;
	}

function hide(ele) {
	document.getElementById(ele).style.display = 'none';
	}

// FORM FIELD EFFECTS
function numeralsOnly(evt)  {
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
		if(charCode > 31 && (charCode < 48 || charCode > 57 ) && charCode != 46) {
			alert( "Enter numbers only in this field." );
			return false;
		}
		return true;
	}

function uncheckRadio(radio) {
		var choice = document.getElementsByName(radio);
		for (i = 0; i < choice.length; i++) {
			if ( choice[i].checked == true ) 
			choice[i].checked = false; 
		}
	}

function updateParent(ele,ele2,vlu,vlu2) {
	parent.document.getElementById(ele).value = vlu;
	parent.document.getElementById(ele2).innerHTML = vlu2;
	parent.Shadowbox.close();
	}

// COOKIE STUFFS
function set_cookie ( name, value, expires_year, expires_month, expires_day, path, domain, secure ) {
	var cookie_string = name + "=" + escape ( value );
	if ( expires_year ) {
		var expires = new Date ( expires_year, expires_month, expires_day );
		cookie_string += "; expires=" + expires.toGMTString();
		}
	if ( path ) cookie_string += "; path=" + escape ( path );
	if ( domain ) cookie_string += "; domain=" + escape ( domain );
	if ( secure ) cookie_string += "; secure";
	document.cookie = cookie_string;	
	}

function delete_cookie ( cookie_name ) {
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 1 );
	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
	}

function get_cookie ( cookie_name ) {
	var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
	if ( results ) {
		return ( unescape ( results[2] ) );
	} else {
		return null;
	}
	}


//////////////////////////////////////////////////////////////////
// qTip - CSS Tool Tips - by Craig Erskine
// http://qrayg.com | http://solardreamstudios.com
//
// Inspired by code from Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
//
// Extended by Jase | http://www.star29.com
// Now uses an array of tags to trigger the qTips
//////////////////////////////////////////////////////////////////

var qTipTags = ["a","span","input","img"]; // just add the tags you want to qTip-ize to the array

var qTipX = 20; //This is qTip's X offset//
var qTipY = -10; //This is qTip's Y offset//

//There's No need to edit anything below this line// (unless you want to)
tooltip = {
	name : "qTip",
	offsetX : qTipX,
	offsetY : qTipY,
	tip : null
	}

tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	for ( var tag in qTipTags ) {
	
		var a, sTitle;
		var anchors = document.getElementsByTagName (qTipTags[tag]);
	
		for (var i = 0; i < anchors.length; i ++) {
			a = anchors[i];
			sTitle = a.getAttribute("title");
			if(sTitle) {
				a.setAttribute("tiptitle", sTitle);
				a.removeAttribute("title");
				a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
				a.onmouseout = function() {tooltip.hide()};
			}
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

/*
// onload is off here... worked around this by piggy-backing the qTip call intot he shadowbox onload handler so there's no onload conflict
window.onload = function () {
	tooltip.init ();
}
*/

//////////////////////////////////////////////////////////////////
// End qTip Script
//////////////////////////////////////////////////////////////////

/*************************************************************
* NLB Background Color Fader v1.0
* Author: Justin Barlow - www.netlobo.com
*
* Description:
* The Background Color Fader allows you to gradually fade the
* background of any HTML element.
*
* Usage:
* Call the Background Color Fader as follows:
*   NLBfadeBg( elementId, startBgColor, endBgColor, fadeTime );
*
* Description of Parameters
*   elementId - The id of the element you wish to fade the
*             background of.
*   startBgColor - The background color you wish to start the
*             fade from.
*   endBgColor - The background color you want to fade to.
*   fadeTime - The duration of the fade in milliseconds.
*************************************************************/

var nlbFade_hextable = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ]; // used for RGB to Hex and Hex to RGB conversions
var nlbFade_elemTable = new Array( ); // global array to keep track of faded elements
var nlbFade_t = new Array( ); // global array to keep track of fading timers
function NLBfadeBg( elementId, startBgColor, endBgColor, fadeTime )
{
	var timeBetweenSteps = Math.round( Math.max( fadeTime / 300, 30 ) );
	var nlbFade_elemTableId = nlbFade_elemTable.indexOf( elementId );
	if( nlbFade_elemTableId > -1 )
	{
		for( var i = 0; i < nlbFade_t[nlbFade_elemTableId].length; i++ )
			clearTimeout( nlbFade_t[nlbFade_elemTableId][i] );
	}
	else
	{
		nlbFade_elemTable.push( elementId );
		nlbFade_elemTableId = nlbFade_elemTable.indexOf( elementId );
	}
	var startBgColorRGB = hexToRGB( startBgColor );
	var endBgColorRGB = hexToRGB( endBgColor );
	var diffRGB = new Array( );
	for( var i = 0; i < 3; i++ )
		diffRGB[i] = endBgColorRGB[i] - startBgColorRGB[i];
	var steps = Math.ceil( fadeTime / timeBetweenSteps );
	var nlbFade_s = new Array( );
	for( var i = 1; i <= steps; i++ )
	{
		var changes = new Array( );
		for( var j = 0; j < diffRGB.length; j++ )
			changes[j] = startBgColorRGB[j] + Math.round( ( diffRGB[j] / steps ) * i );
		if( i == steps )
			nlbFade_s[i - 1] = setTimeout( 'document.getElementById("'+elementId+'").style.backgroundColor = "'+endBgColor+'";', timeBetweenSteps*(i-1) );
		else
			nlbFade_s[i - 1] = setTimeout( 'document.getElementById("'+elementId+'").style.backgroundColor = "'+RGBToHex( changes )+'";', timeBetweenSteps*(i-1) );
	}
	nlbFade_t[nlbFade_elemTableId] = nlbFade_s;
}
function hexToRGB( hexVal )
{
	hexVal = hexVal.toUpperCase( );
	if( hexVal.substring( 0, 1 ) == '#' )
		hexVal = hexVal.substring( 1 );
	var hexArray = new Array( );
	var rgbArray = new Array( );
	hexArray[0] = hexVal.substring( 0, 2 );
	hexArray[1] = hexVal.substring( 2, 4 );
	hexArray[2] = hexVal.substring( 4, 6 );
	for( var k = 0; k < hexArray.length; k++ )
	{
		var num = hexArray[k];
		var res = 0;
		var j = 0;
		for( var i = num.length - 1; i >= 0; i-- )
			res += parseInt( nlbFade_hextable.indexOf( num.charAt( i ) ) ) * Math.pow( 16, j++ );
		rgbArray[k] = res;
	}
	return rgbArray;
}
function RGBToHex( rgbArray )
{
	var retval = new Array( );
	for( var j = 0; j < rgbArray.length; j++ )
	{
		var result = new Array( );
		var val = rgbArray[j];
		var i = 0;
		while( val > 16 )
		{
			result[i++] = val%16;
			val = Math.floor( val/16 );
		}
		result[i++] = val%16;
		var out = '';
		for( var k = result.length - 1; k >= 0; k-- )
			out += nlbFade_hextable[result[k]];
		retval[j] = padLeft( out, '0', 2 );
	}
	out = '#';
	for( var i = 0; i < retval.length; i++ )
		out += retval[i];
	return out;
}
if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function( val, fromIndex ) {
		if( typeof( fromIndex ) != 'number' ) fromIndex = 0;
		for( var index = fromIndex, len = this.length; index < len; index++ )
			if( this[index] == val ) return index;
		return -1;
	}
}
function padLeft( string, character, paddedWidth )
{
	if( string.length >= paddedWidth )
		return string;
	else
	{
		while( string.length < paddedWidth )
			string = character + string;
	}
	return string;
}
