$(document).ready( function() {
	exdate=new Date();
	exdate.setDate(exdate.getDate()+90);
	exdate = exdate.toUTCString();
	$("div#navNLI ul").buttonset();
	$("#aheader")
		.addClass("ui-widget-content ui-corner-all");
	$("#contentWrapper").addClass("ui-widget-content ui-corner-all");
	$("div.box1").addClass("ui-widget-content ui-corner-all");
	$("div.box1 > h2")
		.addClass("ui-state-default ui-state-active ui-corner-top")
		.css("cursor", "pointer")
		.click(function(e) {
			if($(e.target).is("div.box1 h2 a span")) {return;}
			$(this).toggleClass('ui-state-active').next().toggle('slow');
			return false;
		});
	$("div.box1 div h2")
        .addClass("ui-state-default ui-state-active");
	$("div.box1 > h2.hidden").toggleClass('ui-state-active').next().hide();
	$("table.style1 thead tr td, table.style1 thead tr th")
		.addClass("ui-state-default");
	$('#externalLinkDiv').dialog({
		autoOpen: false,
		width: 800,
		height: 500,
		modal: true
	});
	$.expr[':'].external = function(obj) {
		//alert(obj.hostname);
		return !obj.href.match(/^mailto\:/) && 
				(obj.hostname != location.hostname) &&
				obj.hostname != '';
	};
	$('ul.ui-tabs-nav>li>a, div.paginator>a').addClass("skipWindow");
	$('a:external, a.popup')
	    .not('.skipWindow, .fg-button').click(function() {
    		document.getElementById('externalLinkDiv')
    			.innerHTML = '<iframe height="99%" width="100%" src="' + 
    							this.href + '"></iframe>';
    		$('#externalLinkDiv').dialog('option', 'width', 850);
    		$('#externalLinkDiv').dialog('option', 'height', 600);
    		$('#externalLinkDiv').dialog('open');
    		return false;
    	});
	$(".styleTable tr:even").addClass("even")
});

if (typeof($.fn.dataTableExt) != "undefined") {
	$.fn.dataTableExt.oApi.fnReloadAjax = 
			function (oSettings, sNewSource, fnCallback, bStandingRedraw ) {
		if ( typeof sNewSource != 'undefined' && sNewSource != null )
		{
			oSettings.sAjaxSource = sNewSource;
		}
		this.oApi._fnProcessingDisplay( oSettings, true );
		var that = this;
		var iStart = oSettings._iDisplayStart;
		
		oSettings.fnServerData( oSettings.sAjaxSource, null, function(json) {
			/* Clear the old information from the table */
			that.oApi._fnClearTable( oSettings );
			
			/* Got the data - add it to the table */
			for ( var i=0 ; i<json.aaData.length ; i++ )
			{
				that.oApi._fnAddData( oSettings, json.aaData[i] );
			}
			
			oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
			that.fnDraw( that );
			
			if (typeof bStandingRedraw != 'undefined' && 
					bStandingRedraw === true)
			{
				oSettings._iDisplayStart = iStart;
				that.fnDraw( false );
			}
			
			that.oApi._fnProcessingDisplay( oSettings, false );
			
			/* Callback user function - for event handlers etc */
			if ( typeof fnCallback == 'function' && fnCallback != null )
			{
				fnCallback( oSettings );
			}
		} );
	}
}
