
    /*
     * C O M M O N   J A V A S C R I P T   F U N C T I O N S.
     */


    /*
     * Submits specified form.
     *
     * formName   - Name of the form to be submitted, same as value specified
     *              in the 'name' attribute of the form.
     * action     - Action of the form (URL of the server that will handle form's inputs.
     * method     - 'GET' or 'POST'.
     */
    function submitForm(formName, action, method) {

      document.forms[formName].action = action;
      document.forms[formName].method = method;
      document.forms[formName].submit();
    }
    
    function submitFormFromMetricChart(action) {
      document.forms['metric'].action = action;
      document.forms['metric'].method = 'POST';
      document.forms['metric'].submit();
    }

	function submitFormPreserveDisplayHeaderState(formName, action, method){
	   var prm = '';
	   if (document.all.entityShowOrHide.style.display == "none") {
	      prm = 'false';	   
	   } else {
	      prm = 'true';
	   }
	   
	   var newAction = "";
	   if (action.indexOf('?') >= 0) {
	      newAction = action + "&displayEntityDetails=" + prm;
	   } else {
	      newAction = action + "?displayEntityDetails=" + prm;	   
	   }   
	   submitForm(formName, newAction, method);	
	} 
    /*
     * Function to submit a form on an enter key press.
     *
     * Usage:
     *  <input type="text" name="User" size="15" onKeyPress="submitFormOnEnter(event, 'MyForm', 'Some URL', 'POST')">
     */
    function submitFormOnEnter(event, formName, action, method)
    {
        var code = event.keyCode;
	    if (code==13)
		    submitForm(formName, action, method);
    }

    function resetForm(formName, defaultCheckState) {
        var count;
        var formElements = document.forms[formName].elements;

        resetIfAggregation(formElements)

        for (count = 0; count < formElements.length; count++) {
            resetIfTextOrPassword(formElements[count]);
            resetIfSelect(formElements[count]);
            resetIfCheckbox(formElements[count], defaultCheckState);
            resetIfRadio(formElements[count]);
            resetIfTextArea(formElements[count]);
        }
    }

    // introduced this function to avoid potential breakage of other pages
    // TODO:  refactor
    function resetFormWithAggregate(formName, defaultCheckState) {
        var count;
        var formElements = document.forms[formName].elements;

        resetIfAggregation(formElements)

        for (count = 0; count < formElements.length; count++) {
            resetIfTextOrPassword(formElements[count]);
            resetIfSelect(formElements[count]);
            resetIfCheckbox(formElements[count], defaultCheckState);
            resetIfRadio(formElements[count]);
        }
    }

    function resetIfAggregation(formElements) {
        if (formElements.SELECTED_COLUMNS != null && formElements.AVAILABLE_COLUMNS != null) {
            moveAllOptions(formElements.SELECTED_COLUMNS, formElements.AVAILABLE_COLUMNS);
            sortSelect(formElements.AVAILABLE_COLUMNS);
            sortSelect(formElements.SELECTED_COLUMNS);
        }
    }

    function resetIfCheckbox(element, defaultCheckState) {
        if (element.type != "checkbox") {
            return;
        }

        element.checked=defaultCheckState;
    }

    // introduced this function to avoid potential breakage of other pages
    // TODO:  refactor
    function resetIfCheckboxNotAgg(element, defaultCheckState) {
        if (element.type != "checkbox") {
            return;
        }

        if (element.name != "AGGREGATE") {
          element.checked=defaultCheckState;
        }
    }

    function resetIfTextOrPassword(element) {
        if (element.type != "text" && element.type != "password" ) {
            return;
        }

        element.value = "";
    }
    
    function resetIfTextArea(element) {
        if (element.type != "textarea" ) {
            return;
        }

        element.value = "";
    }

    function resetIfSelect(element) {
        var count;
        var selectOptions;

        if (element.type != "select-multiple" && element.type != "select-one") {
            return;
        }

        selectOptions = element.options;

         // Unselect all options.
        for (count = 0; count < selectOptions.length; count++) {
            selectOptions[count].selected = false;
        }

        // Set first option as the one that is selecetd.

         if (element.type == "select-one") {
           if (selectOptions.length > 0) {
            selectOptions[0].selected = true;
           }
         }
    }

    function resetIfRadio(element) {
        var radioButtons;

        if (element.type != "radio") {
            return;
        }

        // A little trick to get a radio button group
        // as opposed to radio button only.
        radioButtons = element.form[element.name];

        radioButtons[0].checked = true;
    }

    function resetMultipleSelect(formName, selectFirst) {
        var count
        var formElements = document.forms[formName].elements;

        for (count = 0; count < formElements.length; count++) {
            var count2;
            var selectOptions;

            if (formElements[count].type != "select-multiple") {
                continue;
            }

            selectOptions = formElements[count].options;

            // Unselect all options.
            for (count2 = 0; count2 < selectOptions.length; count2++) {
                selectOptions[count2].selected = false;
            }

            // Set first option as the one that is seleceted except for MS-LOV.
			if (formElements[count].id.search(/msv_/) != 0) {
	            if ('true' == selectFirst) {
	               if (selectOptions.length > 0) {
	                    selectOptions[0].selected = true;
	               }
	            }
	        }
        }
    }

    /*
     * Checks a checkbox when data is typed into a textfield.
     *
     * @param formName      Name of the form
     * @param checkBoxName  Name of the checkbox
     * @param textFieldName Name of the textfield.  If multiple textfields with same
     *                      name, then pass in the index of the field to watch (ie. [1], [2], etc.)
     */
    function doCheck(formName, checkBoxName, textFieldName) {
     if ( formName && formName != '' && checkBoxName && checkBoxName != '' && textFieldName && textFieldName != '') {  
        	eval("a=document." + formName + "." + textFieldName + ".value");
        	if (a.length != 0 )
            	eval("document." + formName + "." + checkBoxName + ".checked=true");
        	else
            	eval("document." + formName + "." + checkBoxName + ".checked=false");
        }
    }

    function doCheckCalendar(formName, checkBoxName, textFieldName) {
        if ( formName && formName != '' && checkBoxName && checkBoxName != '' && textFieldName && textFieldName != '') {  
           	eval("a=document." + formName + "." + textFieldName + ".value");
            eval("document." + formName + "." + checkBoxName + ".checked=true");
           }
       }
    
    /*
     * Display Passing URL in new Window
     *
     * @param URL      To be displayed
     */
    function doDisplayLocationPupUpView(URL) {
        var winLeft = (screen.width - 400) / 2;
        var winUp = (screen.height - 240) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=520,height=232,left = " + winLeft + ",top = " + winUp + "');");
    }
    
    function doDisplayActivityHistoryPupUpView(URL) {
        var winLeft = (screen.width - 400) / 2;
        var winUp = (screen.height - 240) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=520,height=190,left = " + winLeft + ",top = " + winUp + "');");
    }

    /*
     * Display Passing URL in new Window
     *
     * @param URL      To be displayed
     */
    function doDisplayCurvePupUpView(URL) {
        var winLeft = (screen.width - 400) / 2;
        var winUp = (screen.height - 240) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=377,height=450,left = " + winLeft + ",top = " + winUp + "');");
    }

    /*
     * Display Wizard PopUp View
     *
     * @param URL      To be displayed
     */
    function doDisplayWizardPopUpView(URL) {
        var winLeft = (screen.width - 900) / 2;
        var winUp = (screen.height - 650) / 2;
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=900,height=650,left = " + winLeft + ",top = " + winUp + "');");
    }

    /*
     * Display ScenarioDetails PopUp View
     *
     * @param URL      To be displayed
     */
    function doDisplayScenarioDetailsPopUpView(URL) {
        var winLeft = (screen.width - 600) / 2;
        var winUp = (screen.height - 600) / 2;
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=600,left = " + winLeft + ",top = " + winUp + "');");
    }

    function openWindow(url, name) {
        //winStats='toolbar=no,location=no,directories=no,menubar=no,'
        //winStats+='scrollbars=yes,width=800,height=400'
        var winWidth = 950;
        var winHeight = 275;
        var winLeft = (screen.width - winWidth) / 2;
        var winUp = (screen.height - winHeight) / 2;
        winStats='scrollbars=yes,width='+winWidth+',height='+winHeight+',left='+winLeft+',top='+winUp
        aWindow=window.open(url, name,winStats)
        aWindow.focus()
    }

    function openWorksheetWindow(URL) {
        var winLeft = (screen.width - 400) / 2;
        var winUp = (screen.height - 240) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=377,height=120,left = " + winLeft + ",top = " + winUp + "');");

    }
    
     function doSourcePopUP(URL) {
        var winLeft = (screen.width - 450) / 2;
        var winUp = (screen.height - 250) / 2;
          day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=220,left = " + winLeft + ",top = " + winUp + "');");
    }
    
     function doNotSourcedReasonPopUP(URL) {
        var winLeft = (screen.width - 450) / 2;
        var winUp = (screen.height - 150) / 2;
          day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=120,left = " + winLeft + ",top = " + winUp + "');");
    }
    

     function doCancelSourcedPopUP(URL) {
        var winLeft = (screen.width - 400) / 2;
        var winUp = (screen.height - 100) / 2;
          day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=350,height=115,left = " + winLeft + ",top = " + winUp + "');");
    }

    function displayNotificationActionPopUp(URL) {
        var winLeft = (screen.width - 650) / 2;
        var winUp = (screen.height - 150) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=150,left = " + winLeft + ",top = " + winUp + "');");
    }
    
    
    function displayNotificationUpdateActionPopUp(URL) {
        var winLeft = (screen.width - 375) / 2;
        var winUp = (screen.height - 150) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=375,height=150,left = " + winLeft + ",top = " + winUp + "');");
    }



    /*
     * Display Passing URL in new Window
     *
     * @param URL      To be displayed
     */
    function doDisplayOrgPupUpView(URL) {
        var winLeft = (screen.width - 740) / 2;
        var winUp = (screen.height - 500) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=740,height=500,left = " + winLeft + ",top = " + winUp + "');");
    }

    function doDisplayPODPopUpBrowserView(URL) {
    	var width = 600;
    	var height = 580;      
        var winLeft = (screen.width - width) / 2;
        var winUp = (screen.height - height) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=580,left = " + winLeft + ",top = " + winUp + "');");
    }
    
    function doDisplayPODPopUpPrintView(URL) {
    	var width = 520;
    	var height = 680;          
        var winLeft = (screen.width - width) / 2;
        var winUp = (screen.height - height) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=580,left = " + winLeft + ",top = " + winUp + "');");
    }
    
    function doDisplayPODPopUpEmailView(URL) {
    	var width = 520;
    	var height = 680;          
        var winLeft = (screen.width - width) / 2;
        var winUp = (screen.height - height) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=560,left = " + winLeft + ",top = " + winUp + "');");
    }
    
    function doDisplayPODPopUpFaxView(URL) {
    	var width = 520;
    	var height = 680;          
        var winLeft = (screen.width - width) / 2;
        var winUp = (screen.height - height) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=580,left = " + winLeft + ",top = " + winUp + "');");
    }

    /*
     * Display Passing URL in new Window
     *
     * @param URL      To be displayed
     */
    function doDisplayInventoryLogPopUpView(URL) {
        var winLeft = (screen.width - 740) / 2;
        var winUp = (screen.height - 300) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=740,height=300,left = " + winLeft + ",top = " + winUp + "');");
    }


    /*
     * Display Passing URL in new Window
     *
     * @param URL      To be displayed
     */
    function doDisplayInventoryOnHandQtyGraphPopUpView(URL) {
        var winLeft = (screen.width - 740) / 2;
        var winUp = (screen.height - 300) / 2;
    	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=740,height=330,left = " + winLeft + ",top = " + winUp + "');");
    }

     function doDisplayForecastingProductSelectionPopUpView(URL) {
    	var winLeft = (screen.width - 500) / 2;
    	var winUp = (screen.height - 228) / 2;
	day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,location=0,statusbar=0,scrollbars=1,menubar=0,resizable=1,width=500,height=228, left =" + winLeft + ",top = " + winUp + "');");
    }


    function doDisplayOrderLineDetailsPopUp(URL) {
        openWindow(submitForm('OrderEditor', URL, 'POST'), 'Order Line Details');
    }

    /*
     * Display Passing URL in new Window
     *
     * @param URL      The Change Password Screen
     */
    function doDisplayChangePasswordPopUp(URL) {
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=125,left = 400,top = 250');");
    }

    function doHelpPopUp(URL) {
        var winLeft = (screen.width - 540) / 2;
        var winUp = (screen.height - 380) / 2;
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=540,height=380,left = " + winLeft + ",top = " + winUp + "');");
    }

    function doXMLMessageViewerPopUp(URL) {
        var winLeft = (screen.width - 540) / 2;
        var winUp = (screen.height - 380) / 2;
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=400,left = " + winLeft + ",top = " + winUp + "');");
    }

	function doDocumentViewerPopUp(URL) {
        var winLeft = (screen.width - 540) / 2;
        var winUp = (screen.height - 380) / 2;
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=800,height=400,left = " + winLeft + ",top = " + winUp + "');");
    }
   /*
     * Checks all the checkboxes when user clicks the Select all hyperlink.
     *
     * @param formName      Name of the form
     * @param defaultCheckState  Default State of the checkbox i.e. false unless user sets it to true
     */

    function doSelectAll(formName, defaultCheckState) {
        var count;
        var formElements = document.forms[formName].elements;
        for (count = 0; count < formElements.length; count++) {
             resetIfCheckbox(formElements[count], defaultCheckState);
        }

    function resetIfCheckbox(element, defaultCheckState) {
        if (element.type != "checkbox") {
            return;
        }
         element.checked=defaultCheckState;
    }
    }
    
    function doSelectAll(formName, defaultCheckState, exceptionContains) {
        var count;
        var formElements = document.forms[formName].elements;
        for (count = 0; count < formElements.length; count++) {
             resetIfCheckbox(formElements[count], defaultCheckState, exceptionContains);
        }

    function resetIfCheckbox(element, defaultCheckState, exceptionContains) {
        if (element.type != "checkbox") {
            return;
        }
        
        if (element.name.search(exceptionContains) != -1 ) {
            return;
        }
        
         element.checked=defaultCheckState;
         
         
    }
    }

   /* This method is used in the Message Monitor screen to select only the check boxes that 
    * are not greyed out. 
    *
    */
   function msgDoSelectAll(formName, defaultCheckState) {
        var count;
        var formElements = document.forms[formName].elements;
        for (count = 0; count < formElements.length; count++) {
             resetIfCheckbox(formElements[count], defaultCheckState);
        }

    function resetIfCheckbox(element, defaultCheckState) {
        if (element.type != "checkbox") {
            return;
        }
        if (element.disabled == false) {
         element.checked=defaultCheckState;
        }
    }
     
    }


    /*
     * Retrieve Saved Query OID(form element name savedquery),
     * from FORM (javascript object),
     * and append to URL as parameter in order to
     * pre populate saved query pop up window.
     *
     * @param URL      Saved Query Editor Screen
     * @param form     Java Script FORM object
     */
    function doSavedQueryPopUp(URL, form) {
    	var savedQueryOID = null;
        var element = form.savedquery;
        var elementFrom = form.source;
        for(var i = 0; i <  element.options.length; i++) {
           if(element.options[i].selected) {
              savedQueryOID = element.options[i].value;
              break;
           }
        }
        var fromPrm = "";
        if (elementFrom != null) {   
            fromPrm = "&from=" + elementFrom.value
        }
        var param = "?SAVED_QUERY_OID=" + savedQueryOID + fromPrm;
        day = new Date();
        id = day.getTime();
        var winLeft = (screen.width - 400) / 2;
        var winUp = (screen.height - 150) / 2;
        eval("page" + id + " = window.open(URL + param , '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=150,left=" + winLeft + ",top=" + winUp + "');");
    }

    function doDisplayDirectMessagingPopUp(URL, paramName, paramValue) {
        if (paramValue == null || paramValue.length == 0) {
            return;
        }

        if (paramName == null || paramName.length == 0) {
            return;
        }

        day = new Date();
        id = day.getTime();
        completeURL = URL.concat("?").concat(escape(paramName)).concat("=").concat(escape(paramValue));

        eval("page" + paramName + " = window.open('" + completeURL +"', '" + paramName + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=438,height=415,left=300,top=250');");
    }

    var nodeNumber = 0;

    function dosubmit(obj)
    {
        doselectforsubmit(obj)
    }

    function addOption(obj)
    {
        var optNode
        optNode = document.createElement("OPTION")
        optNode.value = nodeNumber
        optNode.innerText = "Item "+nodeNumber+obj.id
        obj.appendChild(optNode);
        nodeNumber++
    }

    function moveAllItems(FromItem, ToItem)
    {
        var Childer = FromItem.options.length
        for(i=0; i < Childer; i++)
        {
            aNode = FromItem.options[i].cloneNode(true)
            ToItem.appendChild(aNode)
            FromItem.removeChild(FromItem.options[i])
            Childer = FromItem.options.length
            i--
        }
    }

    // this is the code for moving the items
    function moveItems(FromItem, ToItem)
    {
        var Childer = FromItem.options.length
        for(i=0; i < Childer; i++)
        {
            if (FromItem.options[i].selected)
            {
                aNode = FromItem.options[i].cloneNode(true)
                ToItem.appendChild(aNode)
                FromItem.removeChild(FromItem.options[i])
                Childer = FromItem.options.length
                i--
            }
        }
    }

    function doselectforsubmit(objas) {
    //alert("Test=" +  objas.options)
     if (objas.options != null) {
        var Childer = objas.options.length
        Childer--
        if (objas.options.length >= 0) {
            for(i=0; i<=Childer; i++) {
                objas.options[i].selected=true
            }
        }
      }
    } 

    function doCMPopUp(URL) {
    	var pageapplet_win = "CM";
    	eval(pageapplet_win + " = window.open('" + URL +"', '" + pageapplet_win + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=750,height=630,left=100,top=150');");
    }

    function doLogoff(URL) {
	if (typeof(CM) != 'undefined') {
	    CM.close();
	} else {
	    CM = window.open('', 'CM', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=10,height=10,left=0,top=0');
	    CM.close();
	}
        window.location=URL;
    }

    function doExportDataPopUp(URL) {
    	var pageexport_win = "DataExport";
    	eval(pageexport_win + " = window.open('" + URL +"', '" + pageexport_win + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=750,height=630,left=100,top=150');");
    }

    function hideElement(elementId) {
        o = document.getElementById(elementId);
        if (o) {
        	o.style.display = "none";
        }
    }

    function toggleAggregationTable(checkbox, tableId) {
      if(checkbox.checked == true) {
        o = document.getElementById(tableId);
        o.style.display = "";
      } else {
        hideElement(tableId);
        checkbox.checked = false;
      }
    }

    function toggleScheduleCronParametersTable(radiobutton, displayTableId, hideTableId) {
        o = document.getElementById(displayTableId);
        o.style.display = "";
        hideElement(hideTableId);
    }

    /*
     * Updates the order line details anchor on the create/modify order screen
     */
    function updateOrderLineDetailsAnchor(formName, savedCheckboxPrefix,
                    orderLineNumberName, orderLineDetailsNumberPrefix) {
      obj = window.opener;
      doc = obj.document;

      currDoc = window.document
      formElements = currDoc.forms[formName].elements;
      orderDetailNumber = 0;
      count = 0;

      for (idx = 0; idx < formElements.length; idx++) {
        if (formElements[idx].name != null) {
	  if (formElements[idx].type == "checkbox") {
            if (formElements[idx].name.indexOf(savedCheckboxPrefix) >= 0) {
              if (formElements[idx].checked == true) {
                count++;
              }
            }
	  } else {
            if (formElements[idx].name == orderLineNumberName) {
	      orderDetailNumber = formElements[idx].value;
	    }
          }
	}
      }

      for (x = 0; x < doc.anchors.length; x++) {
        if (doc.anchors[x].name != null) {
          detailNumber = orderDetailNumber.valueOf();
          searchString = orderLineDetailsNumberPrefix + detailNumber;
	  if (doc.anchors[x].name.indexOf(searchString) >= 0) {
              doc.anchors[x].innerHTML = count.toString();
	      return
          }
        }
      }
    }

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. Instead,
// please just point to my URL to ensure the most up-to-date versions
// of the files. Thanks.
// ===================================================================


// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to
//  avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		var re = new RegExp(regex);
		for (var i=0; i<obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}

// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",false);
	}
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",true);
	}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression
//  passed in.
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"unselect",false);
	}

// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
  if (obj != null) {
    if (obj.options != null) {
      var o = new Array();
      if (o != null) {
        for (var i=0; i<obj.options.length; i++) {
          o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
        }

        if (o != null) {
          o = o.sort(
		function(a,b) {
                        if ((a != null) && (a.text != null) && (b != null) && (b.text != null)) {
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
                        }
			return 0;
			}
		);

            if (o != null) {
              for (var i=0; i<o.length; i++) {
                obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
              }
            }
          }
        }
      }
    }
  }

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}

// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the
//  onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) {
		var regex = arguments[3];
		if (regex != "") {
			unSelectMatchingOptions(from,regex);
			}
		}
	// Move them over
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			to.options[to.options.length] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	for (var i=0; i<to.options.length; i++) {
		options[to.options[i].text] = true;
		}
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.text] == null || options[o.text] == "undefined") {
				to.options[to.options.length] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		moveSelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(from,to,arguments[2],arguments[3]);
		}
	}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of
//  removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}

// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	// If > 1 option selected, do nothing
	var selectedCount=0;
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			selectedCount++;
			}
		}
	if (selectedCount > 1) {
		return;
		}
	// If this is the first item in the list, do nothing
	var i = obj.selectedIndex;
	if (i == 0) {
		return;
		}
	swapOptions(obj,i,i-1);
	obj.options[i-1].selected = true;
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	// If > 1 option selected, do nothing
	var selectedCount=0;
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			selectedCount++;
			}
		}
	if (selectedCount > 1) {
		return;
		}
	// If this is the last item in the list, do nothing
	var i = obj.selectedIndex;
	if (i == (obj.options.length-1)) {
		return;
		}
	swapOptions(obj,i,i+1);
	obj.options[i+1].selected = true;
	}


