﻿// JScript File
function checkUpload() {
	//alert("NOTE: After Previewing your post, you will have to complete the Attachment field again.")
}

function pnhTextareaInsert(taID, text1, text2, action) {

	var ta = null;
	
	var anchors = document.getElementsByTagName('textarea');
    for (var i=0; i<anchors.length; i++){
        var anchor = anchors[i];
		var relAttribute = String(anchor.getAttribute('rel'));
	    if (relAttribute.toLowerCase().match(taID)){
			ta = anchor;
		}
    }
            
	if(ta != null){
	    // IE WINDOWS
	    if (document.selection) {
		    var str = document.selection.createRange().text;

		    ta.focus();
		    var sel = document.selection.createRange();
    		
		    if (action == "quote_by_url") {
			    var myObject = new Object();
			    myObject.sel = document.selection.createRange().text;
			    var quoteInput = showModalDialog("editor/quote.aspx", myObject, "dialogWidth:27.5em;dialogHeight:12.5em");

			    if (quoteInput != null && quoteInput != "") {
				    startTag = quoteInput;
				    endTag = "[\/quote]";
    				
				    // sel.text = startTag + endTag + "\n";
				    sel.text = startTag + endTag + " ";
			    } else {
				    //sel.text = "[quote]" + "[/quote]" + "\n";
			    }
    	

		    } else {
			    if (str != null && str != "") {
				    // sel.text = text1 + str + text2 + "\n";
				    sel.text = text1 + str + text2 + " ";
			    } else {
				    sel.text = text1 + text2 + " ";
			    }
		    }
    		

	    // MOZZILA
	    } else if (ta.selectionStart | ta.selectionStart == 0) {

		    if (action == "quote") {
			    text1 = "[quote]";
			    text2 = "[/quote]";
		    } else if (action == "image") {
			    text1 = "[image]";
			    text2 = "[/image]";
		    }

		    if (ta.selectionEnd > ta.value.length) { ta.selectionEnd = ta.value.length; }

		    var firstPos = ta.selectionStart;
		    var secondPos = ta.selectionEnd+text1.length; // cause we're inserting one at a time

		    ta.value=ta.value.slice(0,firstPos)+text1+ta.value.slice(firstPos);
		    ta.value=ta.value.slice(0,secondPos)+text2+ta.value.slice(secondPos);
    		
		    ta.selectionStart = firstPos+text1.length;
		    ta.selectionEnd = secondPos;
		    ta.focus();
	    }
	   }else{
	   alert("Can not find: " + taID + "!" + " - " + ta);
	   }
}

function pnhEditTextarea(textarea_id, action) {

	var startTag = "";
	var endTag = "";
	
	switch (action) {
		case "bold":	
			startTag = "[bold]";
			endTag = "[\/bold]";
			break;
		case "italic":	
			startTag = "[italic]";
			endTag = "[\/italic]";
			break;
		case "underline":	
			startTag = "[underline]";
			endTag = "[\/underline]";
			break;
		case "codetag":	
			startTag = "[code]";
			endTag = "[\/code]";
			break;
		case "quote":
		    startTag = "[quote]";
			endTag = "[\/quote]";
			break;
		case "image":
			startTag = "[image]";
			endTag = "[\/image]";
			break;
		case "url":
			startTag = "[url]";
			endTag = "[\/url]";
			break;
	
	}
	
	pnhTextareaInsert(textarea_id, startTag, endTag, action);

	return false;
}

function quoteUser() {
	var thisQuote = showModalDialog("quote.html", "", "font-family:Verdana;font-size:12;dialogWidth:30em;dialogHeight:35em");
	alert(thisQuote);
}


