// *******************************************************
// script by mymtw.de
// *******************************************************
// Sprache ***********************************************
// *******************************************************
tag_prompt = "Gib einen Text ein:";
font_formatter_prompt = "Gib einen Text ein - ";
link_text_prompt = "Gib einen Linknamen ein (optional)";
link_url_prompt = "Gib die volle Adresse des Links ein";
link_email_prompt = "Gib eine e-mail Adresse ein";
list_type_prompt = "Was fuer eine Liste moechtest Du? Gebe '1' ein fuer eine nummerierte Liste, 'a' fuer ein alphabetische, oder gar nichts fuer eine einfache Punktliste.";
list_item_prompt = "Gib einen Listenpunkt ein.\nGebe nichts ein oder druecke 'Cancel' um die Liste fertigzustellen.";
// *******************************************************

tags = new Array();

function getarraysize (thearray) 
{
	for (i = 0; i < thearray.length; i++) 
	{
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null)) return i;
	}
	
	return thearray.length;
}

function arraypush (thearray, value) 
{
	thearraysize		   = getarraysize(thearray);
	thearray[thearraysize] = value;
}

function arraypop (thearray) 
{
	thearraysize = getarraysize(thearray);
	retval		 = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	
	return retval;
}

// *******************************************************

function setmode (modevalue) 
{
	document.cookie = "bbcodemode=" + modevalue + "; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;";
}


function stat (theform, thevalue)
{
	theform.value = eval (thevalue + "_text");
}

function setfocus (theform, id)
{
	document.all.item(id + ':Text').focus();
}

function closetag (theform, id) 
{
	
		if (tags[0]) document.all.item(id + ':Text').value += "[/"+ arraypop(tags) +"]";

	setfocus(theform, id);
}

function closeall (theform, id) 
{

		if (tags[0]) 
		{
			while (tags[0]) 
			{
				document.all.item(id + ':Text').value += "[/" + arraypop(tags) + "]";
			}
			
			document.all.item(id + ':Text').value += " ";
		}
	
	
	setfocus(theform, id);
}
  
// *******************************************************
var selectedText = "";
AddTxt = "";

function getActiveText (msg) 
{ 
	selectedText = (document.all) ? document.selection.createRange().text : document.getSelection();
	
	if (msg.createTextRange) 
	{
		msg.caretPos = document.selection.createRange().duplicate();
	}
	
	return true;
}

function AddText (NewCode, theform, id) 
{
	if (document.all.item(id + ':Text').createTextRange && document.all.item(id + ':Text').caretPos) 
	{
		var caretPos = document.all.item(id + ':Text').caretPos;
		
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
	} 
	else 
	{
		document.all.item(id + ':Text').value += NewCode;
	}
	
	AddTxt = "";
	setfocus (theform, id);
}

function bbcode (theform, id, bbcode, prompttext) 
{
	setfocus (theform, id);
	
	if (bbcode == "IMG") 
	{
		if (selectedText) 
		{
			var dtext = selectedText;
		}
		else 
		{
			var dtext = prompttext;
		}
	
		inserttext = prompt(tag_prompt + "\n[" + bbcode + "]xxx[/" + bbcode + "]", dtext);
		
		if ((inserttext != null) && (inserttext != "")) 
		{ 
			AddTxt = "[" + bbcode + "]" + inserttext + "[/" + bbcode + "] ";
			AddText (AddTxt, theform, id);
		}
	}
	else 
	{
		donotinsert = false;
		
		for (i = 0; i < tags.length; i++) 
		{
			if (tags[i] == bbcode)
			{
				donotinsert = true;
			}
		}
		
		if (!donotinsert) 
		{
			document.all.item(id + ':Text').value += "[" + bbcode + "]";
			arraypush(tags, bbcode);
		}
	}
	
	setfocus (theform, id);
}


// *******************************************************

function fontformat (theform, id, thevalue, thetype) 
{
	setfocus(theform, id);


		if (thevalue != 0) 
		{	
			if (selectedText)
			{
				var dtext = selectedText;
			}
			else 
			{
				var dtext="";
			}
   
			inserttext = prompt (font_formatter_prompt + " " + thetype, dtext);
			
			if ((inserttext != null) && (inserttext != "")) 
			{
				AddTxt = "[" + thetype + "=" + thevalue + "]" + inserttext + "[/" + thetype + "] ";
				AddText(AddTxt, theform, id);
			}
		}
	
}

// *******************************************************

function namedlink (theform, id, thetype) 
{
	if (selectedText) 
	{ 
		var dtext = selectedText; 
	} 
	else 
	{ 
		var dtext = ""; 
	}
	
	linktext = prompt(link_text_prompt, dtext);
		
	var prompttext;
	if (thetype == "URL") 
	{
		prompt_text		= link_url_prompt;
		prompt_contents = "http://";
	}
	else 
	{
		prompt_text		= link_email_prompt;
		prompt_contents = "";
	}
	
	linkurl = prompt(prompt_text, prompt_contents);
	
	if ((linkurl != null) && (linkurl != "")) 
	{
		if ((linktext != null) && (linktext != "")) 
		{
			AddTxt = "[" + thetype + "=" + linkurl + "]" + linktext + "[/" + thetype + "] ";
			AddText(AddTxt, theform, id);
		}
		else
		{
			AddTxt = "[" + thetype + "]" + linkurl + "[/" + thetype + "] ";
			AddText(AddTxt, theform, id);
		}
	}
}

// *******************************************************

function dolist(theform, id) 
{
	listtype = prompt(list_type_prompt, "");
	
	if ((listtype == "a") || (listtype == "1")) 
	{
		thelist = "[list=" + listtype + "]\n";
		listend = "[/list=" + listtype + "] ";
	}
	else 
	{
		thelist = "[list]\n";
		listend = "[/list] ";
	}
	listentry = "initial";
	
	while ((listentry != "") && (listentry != null)) 
	{
		listentry = prompt(list_item_prompt, "");
		
		if ((listentry != "") && (listentry != null))
		{
			thelist = thelist + "[*]" + listentry + "\n";
		}
	}
	AddTxt = thelist + listend;
	AddText (AddTxt, theform, id);
}

// *******************************************************

function smilie (theform, id, thesmilie)
{
	AddSmile = " " + thesmilie + " ";
	AddText (AddSmile, theform, id);
}

function checklength (theform, id, postmaxchars)
{
	if (postmaxchars != 0)
	{
		message = " Die maximale Grenze liegt bei " + postmaxchars + " Zeichen.";
	}
	else
	{
		message = "";
	}
	
	window.alert ("Deine Nachricht ist " + document.all.item(id + ':Text').value.length + " Zeichen lang." + message);
}		

   function ClientValidate(source, arguments)
   {
      if (document.getElementById('InputSystem_Text').value.length <= 3000)
      {
         arguments.IsValid = true;
	  }
      else
      {   
         arguments.IsValid = false;
      }
   }
   
function CommonPopup(url, width, height, wndname)
{
wnd = window.open(url, wndname,'toolbar=no, location=no, scrollbars=1, width=' + width + ', height=' + height + ', left=100, top=100, alwaysRaised=true');
wnd.focus();

if (wnd.opener == null)
{ 
wnd.opener = self;
}
}
