﻿// JScript File

//SINGLETON
var SAjax = 
{          
    initiated:false,
    initiate: function()
    {
        $.ajaxSetup(
            {
                type:"POST",
                dataType:"xml",
                cache:false,
                error:function(XMLHttpRequest, textStatus, errorThrown)
                {
                    
                }
            }
        );
        this.initiated = true;
    },
    
    // senddata: data to be sent e.g. {'op':'getcoursesdetails'}
    // callbackfunction: function to be called when data is successfully loaded
        fromAdmin : function(senddata, handler)
        {
            if(!this.initiated)
            {
                this.initiate();
            }
            $.ajax({
                    url:'Operations/Admin.aspx',
                    data:senddata,
                    success:function(data, textStatus)
                    {
                        handler.handle(data, textStatus);
                    },
                    error:function(httprequest, testStatus, errorThrown)
                    {
                    }
                    
            });            
        },
        fromData : function(senddata, handler)
        {
            if(!this.initiated)
            {
                this.initiate();
            }
            $.ajax({
                    url:'Operations/Data.aspx',
                    data:senddata,
                    success:function(data, textStatus)
                    {
                        handler.handle(data, textStatus);
                    },
                    error:function(httprequest, testStatus, errorThrown)
                    {
                    }
            });
        },
        fromGeneric : function(senddata, handler)
        {
            if(!this.initiated)
            {
                this.initiate();
            }
            $.ajax(
                {
                    url:'Operations/Default.aspx',
                    data:senddata,
                    success:function(data, textStatus)
                    {
                        handler.handle(data, textStatus);
                    },
                    error:function(httprequest, testStatus, errorThrown)
                    {
                    }
                }
            );
        }        
}

    
