// script.js von coppermine, ncnever, modifiziert Mittwoch, 01.12.2004 12:12:56 
function url_add_var(url, add_string)
{
	return url + (url.indexOf("?") == -1 ? "?" : "&") + add_string;
}

function writeCookie(name, data, noDays)
{
	var cookieStr = name + "="+ data;
	var expires = new Date();
	var days = expires.getTime() + (noDays * 24 * 60 * 60 * 1000);
	expires.setTime(days);
	if (writeCookie.arguments.length > 2) 
	{
		cookieStr += "; expires=" + expires.toGMTString();
	}
	document.cookie = cookieStr;
}

function readCookie(cookieName)
{
	var searchName = cookieName + "=";
	var cookies = document.cookie;
	var start = cookies.indexOf(cookieName);
	if (start == -1)
	{ // cookie not found
		return "";
	}
	start += searchName.length; //start of the cookie data
	var end = cookies.indexOf(";", start);
	if (end == -1)
	{
		end = cookies.length;
	}
	return cookies.substring(start, end);
}

// input: html_id: id eines html-elements; 
// input: cookie: "" falls die geänderte sichtbarkeit nicht im cookie gespeichert werden soll, "cookie_name" falls ja; 
// input: visible_attribute: css-attribut "inline" oder "block";
// effect: das html-elemet "html_id" wechselt zwischen versteckt und angezeigt
// output: - 
function blocking(html_id, cookie, visible_attribute)
{
	if (document.layers)
	{
		current = (document.layers[html_id].display == 'none') ? visible_attribute : 'none';
		if (cookie != '')
			writeCookie(cookie, current);
		document.layers[html_id].display = current;
	}
	else if (document.all)
	{
		current = (document.all[html_id].style.display == 'none') ? visible_attribute : 'none';
		if (cookie != '')
			writeCookie(cookie, current);
		document.all[html_id].style.display = current;
	}
	else if (document.getElementById)
	{
		display = (document.getElementById(html_id).style.display == 'none') ? visible_attribute : 'none';
		if (cookie != '')
			writeCookie(cookie, display);
		document.getElementById(html_id).style.display = display;
	}
}

//u.a. für die smilies benötigt:
//effect: ein zeichen einem textfeld mit "name" hinzufügen
//output: -
function addchar(symb, element_id)
{
	if(MS)
	{
		getElem("id",element_id,0).focus();
		with(document.selection.createRange())
		{
			text = symb; 
			collapse(); 
			select();
		}
	}
	else
	{
		getElem("id",element_id,0).focus();
		tt = getElem("id",element_id,0);
		p1 = tt.selectionStart;
		tt.value = tt.value.substring(0, p1) + symb + tt.value.substring(tt.selectionEnd);
		tt.setSelectionRange(p1+symb.length, p1+symb.length);	
	}
}
