function newsPoster(textAreaName) {

	var mySelf = this;

	this.textAreaName = textAreaName;
	this.addUrlDiv = null;
	this.addImageDiv = null;
	this.addImageIframe = null;
	this.addVideoDiv = null;
	this.addCodeDiv = null;
	this.addCommentDiv = null;
	this.newsTitles = new Array();

	//public functions
	//----------------------------------
	this.addURL = addURL;
	this.addUrlToTextarea = addUrlToTextarea;
	this.addMedia = addMedia;
	this.addComment = addComment;
	this.uploadMedia = uploadMedia;
	this.addMediaToTextarea = addMediaToTextarea;
	this.addCode = addCode;
	this.addCodeToTextarea = addCodeToTextarea;
	this.getNewsTextForId = getNewsTextForId;
	this.postNews = postNews;
	this.postComment = postComment;
	this.closeDiv = closeDiv;
	//----------------------------------


	//shows a addUrl box with a text and url box.
	//if the writeDiv has selected text, then this text goes into the "text" textfield
	function addURL() {
	    if (mySelf.addUrlDiv == null) {
	    	textarea = document.getElementById(mySelf.textAreaName);
	        mySelf.addUrlDiv = createPopupDiv(textarea.offsetWidth-textarea.offsetLeft, textarea.offsetTop+20, 300, 75);
	        document.body.appendChild(mySelf.addUrlDiv);
	        addPhpToDiv(mySelf.addUrlDiv, 'includes/ajaxPages/addUrl.php', true);
	        fadePageOn();
	    }
	}

	//shows an addImage box with a text and url box.
	//if the writeDiv has selected text, then this text goes into the "text" textfield
	function addMedia() {
	    if (mySelf.addImageDiv == null) {
	    	textarea = document.getElementById(mySelf.textAreaName);

	        mySelf.addImageDiv = createPopupDiv(textarea.offsetWidth-textarea.offsetLeft, textarea.offsetTop+20, 300, 75);
	        document.body.appendChild(mySelf.addImageDiv);

			this.addImageIframe = document.createElement('iframe');
	        this.addImageIframe.src = 'includes/ajaxPages/addImage.php';
	        this.addImageIframe.id = 'imageIframe';
	        this.addImageIframe.scrolling = "NO";
	        this.addImageIframe.frameBorder = "0";
	        this.addImageIframe.width = "300";
	        this.addImageIframe.height = "65";
	        mySelf.addImageDiv.appendChild(this.addImageIframe);
	        var errorDiv = document.createElement('div');
	        errorDiv.id = "addImageErrorDiv";
	        errorDiv.className = "errorDiv";
	        mySelf.addImageDiv.appendChild(errorDiv);
	        fadePageOn();
	    }
	}

	function addCode() {
	    if (mySelf.addCodeDiv == null) {
	    	textarea = document.getElementById(mySelf.textAreaName);
	        mySelf.addCodeDiv = createPopupDiv(textarea.offsetWidth-textarea.offsetLeft, textarea.offsetTop+20, 300, 300);
	        document.body.appendChild(mySelf.addCodeDiv);
	        addPhpToDiv(mySelf.addCodeDiv, 'includes/ajaxPages/addCode.php', true);
	        fadePageOn();
	    }
	}

	function addComment(id) {
	    if (mySelf.addCommentDiv == null) {
	        mySelf.addCommentDiv = createPopupDiv(document.body.offsetWidth/2 - 150, 100, 350, 320);
	        document.body.appendChild(mySelf.addCommentDiv);
	        addPhpToDiv(mySelf.addCommentDiv, 'includes/ajaxPages/addComment.php?id=' + id, true);
	        fadePageOn();
	    }
	}

	function insertAtCursor(myField, myValue) {
	    //IE support
	    if (document.selection) {
	        myField.focus();
	        sel = document.selection.createRange();
	        sel.text = myValue;
	    }
	    //MOZILLA/NETSCAPE support
	    else if (myField.selectionStart || myField.selectionStart == 0) {
	        var startPos = myField.selectionStart;
	        var endPos = myField.selectionEnd;
	        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	    }
	    else {
	        myField.value += myValue;
	    }
	}

    function getSelectedText() {
    	var str = '';
/*    	var ta = document.getElementById(mySelf.textAreaName);
    	str = ta.getSelection();
		if (document.getSelection) {
	    	str = document.getSelection();
		}
		else if (document.selection && document.selection.createRange) {
			if (document.selection.createRange().parentElement().tagName == 'TEXTAREA') {
		    	var range = document.selection.createRange();
		    	str = range.text;
		    }
		}
*/
		return str;

    }


    function uploadMedia() {
		var file = document.getElementById('ifile');
   		var iframe = this.addImageIframe;
		iframe.contentDocument.getElementById('iform').submit();
    }

    function addMediaToTextarea(mediaName, type, error) {
    	if (error == '') {
			textarea = document.getElementById(mySelf.textAreaName);
			if (type == 'jpg') {
				insertAtCursor(textarea, '<div align="center"><img src="'+mediaName+'"/></div>');
			}
			else if ((type == 'mpg') || (type == 'avi') || (type == 'wmv')) {
				insertAtCursor(textarea, '<div align="center"><embed src="'+mediaName+'"/></div>');
			}
	        closeDiv();
	    }
	    else {
	    	var errorDiv = document.getElementById('addImageErrorDiv');
	    	errorDiv.innerHTML = error;
	    }
    }

    function addUrlToTextarea() {
    	var text = document.getElementById('urlText');
    	var href = document.getElementById('urlHref');
    	if ((text.value != '') && (href.value != '')) {
	    	textarea = document.getElementById(mySelf.textAreaName);
			insertAtCursor(textarea, '<a href="'+href.value+'">'+text.value+'</a>');
	    	closeDiv();
    	}
    	else {
	    	var errorDiv = document.getElementById('addUrlErrorDiv');
	    	errorDiv.innerHTML = 'Enter a name and url for the link';
    	}
    }

    function addCodeToTextarea() {
    	var text = document.getElementById('code');
    	if (text.value != '') {
	    	textarea = document.getElementById(mySelf.textAreaName);
			insertAtCursor(textarea, '<div class="itemCode"><pre>'+text.value+'</pre></div>');
	    	closeDiv();
    	}
    	else {
	    	var errorDiv = document.getElementById('addCodeErrorDiv');
	    	errorDiv.innerHTML = 'Enter some code to add';
    	}
    }

	function closeDiv() {
		if (mySelf.addUrlDiv != null) {
	        document.body.removeChild(mySelf.addUrlDiv);
	        mySelf.addUrlDiv = null;
	        fadePageOff();
	    }
		else if (mySelf.addImageDiv != null) {
	        document.body.removeChild(mySelf.addImageDiv);
	        mySelf.addImageDiv = null;
	        fadePageOff();
	    }
		else if (mySelf.addVideoDiv != null) {
	        document.body.removeChild(mySelf.addVideoDiv);
	        mySelf.addVideoDiv = null;
	        fadePageOff();
	    }
		else if (mySelf.addCodeDiv != null) {
	        document.body.removeChild(mySelf.addCodeDiv);
	        mySelf.addCodeDiv = null;
	        fadePageOff();
	    }
		else if (mySelf.addCommentDiv != null) {
	        document.body.removeChild(mySelf.addCommentDiv);
	        mySelf.addCommentDiv = null;
	        fadePageOff();
	    }

	}

	function getNewsTextForId(id, divid) {
		/*var div = document.getElementById(divid);
		if (div.style.display == 'none') { //add the php to the div and show it
			this.newsTitles[id] = div.innerHTML;
			div.innerHTML = "Loading...";
			div.style.display = '';
			addPhpToDiv(div, 'includes/submits/getNewsTextForId.php?id=' + id, true);
		}
		else if (div.style.display == '') { //hide the div
			div.innerHTML = this.newsTitles[id];
			div.style.display = 'none';
		}*/
		alert('test');
	}


	function postNews(id, titleName, messageName) {
		var query = "../includes/submits/newsSubmit.php";
		var title = document.getElementById(titleName).value.replace(/&/g, "%amp%"); //lowercase g enables global matching
		var message = document.getElementById(messageName).value.replace(/&/g, "%amp%"); //lowercase g enables global matching

		var poststr = titleName+"=" + encodeURI( title )+"&"+messageName+"=" + encodeURI( message );
		if (id != "")
			poststr +=  "&id=" + encodeURI(id);
		var successFunction = function() {
			showHome(new Object());
		};
		submitToPhp(query, document.getElementById('postErrorDiv'), successFunction, poststr);
	}

	function postComment(id, commentName, commentSecurity, commentText) {
		var query = "../includes/submits/commentSubmit.php";

		var poststr = commentName+"=" + encodeURI( document.getElementById(commentName).value )+"&"+commentSecurity+"=" + encodeURI( document.getElementById(commentSecurity).value )+"&"+commentText+"=" + encodeURI( document.getElementById(commentText).value )+"&id=" + encodeURI(id);
		var successFunction = function() {
			closeDiv();
			showHome(new Object());
		};
		submitToPhp(query, document.getElementById('addCommentErrorDiv'), successFunction, poststr);
	}

}