﻿var divID;
function PageOperation(renderDivID, url) {
    divID = renderDivID;
    var data = '{}';
    ShowLoading($('[id$=' + divID + ']'));
    SendJsonCallToGetStatisticsContent(url, data, CheckGetStatisticsContentResponse, CheckGetStatisticsContentErrorResponse);
}

function CheckGetStatisticsContentErrorResponse(xmlReq) {
    var msg;
    // document.write(xmlReq.responseText);      
    if (xmlReq.responseText) {
        //var err = (typeof xmlReq.responseText) == 'string' ? eval('(' + xmlReq.responseText + ')') : xmlReq.responseText;
        var err = xmlReq.responseText;
        if (err)
            msg = err;
        else
            msg = "Could not contact the service";
    }
    $('[id$=divLoading]').hide();
    document.getElementById(divID).innerHTML = msg;
    return false;
}

function CheckGetStatisticsContentResponse(response) {

    var data = response;
    if (data == null || data.length == 0) {

        document.getElementById(divID).innerHTML = "Could not contact the service";
        return false;
    }
    var id = "#" + divID;
    //$('[id$=divLoading]').hide();
    document.getElementById(divID).innerHTML = $(data).find(id).html();
    return false;
}
function SendJsonCallToGetStatisticsContent(url, rawdata, onSuccess, onFalilure) {
    $.ajax(
		    {
		        type: 'POST',
		        url: url,
		        data: rawdata,
		        processData: true,
		        contentType: "application/json",
		        timeout: 10000,
		        dataType: "text/html",
		        success: onSuccess,
		        error: onFalilure
		    });
}


function RedirectToPage(url) {
    window.location = url;
}
