﻿var HEntityID = '';
var HEntityName = '';
var HUserID = '';







//HDownloadUrl - Simple Get/Post AJAX Wrapper
function HDownloadUrl(method, url, func)
{
   var httpObj = HgetXMLHttp();
      
   httpObj.open(method, url, true);
   httpObj.onreadystatechange = function() 
   {
      if(httpObj.readyState == 4)
      {
         if (httpObj.status == 200)
         {
            var contenttype = httpObj.getResponseHeader('Content-Type');
            
            if (contenttype.indexOf('xml')>-1)
            {
               func(httpObj.responseXML);
            }
            else
            {
               func(httpObj.responseText);
            }
         }
         else
         {
            func('Error: '+httpObj.status);
         }
      }
   };
   httpObj.send(null);
}



function HDownloadUrlSync(method, url)
{
    var httpObj = HgetXMLHttp();
    httpObj.open(method, url, false); 
    httpObj.send(null); 
    
    var contenttype = httpObj.getResponseHeader('Content-Type');
            
    if (contenttype.indexOf('xml')>-1)
    {
       return httpObj.responseXML;
    }
    else
    {
       return httpObj.responseText;
    }
}


function HSendUrl(method, url)
{
   var httpObj = HgetXMLHttp();
      
   httpObj.open(method, url, true);
   httpObj.send(null);
}






function HgetXMLHttp()
{
	var httpObj = null;
	if (window.XMLHttpRequest)
	{
		// if IE7, Mozilla, Safari, etc: Use native object
		httpObj = new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
    		// ...otherwise, use the ActiveX control for IE5.x and IE6
    	try
		{
			httpObj = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) { }
    	
		if (httpObj == null)
		try
		{
			httpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) { }
	}
	return (httpObj);
}



function HgetXMLDOM(xmlText)
{
	var XMLDOM = null;

	if ((document.implementation != null) && (typeof document.implementation.createDocument == "function"))
	{
    	// Gecko / Mozilla / Firefox
        var parser = new DOMParser();
        XMLDOM = parser.parseFromString(xmlText, "text/xml");

  	}
	else
	{    
        // IE
        try
		{
            XMLDOM = new ActiveXObject("MSXML2.DOMDocument");
        } catch (e) { }

    		
		if (XMLDOM == null)
		{
            try
			{
                XMLDOM = new ActiveXObject("Microsoft.XMLDOM");
            } catch (e) { }
        }
  
        if (XMLDOM != null)
        {
            XMLDOM.async = false;
            XMLDOM.validateOnParse = false;
        }
    		
		XMLDOM.loadXML(xmlText);
  	}
  
	return(XMLDOM);
}



function HgetXMLNodeInnerText(node)
{
    return(node.textContent||node.innerText||node.text );
}










function HFindPosition(Obj)
{
	var cureft = curtop = 0;
	if (Obj.offsetParent)
	{
		curleft = Obj.offsetLeft
		curtop = Obj.offsetTop
		
		while (Obj = Obj.offsetParent)
		{
			curleft += Obj.offsetLeft
			curtop += Obj.offsetTop
		}
	}
	return [curleft,curtop];
}


function HInspectObj(obj)
{
  var s = "HInspectObj:";

  if (obj == null)
  {
    s = "(null)"; alert(s); return;
  }
  else if (obj.constructor == String)
  {
    s = "\"" + obj + "\"";
  }
  else if (obj.constructor == Array)
  {
    s += " _ARRAY";
  }
  else if (typeof(obj) == "function")
  {
    s += " [function]" + obj;
  }
  else if ((typeof(XMLSerializer) != "undefined") && (obj.constructor == XMLDocument))
  {
    s = "[XMLDocument]:\n" + (new XMLSerializer()).serializeToString(obj.firstChild);
    alert(s); return;
  }
  else if ((obj.constructor == null) && (typeof(obj) == "object") && (obj.xml != null)) {
    s = "[XML]:\n" + obj.xml;
    alert(s); return;
  }
  
  for (p in obj)
  {
    try
    {
      if (obj[p] == null)
      {
        s += "\n" + String(p) + " (...)";
      }
      else if (typeof(obj[p]) == "function")
      {
        s += "\n" + String(p) + " [function]";
      }
      else if (obj[p].constructor == Array)
      {
        s += "\n" + String(p) + " [ARRAY]: " + obj[p];
        for (n = 0; n < obj[p].length; n++)
          s += "\n  " + n + ": " + obj[p][n];
      }
      else
      {
        s += "\n" + String(p) + " [" + typeof(obj[p]) + "]: " + obj[p];
      }
    }
    catch (e) { s+= e;}
  }
  alert(s);
}



function HGetTarget(e) 
{
    var objEvent;
    if (!e) {
        objEvent = window.event;
    } else {
        objEvent = e;
    }
    if (objEvent.srcElement) {
        target = objEvent.srcElement;
    }
    if (objEvent.target) {
        target = objEvent.target;
    }
    return target;
}


function HFindOwnerDIV(element) 
{
    node = element;
    while (node) {
        if (node.nodeType == 1 && node.nodeName == "DIV") 
        {
            return node;
        }
        node = node.parentNode;
    }
    return null;
}


function HCompareOwnerNode(element, compareelement) 
{
    if (element != compareelement)
    {
        node = element;
        while (node)
        {
            if (node == compareelement)
            {
                return true;
            }
            node = node.parentNode;
        }
    }
    else
    {
        return true;
    }
    
    return false;
}



