﻿function jax(Ddata, Uurl, block, Ssuccess)
{
    if (Ddata == null) {Ddata = {};}
    
    if (block)
    {
        Loading(true);
    }

    $.ajax({
        url: Uurl,
        cache: false,
        type: "POST",
        data: Ddata,
        dataType: "xml", 
        success: function(msg) { this.newmsg = msg; },
        complete: function(XMLHttpRequest, textStatus)
        { 
            if (XMLHttpRequest.status != 200 & XMLHttpRequest.status != 500 & XMLHttpRequest.status != 503)
            {
                if (XMLHttpRequest.status == 12031)
                {
                    alert('We have encountered an error thats unique to certain older versions of Internet Explorer 6 please upgrade your browser or wait 300 seconds and try again.')
                }
                else if (XMLHttpRequest.status == 403)
                {
                    alert('Sorry too many people are logged into the system right now (development server can only handle 3 concurrent logons)');
                } 
                else
                {
                    alert(XMLHttpRequest.status);
                }
            }
            else
            { 
                Ssuccess(this.newmsg); 
                 if (block)
                 {
                    Loading(false);
                 }
            }  
        },
        error: function(XMLHttpRequest, textStatus, errorThrown)
        { 
            if (XMLHttpRequest.status == 503) //nizzote error
            {
                alert(XMLHttpRequest.responseText);
            }
            else if (XMLHttpRequest.status != 200 && XMLHttpRequest.status != 403 && XMLHttpRequest.status != 0 && XMLHttpRequest.status != 12031)
            {
                if (XMLHttpRequest.responseText.indexOf("Could not load file or assembly") > -1)
                { 
                    alert("The server is being updated, please wait 5 seconds before submitting anything.");  
                }
                else
                { 
                    alert(XMLHttpRequest.getAllResponseHeaders() + "\n\n" + XMLHttpRequest.responseText);
//                    $.ajax({
//                        url: "/a/logerror.asmx/SaveErrors",
//                        cache: false,
//                        type: "POST",
//                        data: { errorData: XMLHttpRequest.responseText, LocInfo: XMLHttpRequest.getAllResponseHeaders(), ErrorThrown: errorThrown, TextStatus: textStatus, request: getProperties(Ddata), url: Uurl },
//                        success: function(msg) { eval($('string', msg).text()); },
//                        error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.responseText) }
//                    }); 
                }
            }

        }

    });
}


function getHTML(Ddata, Uurl, block, Ssuccess)
{
    if (Ddata == null) {Ddata = {};}
    
    if (block)
    {
        Loading(true);
    }
    
    $.ajax({
      url: Uurl, 
      success: function(msg) { this.newmsg = msg; },
      complete: function(XMLHttpRequest, textStatus)
        { 
            if (XMLHttpRequest.status != 200 & XMLHttpRequest.status != 500 & XMLHttpRequest.status != 503)
            {
                if (XMLHttpRequest.status == 12031)
                {
                    alert('We have encountered an error thats unique to certain older versions of Internet Explorer 6 please upgrade your browser or wait 300 seconds and try again.')
                }
                else if (XMLHttpRequest.status == 403)
                {
                    alert('Sorry too many people are logged into the system right now (development server can only handle 3 concurrent logons)');
                } 
                else
                {
                    alert(XMLHttpRequest.status);
                }
            }
            else
            { 
                Ssuccess(this.newmsg); 
                 if (block)
                 {
                    Loading(false);
                 }
            }  
        },
      error: function(XMLHttpRequest, textStatus, errorThrown)
      {
        if (XMLHttpRequest.status == 503) //nizzote error
        {
            alert(XMLHttpRequest.responseText);
        }
      }
    });

};

function getProperties(obj) {
  var i, v;
  var count = 0;
  var props = [];
  if (typeof(obj) === 'object') {
    for (i in obj) {
      v = obj[i];
      if (v !== undefined && typeof(v) !== 'function') {
        if (i != "undefined")
        {
           props[count] = i;
           count++;
        }
      }
    }
  }
  
  var allprops;
  for (i in props)
  {
    if (i != "undefined")
    {
        allprops += "\n\r" + props[i] + ": " + obj[props[i]];
    }
  } 
  
  return allprops;
};

var loading = 0; 
function Loading(newJob)
{
    //future block screen;

    var oldLoading = loading;
    if (newJob)
    {loading++;} else {loading--;}
    
    if (loading == 1 && oldLoading == 0)
    { $("#loading").show(); }
    else if (loading == 0)
    { 
        $("#loading").fadeOut();
    }
}