tags = new Array();

// replacements for unsupported array functions (because arrayname.push(var)
// and arrayname.pop() are not implemented in IE until version 5.5)

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 = "vbcodemode="+modevalue+"; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;"; }

function normalmode(theform) {
	if (theform.mode[0].checked) return true;
	else return false;
}

function stat(thevalue) { document.vbform.status.value = eval(thevalue+"_text"); }

function closetag(theform) {
	if (normalmode(theform)) stat('enhanced_only');
	else
		if (tags[0]) { theform.Message.value += "[/"+ arraypop(tags) +"]"; }
		else { stat('no_tags'); }
	theform.Message.focus();
}

function closeall(theform) {
	if (normalmode(theform)) stat('enhanced_only');
	else {
		if (tags[0]) {
			while (tags[0]) { theform.Message.value += "[/"+ arraypop(tags) +"]"; }
			theform.Message.value += " ";
		}
		else { stat('no_tags'); }
	}
	theform.Message.focus();
}


function vbcode(theform,vbcode,prompttext) {
	if ((normalmode(theform)) || (vbcode=="IMG")) {
		inserttext = prompt(tag_prompt+"\n["+vbcode+"]xxx[/"+vbcode+"]",prompttext);
		if ((inserttext != null) && (inserttext != "")) theform.Message.value += "["+vbcode+"]"+inserttext+"[/"+vbcode+"] ";
	}
	else {
		donotinsert = false;
		for (i = 0; i < tags.length; i++) {
			if (tags[i] == vbcode) donotinsert = true;
		}
		if (donotinsert) stat("already_open");
		else {
			theform.Message.value += "["+vbcode+"]";
			arraypush(tags,vbcode);
		}
	}
	theform.Message.focus();
}

function fontformat(theform,thevalue,thetype) {
	if (normalmode(theform)) {
		if (thevalue != 0) {
			inserttext = prompt(font_formatter_prompt+" "+thetype,"");
			if ((inserttext != null) && (inserttext != "")) theform.Message.value += "["+thetype+"="+thevalue+"]"+inserttext+"[/"+thetype+"] ";
		}
	}
	else {
		theform.Message.value += "["+thetype+"="+thevalue+"]";
		arraypush(tags,thetype);
	}
	theform.sizeselect.selectedIndex = 0;
	theform.fontselect.selectedIndex = 0;
	theform.colorselect.selectedIndex = 0;
	theform.Message.focus();
}

function namedlink(theform,thetype) {
	linktext = prompt(link_text_prompt,"");
	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 != "")) theform.Message.value += "["+thetype+"="+linkurl+"]"+linktext+"[/"+thetype+"] ";
		else theform.Message.value += "["+thetype+"]"+linkurl+"[/"+thetype+"] ";
	}
	theform.Message.focus();
}

function dolist(theform) {
	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";
	}
	theform.Message.value += thelist+listend;
	theform.Message.focus();
}

function smilie(thesmilie) {
	document.vbform.Message.value += thesmilie+" ";
	document.vbform.Message.focus();
}

function opensmiliewindow(x,y,sessionhash) { window.open("misc.php?action=getsmilies&s="+sessionhash, "smilies", "toolbar=no,scrollbars=yes,resizable=yes,width="+x+",height="+y); }