/*
 * Copies the order type name into a hidden field.
 *
 * selectionListId - Name of the order type selection list
 * hiddenFieldId - Name of the hidden field
 */
function getOrderTypeName(selectionListId,hiddenFieldId) {
  var selList = document.getElementById(selectionListId);
  var hfield = document.getElementById(hiddenFieldId);
  if (hfield != null && selList != null) {
  	hfield.value = selList.options[selList.selectedIndex].text;
  }
}

function displayAdvFilNotificationActionPopUp(URL) {
        var winLeft = (screen.width - 630) / 2;
        var winUp = (screen.height - 110) / 2;
    	day = new Date();
        id = "AdvFilNotificationPopUp";
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750,height=150,left = " + winLeft + ",top = " + winUp + "');");
}

function isBlank(s) {
  if(s != null){
      for (var i = 0 ; i < s.length; i++) {
         var c = s.charAt(i);
         if ((c != ' ') && (c != '\n') && (c != '\t')) {
             return false;
         }
      }
   }
   return true;     
}

   function insertLink(url, imgurl, wsimgurl) {

              if (n6) {
                  document.write("<a href=" + url + ">"  +
                          "<img src=" + imgurl +
                          "border=0 alt='Download/Start CM Application' >" + "</a>");
                  document.write("&nbsp;&nbsp;");
                  document.write("<a href=" +
                       "http://java.sun.com/products/javawebstart/download-windows.html" + ">" +
                       "<img src=" + wsimgurl +
                       "border=0 width=16 height=16 alt='Need to install Java Web Start' >" + "</a> " );
              } else {
                   if (javawsInstalled) {
                      document.write("<a href=" + url + ">"  +
                          "<img src=" + imgurl +
                          "border=0 alt='Download/Start CM Application' >" + "</a>");
                   } else {
                       document.write("<a href=" +
                       "http://java.sun.com/products/javawebstart/download-windows.html" + ">" +
                       "<img src=" + wsimgurl +
                       "border=0 width=16 height=16 alt='Need to install Java Web Start' >" + "</a> " );
                   }
              }

          }  

	function hideOrShowEntityDetails() {
	  if (document.all.entityShowOrHide.style.display == "none") {
	       document.all.entityShowOrHide.style.display = "";
	   } else {
	       document.all.entityShowOrHide.style.display = "none";
	   }	
	}
	
	function clickTab(action) {
	   var prm = '';
	   if (document.all.entityShowOrHide.style.display == "none") {
	      prm = 'false';	   
	   } else {
	      prm = 'true';
	   }
	   
	   var newAction = "";
	   if (action.indexOf('?') >= 0) {
	      newAction = action + "&displayEntityDetails=" + prm;
	   } else {
	      newAction = action + "?displayEntityDetails=" + prm;	   
	   }   
	   window.location = newAction ;	
	}
	
	function checkSelectAndSubmitForm(element, errorMsg, form, action, method) {
	  var checkBoxes = document.forms[form].elements[element];
       var checked;
       //alert(checkBoxes.length);
       if (checkBoxes != null && checkBoxes.length > 0) {
         for (var i = 0; i < checkBoxes.length; i++) {
            if (checkBoxes[i].checked) {
              submitForm(form, action, method);
              return;
            }
         }
       } else if (checkBoxes != null && checkBoxes.checked){
          submitForm(form, action, method);
          return;
       }
       alert(errorMsg);
	  	
	}
    
    
    /**
        
    This is a Javascript implementation of the Java Hashtable object.
    
    Contructor(s):
     Hashtable()
              Creates a new, empty hashtable
    
    Method(s):
     void clear() 
              Clears this hashtable so that it contains no keys. 
     boolean containsKey(String key) 
              Tests if the specified object is a key in this hashtable. 
     boolean containsValue(Object value) 
              Returns true if this Hashtable maps one or more keys to this value. 
     Object get(String key) 
              Returns the value to which the specified key is mapped in this hashtable. 
     boolean isEmpty() 
              Tests if this hashtable maps no keys to values. 
     Array keys() 
              Returns an array of the keys in this hashtable. 
     void put(String key, Object value) 
              Maps the specified key to the specified value in this hashtable. A NullPointerException is thrown is the key or value is null.
     Object remove(String key) 
              Removes the key (and its corresponding value) from this hashtable. Returns the value of the key that was removed
     int size() 
              Returns the number of keys in this hashtable. 
     String toString() 
              Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters ", " (comma and space). 
     Array values() 
              Returns a array view of the values contained in this Hashtable. 
            
*/
function Hashtable(){
    this.clear = hashtable_clear;
    this.containsKey = hashtable_containsKey;
    this.containsValue = hashtable_containsValue;
    this.get = hashtable_get;
    this.isEmpty = hashtable_isEmpty;
    this.keys = hashtable_keys;
    this.put = hashtable_put;
    this.remove = hashtable_remove;
    this.size = hashtable_size;
    this.toString = hashtable_toString;
    this.values = hashtable_values;
    this.hashtable = new Array();
}

