// ----------------------------------------------------------------------------------------------------
// - Add Combo Value
// ----------------------------------------------------------------------------------------------------
function AddComboValue(oCombo, sPrompt, sDefaultValue, sClassName)
{
	var sValue = '';
	var bError = false;
	var i = 0;

	if(sValue = window.prompt(sPrompt, sDefaultValue))
	{
		for(i=0; i<oCombo.options.length; i++)
		{
			if(oCombo.options[i].value.toLowerCase() == sValue.toLowerCase())
			{
				bError = true;

				break;
			};
		};

		if(bError == false)
		{
			var oOption = new Option(sValue, sValue, false, true);

			if(sClassName)
			{
				oOption.className = sClassName;
			};

			oCombo.options[oCombo.options.length] = oOption;

			if(oCombo.onchange)
			{
				oCombo.onchange();
			};
		}
		else
		{
			alert('Der Wert "' + sValue + '" ist bereits in der Liste vorhanden!');
		};
	}
	else if(sValue === '')
	{
		alert('Du hast keinen Wert angegeben!');
	};
};

// ----------------------------------------------------------------------------------------------------
// - Expand Textbox
// ----------------------------------------------------------------------------------------------------
function ExpandTextbox(sTableID, sInputID, sTextareaID, sElementName)
{
	if(oTable = document.getElementById(sTableID))
	{
		if(oInput = document.getElementById(sInputID))
		{
			if(oTextarea = document.getElementById(sTextareaID))
			{
				if(oStatus = document.getElementById('expand[' + sElementName + ']'))
				{
					if(parseInt(oStatus.value) == 0)
					{
						oTable.style.display = 'none';
						oTable.style.visibility = 'hidden';
						oInput.disabled = true;

						oTextarea.value = oInput.value.replace(/( )/g, String.fromCharCode(10));
						oTextarea.disabled = false;
						oTextarea.style.display = '';
						oTextarea.style.visibility = 'visible';

						oStatus.value = 1;
					}
					else
					{
						oTextarea.style.display = 'none';
						oTextarea.style.visibility = 'hidden';
						oTextarea.disabled = true;

						oInput.value = oTextarea.value.replace(/(\r\n|\r|\n)/g, ' ');
						oInput.disabled = false;
						oTable.style.display = '';
						oTable.style.visibility = 'visible';

						oStatus.value = 0;
					};
				};
			};
		};
	};
};

// ----------------------------------------------------------------------------------------------------
// - Bookmark
// ----------------------------------------------------------------------------------------------------
function Bookmark(url, title)
{
	if(window.sidebar)
	{
		window.sidebar.addPanel(title, url, '');
	}
	else if(window.external)
	{
		window.external.AddFavorite(url, title);
	}
	else
	{
		alert('Dein Browser unterstützt diese Funktion leider nicht. Drücke STRG-D die Seite zu den Lesezeichen hinzuzufügen.');
	};
};

// ----------------------------------------------------------------------------------------------------
// - Set Start Page
// ----------------------------------------------------------------------------------------------------
function SetStartPage(obj, url)
{
	if(obj.setHomePage)
	{
		obj.style.behavior = 'url(#default#homepage)';
		obj.setHomePage(url);
	}
	else
	{
		alert('Dein Browser unterstützt diese Funktion leider nicht.');
	};
};

// ----------------------------------------------------------------------------------------------------
// - Open Popup
// ----------------------------------------------------------------------------------------------------
function OpenPopup(sUrl, sTarget, nWidth, nHeight)
{
	var nLeft	= (screen.availWidth - nWidth) / 2;
	var nTop	= (screen.availHeight - nHeight) / 2;

	var oWin	= window.open(sUrl, sTarget, 'channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=' + nTop + ',left=' + nLeft + ',height=' + nHeight + ',width=' + nWidth + '');

	oWin.focus();

	return(true);
};

// ----------------------------------------------------------------------------------------------------
// - Open Win
// ----------------------------------------------------------------------------------------------------
function OpenAnonymWin(sUrl)
{
	var oWin = window.open('http://anonym.to/?' + escape(sUrl), '_blank', '');

	return(true);
};

// ----------------------------------------------------------------------------------------------------
// - DL
// ----------------------------------------------------------------------------------------------------
function DL(oButton)
{
	oButton.style.color = '#00A000';
	oButton.style.fontWeight = 'bold';

	var oWin = window.open(oButton.form.action, '_blank');

	return(true);
};

// ----------------------------------------------------------------------------------------------------
// - Disable Form
// ----------------------------------------------------------------------------------------------------
function DisableForm(sForm)
{
	var oForm = document.forms[sForm];

	var i = 0;

	for(i=0; i<oForm.elements.length; i++)
	{
		oForm.elements[i].disabled = true;
		oForm.elements[i].style.color = 'graytext';
	};

	return(true);
};

