/* ------------------------------------------------ */
/* EXPLORE specific FUNCTIONS
/* ------------------------------------------------ */
maxWidth = 0;

$(document).ready(function() { /* Drop down menu */
    $("#primaryNav li").hover(function() {
            $("ul:not(.subMenu)", this).fadeIn("slow");
        },
        function() {
            // Commented out 10/28/2008 [Jason] $("ul", this).fadeOut("slow");
            $("ul", this).hide();
        }
    );
    $("#primaryNav li ul li").hover(function() {
            $("ul", this).fadeIn("slow");
        },
        function() {
            // Commented out 10/28/2008 [Jason] $("ul", this).fadeOut("slow");
            $("ul", this).hide();
        }
    );
    $("#primaryNav li#nFavs > ul").show();
    $("#primaryNav li#nFavs > ul > li > a").each(function(){
        thisWidth = jQuery(this).width();
        if (maxWidth < thisWidth) maxWidth = thisWidth;
    });
    jQuery(".subMenu").css("left", maxWidth + 10);
    if ($.browser.safari || $.browser.msie || $.browser.mozilla) {
        $("#primaryNav li").hoverClass("sfHover");
    }
});

$.fn.hoverClass = function(c) {
    return this.each(function() {
        $(this).hover(
                function() {
                    $(this).addClass(c);
                },
                function() {
                    $(this).removeClass(c);
                }
                );
    });
};

// PageType and PageSubtype needed for Topseller ajax call. The start.jsp calls setPageDetails
var pageType = '/';
var pageSubtype = 'computers/laptops';

function setPageDetails(type, subtype) {
    pageType = type;
    pageSubtype = subtype;
}

function setTopNavSelection(id) {
    document.getElementById(id).className = "selected";
}

function getTopSellers(divElement) {
    new ajax().update("/showcase/explore/jsp/catalog/topsellersAjax.jsp",
            divElement,
    {
        onLoading : function() {
            getElementById(divElement).innerHTML = "<img src='/images/assets/ajax_loader.gif' alt='Retrieving Topsellers..'/><b>Retrieving Topsellers..</b><br/>"
        },
        onError   : function(request) {
            if (request.instance.status == 404) {
                getElementById(divElement).innerHTML = "<!-- Page not found -->";
            }
        },
        parameters: {type:pageType,subtype:pageSubtype}
    }
            );
}

function getRelatedModels(divElement, subBrand) {
    new ajax().update(pageContext + "/catalog/seriesAjax.jsp",
            divElement,
    {
        parameters: {pageSubBrand:subBrand}
    }
            );
}

function getMediaValueByVideoId(videoId, method, callback) {
	new ajax().request("/showcase/explore/jsp/common/mediaAjax.jsp", {
			method : 'POST',
			parameters : {videoId:videoId,method:method},
			onSuccess : function(request) {
				response = trim(request.getResponseText());
				if (response != "") {
					//remove html comments
					response = response.replace(/\n/g, "").replace(/\r/g, "");
					while ((response.indexOf("<!--") >= 0)){
						if (response.indexOf("<!--") >= 0){
							var startIndex = response.indexOf("<!--");
							var endIndex = response.indexOf("-->") + 3;
							response = response.substring(0, startIndex) + response.substring(endIndex, response.lentgh);
						}
					}
					response = trim(response);
					if (typeof callback == 'function') 
						return callback(response, method);
				}
			}
		}
		);
}


function getProductPrice(prodId, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/priceAjax.jsp",
            placeholder,
    {
        parameters: {prodId:prodId,formatted:false}
    }
            );
}

function getFormattedProductPrice(prodId, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/priceAjax.jsp",
            placeholder,
    {
        parameters: {prodId:prodId,formatted:true}
    }
            );
}

function getFormattedSeriesPrice(catPath, catName, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/priceAjax.jsp",
            placeholder,
    {
        parameters: {catPath:catPath,catName:catName,formatted:true}
    }
            );
}

