

function validateForm(currForm)
{
	// alert ("validateForm");
	setSubCollection();

}


function setSubCollection() {

	var currForm = document.forms["gsa"];
	if (currForm.elements["restrict_sub"].type == "select-one")
	{
		// Extract tab from subcollection
		var subRestrictCollection = currForm.elements["restrict_sub"].options[currForm.elements["restrict_sub"].selectedIndex].value;
		if (subRestrictCollection == "bugs")
			currForm.elements["restrict"].value = "engineer";
		else if (subRestrictCollection == "articles")
			currForm.elements["restrict"].value = "articles";
		else if (subRestrictCollection == "codeshare")
			currForm.elements["restrict"].value = "codeshare";

		else 	
			currForm.elements["restrict"].value = subRestrictCollection;
		// alert ("tab = " + currForm.elements["restrict"].value);

	}
	currForm.submit();

}

function addFormElements()
{
	var currForm = document.forms["gsa"];
	if (typeof(currForm.elements["restrict"]) == "undefined")
	{
		var qPairs = ParseQuery();
		var subCollection = qPairs["restrict"];
		if (subCollection == null || subCollection == "" || typeof(subCollection) == 'undefined')
			subCollection = "";

		document.writeln ('<input type="hidden" name="restrict" value="' + subCollection + '">');
	}
	// alert (currForm.elements["restrict"].value);

	if (typeof(currForm.elements["restrict_sub"]) == "undefined")
	{
		document.writeln ('<input type="hidden" name="restrict_sub">');
	}

	if (typeof(currForm.elements["sitesearch"]) == "undefined")
	{
		document.writeln ('<input type="hidden" name="sitesearch">');
	}
}

function resetSubRestrictCollection(formElement)
{

	if (formElement.type == "select-one")
	{
		formElement.options[0].selected = true;
		formElement.options[0].value = "";
	} else 
		formElement.value = "";
}

function resetPullDown(formElement)
{

	if (formElement.type == "select-one")
	{
		formElement.options[0].selected = true;
		formElement.options[0].value = "";
	} else 
		formElement.value = "";
}

function setCollection(collectionName)
{

	var currForm = document.forms["gsa"];

	/*
	var qPairs = ParseQuery();
	var subRestrictCollection = qPairs["restrict_sub"];
	if (typeof(subRestrictCollection) != "undefined" && 
		subRestrictCollection.indexOf(collectionName + "_") != -1)
		currForm.elements["restrict"].value = subRestrictCollection;
	else 
	*/

	if (collectionName == "all") {
		currForm.elements["restrict"].value = "";
	} else {
		currForm.elements["restrict"].value = collectionName;
	}

	resetSubRestrictCollection(currForm.elements["restrict_sub"]);

	if (collectionName != "edocs")
		resetPullDown(currForm.elements["sitesearch"]);

	// alert (currForm.elements["restrict"].value);
	currForm.submit();


}

function Tab (collection, imagePath) {

	var tmpObj = new Object();
	tmpObj.collection = collection;
	tmpObj.imagePath = imagePath;

	return tmpObj;

}

function showTabs(tabArray) {

	var selectedTab = "";
	var qPairs = ParseQuery();
	var subCollection = qPairs["restrict"];
	var subRestrictCollection = qPairs["restrict_sub"];
	if (subCollection == null || subCollection == "" || typeof(subCollection) == 'undefined')
		selectedTab = tabArray[0].collection;	
	else if (typeof(subRestrictCollection) != "undefined" && 
		subRestrictCollection.indexOf("hr_") != -1)
	{
		selectedTab = "hr";

	} else if (typeof(subRestrictCollection) != "undefined" && 
		subRestrictCollection.indexOf("mktg_") != -1)
	{
		selectedTab = "mktg";

	} else if (typeof(subRestrictCollection) != "undefined" && 
		(subRestrictCollection.indexOf("bugs") != -1 &&
		subRestrictCollection.indexOf("engineer_") != -1) )
	{
		selectedTab = "engineer";

	} else if (typeof(subRestrictCollection) != "undefined" && 
		subRestrictCollection.indexOf("articles") != -1)
	{
		selectedTab = "d2d";

	} else if (typeof(subRestrictCollection) != "undefined" && 
		subRestrictCollection.indexOf("codeshare") != -1) )
	{
		selectedTab = "d2d";

	} else if (typeof(subRestrictCollection) != "undefined" && 
		subRestrictCollection.indexOf("news_") != -1)
	{
		selectedTab = "news";

	} else selectedTab = subCollection;
	// alert (subCollection);
	
	for (var i=0; i<tabArray.length; i++)
	{
	
		currentTab = tabArray[i];
		offImage = currentTab.imagePath + ".gif";
		onImage = currentTab.imagePath + "_f2.gif";
		if (selectedTab == currentTab.collection) {
			onImage = offImage = currentTab.imagePath + "_f2.gif";
		}
		document.writeln("<td><a href=\"javascript:onClick=setCollection('" + currentTab.collection + "');\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('" + currentTab.collection + "','','" + onImage + "',1);\" ><img name=\"" + currentTab.collection + "\" src=\"" + offImage + "\" border=\"0\"/></a></td>");
	
	}

}


function searchOption (dataVal, displayVal) {

	var tmpObj = new Object();
	tmpObj.dataVal = dataVal;
	tmpObj.displayVal = displayVal;

	return tmpObj;

}

function displayOptions(optionsArray, selectedVal, formField, fieldName) {

	
	for (var i=0; i<optionsArray.length; i++) {
		currOption = optionsArray[i];
		document.writeln ('<option value="' + currOption.dataVal + '"');
		if (selectedVal == currOption.dataVal) {
			document.write (" selected");
		}		
		document.writeln ('>' + currOption.displayVal + '</option>');
	}

}

