
// Extensions by Reto Diener
// First Creation: Mai 2008
// --------------------------------------------------------------------------------------------------------------------------------------------
// Cookie handlers

var sCookieNameDynCSS = 'DynCSS';

// Getting date from a specified cookie
function getCookie(name){
  if(name){
    var cname = name + "=";
    var dc = document.cookie;
    if (dc.length > 0) {
      begin = dc.indexOf(cname);
      if (begin != -1) {
        begin += cname.length;
        end = dc.indexOf(";", begin);
        if (end == -1) end = dc.length;
          return unescape(dc.substring(begin, end));
      }
    }
    return null;
  }
}

// Init. cookie and setting data
function setCookie(name, value, expires, path, domain, secure){
  if(name && value){
    document.cookie = name + "=" + escape(value) +
    ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    ((secure == null) ? "" : "; secure");
  }
}

// Deleting a specified cookie
function delCookie(name,path,domain) {
  if(name){
    if (getCookie(name)) {
      document.cookie = name + "=" +
      ((path == null) ? "" : "; path=" + path) +
      ((domain == null) ? "" : "; domain=" + domain) +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  }
}

// First delete the cookie, then write it
function DelAndWriteCookie(sSetCookie,sCookieName){
  if(!sCookieName){
    sCookieName = 'DynCSS';
  }
  delCookie(sCookieName);
  // Cookie expires after about 2 years
  var expiration = new Date();
  expiration.setTime(expiration.getTime() + 60480000000);
  setCookie(sCookieName, sSetCookie, expiration);
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// dynamic CSS style
// set css parameters and cookie value
function set_css_params_user() {

	if (top.large_midcol == true) {
		document.getElementById("title").style.width = '1086px';
		document.getElementById("box").style.width = '1086px';
		document.getElementById("box").style.backgroundImage = 'url(fileadmin/gruene/images/box_bg_large.png)';
		document.getElementById("mid_col").style.width = '706px';
		document.getElementById("navigation").style.width = '706px';
		DelAndWriteCookie( "true", sCookieNameDynCSS );

	}
	else {
		document.getElementById("title").style.width = '886px';
		document.getElementById("box").style.width = '886px';
		document.getElementById("box").style.backgroundImage = 'url(fileadmin/gruene/images/box_bg.png)';
		document.getElementById("mid_col").style.width = '506px';
		document.getElementById("navigation").style.width = '506px';
		DelAndWriteCookie( "false", sCookieNameDynCSS );
	}
}

// toggle css parameters (to be called from user interaction)
function toggle_css_params() {

	if (top.large_midcol == true) top.large_midcol = false;  else top.large_midcol = true;
	set_css_params_user();
	window.location.reload();

}


// set css parameters (ev.) from cookie - to be called at the end of every page request
function set_css_params() {

	var state = getCookie( sCookieNameDynCSS );
	if (state != "false" && state != "true") {
		if (screen.availWidth > 1100) state = "true";			// if enough space set to large window
	}
	if (state != null) {
		if (state == "true") top.large_midcol = true; else top.large_midcol = false;
	}
	set_css_params_user();

}