/*=======Private methods for internal use only========*/

function hashtable_clear(){
    this.hashtable = new Array();
}

function hashtable_containsKey(key){
    var exists = false;
    for (var i in this.hashtable) {
        if (i == key && this.hashtable[i] != null) {
            exists = true;
            break;
        }
    }
    return exists;
}

function hashtable_containsValue(value){
    var contains = false;
    if (value != null) {
        for (var i in this.hashtable) {
            if (this.hashtable[i] == value) {
                contains = true;
                break;
            }
        }
    }
    return contains;
}

function hashtable_get(key){
    return this.hashtable[key];
}

function hashtable_isEmpty(){
    return (parseInt(this.size()) == 0) ? true : false;
}

function hashtable_keys(){
    var keys = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            keys.push(i);
    }
    return keys;
}

function hashtable_put(key, value){
    if (key == null || value == null) {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }else{
        this.hashtable[key] = value;
    }
}

function hashtable_remove(key){
    var rtn = this.hashtable[key];
    this.hashtable[key] = null;
    return rtn;
}

function hashtable_size(){
    var size = 0;
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            size ++;
    }
    return size;
}

function hashtable_toString(){
    var result = "";
    for (var i in this.hashtable)
    {      
        if (this.hashtable[i] != null) 
            result += "{" + i + "},{" + this.hashtable[i] + "}\n";   
    }
    return result;
}

