var Fse; if( ! Fse ) Fse = {}; if( ! Fse.TPF ) Fse.TPF = {}; Fse.TPF.selectForecastTab = function( sTabName ) { Fse.TPF.newLocation( "forecastTab", sTabName ); }; Fse.TPF.selectForecastScope = function( sScopeName ) { Fse.TPF.newLocation( "scope", sScopeName ); }; Fse.TPF.drillDown = function( sNewQueryString ) { return Fse.TPF.get( sNewQueryString ); }; Fse.TPF.get = function( sNewQueryString, sParametersToSuppress ) { var sURL = window.location.pathname; var sQueryString = window.location.search.replace( /.*\?/, "" ); var aParts = sNewQueryString.split( "&" ); for( var iPartIdx = 0; iPartIdx < aParts.length; iPartIdx++ ) { var sQueryStringParam = aParts[iPartIdx]; var aParsed = sQueryStringParam.split( "=" ); var sParam = aParsed[0]; var sValue = aParsed[1]; var reParamSearch = new RegExp( sParam + "=", "i" ); if( sQueryString.search( reParamSearch ) >= 0 ) { var rParam = new RegExp ( sParam + "=[^&]*", "i" ); sQueryString = sQueryString.replace( rParam, sQueryStringParam ); } else { if( sQueryString.length > 0 ) { sQueryString = sQueryString + "&" + sQueryStringParam; } else { sQueryString = sQueryStringParam; } } } if( sParametersToSuppress ) { var aParameters = sParametersToSuppress.split( "," ); var oParametersToSuppress = {} for( var pIdx = 0; pIdx < aParameters.length; pIdx++ ) { oParametersToSuppress[aParameters[pIdx].toLowerCase()] = true; } var sNewQueryString = ""; var aQueryStringParameters = sQueryString.split( "&" ); for( var qIdx = 0; qIdx < aQueryStringParameters.length; qIdx++ ) { var aParts = aQueryStringParameters[qIdx].split( "=" ); if( ! oParametersToSuppress[aParts[0].toLowerCase()]) { if( sNewQueryString != "" ) { sNewQueryString = sNewQueryString + "&"; } sNewQueryString = sNewQueryString + aQueryStringParameters[qIdx]; } } sQueryString = sNewQueryString; } var sLocation = sURL; if( sQueryString.length > 0 ) { sLocation = sLocation + "?" + sQueryString; } window.location.href = sLocation; }; Fse.TPF.newLocation = function ( sParam, sValue ) { var sLocation = window.location.href; var sQueryStringParam = sParam + "=" + encodeURIComponent( sValue ); var sNewLocation; if( sLocation.search( sParam ) >= 0 ) { var rParam = new RegExp ( sParam + "[^&]*" ); sNewLocation = sLocation.replace( rParam, sQueryStringParam ); } else { if( sLocation.indexOf( "?" ) >= 0 ) { sNewLocation = sLocation + "&" + sQueryStringParam; } else { sNewLocation = sLocation + "?" + sQueryStringParam; } } window.location.href = sNewLocation; }; Fse.TPF.productCategoryChanged = function( iCategoryId ) { var oListBox = document.tpf_reportCriteria.prodId; if( iCategoryId == 0 ) { oListBox.options[0].selected = true; oListBox.disabled = true; } else { // select the first one oListBox.options[0].selected = true; // clear the list box of all but the first one for( var i = oListBox.options.length - 1; i > 0; i-- ) { oListBox.remove( i ); } // repopulate based on the selected category id for( var i = 0; i < Fse.TPF._productRange.length; i++ ) { var oProduct = Fse.TPF._productRange[i]; if( oProduct.categoryId == iCategoryId ) { var oOption = document.createElement( "option" ); oOption.appendChild( document.createTextNode( oProduct.product + " - " + oProduct.shortDesc )); oOption.setAttribute( "value", oProduct.prodId ); oListBox.appendChild( oOption ); } } // enable the selector oListBox.disabled = false; } }; Fse.TPF.resetReportCriteria = function( oForm ) { var sLocation = window.location.href; var sURL = sLocation.replace( /\?.*/, "" ); window.location.href=sURL; }; Fse.TPF.postValidateReportCriteria = function( oForm ) { return true; }; Fse.TPF.onTerritoryChange = function( iValue ) { if( iValue != 0 ) { if( document.tpf_reportCriteria.operatorId ) { document.tpf_reportCriteria.operatorId.value = 0; } } }; Fse.TPF.onAccountChange = function( iValue ) { if( iValue != 0 ) { if( document.tpf_reportCriteria.territoryId ) { document.tpf_reportCriteria.territoryId.selectedIndex = 0; } } }; Fse.TPF.toggleAllProducts = function( bChecked ) { if( bChecked ) { document.tpf_reportCriteria.categoryId.disabled = true; document.tpf_reportCriteria.prodId.disabled = true; document.tpf_reportCriteria.sku.disabled = true; } else { if( document.tpf_reportCriteria.sku.value == "" ) { document.tpf_reportCriteria.categoryId.disabled = false; // only enable this one, when the category has been picked document.tpf_reportCriteria.prodId.disabled = document.tpf_reportCriteria.categoryId.selectedIndex == 0; document.tpf_reportCriteria.sku.disabled = false; } else { document.tpf_reportCriteria.sku.disabled = false; document.tpf_reportCriteria.categoryId.disabled = true; document.tpf_reportCriteria.prodId.disabled = true; } } }; Fse.TPF.skuChanged = function() { Fse.TPF.toggleAllProducts( false ); }; Fse.TPF.toggleAllAccounts = function( bChecked ) { document.tpf_reportCriteria.operatorId.disabled = bChecked; document.tpf_reportCriteria.territoryId.disabled = bChecked; }; Fse.TPF.editUnitCounts = function( iOperatorId, iOperatorTk ) { Fse.Ajax.updateContent( "?operatorId=" + iOperatorId + "&operatorTk=" + iOperatorTk + "&view=editUnitCounts", "forecast_minibox", { "fseApplication" : "TPF" } ); }; Fse.TPF.saveUnitCounts = function() { if( Fse.FormManager.submit( document.frm_updateUnitCounts, false )) { var oRequest = Fse.Ajax.sendForm( document.frm_updateUnitCounts ); Spry.Utils.setInnerHTML( "forecast_minibox", oRequest.responseText ); } };