﻿function PageMethod(pagePath, fn, paramArray, successFn, errorFn)
{
  var paramList = Stringify(paramArray);
  //Call the current page
  if ((paramList != null) && (paramList.length > 0))
  {
    $.ajax({
      type: "POST",
      url: pagePath + "/" + fn,
      contentType: "application/json; charset=utf-8",
      data: paramList,
      dataType: "json",
      success: successFn
    });
  }
  else
  {
    $.ajax({
      type: "POST",
      url: pagePath + "/" + fn,
      beforeSend: function(xhr) { xhr.setRequestHeader("Content-type", "application/json; charset=utf-8"); },
      dataType: "json",
      success: successFn
    });
  }
}


function Stringify(paramArray)
{
  var result = '';
  for (var i=0; i<paramArray.length; i+=2)
  {
    if (result.length > 0)
      result += ',';
    result += '"' + paramArray[i] + '":"' + paramArray[i+1] + '"';
  }
  result = '{' + result + '}';
  return result;
}