/**
 * linkSubmittals.js
 *
 * Library for basc submissions...
 *
 */


/**********************************************
 * Initialization
 **********************************************/

/** These are also mirrored in $BASC/www/js/linkSubmittals.js **/
var completeTopicArray = new Array("Application Management","Automation","Availability","Backup/Restore","Boot Process","Certification","Configuration","Crashes & Dumps","Data","Database","Debugging","Desktop Environments","Developer","Devices and Peripherals","Disk Commands","Disk Partitions","Driver Parameters","Drivers","DTrace","Email","Environmentals","Fault Management","File Manipulation","File Transfer","Filesystems","Firmware","Freeware","General","Hardware","Humor","Java","Java Deployment","Kernel","Identity Management","Installation","Interoperability","LAMP/SAMP","Languages","Linux","Load Balancing","Logs","Memory","Middleware","Migration","Monitoring","Name Services","Network Information","Network Tuning","Networking","News","OpenSolaris","OpenSource","OS","Packages","Patches and Releases","Performance","Peripherals","Process Control","Printing","Processes","Power Management","Resource Management","Release Engineering","Reliability","Reporting","Resource Management","Scripts","Servers","Security","Services Management","Software","Solaris","Storage","Sun","Sun Java System","System Management","System Messages","Tools","Time","Troubleshooting","Tuning","Upgrade","Utilities","Users and Groups","Virtualization","Volume Management","Web");

var blogArray = completeTopicArray.sort();
var booksArray = completeTopicArray.sort();
var bluePrintsArray	= completeTopicArray.sort();
var docsArray = completeTopicArray.sort();
var educationArray = completeTopicArray.concat(new Array("Resources")).sort();
var fromTheForumsArray	= completeTopicArray.sort();
var faqArray	= completeTopicArray.sort();
var resourcesArray = completeTopicArray.concat(new Array("AMD","Humor","Software")).sort();
var scriptsArray = completeTopicArray.concat(new Array("Applications/Utilities")).sort();
var servicesArray = new Array("Scripts","SunSolve","Support","Commerce","General");
var shellmeArray = new Array("Additional Resources","Debugging","Disk Commands","Driver Params","File Manipulation","File System","File Transfer","General","Hardware","Kernel","Memory","Network Information","Network Tuning","Processes","Resource Management","Route Configuration","Searching Items","Security","Setting Term Options","Snoop","Swap Files","Swap Space","System Configuration","System Information/Monitoring");
var downloadsArray = new Array("Database","Freeware","General","Management","Networking","Open Source","Security","Sun Software","Tools","Utilities","Web");
var softwareArray = new Array("Database","General","Management","Networking","Security","Tools","Utilities","Web");
var hardwareArray = new Array("Desktop/Server","General","Peripherals","Storage");
var patchesArray = new Array("Firmware Patches");
var discussionArray = completeTopicArray.sort();
var hclArray = new Array("Resources");
var sunDocsArray	= new Array("Configuration","General","Hardware","Middleware","Migration","Networking","Patches","Performance","Security","Services","Virtualization");
var techTipsArray = completeTopicArray.sort();
var videosArray = completeTopicArray.sort();

// Our array of arrays
var categoryArray = new Array(faqArray,blogArray,booksArray,discussionArray,docsArray,educationArray,fromTheForumsArray,hclArray,patchesArray,resourcesArray,scriptsArray,servicesArray,shellmeArray,downloadsArray,bluePrintsArray,sunDocsArray,techTipsArray,softwareArray,hardwareArray,videosArray);

// The scripting languages. This array is duped in $BASC/www/js/linkSubmittals
// as well as in $BASC/lib/resourceSubmitLib.ph for submissions.
var scriptLanguageArray = new Array("awk","bash","bourne","c","c shell","dtrace","ecma","expect","f3","korn","java","javascript","jruby","nawk","perl","php","python","ruby","sed"); 


/**********************************************
 * Methods
 **********************************************/
 
/**
 * Change the categories to correspond with the section we are trying to submit.
 * This is for the new version (non-popup)
 */
function updateCategories(selectedValue) {
	var categories = getObject('ba_Category');
	var sections = getObject('ba_Section');
	var scriptLang = getObject('script_lang');
	var sectionIndex = sections.selectedIndex;
	var sectionName = sections.options[sectionIndex].value;
	var newCategory = "";
	var lang = "";
	
	// Clear our the existing list
	clearOptions(categories, ' -- Select Category -- ');

	// Load in the categories to be selected....
	if (sectionIndex > 0) {
		newCategory = categoryArray[sectionIndex - 1];

		for (var i=0; i < newCategory.length; i++) {
			categories.options[i+1] = new Option(newCategory[i], newCategory[i], false, false);
			categories.options[0].selected = true;
		} // for...
	} // if..
	
	// If there was as selected value passed in, set it here
	if (selectedValue != null) {
		categories.value = selectedValue;
	}
	
	// Now for the scripts part
	clearOptions(scriptLang, ' -- Select Script Language -- ');
	if (sectionName == 'Scripts') {
		scriptLang.disabled = false;
		
		for (var s=0; s < scriptLanguageArray.length; s++) {
			scriptLang.options[s+1] = new Option(scriptLanguageArray[s], scriptLanguageArray[s], false, false);
			scriptLang.options[0].selected = true;
		}
	} else {
		scriptLang.disabled = true;
	}

} // changeCategories()

/**
 * Change the categories to correspond with the section we are trying to submit.
 */
function changeCategories() {
	var catMenu = getObject('linkCategory');
	var sectionMenu = getObject('submittalSubject');
	var sectionIndex = sectionMenu.selectedIndex;
	var newCategory = '';

	// Clear out the existing list
	clearOptions(catMenu, ' -- Select Category -- ');
	
	// Load in the categories to be selected....
	if (sectionIndex > 0) {
		newCategory = categoryArray[sectionIndex - 1];

		for (var i=0; i < newCategory.length; i++) {
			catMenu.options[i+1] = new Option(newCategory[i], newCategory[i], false, false);
			catMenu.options[0].selected = true;
		} // for...
	} // if..

} // changeCategories()

/**
 * clearOptions
 *
 * Clears out the given option list and places
 * the '0' index with the title passed in.
 *
 * @param The object (optionList) to be cleared
 * @param The title of the initial option after the list is cleared
 */
function clearOptions(optionList, title) {
	optionList.length = 0;
	optionList.options[0] = new Option(title,'',true,true);
} // clearOptions() 
 
/** 
 * getObject
 *
 * Determines the platform and returns the corresponding object.
 * Used for form objects.
 *
 * @param name of object
 * @return reference to that object
 */
function getObject(objName) {
	if (document.layers) 
		return document.linkForm.elements[objName];
	else if (document.getElementById) 
		return document.linkForm.elements[objName];
	else if (document.all)
		return document.linkForm.elements[objName];

} // getObject()


/**
 * Generic object grabber for getting an object from the DOM.
 *
 * @param The object name
 * @return The object
 */
function getDocObject(objectName) {
	var returnObj;
	
	// Grab the object
	if (document.getElementById && !(document.all)) {
		returnObj = document.getElementById(objectName);
	} else if (document.all) {
		returnObj = document.all[objectName];
	}
	
	return returnObj;
	
} // getDocObject()



