//addEvent( window, 'load', load );

if( window.getSelection || ( document.selection && document.selection.createRange ) )
	addEvent( document, 'mouseup', setQuoteText );

var quoteText = "";

/*function load() {
	if( !window.getSelection && !( document.selection.createRange ) ) {
		var tmp = getNode( "fpostfirst_qq_1" );
		if( tmp ) tmp.className = "hide";
		for(var i=1; ; i++) {
			var tmp = getNode( "fpost_qq_"+i );
			if( tmp ) tmp.className = "hide";
			else break;
		}
	}
}*/

function setQuoteText() {
	var txt = window.getSelection ? window.getSelection().toString() : document.selection.createRange().text;
	if( txt.length > 0 ) quoteText = txt;
}

function quickQuote( username ) {
    var txtArea = getNode( "comment" );
    if( txtArea ) {
        var qq_tip = getNode( "qq_tip" );
        qq_tip.className = quoteText.length == 0 ? "help" : "hide help";
        
        if( quoteText.length ) {
            txtArea.value += "[QUOTE=" + username + "]" + quoteText + "[/QUOTE]\n";

            /*just for fun*/
            setTimeout( function() { txtArea.style.outline = "1px solid #777"; }, 200 );
            setTimeout( function() { txtArea.style.outline = "none"; }, 1500 );
        }
        txtArea.focus();
    }
}








function addEvent( node, evtType, func ) {
	if( node.addEventListener ) {
		node.addEventListener( evtType, func, false );
		return true;
	} else if( node.attachEvent ) {
		return node.attachEvent( "on" + evtType, func );
	} else {
		return false;
	}
}
function getNode( nodeId ) {
	if( document.getElementById ) {
		return document.getElementById( nodeId );
	}
	else if( document.all && document.all( nodeId ) ) {
		return document.all( nodeId );
	}
	else if( document.layers && document.layers[ nodeId ] ) {
		return document.layers[ nodeId ];
	}
	else {
		return false;
	}
}
