var root = "/";
if (!window.canBeAlone&&top==window) { top.location.replace(root+"#url="+escape(window.location)); }

function loadPlan() {
    if (window.createPopup) {
        var popup = window.createPopup();
        popup.document.body.innerHTML='<img src="'+root+'carte.jpg" width="720" height="625" style="border: outset 3px; cursor: pointer;" title="82, Rue du Viaduc. \nLes élèves entrent par la rue du conseil." />';
        popup.document.onclick=function() { popup.document.canClose=true; }
        popup.show((screen.width-726)/2,(screen.height-631)/2,726,631)
        var timer = 0; timer = setInterval(function() {
            if (popup.document.canClose) {
                popup.hide();
                clearInterval(timer);
            } else {
                popup.show((screen.width-726)/2,(screen.height-631)/2,726,631)
            }
        }, 125)
    } else {
        window.open(root+"carte.jpg","plan","width=740, height=645, left="+parseInt((screen.width-740)/2)+", top="+parseInt((screen.height-645)/2));
    }
}

var pickRecentProgID = function (idList){
	// found progID flag
    var bFound = false;
    for(var i=0; i < idList.length && !bFound; i++){
        try{
            var oDoc = new ActiveXObject(idList[i]);
            o2Store = idList[i];
            bFound = true;
        }catch (objException){
            // trap; try next progID
        };
    };
    if (!bFound) {
		throw ("Aucun ActiveXObject n'est valide sur votre ordinateur, pensez à mettre à jour votre navigateur");
    }
    idList = null;
    return o2Store;
}
 
// Retourne un nouvel objet XmlHttpRequest
var getXmlHttpRequest_AXO=null
var getXmlHttpRequest=function () {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		if (!getXmlHttpRequest_AXO) {
			getXmlHttpRequest_AXO=pickRecentProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
		}
		return new ActiveXObject(getXmlHttpRequest_AXO)
	}
	return false;
}
var getXHR = getXmlHttpRequest;

function getFileContent(url) {
    var xhr = getXHR();
    xhr.open('GET', url, false);
    xhr.send(null);
    return xhr.responseText;
}

function async(f) {
    setTimeout(f, 0);
}

function asyncServerCall(url, postData) {
    var xhr = getXHR();
    xhr.open(postData?'POST':'GET', url, true);
    xhr.onreadystatechange=function() {
        if (xhr.readState==4) {
            alert(xhr.responseText);
        }
    }
    xhr.send(postData?postData:null);
}

function asyncThrow(ex) {
    async(function() { throw (ex); });
}

function asyncAlert(msg) {
    async(function() { alert(msg) });
}

function isChildOf(parent, el) {
    while (el) {
        if (el == parent) { return !!parent; }
        else { el = el.parentNode; }
    }
    return false;
}

function firstParentOfType(el, type) {
    while (el) {
        if (el.tagName==type) { return el; }
        else { el=el.parentNode; }
    }
    return null;
}

function canDoAction(o,e,soft) {
    var response = false;
    if(!o) {
        // Do nothing
    } else {
        // See if the action is doable
        switch (o.tagName) {
            case "TEXTAREA":
            case "SELECT":
                response = true;
            break;
            case "INPUT":
                response = !(o.type=="button"||o.type=="submit");
            break;
        }
    }
    // Apply the result's reponse
    if (response) {
        return true;
    } else {
        e.cancelBubble = !soft;
        e.returnValue = false;
        if (!soft && e.stopPropagation) {
            e.stopPropagation();
        }
        if (e.preventDefault) {
            e.preventDefault();
        }
        return false;
    }
}

function catchEvent(e) { e=e||window.event; return canDoAction(e.srcElement||e.target,e); }
function catchEventSoft(e) { e=e||window.event; return canDoAction(e.srcElement||e.target,e,true); }

function addHandler(o,name,handler) {
    if (o.attachEvent) { o.attachEvent('on'+name, handler); return true; }
    if (o.addEventListener) { o.addEventListener(name, handler, true); return true; }
    var oldH = o['on'+name];
    o['on'+name]=function(e) {
        var res = true;
        try { res=res&&oldH(e); } catch (ex) {}
        try { res=res&&handler(e); } catch (ex) {}
        return res;
    };
}


function getData(name, remplacements) {
    var res = document.getElementById("data_" + name);
    if (res) {
        if (res.firstChild) {
            if (res.firstChild.data) {
                res=res.firstChild.data;
            } else {
                res=res.firstChild.innerHTML.replace(/^\<\!--/, '').replace(/--\>$/,'');
            }
        } else {
            res=res.innerHTML;
        }
    } else {
        return "";
    }
    for (key in remplacements) {
        if (remplacements.hasOwnProperty(key)) {
            res = res.split("<\!" + key + "!\>").join(remplacements[key]);
        }
    }
    return res.replace(/\<\!.*\!\>/gi,"");
}