function getSeriesPrice(catPath, catName, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/priceAjax.jsp",
            placeholder,
    {
        parameters: {catPath:catPath,catName:catName,formatted:false}
    }
            );
}

function getFormattedSubBrandPrice(catPath, catName, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/priceAjax.jsp",
            placeholder,
    {
        parameters: {catPath:catPath,catName:catName,formatted:true}
    }
            );
}


function getSubBrandPrice(catPath, catName, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/priceAjax.jsp",
            placeholder,
    {
        parameters: {catPath:catPath,catName:catName,formatted:false}
    }
            );
}

function getRatingValue(prodId, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/ratingsAjax.jsp",
            placeholder,
    {
        parameters: {prodId:prodId,ratingValue:true,ratingImage:false}
    }
            );
}

function getRatingImage(prodId, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/ratingsAjax.jsp",
            placeholder,
    {
        parameters: {prodId:prodId,ratingValue:false,ratingImage:true}
    }
            );
}

function getSeriesRatingValue(catPath, catName, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/ratingsAjax.jsp",
            placeholder,
    {
        parameters: {catPath:catPath,catName:catName,ratingValue:true,ratingImage:false}
    }
            );
}

function getSeriesRatingImage(catPath, catName, placeholder) {
    new ajax().update("/showcase/explore/jsp/common/ratingsAjax.jsp",
            placeholder,
    {
        parameters: {catPath:catPath,catName:catName,ratingValue:false,ratingImage:true}
    }
            );
}

function captureTabEvent(eventName) {
    try {
        s=s_gi(s_account);
        s.linkTrackVars="eVar1,eVar2,eVar3,eVar4,eVar23,events";
        s.eVar23=eventName;
        if("Reviews" == eventName) {
            s.events="event21,event23";
            s.linkTrackEvents="event21,event23"
        } else {
            s.events="event23";
            s.linkTrackEvents="event23"
        }
        s.tl(this,'o',eventName);
        s.eVar23="";
        s.events="";
    } catch(e) {}
}

//function to show  overview tab on sku detail page
function showSkuOverview(series, displayName, isAccessory, divElement) {
	new ajax().update("/showcase/explore/jsp/catalog/panel/showOverviewAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {captureTabEvent("Overview");} catch(e){}},
           parameters: {series: series, displayName:displayName, isAccessory:isAccessory}
       }
     );
}

//function to show  specs tab on sku detail page
function showSkuSpecs(series, displayName, isAccessory, divElement) {
	new ajax().update("/showcase/explore/jsp/catalog/panel/showSpecsAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {captureTabEvent("Specifications");} catch(e){}},
           parameters: {series: series, displayName:displayName, isAccessory:isAccessory}
       }
     );
}

//function to show Description tab on sku detail page (currently used for accessory only)
function showSkuDescription(series, displayName, isAccessory, divElement) {
	new ajax().update("/showcase/explore/jsp/catalog/panel//showDescriptionAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {captureTabEvent("Description");} catch(e){}},
           parameters: {series: series, displayName:displayName, isAccessory:isAccessory}
       }
     );
}

//function to show features tab on sku detail page
function showSkuFeatures(series, displayName, isAccessory, divElement) {
	new ajax().update("/showcase/explore/jsp/catalog/panel/showFeaturesAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {captureTabEvent("Features");} catch(e){}},
           parameters: {series: series, displayName:displayName, isAccessory:isAccessory}
       }
     );
}

//function to show image-gallery tab on detail page
function showSkuGallery(series, displayName, isAccessory, divElement) {
    new ajax().update("/showcase/explore/jsp/catalog/panel/showGalleryAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {captureTabEvent("Gallery"); loadSkuGallery(); } catch(e){}},
           parameters: {series: series, displayName:displayName, isAccessory:isAccessory}
       }
     );
}