// ----------------------------------------------------------------------------------------------------
// - Open Win
// ----------------------------------------------------------------------------------------------------
function OpenWin(sUrl)
{
	var oWin = window.open('http://anonym.to/?' + escape(sUrl), '_blank', '');

	return(true);
};

// ----------------------------------------------------------------------------------------------------
// - On Mouse Move
// ----------------------------------------------------------------------------------------------------
function OnMouseMove(oImg, bOver)
{
	if(bOver == true)
	{
		oImg.className = oImg.className.replace(/_MOUT/, '_MOVER');
	}
	else
	{
		oImg.className = oImg.className.replace(/_MOVER/, '_MOUT');
	};
};

// ----------------------------------------------------------------------------------------------------
// - Validate Rating Form
// ----------------------------------------------------------------------------------------------------
function ValidateRatingForm(oButton)
{
	if(parseInt(oButton.form.elements['r'].value) > 0)
	{
		return(true);
	}
	else
	{
		alert('Du must eine Bewertung auswÃ¤hlen!');

		return(false);
	};
};

// ----------------------------------------------------------------------------------------------------
// - Copy To Clipboard
// ----------------------------------------------------------------------------------------------------
function CopyToClipboard(oElement)
{
	if(window.clipboardData)
	{
		window.clipboardData.setData('Text', oElement.firstChild.nodeValue);

		alert('Das Password "' + oElement.firstChild.nodeValue + '" befindet sich jetzt in der Zwischenablage.');
	}
	else
	{
		if(SelectElement(oElement) == true)
		{
			alert('Das Password wurde markiert, drücke STRG + C um es in die Zwischenablage zu kopieren.');
		}
		else
		{
			alert('Bitte per Copy & Paste in die Zwischenablage kopieren.');
		};
	};
};

// ----------------------------------------------------------------------------------------------------
// - Select Element
// ----------------------------------------------------------------------------------------------------
function SelectElement(oElement)
{
	if(document.selection)
	{
		var range = document.body.createTextRange();
			range.moveToElementText(oElement);
			range.select();

		return(true);
	}
	else if(window.getSelection)
	{
		var range = document.createRange();
			range.selectNodeContents(oElement);

		var selection = window.getSelection();
			selection.removeAllRanges();
			selection.addRange(range);

		return(true);
	};
};

// ----------------------------------------------------------------------------------------------------
// - Show Entry Thumb
// ----------------------------------------------------------------------------------------------------
function ShowEntryThumb(sThumbUrl, sImageUrl)
{
	if(oThumb = document.getElementById('img_thumb'))
	{
		if(oLink = document.getElementById('link_image'))
		{
			oThumb.src = sThumbUrl;
			oLink.href = sImageUrl;

			return(true);
		};
	};
};

// ----------------------------------------------------------------------------------------------------
// - Rnd
// ----------------------------------------------------------------------------------------------------
function Rnd(nMin, nMax)
{
	return(Math.floor((nMax - nMin + 1) * Math.random() + nMin));
};

// ----------------------------------------------------------------------------------------------------
// - intval
// ----------------------------------------------------------------------------------------------------
function intval(vVal)
{
	return(isNaN(parseInt(vVal)) ? 0 : parseInt(vVal));
};

// ----------------------------------------------------------------------------------------------------
// - OnImageLoad
// ----------------------------------------------------------------------------------------------------
function OnImageLoad(oImage)
{
	oImage.setAttribute('err', '0');

	return(true);
};

// ----------------------------------------------------------------------------------------------------
// - OnImageError
// ----------------------------------------------------------------------------------------------------
function OnImageError(oImage)
{
	nError = intval(oImage.getAttribute('err'));

	if(nError == 0)
	{
		oImage.setAttribute('err', '1');

		if(sSrc = oImage.getAttribute('errsrc'))
		{
			oImage.src = sSrc;
		};
	};

	return(true);
};

// ----------------------------------------------------------------------------------------------------
// - Enable Element
// ----------------------------------------------------------------------------------------------------
function EnableElement(oElement, bEnabled)
{
	oElement.disabled = !bEnabled;
};

// ----------------------------------------------------------------------------------------------------
// - Lock Element
// ----------------------------------------------------------------------------------------------------
function LockElement(oElement, bLocked)
{
	oElement.style.backgroundColor = ((bLocked == true) ? 'window' : 'buttonface');
};

// ----------------------------------------------------------------------------------------------------
// - Show Element
// ----------------------------------------------------------------------------------------------------
function ShowElement(oElement, bVisible)
{
	oElement.style.display = ((bVisible == true) ? '' : 'none');
	oElement.style.visibility = ((bVisible == true) ? 'visible' : 'hidden');
};