function HTMLEncode(str) {
    var d = HTMLEncode.decoder; d.innerHTML = "";
    try { str=str.replace(/\n/g,"[BR]"); } catch (ex) {}
    d.appendChild(document.createTextNode(str));
    return d.innerHTML.replace(/\[BR\]/g,"<br/>");
}
HTMLEncode.decoder = document.createElement("DIV");
HTMLEncode.regexp  = /\<[^\s\>]*(\s*[^\s\>\=]*(\=('|")([^\'"]*)('|")|=[^\s\>=]*)?)*\>/g;

function HTMLDecode(str) {
    var d = HTMLEncode.decoder;
    if (typeof(d.innerText)!="undefined") {
        d.innerHTML = str.replace(/<br\s*>/g,"[BR]");
        return d.innerText.replace(/\[BR\]/g,"\n");
    } else {
        d.innerHTML = str.replace(/<br\s*>/g,"[BR]").replace(HTMLEncode.regexp, "");
        return d.firstChild.data.replace(/[BR]/g,"\n");
    }
}

// Implements a simple cookie listener
var Cookie={};
Cookie.write=function (nom, valeur) {
    try {
        var argv=arguments;
        var argc=arguments.length;
        var expires=(argc > 2) ? argv[2] : null;
        var path=(argc > 3) ? argv[3] : null;
        var domain=(argc > 4) ? argv[4] : null;
        var secure=(argc > 5) ? argv[5] : false;
        document.cookie=escape(nom)+"="+escape(valeur)+
        ((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
        ((path==null) ? "" : ("; path="+path))+
        ((domain==null) ? "" : ("; domain="+domain))+
        ((secure==true) ? "; secure" : "");
    } catch (ex) {}
}
Cookie.read=function (nom) {
    try {
        var arg=escape(nom)+"=";
        var alen=arg.length;
        var clen=document.cookie.length;
        var i=0;
        while (i<clen) {
            var j=i+alen;
            if (document.cookie.substring(i, j)==arg) return Cookie._read(j);
            i=document.cookie.indexOf(" ",i)+1;
            if (i==0) break;
        }
    } catch (ex) {}
    return null; 
}
Cookie._read=function (offset) {
    var endstr=document.cookie.indexOf (";", offset);
    if (endstr==-1) endstr=document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr)); 
}

function connectUser(user) {
    Cookie.write("editUser",user);
    location.reload();
}

if (!Object.prototype.toJSONString) {
    Array.prototype.toJSONString = function () {
        var a = ['['], b, i, l = this.length, v;

        function p(s) {
            if (b) {
                a.push(',');
            }
            a.push(s);
            b = true;
        }

        for (i = 0; i < l; i += 1) {
            v = this[i];
            switch (typeof v) {
            case 'undefined':
            case 'function':
            case 'unknown':
                break;
            case 'object':
                if (v) {
                    if (typeof v.toJSONString === 'function') {
                        p(v.toJSONString());
                    }
                } else {
                    p("null");
                }
                break;
            default:
                p(v.toJSONString());
            }
        }
        a.push(']');
        return a.join('');
    };

    Boolean.prototype.toJSONString = function () {
        return String(this);
    };

    Date.prototype.toJSONString = function () {

        function f(n) {
            return n < 10 ? '0' + n : n;
        }

        return '"' + this.getFullYear() + '-' +
                f(this.getMonth() + 1) + '-' +
                f(this.getDate()) + 'T' +
                f(this.getHours()) + ':' +
                f(this.getMinutes()) + ':' +
                f(this.getSeconds()) + '"';
    };

    Number.prototype.toJSONString = function () {
        return isFinite(this) ? String(this) : "null";
    };
    
    Function.prototype.toJSONString = function() {
        return (""+this+"");
    }
    
    RegExp.prototype.toJSONString=function() {
        return (""+this+"");    
    }

    Object.prototype.toJSONString = function () {
        var a = ['{'], b, i, v;

        function p(s) {
            if (b) {
                a.push(',');
            }
            a.push(i.toJSONString(), ':', s);
            b = true;
        }

        for (i in this) {
            if (true) {
                v = this[i];
                switch (typeof v) {
                case 'undefined':
                case 'function':
                case 'unknown':
                    break;
                case 'object':
                    if (v && v.getType) {
                        if (typeof v.toJSONString === 'function') {
                            p(v.toJSONString());
                        }
                    } else {
                        p("null");
                    }
                    break;
                default:
                    p(v.toJSONString());
                }
            }
        }
        a.push('}');
        return a.join('');
    };


    (function (s) {
        var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };

        s.parseJSON = function (hook) {
            try {
                if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
                        test(this)) {
                    var j = eval('(' + this + ')');
                    if (typeof hook === 'function') {
                        function walk(v) {
                            if (v && typeof v === 'object') {
                                for (var i in v) {
                                    if (v.hasOwnProperty(i)) {
                                        v[i] = walk(v[i]);
                                    }
                                }
                            }
                            return hook(v);
                        }
                        return walk(j);
                    }
                    return j;
                }
            } catch (e) {
            }
            throw new SyntaxError("parseJSON");
        };

        s.toJSONString = function () {
            if (/["\\\x00-\x1f]/.test(this)) {
                return '"' + this.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                    var c = m[b];
                    if (c) {
                        return c;
                    }
                    c = b.charCodeAt();
                    return '\\u00' +
                        Math.floor(c / 16).toString(16) +
                        (c % 16).toString(16);
                }) + '"';
            }
            return '"' + this + '"';
        };
    })(String.prototype);
}

try {
    eval(getFileContent(root+'getEvents.php'));
} catch (ex) {}