jQuery.fn.dataTableExt.oSort['fhf-deal-status-asc']  = function(x,y) {

	var fhf_status = [];
	fhf_status["10"]="First Contact";
	fhf_status["20"]="Pre-approval Complete";
	fhf_status["30"]="Dossier Received";
	fhf_status["40"]="Dossier sent to bank";
	fhf_status["50"]="Verbal OK from bank";
	fhf_status["60"]="Offer sent to client";
	fhf_status["70"]="Offer correctly returned to bank";
	fhf_status["80"]="Funds ready for release";
	fhf_status["90"]="Act of sale complete";
	fhf_status["92"]="Dossier archived";
	fhf_status["95"]="Dossier complete";
	fhf_status["97"]="Dossier on hold - client";
	fhf_status["99"]="Dossier abandoned";
	
	a=0;
	b=0;
	
	for (var name in fhf_status) {
		if (fhf_status[name] == x) {
			a = name; 
		}  
		if (fhf_status[name] == y) {
			b = name; 
		}
	}
	
	return ((a < b) ? -1 : ((a > b) ?  1 : 0));

};

jQuery.fn.dataTableExt.oSort['fhf-deal-status-desc']  = function(x,y) {

	var fhf_status = [];
	fhf_status["10"]="First Contact";
	fhf_status["20"]="Pre-approval Complete";
	fhf_status["30"]="Dossier Received";
	fhf_status["40"]="Dossier sent to bank";
	fhf_status["50"]="Verbal OK from bank";
	fhf_status["60"]="Offer sent to client";
	fhf_status["70"]="Offer correctly returned to bank";
	fhf_status["80"]="Funds ready for release";
	fhf_status["90"]="Act of sale complete";
	fhf_status["92"]="Dossier archived";
	fhf_status["95"]="Dossier complete";
	fhf_status["97"]="Dossier on hold - client";
	fhf_status["99"]="Dossier abandoned";
	
	a=0;
	b=0;
	
	for (var name in fhf_status) {
		if (fhf_status[name] == x) {
			a = name; 
		}  
		if (fhf_status[name] == y) {
			b = name; 
		}
	}
	
	return ((a < b) ? 1 : ((a > b) ?  -1 : 0));

};

$(document).ready(function() {
		
	if ($('#promoterTable').length > 0) {

		oTable = $('#promoterTable').dataTable( {
			"sDom": '<"formControls">T<"clear"><"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>',
			"bJQueryUI": true,
			"sPaginationType": "full_numbers" ,
			"aoColumns": [
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				{ "sClass" : "rptProgram"},
				null,
				{ "sType": "fhf-deal-status"},
				{ "sClass" : "rptComment"},
				null
			]
	
		} );	
	
		//Move checkbox closer to form controls
		tmp = $("#formControlInit").html();
		$("#formControlInit").remove();
		$("div.formControls").append(tmp);
		//Submit handler
		$("#IncludeCompleted").click(function () {
			$("#deal_status_form").submit();
		});
		
		//Implement fixed head on table
		new FixedHeader(oTable);
		
		//Trim comments to 25 chars & create tooltip
		nNodes = $(oTable.fnGetNodes()).find(".rptComment");
		nNodes.each(function () {
			if ($(this).html() > "" && $(this).html().length > 25 ) {
				//id=$(this).parent().attr("id")+"_ttComment";
				//$("#rptToolTips").append("<div class='tooltip' id='"+id+"'>"+$(this).html()+"</div");
				this.setAttribute('title',$(this).html());
				$(this).html($(this).html().substring(0,25)+"...");
				//Add tooltip
				$(this).tooltip();
			}
		});
		
		//Trim program to 25 chars & create tooltip
		nNodes = $(oTable.fnGetNodes()).find(".rptProgram");
		nNodes.each(function () {
			if ($(this).html() > "" && $(this).html().length > 25 ) {
				//id=$(this).parent().attr("id")+"_ttComment";
				//$("#rptToolTips").append("<div class='tooltip' id='"+id+"'>"+$(this).html()+"</div");
				this.setAttribute('title',$(this).html());
				$(this).html($(this).html().substring(0,25)+"...");
				//Add tooltip
				$(this).tooltip();
			}
		});
		

	}		

});