
/**
* This javascript is used to support buttons and/or actions in forms.
* see pwgsc.reo.common.presentation.ButtonsForm.java for common buttons and actions
* buttons may be extended in specific use-case form bean
*/

/**
* This function will show the javascript button images in an html <div> tag that are hidden by default.
* The "id" is the id of the div tag around the buttons eg: <div class="imageButtons" id="buttons">.
* The stylesheet class "imageButtons" should set the display style to "none" by default.
* When javascript is disabled in a browser, the javascript buttons will remain hidden.
* When javascript is enabled, calling fn_showImageButtons("buttons") in your html will change the
* display style to "inline" and show the image buttons, presumably over top of the normal form buttons.
*/
function fn_showButtons(id) {
	var buttons = window.document.getElementById(id);
        if(buttons !== null){
            buttons.style.display = "inline";
        }
}

function fn_hideButtons(id) {
	var buttons = window.document.getElementById(id);
        if(buttons !== null){
            buttons.style.display = "none";
        }
}

/**
* these functions are used during onload of a page to show/hide buttons if js is enabled
*/

function fn_buttons() {
	fn_showImageButtons();
	fn_showImageButtonsTop();
	fn_showImageButtonsTops();
	fn_showImageButtonsTopss();
	fn_hideFormButtons();
	fn_hideFormButtonsTop();
	fn_hideFormButtonsTops();
	fn_hideFormButtonsTopss();
	
}

function fn_showImageButtons() {
	fn_showButtons("imageButtons");
	fn_showButtons("imageButtonsAdd");
	fn_showButtons("imageButtonsAlt");
}

function fn_showImageButtonsTop() {
	fn_showButtons("imageButtonsTop");
	fn_showButtons("imageButtonsTopAdd");
	fn_showButtons("imageButtonsTopAlt");
}

function fn_showImageButtonsTops() {
	fn_showButtons("imageButtonsTops");
	fn_showButtons("imageButtonsTopsAdd");
	fn_showButtons("imageButtonsTopsAlt");
}

function fn_showImageButtonsTopss() {
	fn_showButtons("imageButtonsTopss");
	fn_showButtons("imageButtonsTopssAdd");
	fn_showButtons("imageButtonsTopssAlt");
}

function fn_hideFormButtons() {
	fn_hideButtons("formButtons");
	fn_hideButtons("formButtonsAdd");
	fn_hideButtons("formButtonsAlt");
}

function fn_hideFormButtonsTop() {
	fn_hideButtons("formButtonsTop");
	fn_hideButtons("formButtonsTopAdd");
	fn_hideButtons("formButtonsTopAlt");
}

function fn_hideFormButtonsTops() {
	fn_hideButtons("formButtonsTops");
	fn_hideButtons("formButtonsTopsAdd");
	fn_hideButtons("formButtonsTopsAlt");
}

function fn_hideFormButtonsTopss() {
	fn_hideButtons("formButtonsTopss");
	fn_hideButtons("formButtonsTopssAdd");
	fn_hideButtons("formButtonsTopssAlt");
}


/**
* the functions below are used to support the ButtonsForm.java class plus any use-case specific forms.
* They include:
*   fn_setActionFlag(a, b) - sets form element action flag (a + "Action") to Boolean (b)
*   fn_setButton(a) - sets form element button to value String(a), and calls fn_setActionFlag(a, true)
*	fn_submit(a) - submits default form [0] with optional action a
*   fn_submitForm(f, a)
*/

// set form element action flag (a + "Action") to boolean (b) in form (f) if present
// eg: a = search, b = true // results in <someFormElement name="searchAction" value="true" ... >
function fn_setActionFlag(a, b, f) {
	var form = document.forms[0];
	var elementName = a + "Action";
	if (f !== null) {
		form = document.forms[f];
	} 


	if (form.elements[elementName]) {
		
		form.elements[elementName].value = b;
	}
}

// set form element action flag to true.  see fn_setActionFlag(a, b, f)
// set form element "button" to value String(a) if present - eg: a = search // results in <someFormElement name="button" value="search" ... >
function fn_setButton(a,f) {
	var elementName = "button";
	var form = document.forms[0];
	if (f !== null) {
		form = document.forms[f];
	} 
	fn_setActionFlag(a, "true", f);
	if (form.elements[elementName]) {
		
		form.elements[elementName].value = a;
	}
}

// function to submit default form
function fn_submit(a) {
	var form = document.forms[0];
	if (a !== null) {
		fn_setButton(a);
	}
	
	form.submit();
}

// function to submit specific named form
function fn_submitForm(f,a) {
	var form = document.forms[f];
	if (a !== null) {
		fn_setButton(a,f);
	}
	
	form.submit();
}

function fn_submitFormPCGV(f,a) {
	var form = document.forms[f];
	if (a !== null) {
		fn_setButtonPCGV(a,f);
	}

	form.submit();
}

function fn_setButtonPCGV(a,f) {
	var elementName = "btn";
	var form = document.forms[0];
	if (f !== null) {
		form = document.forms[f];
	} 
	fn_setActionFlag(a, "true", f);
	if (form.elements[elementName]) {
		form.elements[elementName].value = a;
	}
}
