
//toggle hide show something
function hideShowEl(i,v) {
    var sObj = document.getElementById(i).style;
    if(sObj.display == "none") sObj.display = v;
    else if(sObj.display == v) sObj.display = "none";
  }
  

function pnhTextareaInsert(taID, text1, text2) {
	// grab the textarea off the dom tree
	var ta = document.getElementById(taID);
		
	if (window.getSelection) { //Safari
		var str = window.getSelection();
		ta.focus();
		var sel = window.getSelection();
		sel.text = text1 + str + text2;
	} else if (document.selection) { //IE win
		// code ripped/modified from Meg Hourihan 
		// http://www.oreillynet.com/pub/a/javascript/2001/12/21/js_toolbar.html
		var str = document.selection.createRange().text;
		ta.focus();
		var sel = document.selection.createRange();
		sel.text = text1 + str + text2;
	
	} else if (ta.selectionStart | ta.selectionStart == 0) { // Mozzzzzzila relies on builds post bug #88049
		// work around Mozilla Bug #190382
		if (ta.selectionEnd > ta.value.length) { ta.selectionEnd = ta.value.length; }

		// decide where to add it and then add it
		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);
		
		// reset selection & focus... after the first tag and before the second 
		ta.selectionStart = firstPos+text1.length;
		ta.selectionEnd = secondPos;
		ta.focus();
	}	
}

function pnhEditTextarea(textarea_id, action) {

	// decide what you're addding
	var startTag = "";
	var endTag = "";
	
	switch (action) {
		case "strong":	
			startTag = "<strong>";
			endTag = "<\/strong>";
			break;
		case "em":	
			startTag = "<em>";
			endTag = "<\/em>";
			break;
		case "a_href":
			var userInput = prompt("Please enter the site you'd like to link", "http://");
			startTag = "<a href=\""+userInput+"\">";
			endTag = "<\/a>";
			break;
		}

	pnhTextareaInsert(textarea_id,startTag,endTag);

	return false;
}

function PopupPic(sPicURL,sCaption,sWidth,sHeight) {
		//get stuff to center opened window
		if (document.all)
			var xMax = screen.width, yMax = screen.height;
		else
			if (document.layers)
				var xMax = window.outerWidth, yMax = window.outerHeight;
			else
				var xMax = 640, yMax=480;
		var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;
		window.open( "/popup.html?"+sPicURL+"|"+sCaption, "","screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+",resizable=1,height="+sHeight+",width="+sWidth+"");
	   }
