/* 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(element.link, element.title);
else
    element.href=element.getAttribute('link');
}



window.onload = function(){
    if($('auth_loading')){
       $('sign_in').style.display = '';
       $('auth_loading').style.display = 'none';
    
  if ( typeof( window[ 'auth_uid' ] ) != "undefined" ) {
   if(auth_uid) {
        $('sign_in').style.display = 'none';
        $('sign_out').style.display = '';
        $('username').innerHTML = 'kirjautuneena <strong>' + auth_uid + '</strong>';
        $('username').title = 'Henkilötietoihin';
    }
   }
  }
    if(typeof onLoad == 'function')
        onLoad();
}

