var postEntity = ''; var postGovLevel = ''; var Entity = '\STATE:1:State of Utah|'; // GovLevel data table // // To edit the list, just delete a line or add a line. Order is important. // The order displayed here is the order it appears on the drop down. // var GovLevel = '\ STATE:State\ '; //COUNTY:County|\ //CITY:City|\ //SCHOOL DISTRICTS:School Districts|\ //SPECIAL DISTRICTS:Special Districts\ //'; var FiscalPeriod = '\STATE:1:State of Utah:2009 (07/01/08-06/30/09):2009:1|STATE:1:State of Utah:2009 (07/01/08-06/30/09):2009:2|'; function TrimString(sInString) { if ( sInString ) { sInString = sInString.replace( /^\s+/g, "" );// strip leading return sInString.replace( /\s+$/g, "" );// strip trailing } } // Populates the GovLevel selected with the counties from the GovLevel list function populateGovLevel(defaultGovLevel) { if ( postGovLevel != '' ) { defaultGovLevel = postGovLevel; } var GovLevelLineArray = GovLevel.split('|'); // Split into lines var selObj = document.getElementById('govLevel'); // selObj.options[0] = new Option('--- Select ---',''); // selObj.selectedIndex = 0; for (var loop = 0; loop < GovLevelLineArray.length; loop++) { lineArray = GovLevelLineArray[loop].split(':'); GovLevelCode = TrimString(lineArray[0]); GovLevelName = TrimString(lineArray[1]); if ( GovLevelCode != '' ) { selObj.options[loop] = new Option(GovLevelName, GovLevelCode); } if ( defaultGovLevel == GovLevelCode ) { selObj.selectedIndex = loop; } } } //populate fiscal period function populateFiscalPeriod() { var selObj = document.getElementById('year'); var foundEntity = false; // Empty options just in case new drop down is shorter if ( selObj.type == 'select-one' ) { for (var i = 0; i < selObj.options.length; i++) { selObj.options[i] = null; } selObj.options.length=null; selObj.options[0] = new Option('',''); selObj.selectedIndex = 0; } // Populate the drop down with Entities from the selected GovLevel var FiscalPeriodLineArray = FiscalPeriod.split("|"); // Split into lines var optionCntr = 0; for (var loop = 0; loop < FiscalPeriodLineArray.length; loop++) { lineArray = FiscalPeriodLineArray[loop].split(":"); GovLevelCode = TrimString(lineArray[0]); EntityCode = TrimString(lineArray[1]); EntityName = TrimString(lineArray[2]); FiscalCode = TrimString(lineArray[3]); FiscalName = TrimString(lineArray[4]); transType = TrimString(lineArray[5]); ////document.getElementById('EntitySelect').value == EntityCode && if (document.getElementById('entityId').value==EntityCode && EntityCode != '' && document.getElementById('trans_type').value==transType ) { if ( selObj.type == 'text' ) { parentObj = document.getElementById('year').parentNode; parentObj.removeChild(selObj); var inputSel = document.createElement("SELECT"); inputSel.setAttribute("name","year"); inputSel.setAttribute("id","year"); parentObj.appendChild(inputSel) ; } if (document.getElementById('trans_type').value==transType && FiscalCode!= '' && EntityCode != '') { selObj.options[optionCntr] = new Option(FiscalCode, FiscalName); } // See if it's selected from a previous post if ( EntityCode == postEntity && FiscalCode == postFiscalCode) { selObj.selectedIndex = optionCntr; } foundEntity = true; optionCntr++ } } } function getFirstEntity(name) { var firstEntityName = name; // document.write(firstEntityName); document.getElementById('firstEntityName').value = firstEntityName; } function populateEntity() { var selObj = document.getElementById('entityId'); var foundEntity = false; // Empty options just in case new drop down is shorter if ( selObj.type == 'select-one' ) { for (var i = 0; i < selObj.options.length; i++) { selObj.options[i] = null; } selObj.options.length=null; selObj.options[0] = new Option('--- Select Entity ---',''); selObj.selectedIndex = 0; } // Populate the drop down with Entitys from the selected GovLevel var EntityLineArray = Entity.split("|"); // Split into lines var optionCntr = 0; for (var loop = 0; loop < EntityLineArray.length; loop++) { lineArray = EntityLineArray[loop].split(":"); GovLevelCode = TrimString(lineArray[0]); EntityCode = TrimString(lineArray[1]); EntityName = TrimString(lineArray[2]); if (document.getElementById('govLevel').value == GovLevelCode && GovLevelCode != '' ) { // If it's a input element, change it to a select if ( selObj.type == 'text' ) { parentObj = document.getElementById('entityId').parentNode; parentObj.removeChild(selObj); var inputSel = document.createElement("SELECT"); inputSel.setAttribute("name","entityId"); inputSel.setAttribute("id","entityId"); parentObj.appendChild(inputSel) ; // selObj = document.getElementById('entityId'); // selObj.options[0] = new Option('Select Entity',''); // selObj.selectedIndex = 0; } if ( EntityCode != '' ) { selObj.options[optionCntr] = new Option(EntityName, EntityCode); } // See if it's selected from a previous post if ( EntityCode == postEntity && GovLevelCode == postGovLevel ) { selObj.selectedIndex = optionCntr; var FirstEntity = EntityName; //Run the function getFirstEntity(FirstEntity); } foundEntity = true; optionCntr++ } } // If the GovLevel has no Entities, change the select to a text box if ( ! foundEntity ) { parentObj = document.getElementById('entityId').parentNode; parentObj.removeChild(selObj); // Create the Input Field var inputEl = document.createElement("INPUT"); inputEl.setAttribute("id", "entityId"); inputEl.setAttribute("type", "text"); // inputEl.setAttribute("name", "Entity"); inputEl.setAttribute("size", 1); // inputEl.setAttribute("style", "display:none;"); inputEl.setAttribute("value", postEntity); parentObj.appendChild(inputEl) ; } populateFiscalPeriod(); } function initGovLevel(GovLevel) { populateGovLevel(GovLevel); populateEntity(); populateFiscalPeriod(); } //-->