﻿$(function()
{
	//alert(window.location.search);
	if (window.location.search.indexOf('?') > -1 &&
		window.location.search.substring(1).indexOf("=") > -1)
		{
			var QueryString = window.location.search.substring(1);
			var isSmartSearch = false;
			
			var QS_Parts = QueryString.split("&");
			for (var q=0;q<QS_Parts.length;q++)
			{
				if (QS_Parts[q].indexOf("=") > -1)
				{
					var QS_Part = QS_Parts[q].split("=");
					if (QS_Part[0].toLowerCase() == "ss" && QS_Part[1].toLowerCase() == "true")
					{
						isSmartSearch = true;
						break;
					}
				}
			}
	
			if (isSmartSearch)
			{
				$("#smart_search_result").html('<div class="did_you_mean_wrap">Did You Mean...</div>');
				
				var XMLPath = "/Reno/Search/SmartSearch.aspx?return_type=xml&" + window.location.search.substring(1);
				var XSLPath = "/Reno/Search/xsl/SmartSearchResult.xslt";
				//window.location.href=XMLPath;
				//return;
				var Params =
					{
						params: { // object for xsl parameters
							CanonicalWebRoot: WebRoot
						}
						,eval: false /* javascript is already added to the dom with this method goodness */
						,callback: function()
						{
							$("#smart_search_result").html(
									$("#smart_search_result").html()
									.replace(/&lt;/g, "<")
									.replace(/&gt;/g, ">")
							);
						}
					};
				window.setTimeout(function()
				{
					$("#smart_search_result").getTransform(XSLPath, XMLPath, Params);
				},250); // allows other page components to finish loading
				//window.location.href=XMLPath;
			}
		}
});

function DYMClose()
{
	$('#smart_search_result').hide();
}

function DYMModal() 
{
    var minWidth = 488;
    var minHeight = 297;

    var URL = "/Reno/Search/SmartSearch.aspx?return_type=modal&" + window.location.search.substring(1);

	//window.location.href = URL;
	//return;
	
    ShowDialog(URL, minWidth, minHeight);
}
