/*---------------------------------------------------------------------+
| ExiteCMS Content Management System                                   |
+----------------------------------------------------------------------+
| Copyright 2006-2009 Exite BV, The Netherlands                        |
| for support, please visit http://www.exitecms.org                    |
+----------------------------------------------------------------------+
| Released under the terms & conditions of v2 of the GNU General Public|
| License. For details refer to the included gpl.txt file or visit     |
| http://gnu.org                                                       |
+---------------------------------------------------------------------*/

// generic function loader

function addOnloadEvent(fnc) {
	if ( typeof window.addEventListener != "undefined" ) {
		window.addEventListener( "load", fnc, false );
	} else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", fnc );
	} else {
		if ( window.onload != null ) {
			var oldOnload = window.onload;
			window.onload = function ( e ) {
				oldOnload( e );
				window[fnc]();
			};
		} else {
			window.onload = fnc;
		}
	}
}

// generic flip function

function flipdivs(element, divlist)
{
	if (divlist != undefined) {
		var divs = divlist.split(",");
		for(i = 0; i < divs.length; i++) {
			var subdivs = divs[i].split(";");
			if (subdivs[0] != "" && subdivs[0] != element) {
				for(j = 0; j < subdivs.length; j++) {
					document.getElementById(subdivs[j]).style.display = 'none';
					document.getElementById(subdivs[j]).style.visibility = 'hidden';
				}
			} else {
				var showdivs = subdivs;
			}
		}
		if (showdivs != undefined) {
			for(j = 0; j < showdivs.length; j++) {
				document.getElementById(showdivs[j]).style.display = '';
				document.getElementById(showdivs[j]).style.visibility = 'visible';
			}
		}
	}
}

// Cookie functions

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
