var D = document;
var E = D.documentElement;
var h;
var t;
var tt;
var done;
function S(u, p){
    done = false;
    document.getElementById('loading').style.display = 'block';
    document.getElementById('ptext').innerHTML =  '';
    tt = function timedCount(){
        if (h.readyState != 4 & h.readyState == 1 & done == false) {
            //alert(h);
            if (navigator.appName == "Microsoft Internet Explorer") 
                h = new ActiveXObject("Microsoft.XMLHTTP");
            else 
                h = new XMLHttpRequest();
            h.open('POST', u, true);
            h.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            h.send(p);
            h.onreadystatechange = hr;
            t = setTimeout("tt()", 15000);
        }
    }
    if (navigator.appName == "Microsoft Internet Explorer") 
        h = new ActiveXObject("Microsoft.XMLHTTP");
    else 
        h = new XMLHttpRequest();
    h.open('POST', u, true);
    h.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    h.send(p);
    h.onreadystatechange = hr;
    t = setTimeout("tt()", 15000);
}

function hr(){
    if (h.readyState == 4) {
        clearTimeout(t);
        done = true;
        var r = h.responseText;
        if (window.ActiveXObject) {
            var d = new ActiveXObject("Microsoft.XMLDOM");
            d.async = "false";
            d.loadXML(r);
        }
        else {
            var p = new DOMParser();
            var d = p.parseFromString(r, "text/xml");
        }
        var n = d.firstChild.childNodes;
        for (i = 0; i < n.length; i++) {
            try {
                v = n[i];
                if (v == null) 
                    v = '';
                else 
                    if (D.all) {
                        v = v.text;
                    }
                    else {
                        v = v.textContent;
                    }
                v = v.replace(/%26/g, '&');
                v = v.replace(/%3e/g, '>');
                v = v.replace(/%3c/g, '<');
                if (n[i].tagName == 'js') 
                    eval(v);
                document.getElementById(n[i].tagName).innerHTML = v;
            } 
            catch (err) {
            }
        }
        document.getElementById('loading').style.display = 'none';
    }
}

function mywindow(i, y){
    this.y = y;
    this.Up = 0;
    this.m = document.getElementById(i);
    this.m.style.left = (E.clientWidth - parseInt(this.m.style.width)) / 2 + 'px';
    this.m.style.position = 'absolute';
    
    this.P = function(){
        if (window.innerHeight) 
            this.p = window.pageYOffset
        else 
            if (E && E.scrollTop) 
                this.p = E.scrollTop
            else 
                if (D.body) 
                    this.p = D.body.scrollTop
    }
    this.u = function(){
        if (this.Up == 0) 
            return;
        if (Math.abs(this.a - this.b) > .1) {
            this.a = (this.b - this.a) * .2 + this.a;
            this.m.style.top = (this.a + this.p) + 'px';
            t = this;
            setTimeout('t.u()', 50);
        }
        else {
            this.Up = 0;
            t = this;
            //setTimeout('t.d()', 30000);
        }
    }
    this.d = function(){
        if (this.Up == 1) 
            return;
        this.a = (this.a - this.b) * .2 + this.a;
        if ((D.body.clientHeight - this.m.clientHeight - 5 - this.a) > 0) {
            this.m.style.top = (this.a + this.p) + 'px';
            t = this;
            setTimeout('t.d()', 50);
        }
        else 
            this.m.style.display = "none";
    }
    this.Start = function(){
        this.m.style.display = "";
        this.a = E.clientHeight - this.m.clientHeight - 5;
        this.b = this.y;
        this.P();
        this.m.style.top = (this.a + this.p - 10) + 'px';
        this.Up = 1;
        t = this;
        setTimeout('t.u()', 50);
    }
    this.DragStart = function(e){
        this.Up = 0;
        if (e == null) 
            e = window.event;
        this.eElement = (e.srcElement) ? e.srcElement : e.originalTarget;
        if (this.eElement.nodeType == 3) 
            this.eElement = this.eElement.parentNode;
        this.f = e.clientX - parseInt(this.m.style.left);
        this.g = e.clientY - parseInt(this.m.style.top);
        t = this;
        D.body.onmousemove = function(e){
            t.Drag(e);
        };
        D.body.onmouseup = function(){
            D.body.onmousemove = "";
        };
    }
    this.Drag = function(e){
        if (e == null) 
            e = window.event;
        this.m.style.left = (e.clientX - this.f) + 'px';
        this.m.style.top = (e.clientY - this.g) + 'px';
        this.a = e.clientY - this.g - this.p;
    }
    this.Close = function(){
        this.m.style.display = "none";
    }
}

function send(i){
    S(i);
    return false;
}

