/**
 * baUtilities.js
 *
 * Description: Various functions and setups for BigAdmin.
 *
 * Last Updated: 10/04/01 Robert Weeks rweeks@eng
 */


/*******************************************************
 * Vars
 *******************************************************/


/*******************************************************
 * Methods
 *******************************************************/
 
/**
 * gotoMOTDMonth
 *
 * Load the location given by the selected index of the
 * crumbForm
 */
function gotoCommand() {
	var shellMeForm = document.shellMeForm;
	var selectedIndex = shellMeForm.commandArchive.selectedIndex;
	var newLocation = shellMeForm.commandArchive.options[selectedIndex].value;
	
	// Is this one of the first 2 selected?
	if (selectedIndex < 2) {
		shellMeForm.commandArchive.options[0].selected = true;
		return;
	}
	
	// Else go to the value
	shellMeForm.commandArchive.options[0].selected = true;
	self.location = newLocation;
	return;
	
} // gotoMOTDMonth()

/**
 * Open up the printer-friendly page in a separate window.
 */
function openPrintFriendly(url,width,height) {
	var name = 'printFriendlyView';

	// Validate the args
	if (url == null) url = '';
	if (width == null) width = 710;
	if (height == null) height = 650;

	pfp = window.open(url, name, 
					  'width=' + width + ',height=' + height + 
					  ',resizable=no,scrollbars=yes,menubar=yes,toolbar=no,' +
					  'location=no,directories=no,status=no');
					  
	pfp.focus();
}

 
/**
 * openXPertPage
 * Open the xpert page for the desired resut (arg)
 */
function openXPertPage(url) {
	window.name='cd0ContentFrame';
	var xpertWin = window.open(url,'xpertWin','scrollbars=yes,location=no,status=no,menubar=no,height=400,height=500,resizable=yes');
	xpertWin.focus();
} // openDescriptionPage()


/**
 * openDescriptionPage
 * Open the page window...
 */
function openDescriptionPage(dir,page) {
	window.name='cd0ContentFrame';
	var desString = dir + '/' + page + '.html#' + page;
	var desWin = window.open(desString,'description','scrollbars=yes,location=no,status=no,menubar=no,height=240,width=420,resizable=yes');
	desWin.focus();
} // openDescriptionPage()


/**
 * tearSearch
 * Tear off the search window to be seperate
 */
function tearSearch() {
	// Make sure we name the window the correct target
	// This is in correspondence with all the other
	// popups as well
	window.name='cd0ContentFrame';
	var searchWin =
		window.open('/bigadmin/common/searchSmall.html','searchWin',
		            'scrollbars=no,location=no,status=no,menubar=no,width=240,height=120,resizable=yes');
} // tearSearch


/**
 * For The Xtreme Tech Show
 * Open the review window.
 */
function openReviewWindow(page) {
  var desWin = window.open(page,'description','scrollbars=yes,location=no,status=no,menubar=no,height=360,width=450,resizable=yes');
  desWin.focus();
} // openReviewWindow()

/**
 * Open up the submittal window
 */
function openLinkForm() {
	window.name='cd0ContentFrame';
	var linkForm = window.open("https://www.sun.com/bigadmin/common/submittals.jsp","linkForm");
} // openLinkForm()

/**
 * Open the product submittal form - make sure it is pointing to the secure server.
 */
function openProductLinkForm() {
	window.name='cd0ContentFrame';
  var productLinkForm = window.open("https://www.sun.com/bigadmin/common/submittals.jsp","linkForm");
} // openLinkForm()



/*******************************************************
 * Begin HCL Methods
 *******************************************************/
 
/**
 * Open HCL Submittal Form
 */
function openHCLSubmittal(which) {
	window.name='cd0ContentFrame';
	var whichSubmittal = "";
	var url = "/bigadmin/hcl/submittal/submit.jsp";
	var hclLinkForm = window.open(url,'hclLinkForm','width=500,height=650,scrollbars');
	hclLinkForm.focus();
} // openHCLSubmittal()

/**
 * Open HCL Comment Form
 */
function openHCLComment(url) {
	window.name='cd0ContentFrame';
	var hclComment = window.open(url,'hclComment','width=450,height=650,scrollbars');
	hclComment.focus();
} // openHCLComment()

 
/**
 * openHCLDetailPage
 * Open the detail for the HCL item.
 */
