var seltext = null;
var selit = null;
var newwindow = null;

function makeBold()
{
	if (document.selection)
	{
		seltext = (document.all)? document.selection.createRange() : document.getSelection();
		selit = (document.all)? document.selection.createRange().text : document.getSelection();
		if (selit.length>=1)
		{
		        if (seltext)
		        {            
				seltext.text = '[[' + selit + ']]';
			        window.focus()
		        }
		}
	}
}

function makeItalic()
{
    seltext = (document.all)? document.selection.createRange() : document.getSelection();
    var selit = (document.all)? document.selection.createRange().text : document.getSelection();
    if (selit.length>=1)
    {
        if (seltext)
        {            
            seltext.text = '{{' + selit + '}}';
            window.focus()
        }
    }
}

function makeUnderlined()
{
    seltext = (document.all)? document.selection.createRange() : document.getSelection();
    var selit = (document.all)? document.selection.createRange().text : document.getSelection();
    if (selit.length>=1)
    {
        if (seltext)
        {            
            seltext.text = '<<' + selit + '>>';
            window.focus()
        }
    }
}

function makeBullited()
{
	 seltext = (document.all)? document.selection.createRange() : document.getSelection();
    var selit = (document.all)? document.selection.createRange().text : document.getSelection();
    if (selit.length>=1)
    {
        if (seltext)
        {            
            seltext.text = '(*' + selit + '*)';
            window.focus()
        }
    }
}

function makeLink()
{
    seltext = (document.all)? document.selection.createRange() : document.getSelection();
    var selit = (document.all)? document.selection.createRange().text : document.getSelection();
     
    seltext.text = 'link-ext(' + prompt("Indtast adressen på linket", "") + ', ' + prompt("Indtast det viste navn til linket", seltext.text) + ')';
    window.focus()
}

function OpenWindow(sURL, iWidth, iHeight)
{

	if((newwindow != null) && (!newwindow.closed))
	{
		newwindow.close();
	}
	
	newwindow = window.open("/x/function/ImageViewer.aspx?iU=" + sURL, "Billedviser", "width=" + iWidth + ", height=" + iHeight + ", top=100, left=100, screenY=100, screenX=100, scrollbars=no, status=no");
	
	newwindow.focus();
	
}

function OpenSendLinkToFriendWindow(sUrl, sName, iWidth, iHeight, iLeft, iTop)
{
	window.open(sUrl, sName, "width=" + iWidth + ", height=" + iHeight + ", top=" + iTop + ", left=" + iLeft + ", screenY=" + iTop + ", screenX=" + iLeft);
}

function Bookmark()
{
	var title = document.title;
	var url = location.href;

	if (window.sidebar)
		window.sidebar.addPanel(title, url,"");
	else if (window.opera && window.print)
	{
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	}
	else if (document.all)
		window.external.AddFavorite( url, title);
}

function PrintView(sPageName)
{
	newwindow = window.open('/Print?ID=' + sPageName, 'PrintView', 'height=600,width=700,top=100,left=100,screenY=100,screenX=100,scrollbars=yes,status=no');
	newwindow.focus();
}

function TextPopUp(sText)
{
	var mywindow=window.open("","help","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,width=300,height=255,screenX=500,screenY=100");
	mywindow.document.write("<HTML><HEAD><TITLE></TITLE></HEAD><BODY>");
	mywindow.document.write(sText);
	mywindow.document.write("<FORM><INPUT TYPE='button' VALUE='Close this Window' onClick='window.close()'></FORM></BODY></HTML>");
}

function MaxChars(inputID, iMax)
{
	var txtInput = document.getElementById(inputID);
	var iTotal = txtInput.value.length;
		
	if (iTotal > iMax)
	{
		var iOverflow = txtInput.value.length - iMax;
		txtInput.value = txtInput.value.substring(0, iMax);
		
		if (iOverflow > 2)
			alert('Du kan maksimalt indtaste ' + iMax + ' tegn per modul.\r\nDer blev indsat ' + iTotal + ' tegn.\r\n' + iOverflow + ' tegn blev fjernet!');
		else
			alert('Du kan maksimalt indtaste ' + iMax + ' tegn per modul.');
	}
}