String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

var submitTicket = function(){

	$('TicketOs').value = BrowserDetect.OS;
	$('TicketFlashVersion').value = FlashDetect.raw;
	$('TicketBrowser').value = BrowserDetect.browser + ' ' + BrowserDetect.version;

	return true;
}

document.observe('dom:loaded', function(){
  Event.observe('TicketTicketCategoryId','change',function(){
    if ($F('TicketTicketCategoryId') != null && $F('TicketTicketCategoryId').length != 0) {
      $('helpdesk_form').hide();
      Effect.Appear('helpful_links');
      $('helpful_links').update('<div id="inner"><img src="/img/help_desk/help_links_loading.gif" id="loading" alt="Loading, please wait..." /></div>');
  
      new Ajax.Request('/help_desk/category/get_category_links_ajax/'+$F('TicketTicketCategoryId'),
      {
        method:'get',
        onSuccess: function(transport){     
        	var response = transport.responseText || "no response text";
        	
        	if (response.trim() == 'failed') {
        	  Effect.Fade('helpful_links');
            Effect.Appear('helpdesk_form');
        	} else {        	
            $('helpful_links').update('<div id="inner">' + response + '</div>');
            
            $('go_to_helpdesk_form').observe('click', function(event) {
              Effect.Fade('helpful_links');
              Effect.Appear('helpdesk_form');
              Event.stop(event);
            }); 
          }
        },
        onFailure: function(){ 
          alert('Something went wrong.  Please fill out the form with your issue, and we will be sure to get back to you.');
          Effect.Fade('helpful_links');
          Effect.Appear('helpdesk_form');
        }
      });
    }
  });
});