function hashtable_values(){
    var values = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            values.push(this.hashtable[i]);
    }
    return values;
}

 function schedulerPopUp(URL) {
  id = new Date().getTime();
  eval("page" + id + " = window.open(URL , '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750,height=200,left = 200,top = 287');");   
}

   function displayTaskActionPopUp(URL, ht, wd) {
        var winLeft = (screen.width - wd) / 2;
        var winUp = (screen.height - ht) / 2;
        var popUpHeight = ht;
        var popUpWidth = wd;
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+popUpWidth+",height="+popUpHeight+",left = " + winLeft + ",top = " + winUp + "');");
    }
    
function doConfirmPopUP(URL) {
    var winLeft = (screen.width - 200) / 2;
    var winUp = (screen.height - 25) / 2;
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=150,left = " + winLeft + ",top = " + winUp + "');");
}

function disableSelection(element) {
    element.onselectstart = function() {
        return false;
    };
    element.unselectable = "on";
    element.style.MozUserSelect = "none";
    element.style.cursor = "default";
}
function showLongValueEditor(URL, formRef, element){
	var win = window.open(URL, 'LongValueEditor',
		'height=360,width=620,toolbar=0,menubar=0,scrollbars=1,resizable=1,status=1,location=0,left=30,top=30');
		
	win.opener = self;	
	// Set reffering field in the new window so that the value can be updated from there.
	win.reffield = document.forms[formRef].elements[element];
	win.focus();
}
