//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";}
function ShowVis(a) {document.getElementById(a).style.visibility = "visible";}

//USAGE: <a href="javascript:HideDiv('TargetID');">HideDiv</a>
function HideDiv(a) {document.getElementById(a).style.display = "none";}
function HideVis(a) {document.getElementById(a).style.visibility = "hidden";}

//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";}
}
function ShowHideVis(a) {
	if(document.getElementById(a).style.visibility == "hidden") {document.getElementById(a).style.visibility = "visible";}
	else {document.getElementById(a).style.visibility = "hidden";}
}


//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 SwapSWFt(a,b,c,d,e,f,g)	{var so = new SWFObject(b,c,d,e,f,g); so.addParam('wmode','transparent'); 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;}

//Function to swap a tab grouping's content only (no buttons or tabs are affected):
//('TargetID base name', # selected, # total in this group)
function ShowInfo(c,d,e) {
	for (var i = 1; i <= e; i++) {
		if (i == d)	{document.getElementById(c+i).style.display = "block"; document.getElementById(c+'l'+i).className = "linkon";}
		else		{document.getElementById(c+i).style.display = "none"; document.getElementById(c+'l'+i).className = "linkoff";}
	}	
}


//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;}