function openHCLDetailPage(dir,page) {
	window.name='cd0ContentFrame';
	var desString = dir + '/' + page + '.html';
	var detWin = window.open(desString,'HCLDetail','scrollbars=yes,location=no,status=no,menubar=no,width=450,height=650,resizable=yes');
	detWin.focus();
} // openHCLDetailPage()

function openHCLHelpPage(page) {
	var desString = '/bigadmin/hcl/submittal/help.jsp?helpLink=' + page;
	var helpWin = window.open(desString,'helpWin','scrollbars=yes,location=no,status=no,menubar=no,width=400,height=200,resizable=yes');
	helpWin.focus();
} // openHelpPage()

function openHelpPage(dir,page,position) {
	window.name='cd0ContentFrame';
	var desString = dir + '/' + page + '.html#' + position;
	var helpWin = window.open(desString,'helpWin','scrollbars=yes,location=no,status=no,menubar=no,width=400,height=350,resizable=yes');
	helpWin.focus();
} // openHelpPage()


/*******************************************************
 * End HCL Methods
 *******************************************************/

/**
 * Toggle a specific document element.
 */
function toggle(div) {
	var el = getDocObject(div);

	if (el.style.display == 'block')
		el.style.display = 'none';
	else
		el.style.display = 'block';
}

function toggleContentBlock(blockName) {
	var blockObj = getDocObject(blockName + '_content');
	var toggleAnchor = getDocObject(blockName + '_anchor');
	var blockObjStyle = "";
	
	var showToggle = "[+] Show";
	var hideToggle = "[-] Hide";
	
	// If we don't have an obj, no reason to go further
	if (blockObj == null) return;
	
	// Now we can test and toggle
	if (blockObj.style.display) {
		blockObjStyle = blockObj.style.display;
	}
	
	// Test it
	if (blockObjStyle == "none") {
		blockObj.style.display = "inline";
		toggleAnchor.innerHTML = hideToggle;
	} else if (blockObjStyle == "inline") {
		blockObj.style.display = "none";
		toggleAnchor.innerHTML = showToggle;
	}

} // toggleContentBlock()


/**
 * Param encode what we can/need for the filters that utilize OneSearch
 */
function filterParamEncode(sStr) {
	return escape(sStr).replace(/\\/g, '%5C').replace(/\//g, '%2F').replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27');
}

/**
 * Fill out the selection given with the array given.
 */
function fillSelectionOptions(selectComponentName,arrayToParse) {
	var selectComponent = getDocObject(selectComponentName);
	clearOptions(selectComponent, '');
	for (var i=0; i < arrayToParse.length; i++) {
		if (arrayToParse[i] != null && arrayToParse[i] != '')
			selectComponent.options[i+1] = new Option(arrayToParse[i], arrayToParse[i], false, false);
	}
	selectComponent.options[0].selected = true;
} // fillSelectionOptions();

/**
 * 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()

/** 
 * getFormObject
 *
 * Determines the platform and returns the corresponding object
 *
 * @param name of object
 * @param form object
 * @return reference to that object
 */
function getFormObject(objName,thisForm) {
	if (document.layers) 
		return thisForm.elements[objName];
	else if (document.getElementById) 
		return thisForm.elements[objName];
	else if (document.all)
		return thisForm.elements[objName];

	// We need  to return something
	return thisForm.elements[objName];

} // getFormObject()

/**
 * 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;
	if (title != '') {
		optionList.options[0] = new Option(title,'',true,true);
	}
} // clearOptions()

/**
 * redirectPage
 *
 * Used for pulldown redirects.
 * Form must be named redirectForm
 * Select must be named redirectPage
 */
function redirectSelect() {
	var redirectForm = document.redirectForm;
	var selectedIndex = redirectForm.redirectPage.selectedIndex;
	var newLocation = redirectForm.redirectPage.options[selectedIndex].value;

	// Is this one of the first 2 selected?
	if (selectedIndex < 2 || newLocation.indexOf('#') != -1) {
		redirectForm.redirectPage.options[0].selected = true
		return;
	}

	// Else go to the value
	self.location = newLocation;

} // redirectSelect()








