/*
* OpenPHPNuke: Great Web Portal System
*
* Copyright (c) 2001-2012 by
* Stefan Kaletta stefan ( at ) kaletta.de
*
* This program is free software. You can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
* See LICENSE for details.
*
* This software is based on various code found in the internet
* See CREDITS for details
* If you are an author of a part of opn and not you are not mentioned
* SORRY for that ! We respect your rights to your code, so please send
* an eMail to devteam@openphpnuke.com we will include you to the CREDITS asap
*/

function opn_theme_sw_display (id, cssclass) {

	if (document.getElementById(id).style.display != 'block') {
		document.getElementById(id).style.display = 'block';
		opn_theme_save_cookie (id, 1);
		document.getElementById('div_' + id).className = cssclass + '_open';
	} else {
		document.getElementById(id).style.display = 'none';
		opn_theme_save_cookie (id, 0);
		document.getElementById('div_' + id).className = cssclass + '_close';
	}
}

function opn_theme_save_cookie (id, wert) {
	var a = new Date();
	a = new Date(a.getTime() +1000*60*60*24*1);
	document.cookie = id + '=' + wert + '; expires='+a.toGMTString()+';';
}

function opn_theme_get_cookie (n) {
	var a = document.cookie + ';';
	var res = '';
	var cookiename;
	var cookiewert;
	var i;
	while(a != '') {
		cookiename = a.substring(0,a.search('=')) ;
		cookiewert = a.substring(a.search('=')+1,a.search(';'));

		if(cookiewert == '')
			{cookiewert = a.substring(a.search('=')+1,a.length);}

		if (n == opn_theme_trim (cookiename) ) {
			res = cookiewert;
		}

		i = a.search(';')+1;
		if (i == 0) {
			i = a.length;
		}
		a = a.substring(i,a.length);
	}
	return(res);
}

function opn_theme_trim (z) {
  return z.replace (/^\s+/, '').replace (/\s+$/, '');
}

function opn_theme_set_display (id, cssclass) {

	var a = opn_theme_get_cookie (id);
	if (a == 1) {
		document.getElementById(id).style.display = 'block';
		document.getElementById('div_' + id).className = cssclass + '_open';
	} 
	if (a == 0) {
		document.getElementById(id).style.display = 'none';
		document.getElementById('div_' + id).className = cssclass + '_close';
	}
}