function post(p, i){
    S(p, i);
    return false;
}






function addev(elmclass, elmevent, elmfunc){

try {
$('#ptext a.light').lightBox();
}
catch(e) {
}
    function listen(evnt, elem, func){
        if (elem.addEventListener) // W3C DOM
            elem.onclick = function(e){
                return func(elem);
            };
        //elem.addEventListener(evnt,function() {func(elem);return false ;},false);
        else 
            if (elem.attachEvent) { // IE DOM
                elem.onclick = function(e){
                    event.returnValue = false;
                    return func(elem);
                };
            //var r = elem.attachEvent("on"+evnt, function() { return func(elem);});
            //return r;
            }
            else 
                window.alert('I\'m sorry Dave, I\'m afraid I can\'t do that.');
    }
    
    /*
     Developed by Robert Nyman, http://www.robertnyman.com
     Code/licensing: http://code.google.com/p/getelementsbyclassname/
     */
    var getElementsByClassName = function(className, tag, elm){
        if (document.getElementsByClassName) {
            getElementsByClassName = function(className, tag, elm){
                elm = elm || document;
                var elements = elm.getElementsByClassName(className), nodeName = (tag) ? new RegExp("\\b" + tag + "\\b", "i") : null, returnElements = [], current;
                for (var i = 0, il = elements.length; i < il; i += 1) {
                    current = elements[i];
                    if (!nodeName || nodeName.test(current.nodeName)) {
                        returnElements.push(current);
                    }
                }
                return returnElements;
            };
        }
        else 
            if (document.evaluate) {
                getElementsByClassName = function(className, tag, elm){
                    tag = tag || "*";
                    elm = elm || document;
                    var classes = className.split(" "), classesToCheck = "", xhtmlNamespace = "http://www.w3.org/1999/xhtml", namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace) ? xhtmlNamespace : null, returnElements = [], elements, node;
                    for (var j = 0, jl = classes.length; j < jl; j += 1) {
                        classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
                    }
                    try {
                        elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
                    } 
                    catch (e) {
                        elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
                    }
                    while ((node = elements.iterateNext())) {
                        returnElements.push(node);
                    }
                    return returnElements;
                };
            }
            else {
                getElementsByClassName = function(className, tag, elm){
                    tag = tag || "*";
                    elm = elm || document;
                    var classes = className.split(" "), classesToCheck = [], elements = (tag === "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag), current, returnElements = [], match;
                    for (var k = 0, kl = classes.length; k < kl; k += 1) {
                        classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
                    }
                    for (var l = 0, ll = elements.length; l < ll; l += 1) {
                        current = elements[l];
                        match = false;
                        for (var m = 0, ml = classesToCheck.length; m < ml; m += 1) {
                            match = classesToCheck[m].test(current.className);
                            if (!match) {
                                break;
                            }
                        }
                        
                        if (match) {
                            returnElements.push(current);
                        }
                    }
                    return returnElements;
                };
            }
        return getElementsByClassName(className, tag, elm);
    };
    
    
    var elms = getElementsByClassName(elmclass);
    for (var i in elms) 
        listen(elmevent, elms[i], elmfunc);
}

function init(){
    setInterval(checkhash, 1000);
}

function checkhash(){
    if (window.location.hash == page) {
        return;
    }
    page = window.location.hash;
    gopage = page.replace(/#/, "");
    myreg = new RegExp('^op=.*$','');
    if (page && myreg.test(gopage)) {
        S('.?' + gopage + '&a=1');
    }else
	{
		if(gopage){
		S(gopage + '&a=1');
		}else
		{
		S('?a=1');		
		}
	}
}

function hash(name, title){
    if (name) {
        page = '#' + name;
        window.location.hash = name;
    }
    else {
        page = '';
    }
    if (title) {
        document.title = title;
        var pt = document.getElementById('page_title');
        if (pt) {
            pt.innerHTML = title;
        }
    }
}

function myfunc(elem){
    S(elem + '&a=1');
    return false
}

function set_active(name){
    frmobj = document.getElementById('history');
    var his = encodeURIComponent(frmobj.his.value);
    var active = encodeURIComponent(frmobj.active.value);
    S('index.php?op=pages&a=1&name=' + name, 'active=' + active + '&his=' + his);
    return false;
}

function set_show(name){
    frmobj = document.getElementById('history');
    var his = encodeURIComponent(frmobj.his.value);
    S('index.php?op=pages&a=1&name=' + name, 'his=' + his);
    return false;
}

function start(name){
    setInterval(checkhash, 1000);
    var page = '';
    addev('ajax', 'click', myfunc);
	if (!window.location.hash) {
		hash(name, '');
	}else
	{
	   hash('', '');
	}
}
