﻿var moz =
    (typeof document.implementation != 'undefined')
    && (typeof document.implementation.createDocument != 'undefined');
    
var ie = (typeof window.ActiveXObject != 'undefined');

function getXmlHttp()
{
    if (window.ActiveXObject)
    {
        try
        {
            return new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {}
        try
        {
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {}
    }
    else if (window.XMLHttpRequest)
    {
        try
        {
            return new XMLHttpRequest();
        }
        catch (e) {}
    }
}

function getXmlDocument(p_sSource, p_sSourceType)
{
    var xmlDoc;
    
    if (moz)
    {
        xmlDoc = document.implementation.createDocument("", "", null)
        //xmlDoc.onload = readXML;
    }
    else if (ie)
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        while(xmlDoc.readyState != 4) {};
    }
    
    if (p_sSource != null)
    {
        switch (p_sSourceType)
        {
            case "url":
                xmlDoc.load(p_sSource);
                break;
            case "text":
                if (moz)
                {
                    parser=new DOMParser();
                    xmlDoc=parser.parseFromString(p_sSource, "text/xml");
                }
                else if (ie)
                {
                    xmlDoc.loadXML(p_sSource);
                }
                break;
        }
        
    }
    
    return xmlDoc;
}

function SetPageOffset(p_sOffset)
{
	m_sPageOffset = p_sOffset;
}

function RequestXmlHttp(p_sPage, p_sQueryString, p_oPostXml)
{		
	var sHref = m_sPageOffset + p_sPage + "?" + p_sQueryString;
    return SendXmlHttp(sHref, p_oPostXml);
}

function SendXmlHttp(p_sURL, p_oPostXml)
{		
	var oXmlhttp = getXmlHttp();
    var sMethod = p_oPostXml == null ? "GET" : "POST";
    
    oXmlhttp.open(sMethod, p_sURL, false);
    oXmlhttp.send(p_oPostXml);
    
    return oXmlhttp.responseText;
}

function SavePageOrder(p_iPageID, p_iOrder)
{
    //RequestXmlHttp("XmlHttpGate.aspx", "Type=Page&PageID=" + p_iPageID + "&Order=" + p_iOrder, null);
    new Ajax.Request('XmlHttpGate.aspx?PageID=' + p_iPageID + '&Order=' + p_iOrder + '&Type=PageOrder', 
    {
        onSuccess: requestSuccess
    });   
}

function requestSuccess()
{

}

function SavePageLevel(p_iPageID, p_iOrder, p_iParentID)
{
    RequestXmlHttp("XmlHttpGate.aspx", "Type=Page&PageID=" + p_iPageID + "&Order=" + p_iOrder + "&ParentID=" + p_iParentID, null);
}

function selectNodes(xnNode, sXPath)
{ 
   if (moz)
   {
        var oEvaluator = new XPathEvaluator(); 
        var oResult = oEvaluator.evaluate(sXPath, xnNode, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); 
        var aNodes = new Array(); 
        if (oResult != null)
        { 
            var oElement = oResult.iterateNext(); 
            while(oElement)
            { 
                aNodes.push(oElement); 
                oElement = oResult.iterateNext(); 
            } 
        } 
        return aNodes;
   }
   else
   {
        return xnNode.selectNodes(sXPath);
   }
}