function getPageN() {
    if (document.getElementById(getPageName() + "i")) {
        var h = document.getElementById(getPageName() + "i").childNodes[0].innerHTML;
        var t = h;
        if (getPageName() == "home")
        {
            h = document.getElementById(getPageName() + "i").childNodes[0].innerHTML.split("|")[0];
            t = document.getElementById(getPageName() + "i").childNodes[0].innerHTML.split("|")[1];
        }
        getPage(getPageName(), document.getElementById(getPageName() + "i"), h, t, 1);
    }
}

function getPage(page, pnode, h, t, pt) {
    var tnodes = new Array("innerm", "content");
    document.getElementById("load").style.display = "inline";
    if (xmlhttp.readyState == 0 || xmlhttp.readyState == 4) {
        try {
            xmlhttp.open("GET", "data.php?p=" + page, true);
            xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4) {
                    document.getElementById("load").style.display = "none";
                    if (document.getElementById(tnodes[pt]).innerHTML != xmlhttp.responseText) {
                        doInnerHTML(tnodes[pt], xmlhttp.responseText);
                        if (page == "statyas") {
                            window.setTimeout("getPage('s9', document.getElementById('s9'), '', document.getElementById('s9').innerHTML, 0)", 10);
                        }
                        else if (page == "contact") {
                            window.setTimeout("cm()", 10);
                        }
                    }
                    navi(pnode, h, t);
                }
            }
            xmlhttp.send(null);
        }
        catch(e) {
            doInnerHTML("content", e);
        }
    }
}

function sajax() {
    if (callInProgress()) {
        xmlhttp.abort();
    }
}

function callInProgress() {
    switch ( xmlhttp.readyState ) {
        case 1, 2, 3:
            return true;
        break;

        default:
            return false;
        break;
    }
}

function navi(node, h, t) {
    try {
        for (i = 0; i <= node.parentNode.childNodes.length; i++) {
            node.parentNode.childNodes[i].className = "";
        }
    }
    catch(e){}
    node.className = "c";

    if (h != "")
    { doInnerHTML("header", h); }
    if (t != "")
    { document.title = "chudosok.info - " + t; }
}

function cm() {
    if (!document.getElementById("cs")) {
        if (document.createElementNS) {
            var cscrpt = document.createElementNS("http://www.w3.org/1999/xhtml", "script");
        }
        else {
            var cscrpt = document.createElement("script");
        }
        cscrpt.setAttribute("id", "cs");
        cscrpt.setAttribute("type", "text/javascript");
        cscrpt.setAttribute("src", "contact.js");
        document.getElementsByTagName("head")[0].appendChild(cscrpt);
    }
    if (!isSup()) {
        document.getElementById("sender").disabled = true;
        document.getElementById("sender").value = "Не можна послать email с вашим браузером.";
    }
}

function isSup() {
    try {
        if (xmlhttp.setRequestHeader)
        { return (true); }
        else
        { return (false); }
    }
    catch (e) { return (true); /*IE gives an exception even though it supports the method*/ }
}

function getPageName()
{
    var n;
    if (window.location.href.split("#")[1]) {
        n = window.location.href.split("#")[1];
    }
    else { n = "home"; }
    return n;
}

var lastURL = window.location.href;

function chkURL() {
    if (window.location.href != lastURL) {
        lastURL = window.location.href;
        getPageN();
    }
    window.setTimeout("chkURL()", 100);
}

window.setTimeout("chkURL()", 100);