function setLinks(expand) {
	var themenu = document.getElementById('fixedmenu1');
	var more = document.getElementById('expandlink');
	var less = document.getElementById('despandlink');
		if (expand == true){
			themenu.style.display = 'block';
			more.style.display = 'none';
			less.style.display = 'block';
		}
		if (expand == false){
			themenu.style.display = 'none';
			more.style.display = 'block';
			less.style.display = 'none';
		}
}

function setProfiles(altern) {
	var content1 = document.getElementById('plainprofile');
	var content2 = document.getElementById('alternprofile');
	var links1 = document.getElementById('plainlinks');
	var links2 = document.getElementById('alternlinks');
	var alt = document.getElementById('alternate');
	var alt1 = document.getElementById('alternate1');
		if (altern == true){
			content1.style.display = 'none';
			content2.style.display = 'block';
			links1.style.display = 'none';
			links2.style.display = 'block';
			alt.style.display = 'block';
			alt1.style.display = 'none';
		}
		if (altern == false){
			content1.style.display = 'block';
			content2.style.display = 'none';
			links1.style.display = 'block';
			links2.style.display = 'none';
			alt.style.display = 'none';
			alt1.style.display = 'block';
		}
}

/*function writeImgTag(code) {
	var cache = document.getElementById('f').article.value;
	this.code = code;
	document.getElementById('f').article.value = cache + code;
	document.getElementById('f').article.focus();
}

function writeCodeTag(code) {
	var cache = document.getElementById('f').article.value;
	this.code = code;
	document.getElementById('f').article.value = cache + code;
	document.getElementById('f').article.focus();
}

function writeUrlTag(){

	if(navigator.userAgent.indexOf('MSIE 7')>0){
		IEprompt('Please type in the URL:', 'http://');
	} else {
		var code = '[url="' + prompt('Please type in the URL:', 'http://', true) + '"][/url]';
		var cache = document.getElementById('f').article.value;
		this.code = code;
		document.getElementById('f').article.value = cache + code;
		document.getElementById('f').article.focus();
	}
}
*/

/***********************************
/*
/* This function is where all the magic happens to
/* allow the client to add an element to the textarea
/* and have the cursor positioned after that element
/*
/***********************************/

function insertAtCaret(obj, text) {
//	var obj = document.getElementById('f').article;
//	var text = "This is the stuff that goes into the textarea";
    if(document.selection) {
        // Go the IE way
        /* First of all, focus the object, we want to work with
		   If we do not do so, it is possible, that the selection
		   is not, where we expect it to be
		*/
		obj.focus();

		/* Create a TextRange based on the document.selection
		   This TextRanged can be used to replace the selected
		   Text with the new one
		*/
		var range = document.selection.createRange();

		/* If the range is not part of our Object (remember the
		   textarea or input field), stop processing here
		*/
		if(range.parentElement() != obj) {
		    return false;
		}

		/* Save the current value. We will need this value later
		   to find out, where the text has been changed
		*/
		var orig = obj.value.replace(/rn/g, "n");

		/* Replace the Text */
		range.text = text;

		/* Now get the new content and save it into
		   a temporary variable
		*/
		var actual = tmp = obj.value.replace(/rn/g, "n");

		/* Find the first occurance, where the original differs
		   from the actual content. This could be the startposition
		   of our text selection, but it has not to be. Think of the
		   selection "ab" and replacing it with "ac". The first
		   difference would be the "c", while the start position
		   is the "a"
		*/
		for(var diff = 0; diff < orig.length; diff++) {
		    if(orig.charAt(diff) != actual.charAt(diff)) break;
		}

		/* To get the real start position, we iterate through
		   the string searching for the whole replacement
		   text - "abc", as long as the first difference is not
		   reached. If you do not understand that logic - no
		   blame to you, just copy & paste it ;)
		*/
		for(var index = 0, start = 0;
		    tmp.match(text)
		        && (tmp = tmp.replace(text, ""))
		        && index <= diff;
		    index = start + text.length
		) {
		    start = actual.indexOf(text, index);
		}
    } else if(obj.selectionStart) {
        // Go the Gecko way
        /* Find the Start and End Position */
		var start = obj.selectionStart;
		var end   = obj.selectionEnd;

		/* Remember obj is a textarea or input field */
		obj.value = obj.value.substr(0, start)
		    + text
		    + obj.value.substr(end, obj.value.length);
    }

	if(start != null) {
		setCaretTo(obj, start + text.length);
	} else {
		obj.value += text;
	}

	function setCaretTo(obj, pos) {
		if(obj.createTextRange) {
			var range = obj.createTextRange();
			range.move('character', pos);
			range.select();
		} else if(obj.selectionStart) {
			obj.focus();
			obj.setSelectionRange(pos, pos);
		}
	}
}

/***********************************
/*
/* This function writes a URL to the form textarea
/* with a special version for IE 7 (Typical)
/*
/***********************************/

function writeUrlTag(){
	if(navigator.userAgent.indexOf('MSIE 7')>0){
		IEprompt('Please type in the URL:', 'http://');
		IEprompt('Please type in a title:', '');
	} else {
		var obj = document.getElementById('f').article;
		var popme = prompt('Please type in the URL:', 'http://', true);
		var popme1 = prompt('Please type in a title:', '', true);
		if(popme){
			var text = '[url="' + popme + '" title="' + popme + '"][/url]';
		} else {
			return false;
		}
		insertAtCaret(obj, text);
	}
}

/***********************************
/*
/* This function writes one of a number of tags
/* to the textarea... nice and simple
/*
/***********************************/

function writeCodeTag(code){
	var obj = document.getElementById('f').article;
	var text = code;
	insertAtCaret(obj, text);
}

/***********************************
/*
/* This function writes one of a number of
/* smilies to the textarea... nice and simple too
/*
/***********************************/

function writeImgTag(code) {
	var obj = document.getElementById('f').article;
	var text = code;
	insertAtCaret(obj, text);
}
function writeImgTagBlog(code) {
	var obj = document.getElementById('blogF').article;
	var text = code;
	insertAtCaret(obj, text);
}

/**
 * This funtion adds the functionality
 * of youtube videos at the click of a link
 *
 **/

function addVid(){
	var obj = document.getElementById('f').article;
	var sUrl = prompt("Please type in video code:\nE.g. cvS-2dK1X4I", "");
	if(sUrl){
		var vidCode = "<object type=\"application/x-shockwave-flash\" data=\"http://www.youtube.com/v/"+ sUrl+ "\" width=\"400\" height=\"326\" class=\"youTube\">\n<param name=\"movie\" value=\"http://www.youtube.com/v/"+ sUrl +"\" />\n<param name=\"allowScriptAcess\" value=\"sameDomain\" />\n<param name=\"quality\" value=\"best\" />\n<param name=\"scale\" value=\"noScale\" />\n<param name=\"salign\" value=\"TL\" />\n<param name=\"FlashVars\" value=\"playerMode=embedded\" />\n</object>";
	} else {
		return false;
	}
	insertAtCaret(obj, vidCode);
}
//window.onload(setLinks);
//window.onload(setProfiles);