
		/* Custom filtering function which will filter data in column four between two values */
 $.fn.dataTableExt.afnFiltering.push(
 	function( oSettings, aData, iDataIndex ) {
 		var iMin = document.getElementById('min').value * 1;
 		var iMax = document.getElementById('max').value * 1;
 		var iCapacity = aData[5] == "-" ? 0 : aData[5]*1;
 		if ( iMin == "" && iMax == "" )
 		{
 			return true;
 		}
 		else if ( iMin == "" && iCapacity < iMax )
 		{
 			return true;
 		}
 		else if ( iMin < iCapacity && "" == iMax )
 		{
 			return true;
 		}
 		else if ( iMin < iCapacity && iCapacity < iMax )
 		{
 			return true;
 		}
 		return false;
 	}
 );
 
  $.fn.dataTableExt.afnFiltering.push(
 	function( oSettings, aData, iDataIndex ) {
 		var iMinWeight = document.getElementById('min-weight').value * 1;
 		var iMaxWeight = document.getElementById('max-weight').value * 1;
 		var iWeight = aData[11] == "-" ? 0 : aData[11]*1;
 		if ( iMinWeight == "" && iMaxWeight == "" )
 		{
 			return true;
 		}
 		else if ( iMinWeight == "" && iWeight < iMaxWeight )
 		{
 			return true;
 		}
 		else if ( iMinWeight < iWeight && "" == iMaxWeight )
 		{
 			return true;
 		}
 		else if ( iMinWeight < iWeight && iWeight < iMaxWeight )
 		{
 			return true;
 		}
 		return false;
 	}
 );
		
		
		var oTable;
			
			/* Formating function for row details */
			function fnFormatDetails ( nTr )
			{
				var iIndex = oTable.fnGetPosition( nTr );
				var aData = oTable.fnSettings().aoData[iIndex]._aData;
				
				var sOut = '<table class="details-table" cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">';
				sOut += '<tr class="row"><td>Konum:</td><td><strong>'+aData[3]+'</strong> | <strong>'+aData[2]+'</strong> | <a href="uyenin-konumu/id/'+aData[17]+'" class="iframe" target="_blank">Haritada Göster</a></td><td class="logo" rowspan="6">'+aData[13]+'</td></tr>';
				sOut += '<tr class="row"><td>Telefon:</td><td>'+aData[6]+'</td></tr>';
				sOut += '<tr class="row"><td>Faks:</td><td>'+aData[7]+'</td></tr>';
				sOut += '<tr class="row"><td>E-Posta:</td><td>'+aData[9]+'</td></tr>';
				sOut += '<tr class="row"><td>Web Sitesi:</td><td>'+aData[8]+'</td></tr>';
				sOut += '<tr class="row"><td>Kategoriler:</td><td>'+aData[14]+'</td></tr>';
				sOut += '</table>';
				
				return sOut;
			}
			
			
			
			$(document).ready(function() {
                
				/*
				 * Insert a 'details' column to the table
				 */
				var nCloneTh = document.createElement( 'th' );
				var nCloneTd = document.createElement( 'td' );
				nCloneTd.innerHTML = '<img src="themes/tudoksad/images/datatables/details_open.png">';
				nCloneTd.className = "center";
				
				$('#example thead tr').each( function () {
					this.insertBefore( nCloneTh, this.childNodes[0] );
				} );
				
				$('#example tbody tr').each( function () {
					this.insertBefore(  nCloneTd.cloneNode( true ), this.childNodes[0] );
				} );
				
				/*
				 * Initialse DataTables, with no sorting on the 'details' column
				 */
				 
				oTable = $('#example').dataTable( {
				"iDisplayLength": 12,
				"sPaginationType": "full_numbers",
		        "oLanguage": { "sUrl": "mysite/text/tr_TR.txt" },
				"sDom": 'T<"clear">lfrtip',


				
					"aoColumns": [
						{ "bSortable": false },
						null, {
			                 "bVisible":    false }, null, null, null, { "bSearchable": false,
			                 "bVisible":    false }, { "bSearchable": false,
			                 "bVisible":    false }, { "bSearchable": false,
			                 "bVisible":    false }, { "bSearchable": false,
			                 "bVisible":    false }, null, null, null, { "bSearchable": false,
			                 "bVisible":    false }, { "bVisible": false }, { "bSearchable": false,
			                 "bVisible":    false }, { "bSearchable": false,
			                 "bVisible":    false }, { "bSearchable": false,
			                 "bVisible":    false }
					],
					"aaSorting": [[1, 'asc']]
					
				});
				
$('#member_filter').change(function() {
oTable.fnFilter( $(this).val() );
} );


				
			     	$('#min').keyup( function() { oTable.fnDraw(); } );
 	$('#max').keyup( function() { oTable.fnDraw(); } );
				     	$('#min-weight').keyup( function() { oTable.fnDraw(); } );
 	$('#max-weight').keyup( function() { oTable.fnDraw(); } );



				
				/* Add event listener for opening and closing details
				 * Note that the indicator for showing which row is open is not controlled by DataTables,
				 * rather it is done here
				 */
				$('td img', oTable.fnGetNodes() ).each( function () {
					$(this).click( function () {
						var nTr = this.parentNode.parentNode;
						if ( this.src.match('details_close') )
						{
							/* This row is already open - close it */
							this.src = "themes/tudoksad/images/datatables/details_open.png";
							oTable.fnClose( nTr );
						}
						else
						{
							/* Open this row */
							this.src = "themes/tudoksad/images/datatables/details_close.png";
							oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
						}
					} );
				} );
			} );
