function CJL_RegisterEvent(elem, type, listener, useCapture, noAutoStart)
{
   var proto = arguments.callee.prototype;

   this.e = elem;
   this.type = type;
   this.cap = useCapture;
   this.l = listener;


   proto.start = function()
   {
      if( this.e.attachEvent )
      {
         this.e.attachEvent("on" + this.type, this.l);
      }
      else if( this.e.addEventListener )
      {
         this.e.addEventListener(this.type, this.l, this.cap);
      }
   }

   if( ! noAutoStart )
   {
      this.start(elem, type, listener);
   }

   proto.stop = function()
   {
      if( this.e.detachEvent )
      {
          this.e.detachEvent("on" + this.type, this.l);
      }
      else if( this.e.removeEventListener )
      {
          this.e.removeEventListener(this.type, this.l, this.cap);
      }
   }
}

function attachBehaviors()  {
	if  ($('form'))  {
	  $('form').setAttribute("onsubmit", "return false;");
  }
	if  ($('commentform'))  {
	  $('commentform').setAttribute("onsubmit", "return false;");
  }  
	$('searchbox').setAttribute("autocomplete", "off");
	$('searchbox').value = '';

	new CJL_RegisterEvent($('searchbox'), "keypress", initSearch);
}

function initSearch() {
  var t = window.setTimeout("liveSearch()",200);
}

function liveSearch()  
{
	$('spinner').style.visibility = 'visible';
  searchTerm = $('searchbox').value;
  searchType = $('searchtype').value;
  userID = $('user_id').value;
  
  pars = 'search=' + searchTerm + '&searchtype=' + searchType + '&user_id=' + userID;
  theUrl = 'search.php';
  var searchNow = new Ajax.Updater('searchresults', theUrl, {method: 'post', parameters: pars, onComplete: finishSearch});	
}

function finishSearch()  {
	theResults = $('searchresults');
	if (theResults.innerHTML != '')  {
	result = new Effect.Appear('searchresults', {duration:0.5});
	  }
	else  {
		result = new Effect.Fade('searchresults', {duration:0.5});
	}
	  $('spinner').style.visibility = 'hidden';
}

function getHTML(p_nPID, p_bEvent, p_bAlert, p_sAlertType, p_sMoreButton, p_nUserID)
{   
  if (p_bAlert == "TRUE") {
    var url = 'http://www.beatfreax.com/alert.php';
	  var pars = 'type='+p_sAlertType+'&user_id='+p_nUserID;
	  var plus = 'http://www.beatfreax.com/images/plus.gif';
    var minus = 'http://www.beatfreax.com/images/minus.gif';
    
    if (document.getElementById(p_sMoreButton).src == plus) {
      document.getElementById(p_sMoreButton).src = minus;
    } else {
      document.getElementById(p_sMoreButton).src = plus;
    }
	  
	  var myAjax = new Ajax.Updater(
	  { success: 'placeholder'+p_sAlertType}, url, 
	  { method: 'get', parameters: pars, onComplete: doEffect(p_sAlertType) });
	  
  } else  if (p_bEvent) {
    var url = 'http://www.beatfreax.com/festivalinfo.php';
	  var pars = 'party_id='+p_nPID;
	  
	  var myAjax = new Ajax.Updater(
	  { success: 'placeholder'+p_nPID}, url, 
	  { method: 'get', parameters: pars, onComplete: doEffect(p_nPID) });
	  
	}
}

function getCityList(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	
	if(countryCode.length>0){
	  var url = 'get_cities.php';
	  var pars = 'country_id='+countryCode;

		var myAjax = new Ajax.Updater(
	  { success: 'city_select' }, 
	  url, 
	  { 
	    method: 'get', 
	    parameters: pars
	  });
	}
}

function getLocationList(sel)
{
	var cityCode = sel.options[sel.selectedIndex].value;
	
	if(cityCode.length>0){
	  var url = 'get_locations.php';
	  var pars = 'city_id='+cityCode;
	  
		var myAjax = new Ajax.Updater(
	  { success: 'location_select'}, url, 
	  { method: 'get', parameters: pars });
	}
}

function doEffect(p_nPID)
{   
  sPlaceholder = 'placeholder'+p_nPID;
  new Effect.toggle(sPlaceholder);
}