function attachQueryBarListener(){
	$('current_time').value = fmtDate("%Y%m%dT%H%M%S");
  $('demoQuery').observe('submit', function(e){
    e.stop();
    new Ajax.Request('/demo', {
      method: 'get',
      parameters: Form.serialize(this),
      onSuccess: function(transport) {
        $('jaxContent').innerHTML = transport.responseText;
        attachQueryBarListener();
				$$('#demoQuery input')[0].select();
      }
    });
  });
}

function jaxLinkJs(href){
		new Effect.Fade('jaxContent', {duration: 0.2});

		new Ajax.Request(href, {method: 'get', onSuccess: function(transport) {
			window.appearing = transport.responseText;	// cry me a river.
			window.busyfading = setInterval("if ($('jaxContent').style.display == 'none') { $('jaxContent').innerHTML = window.appearing; new Effect.Appear('jaxContent', {duration: 0.8}); if($$('#demoQuery input')[0]){attachQueryBarListener(); setTimeout(\"$$('#demoQuery input')[0].select();\",100)}; clearInterval(window.busyfading) }",50);
		}});
} 

function jaxLinkJs_nofade(href){
	$('jaxContent').style.display='none';

	new Ajax.Request(href, {method: 'get', onSuccess: function(transport) {
		$('jaxContent').innerHTML = transport.responseText;
		new Effect.Appear('jaxContent', {duration: 0.8});
	}});
}


// Note this relies on Prototype's toPaddedString method
// Full year = %Y; month = %m; day = %d; hour = %H; minute = %M; second = %S
function fmtDate(fmt){
	var today = new Date();
	fmt = fmt.replace(/%Y/, today.getFullYear());
	fmt = fmt.replace(/%m/, (today.getMonth() + 1).toPaddedString(2));
	fmt = fmt.replace(/%d/, today.getDate().toPaddedString(2));
	fmt = fmt.replace(/%H/, today.getHours().toPaddedString(2));
	fmt = fmt.replace(/%M/, today.getMinutes().toPaddedString(2));
	fmt = fmt.replace(/%S/, today.getSeconds().toPaddedString(2));
	return fmt
}
	
/** ------------------- DEPRECATED ---------------------
**		String.prototype.displayXML = function () {                                       
**			return(this.replace(/<\?.+\?>/,'').replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;').replace(/\n/g,'<br>').replace(/\s/g,'&nbsp;&nbsp;'));                                                                     
**		}
**		
**		// see note at NiHelper#get_example_query //
**		var qEx = new Array(
**			"Pay credit card bill on the 22nd of each month",
**		 	"Go to the mall tomorrow at noon",
**		 	"Eat lunch with maria at 2 on friday",
**		 	"Conference call today at 4pm",
**		 	"Movie this saturday from 2-3:30 and 5 to 6:30"
**		);
**		
**		function randomizeMessage(){
**			$('qEx').innerHTML = qEx[Math.floor(Math.random()*5)];
**		}
** ------------------------------------------------------ */