//function to show customer reviews tab on sku detail page
function showSkuCustomerReviews(series, displayName, isAccessory, order, divElement, pop) {
	new ajax().update("/showcase/explore/jsp/catalog/panel/showReviewsAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() { try {callReviewJS(); captureTabEvent("Reviews");} catch(e){} },
           parameters: {series: series, displayName:displayName, isAccessory:isAccessory, order:order, pop:pop}
       }
     );
}

//function to show videos tab on sku detail page
function showSkuVideos(series, displayName, isAccessory, divElement) {
	new ajax().update("/showcase/explore/jsp/catalog/panel/showVideosAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {callVideosJS(); captureTabEvent("Videos");} catch(e){}},
           parameters: {series: series, displayName:displayName, isAccessory:isAccessory}
       }
     );
}


//function to show overview tab on series page
function showSeriesOverview(catPath, catName, divElement) {                            
	new ajax().update("/showcase/explore/jsp/catalog/panel/showSeriesOverviewAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {callExtrasRotatorJS(); captureTabEvent("Overview");} catch(e){}},
           parameters: {catPath:catPath, catName:catName}
       }
     );
}

//function to show gallery tab on series page
function showSeriesImageGallery(catPath, catName, divElement) {
    new ajax().update("/showcase/explore/jsp/catalog/panel/showSeriesImageGalleryAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {captureTabEvent("Image Gallery");} catch(e){}},
           parameters: {catPath:catPath, catName:catName}
       }
     );
}

//function to show ask and answers tab on series page
function showSeriesAnswers(catPath, catName, divElement) {
    new ajax().update("/showcase/explore/jsp/catalog/panel/showSeriesAnswersAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {callSeriesAnswersJS();captureTabEvent("Answers");} catch(e){}},
           parameters: {catPath:catPath, catName:catName}
       }
     );
}

//function to show reviews tab on series page
function showSeriesReviews(catPath, catName, order, divElement) {
    new ajax().update("/showcase/explore/jsp/catalog/panel/showSeriesReviewsAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {callReviewJS();captureTabEvent("Reviews");} catch(e){}},
           parameters: {catPath:catPath, catName:catName, order:order}
       }
     );
}

//function to show accessories tab on series page
function showSeriesAccessories(catPath, catName, divElement) {
    new ajax().update("/showcase/explore/jsp/catalog/panel/showSeriesAccessoriesAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {captureTabEvent("Accessories");} catch(e){}},
           parameters: {catPath:catPath, catName:catName}
       }
     );
}

//function to show videos tab on series page
function showSeriesVideo(catPath, catName, divElement) {
    new ajax().update("/showcase/explore/jsp/catalog/panel/showSeriesVideoAjax.jsp",
       divElement,
       {
           onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
           onPostSuccess: function() {try {callVideosJS(); captureTabEvent("Video");} catch(e){}},
           parameters: {catPath:catPath, catName:catName}
       }
     );
}

function callSeriesAnswersJS(){
     if (document.getElementById("AAScripts")){
		eval(document.getElementById("AAScripts").innerHTML);
	}
}

function changeSeriesReviewOrder(catPath, catName){
        var order = document.getElementById("sortOrder").options[document.getElementById("sortOrder").selectedIndex].value;
        showSeriesReviews(catPath, catName, order, 'ajaxPanel');
}

function callExtrasRotatorJS(){
	if (document.getElementById("extrasRotatorScripts")){
		eval(document.getElementById("extrasRotatorScripts").innerHTML);
	}
}


function callReviewJS(){
	if (document.getElementById("paginationScripts")){
		eval(document.getElementById("paginationScripts").innerHTML);
	}
}

function callVideosJS(){
	if (document.getElementById("videoScripts")){
		eval(document.getElementById("videoScripts").innerHTML);
	}
}

