/**
@author Templarian
@version 0.4
*/

/**
GETS URL PARM OFF LAST JS FILE
*/
var t_scripts = document.getElementsByTagName('script');
var t_path = t_scripts[t_scripts.length - 1].src.lastIndexOf('=');
if(t_path != -1)
{
    t_path = decodeURIComponent(t_scripts[t_scripts.length - 1].src.substr(t_path + 1));
}
else
{
    alert("Path to external File not found!");
}
/**
Submit(function/action, [input_id1, input_id2, ...])
@param function/action {string} Name of ??? + AJAX() for return function and ?action=???
@param optional {string} Values of ID form elements ?action=example&p1=???&p2=???
*/
function submit()
{
    var func = arguments[0];
    var url = t_path + "?action="+encodeURIComponent(arguments[0]);
    for(var i = 1; i < arguments.length; i++)
    {
        url += "&p" + i + "=" + encodeURIComponent(document.getElementById(arguments[i]).value);
    }
    var req = null;
    messageBox('Loading');
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject)
    {
        try
        {
            req = new ActiveXObject("Msxml2.XMLHTTP");
	}
        catch (e)
	{
            try
            {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (f) {}
        }
    }
    req.onreadystatechange = function()
    {
	messageBox('Waiting');
	if(req.readyState == 4)
	{
            if(req.status == 200)
            {
                messageBox('');
                eval(func+"AJAX(req.responseText);");
            }
            else
            {
                alert("Error: " + req.status + " " + req.statusText);
            }
        }
    };
    req.open("GET", url, true);
    req.send(null);
}
/**
send(function/action, [variable1, variable2, ...])
@param function/action {string} Name of ??? + AJAX() for return function and ?action=???
@param optional {string} Values to send ?action=example&p1=???&p2=???
*/
function send()
{
    var func = arguments[0];
    var url = t_path + "?action="+encodeURIComponent(arguments[0]);
    for(var i = 1; i < arguments.length; i++)
    {
        url += "&p" + i + "=" + encodeURIComponent(arguments[i]);
    }
    var req = null;
    messageBox('Loading');
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject)
    {
        try
        {
            req = new ActiveXObject("Msxml2.XMLHTTP");
	}
        catch (e)
	{
            try
            {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (f) {}
        }
    }
    req.onreadystatechange = function()
    {
	messageBox('Waiting');
	if(req.readyState == 4)
	{
            if(req.status == 200)
            {
                messageBox('');
                eval(func+"AJAX(req.responseText);");
            }
            else
            {
                alert("Error: " + req.status + " " + req.statusText);
            }
        }
    };
    req.open("GET", url, true);
    req.send(null);
}
/**
sendConfirm(function/action, message, [variable1, variable2, ...])
@param function/action {string} Name of ??? + AJAX() for return function and ?action=???
@param optional {string} Values of ID form elements ?action=example&p1=???&p2=???
*/
function sendConfirm()
{
    var func = arguments[0];
    var msg = arguments[1];
    var r = confirm("Are you sure you want to " + msg + "?");
    if (r === true)
    {
        var url = t_path + "?action="+encodeURIComponent(arguments[0]);
        for(var i = 2; i < arguments.length; i++)
        {
            url += "&p" + (i - 1) + "=" + encodeURIComponent(arguments[i]);
        }
        var req = null;
        messageBox('Loading');
        if (window.XMLHttpRequest)
        {
            req = new XMLHttpRequest();
        } 
        else if (window.ActiveXObject)
        {
            try
            {
                req = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    req = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (f) {}
            }
        }
        req.onreadystatechange = function()
        {
            messageBox('Waiting');
            if(req.readyState == 4)
            {
                if(req.status == 200)
                {
                    messageBox('');
                    eval(func+"AJAX(req.responseText);");
                }
                else
                {
                    alert("Error: " + req.status + " " + req.statusText);
                }
            }
        };
        req.open("GET", url, true);
        req.send(null);
    }
}
/**
messageBox(function/action, message, [variable1, variable2, ...])
@param function/action {string} Name of ??? + AJAX() for return function and ?action=???
@param optional {string} Values of ID form elements ?action=example&p1=???&p2=???
*/

function post()
{
    var func = arguments[0];
    var url = t_path + "?action="+encodeURIComponent(arguments[0]);
    var params = "";
    for(var i = 1; i < arguments.length; i++)
    {
        params += "&p" + i + "=" + encodeURIComponent(document.getElementById(arguments[i]).value);
    }
    var req = null;
    messageBox('Loading');
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject)
    {
        try
        {
            req = new ActiveXObject("Msxml2.XMLHTTP");
	}
        catch (e)
	{
            try
            {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (f) {}
        }
    }
    req.onreadystatechange = function()
    {
	messageBox('Waiting');
	if(req.readyState == 4)
	{
            if(req.status == 200)
            {
                messageBox('');
                eval(func+"AJAX(req.responseText);");
            }
            else
            {
                alert("Error: " + req.status + " " + req.statusText);
            }
        }
    };
    req.open("POST", url, true);
    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    req.setRequestHeader("Content-length", params.length);
    req.setRequestHeader("Connection", "close");
    req.send(params);
}