/* ------------------------------------------------
   Smack JavaScript application library
   All code Copyright Smack 2000-2007.
   Author: Eric Svensson
------------------------------------------------ */


/* -----------------------------
            Quotation
----------------------------- */

var docSelectedText = "";
var quotePreStr = '<br /><div class="viewQuoteBox" contenteditable="false">';
    quotePreStr += '<div class="viewQBCR1" contenteditable="false"><img src="http://img.playing.se/playing.se/filler.gif" width="1" height="1" alt="" /></div>';
    quotePreStr += '<div class="viewQBCR2" contenteditable="false"><img src="http://img.playing.se/playing.se/filler.gif" width="1" height="1" alt="" /></div>';
    quotePreStr += '<div class="viewQuoteBoxInner"'+(!browser_opera ? ' contenteditable="true"' : '')+'><h1>##quoteHeader##<br /></h1>'
var quoteSufStr='</div>';
    quoteSufStr += '<div class="viewQBCR2" contenteditable="false"><img src="http://img.playing.se/playing.se/filler.gif" width="1" height="1" alt="" /></div>';
    quoteSufStr += '<div class="viewQBCR1" contenteditable="false"><img src="http://img.playing.se/playing.se/filler.gif" width="1" height="1" alt="" /></div>';
    quoteSufStr += '</div><br />';

function gfiQuoteListenerM(e) {
	$('#gfiQuoteTA').val('');
	if (browser_ie) {
		var selRange=document.selection.createRange();
		var selText=selRange.text;
	}
	$('#gfiQuoteTA').val(browser_ie ? selText : (browser_gecko ? window.getSelection() : window.document.getSelection()));
}
function gfiQuoteListenerS(e) {
	window.document.onmouseup = gfiQuoteListenerE;
	window.document.onmousemove = gfiQuoteListenerM;
}
function gfiQuoteListenerE(e) {
	window.document.onmouseup = null;
	window.document.onmousemove = updateMousePositionCoords;
}
function initQuoteInsert() {
	MM_showHideLayers('gfiFrameQuote','','show');
	$('#gfiQuoteTA').val('');
	window.document.onmousedown = gfiQuoteListenerS;
}
function closeQuoteInsert() {
	window.document.onmousedown = textSelectionListenerS;
	window.document.onmouseup = null;
	MM_showHideLayers('gfiFrameQuote','','hide');
}
function insertQuoteVal() {
	rtef.insertHTML(quotePreStr.replace('##quoteHeader##','Citat:')+$('#gfiQuoteTA').val()+quoteSufStr);
	closeQuoteInsert();
	if (browser_opera) {
		document.newpost.text.focus();
	}else{
		window.scrollBy(0,10000);
	}
}
function textSelectionListenerS(e) {
	window.document.onmouseup = textSelectionListenerE;
}
function textSelectionListenerE(e) {
	var selText = '';
	if (window.getSelection) {
		selText = window.getSelection();
	}else if (document.selection) {
		selText = document.selection.createRange().text;
	}
	var selText1 = selText+'';
	if (selText1.length>0) docSelectedText = selText1;

	window.document.onmousedown = textSelectionListenerS;
	window.document.onmouseup = null;
	window.document.onmousemove = updateMousePositionCoords;
}

function quoteNPost(id,t) {
	if (docSelectedText.length>0) {
        var text = docSelectedText.replace('\n','<br>');
		document.quoteForm.quoteid.value=id;
		document.quoteForm.quotetype.value=t;
		document.quoteForm.quotetext.value=text;
		document.quoteForm.submit();
	}else{
		alert('Markera först texten du vill citera.');
	}
}

function quote(author) {
	if (docSelectedText.length>0) {
		var text = docSelectedText.replace('\n','<br />');
		if (browser_opera) document.getElementById('text').focus();
		rtef.insertHTML(quotePreStr.replace('##quoteHeader##','Citerar '+author+':')+text+quoteSufStr);
		docSelectedText = "";
		if (browser_opera) {
			document.getElementById('text').focus();
		}else{
			window.scrollBy(0,10000);
		}
	}else{
		alert('Markera först texten du vill citera.');
	}
}


