﻿
function AjaxFailed(XMLHttpRequest, textStatus, errorThrown) {
    alert("Error: " + XMLHttpRequest.responseText);
    writeToConsole("Error: " + XMLHttpRequest.responseText)

    

}


function GlobalPageMethod(fn, paramArray, successFn, errorFn, servicePage, async) {

    //Create list of parameters in the form:
    //{"paramName1":"paramValue1","paramName2":"paramValue2"}
    var paramList = '';
    if (paramArray.length > 0) {
        for (var i = 0; i < paramArray.length; i += 2) {
            if (paramList.length > 0) paramList += ',';
            paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
        }
    }

    paramList = '{' + paramList + '}';

    var url = servicePage + "/" + fn;

    //Call the page method
    $.ajax({
        type: "POST",
        url: url,
        contentType: "application/json; charset=utf-8",
        data: paramList,
        dataType: "json",
        success: successFn,
        timeout:1000000,
        error: errorFn, 
        async: async
    });

}

function formatJSONDate(jsonDate) {
    var newDate = new Date(parseInt(jsonDate.substr(6)));
    //var newDate = dateFormat(jsonDate, "mm/dd/yyyy");
    return newDate;

}

function ptiUser() {

    this.P_UID;
    this.FirstName;
    this.LastName;
    this.P_level;
    this.CallLeader;
}

function writeToConsole(mess) {
    if (window.console && window.console.firebug) {
        // warn user 
        console.log(mess);
    }
}