// ----------------------------------------------------------------------------------------------------
// - Set Wrap
// ----------------------------------------------------------------------------------------------------
function SetWrap(oElement, sWrap)
{
	oElement.setAttribute('wrap', sWrap);

	var parNod = oElement.parentNode
	var nxtSib = oElement.nextSibling;

	parNod.removeChild(oElement);
	parNod.insertBefore(oElement, nxtSib);
};

// ----------------------------------------------------------------------------------------------------
// - Toolbar
// ----------------------------------------------------------------------------------------------------
function handleMove(oElement, bOver)
{
	oElement.className = ((bOver) ? 'MOVER' : 'MOUT');
};

function handleClick(oElement, bDown)
{
	oElement.className = ((bDown) ? 'MPRESS' : 'MOUT');
};

// ----------------------------------------------------------------------------------------------------
// - BB Code
// ----------------------------------------------------------------------------------------------------
function Toolbar_Bold(oText)
{
	InsertBB(oText, '[b]', '[/b]');
};

function Toolbar_Italic(oText)
{
	InsertBB(oText, '[i]', '[/i]');
};

function Toolbar_Underline(oText)
{
	InsertBB(oText, '[u]', '[/u]');
};

function Toolbar_Size(oText)
{
	InsertBB(oText, '[size=2]', '[/size]');
};

function Toolbar_Center(oText)
{
	InsertBB(oText, '[center]', '[/center]');
};

function Toolbar_Justify(oText)
{
	InsertBB(oText, '[justify]', '[/justify]');
};

function Toolbar_Color(oText)
{
	InsertBB(oText, '[color=green]', '[/color]');
};

function Toolbar_Url(oText)
{
	InsertBB(oText, '[url href = "http://"]', '[/url]');
};

function Toolbar_Image(oText)
{
	InsertBB(oText, '[img]', '[/img]');
};

function Toolbar_List(oText)
{
	InsertBB(oText, '[list]\n', '\n[/list]');
};

function Toolbar_Listitem(oText)
{
	InsertBB(oText, '[li]', '[/li]');
};

function InsertBB(oText, aTag, eTag)
{
	oText.focus();

	if(typeof document.selection != 'undefined')	/* für Internet Explorer */
	{
		/* Einfügen des Formatierungscodes */

		var range = document.selection.createRange();
		var insText = range.text;

		range.text = aTag + insText + eTag;

		/* Anpassen der Cursorposition */

		range = document.selection.createRange();

		if(insText.length == 0)
		{
			range.move('character', -eTag.length);
		}
		else
		{
			range.moveStart('character', aTag.length + insText.length + eTag.length);
		}

		range.select();
	}
	else if(typeof oText.selectionStart != 'undefined')		/* für neuere auf Gecko basierende Browser */
	{
		/* Einfügen des Formatierungscodes */

		var start = oText.selectionStart;
		var end = oText.selectionEnd;
		var insText = oText.value.substring(start, end);

		oText.value = oText.value.substr(0, start) + aTag + insText + eTag + oText.value.substr(end);

		/* Anpassen der Cursorposition */

		var pos;

		if (insText.length == 0)
		{
			pos = start + aTag.length;
		}
		else
		{
			pos = start + aTag.length + insText.length + eTag.length;
		}

		oText.selectionStart = pos;
		oText.selectionEnd = pos;
	}
	else
	{
		oText.value += aTag + eTag;
	};
};

// ----------------------------------------------------------------------------------------------------
// - Set Cookie
// ----------------------------------------------------------------------------------------------------
function SetCookie(name, value, expire, path, domain, secure)
{
	var sCookie = '';

	if(name)
	{
		sCookie += name; // escape(name);
		sCookie += '=';
		sCookie += escape(value);

		if(expire)
		{
			sCookie += '; ';
			sCookie += escape('expires');
			sCookie += '=';
			sCookie += ((isNaN(expire) == true)? expire : new Date(parseInt(expire) * 1000).toGMTString());
		};

		if(path)
		{
			sCookie += '; ';
			sCookie += escape('path');
			sCookie += '=';
			sCookie += path; // escape(path);
		};

		if(domain)
		{
			sCookie += '; ';
			sCookie += escape('domain');
			sCookie += '=';
			sCookie += escape(domain);
		};

		if(secure)
		{
			sCookie += '; ';
			sCookie += escape('secure');
			sCookie += '=';
			sCookie += escape((secure == true) ? '1' : '0');
		};

		document.cookie = sCookie;

		return(true);
	};
};

// ----------------------------------------------------------------------------------------------------
// - Get Cookie
// ----------------------------------------------------------------------------------------------------
function GetCookie(name)
{
	var oCookie	= document.cookie.split('; ');
	var nPos	= 0;
	var i		= 0;

	for(i=0; i<oCookie.length; i++)
	{
		nPos = oCookie[i].indexOf('=');

		if(nPos != (-1))
		{
			if(unescape(oCookie[i].substr(0, nPos)) == name)
			{
				return(unescape(oCookie[i].substr(nPos + 1)));
			};
		};
	};
};
