if( ! Fse ) Fse = {}; Fse.REC = {}; Fse.REC.resetKeyword = function() { document.getElementById( "recKeyword" ).value = ""; }; Fse.REC.resetCategory = function() { var oCategory = document.getElementById( "recCategory" ); if( oCategory ) { oCategory.selectedIndex = 0; } }; Fse.REC.resetSearch = function() { Fse.REC.resetCategory(); Fse.REC.resetKeyword(); Fse.FormManager.submit( document.frm_recipeSearchCenter, true ); }; Fse.REC.recalculateRecipe = function() { if( Fse.FormManager.submit( document.frm_recalcRecipe, false )) { var oServings = document.getElementById( "servings" ); if( oServings ) { var sLocation = Fse.REC.getNewLocation( "recalc=true&servings=" + oServings.value ); Fse.Ajax.updateContent( sLocation, "recipe-details" ); } } }; Fse.REC.getNewLocation = function( sNewQueryString ) { var sLocation = window.location.href; var sURL = sLocation.replace( /\?.*/, "" ); var sQueryString = sLocation.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]; if( sQueryString.search( sParam + "=" ) >= 0 ) { var rParam = new RegExp ( sParam + "=[^&]*" ); sQueryString = sQueryString.replace( rParam, sQueryStringParam ); } else { if( sQueryString.length > 0 ) { sQueryString = sQueryString + "&" + sQueryStringParam; } else { sQueryString + sQueryStringParam; } } } if( sQueryString.length > 0 ) { sLocation = sURL + "?" + sQueryString; } else { sLocation = sURL; } return sLocation; }; Fse.REC.fetchRecipeCounts = function( aIds ) { var fnCallback = function( oRequest ) { for( var idx = 0; idx < aIds.length; idx++ ) { var sId = aIds[idx]; var nRecipeCount = oRequest.xhRequest.getResponseHeader( "recipe-count-" + sId ); if( nRecipeCount && nRecipeCount > 0 ) { var oLookupLink = document.getElementById( sId ); var oLinkElement = document.createElement( "a" ); oLinkElement.setAttribute( "href", oLookupLink.getAttribute( "href" )); var sRecipeCountText = nRecipeCount + "\xA0recipe"; if( nRecipeCount > 1 ) { sRecipeCountText = sRecipeCountText + "s"; } var oCountNode = document.createTextNode( "(" + sRecipeCountText + ")"); oLinkElement.appendChild( oCountNode ); oLookupLink.appendChild( oLinkElement ); /* var oImageNode = document.createElement( "img" ); oImageNode.setAttribute( "src", oLookupLink.getAttribute( "src" )); oImageNode.setAttribute( "onclick", "window.location.href='" + oLookupLink.getAttribute( "href" ) + "'" ); oLookupLink.appendChild( oImageNode ); */ } } }; var sCountURL = "?do=getRecipeCount"; for( var idx = 0; idx < aIds.length; idx++ ) { sCountURL = sCountURL + "&lookupId=" + encodeURIComponent(aIds[idx]); } Fse.Ajax.getURL( sCountURL, fnCallback ); };