var emp_purge_obj = null ;
var item_sort = new Array();
$(document).ready(function() 
{ 
	$('#emp-purge-tabs').tabs() ;
	
	$('input').css('marginTop', 0); 
	$('input').css('marginBottom',0);
	$('select').css('marginTop',0) ;
	$('select').css('marginBottom',0) ;	
	$('#btnEmpPurgeList').button().bind('click',filterEmpPurge) ;
	$('#btnEmpPurgeStart').button().bind('click',startEmpPurge) ;
}) ;
function sortEmpTable(elmt){
	var col = 0;
	var theader = document.getElementById('sbg-emp-purge-header').rows[0];
	for(i=0;i<theader.cells.length;i++){
		var strHTML = theader.cells[i].innerHTML;
		if(elmt.innerHTML == strHTML){
			col = i;
		}
	}
	
	var asc = item_sort[col];
	var tbody = document.getElementById('sbg-emp-purge-table');
	
	for(i = 0; i < tbody.rows[0].cells.length; i++){
		item_sort[i] = (col == i ? item_sort[i] * -1 : 1);
	}
	
    var rows = tbody.rows, rlen = rows.length, arr = new Array(), i, j, cells, clen;
	
    for(i = 1; i < rlen; i++){
		cells = rows[i].cells;
		clen = cells.length;
		arr[i-1] = new Array();
        for(j = 0; j < clen; j++){
			arr[i-1][j] = cells[j].innerHTML;
			cells[j].innerHTML = '';
        }
    }
    arr.sort(function(a, b){
		if(a[col] == b[col])
			return 0;
		if(!isNaN(a[col]) && !isNaN(b[col])){
			return ((parseInt(a[col]) > parseInt(b[col])) ? asc : -1*asc);
		}
        return ((a[col] > b[col]) ? asc : -1*asc);
    });
	
    for(i = 1; i < rlen; i++){
		cells = rows[i].cells;
		clen = cells.length;
        for(j = 0; j < clen; j++){
			cells[j].innerHTML = arr[i-1][j];
        }
    }

}
function filterEmpPurge() {
	var data = { "type": C_LIST,
					"company": $('#cobEmployeePurgeCompany').val(),
					"department": $('#cobEmployeePurgeDepartment').val(),
					"resign": $('#cobEmployeePurgeResign').val()} ;
	var url = "request.pzx?c=" + emp_purge_url + "&d=" + new Date().getTime() ;		
	callServer(url,"html",data,showEmpPurgeFilterList,emp_purge_obj) ;
}

function showEmpPurgeFilterList(obj,resp) {
	var fr = '<tr>' +
				'<td style="width:25px"></td>' +
				'<td style="width:50px;height:1px"></td>' +
				'<td style="width:100px"></td>' +
				'<td style="width:250px"></td>' +
				'<td style="width:250px"></td>' +
				'<td style="width:250px"></td>' +
			'</tr>';
	$('#sbg-emp-purge-table').html(fr + resp) ;
}

function showOutstanding(id) {
	showDialog("Outstanding Claims", $('#tableOutstanding' + id).html());
}
/*
function resizeEmpGrid(vis) {
	var h = $("#sbg-center-panel").outerHeight() - $("#emp-filter").outerHeight() - 55;
	if (vis)
		h = h - $('#sbg-emp-entry').outerHeight();
	$("div#sbg-emp-data").css("height", h +'px') ;
}*/

function startEmpPurge() {
	var purge_id = "";
	$('#sbg-emp-purge-table tr').each(function() { 
		id = $(this).find("td").eq(3).html() ;
		//alert(" id : " + id);
		if($("#chkEmpPurge" + id).prop('checked')){
			if (purge_id != "")
				purge_id += ",";
			purge_id += id;
		}
	});
	var data = { "type": "EMP_PURGE",
					"emp_ids": purge_id} ;
	var url = "request.pzx?c=" + emp_purge_url + "&d=" + new Date().getTime() ;		
	callServer(url,"json",data,showEmpPurge,emp_purge_obj) ;
}
function showEmpPurge(obj,resp) {
	if (resp.status == C_OK) {
		showDialog("System Message",resp.mesg) ;
		filterEmpPurge();
	}
	else {
		showDialog("System Message",resp.mesg) ;
	}
}

