
/* mfgx-admin.js - The main library of Javascript functions used in the KV site. */
/**
* Function to enable/disable tabs or subtabs on the client.
* @param tabIds  Array: DOM IDs for tabs to enable/disable.
* @param enable  Boolean: When true enable, otherwise disable.
*/
/* Copyright 1986-2009 QAD Inc., Santa Barbara, CA, USA.
* All rights reserved worldwide.  This is an unpublished work.
* $Revision: 1.0 $
* BY: Dingwei Zhang Date:     09/14/09       SV1-1762
* BY: Yu Li         Date:     12/31/09       SV1-1990           */
function changeState(tabIds, enable) {
for (var i=0;i<tabIds.length;i++) {
var elem = document.getElementById(tabIds[i]);
if (elem) {
var href = elem.getAttribute('href');
if (href.length > 11 && "javascript:" == href.substring(0, 11)) {
if (enable) {
if (href.substring(11, 13) == '//') {
href = "javascript:" + href.substring(13);
}
elem.style.color = '#fff';
elem.style.cursor = 'pointer';
elem.parentNode.setAttribute('className', 'InActive');
} else if (! enable) {
if (href.substring(11,13) != '//') {
href = "javascript://" + href.substring(11);
}
elem.style.color = '#ccc';
elem.style.textDecoration = 'none';
elem.style.cursor = 'default';
elem.parentNode.setAttribute('className', 'InActiveDisabled');
}
}
elem.setAttribute('href',href);
}
}
};
/**
* Replaces the current form action with the supplied action, submits the form,
* and then sets the previous form action.
*/
function swapAction(id, action) {
var frm = document.getElementById(id);
var oldAction = frm.action;
frm.action = action
frm.submit();
frm.action = oldAction;
};
/**
* Creates a pdf report by forwarding this page to the report action
* @param reportType The report type.
*/
function executeReport(reportType) {
var frm = document.getElementById('fmain');
var oldAction = frm.action;
var newAction = oldAction.substring(0, oldAction.indexOf('/', 1))+'/' + 'report.do?action=run'+reportType+'&oldAction='+oldAction;
if(frm.itemGraphReport)
newAction = '/sv/item/report.do?action=runReport&oldAction='+oldAction;
if(frm.supplierGraphReport)
newAction = '/sv/supplier/report.do?action=runReport&oldAction='+oldAction;
if(frm.itemMinMaxGraphReport)
newAction = '/sv/itemMinMax/report.do?action=runReport&oldAction='+oldAction;
if(frm.schFcastCompGraphReport)
newAction = '/sv/schFcastComp/report.do?action=runReport&oldAction='+oldAction;
if(frm.usageFcastTrendGraphReport)
newAction = '/sv/usageFcastTrend/report.do?action=runReport&oldAction='+oldAction;
if(frm.BOMReport){
oldAction='/sv/item/BOMReport.do?&orgSysID=' + document.getElementById('fmain').elements['orgSysID'].value + '&itemPlaceSysID=' +document.getElementById('fmain').elements['itemPlaceSysID'].value + '&entitySysID=' +document.getElementById('fmain').elements['entitySysID'].value + '&itemID=' +document.getElementById('fmain').elements['itemID'].value + '&level='+document.getElementById('fmain').elements['level'].value ;
newAction = '/sv/report.do?action=run'+reportType+'&oldAction='+ oldAction;
}
frm.action = newAction
frm.submit();
frm.action = oldAction;
};
/**
* Convenience function to disable anchors when assigned to the "onclick" event
* handler.
*/
function disableAction() {return false;};
/**
* Convenience function to re-enable anchors when assigned to the "onclick" event
* handler.
*/
function enableAction() {return true;};
/*
* Used to toggle the visibility of an element (identified by id)
* in the current document.
*/
function toggleVisibility(id) {
toggleVisibility(id, null);
}
/*
* Used to toggle the visibility of an element (identified by id)
* in the current document.  The change in state is communicated
* to the server via the provided profileKey the next time the
* page is submitted.
*/
function toggleVisibility(id, profileKey, gotoServer) {
//list of standards-compliant display properties
showImgState = 'inline';
showTableState = 'table';
showTrState = 'table-row';
showTdState = 'table-cell';
showBlockState = 'block';
hideState = 'none';
var elem = document.getElementById(id);
state = elem.style.display;
//if current state is hidden, now show
if(state == 'none'){
//Gecko requires specific display properties for specific elements
//Look up correct visible display property based on nodeName
if(navigator.userAgent.indexOf('Gecko') != -1){
if(elem.nodeName == 'IMG')
state = showImgState;
else if(elem.nodeName == 'TABLE')
state = showTableState;
else if(elem.nodeName == 'TR')
state = showTrState;
else if(elem.nodeName == 'TD')
state = showTdState;
else
state = showBlockState;
//IE uses 'block' as if it were a default visible display property
} else {
state = showBlockState;
}
//if current state is visible, now hide
} else {
state = hideState;
}
if (profileKey != null)
updateProfile(profileKey, state);
if (! gotoServer) {
elem.style.display = state;
} else {
document.getElementById('fmain').submit();
}
}
/*
* Used to communicate profile changes to the server.
*/
function updateProfile(_key, _value) {
var frm = document.getElementById('fmain');
var entries = frm.profileChanges.value.split("<NUP>");
var data = "";
for (var i=0;i<entries.length; i++) {
var key = entries[i].substring(0, entries[i].indexOf("="));
if (key != _key)
data += (data.length != 0 ? "<NUP>" : '') + entries[i];
}
data += (data.length != 0 ? "<NUP>" : '') + _key + '=' + _value;
frm.profileChanges.value = data;
}
/*
* Toggles the taskbar arrows.
*/
function swapArrows(state){
var rightArrows = document.getElementById('SidebarTabArrowsOpen');
var leftArrows = document.getElementById('SidebarTabArrowsClosed');
state == 'none' ? imgSwap(rightArrows,leftArrows):imgSwap(leftArrows,rightArrows);
}
/** Called by swapArrows  */
function imgSwap(hide,show){
hide.style.display='none';
show.style.display='inline';
}
/**
* Open a link into a new centered window.
*/
function openNewWindow(winURL, winWidth, winHeight, winConfig){
mmConfig="width="+winWidth+",";
mmConfig+="height="+winHeight+",";
mmConfig+="left="+((screen.availWidth - winWidth)/2)+",";
mmConfig+="top="+((screen.availHeight - winHeight)/2)+",";
mmConfig+=winConfig;
var mmWin=open(winURL,"",mmConfig);
mmWin.focus();
}
/**
* Open a link into a new centered window with specified title.
*/
function openNewWindowWithTitle(winURL, winWidth, winHeight, winConfig, winTitleName){
mmConfig="width="+winWidth+",";
mmConfig+="height="+winHeight+",";
mmConfig+="left="+((screen.availWidth - winWidth)/2)+",";
mmConfig+="top="+((screen.availHeight - winHeight)/2)+",";
mmConfig+=winConfig;
var mmWin=window.open(winURL,winTitleName,mmConfig);
mmWin.focus();
}
function nw(winURL, winWidth, winHeight, winConfig){
openNewWindow(winURL, winWidth, winHeight, winConfig);
}
/**
* Deprecated use openNewWindow().
*/
function openWindow(url, settings) {
window.open(url, null, settings);
}
function openFullWindow(url) {
var win = open(url);
win.focus();
}
/**
* Sets the supplied parameter into the form action specified by id.  If the
* parameter already exists it will be replaced, otherwise it will be appended.
* @param id      DOM id of a Form.
* @param key     Name of the parameter.
* @param value Value of the parameter.
*
*/
function setFormActionParam(id, key, value) {
var frm = document.getElementById(id);
var pos = frm.action.indexOf('?');
if (frm.action.indexOf(key + '=') == -1) {
frm.action += (pos == -1 ? '?' : '&') + key + '=' + value;
} else {
var re= new RegExp(key+'=.*?(&|$)', 'g');
frm.action =
frm.action.substring(0, pos+1) +
frm.action.substring(pos+1,frm.action.length).replace(re, key + '=' + value + '$1');
}
}
/** Copy the contents of one form to another and submit (supply id of form as input)*/
function copyForm(from, to) {
var f = document.getElementById(from);
var t = document.getElementById(to);
var buf = '';
for (var i=0;i<f.elements.length;i++) {
var e = f.elements[i];
if (e.name && e.type) {
var elemType = e.type;
if (elemType == 'select-multiple') {
for(var o=0;o<e.options.length;o++) {
if (e.options[o].selected) {
buf += (buf.length != 0 ? '&' : '') + e.name + '=' + escape(e.options[o].value);
}
}
} else {
if ((elemType != 'radio' && elemType != 'checkbox') || e.checked) {
buf += (buf.length != 0 ? '&' : '') + e.name + '=' + escape(e.value);
}
}
}
}
t.action += (t.action.indexOf('?') == -1 ? '?' : '&') + buf;
t.submit();
return false;
}
/** Move the focus to and select the field */
function formFieldFocus(fieldName){
document.getElementById('fmain').elements[fieldName].focus();
if(document.getElementById('fmain').elements[fieldName].type == 'text'){
document.getElementById('fmain').elements[fieldName].select();
}
}
/** Set the checked state of a single checkbox or any array of checkboxes */
function setAllCheckBox(fieldName, value) {
var elem = document.getElementById('fmain').elements[fieldName];
if (elem) {
if (elem.length) {
for(var i=0;i<elem.length;i++) {
if (elem[i].disabled == false){
elem[i].checked = value;
}
}
} else {
if (elem.disabled == false){
elem.checked = value;
}
}
}
}
/** Set the checked state of a single checkbox or any array of checkboxes */
function setAllCheckBoxForParent(parentFieldName, fieldName) {
var parent = document.getElementById('fmain').elements[parentFieldName];
var elem = document.getElementById('fmain').elements[fieldName];
if (elem) {
if (elem.length) {
for(var i=0;i<elem.length;i++) {
if (elem[i].disabled == false){
elem[i].checked = parent.checked;
}
}
} else {
state = elem.checked;
if (elem.disabled == false){
elem.checked = parent.checked;
}
}
}
}
function setCheckParentForChildren(parentFieldName, fieldName) {
var parent = document.getElementById('fmain').elements[parentFieldName];
var elem = document.getElementById('fmain').elements[fieldName];
var chk = false;
if (elem) {
if (elem.length) {
for(var i=0;i<elem.length;i++) {
if (elem[i].disabled == false && elem[i].checked == true){
chk = true;
break;
}
}
} else {
state = elem.checked;
if (elem.disabled == false && elem.checked == true){
chk = true;
}
}
parent.checked = chk;
}
}
/** Toggles the checked state of a single checkbox or any array of checkboxes */
function toggleAllCheckBox(fieldName) {
var elem = document.getElementById('fmain').elements[fieldName];
if (elem) {
if (elem.length) {
for(var i=0;i<elem.length;i++) {
if (elem[i].disabled == false){
state = elem[i].checked;
if (state == true){
elem[i].checked = false;
} else {
elem[i].checked = true;
}
}
}
} else {
state = elem.checked;
if (elem.disabled == false){
if (state == true){
elem.checked = false;
} else {
elem.checked = true;
}
}
}
}
}
/** Set the value of a single textbox or any array of textboxes */
function setAllTextBox(fieldName, value) {
var elem = document.getElementById('fmain').elements[fieldName];
if (elem) {
if (elem.length) {
for(var i=0;i<elem.length;i++)
elem[i].value = value;
} else {
elem.value = value;
}
}
}
/** Toggles the value of a single textbox or any array of textboxes (supply value choices as ":" separated) */
function reverseAllTextBox(fieldName, value, idx) {
var toggleOpts = new Array(2);
toggleOpts[0] = value.substring(0,value.indexOf(':'));
toggleOpts[1] = value.substring(value.indexOf(':')+1);
var elem = document.getElementById('fmain').elements[fieldName];
if (elem) {
if (elem.length) {
if (idx) {
elem[idx].value = (elem[idx].value == toggleOpts[0] ? toggleOpts[1] : toggleOpts[0]);
} else {
for(var i=0;i<elem.length;i++)
elem[i].value = (elem[i].value == toggleOpts[0] ? toggleOpts[1] : toggleOpts[0]);
}
} else {
elem.value = (elem.value == toggleOpts[0] ? toggleOpts[1] : toggleOpts[0]);
}
}
}
/** Select all options in an HTML select */
function selectAll(box1) {
var index = 0;
while(index < box1.length) {
box1.options[index].selected = true;
index++;
}
}
function move(box1,box2,all) {
var index = 0;
while(index < box1.length) {
if(all || box1.options[index].selected ) {
var val = box1.options[index].value;
var txt = box1.options[index].text;
box2.options[box2.length] = new Option(txt,val);
box1.remove(index);
} else {
index++;
}
}
}
/* all purpose gets width of window */
function getWidth(){
if (window.innerWidth){
return window.innerWidth;
} else if (document.documentElement && document.documentElement.clientWidth){
return document.documentElement.clientWidth;
} else if (document.body.offsetWidth){
return document.body.offsetWidth;
} else if (document.body){
return document.body.clientWidth;
}
}
function isMSIE(){
return (navigator.appName == "Microsoft Internet Explorer")
}
/* This function is fired on every page and will
add odd and even row colors where the class attribute
"alt" has been applied to tr elements
*/
function altRows(){
var allRows = document.getElementsByTagName("tr");
for(i=0;i<allRows.length;i++){
if(allRows[i].className=="alt"){
if ( (i % 2) == 1 ){
allRows[i].className="Even";
} else {
allRows[i].className="Odd";
}
}
}
}
/* This hack compensates for "1-up" font-size bug in IE */
/* It sets the css default size for all other elements to inherit */
function IEFontBug(){
document.write('<style>');
if(isMSIE()){
document.write('* { font-size: 12px; }');
} else {
document.write('* { font-size: small; }');
}
document.write('</style>');
}
/*
* Toggles the disclosure triangles on togglebar.jsp
*/
function toggleTriangles(ids){
for(i=0;i<ids.length;i++){
toggleVisibility(ids[i]);
}
}
/*
* Syncs up the disclosure triangle in the toggle bar
* with the display property of the corresponding taskbar pane.
*/
function syncTriangle(id){
arrow1 = document.getElementById(id+'01');
arrow2 = document.getElementById(id+'02');
displayProp = document.getElementById(id).style.display;
if(displayProp == 'none'){
arrow1.style.display='none';
arrow2.style.display='inline';
} else {
arrow1.style.display='inline';
arrow2.style.display='none';
}
}
/*
* Calls syncTriangle().
*/
function syncTriangles(ids){
for(i=0;i<ids.length;i++){
if(document.getElementById(ids[i]))
syncTriangle(ids[i]);
}
}
/*
* Fixes the milonic menu for those
* who use the Mac OSX Safari browser
* The problem results from the script setting
* width:NaNpx in the css on top-level menus,
* which resolves to 0 by Safari.
*/
function fixMenu(){
if(navigator.userAgent.indexOf("Safari")!= -1){
//The top level menu divs are assigned an id
//matching this pattern.
//The number of these divs differs by role.
var rx = /^hel\d/;
var elems = document.getElementsByTagName('div');
x = -1;
y = 0;
for (i=0;i<elems.length;i++){
if(rx.test(elems[i].id)){
//It is not known in advance what the menu width
//should be, so it is calculated by string length.
w = elems[i].firstChild.firstChild.lastChild.nodeValue.length * 6;
//Move each subsequent menu item to the left.
//The first item does not need to move.
elems[i].style.left= y + "px";
y += w;
}
}
}
}
/*
* Screen : New Item Place Maintenance
* Populates SYSID in the hidden fields only if there is a change in the fields
*/
function populateHiddenField(fieldName, value, idx) {
var elem = document.getElementById('fmain').elements[fieldName];
if (elem) {
if (elem.length) {
if (idx) {
elem[idx].value = value;
} else {
for(var i=0;i<elem.length;i++)
elem[i].value = value;
}
} else {
elem.value = value;
}
}
}
// Screen - Item Policy maintenance
// Changes the field value and checks / unchecks the Checkbox
function changeFldStDisChk(disFieldname, fieldname, chkname){
var flag= document.getElementById('fmain').elements[chkname].checked;
document.getElementById('fmain').elements[disFieldname].disabled=!(flag);
document.getElementById('fmain').elements[fieldname].value=flag;
document.getElementById('fmain').elements[chkname].checked=flag;
}
// Screen - Item Policy maintenance
// Enables/Disables the field based on the select option
function changeFldStatus(selectName, fieldName, hdnFieldName){
var selectValue = document.getElementById('fmain').elements[selectName].options[document.getElementById('fmain').elements[selectName].selectedIndex].value
var orgValue = document.getElementById('fmain').elements[hdnFieldName].value;
if (selectValue == "2"){
if (orgValue=="0"){
document.getElementById('fmain').elements[fieldName].disabled=false;
}
else{
document.getElementById('fmain').elements[fieldName].disabled=true;
}
}
else{
if (selectValue=="0"){
document.getElementById('fmain').elements[fieldName].disabled=false;
}
else{
document.getElementById('fmain').elements[fieldName].disabled=true;
}
}
}
// Screen - Item Policy maintenance
// Changes the field value and disables the Button
function hideDivOnSelectOption(divID, selectName, selectValue){
var elem = document.all(divID);
if (elem.length>1){
for (var i=0;i<elem.length;i++) {
if (document.getElementById('fmain').elements[selectName].options[document.getElementById('fmain').elements[selectName].selectedIndex].value == selectValue){
elem[i].style.visibility="visible";
}
else{
elem[i].style.visibility="hidden";
}
}
}
else{
if (document.getElementById('fmain').elements[selectName].options[document.getElementById('fmain').elements[selectName].selectedIndex].value == selectValue){
elem.style.visibility="visible";
}
else{
elem.style.visibility="hidden";
}
}
}
// Validates the characters in the field value
function validateCharacters(str,validcharlist)
{
var retval=true;
var txt=str;
var txtlow=txt.toLowerCase();
for (var i=0;i<txtlow.length;i++)
{
var ex=validcharlist.indexOf(txtlow.substring(i,i+1));
if(ex==-1)
{
retval=false;
break;
}
}
return retval;
}
// Makes an asynchronous call to the server.
function asyncCall(method, url){
var xmlHttp=null;
try {
xmlHttp = new XMLHttpRequest();
} catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
xmlHttp.open(method, url);
xmlHttp.send(null);
}
// Wires an event handler to an event without replacing existing event handlers.
function wireEventHandler(node, eventName, func) {
if (node.addEventListener){
node.addEventListener(eventName.substring(2, eventName.length), func, false);
} else if (node.attachEvent){
node.attachEvent(eventName, func);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function deleteDataReport(reportType) {
var frm = document.getElementById('fmain');
var oldAction = frm.action;
if (reportType == "deletePO")
var newAction = '/sv/delete/po.do?DeleteClosedPOAction=runA';
if (reportType == "deleteASN")
var newAction = '/sv/delete/asn.do?DeleteReceivedASNsAction=runA';
if (reportType == "deleteSchedules")
var newAction = '/sv/delete/schedule.do?DeleteClosedSchedulesAction=runA';
//alert(newAction);
frm.action = newAction
frm.submit();
frm.action = oldAction;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Change history and breadcrumb link from get to post
function getToPost(url) {
url=unescape(url);
var tempForm = document.createElement("form");
tempForm.method = "post";
if (url.indexOf('?') != -1) {
var str=url.split("?");
var para=str[1].split("&");
tempForm.action = str[0];
document.body.appendChild(tempForm);
for (var i=0;i<para.length;i++)
{
var key=para[i].split("=");
var elem=document.createElement("input");
elem.type="hidden";
elem.name=key[0];
elem.value=key[1];
tempForm.appendChild(elem);
}
tempForm.submit();
}
else {
tempForm.action = url;
document.body.appendChild(tempForm);
tempForm.submit();
}
}
