/** * This method is used to move options from one list to another. */ function addSelectedToList(src,dest) { moveOptions(src,dest); sortList(dest); } /** * */ function moveOptions(src, dest){ for(var i=0; i < src.options.length;i++) { if(src.options[i].selected && src.options[i].value != "-1" && src.options[i].value != "00"){ var no = new Option(); no.value = src.options[i].value; no.text = src.options[i].text; dest.options[dest.options.length] = no; src.options[i] = null; i--; } } } /** * This is a helper method to methods in this file. */ function clearList(list1) { if(list1 == null || typeof(list1) == "undefined" || typeof(list1.options) == "undefined" ){ return; } len = list1.options.length; if ( len > 0 ) { for(i=1;i < len;i++) list1.options[1] = null; } } /** * This moves all options from one list to the other list. */ function addAllToList(src,dest) { selectAll(src); moveOptions(src,dest); sortList(dest); } /** * This uses the quickSort. I don't know of any possible fast method * to fix this. */ function sortList (optionList) { var maxNum = optionList.length; var lowerBound = 0; var upperBound = maxNum - 1; quickSort(optionList, lowerBound, upperBound); } function compare(option1, option2) { return option1.text > option2.text && option1.value != "-1" && option1.value != "0" && option1.value != "00"; } function partition(optionList, lowerBound, upperBound) { var i = lowerBound + 1; var j = upperBound; var p = lowerBound + parseInt((upperBound - lowerBound) / 2); var pivot = createOption(optionList[p].text, optionList[p].value); copyOption(optionList[p], optionList[lowerBound]); while (true) { while (i < j && compare(pivot, optionList[i])) { i++; } while (j >= i && compare(optionList[j], pivot)) { j--; } if (i >= j) { break; } var temp = createOption(optionList[i].text, optionList[i].value); copyOption(optionList[i], optionList[j]); copyOption(optionList[j], temp); j--; i++; } // pivot belongs in optionList[j] copyOption(optionList[lowerBound], optionList[j]); copyOption(optionList[j], pivot); return j; } function createOption(text, value) { var no = new Option(); no.text = text; no.value = value; return no; } function copyOption(option1, option2) { option1.text = option2.text; option1.value = option2.value; } function quickSort(optionList, lowerBound, upperBound){ if (lowerBound < upperBound) { var middle = partition (optionList, lowerBound, upperBound); quickSort(optionList, lowerBound, middle - 1); lowerBound = middle + 1; quickSort(optionList, middle + 1, upperBound); upperBound = middle - 1; } } var stateSelectGlobal = null; var ezStateProvinceIdGlobal = null; var intervalGlobal = null; /** * */ function loadStateProvince(countrySelect, stateSelect, stateProvince) { if(stateSelectGlobal != null){ return; } if(intervalGlobal != null){ clearInterval(intervalGlobal); } var countryIndex = countrySelect.selectedIndex; var countrySelectValue = countrySelect.options[countryIndex].value; if(countrySelectValue == "-1") { clearList(stateSelect); stateSelect.options[0] = new Option("","-1"); stateSelect.disabled=true; } else { stateSelectGlobal = stateSelect; ezStateProvinceIdGlobal = stateProvince; var url = "../util/stateList.jsp?ezCountryId=" + countrySelectValue; loadIFrame(url); } } function loadIFrame(url) { var actionIFrame = " "; //4-16-2012 Used in workspace if(typeof(parent.document.getElementById('actionIFrame')) != "undefined" && parent.document.getElementById('actionIFrame') != null){ actionIFrame = parent.document.getElementById('actionIFrame'); } //4-16-2012 Used in the setup wizard screen else if(typeof(parent.parent.document.getElementById('actionIFrame')) != "undefined" && parent.parent.document.getElementById('actionIFrame') != null){ actionIFrame = parent.parent.document.getElementById('actionIFrame'); } if (actionIFrame.src) { // W3C method actionIFrame.src = url; } else { // assume MSIE-style actionIFrame.location = url; } } /** * This is used when the address needs to be loaded on an address page. */ function fillInStateProvinceList(SectAr) { var stateSelect = stateSelectGlobal; if(stateSelect == null){ return; } clearList(stateSelect); var j = 1; if(SectAr.length != 0){ var choose = "\u0043\u0068\u006f\u006f\u0073\u0065\u0020\u006f\u006e\u0065"; }else{ var choose = "\u004e\u006f\u0074\u0020\u0041\u0076\u0061\u0069\u006c\u0061\u0062\u006c\u0065"; } var option1 = new Option(choose,"-1"); stateSelect.options[0] = option1; stateSelect.disabled=false; for(var i = 1; i < SectAr.length; i++) { var seltext = SectAr[i][1]; var selval = SectAr[i][0]; option1 = new Option(seltext,selval); stateSelect.options[j] = option1; if(ezStateProvinceIdGlobal != null && ezStateProvinceIdGlobal == selval) { stateSelect.options[j].selected = true; } j++; } stateSelectGlobal = null; } /** * This is a helper method to methods in this file. */ function isListEmpty(list1){ if(list1.length <= 0) return true; return false; } /** * This selects all the options in a select, * where you can select multiple options. * ie when you have */ function selectAll(listBox){ for ( var i = 0 ; i < listBox.length; i++) { listBox.options[i].selected=true; } } /** * This is used when you have a select * and are adding options. * * This checks to see that there is at least * one valid option in the list. */ function containsValidOption(listBox,fieldName1, fieldName2){ var atLeastOneValueValid = false; for ( var i = 0 ; i < listBox.length; i++) { if (listBox.options[i].value != -1){ atLeastOneValueValid = true; } } if(atLeastOneValueValid == false){ // if you need to add and 's, add it to the fieldName2 param when calling this method. var msg = MessageUtil.getMessage("\u0054\u0068\u0065\u0072\u0065\u0020\u006d\u0075\u0073\u0074\u0020\u0062\u0065\u0020\u0061\u0074\u0020\u006c\u0065\u0061\u0073\u0074\u0020\u006f\u006e\u0065\u0020\u0023\u0020\u0061\u0064\u0064\u0065\u0064\u0020\u0074\u006f\u0020\u0074\u0068\u0065\u0020\u0023\u0020\u006c\u0069\u0073\u0074\u002e", new Array(fieldName1, fieldName2)); alert(msg); } return atLeastOneValueValid; } /** * This is used when you have a select * and want to make sure that at least * one option is selected */ function selectedValidOption(listBox,fieldName){ var selectedValidOption = false; var val = MessageUtil.getMessage("\u003c\u0041\u006c\u006c\u003e"); for ( var i = 0 ; i < listBox.length; i++) { if (listBox.options[i].selected && (listBox.options[i].value != -1 || listBox.options[i].text.replace(/[<>\s]/g, "") == val.replace(/[<>\s]/g, "") )) { selectedValidOption = true; } } if(selectedValidOption == false){ var msg = MessageUtil.getMessage("\u0050\u006c\u0065\u0061\u0073\u0065\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u0020\u0061\u0020\u0023", new Array(fieldName)); alert(msg); } try{ listBox.focus(); }catch(e){ } return selectedValidOption; } function selectedValidOptionVowel(listBox,fieldName){ var selectedValidOption = false; var val = MessageUtil.getMessage("\u003c\u0041\u006c\u006c\u003e"); for ( var i = 0 ; i < listBox.length; i++) { if (listBox.options[i].selected && (listBox.options[i].value != -1 || listBox.options[i].text == val )){ selectedValidOption = true; } } if(selectedValidOption == false){ var msg = MessageUtil.getMessage("\u0050\u006c\u0065\u0061\u0073\u0065\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u0020\u0061\u006e\u0020\u0023", new Array(fieldName)); alert(msg); } try { listBox.focus(); } catch(e) { // This failed so don't do anything. Just don't throw the exception. // can we write something to the javascript console? } return selectedValidOption; } function selectedValidOptionVowel(listBox,fieldName){ var selectedValidOption = false; for ( var i = 0 ; i < listBox.length; i++) { if (listBox.options[i].selected && (listBox.options[i].value != -1 || listBox.options[i].text == '' )){ selectedValidOption = true; } } if(selectedValidOption == false){ var msg = MessageUtil.getMessage("\u0050\u006c\u0065\u0061\u0073\u0065\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u0020\u0061\u006e\u0020\u0023", new Array(fieldName)); alert(msg); } listBox.focus(); return selectedValidOption; } /** * This is used when there is only one facility in the * table and you want to delect it */ function selectedDeleteValidOption(listBox,fieldName){ var selectedValidOption = false; var len=listBox.length; for ( var i = 0 ; i < listBox.length; i++) { if (listBox.options[i].selected && listBox.options[i].value != -1){ selectedValidOption = true; } } if(selectedValidOption == false){ var msg = MessageUtil.getMessage("\u0054\u0068\u0065\u0072\u0065\u0020\u006d\u0075\u0073\u0074\u0020\u0062\u0065\u0020\u0061\u0074\u0020\u006c\u0065\u0061\u0073\u0074\u0020\u006f\u006e\u0065\u0020\u0023\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u0065\u0064\u002e", new Array(fieldName)); alert( msg); } if(len == 1) { var msg = "\u0054\u0068\u0065\u0072\u0065\u0020\u006d\u0075\u0073\u0074\u0020\u0062\u0065\u0020\u0061\u0074\u0020\u006c\u0065\u0061\u0073\u0074\u0020\u006f\u006e\u0065\u0020\u0066\u0061\u0063\u0069\u006c\u0069\u0074\u0079\u002c\u0020\u0073\u006f\u0020\u0079\u006f\u0075\u0020\u0063\u0061\u006e\u0020\u006e\u006f\u0074\u0020\u0064\u0065\u006c\u0065\u0074\u0065\u0020\u0069\u0074\u002e"; alert(msg); } else { listBox.focus(); return selectedValidOption; } } /** * When dealing with country and stateProvinces you can use this * function to when doing a reset on the form or for * initializing what the country and stateProvince should be * set to. See BuyerFacilityUpdate for an example. */ function initializeStateProvinceCountry(countrySelect, stateProvinceSelect, country,stateProvince){ countrySelect.value=country; var callLoadStateProvinceFunction= function(){loadStateProvince(countrySelect, stateProvinceSelect, stateProvince);}; if(stateSelectGlobal == null){ loadStateProvince(countrySelect,stateProvinceSelect, stateProvince); }else{ var intervalTime = 100; intervalGlobal = window.setInterval(callLoadStateProvinceFunction, intervalTime); } } /** * Checks to make sure that at least one check box * named fieldName has been checked on the form frm. */ function checkboxListValidate(frm,fieldName) { for(i=0; i < frm.elements.length ; i++) { if (frm.elements[i].name==fieldName && frm.elements[i].checked == true) { return true; } } return false; } /** * If user checks the main category check box * then all sub category checkboxes will be selected */ function selectCheckboxList(frm,categoryId,isChecked) { for(i=0; i < frm.elements.length ; i++) { if (frm.elements[i].type== "checkbox" && frm.elements[i].name == categoryId) { frm.elements[i].checked = isChecked; } } } /** * If user checks the priority check box * then show checkbox will be selected */ function selectCheckBox(fld,subCategoryId) { for(i=0; i < fld.form.elements.length ; i++) { if (fld.form.elements[i].type== "checkbox" && fld.form.elements[i].value == subCategoryId) { if(fld.checked){ fld.form.elements[i].checked = true; return; } else { //fld.form.elements[i].checked = false; } } } } /** * If the priority check box * is selected then show checkbox cannot be unchecked */ function unCheckShowBox(fld,subCategoryId) { for(i=0; i < fld.form.elements.length ; i++) { if (fld.form.elements[i].type== "checkbox" && fld.form.elements[i].value == subCategoryId) { if(fld.checked){ return; } else { fld.form.elements[i].checked = false; } } } }