﻿var LeftSearch = {
    // use for Search.SearchUI.LoadLocations
    // check the user selection of the location dropdown throughout the site
    LocationEval : function(obj) {
	    var val = obj.options[obj.selectedIndex].value;
	    if ( val == "" ) {
		    obj.selectedIndex = 0;
		    return;
	    } else if ( val == "edit" ) {
		    location.href = "/users/userlocation.aspx?do=edit";
	    } else if ( val == "enter" ) {
		    location.href = "/users/userlocation.aspx";
	    }	    
    },
    
    ChangedLocation : function(sel, url) {
        val = sel.options[sel.selectedIndex].value;
                
        if ( val == "" && sel.selectedIndex != 0 ) {
            sel.selectedIndex = 0;
            return;
        }

        if ( val == "" || val.indexOf("n-") == 0 || val.indexOf("r-") == 0 || val.indexOf("u-") == 0 ) {
            location.href = "/search/find.aspx?" + url + val;
            return;
        }

        LeftSearch.LocationEval(sel);
    },
    
    Arts : {
        // set the values from the querystring
        SetValues : function(qsobj) {
            qsobj = qsobj || location.search.toQueryParams();
            
            // area
            if ( qsobj["area"] ) $("select[name*=ArtLocation]").val(qsobj["area"]);
            // category
            if ( qsobj["int1"] ) $("select[name*=ArtCategoryID]").val(qsobj["int1"]);
            // feature
            if ( qsobj["feature"] ) $("select[name*=ArtFeature]").val(qsobj["feature"]);
        },
        
        Go : function() {
			var o = { 
				"area" : $("select[name*=ArtLocation]").val(),
				"int1" : $("select[name*=ArtCategoryID]").val(),
				"feature" : $("select[name*=ArtFeature]").val()
			};
			
			var oq = Object.toQueryString(o,"&");
			if ( oq ) location.href = "/search/find.aspx?secid=2&" + oq;
		}
    },
    
    Broadway : {
         // set the values from the querystring
        SetValues : function(qsobj) {
            qsobj = qsobj || location.search.toQueryParams();
            
            // category;
            if ( qsobj["feature"] ) $("select[name*=showCategory]").val(qsobj["feature"]);
            // price
            if ( qsobj["feature"] ) $("select[name*=showPrice]").val(qsobj["feature"]);
        },
        
        Go : function(sel) {
			val = sel.options[sel.selectedIndex].value;
			if ( val == "" ) return;
			location.href = "/broadway_tickets/" + val + "/editorial.aspx";
		},
		
		Go2 : function(sel) {
			val = sel.options[sel.selectedIndex].value;
			if ( val == "" ) return;
			location.href = "/search/find.aspx?secid=8&feature=" + val;
		}
    },
    
    
    Visitor : {
        Go : function( sel ) {
			if ( !sel || sel.selectedIndex == 0 ) return;
			val = sel.options[sel.selectedIndex].value;
			if ( val == "" ) return;
			location.href = "/visitor_guide/" + val + "/editorial.aspx";
		}   
    },
    
    YellowPage : {
         // set the values from the querystring
        SetValues : function(qsobj) {
            qsobj = qsobj || location.search.toQueryParams();
            
            // area
            if ( qsobj["area"] ) $("select[name*=YPArea]").val(qsobj["area"]);
            // name
            if ( qsobj["name"] ) $("select[name*=YPName]").val(qsobj["name"]);
        },
        
        Go : function() {
			var o = { 
				"area" : $("select[name*=YPArea]").val(),
				"name" : $("select[name*=YPName]").val()
			};
			if ( o.name == "" ) return;			
			location.href = "/search/find.aspx?secid=1&" + Object.toQueryString(o,"&");
		}   
    },
    
    Shop : {
        // set the values from the querystring
        SetValues : function(qsobj) {
            qsobj = qsobj || location.search.toQueryParams();
            
            // area
            if ( qsobj["area"] ) $("select[name*=ShopLocation]").val(qsobj["area"]);
            // category
            if ( qsobj["bdcid"] ) $("select[name*=ShopBdcID]").val(qsobj["bdcid"]);
            // feature
            if ( qsobj["feature"] ) $("select[name*=ShopFeature]").val(qsobj["feature"]);
            // name
            if ( qsobj["name"] ) $("select[name*=ShopName]").val(qsobj["name"]);
        },
        
        Go : function() {
			var o = { 
				"area" : $("select[name*=ShopLocation]").val(),
				"bdcid" : $("select[name*=ShopBdcID]").val(),
				"feature" : $("select[name*=ShopFeature]").val(),
				"name" : $("select[name*=ShopName]").val()
			};
			var oq = Object.toQueryString(o,"&");
			if ( oq ) location.href = "/search/find.aspx?secid=7&" + oq;
		}
    },
    
    Movies : {
		SetValues : function(qsobj) {
            qsobj = qsobj || location.search.toQueryParams();            
            // area
            if ( qsobj["area"] ) $("select[name*=MovieArea]").val(qsobj["area"]);
            // category
            if ( qsobj["category"] ) $("select[name*=MovieCategory]").val(qsobj["category"]);
            // sort by
            if ( qsobj["int1"] ) $("select[name*=MovieTopRated]").val(qsobj["int1"]);
        },
        
        Go : function(type, sel) {
			if ( sel.selectedIndex == 0 ) return;

			var val = sel.options[sel.selectedIndex].value;
			if ( type == "title" ) {
				location.href = "/movies/title/" + val + "/synopsis.aspx";
			} else if ( type == "location" ) {
				location.href = "/search/find.aspx?secid=28&area=" + val;
			} else if ( type == "category" ) {
				location.href = "/search/find.aspx?secid=28&category=" + escape(val);
			} else if ( type == "rating" ) {
				if ( sel.selectedIndex == 1 )
					location.href = "/search/find.aspx?secid=28&sort=editor&int1=1";
				else if ( sel.selectedIndex == 2 )
					location.href = "/search/find.aspx?secid=28&sort=editor&dir=asc&int1=2";
			}
		}
    },
    
    Nightlife : {
		SetValues : function(qsobj) {
            qsobj = qsobj || location.search.toQueryParams();            
            // area
            if ( qsobj["area"] ) $("select[name*=BarLocation]").val(qsobj["area"]);
            // bar category
            if ( qsobj["int1"] ) $("select[name*=BarCategoryID]").val(qsobj["int1"]);
            // from/to
            if ( qsobj["from"] ) $("select[name*=MusicEvtFrom]").val(qsobj["from"]);
            // genre
            if ( qsobj["genre"] ) $("select[name*=MusicEvtGenre]").val(qsobj["genre"]);
        },
        
        GoBars : function() {
			var o = { 
				"area" : $("select[name*=BarLocation]").val(),
				"int1" : $("select[name*=BarCategoryID]").val()
			};
			var oq = Object.toQueryString(o,"&");
			if ( oq ) location.href = "/search/find.aspx?secid=5&" + oq;
		},
		
		GoMusic : function() {
			var o = { 
				"genre" : $("select[name*=MusicEvtGenre]").val(),
				"from" : $("select[name*=MusicEvtFrom]").val(),
				"to" : $("select[name*=MusicEvtFrom]").val()
			};
			var oq = Object.toQueryString(o,"&");
			if ( oq ) location.href = "/search/find.aspx?secid=30&category=17&" + oq;
		}
		
    },
    
    Restaurants : {
        // set the values from the querystring
        SetValues : function(qsobj) {
            qsobj = qsobj || location.search.toQueryParams();
            
            // area
            if ( qsobj["area"] ) $("select[name*=RestoLocation]").val(qsobj["area"]);
            // cuisine
            if ( qsobj["int1"] ) $("select[name*=RestoCuisineID]").val(qsobj["int1"]);
            // price
            if ( qsobj["int4"] ) $("select[name*=RestoPriceID]").val(qsobj["int4"]);
            // feature
            if ( qsobj["feature"] ) $("select[name*=RestoFeature]").val(qsobj["feature"]);
        },
        
        Go : function() {
			var o = { 
				"area" : $("select[name*=RestoLocation]").val(),
				"int1" : $("select[name*=RestoCuisineID]").val(),
				"int4" : $("select[name*=RestoPriceID]").val(),
				"feature" : $("select[name*=RestoFeature]").val()
			};
			var oq = Object.toQueryString(o,"&");
			if ( oq ) location.href = "/search/find.aspx?secid=6&" + oq;
		}
    },
    
    
    Events : {        
        // set the values from the querystring
        SetValues : function(qsobj) {
            qsobj = qsobj || location.search.toQueryParams();
            
            // area
            if ( qsobj["area"] ) $("select[name*=EvtLocation]").val(qsobj["area"]);
            
            var cat = $("select[name*=EvtCategory]");
            //var gen = $("select[name*=EvtGenre]");
            // category
            if ( qsobj["category"] ) cat.val(qsobj["category"]);            
            // genre
//            if ( qsobj["genre"] ) {                
//                LeftSearch.Events.PopGenre(cat[0], gen[0]);
//                gen.val(qsobj["genre"]);
//                gen.parent().show();         
//            } else {
//				gen.parent().hide();
//            }
            // date from
            if ( qsobj["from"] ) $("select[name*=EvtFrom]").val(qsobj["from"]);            
            // date to
            if ( qsobj["to"] ) $("select[name*=EvtTo]").val(qsobj["to"]);
        },
        
//        PopGenre : function(cat, gen) {
//			var idx = cat.selectedIndex;
//			// get the jquery object of the genre select
//            genj = gen ? $(gen) : $("select[name*=EvtGenre]");
//            
//            // if select all, just hide the 
//            if ( idx == 0 )  {
//				genj.val( "" );
//				genj.parent().hide();
//				return;
//			}                     
//            
//            // clear all the options
//            genj.empty();
//            
//            // get the dom object
//            gen = gen || genj[0];
//            // add the options according to cat2genre
//            // cat2genre is genereted in LeftSearchEvents.ascx            
//            gen.options[0] = new Option("All Genres", "");
//            for ( i = 0; i < cat2genre[idx].length; i++ ) {
//				// id and name are separated with a tab character
//				var s = cat2genre[idx][i].toString().split("\t");
//				var gid = s[0]; var gname = s[1];
//				// ignore if name is empty				
//				if ( gname.strip() == "" ) continue;				
//				// add to the option list
//				gen.options[i+1] = new Option(gname, gid);
//            }
//            // make sure to show it
//            genj.parent().show();            
//        },
        
        CheckFromTo : function(where) {
			to = $("select[name*=EvtTo]");
			var from = $("select[name*=EvtFrom]");
			if ( Date.compare(from.val(), to.val()) > 0 ) {
				// from is after to
				if ( where == 'to' ) from.val( to.val() );
				else to.val( from.val() );
			}
        },
        
        Go : function() {
			var o = { 
				"area" : $("select[name*=EvtLocation]").val(),
				"category" : $("select[name*=EvtCategory]").val(),
				//"genre" : $("select[name*=EvtGenre]").val(),
				"from" : $("select[name*=EvtFrom]").val(),
				"to" : $("select[name*=EvtTo]").val()
			};
			var oq = Object.toQueryString(o,"&");
			
			if ( oq ) location.href = "/events/?secid=30&" + oq + "&int4=1#list";
		},
		
		searchByName : function(name) {
			location.href = "/events/?secid=30&sort=editor&dir=desc&int4=7&name=" + name + "#list";
		}
    }

} // LeftSearch


var FindRes = {

    changeExpand : function(id,ExpandM,ExpandP) 
    {

        if( $(id).html().replace(/&amp;/,"&") == ExpandP)
        {
            $(id).html(ExpandM);            
        }
        else
        {
            $(id).html(ExpandP);
        }
    },
    
    	overtestytab : function(tab) {

			tab.style.background = "#ffffff";
			var img = tab.getElementsByTagName("IMG")[0];
			img.src = "/image/spacer.gif";
			
			

	},
	
	outtestytab : function(tab) {
			tab.style.background = "transparent url(/image/tab_bckgrd.jpg) repeat-x scroll 0 0";
			var img = tab.getElementsByTagName("IMG")[0];
			img.src = "/image/tab_arrow.gif";
			}			
} // end FindRes