// textbox

helpstat = false;
stprompt = false;
basic = true;

function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 0) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 2) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}

function AddText(text) {
	var tarea = document.formulier.textbox;
	if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
		start = tarea.selectionStart;
		end = tarea.selectionEnd;
		tarea.value = tarea.value.substr(0,tarea.selectionStart)
			+ text + tarea.value.substr(tarea.selectionEnd);
		tarea.focus();
		tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
		tarea.selectionEnd = start + text.length;
	} else {
		if (tarea.createTextRange && tarea.caretPos) {
			var caretPos = tarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?   text + ' ' : text;
		}
		else {
			tarea.value += text;
		}
		tarea.focus(caretPos);
	}
}

function bold() {
	var text = getText();
	if (helpstat) {
		alert("[b][/b] maakt de tekst vet.\n\nGebruik: [b]Dit is vette tekst.[/b]");
	} else if (basic) {
		AddTxt="[b]" + text + "[/b]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die VET moet worden.",text);
		} else {
			txt=prompt("Tekst die VET moet worden.","Tekst");
		}
		if (txt!=null) {
			AddTxt="[b]"+txt+"[/b]";
			AddText(AddTxt);
		}
	}
}

function italicize() {
	var text = getText();
	if (helpstat) {
		alert("[i][/i] maakt de tekst schuin.\n\nGebruik: [i]Dit is schuine tekst.[/i]");
	} else if (basic) {
		AddTxt="[i]" + text + "[/i]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die SCHUIN moet worden",text);
		} else {
			txt=prompt("Tekst die SCHUIN moet worden","Tekst");
		}
		if (txt!=null) {
			AddTxt="[i]"+txt+"[/i]";
			AddText(AddTxt);
		}
	}
}

function underline() {
	var text = getText();
  	if (helpstat) {
		alert("[u][/u] maakt de tekst onderstreept.\n\nGebruik: [u]Dit is onderstreepte tekst.[/u]");
	} else if (basic) {
		AddTxt="[u]" + text + "[/u]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die ONDERSTREEPT moet worden.",text);
		} else {
			txt=prompt("Tekst die ONDERSTREEPT moet worden.","Tekst");
		}
		if (txt!=null) {
			AddTxt="[u]"+txt+"[/u]";
			AddText(AddTxt);
		}
	}
}

function strike() {
	var text = getText();
	if (helpstat) {
		alert("[s][/s] maakt de tekst doorgestreept.\n\nGebruik: [s]Dit is doorgestreepte tekst.[/s]");
	} else if (basic) {
		AddTxt="[s]" + text + "[/s]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die DOORGESTREEPT moet worden.",text);
		} else {
			txt=prompt("Tekst die DOORGESTREEPT moet worden.","Tekst");
		}
		if (txt!=null) {
			AddTxt="[s]"+txt+"[/s]";
			AddText(AddTxt);
		}
	}
}

function left() {
	var text = getText();
 	if (helpstat) {
		alert("[left][/left] lijnt de tekst links uit.\n\nGebruik: [left]Deze tekst is links uitgelijnd.[/left]");
	} else if (basic) {
		AddTxt="[left]" + text + "[/left]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die LINKS uitgelijnd moet worden.",text);
		} else {
			txt=prompt("Tekst die LINKS uitgelijnd moet worden.","Tekst");
		}
		if (txt!=null) {
			AddTxt="[left]"+txt+"[/left]";
			AddText(AddTxt);
		}
	}
}

function center() {
	var text = getText();
 	if (helpstat) {
		alert("[center][/center] centreert de tekst.\n\nGebruik: [center]Deze tekst is gecentreerd.[/center]");
	} else if (basic) {
		AddTxt="[center]" + text + "[/center]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die GECENTREERD moet worden.",text);
		} else {
			txt=prompt("Tekst die GECENTREERD moet worden.","Tekst");
		}
		if (txt!=null) {
			AddTxt="[center]"+txt+"[/center]";
			AddText(AddTxt);
		}
	}
}

