/** Variables **/
//var aAllowedUrlStart = new Array("http://bethesda.landit.dk/", "bethesda.landit.dk/"); //Loaded in top.php

document.write("<style>");
document.write("#veil {");
document.write("    position:absolute;");
document.write("	left:0px;");
document.write("	top:expression(document.documentElement.scrollTop+document.documentElement.clientHeight-this.clientHeight);");
document.write("}");
document.write("body > div#veil {");
document.write("    position: fixed;");
document.write("    top:0px;");
document.write("	left:0px;");
document.write("}");
document.write("</style>");
document.write("<div style='width:100%;height:100%;background-color:#000000;filter:alpha(opacity=10);-moz-opacity:.10;opacity:.10;visibility:hidden; display:none; z-index:1' id='veil'></div>");

function makeSure(txt) {
	var answer = confirm(txt);
	if (answer == true) {
		return true;
	} 
	else {
		return false;
	}
}

function displayListButton(id, image, text, url, aclass, cellheight, width) {
//var asdf = image.split("@");

image_1_path = 'images/sm_'+image+'_btn_01.gif';
image_2_path = 'images/sm_btn_02.gif';
image_3_path = 'images/sm_btn_03.gif';
								
document.getElementById(id).innerHTML = ''
	+'<div style="width:'+(width+14+3)+'px; cursor:pointer;" onclick="'+ url +'" onmouseover="listButtonEffect(\'btn_'+id+'\', \''+image+'\', \'hvr\');" onmouseout="listButtonEffect(\'btn_'+id+'\', \''+image+'\', \'btn\');" onmousedown="listButtonEffect(\'btn_'+id+'\', \''+image+'\', \'clk\');" onmouseup="listButtonEffect(\'btn_'+id+'\', \''+image+'\', \'hvr\');">'
	+'	<div id="btn_'+id+'_1" style="float:left; width:14px; height:16px; background-image:url('+image_1_path+');"></div>'
	+'	<div id="btn_'+id+'_2" style="float:left; width:'+width+'px; line-height:16px; font-size:10px; height:16px; background-image:url('+image_2_path+');">'+ text +'</div>'
	+'	<div id="btn_'+id+'_3" style="float:left; width:3px; height:16px; background-image:url('+image_3_path+');"></div>'
	+'</div>';
}

function listButtonEffect(id, button, effect) {
document.getElementById(id+'_1').style.backgroundImage = 'url(images/sm_'+button+'_'+effect+'_01.gif)';
document.getElementById(id+'_2').style.backgroundImage = 'url(images/sm_'+effect+'_02.gif)';
document.getElementById(id+'_3').style.backgroundImage = 'url(images/sm_'+effect+'_03.gif)';
}

function InsertTag(StartTag, endTag, fieldId) {
	var txtarea = document.getElementById(fieldId);

	if (document.selection) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += StartTag + endTag;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = StartTag + theSelection + endTag;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		var begin = txtarea.value.substr(0, txtarea.selectionStart);
		var selection = txtarea.value.substr(txtarea.selectionStart, txtarea.selectionEnd - txtarea.selectionStart);
		var end = txtarea.value.substr(txtarea.selectionEnd);
		var newCursorPos = txtarea.selectionStart;
		var scrollPos = txtarea.scrollTop;

		txtarea.value = begin + StartTag + selection + endTag + end;

		if (txtarea.setSelectionRange)
		{
			if (selection.length == 0)
				txtarea.setSelectionRange(newCursorPos + StartTag.length, newCursorPos + StartTag.length);
			else
				txtarea.setSelectionRange(newCursorPos, newCursorPos + StartTag.length + selection.length + endTag.length);
			txtarea.focus();
		}
		return;
	}
	else
	{
		txtarea.value += StartTag + endTag;
		txtarea.focus();
	}
}

function InsertLink(fieldId) 
{
	var txtarea = document.getElementById(fieldId);
	var name = prompt("Indtast dit link",'http://');
	
	if (name != null && name != "") 
	{
		var okToProceed = false;
		/** We check to see if the url start matches the allowed url start **/
		for(x in aAllowedUrlStart)
		{
			if(name.substr(0, aAllowedUrlStart[x].length) == aAllowedUrlStart[x])
			{
				okToProceed = true;
			}
		}
		if(okToProceed)
		{
			var startTag = '[URL="'+name+'"]';
			var endTag = '[/URL]';
			if (document.selection) {
				theSelection = document.selection.createRange().text;
				if (!theSelection) {
					txtarea.value += startTag + name + endTag;
					txtarea.focus();
					return;
				}
				document.selection.createRange().text = startTag + theSelection + endTag;
				txtarea.focus();
				return;
			}
			else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
			{
				var begin = txtarea.value.substr(0, txtarea.selectionStart);
				var selection = txtarea.value.substr(txtarea.selectionStart, txtarea.selectionEnd - txtarea.selectionStart);
				var end = txtarea.value.substr(txtarea.selectionEnd);
				var newCursorPos = txtarea.selectionStart;
				var scrollPos = txtarea.scrollTop;
		
				txtarea.value = begin + startTag + selection + endTag + end;
		
				if (txtarea.setSelectionRange)
				{
					if (selection.length == 0)
						txtarea.setSelectionRange(newCursorPos + startTag.length, newCursorPos + startTag.length);
					else
						txtarea.setSelectionRange(newCursorPos, newCursorPos + startTag.length + selection.length + endTag.length);
					txtarea.focus();
				}
				return;
			}
			else
			{
				txtarea.value += startTag + name + endTag;
				txtarea.focus();
			}	
		}
	}
}