<!--

//var selField  = 'post_message';
var selMode   = "normal";

var url_text      = "Please insert the URL (Ex: http://www.google.com/)";
var webpage_text  = "Please insert the address title (Ex: Google)";
var title_text	  = "Optional: Enter a title attribute";
var image_text    = "Please insert the image link (Ex: http://www.nice-domain.com/image.gif)";
var email_text    = "Pleas einsert an e-mail address";
var email_title   = "Please insert the title of the e-mail address(or leave it blank, to show it like the address) Ex: 'My e-mail address'";
var enter_text    = "Please insert the text you would like to format";

var button_0 = 0;
var button_1 = 0;
var button_2 = 0;
var button_3 = 0;
var button_4 = 0;


tagarray  = new Array();
usedarray = new Array();

function nullo()
{
	return;
}
		
//  State change

function styleswap(link)
{
	if (document.getElementById(link).className == 'htmlButtonOff')
	{
		document.getElementById(link).className = 'htmlButtonOn';
	}
	else
	{
		document.getElementById(link).className = 'htmlButtonOff';
	}
}

//  Set button mode

function setmode(which)
{	
	if (which == 'guided')
		selMode = 'guided';
	else
		selMode = 'normal';
}

// Clear state

function clear_state()
{
	if (usedarray[0])
	{
		while (usedarray[0])
		{
			clearState = arraypop(usedarray);
			
			eval(clearState + " = 0");
			
			document.getElementById(clearState).className = 'htmlButtonOff';
		}
	}	
}

// Array size

function getarraysize(thearray)
{
	for (i = 0; i < thearray.length; i++)
	{
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
		{
			return i;
		}
	}
	
	return thearray.length;
}        

// Array push

function arraypush(thearray, value)
{
	thearray[getarraysize(thearray)] = value;
}

// Array pop

