/***Copyright and coded by Dakusan, please do not steal, but you may study and learn... - See http://www.castledragmire.com/Copyright for more information. ***/
//Generic functions
var
IsIE=(navigator.appName.indexOf("Microsoft")!=-1),
IsIE6=(IsIE && parseFloat(navigator.appVersion.split("MSIE")[1])<7);

//Assign mouseover menu button highlights (Save a little HTML...)
function M(Obj)
{
	Obj.onmouseover=function() { MO(Obj,1); };
	Obj.onmouseout=function() { MO(Obj,0); };
	MO(Obj,1);
}

//Perform mouseover menu button highlights
function MO(Obj,State)
{
	if(!IsIE6)
		Obj.src=(State ? $('ButtonSelectPic').src : $('DDLogoPic').src);
	else
		Obj.style.filter=(State ? "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$('ButtonSelectPic').src+"', sizingMethod='scale')" : "");
}

var
$   =function(O)	{return document.getElementById(O);}, //GetElement
$CP =function(O,P)	{for(var i in P)eval("O."+i+"=P[i];");return O;}, //Copy Properties
$GE =function(O)	{return typeof(O)=="string"?$(O):O;}, //GetElement by String or Object
$CE =function(T,P,A)	{T=document.createElement(IsIE&&typeof(P)=="object"&&'name' in P?'<'+T+' name="'+P.name+'">':T);if(P)$CP(T,P);if(A)$GE(A).appendChild(T);return T;}, //CreateElement of Type "T", Copy Properties "P", and Append to "A"
$EV =function(E)	{return IsIE?window.event:E;}, //Get the event object
$EVS=function(E)	{return $EV(E)[IsIE?'srcElement':'currentTarget'];}, //Get the source element of the event
$SE =function(O,E,F)	{ if(IsIE) eval("O[E]=function() {"+F+"};"); else O.setAttribute(E,F); }, //SetEvent
$GT =function(L)	{ document.location.href=document.getElementsByTagName('base')[0].href+L; };

//Creates a dynamic function, passed as a string, with all variables inside of it defined in the Object Vars
function DynamicFunc(Func, Vars)
{
	for(var i in Vars)
		eval("var "+i+"=Vars[i];");
	eval("var F=function(event) {"+Func+"}");
	return F;
}

//Turn on PNG Transparency for needed objects if in IE6
function TransparentBackgrounds(PopupBox, ContentTable)
{
	if(!IsIE6)
		return;

	//Content table dynamic texture
	if(ContentTable==true)
		for(var i=2;i<=3;i++)
			$CP($("d"+i), {'style.filter':'progid:DXImageTransform.Microsoft.Alpha(opacity='+(i==2 ? 75 : 50)+')', 'style.backgroundImage':'url(BG'+i+'S.jpg)'});

	//Popup box
	if(PopupBox==true)
		for(var i=0;i<3;i++)
			for(var n=0;n<3;n++)
			{
				var MyCell=$("PopupWindow").firstChild.rows[i].cells[n], MyUrl=MyCell.style.backgroundImage.substr(3);
				$CP(MyCell, {'style.filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+(MyUrl=MyUrl.substr(0,MyUrl.length-1))+"', sizingMethod='scale')", 'style.backgroundImage':''});
			}
}

//Toggle the display of an item
function Toggle(O)
{
	O=(typeof(O)=='string' ? $(O) : O);
	O.style.display=(O.style.display!='none' ? 'none' : 'block');
	RefreshContentBox();
	return false;
}

//Look for definitions and HideTexts
function CreateDefines()
{
	//Now process HideLinks by looping through all spans and divs
	var HTs=[document.getElementsByTagName('span'), document.getElementsByTagName('div')]; //Wish getElementsByClassName was valid in everything
	for(var n in HTs)
		for(var i in HTs[n])
			if(HTs[n][i].className && HTs[n][i].className.search('HideText')!=-1)
				$SE(HTs[n][i], 'onclick', 'HideTextToggle(this,0,event);');
			else if(HTs[n][i].className && HTs[n][i].className.search('ToggleText')!=-1)
				$SE(HTs[n][i], 'onclick', 'HideTextToggle(this,1);');
	return 0;
}
function HideTextToggle(O,T,E)
{
	if(T==0) //If clicking a hide text, ignore triggers on input boxes and anchors
	{
		var C=$EV(E);
		C=(C.srcElement!==undefined ? C.srcElement : C.explicitOriginalTarget);
		for(;C && (C.className===undefined || C.className.indexOf('HideText')==-1);C=C.parentNode) //Loop until 'HideText' class is found
			if(C.tagName!==undefined && (C.tagName.toLowerCase()=='a' || C.tagName.toLowerCase().indexOf('input')!=-1)) //If an anchor or input box is found, exit prematurely
				return;
	}

	O.style.display='none';
	O[(T==0 ? 'previous' : 'next')+'Sibling'].style.display='inline';
}

function EncodeFormString(Str)
{
	var RepArr=[/"/g,'%22', /'/g,'%27', /\+/g,'%2B', /\r/g,'%13', /\n/g,'%10', /_/g,'%5F', / /g,'_', /\//g,'%2F'];
	for(var i=0;i<RepArr.length;i+=2)
		Str=Str.replace(RepArr[i], RepArr[i+1]);
	return Str;
}

