/* General Javascript include */



function $(id){
    return document.getElementById(id);
}

Cookie = {
    isSupported: function(){
        return !!navigator.cookieEnabled;
    },
    exists: function(name){
        return document.cookie.indexOf(name + "=") + 1;
    },
    write: function(name, value, expires, path, domain, secure) {
        expires instanceof Date ? expires = expires.toGMTString()
        : typeof(expires) == 'number' && (expires = (new Date(+(new Date) + expires * 1e3)).toGMTString());
        var r = [name + "=" + escape(value)], s, i;
        for(i in s = {expires: expires, path: path, domain: domain})
            s[i] && r.push(i + "=" + s[i]);
        return secure && r.push("secure"), document.cookie = r.join(";"), true;
    },
    read: function(name){
        var c = document.cookie, s = this.exists(name), e;
        return s ? unescape(c.substring(s += name.length, (c.indexOf(";", s) + 1 || c.length + 1) - 1)) : "";
    },
    remove: function(name, path){
        return this.exists(name) && this.write(name, "", new Date(0), path);
    }
};

var Auth = {
    cookieName: "cva_usr",
    login: function (name) {
        Cookie.write(this.cookieName, name, null, "/");
    },
    user: function () {
        var username = Cookie.read(this.cookieName);
        return (username == "") ? false : username;
    },
    logout: function () {
        Cookie.remove(this.cookieName, "/");
    }
};

function bookmark(element) {
    if(document.all)// ie
        window.external.AddFavorite(document.location, element.title);
}

function toggleYear(strYear)
{
 var divs = document.getElementsByTagName('div');
         for(var x=0; x<divs.length; x++)
          if(divs[x].className=='year'){
             if(strYear=='')               
                    strYear=divs[x].id;              
             if(divs[x].id==strYear)
                    divs[x].style.display='';
             else
                    divs[x].style.display='none';
          }
                
}



window.onload = function(){
    if($('auth_loading')){
        if(Auth.user()){
            $('sign_out').style.display = '';
            $('username').innerHTML = Auth.user();
        } else {
            $('sign_in').style.display = '';
        }
        $('auth_loading').style.display = 'none';
    }
    if(typeof onLoad == 'function'){
        onLoad();
    }
}