function changeReviewOrder(series, displayName, isAccessory, pop){
        var order = document.getElementById("sortOrder").options[document.getElementById("sortOrder").selectedIndex].value; 
        //if pop is true, the page is opened is new window. Just change URL and reload.
        if (pop == "true"){
        	var url = location.href;
        	var startIndex = url.indexOf("&order=");
        	var endIndex = url.indexOf("&pop=");
        	var newUrl = url.substring(0,startIndex)+"&isAccessory="+ isAccessory +"&order="+order+url.substring(endIndex);
        	window.location.href = newUrl;
        	
        } else
        	showSkuCustomerReviews(series, displayName, isAccessory, order, 'ajaxPanel', pop);
}

function switchGalleryid(id, noOfIds){
	hideallGalleryids(noOfIds);
	showGallerydiv(id);
}

function hideallGalleryids(noOfIds){
	//loop through the array and hide each element by id
	for (var i=0;i<noOfIds;i++){
		hideGallerydiv('pic' + i);
	}
}

function hideGallerydiv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	    //alert(id);
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}


function showGallerydiv(id) {
	//safe function to show an element with a specified id

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function displayReviewsTab() {
    changeTabImage(this);
    document.getElementById('tab4').className = 'selected';
    
    if (document.getElementById("tab4"))
        document.getElementById("tab4").scrollIntoView();
}

//function for image gallery on sky detail page
(function($) {
  var s = s || {};
  $.fn.sku_gallery = function(options) {
    this.each(function() {

      var defaults = {
        holder: '.thumbs',
        imgs: 'a',
        imgs_height: null,
        arrows: 'a.nav-arrow',
        img_id: 'gallery-image',
        disabled_class: 'unclickable',
        imgs_per: 6
      }

      s = $.extend(defaults, options);

      s.holder = $(s.holder, this),
        s.imgs = $(s.imgs, s.holder),
        s.imgs_height = s.imgs_height || s.imgs.eq(0).outerHeight(),
        s.imgs_height_total = (s.imgs_height * (s.imgs.length - s.imgs_per)),
        s.arrows = $(s.arrows, this);

      s.imgs.click(function(e) {
        e.preventDefault();
        //document.getElementById(s.img_id).src = this.href;
      });



      s.arrows.click(function(e) {
        e.preventDefault();
        if ($(this).hasClass(s.disabled_class)) return this;

        amt = (this == s.arrows[0]) ? s.imgs_height : s.imgs_height * -1;
        
        thumbs_top = parseInt(s.holder.css('top'));
        thumbs_top_new = thumbs_top + amt;
        switch (thumbs_top_new) {
          case 0:
            s.arrows.eq(0).addClass(s.disabled_class);
            break;
          case (s.imgs_height_total * -1):
            s.arrows.eq(1).addClass(s.disabled_class);
            break;
          default:
            s.arrows.removeClass(s.disabled_class);
            break;
        }
        
        	
        s.holder.animate({ top: thumbs_top_new }, 200);
        //fix for top scroll arrow not appearing - start
        if(thumbs_top==0){
		s.arrows.eq(0).removeClass(s.disabled_class);
        }
        if(thumbs_top==-1*amt){
		s.arrows.eq(1).removeClass(s.disabled_class);
        }
        //fix for top scroll arrow not appearing - end
      });
      if (s.imgs.length > 6) s.arrows.eq(1).removeClass(s.disabled_class);
    });
  }
})(jQuery);


function loadSkuGallery() {
        $('#gallery').sku_gallery({ imgs_height: 83 });
}

function displayContentBlock(divElement,ruleName,ruleValue,contName) {
$(document).ready(function () {
	jQuery("#" + divElement).load(
		"/showcase/explore/jsp/common/contentBlockAjax.jsp",
		{ruleName:ruleName,ruleValue:ruleValue,contName:contName}
	);
 });

}

jQuery(function ($) {
window.disclaimer = function (shortName) {
     var divElement = 'disclaimer-overlay';
     var disclaimer_box = $('#' + divElement);
     new ajax().update("/showcase/explore/jsp/common/disclaimerAjax.jsp",
           divElement,
           {
                onError : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
                onPostSuccess: function() {
                           var position = scroll_position();
                           position.top += ($(window).height() - disclaimer_box.height()) / 2;
                           position.left += ($(window).width() - disclaimer_box.width()) / 2;
                          disclaimer_box.css(position).show().find('a.close').click(function (e) { e.preventDefault(); disclaimer_box.hide() });
                },
                parameters: {shortName:shortName}
           }
     );
} // window.disclaimer
});

function search(form) {
     var st = document.getElementById(form || 'gSrch').search_term.value;
     if (st.search(/[A-Za-z0-9]/) != -1) { st = st.replace("\n", " ", "g").replace("\r", " ", "g").replace(/Ã©|&eacute;/g, 'e').replace(/Â®|&reg;|â„¢|&trade;/g, ''); window.location = "/search/" + encodeURI(st); }
     else { alert("Please enter a keyword or phrase to search.") }
     return false;
}

function lookupTitle(event, searchBoxId, autoSuggestDivId){
        var keyPressed;
        if (event) {
            keyPressed = event.charCode ? event.charCode : event.keyCode;
        }
        else if (window.event) {
            keyPressed = window.event.charCode ? window.event.charCode : window.event.keyCode;
        }

        var productResultsFound = 0;
        var contentResultsFound = 0;
        var autoSuggestSize =  maxProductResultsAllowed + maxContentResultsAllowed + 2;
        var searchBoxValue = document.getElementById(searchBoxId).value;
        var searchKeyArray = searchBoxValue.split(" ");
        var searchResults = "<div id=\"instant-results\">";
        var matchFound = false;     //this is used per title.
        var resultFound = false;  //this is global value.. true mean autosuggest to return result
        if (enableAutoSuggest && searchBoxValue.length > 0){
            for (var i = 0; i < titleArray.length; i++){
                matchFound = false;
                var val = titleArray[i];
                var titleValue = val.split("#-#->")[0];
				var descriptionValue = val.split("#-#->")[1];
                var fullPath = val.split("#-#->")[2];
				var thumbnailPath = val.split("#-#->")[3];
                var type = val.split("#-#->")[4];
				if (type.toUpperCase() == 'PRESS RELEASE') //treat press release same as content
					type = 'CONTENT';
					
                //only lookup for 5 products match
                if (type.toUpperCase() == 'PRODUCT' && productResultsFound >= maxProductResultsAllowed)
                    continue;

                //only lookup for 5 content match
                if (type.toUpperCase() == 'CONTENT' && contentResultsFound >= maxContentResultsAllowed)
                    continue;

                for (var j = 0; j < searchKeyArray.length; j++ ){
                    var wordToSearch = searchKeyArray[j];
					wordToSearch = wordToSearch.replace(/\"/g,'&quot;'); //replace all double quotes to &quot; before doing lookup
                    if (titleValue.replace(/&eacute;/g, 'e').toUpperCase().indexOf(wordToSearch.toUpperCase()) >= 0){
                        matchFound = true;
                    } else {
                        matchFound = false;
                        break;
                    }
                }
                if (matchFound){
					//generate starting tags
                    if (type.toUpperCase() == 'PRODUCT'){
                        if (productResultsFound == 0){
                            searchResults += "<div class=\"product-results section\">";
							searchResults += "<h1 class=\"section-title\">Products</h1>";
                        }
                        productResultsFound++;
                    }
                    else if (type.toUpperCase() == 'CONTENT') {
						//if products found, close products <div>
						if (productResultsFound > 0 && contentResultsFound == 0) { 
							searchResults += "</div>";
						}
                        if (contentResultsFound == 0) {
                            searchResults += "<div class=\"content-results section\">";
							searchResults += "<h1 class=\"section-title\">Articles</h1>";
                        }
                        contentResultsFound++;
                    }
					
					//generate each result
                    resultFound = true;
					if (type.toUpperCase() == 'PRODUCT'){
						searchResults += "<a href=\""+fullPath+"\" class=\"link\">";
						searchResults +=  "<span class=\"img\"><img src=\""+ thumbnailPath +"\" alt=\""+ titleValue +"\" title=\""+ titleValue +"\" /></span>";
						searchResults += "<strong>"+ titleValue +"</strong>";
						searchResults += "<span class=\"desc\">"+ descriptionValue +"</span>";
						searchResults += "</a>";
					} else if (type.toUpperCase() == 'CONTENT') {
						searchResults += "<a href=\""+fullPath+"\" class=\"link\">" + titleValue +" </a>";
					}
                }
            }
			if (contentResultsFound > 0) {
			    searchResults += "</div>";
		    }
        }

		//if content found, close content <div>
		if (contentResultsFound > 0) { 
			searchResults += "</div>";
		}
        searchResults += "</div>";

		if (productResultsFound == 0 && contentResultsFound == 0)
				searchResults = "";
		
		getElementById(autoSuggestDivId).innerHTML = searchResults;		
        if (searchResults != "") {
				show(autoSuggestDivId);
		} else {
			hide(autoSuggestDivId);
		}
    }
	
function suggestResultsKeyUp (event) {
    var asciiKey;
	if (event)
		asciiKey = event.charCode ? event.charCode : event.keyCode;
	else
		asciiKey = window.event.charCode ? window.event.charCode : window.event.keyCode;
	if (asciiKey == 13) {
		if (document.autosuggest || document.gSrch){
			window.location = getElementById("SuggestResults").options[getElementById("SuggestResults").selectedIndex].value;
		}
	}
};
	
function submitSearch(elementId){
	var st = document.getElementById(elementId).value;
    if (st.search(/[A-Za-z0-9]/) != -1) { 
		st = st.replace("\n", " ", "g").replace(/\"/g,'').replace(/\?/g,'').replace(/%/g,'').replace("\r", " ", "g").replace(/é|&eacute;/g, 'e').replace(/&/g, '').replace(/®|&reg;|&#174|™|&trade;/g, '');		
		window.location = "/search/" + encodeURI(st); 
	 }
     else { alert("Please enter a keyword or phrase to search.") }
     return false;  
}

function paginateSearchResults(nValue, params, hValue ){
    updateSearchResults(nValue, params, hValue);
}

function updateSearchResults(nValue, params, hValue ){
    var url = "/showcase/explore/jsp/search/naturalSearchResultsUTC.jsp?"+params;
    if (nValue != null){
        url = url + "&N=" +nValue + "&ajaxCall=true";
    }
    jQuery.ajax({
        type: "GET", /* IE does not cache any more with POST */
        url: url,
		cache: true,
        success: function(data, textStatus) {
            if (document.getElementById("results-container"))
                document.getElementById("results-container").innerHTML  =   data;
        },
        error: function(request, textStatus, errorThrow) {
            if (request.status == 404) {
                if (document.getElementById("results-container"))
                    document.getElementById("results-container").innerHTML  =  "<!-- Page not found -->";                
            }
        }
        }); //end of ajax call
}

function scrollToResults(){
    scroll(0, $('#utcResultsDiv').offset().top)
}

function selectRefinement(nValue, otherParams, hValue){
    updateSearchResults(nValue, otherParams, hValue);
}

function changeSortOrderOfSearchResults(nValue, otherParams, hValue){
    var order = document.getElementById("sortBy").options[document.getElementById("sortBy").selectedIndex].value;
    if (order != 'pSearchResultDefault') { //don't add sort parameter for default result, else Ntk will be disabled.
        otherParams+="&Ns="+order;
    }
    updateSearchResults(nValue, otherParams, hValue);
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

function setCookie( name, value, expiryInDays, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );

    //  if the expiryInDays variable is set, make the correct  expires time
    if ( expiryInDays ){
        expiryInDays = expiryInDays * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expiryInDays) );


    document.cookie = name + "=" +(  value ) +
    ( ( expiryInDays ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );

}

	




