//POPUP WINDOW FUNCTIONS--------------------------------------------------------------------------------------------------------------
//Function to launch Fixed Size Popup Window
//USEAGE: <a href="javascript:PopupWindowFixed('RadRec2.html', 'RadRec', 600, 390)">Click here for pop-out.</a>
function PopupWindowFixed(Source, Name, Width, Height) { 
	Options = "toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=0,width=" + Width + ",height=" + Height;
	window.open(Source, Name, Options); 
}

//Function to launch Adjustable Size Popup Window
//USEAGE: <a href="javascript:PopupWindowFixed('RadRec2.html', 'RadRec', 600, 390)">Click here for pop-out.</a>
function PopupWindow(Source, Name, Width, Height) { 
	Options = "toolbar=0,location=0,directories=0,menubar=0,scrollbars=1,resizable=1,width=" + Width + ",height=" + Height;
	window.open(Source, Name, Options); 
}



//PROPERTY SWAPPING FUNCTIONS---------------------------------------------------------------------------------------------------------
//Functions to Show/Hide Div Tags:
//USAGE: <a href="javascript:ShowDiv('TargetID');">ShowDiv</a>
function ShowDiv(a) {document.getElementById(a).style.display = "block";}

//USAGE: <a href="javascript:HideDiv('TargetID');">HideDiv</a>
function HideDiv(a) {document.getElementById(a).style.display = "none";}

//USAGE: <a href="javascript:ShowHide('TargetID');">ShowHide</a>
//NOTE: Make sure target's display is actually set to block or none first.
function ShowHide(a) {
	if(document.getElementById(a).style.display == "none") {document.getElementById(a).style.display = "block";}
	else {document.getElementById(a).style.display = "none";}
}


//Functions that swap element backgrounds:
//USAGE: <a href="javascript:ClearBkg('TargetID');">ClearBkg</a>
function ClearBkg(a) {document.getElementById(a).style.background = "url()";}

//USAGE: <a href="javascript:SwapBkg('TargetID','#424 no-repeat top center url(images/test.gif)');">SwapBkg</a>
function SwapBkg(a,b) {document.getElementById(a).style.background = b;}

//USAGE: <a href="javascript:SwapBkgUrl('TargetID', 'images/test.gif');">SwapBkgUrl</a>
function SwapBkgUrl(a,b) {document.getElementById(a).style.background = "url('"+b+"')";}

//USAGE: <a href="javascript:SwapBkgNoRepUrl('TargetID', 'images/test.gif');">SwapBkgNoRepUrl</a>
function SwapBkgNoRepUrl(a,b) {document.getElementById(a).style.background = "no-repeat url('"+b+"')";}

//USAGE: <a href="javascript:SwapBkgNoRepCTUrl('TargetID', 'images/test.gif');">SwapBkgNoRepCTUrl</a>
function SwapBkgNoRepCTUrl(a,b) {document.getElementById(a).style.background = "no-repeat center top url('"+b+"')";}


//Functions that swap other element properties:
//USAGE: <a href="javascript:SwapH('TargetID', '400px');">SwapH</a><br />
function SwapH(a,b) {document.getElementById(a).style.height = b;}

//USAGE: <a href="javascript:SwapW('TargetID', '300px');">SwapW</a><br />
function SwapW(a,b) {document.getElementById(a).style.width = b;}

//USAGE: <a href="javascript:SwapColor('TargetID', '#0ff');">SwapColor</a><br />
function SwapColor(a,b) {document.getElementById(a).style.color = b;}

//USAGE: <a href="javascript:SwapProp('TargetID','height','300px');">SwapProp</a><br />
//NOTE: This function will obviously only support the included properties.
function SwapProp(a,b,c) {
	if(b == 'height') {document.getElementById(a).style.height = c;}
	if(b == 'width') {document.getElementById(a).style.width = c;}
	if(b == 'color') {document.getElementById(a).style.color = c;}
	if(b == 'background') {document.getElementById(a).style.background = c;}
	if(b == 'display') {document.getElementById(a).style.display = c;}
	if(b == 'float') {document.getElementById(a).style.float = c;}
	if(b == 'src') {document.getElementById(a).src = c;}
	if(b == 'class') {document.getElementById(a).className = c;}
}



