var FF15 = (-1 != navigator.userAgent.indexOf('Firefox/1.5'));
var ie = /*@cc_on!@*/false; //(-1 != navigator.appName.indexOf('Microsoft'));
var firefox = (ie ? false : (/(Firefox|Iceweasel)/.test(navigator.userAgent)));
var opera = !ie && !firefox && navigator.userAgent.indexOf('Opera');
var fragment;
var selectedText = '';
var comparetoText;
var inmsgid;
function showquotelink(element,id,name) {
	var hashValue = "bottom";

	if (hashValue == window.location.hash)
    {
         window.location.hash = new String((new Date().getMilliseconds()));
    }

	document.write(
		'<a class="cite"' + (
			firefox
		?	' onmouseover="storeSelection('+id+')"'
		:	''
		) + ' onclick="window.location.hash=\'bottom\'; return quoteElement(\'' + element + '\',' + id + (name ? ',\''+name+'\'' : '') + ')">'
	);
}
function storeSelection() {
	inmsgid = 0;
	if (window.getSelection || document.getSelection)
        {
		var selection = window.getSelection ? window.getSelection() : document.getSelection();
		if (!selection) {
			return;
		}
		if (typeof selection == 'string') {
			if (selection) {
				selectedText = comparetoText = selection;
			}
		} else {
			var node = selection.anchorNode;
			while (node && (!node.id || !node.id.match(/^m(\d+)$/))) {
				node = node.parentNode;
			}
			if (node) {
				inmsgid = RegExp.$1;
			}
						var newtext = selection.toString();
			if (newtext) {
				selectedText = selection.toString();
			
				comparetoText =
					selectedText
				&&	selection.getRangeAt
				?	selection.getRangeAt(0).cloneContents().textContent
				:	selectedText;
			}
		}
	} else if (
		document.selection
	&&	document.selection.type == 'Text'
	) {
		var newtext = document.selection.createRange().text;
		if (newtext) {
			selectedText = comparetoText = newtext;
		}
	}
}
function quoteElement(element,id,name) {
	if (!firefox) {
		if (window.getSelection) {
			selectedText = window.getSelection();
			if (!selectedText) {
				alert('Je moet wel een stuk tekst selecteren om te  citeren! (1)');
				return false;
			}
		} else if (!document.selection) {
			alert('Je browser ondersteunt deze citeerfunctie niet! (1)');
			return false;
		} else if (document.selection.type == 'None') {
			alert('Je moet wel een stuk tekst selecteren om te  citeren! (2)');
			return false;
		} else if (document.selection.type == 'Text') {
			selectedText = document.selection.createRange().text;
			if (!selectedText) {
				alert('Je moet wel een stuk tekst selecteren om te  citeren! (3)');
				return false;
			}
		}
	} else if (!selectedText) {
		alert('Je moet wel een stuk tekst selecteren om te  citeren! (4)');
		return false;
	}
	// when firefox is used, and only a smiley is selected,
	// selectedText is not empty, but comparetoText is! 
	// just continue, we have already checked whether something was selected
	if (firefox && comparetoText || !firefox && selectedText) {
		var obj = document.getElementById('body_' + id);
		if (!obj) {
			alert('Internal error (body_'+id+' not found)');
			return false;
		}
		var containerText;
		if (obj.innerText) {
			containerText = obj.innerText;
		} else if (obj.textContent) {
			containerText = obj.textContent;
		} else {
			alert('Je browser ondersteunt deze citeerfunctie niet! (2)');
			showProperties(obj);
			return false;
		}
		if (	firefox
		?	-1 == containerText.indexOf(comparetoText)
		:	-1 == containerText.indexOf(selectedText)
		) {
			alert('Je moet "citeer" van het juiste bericht klikken!');
			return false;
		}
	}
	if (fillElement('inputbody',element,id,name)) {

	}
	else {
		alert(	'invoerveld is niet te vinden.\n' +
		'Waarschijnlijk is het onderwerp reeds gesloten of heb je reeds een reactie geplaatst.'
	);
	return false;
	}
}
function fillElement(objname,element,id,name) {
	var obj = document.getElementById(objname);
	if (!obj) {
		return false;
	}
	if (obj.value) {
		obj.value += '\n';
	}
	obj.value += '[quote="[url=http://www.flitsservice.nl/phpBB/post' + id + '.html#p' + id + ']' + name + '[/url]"] ' + selectedText + '[/quote]\n';
	return true;
}