//Drag and Drop
var HDrag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= HDrag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = HDrag.obj = this;
		e = HDrag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= HDrag.drag;
		document.onmouseup		= HDrag.end;

		return false;
	},

	drag : function(e)
	{
		e = HDrag.fixE(e);
		var o = HDrag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		HDrag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		HDrag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		HDrag.obj.lastMouseX	= ex;
		HDrag.obj.lastMouseY	= ey;

		HDrag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		
		HDrag.obj.root.onDragEnd(	parseInt(HDrag.obj.root.style[HDrag.obj.hmode ? "left" : "right"]), 
									parseInt(HDrag.obj.root.style[HDrag.obj.vmode ? "top" : "bottom"]));
		HDrag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
//Drag and Drop




//HEffectFade
HEffectFade = {
	
	FadeIn : function( obj , speed )
	{ 
        var timer = 0;
	
	    this.changeOpacity(obj.id,0);
	    obj.style.display ='block';
	    
	    for(i = 0; i <= 100; i++)
        { 
            setTimeout("HEffectFade.changeOpacity('" + obj.id + "'," + i + ")",(timer * speed)); 
            timer++;
        }

	    
	},
	
	FadeOut : function( obj , speed )
	{ 
	    var timer = 0;
	    
	    for(i = 100; i >= 0; i--)
        { 
            setTimeout("HEffectFade.changeOpacity('" + obj.id + "'," + i + ")",(timer * speed)); 
            timer++; 
        }
	
	    
	    this.changeOpacity(obj.id,100);
    },
    
    
    changeOpacity : function ( objid, opacity )
    {
        var obj = document.getElementById(objid);
        obj.style.opacity = (opacity / 100); 
        obj.style.MozOpacity = (opacity / 100); 
        obj.style.KhtmlOpacity = (opacity / 100); 
        obj.style.filter = "alpha(opacity=" + opacity + ")";
    }
}
//HEffectFade




//String functions

function HStringTrim( text )
{
    return text.replace(/^\s+|\s+$/g, ''); 
}

function HStringTruncate( text, length, trail )
{
    length = length || 30;
    trail = trail === undefined ? '...' : trail;
    return text.length > length ? text.slice(0, length - trail.length) + trail : String(text);
}

function HStringTruncateWords( text, length, trail )
{
    var words=text.split(" ");
    var numWords=words.length;
    var output=[];
    var ol=0;
    var cWord;
    var w;
    for(w=0; w<numWords; ++w)
    {
        cWord=words[w];
        cwl=cWord.length;
        if((ol+cwl)<=length)
        {
            output.push(cWord);
            ol+=cwl+1;
        }
        else break
    }
    return output.join(" ")+trail;
}

function HStringStartsWith( text, pattern )
{
    return text.indexOf(pattern) === 0;
}

function HStringEndsWith( text, pattern )
{
    var d = text.length - pattern.length;
    return d >= 0 && text.lastIndexOf(pattern) === d;
}


//HStringBuilder
function HStringBuilder(value)
{
	this.strings = new Array("");
	this.append(value);
}

    HStringBuilder.prototype.append = function (value)
    {
	    if (value)
	    {
		    this.strings.push(value);
	    }
    }

    HStringBuilder.prototype.clear = function ()
    {
	    this.strings.length = 1;
    }

    HStringBuilder.prototype.toString = function ()
    {
	    return this.strings.join("");
    }
//HStringBuilder


function HBookmarkpage()
{
    window.external.AddFavorite(window.location.href, document.title);
}











var _modalSetup = false;


function HSetupModalWindow()
{
    if (_modalSetup == false)
    {
        var s = "";
        s = s + "<div id=\"modalWindow\" style=\"position: fixed; left: 0; top: 0; z-index: 999; background-color: white; display: none; border: 3px solid #d0c99b;\"><div id=\"modalWindowLoading\" style=\"position: relative; top: 40%; display: none; width: 98%; text-align: center;\"><img src=\"Images/ani_32x32_swirl.gif\" /><br /><b>Loading</b></div><div id=\"modalWindowContent\"></div></div>";
        s = s + "<div id=\"modalBackground\" style=\"position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 998;background-color:#ffffff; display: none; opacity: 0.50; filter: alpha(opacity=50)\"></div>";
        
        var div = document.createElement("div");
        div.innerHTML = s;
        document.body.appendChild(div);
        
        _modalSetup = true;
    }
}



function HShowModalWindow(Content, Height, Width)
{
    HSetupModalWindow();
    
    document.getElementById('modalWindowContent').innerHTML = "Loading...";
    document.getElementById('modalWindow').style.height = Height + 'px';
    document.getElementById('modalWindow').style.width = Width + 'px';
    document.getElementById('modalWindow').style.display = 'block';
    $('#modalBackground').fadeIn('fast');
    
    // call once to center everything
	HModalWindowOnWindowResize();
    
    if (window.attachEvent)
		window.attachEvent('onresize', HModalWindowOnWindowResize);
	else if (window.addEventListener)
		window.addEventListener('resize', HModalWindowOnWindowResize, false);
	else
		window.onresize = HModalWindowOnWindowResize;
	
	if (document.all)
		document.documentElement.onscroll = HModalWindowOnWindowResize;

		
	//Apppend content
	document.getElementById('modalWindowContent').style.display='none';
	document.getElementById('modalWindowContent').innerHTML = Content;
	
	//See if the content is an iframe
	if (Content.indexOf("iframe") > 0)
	{
	    document.getElementById('modalWindowLoading').style.display='block';
	    $("iframe").bind("load", function(e){
            document.getElementById('modalWindowLoading').style.display='none';
            document.getElementById('modalWindowContent').style.display='block';
        });
	}
	else
	{
	    document.getElementById('modalWindowContent').style.display='block';
	}
}


function HModalWindowOnWindowResize()
{
	var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
	var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
	var div = document.getElementById('modalWindow');
	
	div.style.left = Math.max((left + (HGetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
	div.style.top = (Math.max((top + (HGetWindowHeight() - div.offsetHeight) / 2), 0) - 80) + 'px';
}


function HHideModalWindow()
{
    $('#modalBackground').fadeOut('fast');
    document.getElementById('modalWindow').style.display = 'none';
	
	if (window.detachEvent)
		window.detachEvent('onresize', HModalWindowOnWindowResize);
	else if (window.removeEventListener)
		window.removeEventListener('resize', HModalWindowOnWindowResize, false);
	else
		window.onresize = null;
}



function HGetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}

function HGetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}












function HShowLoginSignupModal()
{
    HShowModalWindow("<iframe src=\"Signup_Inner.aspx\" width=\"100%\" height=\"440\" frameborder=0 align=middle>loading...</iframe>", 440, 500);
}


function HShowUserProfileEditLocationModal()
{
    HShowModalWindow("<iframe src=\"You_Edit_Location_Inner.aspx\" width=\"100%\" height=\"360\" frameborder=0 align=middle>loading...</iframe>", 360, 500);
}


function HShowSubmitMediaModal( ee )
{
    HShowModalWindow("<iframe src=\"Entity_Media_Add_Inner.aspx?ee=" + ee + "\" width=\"100%\" height=\"460\" frameborder=0>loading...</iframe>", 460, 500);
}


function HShowAddFlagModal( o, id )
{
    HShowModalWindow("<iframe src=\"Flags_Add_Inner.aspx?o=" + o + "&id=" + id + "\" width=\"100%\" height=\"380\" frameborder=0 align=middle>loading...</iframe>", 380, 500);
}


function HShowSubmitSendPhone( ee )
{
    HShowModalWindow("<iframe src=\"Entity_SendPhone_Inner.aspx?ee=" + ee + "\" width=\"100%\" height=\"380\" frameborder=0 align=middle>loading...</iframe>", 380, 500);
}


function HShowSubmitSendEmail( ee )
{
    HShowModalWindow("<iframe src=\"Entity_SendEmail_Inner.aspx?ee=" + ee + "\" width=\"100%\" height=\"380\" frameborder=0 align=middle>loading...</iframe>", 380, 500);
}


function HShowEntityRelationshipBuilderModal( ee )
{
    alert('Coming Soon');
    //HShowModalWindow("<iframe src=\"Search_Builder_Inner.aspx?ee=" + ee + "\" width=\"100%\" height=\"380\" frameborder=0 align=middle>loading...</iframe>", 380, 500);
}


function HShowFeedbackModal( page, querystring, element )
{
    HShowModalWindow("<iframe src=\"Feedback_Inner.aspx?page=" + page + "&querystring=" + querystring + "&element=" + element + "\" width=\"100%\" height=\"380\" frameborder=0 align=middle scrolling=\"no\">loading...</iframe>", 380, 500);
}


function HShowFacebookInfoModal(  )
{
    HShowModalWindow("<iframe src=\"FacebookInfo_Inner.htm\" width=\"100%\" height=\"350\" frameborder=0 align=middle scrolling=\"no\">loading...</iframe>", 350, 500);
}



function HEntityShowInfo( entityid, infocontainerid )
{
    if (document.getElementById(infocontainerid) != null)
    {
        //get info content
        document.getElementById(infocontainerid).innerHTML = "<img src='Images/ani_16x16_swirl.gif' align='absmiddle'/>&nbsp;Loading...";
        
        HDownloadUrl('get', 'restHandler.ashx?method=entityinfowindow&EntityID=' + entityid, function(text)
        {
            var html = HgetXMLNodeInnerText(text.documentElement);
            document.getElementById(infocontainerid).innerHTML = html;
        });
    }
}




var HEntityMedia = new oHEntityMedia()

function oHEntityMedia()
{
    this.pausehide = false;
    this.pausehideinfo = false;
    
    oHEntityMedia.prototype.Register = function( mediaid, caption, author, source, license, mediaurl )
	{
	
        $("#Media_" + mediaid).hoverIntent(
            function (event)
            {
                if (document.getElementById("media_attrib_" + mediaid) == null)
                {
                    var html = '<div id="media_attrib_' + mediaid + '_content" class="mediaattrib_window_content">'
                    if (caption.toString().length > 0) { html += '<b>' + caption.toString() + '</b><br>'; }
                    if (author.toString().length > 0) { html += 'author: ' + author.toString() + '<br>'; }
                    if (source.toString().length > 0) { html += 'source: ' + source.toString() + '<br>'; }
                    if (license.toString().length > 0) { html += 'license: ' + license.toString() + '<br>'; }
                    html += '<a href="javascript:HShowAddFlagModal(\'EntityMedia\', \'' + mediaid + '\');\" class=\"textminus1\">report this photo</a><br>';
                    //html += '<img src="images/pixel.gif" height="6" width="1"><br><a href="Media.aspx?m=' + mediaid + '">view full size</a><br>';
                    html += '</div>';
                
                    entitymediawindowdiv = document.createElement("div");
                    entitymediawindowdiv.innerHTML = html;
                    entitymediawindowdiv.style.zIndex = 800;
                    entitymediawindowdiv.style.display = 'none';
                    entitymediawindowdiv.id = 'media_attrib_' + mediaid;
                    entitymediawindowdiv.className = 'mediaattrib_window';
                    document.body.appendChild(entitymediawindowdiv);
                    
                    $(entitymediawindowdiv).hover(
                        function () {
                            HEntityMedia.pausehide = true;
                        }, 
                        function () {
                            HEntityMedia.pausehide = false;
                            $('#media_attrib_' + mediaid).fadeOut('fast');
                        }
                    );
                    
                    
                    entitymediawindowinfodiv = document.createElement("div");
                    entitymediawindowinfodiv.innerHTML = "<img src='images/icon_media_attrib.gif'>";
                    entitymediawindowinfodiv.style.zIndex = 799;
                    entitymediawindowinfodiv.id = 'media_attrib_info' + mediaid;
                    entitymediawindowinfodiv.className = 'mediaattrib_window';
                    document.body.appendChild(entitymediawindowinfodiv);
                    
                    $(entitymediawindowinfodiv).hover(
                        function () {
                            HEntityMedia.pausehideinfo = true;
                            
                            var poswin = HFindPosition(document.getElementById("media_attrib_info" + mediaid));
                            document.getElementById("media_attrib_" + mediaid).style.left = poswin[0] + 'px';
                            document.getElementById("media_attrib_" + mediaid).style.top = poswin[1] + 'px';
                            $('#media_attrib_' + mediaid).fadeIn('fast');
                        }, 
                        function () {
                            HEntityMedia.pausehideinfo = false;
                            $('#media_attrib_info' + mediaid).fadeOut('fast');
                            
                            if (HEntityMedia.pausehide == false)
                            {
                                $('#media_attrib' + mediaid).fadeOut('fast');
                            }
                        }
                    );
                }
                
                
                var pos = HFindPosition(document.getElementById("Media_" + mediaid));
                document.getElementById("media_attrib_info" + mediaid).style.left = pos[0] - 9 + 'px';
                document.getElementById("media_attrib_info" + mediaid).style.top = pos[1] + $("#Media_" + mediaid).height() - 6 + 'px';
                $('#media_attrib_info' + mediaid).fadeIn('fast');
                
                
                
            }, 
            function () 
            {
                HEntityMedia.pausehide = false;
                if (HEntityMedia.pausehideinfo == false)
                {
                    $('#media_attrib_info' + mediaid).fadeOut('fast');
                }
            }
        );
	}
	
	
	
	oHEntityMedia.prototype.showZoom = function( obj, id, mediaurl )
	{
	    if (obj != null && mediaurl != null)
	    {
	        if (document.getElementById('mediazoom_' + id) == null)
	        {
	            var zoomdiv = document.createElement("div");
                zoomdiv.innerHTML = "<img src=\"" + mediaurl + "\">";
                zoomdiv.style.zIndex = 800;
                zoomdiv.style.position = 'absolute';
                zoomdiv.style.backgroundColor = '#ffffff';
                zoomdiv.className = 'mediazoom_window';
                zoomdiv.id = 'mediazoom_' + id;
                zoomdiv.style.display = 'none';
                document.body.appendChild(zoomdiv);
            }
            
            var pos = HFindPosition(obj);
            var x = pos[0] - 120;
            var y = pos[1] + 15;
            document.getElementById('mediazoom_' + id).style.top = y + 'px';
            document.getElementById('mediazoom_' + id).style.left = x + 'px';
            
            $('#mediazoom_' + id).fadeIn('fast');
            hidehidemes();
	    }
	}
	
	oHEntityMedia.prototype.hideZoom = function( id )
	{
	    if (document.getElementById('mediazoom_' + id) != null)
	    {
	        $('#mediazoom_' + id).fadeOut('fast');
	        showmhidemes();
	    }
	}
	
}






var HEntityURL = new oHEntityURL()

function oHEntityURL()
{
    
    oHEntityURL.prototype.Register = function( ownerid, urlid, src )
	{
	    $("#" + ownerid).hoverIntent(
            function (event)
            {
                if (document.getElementById("entity_url_" + urlid) == null)
                {
                    var html = '<div style="border: solid 1px #e8e8d8; padding: 4px; background: #ffffff url(images/ani_16x16_swirl.gif) no-repeat 6px 6px"><img src="' + src + '"></div>';
                
                    entityurlwindowdiv = document.createElement("div");
                    entityurlwindowdiv.innerHTML = html;
                    entityurlwindowdiv.style.position = 'absolute';
                    entityurlwindowdiv.style.zIndex = 800;
                    entityurlwindowdiv.id = 'entity_url_' + urlid;
                    entityurlwindowdiv.className = '';
                    document.body.appendChild(entityurlwindowdiv);
                }
                
                var pos = HFindPosition(document.getElementById(ownerid));
	            var x = pos[0] + 40;
	            var y = pos[1] + 14;
                document.getElementById("entity_url_" + urlid).style.left = x - 80 + 'px';
                document.getElementById("entity_url_" + urlid).style.top = y + 'px';
            
                $('#entity_url_' + urlid).fadeIn('fast');
            }, 
            function () 
            {
                $('#entity_url_' + urlid).fadeOut('fast');
            }
        );
	}
	
}






var HEntityWindow = new oHEntityWindow()

function oHEntityWindow()
{
    this.setup = false;
    this.hidetimer = null;
    this.pausehide = false;
    this.currentopenerobj = null;
    this.entitywindowdiv = null;
    this.disabled = false;
    
    oHEntityWindow.prototype.init = function()
    {
        if (this.setup == false)
        {
            entitywindowdiv = document.createElement("div");
            entitywindowdiv.innerHTML = "<div id=\"entitywindow\" class=\"entity_window\"><div id=\"entitywindowcontent\" class=\"entity_window_content\"></div></div>";
            entitywindowdiv.style.zIndex = 800;
            document.body.appendChild(entitywindowdiv);
            //onmouseout=\"HEntityWindow.Hide();\" onmouseover=\"HEntityWindow.PreventHide();\" 
            $(entitywindowdiv).hover(
                function () {
                    HEntityWindow.PreventHide();
                }, 
                function () {
                    HEntityWindow.Hide();
                }
            );
            
            
            //Close the window if the document gets focus
            $(document).bind('mousedown', HEntityWindow.checkMouse).bind('keydown', HEntityWindow.checkKey);
            
            this.setup = true;
        }
    }
    
    
    oHEntityWindow.prototype.checkMouse = function( e )
	{
	    if (e.target)
	    {
	        if (document.getElementById('entitywindow').style.display=='block')
	        {
                if (e.target.id != 'entitywindowcontent')
                {
	                HEntityWindow.Hide();
	            }
	            
	        }
	    }
	}
	
	
	oHEntityWindow.prototype.checkKey = function( e )
	{
	    if (e.keyCode)
	    {
	        if (document.getElementById('entitywindow').style.display=='block')
	        {
	            if (e.keyCode == 27)
	            {
	                HEntityWindow.ForceHide();
	            }
	        }
	    }
	}
    
    
    oHEntityWindow.prototype.Show = function( openerobj, entityid, xoffset, yoffset)
	{
	    
	    if (HEntityWindow.disabled == true) return;
	    HEntityWindow.pausehide = true;
	    if (HEntityWindow.hidetimer){ clearTimeout(HEntityWindow.hidetimer); }
	    if (this.currentopenerobj == openerobj && document.getElementById('entitywindow').style.display == 'block') return;
	
        this.init();
        this.currentopenerobj = openerobj;
        
        document.getElementById('entitywindowcontent').style.height = '100%';
        
        document.getElementById('entitywindowcontent').innerHTML = "<div style='text-align: center;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='Images/ani_16x16_swirl.gif' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><b>Loading</b></div>";
        
        var pos = HFindPosition(openerobj);
	    var x = pos[0] + 40;
	    var y = pos[1] + 14;
	    
	    xoffset = xoffset||0;
	    yoffset = yoffset||0;
        
        document.getElementById('entitywindow').style.left = (x + xoffset) + 'px';
	    document.getElementById('entitywindow').style.top = (y + yoffset) + 'px';
        
        document.getElementById('entitywindow').style.display='block';
        
        //Get the Conetent
        $.ajax({
            url: "restHandler.ashx?method=entityinfowindow&EntityID=" + entityid + "",
            type: "GET",
            cache: false,
            success: function(data)
            {
                document.getElementById('entitywindowcontent').innerHTML = data;
            }
        });
        
        HEntityWindow.pausehide = false;
        if (HEntityWindow.hidetimer != null){ clearTimeout(HEntityWindow.hidetimer); }
	}
	
	
	oHEntityWindow.prototype.PreventHide = function()
	{ 
	    HEntityWindow.pausehide = true;
	    if (HEntityWindow.hidetimer != null){ clearTimeout(HEntityWindow.hidetimer); }
	}
	
	
	oHEntityWindow.prototype.Hide = function()
	{
        if (this.setup == false) return;
        HEntityWindow.pausehide = false;
        HEntityWindow.hidetimer = setTimeout("HEntityWindow.PreHide()",500);
	}
	
	oHEntityWindow.prototype.PreHide = function()
	{ 
        if (HEntityWindow.pausehide == true) return;
        HEntityWindow.ForceHide();
	}
	
	oHEntityWindow.prototype.ForceHide = function()
	{
        if (this.setup == false) return;
        if (this.disabled == true) return;
        
        clearTimeout(HEntityWindow.hidetimer);
        
        document.getElementById('entitywindow').style.display = 'none';
        document.getElementById('entitywindowcontent').innerHTML = "";
        this.currentopenerobj = null;
        this.disabled = false;
        this.pausehide = false;
	}
	
	oHEntityWindow.prototype.Disable = function()
	{ 
	    HEntityWindow.ForceHide();
	    HEntityWindow.disabled = true;
	}
	
	oHEntityWindow.prototype.Enable = function()
	{ 
	    HEntityWindow.disabled = false;
	}



    oHEntityWindow.prototype.RegisterAHREF = function( ownerid, entityid )
	{ 
	    var hrefobj = document.getElementById(ownerid);
	    if (hrefobj)
	    {
	        $("#" + ownerid).hoverIntent(
                function () {
                    HEntityWindow.Show(hrefobj, entityid);
                }, 
                function () {
                    HEntityWindow.Hide();
                }
            );
	    }
	}

}




var HEntityRelationshipGraph2 = new oHEntityRelationshipGraph2()

function oHEntityRelationshipGraph2()
{
    this.setup = false;
    this.graphcontainer = null;
    this.entityid = null;
    this.entityname = "";
    this.query = "";
    
    this.graph_entities = new Array();
    this.graph_queryresultsxml = null;
    this.graph_topcount = 1;
    this.graph_topweight = 1;
    this.graph_bottomweight = 1;
    this.graph_relcount = 1;
    this.graph_diameter;
    this.graph_radius;
    this.graph_degrees = 0;
    this.graph_rootcenterx = 1;
    this.graph_rootcentery = 1;
    this.graph_entityroot;
    this.graph_currentslot = 0;
    this.graph_primoslotfilled = false;
    this.graph_currenthighlight = 0;
    
    
    oHEntityRelationshipGraph2.prototype.init = function()
    {
        var containerwidth = 315;
        var containerheight = 315;
        
        var graphcontainerhtml = '\
        <div id="relationshipmap_disable" style="z-index: 100; display:none; width: ' + containerwidth + 'px; height: 100%; position: absolute; background-color: #ffffff;"></div>\
        <div id="relationshipmap_loading" style="z-index: 300; display: block; height: 108%; width: 100%; position: absolute; top 0px; text-align: center;">\
        <div id="relationshipmap_loading_modal" style="opacity: 0.70; filter: alpha(opacity=70); z-index: 301; display: block; height: 102%; width: 110%; position: relative; top 0px; background-color: White; text-align: center;"></div>\
        <div id="relationshipmap_loading_content" style="z-index: 302; display: block; position: relative; top: -235px; background-color: Transparent; text-align: center;"><br /><br /><img src="Images/ani_32x32_swirl.gif" /><br /><b>Loading</b></div>\
        </div>\
        <div id="relationshipmap" style="overflow: visible; height: ' + containerheight + 'px; z-index: 99; position: relative; top: 2px; left: 0px; display: block; width: 100%;">\
        <div id="relationshipmap_inner" style="position: relative; height: ' + containerheight + 'px; top: -10px; left: 0px; "></div>\
        </div>'
        this.graphcontainer.innerHTML = graphcontainerhtml;
        
        this.setup = true;
    }
    
    
    oHEntityRelationshipGraph2.prototype.Show = function( in_graphcontainer, in_entityid, in_entityname, in_query )
	{
	    this.graphcontainer = document.getElementById(in_graphcontainer);
        this.entityid = in_entityid;
        this.entityname = in_entityname;
        this.query = in_query;
	    
	    if (this.setup == false)
	    {
            this.init();
	    }
	    
	    this.graph_entities = new Array();
	    this.RefreshCanvas();
        
        document.getElementById('relationshipmap_loading').style.display = 'block';
        
        
        HDownloadUrl('get', 'restHandler.ashx?method=relatedentitiesxml&SortuvQuery=' + this.query, function(xml)
        {
            HEntityRelationshipGraph2.graph_queryresultsxml = xml;
            
            HEntityRelationshipGraph2.graph_entities = new Array();

            HEntityRelationshipGraph2.graph_entityroot = new HEntityRelationshipGraph2.Entity(HEntityRelationshipGraph2.entityid, HEntityRelationshipGraph2.entityname, '0', 0, 0);
            
            HEntityRelationshipGraph2.graph_relcount = parseInt(xml.documentElement.getElementsByTagName("e").length);
            
            HEntityRelationshipGraph2.graph_diameter = 330;
            HEntityRelationshipGraph2.graph_degrees = 360 / 20; //HEntityRelationshipGraph2.graph_relcount;
            HEntityRelationshipGraph2.graph_radius = HEntityRelationshipGraph2.graph_diameter / 2;
            HEntityRelationshipGraph2.graph_topcount = parseFloat(xml.documentElement.getAttribute("tc"));
            HEntityRelationshipGraph2.graph_topweight = parseFloat(xml.documentElement.getAttribute("tw"));
            HEntityRelationshipGraph2.graph_bottomweight = parseFloat(0);

            var nodeentities = xml.documentElement.getElementsByTagName("e");
            for (var i = 0; i < nodeentities.length; i++)
            {
                var indexEntity = parseInt(i + 1);
                entity = new HEntityRelationshipGraph2.Entity(nodeentities[i].getAttribute("id"), nodeentities[i].getAttribute("n"), indexEntity, parseFloat(nodeentities[i].getAttribute("w")), parseFloat(nodeentities[i].getAttribute("c")));
                HEntityRelationshipGraph2.graph_entities[indexEntity] = entity;
                
                if (i == 10 || (i + 1) == nodeentities.length) { HEntityRelationshipGraph2.graph_bottomweight = parseFloat(nodeentities[i].getAttribute("w")); }
            }
            
            
            HEntityRelationshipGraph2.graph_entities.sort(function() {return 0.5 - Math.random()});
            
            
            HEntityRelationshipGraph2.graph_rootcenterx = parseInt((document.getElementById("relationshipmap").offsetWidth / 2));
            HEntityRelationshipGraph2.graph_rootcentery = parseInt((document.getElementById("relationshipmap").offsetHeight / 2));
            HEntityRelationshipGraph2.Draw();
            
            document.getElementById('relationshipmap_loading').style.display = 'none';
        });
	    
	}
	
	
	
	oHEntityRelationshipGraph2.prototype.RefreshCanvas = function()
	{
        if (document.getElementById("relationshipmap_inner").hasChildNodes())
        {
            while (document.getElementById("relationshipmap_inner").childNodes.length >= 1)
            {
                document.getElementById("relationshipmap_inner").removeChild(document.getElementById("relationshipmap_inner").firstChild);
            }
        }

        var imgback = document.createElement("img");
        imgback.style.display = "block";
        
        imgback.src = "images/graphback_300.gif";
        imgback.style.marginTop = "18px";
        imgback.style.marginLeft = "5px";
        imgback.style.marginRight = "5px";
            
        imgback.style.textAlign = "center";
        imgback.unselectable="on";
        document.getElementById("relationshipmap_inner").appendChild(imgback);
	}
	
	
	oHEntityRelationshipGraph2.prototype.Draw = function()
	{
	    this.RefreshCanvas();
	    
        //Root
        var rootEntity = this.graph_entityroot.divEntity;
        rootEntity.style.zIndex = 101;
        rootEntity.style.left = this.graph_rootcenterx - 44 + "px";
        if (jQuery.browser.msie == true) { rootEntity.style.top = this.graph_rootcentery + "px"; }
        else { rootEntity.style.top = this.graph_rootcentery - 18 + "px"; }
        rootEntity.style.display="block";
        document.getElementById("relationshipmap_inner").appendChild(rootEntity);
        rootEntity.innerHTML = "<div id='entitynode' style='position:relative; width:80px;' class='graphentitynode_root'><div style='position:relative; background:transparent url(images/pixel.gif) no-repeat scroll center top;margin:0px auto;'><img src='Images/graphnode_root.gif'></div>" + HStringTruncate(this.graph_entityroot.EntityName, 25) + "</div>";
        
        
        this.graph_primoslotfilled = false;
        for (var i = 0; i < this.graph_entities.length; i++)
        {
            if ( this.graph_entities[i] )
            {
                if ( this.graph_entities[i].EntityRank <= 10)
                {
                    this.DrawEntity(this.graph_entities[i], i, 1);
                }
                else
                {
                    this.DrawEntity(this.graph_entities[i], i, 2);
                }
            }
        }
    }
    
    
    oHEntityRelationshipGraph2.prototype.DrawEntity = function( entity, i, leveloffset )
	{
	    
	    if (entity) 
	    {
	        var slot = i;
            if (leveloffset == 1)
            {
                slot = this.graph_currentslot + 2;
                this.graph_currentslot = slot;
            }
	        
            var childEntity = entity.divEntity;
            var weightedradius = this.graph_radius;
            
            if (leveloffset == 2) { weightedradius = weightedradius - 20; }
            if (leveloffset == 1)
            {
                var weightdistance = this.graph_topweight - this.graph_bottomweight;
                var weightoffset = ((this.graph_bottomweight / this.graph_topweight) * this.graph_radius)
                weightedradius = this.graph_radius - ((entity.EntityWeight / this.graph_topweight) * this.graph_radius) + weightoffset;
            }
            
            if (weightedradius < 70) { weightedradius = 70; }
            if (entity.EntityWeight > this.graph_topweight) 
            { 
                weightedradius = 50; 
                if (this.graph_primoslotfilled == false)
                {   this.graph_primoslotfilled = true;
                    slot = 8;
                }
            }
            else if (entity.EntityWeight == this.graph_topweight) 
            { 
                weightedradius = 55; 
                if (this.graph_primoslotfilled == false)
                {   this.graph_primoslotfilled = true;
                    slot = 1;
                }
            }
            
            var childcenterx = weightedradius * (Math.cos((this.graph_degrees * 0.0174532925) * (slot))) + this.graph_rootcenterx;
            var childcentery = weightedradius * (Math.sin((this.graph_degrees * 0.0174532925) * (slot))) + this.graph_rootcentery;
            
            childEntity.style.left = this.graph_rootcenterx + "px";
            childEntity.style.top = this.graph_rootcentery + "px";
            if (leveloffset == 1) { childEntity.style.zIndex = 100; } else { childEntity.style.zIndex = 99; }
            childEntity.style.display="block";
            childEntity.style.position="absolute";
            document.getElementById("relationshipmap_inner").appendChild(childEntity);
            var graphnodeimage = this.getGraphnodeImage(entity.EntityCount, leveloffset);
            entity.EntityGraphNodeImage = graphnodeimage;
            
            var innerchild="";
            
            if (leveloffset == 1) 
            {
                innerchild+="<div id='entitnode_container_" + entity.EntityID + "' style='position:relative; width:80px;' class='graphentitynode'  title='" + entity.EntityName + "'>";
                innerchild+="<div id='entitynode_node_" + entity.EntityID + "' style='position:relative; background:transparent url(images/pixel.gif) no-repeat scroll center top;margin:0px auto; text-align:center;'><img id='entitynode_image_" + entity.EntityID + "' src='Images/" + graphnodeimage + "' unselectable='on'></div>";
                
                innerchild+="<div id='entitynode_title_" + entity.EntityID + "' style='position:relative; padding-top: 4px; background:transparent;'><span style='background-color: #ffffff; white-space: nowrap;'>" + HStringTruncate(entity.EntityNameShort, 21) + "</span></div>";
                innerchild += "</div>";
            }
            else
            {
                innerchild+="<div id='entitnode_container_" + entity.EntityID + "' style='position:relative; width:20px;' class='graphentitynode'>";
                innerchild+="<div id='entitynode_node_" + entity.EntityID + "' title='" + entity.EntityName + "' style='position:relative; background:transparent url(images/pixel.gif) no-repeat scroll center top;margin:0px auto;'><img id='entitynode_image_" + entity.EntityID + "' src='Images/" + graphnodeimage + "' unselectable='on' style='display: block;'></div>";
                innerchild += "</div>";
            }
            
            childEntity.innerHTML = innerchild;
            
            entity.divEntityX = childcenterx - (childEntity.offsetWidth / 2);
            entity.divEntityY = childcentery - (childEntity.offsetHeight / 2);
            
            if (leveloffset == 1) $(childEntity).animate({left: entity.divEntityX + "px", top: entity.divEntityY + "px"},500);
            if (leveloffset != 1) { childEntity.style.left = entity.divEntityX + "px"; childEntity.style.top = entity.divEntityY + "px"; }
            
            $("#entitnode_container_" + entity.EntityID.toString()).bind("click", function(){
                window.location.href = 'Details.aspx?EntityID=' + entity.EntityID;
                return;
            });
            
            
            
            $("#entitnode_" + entity.EntityID.toString()).hover(
                function () {
                    document.getElementById('entitnode_' + entity.EntityID.toString()).style.zIndex = 201;
                }, 
                function () {
                    document.getElementById('entitnode_' + entity.EntityID.toString()).style.zIndex = 100;
                }
            );
            
        }
	
	}
	
	
	oHEntityRelationshipGraph2.prototype.getGraphnodeImage = function( count, leveloffset )
	{
	    
	    var graphnodeimage = 'graphnode_4.gif';

        var divider = 1;
        if (leveloffset == 0) { divider = 3; }
        if (leveloffset == 2) { divider = 4; }

        if (leveloffset == 1)
        {
            nodepercent = ((count / this.graph_topcount) * 100) / divider;
        
            if (nodepercent > 50)
            { graphnodeimage = 'graphnode_5.gif'; }
            else if (nodepercent > 40)
            { graphnodeimage = 'graphnode_4.gif'; }
            else if (nodepercent > 30)
            { graphnodeimage = 'graphnode_3.gif'; }
            else if (nodepercent > 10)
            { graphnodeimage = 'graphnode_2.gif'; }
            else
            { graphnodeimage = 'graphnode_1.gif'; }
        }
        else
        {
            nodepercent = ((count / this.graph_topcount) * 100);
        
            if (nodepercent > 50)
            { graphnodeimage = 'graphnode_back_4.gif'; }
            else if (nodepercent > 40)
            { graphnodeimage = 'graphnode_back_3.gif'; }
            else if (nodepercent > 30)
            { graphnodeimage = 'graphnode_back_2.gif'; }
            else
            { graphnodeimage = 'graphnode_back_1.gif'; }
        }

        return graphnodeimage;
	
	}
	
	
	oHEntityRelationshipGraph2.prototype.Entity = function( entityid, entityname, rank, weight, count )
	{
	    var div = document.createElement("div");
        div.style.display = "none";
        div.style.position = "absolute";
        div.style.cursor= "pointer";
        div.id="entitnode_" + entityid.toString();
        this.divEntity = div;
	
        this.EntityID = entityid;
        this.EntityName = entityname;
        this.EntityRank = rank;
        this.EntityWeight = weight;
        this.EntityCount = count;
        this.Relevance = Math.round(weight / HEntityRelationshipGraph2.graph_topweight * 100);
        
        this.divEntityX = 0;
        this.divEntityY = 0;
        
        this.EntityGraphNodeImage = "";
        
        this.EntityNameShort = entityname;
        if (entityname.lastIndexOf(" - ") > 0)
        {
            this.EntityNameShort = entityname.substring(0,entityname.lastIndexOf(" - "));
        }
	}
	
	
	
	oHEntityRelationshipGraph2.prototype.Highlight  = function( caller, entityid, showinfo )
	{
	    if (entityid == this.graph_currenthighlight) { return; }
	
	    this.ClearHighlight(this.graph_currenthighlight);
	
	    if (document.getElementById('entitnode_' + entityid)) { document.getElementById('entitnode_' + entityid).style.zIndex = 201; }
	    if (document.getElementById('entitynode_image_' + entityid)) { document.getElementById('entitynode_image_' + entityid).src= 'images/graphnode_highlight.gif'; }
	    if (document.getElementById('entitynode_title_' + entityid)) { document.getElementById('entitynode_title_' + entityid).className = 'graphentitynode_selected'; }
	    
	    HEntityWindow.ForceHide();
	    
	    this.graph_currenthighlight = entityid;
	}
	
	
	oHEntityRelationshipGraph2.prototype.ClearHighlight = function( entityid )
	{
	    if (entityid == 0) { return; }
	    
	    if (document.getElementById('entitnode_' + entityid))
	    {
	        var entity = this.getEntity(entityid);
	        
	        document.getElementById('entitnode_' + entityid).style.zIndex = 100;
    	    
	        if (document.getElementById('entitynode_image_' + entityid)) 
	        {
	            try
	            {
	                document.getElementById('entitynode_image_' + entityid).src= 'images/' + entity.EntityGraphNodeImage;
	            }
	            catch(err)
	            {
	                document.getElementById('entitynode_image_' + entityid).src= 'images/graphnode_4.gif';
	            }
	        }
	        
	        if (document.getElementById('entitynode_title_' + entityid)) { document.getElementById('entitynode_title_' + entityid).className = 'graphentitynode'; }
	    }
	}
	
	
	oHEntityRelationshipGraph2.prototype.getEntity = function( entityid )
	{
	    var entity = null;
	    
	    for (var i = 1; i < this.graph_entities.length; i++)
        {
            if ( this.graph_entities[i] )
            {
                if (this.graph_entities[i].EntityID == entityid)
                {
                    entity = this.graph_entities[i];
                }
            }
        }
        
        return entity;
	}
    
}





//Search History
var HSearchHistory = new oHSearchHistory()

function oHSearchHistory()
{
    this.setup = false;
    this.containersearchhistory = null;
    this.showhistorycontent = false;
    
    
    oHSearchHistory.prototype.Register = function( searchhistorycontainerid )
    {
        if (this.setup == false)
        {
            this.containersearchhistory = document.getElementById(searchhistorycontainerid);
            this.setup = true;
            this.Show();
        }
    }
    
    
    oHSearchHistory.prototype.AddSearch = function( query, display )
    {
        if (query.length < 5 || display.length < 5) { return false; }
    
        //Add to cookies
        var hsh_s = $.cookie('hsh_s');
        
        var newsearch = query + "_" + display;
        var search = newsearch;
        
        if (hsh_s && hsh_s != '') 
        {
            var c = 0;
            var items = hsh_s.split('|');
            for (var i = 0; i < items.length; i++) 
            {
                var item = jQuery.trim(items[i]);
                if (item && item != null && item != 'null' && item != '') 
                {
                    if (item != newsearch)
                    {
                        c++;
                        if (c < 10)
                        {
                            search = search + "|" + item;
                        }
                    }
                }
                
            }
        }
        
        hsh_s = search;
        $.cookie('hsh_s', hsh_s);
        
        this.Show();
    }
    
    
    oHSearchHistory.prototype.AddEntity = function( entityid, nam )
    {
        //Add to cookies
        var hsh_e = $.cookie('hsh_e');
        hsh_e = hsh_e + "|" + entityid + "_" + nam;
        $.cookie('hsh_s', hsh_e);
        
        this.Show();
    }



    oHSearchHistory.prototype.Show = function()
    {
        if (this.containersearchhistory)
        {
            //Searches
            var searches = new Array();
            
            var hsh_s = $.cookie('hsh_s')
            
            if (hsh_s && hsh_s != '') 
            {
                var items = hsh_s.split('|');
                for (var i = 0; i < items.length; i++) 
                {
                    var item = jQuery.trim(items[i]);
                    if (item && item != '') 
                    {
                        var search = item.split('_');
                        var query = search[0];
                        var display = search[1];
                        
                        searches.push('<div style="line-height: 12px; padding: 7px 5px 0px 1px;"><a href="Search.aspx?SortuvQuery=' + escape(query) + '" class="aless" title="' + display.toLowerCase() + '">&raquo; ' + HStringTruncate(display.toLowerCase().replace('anything',''), 48) + '</a></div>');
                    }
                    
                }
                
            }
            
        
            if (searches.length > 0)
            {
                var searchesHTML = '';
                
                for (var i = 0; i < searches.length; i++)
                {
                    if (i <= 2)
                    {
                        searchesHTML += searches[i];
                    }
                }
                
                if (searches.length > 3)
                {
                    searchesHTML += '<div id="SearchHistory_moresearches">\
                    <div id="SearchHistory_moresearches_header" class="aless textminus1" style="line-height: 12px; padding-top: 6px; cursor: pointer;">+ more</div>\
                    <div id="SearchHistory_moresearches_content" style="display: none;">';
                    
                    for (var i = 0; i <= searches.length - 1; i++)
                    {
                        if (i > 2)
                        {
                            searchesHTML += searches[i];
                        }
                    }
                    
                    searchesHTML += "</div></div>";
                    
                }
                
                
                if (searches.length > 0)
                {
                    this.containersearchhistory.innerHTML = 'Recent Searches&nbsp;<span class="textminus1 aless" onclick="HSearchHistory.clear();">(clear)</span><br />' + searchesHTML;
                }
                
                
                if (document.getElementById("SearchHistory_moresearches_content"))
                {
                    if (this.showhistorycontent == false)
                    {
                        document.getElementById("SearchHistory_moresearches_content").style.display = 'none';
                    }
                    else
                    {
                        document.getElementById("SearchHistory_moresearches_content").style.display = 'block';
                    }
                    
                    
                    $("#SearchHistory_moresearches_header").bind("click", function(){
                        if (HSearchHistory.showhistorycontent == false)
                        {
                            document.getElementById("SearchHistory_moresearches_content").style.display = 'block';
                            HSearchHistory.showhistorycontent = true;
                            document.getElementById("SearchHistory_moresearches_header").innerHTML = '- less';
                        }
                        else
                        {
                            document.getElementById("SearchHistory_moresearches_content").style.display = 'none';
                            HSearchHistory.showhistorycontent = false;
                            document.getElementById("SearchHistory_moresearches_header").innerHTML = '+ more';
                        }
                    });
                }
                
            }
            else
            {
                this.containersearchhistory.innerHTML = '';
            }
            
        }
    }
    
    oHSearchHistory.prototype.clear = function()
    {
        if (confirm('Are you sure you would like to clear your recent search history?'))
        {
            $.cookie('hsh_s', '');
            this.Show();
        }
    }

}




var HEntityMaps = new oHEntityMaps()

function oHEntityMaps()
{
    this.mapcontainerid = "";
    this.infocontainerid = "";
    this.Entities = new Array();
    this.rootEntity = null;
    this.map = null;
    this.maplayer = null;
    this.map_currenthighlight = "";
    this.mapControl = null;
    this.lastZIndex = 1001;
    
    oHEntityMaps.prototype.Register = function( mapcontainerid, infocontainerid )
	{
	    this.mapcontainerid = mapcontainerid;
        this.infocontainerid = infocontainerid;
	}
	
	
	oHEntityMaps.prototype.Show = function( rootEntity, Entities )
	{
	    $(document).ready(function()
	    {
	    
	        //info container
            if (HEntityMaps.infocontainerid != "")
            {
                var infocontainerhtml = '\
                <div id="infocontainer_content"><div class="tip">Roll over any item on the map to see more details.<br>Click any item on the map view the item.</div></div>\
                <br>\
                <div id="infocontainer_functions"></div>'
                document.getElementById(HEntityMaps.infocontainerid).innerHTML = infocontainerhtml;
            }
	        
	        HEntityMaps.rootEntity = rootEntity;
	        HEntityMaps.Entities = Entities;
    	    
	        if (HEntityMaps.map!=null)
            {
                HEntityMaps.map.DeleteAllShapes();
                HEntityMaps.map.Dispose();
                HEntityMaps.map = null;
                HEntityMaps.maplayer = null;
                HEntityMaps.mapControl = null;
            }
    	    
	        HEntityMaps.map = new VEMap(HEntityMaps.mapcontainerid);
	        HEntityMaps.map.HideDashboard();
	        
	        
	        if (rootEntity != null)
	        {
	            HEntityMaps.map.LoadMap(new VELatLong(rootEntity.Latitude, rootEntity.Longitude), 14 ,'r' ,false, VEMapMode.Mode2D);
	        }
	        else
	        {
	            HEntityMaps.map.LoadMap(new VELatLong(0, 0), 14 ,'r' ,false, VEMapMode.Mode2D);
	        }
	        
	        HEntityMaps.maplayer = new VEShapeLayer();         
	        HEntityMaps.map.AddShapeLayer(HEntityMaps.maplayer);
	        HEntityMaps.maplayer.DeleteAllShapes();
    	    
    	    
	        //Add entities
    	    
	        for (var i = 0; i < Entities.length; i++)
            {
                HEntityMaps.AddEntity(Entities[i]);
            }
            
            if (rootEntity != null) { HEntityMaps.AddEntity(rootEntity); }
            
            
            
            //Rezoom based on added entities
            rect = HEntityMaps.maplayer.GetBoundingRectangle();
            HEntityMaps.map.SetMapView(rect);

            count = HEntityMaps.maplayer.GetShapeCount();
            if (count <= 1)
            {
               HEntityMaps.map.SetZoomLevel(17);
            }
            
            
            //Controls
            if (HEntityMaps.mapControl == null)
            {
                HEntityMaps.mapControl = document.createElement("div");
                HEntityMaps.mapControl.id = "mapControl";
                HEntityMaps.mapControl.style.border = "1px solid #d0c99b";
                HEntityMaps.mapControl.style.padding = "1px";
                HEntityMaps.mapControl.style.background = "#ffffff";
                HEntityMaps.mapControl.style.opacity = "0.80";
                HEntityMaps.mapControl.style.filter = "alpha(opacity=80)";
                HEntityMaps.mapControl.innerHTML = "&nbsp;<span onclick=\"HEntityMaps.ChangeMapStyle('h');\" style=\"cursor: pointer; font-size: 60%;\" title=\"Switch to aerial view\">aerial</span> <span onclick=\"HEntityMaps.ChangeMapStyle('r');\" style=\"cursor: pointer; font-size: 60%;\" title=\"Switch to road view\">road</span> | ";
                if (rootEntity != null) { HEntityMaps.mapControl.innerHTML += " <span onclick=\"HEntityMaps.CenterRoot();\" style=\"cursor: pointer; font-size: 60%;\" title=\"Center to " + rootEntity.EntityName + "\">center to <img src=\"images/mapnode_root_sm.gif\" align=\"absmiddle\"></span> | "; }
                HEntityMaps.mapControl.innerHTML += "<span class=\"aless\" unselectable onclick=\"HEntityMaps.map.ZoomOut();\" style=\"cursor: pointer;\" title=\"Zoom out\"><img src=\"images/mapcontrol_zoomout.gif\" align=\"middle\"></span><span class=\"aless\" onclick=\"HEntityMaps.map.ZoomIn();\" style=\"cursor: pointer;\" title=\"Zoom in\"><img src=\"images/mapcontrol_zoomin.gif\" align=\"middle\"></span>&nbsp;";
                
                HEntityMaps.map.AddControl(HEntityMaps.mapControl);
                document.getElementById(HEntityMaps.mapcontainerid).appendChild(HEntityMaps.mapControl);
                HEntityMaps.mapControl.style.top ="4px";
                HEntityMaps.mapControl.style.left = "4px";
            }
            
            
            //Events
            HEntityMaps.map.AttachEvent("onchangeview",HEntityMaps.changeviewHandler);
            
        
        })
	}
	
	
	oHEntityMaps.prototype.AddEntity = function( entity )
	{
	    if (entity != null)
	    {
	    
            if (entity.Latitude == 0 || entity.Longitude == 0) { return false; }
            	    
	        
	        var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(entity.Latitude, entity.Longitude));
	        
	        
	        var iconimg = 'mapnode_4.gif';
	        if (HEntityMaps.rootEntity != null && entity.EntityID == HEntityMaps.rootEntity.EntityID)
	        {
	            iconimg = 'mapnode_root.gif';
	            shape.SetZIndex(1001);
	        }
	        
	        var iconnumber = ' ';
	        if (entity.DisplayNumber) { iconnumber = entity.DisplayNumber.toString(); }
	        if (jQuery.browser.mozilla == true) { iconnumber = '<a style="color: #ffffff;">' + iconnumber + '</a>'; };
	        
	        var padding = 6; if (entity.DisplayNumber > 9) { padding = 3; }
	        var icon = '<div id="entitymap_node_' + entity.EntityID.toString() + '" title="' + entity.EntityName + '" style="background: url(images/' + iconimg + ') no-repeat 0px 0px; height:22px; width:22px; font-size: 60%; color: #FFFFFF; padding-left:' + padding + 'px; padding-top: 2px; cursor: pointer;" onclick="window.location.href=\'Details.aspx?EntityID=' + entity.EntityID + '\'" onmouseover="HEntityMaps.Highlight(' + entity.EntityID + ', true);">' + iconnumber + '</div>';
	        shape.SetCustomIcon(icon);
	        
	        
	        HEntityMaps.map.ClearInfoBoxStyles();
	        HEntityMaps.maplayer.AddShape(shape);
	        
	        entity.ShapeID = shape.GetID();
	        
	    }
	}
	
	
	oHEntityMaps.prototype.changeviewHandler = function(e)
	{

        //See if the root is in the view
        if (HEntityMaps.rootEntity != null)
        {
            
        }
        
        for (var i = 0; i < HEntityMaps.maplayer.GetShapeCount(); i++)
        {
            shape = HEntityMaps.maplayer.GetShapeByIndex(i);
            if (shape != null)
            {
                var pts = shape.GetPoints();
                if (pts != null)
                {
                    if (HEntityMaps.isEntityVisible(pts[0]) == false)
                    {
                        if(shape.GetZIndex() == 1001)
                        {
                            //root
                            
                        }
                        else
                        {
                            
                        } 
                    }
                }
            }
        }
	}
	
	
	oHEntityMaps.prototype.isEntityVisible = function(entitylatlng)
    {
        var v = HEntityMaps.map.GetMapView();
        var pinPx = HEntityMaps.map.LatLongToPixel(entitylatlng);
        var mapTopLeftPx = HEntityMaps.map.LatLongToPixel(v.TopLeftLatLong);
        var mapBottomRightPx = HEntityMaps.map.LatLongToPixel(v.BottomRightLatLong);
        if(((pinPx.x >= mapTopLeftPx.x) && (pinPx.x <= mapBottomRightPx.x)))
        {
            if(((pinPx.y >= parseInt(mapTopLeftPx.y)) && (pinPx.y <= mapBottomRightPx.y)))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
	
	
	oHEntityMaps.prototype.Highlight = function( entityid, showinfo )
	{
	
	    if(showinfo==null)showinfo = true;
	    
	    if (this.map_currenthighlight != "") { HEntityMaps.ClearHighlight(this.map_currenthighlight); }
	    
        this.map_currenthighlight = entityid;
	    
	    if (!document.getElementById('entitymap_node_' + entityid)) return;
	    
	    if (HEntityMaps.rootEntity == null || entityid != HEntityMaps.rootEntity.EntityID)
        {
            document.getElementById('entitymap_node_' + entityid).style.backgroundImage="url('images/mapnode_selected.gif')";
	    }
	    
	    if (showinfo == true) this.ShowInfo(entityid);
	    
	}
	
	
	
	oHEntityMaps.prototype.ShowInfo = function( entityid )
	{
	    if (document.getElementById(HEntityMaps.infocontainerid) != null)
	    {
            //get info content
	        document.getElementById('infocontainer_content').innerHTML = "<img src='Images/ani_16x16_swirl.gif' align='absmiddle'/>&nbsp;Loading...";
	        HDownloadUrl('get', 'restHandler.ashx?method=entityinfowindow&EntityID=' + entityid, function(text)
            {
                var entity = HEntityMaps.getEntity(entityid);
            
                var html = HgetXMLNodeInnerText(text.documentElement);
                
                if (HEntityMaps.rootEntity == null || entityid != HEntityMaps.rootEntity.EntityID)
                {
                    html += '<br><br><table cellpadding="0" cellspacing="0" border="0"><tr><td nowrap style=\"background-color: #e8e8d8;\"><img src="images/pixel_dec223.gif" style="height: 7px; width: ' + entity.Relevance + '%;"><img src=\"images/pixel_ffffff.gif\" style=\"height: 7px; width:1px;\"></td></tr><tr><td style="color: #999999; font-size: 80%;" nowrap>relevance: ' + entity.Relevance + '</td></tr></table>'
                }
                
                document.getElementById('infocontainer_content').innerHTML = html;
                
                var nam = '';
                if (entity != null && entity.EntityName != null) { nam=entity.EntityName; }
                
                var functionsHTML = '\
                <div><a href="Details.aspx?e=' + entityid + '&vm=2">Details &raquo;</a></div>\
                <div id="infocontainer_functions_center" class="a" style="cursor: pointer;"><i>sortuv</i> ' + nam + ' &raquo;</div>\
                <br>'
                document.getElementById('infocontainer_functions').innerHTML = functionsHTML;
                
                
                HDownloadUrl('get', 'DataWS/EntityRelationshipsWS.asmx/getRelatedEntityQueries?e=' + entityid, function(xml)
                {
                    $(document).ready(function($)
                    {
                        var options = {minWidth: 180, hoverOpenDelay: 200, offsetTop: 0};
                        var menu_relationshiplistqueries = new $.Menu('#infocontainer_functions_center', null, options);
                        
                        var nodequeries = xml.documentElement.getElementsByTagName("q");
                        for (var i = 0; i < nodequeries.length; i++)
                        {
                            var jsgraphurl = 'Search.aspx?SortuvQuery=' + escape(nodequeries[i].getAttribute("q"));
                            menu_relationshiplistqueries.addItem( new $.MenuItem({src: nodequeries[i].getAttribute("d"), url: jsgraphurl}) );
                        }
                        
                        menu_relationshiplistqueries.addItem( new $.MenuItem({src: '<b>Build your own...</b>', url:'javascript:HShowEntityRelationshipBuilderModal(' + entityid + '); $.Menu.closeAll();'}) );
                    });
                });
                
                
                //Add functions handlers
                $("#infocontainer_functions_center").bind("click", function(){
		            window.location.href = 'Details.aspx?EntityID=' + entityid;
                });
                
            })
        }
        
	}
	
	
	oHEntityMaps.prototype.ClearHighlight = function( entityid )
	{
	    if (document.getElementById('entitymap_node_' + entityid))
	    {
	        if (HEntityMaps.rootEntity != null && entityid == HEntityMaps.rootEntity.EntityID)
	        {
	            document.getElementById('entitymap_node_' + entityid).style.backgroundImage="url('images/mapnode_root.gif')";
	        }
	        else
	        {
	            document.getElementById('entitymap_node_' + entityid).style.backgroundImage="url('images/mapnode_4.gif')";
	        }
	        
	        if (document.getElementById(HEntityMaps.infocontainerid) != null)
    	    {
	            document.getElementById('infocontainer_content').innerHTML = "<div class=\"tip\">Roll over any item on the map to see more details.<br>Click any item on the map view the item.</div>";
	            document.getElementById('infocontainer_functions').innerHTML = "";
	        }
	    }
	}
	
	
	oHEntityMaps.prototype.ChangeMapStyle = function( mapstyle )
	{
	    this.map.SetMapStyle(mapstyle);
	}
	
	
	oHEntityMaps.prototype.CenterRoot = function()
	{
	    if (this.rootEntity != null)
	    {
	        this.map.SetCenterAndZoom(new VELatLong(this.rootEntity.Latitude, this.rootEntity.Longitude), 15);
	    }
	}
	
	
	oHEntityMaps.prototype.CenterEntity = function( entityid )
	{
	    var entity = HEntityMaps.getEntity(entityid);
	    
	    if (entity != null)
	    {
	        shape = this.map.GetShapeByID(entity.ShapeID);
	        if (shape)
	        {
	            this.lastZIndex++;
	            shape.SetZIndex(this.lastZIndex);
	        }
	        
	        this.map.SetCenterAndZoom(new VELatLong(entity.Latitude, entity.Longitude), 13);
	    }
	}
	
	
	oHEntityMaps.prototype.getEntity = function( entityid )
	{
	    
	    var entity = null;
	    
	    for (var i = 0; i < this.Entities.length; i++)
        {
            if ( this.Entities[i] )
            {
                if (this.Entities[i].EntityID == entityid)
                {
                    entity = this.Entities[i];
                }
            }
        }
        
        return entity;
	}
	
	
	oHEntityMaps.prototype.Entity = function( entityid, entityname, latitude, longitude, relevance, displaynumber )
	{
        this.EntityID = entityid;
        this.EntityName = entityname;
        this.Latitude = latitude;
        this.Longitude = longitude;
        this.Relevance = relevance;
        this.DisplayNumber = displaynumber;
        this.ShapeID;
	}

}






var HEntityMap = new oHEntityMap()

function oHEntityMap()
{
    this.map = null;
    this.maplayer = null;
    this.mapControl = null;
	
	oHEntityMap.prototype.ShowModal = function( latitude, longitude, nam, address )
	{
	    $(document).ready(function()
	    {
	        HShowModalWindow("<div id=\"mapModal\" style='position:relative; top: 0px; width:100%; height:20px; border-bottom: solid 1px #e8e8d8;'><table><tr><td style='width: 100%;'><b>" + nam + "</b></td><td nowrap><span style='cursor: pointer;' class='aless' onclick='parent.HHideModalWindow();'>X</span></td></tr></table></div><div id='entitymapdiv' style='position:relative; width:460px; height:360px;'></div>", 380, 460);
	        
	        if (HEntityMap.map!=null)
            {
                HEntityMap.map.Dispose();
                HEntityMap.map = null;
                HEntityMap.maplayer = null;
                HEntityMap.mapControl = null;
            }
            
            
    	    
	        HEntityMap.map = new VEMap('entitymapdiv');
	        HEntityMap.map.HideDashboard();
	        HEntityMap.map.LoadMap(new VELatLong(latitude, longitude), 15 ,'r' ,false, VEMapMode.Mode2D);
	        
	        
	        HEntityMap.maplayer = new VEShapeLayer();         
	        HEntityMap.map.AddShapeLayer(HEntityMap.maplayer);
	        HEntityMap.maplayer.DeleteAllShapes();
    	    
    	    
	        var icon = '<img src="images/mapnode_root.gif" border="0">'
            
            var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(latitude, longitude));
            shape.SetCustomIcon(icon);
            HEntityMap.map.ClearInfoBoxStyles();
            HEntityMap.maplayer.AddShape(shape);
            
            
            //Controls
            if (HEntityMap.mapControl == null)
            {
                HEntityMap.mapControl = document.createElement("div");
                HEntityMap.mapControl.id = "mapControlMap";
                HEntityMap.mapControl.style.border = "1px solid #d0c99b";
                HEntityMap.mapControl.style.padding = "1px";
                HEntityMap.mapControl.style.background = "#ffffff";
                HEntityMap.mapControl.style.opacity = "0.80";
                HEntityMap.mapControl.style.filter = "alpha(opacity=80)";
                HEntityMap.mapControl.innerHTML = "&nbsp;<span onclick=\"HEntityMap.ChangeMapStyle('h');\" style=\"cursor: pointer; font-size: 60%;\" title=\"Switch to aerial view\">aerial</span> <span onclick=\"HEntityMap.ChangeMapStyle('r');\" style=\"cursor: pointer; font-size: 60%;\" title=\"Switch to road view\">road</span>  <span class=\"aless\" onclick=\"HEntityMap.SetBirdseye();\" style=\"cursor: pointer; font-size: 60%;\" title=\"Switch to birds eye view\">birdseye</span> |";
                HEntityMap.mapControl.innerHTML += " <span onclick=\"HEntityMap.CenterRoot('" + latitude + "', '" + longitude + "');\" style=\"cursor: pointer; font-size: 60%;\" title=\"Center to " + nam + "\">center to <img src=\"images/mapnode_root_sm.gif\" align=\"absmiddle\"></span> |";
                HEntityMap.mapControl.innerHTML += " <span class=\"aless\" unselectable onclick=\"HEntityMap.map.ZoomOut();\" style=\"cursor: pointer;\" title=\"Zoom out\"><img src=\"images/mapcontrol_zoomout.gif\" align=\"middle\"></span><span class=\"aless\" onclick=\"HEntityMap.map.ZoomIn();\" style=\"cursor: pointer;\" title=\"Zoom in\"><img src=\"images/mapcontrol_zoomin.gif\" align=\"middle\"></span>&nbsp;";
                
                HEntityMap.map.AddControl(HEntityMap.mapControl);
                document.getElementById("entitymapdiv").appendChild(HEntityMap.mapControl);
                HEntityMap.mapControl.style.top ="4px";
                HEntityMap.mapControl.style.left = "4px";
            }
            
	    })
    }
    
    
    oHEntityMap.prototype.ChangeMapStyle = function( mapstyle )
	{
	    this.map.SetMapStyle(mapstyle);
	}
	
	
	oHEntityMap.prototype.CenterRoot = function( latitude, longitude )
	{
	    this.map.SetCenterAndZoom(new VELatLong(latitude, longitude), 17);
	}
	
	
	oHEntityMap.prototype.SetBirdseye = function( )
	{
	    if (this.map.IsBirdseyeAvailable())
	    {
	        this.ChangeMapStyle("o");
	    }
	}
    
}





var HLocationRefineMenu = new oHLocationRefineMenu;

function oHLocationRefineMenu()
{
    this.MenuItemID = "";
    this.EntityID = "";
    this.Query = "";
    
    oHLocationRefineMenu.prototype.Register = function( menuitemid, entityid, rq )
    {
        this.MenuItemID = menuitemid;
        this.EntityID = entityid;
        this.Query = rq;
        
        jQuery(document).ready(function()
        {
            if (document.getElementById("locationrefinemenu_" + entityid.toString()) == null)
            {
                menudiv = document.createElement("div");
                menudiv.innerHTML = '<iframe src=\"Search_Filter_Inner.aspx?SortuvQuery=' + rq + '&e=' + entityid + '\" width=\"100%\" height=\"275\" frameborder=0 scrolling=no align=middle>loading...</iframe>';
                menudiv.className = 'filtermenu_body';
                menudiv.style.position = 'absolute';
                menudiv.style.zIndex = 999;
                menudiv.style.display = 'none';
                menudiv.id = 'locationrefinemenu_' + entityid.toString();
                menudiv.style.width = '380px';
                menudiv.style.height = '280px';
                document.body.appendChild(menudiv);
                
                $(document).bind('mousedown', HLocationRefineMenu.checkMouse).bind('keydown', HLocationRefineMenu.checkKey);
            }
        
        
            $("#" + menuitemid).bind("click", function(){
                $.Menu.closeAll();
                document.getElementById(menuitemid).className='filtermenu_header_selected';
                
                var pos = HFindPosition(document.getElementById(menuitemid));
                var x = pos[0];
                var y = pos[1];
                
                document.getElementById("locationrefinemenu_" + entityid.toString()).style.top = y + 20 + 'px';
                document.getElementById("locationrefinemenu_" + entityid.toString()).style.left = x + 'px';
                
                document.getElementById("locationrefinemenu_" + entityid.toString()).style.display = 'block';
                HShowModalBackground(0);
            });
           
        })
        
    }
    
    oHLocationRefineMenu.prototype.hide = function( )
	{
	    HHideModalBackground();
	    document.getElementById(this.MenuItemID).className='filtermenu_header';
	    document.getElementById('locationrefinemenu_' + HLocationRefineMenu.EntityID.toString()).style.display = 'none';
	}
    
    
    oHLocationRefineMenu.prototype.checkMouse = function( e )
	{
	    if (e.target){
	        if (document.getElementById('locationrefinemenu_' + HLocationRefineMenu.EntityID.toString()).style.display=='block'){
                if (HCompareOwnerNode(e.target, document.getElementById('locationrefinemenu_' + HLocationRefineMenu.EntityID.toString())) == false){
	                HLocationRefineMenu.hide();
	            }
	        }
	    }
	}
	
	
	oHLocationRefineMenu.prototype.checkKey = function( e )
	{
	    if (e.keyCode){
	        if (document.getElementById('locationrefinemenu_' + HLocationRefineMenu.EntityID.toString()).style.display=='block'){
	            if (e.keyCode == 27){
	                HLocationRefineMenu.hide();
	            }
	        }
	    }
	}

}



function HShowModalBackground( opacity )
{
    if (document.getElementById("modalBackgroundEx") == null)
    {
        var div = document.createElement("div");
        div.innerHTML = "<div id=\"modalBackgroundEx\" style=\"position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 998;background-color:#ffffff; display: none; opacity: 0." + opacity.toString() + "; filter: alpha(opacity=" + opacity.toString() + ")\"></div>";
        document.body.appendChild(div);
    }
    
    document.getElementById("modalBackgroundEx").style.display='block';
}


function HHideModalBackground()
{
    document.getElementById("modalBackgroundEx").style.display='none';
}







function HShowFeedbackIcon(tooltip, element)
{
    var page = location.pathname;
    var querystring = location.search;
    
    if (tooltip.toString().length == 0) { tooltip = 'Please click here to give us feedback.'; }
    
    document.write('<img src="Images/icon_feedback.gif" align="absmiddle" style="cursor: pointer;" title="' + tooltip + '" onclick="HShowFeedbackModal(\'' + page + '\', \'' + querystring + '\',\'' + escape(element) + '\');"/>');
    
}





//Search Header
var id_txtSortuvEntityName = '';
var id_txtSortuvLocation = '';
var id_hSortuvLocationDirective = '';
var id_hSortuvEntityID = '';
var id_hSortuvCategoryIDs = '';

var waterSortuvEntityName_0 = 'Your favorite restaurant, hotel, bar or store?';
var waterSortuvEntityName_200 = 'Your favorite restaurant?';
var waterSortuvEntityName_176 = 'Your favorite bar or club?';
var waterSortuvEntityName_147 = 'Your favorite hotel?';
var waterSortuvEntityName_235 = 'Your favorite store?';
var waterSortuvEntityName_23 = 'Your favorite museum?';
var waterSortuvEntityName_45 = 'Your favorite spa or salon?';
var waterSortuvEntityName = waterSortuvEntityName_0;

function HSetupSortuv(in_id_txtSortuvEntityName, in_id_txtSortuvLocation, in_id_hSortuvLocationDirective, in_id_hSortuvEntityID, in_id_hSortuvCategoryIDs)
{
    id_txtSortuvEntityName = in_id_txtSortuvEntityName;
    id_txtSortuvLocation = in_id_txtSortuvLocation;
    id_hSortuvLocationDirective = in_id_hSortuvLocationDirective;
    id_hSortuvEntityID = in_id_hSortuvEntityID;
    id_hSortuvCategoryIDs = in_id_hSortuvCategoryIDs;
    
    $(document).ready(function()
    {
        $("#" + id_txtSortuvEntityName).autocomplete( "restHandler.ashx?method=entitysuggest", { delay:10, minChars:2, width:328, onItemSelect:HSortuvEntitySuggestHandler, onFindValue:HSortuvEntitySuggestFindValue, formatItem:HSortuvEntitySuggestFormatItem });
        if (document.getElementById(id_txtSortuvLocation)) { $("#" + id_txtSortuvLocation).autocompleteArray(["Seattle, WA", "Birmingham, AL", "Huntsville, AL", "Madison, AL", "Mobile, AL", "Montgomery, AL", "Tuscaloosa, AL", "Decatur, AL", "Anchorage, AK", "Juneau, AK", "Seward, AK", "Seward, AK", "Fairbanks, AK", "College, AK", "Chandler, AZ", "Flagstaff, AZ", "Grand Canyon, AZ", "Mesa, AZ", "Phoenix, AZ", "Scottsdale, AZ", "Sedona, AZ", "Tempe, AZ", "Tucson, AZ", "Bentonville, AR", "Fayetteville, AR", "Hot Springs, AR", "Little Rock, AR", "Berkeley, CA", "Covina, CA", "Fresno, CA", "Los Angeles, CA", "Napa Valley, CA", "Sonoma Valley, CA", "Newport Beach, CA", "Oakland, CA", "Orange County, CA", "Oxnard, CA", "Palm Springs, CA", "Palo Alto, CA", "Redwood City, CA", "Sacramento, CA", "San Bernardino, CA", "San Diego, CA", "San Francisco, CA", "San Jose, CA", "Santa Barbara, CA", "Santa Maria, CA", "Stockton, CA", "Visalia, CA", "Beaver Creek, CO", "Boulder, CO", "Colorado Springs, CO", "Denver, CO", "Steamboat Springs, CO", "Telluride, CO", "Brookfield, CT", "Greenwich, CT", "Hartford, CT", "New Haven, CT", "New London, CT", "Stamford, CT", "Dover, DE", "Wilmington, DE", "Washington, DC", "Boca Raton, FL", "Daytona Beach, FL", "Destin, FL", "Fort Lauderdale, FL", "Fort Myers, FL", "Gainesville, FL", "Jacksonville, FL", "Key West, FL", "Miami, FL", "Naples, FL", "Ocala, FL", "Orlando, FL", "Palm Beach, FL", "West Palm Beach, FL", "Panama City, FL", "Pensacola, FL", "Sarasota, FL", "Space Coast, FL", "St. Augustine, FL", "St. Petersburg, FL", "Tallahassee, FL", "Tampa, FL", "Alpharetta, GA", "Atlanta, GA", "Augusta, GA", "Brunswick, GA", "Golden Isles, GA", "Columbus, GA", "Helen, GA", "Kingsland, GA", "Macon, GA", "Rome, GA", "Savannah, GA", "Valdosta, GA", "Big Island, HI", "Honolulu, HI", "Kauai, HI", "Maui, HI", "Sun Valley, ID", "Bloomington, IL", "Normal, IL", "Chicago, IL", "Decatur, IL", "Galena, IL", "Moline, IL", "Quad Cities, IL", "Naperville, IL", "Peoria, IL", "Schaumburg, IL", "Urbana, IL", "Fort Wayne, IN", "Indianapolis, IN", "Lafayette, IN", "Merrillville, IN", "Shipshewana, IN", "Cedar Falls, IA", "Cedar Rapids, IA", "Des Moines, IA", "Iowa City, IA", "Wichita, KS", "Lexington, KY", "Louisville, KY", "Paducah, KY", "Baton Rouge, LA", "New Orleans, LA", "Annapolis, MD", "Baltimore, MD", "Boston, MA", "Hyannis, MA", "Marlborough, MA", "Plymouth, MA", "Ann Arbor, MI", "Detroit, MI", "Flint, MI", "Grand Rapids, MI", "Kalamazoo, MI", "Lansing, MI", "Baxter, MN", "Duluth, MN", "Minneapolis, MN", "Montevideo, MN", "Rochester, MN", "St. Cloud, MN", "St. Paul, MN", "Biloxi, MS", "Gulfport, MS", "Jackson, MS", "Oxford, MS", "Vicksburg, MS", "Branson, MO", "Kansas City, MO", "OFallon, MO", "St. Louis, MO", "Billings, MT", "Bozeman, MT", "Omaha, NE", "Las Vegas, NV", "Reno, NV", "Tahoe, NV", "Manchester, NH", "Atlantic City, NJ", "Newark, NJ", "Princeton, NJ", "Franklin Lakes, NJ", "Patterson, NJ", "Albuquerque, NM", "Santa Fe, NM", "Buffalo, NY", "Corning, NY", "Long Island, NY", "New York, NY", "Newburgh, NY", "Queensbury, NY", "Rochester, NY", "Syracuse, NY", "Brooklyn, NY", "Utica, NY", "Albany, NY", "New Rochelle, NY", "Hudson Valley, NY", "Binghamton, NY", "Glens Falls, NY", "Ithaca, NY", "Elmira, NY", "Kingston, NY", "Asheville, NC", "Chapel Hill, NC", "Charlotte, NC", "Durham, NC", "Fayetteville, NC", "Greensboro, NC", "Hickory, NC", "Raleigh, NC", "Winston-Salem, NC", "Bismarck, ND", "Fargo, ND", "Akron, OH", "Canton, OH", "Cincinnati, OH", "Cleveland, OH", "Columbus, OH", "Dayton, OH", "Sandusky, OH", "Toledo, OH", "Oklahoma City, OK", "Tulsa, OK", "Portland, OR", "Bethlehem, PA", "Erie, PA", "Gettysburg, PA", "Harrisburg, PA", "Lancaster, PA", "Philadelphia, PA", "Pittsburgh, PA", "Poconos, PA", "Scranton, PA", "West Middlesex, PA", "Williamsport, PA", "York, PA", "Newport, RI", "Providence, RI", "Anderson, SC", "Beaufort, SC", "Charleston, SC", "Clemson, SC", "Columbia, SC", "Greenville, SC", "Hilton Head, SC", "Kiawah Island, SC", "Myrtle Beach, SC", "Spartanburg, SC", "Rapid City, SD", "Sioux Falls, SD", "Chattanooga, TN", "Kingsport, TN", "Knoxville, TN", "Memphis, TN", "Nashville, TN", "Austin, TX", "Corpus Christi, TX", "Dallas, TX", "Denton, TX", "El Paso, TX", "Fort Worth, TX", "Galveston, TX", "Houston, TX", "McAllen, TX", "San Antonio, TX", "South Padre Island, TX", "Tyler, TX", "Waco, TX", "Wichita Falls, TX", "Heber City, UT", "Ogden, UT", "Park City, UT", "Provo, UT", "Salt Lake City, UT", "Burlington, VT", "Stowe, VT", "Alexandria, VA", "Charlottesville, VA", "Lynchburg, VA", "Newport News, VA", "Norfolk, VA", "Richmond, VA", "Roanoke, VA", "Sterling, VA", "Virginia Beach, VA", "Williamsburg, VA", "Bellevue, WA", "Kirkland, WA", "Redmond, WA", "Woodenville, WA", "Spokane, WA", "Bothell, WA", "Bainbridge Island, WA", "Bellingham, WA", "Bremerton, WA", "Castle Rock, WA", "Duvall, WA", "Edmonds, WA", "Everett, WA", "Fall City, WA", "Federal Way, WA", "Friday Harbor, WA", "Gig Harbor, WA", "Issaquah, WA", "Lynnwood, WA", "Mukilteo, WA", "Olympia, WA", "Renton, WA", "San Juan Island, WA", "Sammamish, WA", "Tacoma, WA", "Vancouver, WA", "Walla Walla, WA", "Yakima, WA", "Beckley, WV", "Charleston, WV", "Huntington, WV", "Morgantown, WV", "Appleton, WI", "Baraboo, WI", "Eau Claire, WI", "Green Bay, WI", "La Crosse, WI", "Madison, WI", "Milwaukee, WI", "Oshkosh, WI", "Pleasant Prairie, WI", "Racine, WI", "Casper, WY", "Jackson Hole, WY", "Cheyenne, WY", "Lander, WY", "Sheridan, WY"], { delay:10, minChars:1, matchSubset:1, autoFill:false, maxItemsToShow:10, onItemSelect:HSortuvLocationSuggestHandler }); }
        
        if ($.trim($("#" + id_txtSortuvEntityName).val()) == "")
        {
            $("#" + id_txtSortuvEntityName).val(waterSortuvEntityName); document.getElementById(id_txtSortuvEntityName).style.color='#999999';
        }
        $("#" + id_txtSortuvEntityName).focus(function(){
            if ($("#" + id_txtSortuvEntityName).val() == waterSortuvEntityName){
                $("#" + id_txtSortuvEntityName).val(""); document.getElementById(id_txtSortuvEntityName).style.color='#333333';
            }
        }).blur(function(){
            if ($.trim($("#" + id_txtSortuvEntityName).val()) == "") {
                $("#" + id_txtSortuvEntityName).val(waterSortuvEntityName); document.getElementById(id_txtSortuvEntityName).style.color='#999999';
            }
        });
        
        $("#" + id_txtSortuvEntityName).change(function(){
            $("#" + id_hSortuvEntityID).val("");
        });
        
        if (document.getElementById(id_txtSortuvLocation)) {
            if ($.trim($("#" + id_txtSortuvLocation).val()) == "")
            {
                $("#" + id_txtSortuvLocation).val("City, State or Zip"); document.getElementById(id_txtSortuvLocation).style.color='#999999';
            }
            $("#" + id_txtSortuvLocation).focus(function(){
                if ($("#" + id_txtSortuvLocation).val() == "City, State or Zip"){
                    $("#" + id_txtSortuvLocation).val(""); document.getElementById(id_txtSortuvLocation).style.color='#333333';
                }
            }).blur(function(){
                if ($.trim($("#" + id_txtSortuvLocation).val()) == "") {
                    $("#" + id_txtSortuvLocation).val("City, State or Zip"); document.getElementById(id_txtSortuvLocation).style.color='#999999';
                }
            });
            
            $("#" + id_txtSortuvLocation).change(function(){
                $("#" + id_hSortuvLocationDirective).val("");
            });
        }
        
    })
}

function HSortuvEntitySuggestHandler(li) {
    var oSuggest = $("#" + id_txtSortuvEntityName)[0].autocompleter;
    if (li == null) return false;
    if (li.extra != null) {
        document.getElementById(id_hSortuvEntityID).value = li.extra[0];
    }
    return false;
}

function HSortuvEntitySuggestFindValue(li) {
    if (li == null) return false;
    if (li.extra != null) {
        document.getElementById(id_hSortuvEntityID).value = li.extra[0];
    }
}

function HSortuvEntitySuggestFormatItem(row) {
    return row[0];
}

function HSortuvLocationSuggestHandler() {
    $("#" + id_hSortuvLocationDirective).val("");
}


function HSetSortuvCategoryIDs(catids, tab)
{
    if (document.getElementById(id_hSortuvCategoryIDs)) { document.getElementById(id_hSortuvCategoryIDs).value = catids; }
    
    document.getElementById('catSortuvAnything').className='searchbartab';
    document.getElementById('catSortuv200').className='searchbartab';
    document.getElementById('catSortuv176').className='searchbartab';
    document.getElementById('catSortuv147').className='searchbartab';
    document.getElementById('catSortuv235').className='searchbartab';
    document.getElementById('catSortuv23').className='searchbartab';
    document.getElementById('catSortuv45').className='searchbartab';
    
    if (tab) {
        tab.className='searchbartab_selected';
        
        if (document.getElementById(id_txtSortuvEntityName)) {
            if ($.trim($("#" + id_txtSortuvEntityName).val()) == "" || $.trim($("#" + id_txtSortuvEntityName).val()) == waterSortuvEntityName)
            {
                $("#" + id_txtSortuvEntityName).val("");
            }
        }
        
        if (tab.id == 'catSortuvAnything') { waterSortuvEntityName=waterSortuvEntityName_0; }
        if (tab.id == 'catSortuv200') { waterSortuvEntityName=waterSortuvEntityName_200; }
        if (tab.id == 'catSortuv176') { waterSortuvEntityName=waterSortuvEntityName_176; }
        if (tab.id == 'catSortuv147') { waterSortuvEntityName=waterSortuvEntityName_147; }
        if (tab.id == 'catSortuv235') { waterSortuvEntityName=waterSortuvEntityName_235; }
        if (tab.id == 'catSortuv23') { waterSortuvEntityName=waterSortuvEntityName_23; }
        if (tab.id == 'catSortuv45') { waterSortuvEntityName=waterSortuvEntityName_45; }
        
        if (document.getElementById(id_txtSortuvEntityName)) {
            if ($.trim($("#" + id_txtSortuvEntityName).val()) == "")
            {
                $("#" + id_txtSortuvEntityName).val(waterSortuvEntityName); document.getElementById(id_txtSortuvEntityName).style.color='#999999';
            }
        }
    }
    
}



function validateSortuvSearch()
{
    var valid = true;
    
    if ($("#" + id_txtSortuvEntityName).val() == "" || $("#" + id_txtSortuvEntityName).val() == waterSortuvEntityName)
    {
        $("#" + id_txtSortuvEntityName).animate({ color: "#dd3c10", borderBottomColor: "#dd3c10", borderLeftColor: "#dd3c10", borderRightColor: "#dd3c10", borderTopColor: "#dd3c10" }, { duration: 200, queue: true }).animate({ color: "#999999", borderBottomColor: "#ffffff", borderLeftColor: "#ffffff", borderRightColor: "#ffffff", borderTopColor: "#ffffff" }, { duration: 300, queue: true });
        valid = false;
    }

    return valid;
}



function HRegisterLocationBox(id)
{
    $(document).ready(function()
    {
        $("#" + id).autocompleteArray(["Seattle, WA", "Birmingham, AL", "Huntsville, AL", "Madison, AL", "Mobile, AL", "Montgomery, AL", "Tuscaloosa, AL", "Decatur, AL", "Anchorage, AK", "Juneau, AK", "Seward, AK", "Seward, AK", "Fairbanks, AK", "College, AK", "Chandler, AZ", "Flagstaff, AZ", "Grand Canyon, AZ", "Mesa, AZ", "Phoenix, AZ", "Scottsdale, AZ", "Sedona, AZ", "Tempe, AZ", "Tucson, AZ", "Bentonville, AR", "Fayetteville, AR", "Hot Springs, AR", "Little Rock, AR", "Berkeley, CA", "Covina, CA", "Fresno, CA", "Los Angeles, CA", "Napa Valley, CA", "Sonoma Valley, CA", "Newport Beach, CA", "Oakland, CA", "Orange County, CA", "Oxnard, CA", "Palm Springs, CA", "Palo Alto, CA", "Redwood City, CA", "Sacramento, CA", "San Bernardino, CA", "San Diego, CA", "San Francisco, CA", "San Jose, CA", "Santa Barbara, CA", "Santa Maria, CA", "Stockton, CA", "Visalia, CA", "Beaver Creek, CO", "Boulder, CO", "Colorado Springs, CO", "Denver, CO", "Steamboat Springs, CO", "Telluride, CO", "Brookfield, CT", "Greenwich, CT", "Hartford, CT", "New Haven, CT", "New London, CT", "Stamford, CT", "Dover, DE", "Wilmington, DE", "Washington, DC", "Boca Raton, FL", "Daytona Beach, FL", "Destin, FL", "Fort Lauderdale, FL", "Fort Myers, FL", "Gainesville, FL", "Jacksonville, FL", "Key West, FL", "Miami, FL", "Naples, FL", "Ocala, FL", "Orlando, FL", "Palm Beach, FL", "West Palm Beach, FL", "Panama City, FL", "Pensacola, FL", "Sarasota, FL", "Space Coast, FL", "St. Augustine, FL", "St. Petersburg, FL", "Tallahassee, FL", "Tampa, FL", "Alpharetta, GA", "Atlanta, GA", "Augusta, GA", "Brunswick, GA", "Golden Isles, GA", "Columbus, GA", "Helen, GA", "Kingsland, GA", "Macon, GA", "Rome, GA", "Savannah, GA", "Valdosta, GA", "Big Island, HI", "Honolulu, HI", "Kauai, HI", "Maui, HI", "Sun Valley, ID", "Bloomington, IL", "Normal, IL", "Chicago, IL", "Decatur, IL", "Galena, IL", "Moline, IL", "Quad Cities, IL", "Naperville, IL", "Peoria, IL", "Schaumburg, IL", "Urbana, IL", "Fort Wayne, IN", "Indianapolis, IN", "Lafayette, IN", "Merrillville, IN", "Shipshewana, IN", "Cedar Falls, IA", "Cedar Rapids, IA", "Des Moines, IA", "Iowa City, IA", "Wichita, KS", "Lexington, KY", "Louisville, KY", "Paducah, KY", "Baton Rouge, LA", "New Orleans, LA", "Annapolis, MD", "Baltimore, MD", "Boston, MA", "Hyannis, MA", "Marlborough, MA", "Plymouth, MA", "Ann Arbor, MI", "Detroit, MI", "Flint, MI", "Grand Rapids, MI", "Kalamazoo, MI", "Lansing, MI", "Baxter, MN", "Duluth, MN", "Minneapolis, MN", "Montevideo, MN", "Rochester, MN", "St. Cloud, MN", "St. Paul, MN", "Biloxi, MS", "Gulfport, MS", "Jackson, MS", "Oxford, MS", "Vicksburg, MS", "Branson, MO", "Kansas City, MO", "OFallon, MO", "St. Louis, MO", "Billings, MT", "Bozeman, MT", "Omaha, NE", "Las Vegas, NV", "Reno, NV", "Tahoe, NV", "Manchester, NH", "Atlantic City, NJ", "Newark, NJ", "Princeton, NJ", "Franklin Lakes, NJ", "Patterson, NJ", "Albuquerque, NM", "Santa Fe, NM", "Buffalo, NY", "Corning, NY", "Long Island, NY", "New York, NY", "Newburgh, NY", "Queensbury, NY", "Rochester, NY", "Syracuse, NY", "Brooklyn, NY", "Utica, NY", "Albany, NY", "New Rochelle, NY", "Hudson Valley, NY", "Binghamton, NY", "Glens Falls, NY", "Ithaca, NY", "Elmira, NY", "Kingston, NY", "Asheville, NC", "Chapel Hill, NC", "Charlotte, NC", "Durham, NC", "Fayetteville, NC", "Greensboro, NC", "Hickory, NC", "Raleigh, NC", "Winston-Salem, NC", "Bismarck, ND", "Fargo, ND", "Akron, OH", "Canton, OH", "Cincinnati, OH", "Cleveland, OH", "Columbus, OH", "Dayton, OH", "Sandusky, OH", "Toledo, OH", "Oklahoma City, OK", "Tulsa, OK", "Portland, OR", "Bethlehem, PA", "Erie, PA", "Gettysburg, PA", "Harrisburg, PA", "Lancaster, PA", "Philadelphia, PA", "Pittsburgh, PA", "Poconos, PA", "Scranton, PA", "West Middlesex, PA", "Williamsport, PA", "York, PA", "Newport, RI", "Providence, RI", "Anderson, SC", "Beaufort, SC", "Charleston, SC", "Clemson, SC", "Columbia, SC", "Greenville, SC", "Hilton Head, SC", "Kiawah Island, SC", "Myrtle Beach, SC", "Spartanburg, SC", "Rapid City, SD", "Sioux Falls, SD", "Chattanooga, TN", "Kingsport, TN", "Knoxville, TN", "Memphis, TN", "Nashville, TN", "Austin, TX", "Corpus Christi, TX", "Dallas, TX", "Denton, TX", "El Paso, TX", "Fort Worth, TX", "Galveston, TX", "Houston, TX", "McAllen, TX", "San Antonio, TX", "South Padre Island, TX", "Tyler, TX", "Waco, TX", "Wichita Falls, TX", "Heber City, UT", "Ogden, UT", "Park City, UT", "Provo, UT", "Salt Lake City, UT", "Burlington, VT", "Stowe, VT", "Alexandria, VA", "Charlottesville, VA", "Lynchburg, VA", "Newport News, VA", "Norfolk, VA", "Richmond, VA", "Roanoke, VA", "Sterling, VA", "Virginia Beach, VA", "Williamsburg, VA", "Bellevue, WA", "Kirkland, WA", "Redmond, WA", "Woodenville, WA", "Spokane, WA", "Bothell, WA", "Bainbridge Island, WA", "Bellingham, WA", "Bremerton, WA", "Castle Rock, WA", "Duvall, WA", "Edmonds, WA", "Everett, WA", "Fall City, WA", "Federal Way, WA", "Friday Harbor, WA", "Gig Harbor, WA", "Issaquah, WA", "Lynnwood, WA", "Mukilteo, WA", "Olympia, WA", "Renton, WA", "San Juan Island, WA", "Sammamish, WA", "Tacoma, WA", "Vancouver, WA", "Walla Walla, WA", "Yakima, WA", "Beckley, WV", "Charleston, WV", "Huntington, WV", "Morgantown, WV", "Appleton, WI", "Baraboo, WI", "Eau Claire, WI", "Green Bay, WI", "La Crosse, WI", "Madison, WI", "Milwaukee, WI", "Oshkosh, WI", "Pleasant Prairie, WI", "Racine, WI", "Casper, WY", "Jackson Hole, WY", "Cheyenne, WY", "Lander, WY", "Sheridan, WY"], { delay:10, minChars:1, matchSubset:1, autoFill:false, maxItemsToShow:10, onItemSelect:HSortuvLocationSuggestHandler });
        
        if (document.getElementById(id)) {
            if ($.trim($("#" + id).val()) == "")
            {
                $("#" + id).val("City, State or Zip"); document.getElementById(id).style.color='#999999';
            }
            $("#" + id).focus(function(){
                if ($("#" + id).val() == "City, State or Zip"){
                    $("#" + id).val(""); document.getElementById(id).style.color='#333333';
                }
            }).blur(function(){
                if ($.trim($("#" + id).val()) == "") {
                    $("#" + id).val("City, State or Zip"); document.getElementById(id).style.color='#999999';
                }
            });
        }
        
    })
}


function validateQueryLocationFilter(id, errorid)
{
    var valid = true;
    
    if ($("#" + id).val().length < 3 || $("#" + id).val() == "City, State or Zip")
    {
        $("#" + id).animate({ borderBottomColor: "#dd3c10", borderLeftColor: "#dd3c10", borderRightColor: "#dd3c10", borderTopColor: "#dd3c10" }, { duration: 200, queue: true }).animate({ borderBottomColor: "#ffffff", borderLeftColor: "#ffffff", borderRightColor: "#ffffff", borderTopColor: "#ffffff" }, { duration: 300, queue: true });
        valid = false;
    }

    return valid;
}


function toggleQueryFilters()
{
    if (document.getElementById('QueryFilters_outer').style.display=='none')
    {
        $('#QueryFilters_outer').show('fast');
        document.getElementById('QueryFilters_img').src='images/filterswhere_opened.gif';
    }
    else
    {
        $('#QueryFilters_outer').hide('fast');
        document.getElementById('QueryFilters_img').src='images/filterswhere.gif';
    }
}


function toggleExpandoQueryFilters(outerdivid, linkdivid)
{
    if (document.getElementById(outerdivid).style.display=='none')
    {
        $('#' + outerdivid).show('fast');
        document.getElementById(linkdivid).innerHTML='- Less';
    }
    else
    {
        $('#' + outerdivid).hide('fast');
        document.getElementById(linkdivid).innerHTML='+ More';
    }
}


function toggleExpandoQueryCategoryFilters(outerdivid, linkdivid, catid, query)
{
    if (document.getElementById(outerdivid).style.display=='none')
    {
        document.getElementById(linkdivid).innerHTML='...';
        
        if (document.getElementById(outerdivid).innerHTML.length == 0){
            $.ajax({
                url: "restHandler.ashx?method=categoryfilters&CategoryID=" + catid + "&Query=" + query + "",
                type: "GET",
                cache: false,
                success: function(data)
                {
                    document.getElementById(outerdivid).innerHTML = data;
                    $('#' + outerdivid).show('fast');
                    document.getElementById(linkdivid).innerHTML='-';
                }
            });
        }
        else{
            $('#' + outerdivid).show('fast');
            document.getElementById(linkdivid).innerHTML='-';
        }
    }
    else
    {
        $('#' + outerdivid).hide('fast');
        document.getElementById(linkdivid).innerHTML='+';
    }
}



function redirURL(entityurlid)
{
    $.ajax({
        url: "restHandler.ashx?method=redirurl&EntityURLID=" + entityurlid + "",
        type: "GET",
        cache: false
    });
}


function captureAffil(affiliateid, entityid)
{
    $.ajax({
        url: "restHandler.ashx?method=captureaffil&AffiliateID=" + affiliateid + "&EntityID=" + entityid + "",
        type: "GET",
        cache: false
    });
}


function logAPI(methodName, itemID_A, context)
{
    $.ajax({
        url: "restHandler.ashx?method=logAPI&methodName=" + methodName + "&itemID_A=" + itemID_A + "&context=" + context + "",
        type: "GET",
        cache: false
    });
}





function renderShopStyleWidget_byQuery(containerid, query, entityid)
{
    if (document.getElementById(containerid))
    {
        $.ajax({
            url: "restHandler.ashx?method=renderShopStyleWidget_byQuery&Query=" + query + "&EntityID=" + entityid + "",
            type: "GET",
            cache: false,
            success: function(data)
            {
                document.getElementById(containerid).innerHTML = data;
                $(".genericcarousel").jCarouselLite({ visible: 6, btnNext: ".genericcarouselnext", btnPrev: ".genericcarouselprev", vertical: 'true' });
            }
        });
    }
}


function renderShopStyleWidget_byRetailerID(containerid, retailerid, entityid)
{
    if (document.getElementById(containerid))
    {
        $.ajax({
            url: "restHandler.ashx?method=renderShopStyleWidget_byRetailerID&RetailerID=" + retailerid + "&EntityID=" + entityid + "",
            type: "GET",
            cache: false,
            success: function(data)
            {
                document.getElementById(containerid).innerHTML = data;
                $(".genericcarousel").jCarouselLite({ visible: 6, btnNext: ".genericcarouselnext", btnPrev: ".genericcarouselprev", vertical: 'true' });
            }
        });
    }
}


function renderShopStyleWidget_byBrandID(containerid, brandid, entityid)
{
    if (document.getElementById(containerid))
    {
        $.ajax({
            url: "restHandler.ashx?method=renderShopStyleWidget_byBrandID&BrandID=" + brandid + "&EntityID=" + entityid + "",
            type: "GET",
            cache: false,
            success: function(data)
            {
                document.getElementById(containerid).innerHTML = data;
                $(".genericcarousel").jCarouselLite({ visible: 6, btnNext: ".genericcarouselnext", btnPrev: ".genericcarouselprev", vertical: 'true' });
            }
        });
    }
}


function hidehidemes()
{
    $('.hideme').css('visibility' ,'hidden');
}

function showmhidemes()
{
    $('.hideme').css('visibility' ,'visible');
}


function linkTo(url)
{
    window.open(url);
    return false;
}