$(document).ready(function() 
{ 
	$('#btnResetPasswordHistoryReportView').button().bind('click',viewResetPasswordHistoryReport) ;
	$('#btnResetPasswordHistoryReportPrint').button().bind('click',printResetPasswordHistoryReport) ;
	$('#btnResetPasswordHistoryReportExport').button().bind('click',exportResetPasswordHistoryReport) ;
    
	var dteopt = {
		dateFormat: "dd/mm/yy",
		showOn: "button",
		buttonImage: "image/calendar.gif",
		buttonImageOnly: true
	};
    
	$('#txtResetPasswordHistoryReportDateStart').datepicker(dteopt) ;
	$('#txtResetPasswordHistoryReportDateEnd').datepicker(dteopt) ;
    
    var dLast = 30;
	var date = new Date();
	var firstDay = new Date();
	var lastDay = new Date();
	var todayDate = new Date();
	var startDate = new Date(new Date().setDate(todayDate.getDate()-dLast));
	firstDay.setFullYear(date.getFullYear(), date.getMonth(), 1);
	lastDay.setFullYear(date.getFullYear(), date.getMonth() + 1, 0);
    $('#txtResetPasswordHistoryReportDateStart').val((startDate.getDate() <= 9 ? "0" + startDate.getDate() : startDate.getDate()) + "/" + (startDate.getMonth()+1 <= 9 ? "0" + (startDate.getMonth()+1) : (startDate.getMonth()+1) ) + "/" + startDate.getFullYear());
	$('#txtResetPasswordHistoryReportDateEnd').val((todayDate.getDate() <= 9 ? "0" + todayDate.getDate() : todayDate.getDate()) + "/" + (todayDate.getMonth()+1 <= 9 ? "0" + (todayDate.getMonth()+1) : (todayDate.getMonth()+1) ) + "/" + todayDate.getFullYear());
	
	$(window).resize(resizeResetPasswordHistoryReportGrid) ;
	resizeResetPasswordHistoryReportGrid() ;
}) ;
function resizeResetPasswordHistoryReportGrid() {
	
	var h = $("#sbg-center-panel").outerHeight() - $("#sbg-reset-password-history-report-option").outerHeight() - 55;
	$("div#sbg-reset-password-history-report-data").css("height", h +'px') ;		
}
function exportResetPasswordHistoryReport() {
	if (validateResetPasswordHistoryReport()) {
		var url = "report.pzx?c=" + reset_password_history_report_url + "&d=" + new Date().getTime() +
                "&co=" + $('#cobResetPasswordHistoryReportUser').val() + 
                "&dp=" + $('#cobResetPasswordHistoryReportUserTarget').val() +
                "&tn=" + $('#cobResetPasswordHistoryReportType').val() + 
                "&dt=" + $('#txtResetPasswordHistoryReportDateStart').val() + 
                "&dtend=" + $('#txtResetPasswordHistoryReportDateEnd').val() + 
            "&t=" + C_EXPORT ;
		showReport(url); ;
	}
}
function printResetPasswordHistoryReport() {
	var url = "report.pzx?c=" + reset_password_history_report_url + "&d=" + new Date().getTime() +
                "&co=" + $('#cobResetPasswordHistoryReportUser').val() + 
                "&dp=" + $('#cobResetPasswordHistoryReportUserTarget').val() +
                "&tn=" + $('#cobResetPasswordHistoryReportType').val() + 
                "&dt=" + $('#txtResetPasswordHistoryReportDateStart').val() + 
                "&dtend=" + $('#txtResetPasswordHistoryReportDateEnd').val() + 
                "&t=" + C_REPORT ;
	showReport(url) ;
}
function viewResetPasswordHistoryReport() {
	if (validateResetPasswordHistoryReport()) {
        var data = { "type": C_LIST, 
                "user"              : $('#cobResetPasswordHistoryReportUser').val(), 
                "user_target"       : $('#cobResetPasswordHistoryReportUserTarget').val(), 
                "reset_type"        : $('#cobResetPasswordHistoryReportType').val(), 
                "start"             : $('#txtResetPasswordHistoryReportDateStart').val(), 
                "end"               : $('#txtResetPasswordHistoryReportDateEnd').val()  } ;
        var url = "request.pzx?c=" + reset_password_history_report_url + "&d=" + new Date().getTime() ;
        callServer(url,"html",data,showResetPasswordHistoryReport) ;
    }
}
function validateResetPasswordHistoryReport() {
	return true ;
}
function showResetPasswordHistoryReport(obj,resp) {
	var fr = '' ;
	$('#sbg-reset-password-history-report-table').html(fr + resp) ;
}