function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function validate_login(theform){
	var errors = "";
	if(!theform.login_username.value){
		errors += "Please enter your username to login\n";
	}
	if(!theform.login_password.value){
		errors += "Please enter your password to login";
	}
	if(errors){
		alert(errors);
		return (false);
	}else{
		return (true);
	}
}

/*------------------------------------------------------------------
AJAX Helper functions

Author: Eric Ingram

Description: parses an XML document via HTTP
    and returns a simple JS object. Example:

    root = parseDocument("xmldoc.xml");
    root.element1[0];                      - Base element object (collection)
    root.element1[0].attrib1;              - Attributes (string)
    root.element1[0]._text;                - Inner element text (string)
    root.element1[0].children.element2[0]; - Child objects (collection)

    This is mostly intended for documents where
    you already know the structure.
------------------------------------------------------------------*/
var xmlreq, xmlcallback;

// Fetch a document through XML HTTP.
function fetchXMLDoc (url, async, proc) {

    try {

       if (window.XMLHttpRequest) {
            // Safari and Mozilla
            xmlreq = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            // Internet Explorer
            xmlreq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
    } catch (e) {
        alert("Unable to create XML parser.");
        return false;
    }

    if (!async) {
        var async = false;
    } else if (async == true) {
        // Callback to process the document.
        xmlreq.onreadystatechange = processXMLReqChange;
        // Custom callback.
        xmlcallback = proc;
    }

    xmlreq.open("GET", url, async);
    xmlreq.send(null);

    if (async == false) {
        return xmlreq.responseXML;
    } else {
        return true;
    }
}

function processXMLReqChange() {

    // Status ready.
    if (xmlreq.readyState == 4) {
        // Loaded "OK".
        if (xmlreq.status == 200) {
            if (xmlcallback) {
                xmlroot = parseXML(xmlreq.responseXML);
                xmlcallback(xmlroot);
            }
        } else {
            xmlcallback(false);
        }
    }
}


function parseDocument (url, async, proc) {

    // Fetch the focument via HTTP.
    xmldoc = fetchXMLDoc(url, async, proc);

    // Return if this is asyncronous.
    if (async == true) {
        return true;
    }

    // Return the root object after parsing is finished.
    return parseXML(xmldoc);
}

function parseXML (xmldoc) {

    // Make sure we have a valid XML object.
    if (!xmldoc) {
        return false;
    }

    // XML root object.
    var xmlroot = new Object();

    // Parse over the initial children for the root node.
    var len = xmldoc.documentElement.childNodes.length;
    for (var i = 0; i < len; i++) {
        xmlroot = parseNode(xmlroot, xmldoc.documentElement.childNodes[i]);
    }

    // Return the root object after parsing is finished.
    return xmlroot;
}


function parseNode (xmlparent, xmlnode) {
    var len;

    switch (xmlnode.nodeType) {
        case 1: // Type: Element
            if (eval("xmlparent." + xmlnode.nodeName + " == null")) {
                eval("xmlparent." + xmlnode.nodeName + "= new Array();");
            }
            // Create the base object.
            eval("xmlparent." + xmlnode.nodeName + "[xmlparent." + xmlnode.nodeName + ".length] = new Object();");

            // Recurr over the children.
            if (len = xmlnode.childNodes.length) {
                eval("xmlparent." + xmlnode.nodeName + "[xmlparent." + xmlnode.nodeName + ".length - 1].children = new Object();");
                for (var i = 0; i < len; i++) {
                    eval("xmlparent." + xmlnode.nodeName + "[xmlparent." + xmlnode.nodeName + ".length - 1].children = parseNode(xmlparent." + xmlnode.nodeName + "[xmlparent." + xmlnode.nodeName + ".length - 1].children, xmlnode.childNodes[" + i + "]);");
                }
            }
            // Attributes
            len = xmlnode.attributes.length;
            for (var i = 0; i < len; i++) {
                eval("xmlparent." + xmlnode.nodeName + "[xmlparent." + xmlnode.nodeName + ".length - 1]." + xmlnode.attributes[i].nodeName + " = xmlnode.attributes[" + i + "].value;");
            }
            break;

        case 3: //Type: Text
            xmlparent._text = xmlnode.nodeValue;
            break;
    }
    return xmlparent;
}