//CLASS AND OBJECT SWAPPING FUNCTIONS-------------------------------------------------------------------------------------------------
//Function to swap css class:
//USEAGE: <a href="javascript:SwapClass('test','code red');">SwapClass</a>
function SwapClass(a,b) {document.getElementById(a).className = b;}

//Function to swap SWF source (Requires presence of swfobject.js):
//USEAGE: <a href="javascript:SwapSWF('TargetID','NewSource','NewTitle','Width#','Height#','Version#','Bkg#');">Swap SWF</a>
function SwapSWF(a,b,c,d,e,f,g)	{var so = new SWFObject(b,c,d,e,f,g); so.write(a);}

//Function to swap the source of an Iframe:
//('TargetID', 'NewSourceURL')
function SwapIframe(a,b) {document.getElementById(a).src = b;}

//Function to swap the source of an image:
//('TargetID', 'Path of image to swap (relative to document)')
function SwapImg(a,b) {document.getElementById(a).src = b;}






//FORM INPUT FUNCTIONS----------------------------------------------------------------------------------------------------------------
//Clear And Replace Form Text:
//USAGE: <textarea id="Comments" onfocus="clearText(this);"onblur="replaceText(this);">Default text here.</textarea>
function clearText(thefield)	{if (thefield.defaultValue == thefield.value) { thefield.value = "" } } 
function replaceText(thefield)	{if (thefield.value == "") { thefield.value = thefield.defaultValue } }

// Replace input field with default value on blur if nothing was entered:
// USAGE: <input type="text" value="Default Value" onfocus="ClearField(this)" onblur="ClearField(this)" />
function ClearField(thefield)	{
	if (thefield.value == "") { thefield.value = thefield.defaultValue } else
	if (thefield.defaultValue == thefield.value) { thefield.value = "" }
}

// Replace input field with GREY default value on blur if nothing was entered (css should match grey color):
// USAGE: <input type="text" value="Default Value" onfocus="GreyField(this,'on')" onblur="GreyField(this,'off')" />
function GreyField(thefield,onOff) {
	if (onOff == 'on') {if (thefield.value == thefield.defaultValue) {thefield.value = ""; thefield.style.color = '#9ff';}} else
	if (thefield.value == "") {thefield.value = thefield.defaultValue; thefield.style.color = '#999';}
}

//General Form Validator (arguments are ID names that are "required". ID names should equal Default Values.):
//USAGE: <form action="javascript:alert('Thanks')" onSubmit="return ValidateForm('Name','Phone','Email');">
function ValidateForm() {
	var ra = arguments; var ralen = ra.length;
	for(i = 0; i < ralen; i++){
		if(document.getElementById(ra[i]).value == document.getElementById(ra[i]).defaultValue) {
			alert("Please enter your "+document.getElementById(ra[i]).defaultValue+".");
			document.getElementById(ra[i]).focus();
			return false;
		}
		if(ra[i] == 'email'){
			if(document.getElementById(ra[i]).value.indexOf("@") == -1) {
				alert("Please enter a valid email address.");
				document.getElementById(ra[i]).focus();
				return false;
			}
		}
	}
	return true;
}

//applies the selected value to a text field.
function showSelection(a,b) {
	var sourceID = a; var targetID = b;
	var selection = document.getElementById(sourceID);
	document.getElementById(targetID).value = selection.options[selection.selectedIndex].text;
}

//Swap Content Of Form Text Box:
//('Text to be displayed', 'Target ID')
function showTitle(a,b)	{var textstring = a; var targetID = b; document.getElementById(targetID).value = textstring;}



//MM FUNCTIONS------------------------------------------------------------------------------------------------------------------------
//The frequently used Find Object Function:
function MM_findObj(n, d) { //v4.01
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}

//Function that swaps images:
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null) {document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Function that restores swapped images:
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//Function that handles image preload:
function MM_preloadImages() { //v3.0
	var d=document;
	if(d.images) {
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0) {d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}
	}
}
