// JavaScript Document collapse and cookie functions
function collapse(el,section) {
	if(document.getElementById)	{
			var hide = document.getElementById(el);
			if (	hide.className == "hidethis") {

						if (	section == "reveal"){
								hide.className=hide.className.replace(new RegExp("hidethis\\b"), "reveal");
									writeCookie('LogJoin', 'reveal', 8760)
									}

						if (	section == "reveal2"){
								hide.className=hide.className.replace(new RegExp("hidethis\\b"), "reveal2");
									writeCookie('LogJoin', 'reveal2', 8760)
							}
					}
			else	{
						if (	section == "reveal"){
								if (	hide.className == "reveal2"){
								hide.className=hide.className.replace(new RegExp("reveal2\\b"), "reveal");
								writeCookie('LogJoin', 'reveal', 8760)
								}
								else{
									hide.className=hide.className.replace(new RegExp("reveal\\b"), "hidethis");
								writeCookie('LogJoin', 'hidethis', 8760)
								}
						}
						if (	section == "reveal2"){
						if (	hide.className == "reveal"){
								hide.className=hide.className.replace(new RegExp("reveal\\b"), "reveal2");
							writeCookie('LogJoin', 'reveal2', 8760)
						}
						else {
							hide.className=hide.className.replace(new RegExp("reveal2\\b"), "hidethis");
							writeCookie('LogJoin', 'hidethis', 8760)
							}
					}
		 		}
			}	
}
function fade(el,id) {
	
	document.getElementById('change-' +id).className = 'section1';
	document.getElementById('login-needed-' +id).visibility = 'hidden';
//	if(document.getElementById)	{
//			var hide = document.getElementById(el);
//			
//			if (	(hide.className).indexOf("fadethis") !=-1) {
//					hide.className=hide.className.replace(new RegExp("fadethis\\b"), "dummy");
//					}
//			else	
//					{	hide.className=hide.className.replace(new RegExp("dummy\\b"), "fadethis");
//			}
//		}
}
function collapse2(el,section) {
	if(document.getElementById)	{
	var toggle = document.getElementById(el);
				if (	section == "no-email"){
								toggle.className=toggle.className.replace(new RegExp("email-ok\\b"), "no-email");
							}
		else {
							toggle.className=toggle.className.replace(new RegExp("no-email\\b"), "email-ok");
					}
		}
}

function isNullOrUndefined(a,value){
   if(typeof value != 'undefined'){
               if (typeof a == 'undefined'){
                   return value;
               }else{
                   if(a==null){
                       return value;
                   }else{
                       return a;
                   }
               }
       }else{
           if(typeof a == 'undefined'){
                   return true;
           }else{
               if(a==null){
                       return true;
               }else{
                       return false;
               }
           }
       }
}
function setLoginJoin() {
	var elName = readCookie('LogJoin');
	var showit = document.getElementById("sidebar");
	if(isNullOrUndefined(showit)!= true)
	{
	if (elName =="reveal") {
					showit.className=showit.className.replace(new RegExp("hidethis\\b"), "reveal");
					}
	if (elName =="reveal2") {
	showit.className=showit.className.replace(new RegExp("hidethis\\b"), "reveal2");
			}
	}
} 

function readCookie(name) { var cookieValue = ""; var search = name + "="; if(document.cookie.length > 0) { offset = document.cookie.indexOf(search); if (offset != -1) { offset += search.length; end = document.cookie.indexOf(";", offset); if (end == -1) end = document.cookie.length; cookieValue = unescape(document.cookie.substring(offset,
end)) } } return cookieValue;
}
// writeCookie("myCookie", "my name", 24); 
// Stores the string "my name" in the cookie "myCookie" which expires after 24 x365 hours. 
function writeCookie(name, value, hours) { var expire = ""; if(hours != null) { expire = new Date((new Date()).getTime() + hours * 3600000); expire = "; expires=" + expire.toGMTString(); } document.cookie = name + "=" + escape(value)
+ expire; }

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent (setLoginJoin);