function right() {
	var text = getText();
 	if (helpstat) {
		alert("[right][/right] lijnt de tekst rechts uit.\n\nGebruik: [right]Deze tekst is right uitgelijnd.[/right]");
	} else if (basic) {
		AddTxt="[right]" + text + "[/right]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die RECHTS uitgelijnd moet worden.",text);
		} else {
			txt=prompt("Tekst die RECHTS uitgelijnd moet worden.","Tekst");
		}
		if (txt!=null) {
			AddTxt="[right]"+txt+"[/right]";
			AddText(AddTxt);
		}
	}
}

function hr() {
	var text = getText();
	if (helpstat) {
		alert("[hr] tekent een horizontale lijn.\n\nGebruik: [hr]");
	} else {
		AddTxt="[hr]" + text;
		AddText(AddTxt);
	}
}

function hyperlink() {
	if (helpstat) {
		alert("[url][/url] \nMaakt van een URL een werkende LINK\n\nGebruik: [url]http://www.hierkomtdesite.com[/url]\n\nOf: [url=\"http://www.hierkomtdesite.com\"]link tekst[/url]");
	    }
	else {
		txt2=prompt("Tekst die als link getoond moet worden.\nLaat het invoerveld leeg als de link zelf als link getoond moet worden.","");
		if (txt2!=null) {
			txt=prompt("URL voor de link.","http//:");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt=txt;
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}
			}
		}
	}
}

function email() {
	if (helpstat) {
		alert("Maakt van een e-mailadres een werkende Mailto:-LINK\n\nGebruik: iemand\@ergens.com \nOf: [url=\"iemand\@ergens.com\"]link tekst[/url]");
		}
	else {
		txt2=prompt("Tekst die als link getoond moet worden.\nLaat het invoerveld leeg als het e-mailadres zelf als link getoond moet worden.","");
		if (txt2!=null) {
			txt=prompt("URL voor de link.","mailto:");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt=txt;
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}
			}
		}
	}
}

function image() {
	var text = getText();
	if (helpstat){
		alert("Voegt een plaatje toe.\n\nGebruik: [img]http://www.ergens.com/plaatje.gif[/img]");
	} else if (basic) {
		AddTxt="[img]" + text + "[/img]";
		AddText(AddTxt);
	} else {
		txt=prompt("URL voor het plaatje","http://");
		if(txt!=null) {
			AddTxt="[img]"+txt+"[/img]";
			AddText(AddTxt);
		}
	}
}

function quote() {
	var text = getText();
	if (helpstat) {
		alert("[quote][/quote] zorgt ervoor dat de tekst als een citaat wordt gezien.\n\nGebruik: [quote]Dit is een citaat.[/quote]");
	} else if (basic) {
		AddTxt="[quote]" + text + "[/quote]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die geciteerd moet worden.",text);
		} else {
			txt=prompt("Tekst die geciteerd moet worden.","Tekst");
		}
		if (txt!=null) {
			AddTxt="[quote]"+txt+"[/quote]";
			AddText(AddTxt);
		}
	}
}

function list() {
	if (helpstat) {
		alert("List Tag Builds a bulleted, numbered, or alphabetical list.\n\nUSE: [list] [*]item1[/*] [*]item2[/*] [*]item3[/*] [/list]");
	} else if (basic) {
		AddTxt=" [list][*]  [/*][*]  [/*][*]  [/*][/list]";
		AddText(AddTxt);
	} else {
		type=prompt("Type of list Enter \'A\' for alphabetical, \'1\' for numbered, Leave blank for bulleted.","");
		while ((type!="") && (type!="A") && (type!="a") && (type!="1") && (type!=null)) {
			type=prompt("ERROR! The only possible values for type of list are blank 'A' and '1'.","");
		}
		if (type!=null) {
			if (type=="") {
				AddTxt="[list]";
			} else {
				AddTxt="[list="+type+"]";
			}
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt("List item Leave blank to end list","");
				if (txt!="") {
					AddTxt+="[*]"+txt+"[/*]";
				}
			}
			if (type=="") {
				AddTxt+="[/list] ";
			} else {
				AddTxt+="[/list="+type+"]";
			}
			AddText(AddTxt);
		}
	}
}

