   function gup( name )
   {
       name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
       var regexS = "[\\?&]"+name+"=([^&#]*)";
       var regex = new RegExp( regexS );
       var results = regex.exec( window.location.href );
       if( results == null )
           return "";
       else
           return results[1];
   }

   function SetOrder(Sort)
   {
       what = GetWhat();
       where = GetWhere() ;
       within = GetWithin ( );
       type = GetType();
       Category = GetCat();
       if ( !Category ) Category = "ALL";

       var Date = gup ('date');

       if ( Date == "" )
       {
            Date = 'future';
       }

       loc = 'events.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&'+ 'type=' + type + '&' + 'date=' + Date + '&' + 'sort=' + Sort + '&' + 'within=' + within;
       location.href=loc;
   }

   function SetDate(Date)
   {
       what = GetWhat();
       where = GetWhere() ;
       within = GetWithin (); 
       type = GetType();
       Category = GetCat();
       if ( !Category ) Category = "ALL";

       var Sort = gup ('sort');

       if ( Date == "" )
       {
            Date = 'future';
       }

       if ( Sort == "" )
       {
            Sort = 'sd';
       }

       loc = 'events.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' + 'type=' + type + '&' + 'date=' + Date + '&' + 'sort=' + Sort + '&' + 'within=' + within;

       location.href=loc;
   }

   function SetOrg()
   {
       what = GetWhat();
       where = GetWhere();
       var Sort = gup ('sort');

       if ( Date == "" )
       {
            Date = 'future';
       }

       if ( Sort == "" )
       {
            Sort = 'sd';
       }

       loc = 'organizers.php?location=' + where + '&' + 'keywords=' + what;

       location.href=loc;
   }

   function SetBus()
   {
       what = GetWhat();
       where = GetWhere();
       var Sort = gup ('sort');

       if ( Date == "" )
       {
            Date = 'future';
       }

       if ( Sort == "" )
       {
            Sort = 'sd';
       }

       loc = 'businesses.php?location=' + where + '&' + 'keywords=' + what;

       location.href=loc;
   }

   function SetVen()
   {
       what = GetWhat();
       where = GetWhere();
       var Sort = gup ('sort');

       if ( Date == "" )
       {
            Date = 'future';
       }

       if ( Sort == "" )
       {
            Sort = 'sd';
       }

       loc = 'venues.php?location=' + where + '&' + 'keywords=' + what;

       location.href=loc;
   }

   function SetWithin()
   {
       what = GetWhat();
       where = GetWhere() ;
       within = GetWithin();

       var table = GetTable();
       var Sort = gup ('sort');
       var Date = gup ('date');

       if ( ( table != 'sponsors' ) && ( table != 'speakers' ) && ( table != 'members' ) ) Category = GetCat();  
       if ( ( table != 'sponsors' ) && ( table != 'speakers' ) && ( table != 'members' ) ) type = GetType(); 

       if ( Date == "" )
       {
            Date = 'future';
       }

       if ( Sort == "" )
       {
            Sort = 'sd';
       }

       if ( table == 'events' ) loc = 'events.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' + 'type=' + type + '&' + 'date=' + Date + '&' + 'sort=' + Sort + '&' + 'within=' + within;

       if ( table == 'organizers' ) loc = 'organizers.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' + 'type=' + type + '&' + 'within=' + within;

       if ( table == 'venues' ) loc = 'venues.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&'+ 'type=' + type + '&' + 'within=' + within;

       if ( table == 'sponsors' ) loc = 'sponsors.php?keywords=' + what + '&' + 'location=' + where + '&' + 'within=' + within;

       if ( table == 'speakers' ) loc = 'speakers.php?keywords=' + what + '&' + 'location=' + where + '&' + 'within=' + within; 

       if ( table == 'members' ) loc = 'businesses.php?keywords=' + what + '&' + 'location=' + where + '&' + 'within=' + within;

       location.href=loc;
   }

   function SetLoc(Category)
   {
       what = GetWhat();
       where = GetWhere() ;

       var Date = 'future';
       var Sort = 'sd';
       var within = '75mi';

       loc = 'events.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' + 'date=' + Date + '&' + 'sort=' + Sort + '&' + 'within=' + within;

       location.href=loc;
   }

   function SetType(Type)
   {
       what = GetWhat();
       where = GetWhere() ;
       within = GetWithin();
       Category = GetCat();
       if ( !Category ) Category = "ALL"; 
       var table = GetTable();
       if ( Type ) table = 'events';
       if ( !Type ) Type = GetType();
       

       var Sort = gup ('sort');
       var Date = gup ('date');

       if ( Date == "" )
       {
            Date = 'future';
       }

       if ( Sort == "" )
       {
            Sort = 'sd';
       }

       if ( table == 'events'  ) loc = 'events.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' + 'type=' + Type + '&' + 'date=' + Date + '&' + 'sort=' + Sort + '&' + 'within=' + within;

       if ( table == 'organizers' ) loc = 'organizers.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' + 'type=' + Type + '&' + 'within=' + within;

       if ( table == 'venues' ) loc = 'venues.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' + 'type=' + type + '&' + 'within=' + within;

       if ( table == 'sponsors' ) loc = 'sponsors.php?keywords=' + what + '&' + 'location=' + where + '&' + 'within=' + within;

       if ( table == 'speakers' ) loc = 'speakers.php?keywords=' + what + '&' + 'location=' + where + '&' + 'within=' + within;

       location.href=loc;
   }

   function SetCat(Category)
   {
       what = GetWhat();
       where = GetWhere() ;
       within = GetWithin();
       Type   = 'ALL';
       var table = GetTable();
       if ( Category ) table = 'events';
       if ( !Category ) Category = GetCat();
       if ( !Category ) Category = "ALL";

       var Sort = gup ('sort');
       var Date = gup ('date');

       if ( Date == "" )
       {
            Date = 'future';
       }

       if ( Sort == "" )
       {
            Sort = 'sd';
       }

       if ( table == 'events'  ) loc = 'events.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' + 'type=' + Type + '&' + 'date=' + Date + '&' + 'sort=' + Sort + '&' + 'within=' + within;

       if ( table == 'organizers' ) loc = 'organizers.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' +'type=' + Type + '&' + 'within=' + within;

       if ( table == 'venues' ) loc = 'venues.php?keywords=' + what + '&' + 'location=' + where + '&' + 'category=' + Category + '&' + 'type=' + type + '&' + 'within=' + within;

       if ( table == 'sponsors' ) loc = 'sponsors.php?keywords=' + what + '&' + 'location=' + where + '&' + 'within=' + within;

       if ( table == 'speakers' ) loc = 'speakers.php?keywords=' + what + '&' + 'location=' + where + '&' + 'within=' + within;

       location.href=loc;
   }


   function GetType ( )
   {
            for( var i = 0; i < document.f.type.options.length; i++ )
            {
                 if ( document.f.type.options[i].selected == true )
                      type = document.f.type.options[i].value;
            }
            return type;
   }

   function GetCat ( )
   {
            for( var i = 0; i < document.f.category.options.length; i++ )
            {
                 if ( document.f.category.options[i].selected == true )
                      category = document.f.category.options[i].value;
            }
            return category;
   }

   function GetWithin ( )
   {
            for( var i = 0; i < document.f.within.options.length; i++ )
            {
                 if ( document.f.within.options[i].selected == true )
                      within = document.f.within.options[i].value;
            }
            return within;
   } 

   function GetWhat()
   {
       what = document.f.keywords.value.replace(/^\s+|\s+$/g,"");
       return what;
   }

   function GetLoc()
   {
        where = document.f.location.value;
        return where; 
   }

   function GetWhere()
   {
       where = document.f.location.value.replace(/^\s+|\s+$/g,"");
       return where;
   }

   function Subscribe(subtype)
   {
       str = window.location.href;
       index = str.lastIndexOf("?");
       arg = str.substring(index);
       if ( subtype == "rss" ) loc = '/events/rss/rss.php' + arg;
       location.href=loc;
   }

function MM_openBrWindow(theURL,winName,features)
{
         newWin = window.open(theURL,winName,features);
         newWin.moveTo(550,500)
}

function setLocation(code)
{
  f.location.value = code;
  f.place.value = code
}

function GetTable() 
{
         var query = location.href;
         var vars = query.split("/");
         page = vars[3];
         var parts = page.split(".");
         if ( parts[0] == "businesses" ) parts[0]="members";
         return parts[0];
}