function arraypop(thearray)
{
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

// Insert single tag

function singleinsert(tagOpen)
{		
	eval("document.submit_topic." + selField + ".value += tagOpen");	
	
	curField = eval('document.submit_topic.' + selField);
	curField.blur();
	curField.focus();	
}


// Insert font color and size

function selectinsert(item, tag)
{
	var selval =  item.options[item.selectedIndex].value;
		
    if (selval == 0)
    	return;

	var tagOpen		= '[' + tag + '=' + selval + ']';
	var tagClose	= '[/' + tag + ']';
		
	taginsert('other', tagOpen, tagClose, 'menu');
}

// Insert tag

var tagarray  	= new Array();
var usedarray 	= new Array();
var running		= 0;

function taginsert(item, tagOpen, tagClose, type)
{
	// Determine which tag we are dealing with

	var which = eval('item.name');
	
	var theSelection = false;  
	var result		 = false;
	eval("var theField = document.submit_topic." + selField + ";");
		
	if (selMode == 'guided')
	{
		data = prompt(enter_text, "");
		
		if ((data != null) && (data != ""))
		{
			result = tagOpen + data + tagClose;		
		}
	}

	// Is this a Windows user?  
	
	// If so, add tags around selection

	if (document.selection) 
	{
		theSelection = document.selection.createRange().text;
		
		theField.focus();
	
		if (theSelection)
		{
			document.selection.createRange().text = (result == false) ? tagOpen + theSelection + tagClose : result;
		}
		else
		{
			document.selection.createRange().text = (result == false) ? tagOpen + tagClose : result;
		}
		
		theSelection = '';
		
		theField.blur();
		theField.focus();
		
		return;
	}
	else if ( ! isNaN(theField.selectionEnd))
	{
		var selLength = theField.textLength;
		var selStart = theField.selectionStart;
		var selEnd = theField.selectionEnd;
		if (selEnd <= 2)
			selEnd = selLength;

		var s1 = (theField.value).substring(0,selStart);
		var s2 = (theField.value).substring(selStart, selEnd)
		var s3 = (theField.value).substring(selEnd, selLength);
		
		if (result == false)
		{
			var newStart = selStart + tagOpen.length + s2.length + tagClose.length;
		
			theField.value = (result == false) ? s1 + tagOpen + s2 + tagClose + s3 : result;
		}
		else
		{
			var newStart = selStart + result.length;
		
			theField.value = s1 + result + s3;
		}
		
		theField.focus();
		theField.selectionStart = newStart;
		theField.selectionEnd = newStart;
		return;
	}
	else if (selMode == 'guided')
	{
		eval("document.submit_topic." + selField + ".value += result");			
		
		curField = eval('document.submit_topic.' + selField);
		curField.blur();
		curField.focus();	
		return;		
	}
	
		
	// Add single open tags
	
	if (item == 'other')
	{
		if (tagClose)
		{
			eval("document.submit_topic." + selField + ".value += tagOpen + tagClose");
		}
		else
		{
			eval("document.submit_topic." + selField + ".value += tagOpen");
		}
	}
	else if (eval(which) == 0)
	{
		var result = tagOpen;
		
		eval("document.submit_topic." + selField + ".value += result");			
		eval(which + " = 1");
		
		arraypush(tagarray, tagClose);
		arraypush(usedarray, which);
		
		running++;
					   
		styleswap(which);
	}
	else
	{
		// Close tags
	
		n = 0;
		
		for (i = 0 ; i < tagarray.length; i++ )
		{
			if (tagarray[i] == tagClose)
			{
				n = i;
				
				running--;
				
				while (tagarray[n])
				{
					closeTag = arraypop(tagarray);
					eval("document.submit_topic." + selField + ".value += closeTag");			
				}
				
				while (usedarray[n])
				{
					clearState = arraypop(usedarray);
					eval(clearState + " = 0");
					document.getElementById(clearState).className = 'htmlButtonA';
				}						
			}
		}
	}
	
	curField = eval('document.submit_topic.' + selField);
	curField.blur();
	curField.focus();
}

// Prompted tags

function promptTag(which)
{

	if ( ! which)
		return;
		
	// Is this a Windows user?  
		
	var theSelection = "";    
	eval("var theField = document.submit_topic." + selField + ";");
	
	if ((navigator.appName == "Microsoft Internet Explorer") &&
		(navigator.appVersion.indexOf("Win") != -1))
	{
		theSelection = document.selection.createRange().text; 
	}
	else if (theField.selectionEnd && (theField.selectionEnd - theField.selectionStart > 0))
	{
		var selLength = theField.textLength;
		var selStart = theField.selectionStart;
		var selEnd = theField.selectionEnd;
		if (selEnd == 1 || selEnd == 2)
			selEnd = selLength;

		var s1 = (theField.value).substring(0,selStart);
		var s2 = (theField.value).substring(selStart, selEnd)
		var s3 = (theField.value).substring(selEnd, selLength);
		theSelection = s2;
	}
	
	// Create Link
	if (which == "link")
	{
		var URL = prompt(url_text, "http://");
				
		if ( ! URL || URL == 'http://' || URL == null)
			return; 
		
		var Name = prompt(webpage_text, theSelection);
		
		if ( ! Name || Name == null)
			return; 
				
		var Link = '[url=' + URL + ']' + Name + '[/url]';
	}
	
	
	if (which == "image")
	{
		var URL = prompt(image_text, "http://");
				
		if ( ! URL || URL == 'http://' || URL == null)
			return; 
							
		var Link = '[img]' + URL + '[/img]';
	}
	
	
	if (which == "email")
	{
		var Email = prompt(email_text,"");
		
		if ( ! Email || Email == null)
			return; 
			
		var Title = prompt(email_title, theSelection);
		
		if (Title == null)
			return; 
	
		if (Title == "")
			Title = Email;
	
		var Link = '[' + 'email=' + Email + ']' + Title + '[' + '/email]';                
	}

	if ((navigator.appName == "Microsoft Internet Explorer") &&
		(navigator.appVersion.indexOf("Win") != -1))
	{
		if (theSelection != "")
		{
			document.selection.createRange().text = Link;
		}
		else
		{
			eval("document.submit_topic." + selField + ".value += Link");			
		}
	}
	else if (theField.selectionEnd && (theField.selectionEnd - theField.selectionStart > 0))
	{
		theField.value = s1 + Link + s3;
	}
	else
	{
		eval("document.submit_topic." + selField + ".value += Link");			
	}
	
	curField = eval('document.submit_topic.' + selField);
	curField.blur();
	curField.focus();
}

// Close all tags

function closeall()
{	
	if (tagarray[0])
	{
		while (tagarray[0])
		{
			closeTag = arraypop(tagarray);
						
			eval("document.submit_topic." + selField + ".value += closeTag");			
		}
	}
	
	clear_state();	
	curField = eval('document.submit_topic.' + selField);
	curField.focus();
}


function show_textbox(message_id,text,topic_id,forum_id) 
{ 
 var message  = "<fieldset id=\"edit_message\">\n";						
	   message += "<form name=\"edit_message\" action=\"forum_";						
		 message += forum_id;
		 message += "_topic_";						
		 message += topic_id;
		  message += "_post_";						
		 message += message_id;
		 message += "_edit_message.html\" method=\"post\" onSubmit=\"return validateCompleteForm(this, 'error_form');\">\n";
		 message += "<p><label for=\"edit_message\"><span class=\"notice\">*</span>Message</label><textarea name=\"edit_message\" name=\"edit_message\" realname=\"Message\" required=\"1\" id=\"edit_message\" wrap=\"virtual\">";
		 message += text;
	   message += "</textarea></p>";
		 message += "<input type=\"hidden\" name=\"message_id\" value=\"";
		 message += message_id;
		 message += "\">";
		 message += "<input type=\"hidden\" name=\"forum_id\" value=\"";
		 message += forum_id;
		 message += "\">";
		 message += "<input type=\"hidden\" name=\"topic_id\" value=\"";
		 message += topic_id;
		 message += "\">";
		 message += "<label for=\"post_sent\">&nbsp;</label><p class=\"button_p\"><input id=\"post_sent\" type=\"submit\" name=\"sent\" value=\"Save &#187;\" class=\"button\"><input type=\"button\" name=\"cancel\" value=\"Cancel &#187;\" onClick=\"javascript:location.reload(true)\" class=\"button\"></p>";
		 message += "</form>";								
					
	  document.getElementById(message_id).innerHTML  = message;					 					
} 
				


//-->