function showfont(font) {
	var text = getText();
 	if (font) {
	 	if (helpstat) {
			alert("Font Tag Sets the font face for the enclosed text.\n\nUSE: [font="+font+"]The font of this text is "+font+"[/font]");
		} else if (basic) {
			AddTxt="[font="+font+"]" + text + "[/font="+font+"]";
			AddText(AddTxt);
		} else {
			if (text) {
				txt=prompt("Text to be in "+font,text);
			} else {
				txt=prompt("Text to be in "+font,"Text");
			}
			if (txt!=null) {
				AddTxt="[font="+font+"]"+txt+"[/font="+font+"]";
				AddText(AddTxt);
			}
		}
	document.formulier.Font.selectedIndex = 0;
	}
}

function showsize(size) {
	var text = getText();
	if (size) {
		if (helpstat) {
			alert("Size Tag Sets the text size. Possible values are 1 to 6.\n1 being the smallest and 6 the largest.\n\nUSE: [size="+size+"]This is size "+size+" text[/size="+size+"]");
		} else if (basic) {
			AddTxt="[size="+size+"]" + text + "[/size="+size+"]";
			AddText(AddTxt);
		} else {
			if (text) {
				txt=prompt("Text to be size "+size,text);
			} else {
				txt=prompt("Text to be size "+size,"Text");
			}
			if (txt!=null) {
				AddTxt="[size="+size+"]"+txt+"[/size="+size+"]";
				AddText(AddTxt);
			}
		}
	document.formulier.Size.selectedIndex = 0;
	}
}

function showcolor(color) {
	var text = getText();
	if (color) {
		if (helpstat) {
			alert("Color Tag Sets the text color. Any named color can be used.\n\nUSE: ["+color+"]This is some "+color+" text[/"+color+"]");
		} else if (basic) {
			AddTxt="["+color+"]" + text + "[/"+color+"]";
			AddText(AddTxt);
		} else {
			if (text) {
		     		txt=prompt("Text to be "+color,text);
			} else {
	     			txt=prompt("Text to be "+color,"Text");
			}
			if(txt!=null) {
				AddTxt="["+color+"]"+txt+"[/"+color+"]";
				AddText(AddTxt);
			}
		}
	document.formulier.Color.selectedIndex = 0;
	}
}

function storeCaret(ftext) {
	if (ftext.createTextRange) {
		ftext.caretPos = document.selection.createRange().duplicate();
	}
}

function getText() {
	var tarea = document.formulier.textbox;
	if (tarea.createTextRange && tarea.caretPos) {
		return tarea.caretPos.text;
	} else if (typeof tarea.selectionStart != 'undefined'){
		return tarea.value.substr(tarea.selectionStart,tarea.selectionEnd-tarea.selectionStart)
	}
	return '';
}

function exlink() {
	var text = getText();
	if (helpstat) {
		alert("[exlink][/exlink] voegt een externe link toe.\n\nGebruik: [exlink]url^linktekst[/exlink]");
	} else if (basic) {
		AddTxt="[exlink]url^linktekst[/exlink]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die VET moet worden.",text);
		} else {
			txt=prompt("Tekst die VET moet worden.","Tekst");
		}
		if (txt!=null) {
			AddTxt="[b]"+txt+"[/b]";
			AddText(AddTxt);
		}
	}
}

function maillink() {
	var text = getText();
	if (helpstat) {
		alert("[maillink][/maillink] voegt een mail link toe.\n\nGebruik: [maillink]e-mailadres^linktekst[/maillink]");
	} else if (basic) {
		AddTxt="[maillink]e-mailadres^linktekst[/maillink]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Tekst die VET moet worden.",text);
		} else {
			txt=prompt("Tekst die VET moet worden.","Tekst");
		}
		if (txt!=null) {
			AddTxt="[b]"+txt+"[/b]";
			AddText(AddTxt);
		}
	}
}