function popup(url, size, name)	{
		if (size == 1) {
			var newwindow=window.open(url,'name','height=500,width=800,toolbar=no,scrollbars=yes');
			if (window.focus) {newwindow.focus()}
		}
		else if(size==2) {
			var newwindow=window.open(url,'name','height=180,width=300,toolbar=no,scrollbars=yes');
			if (window.focus) {newwindow.focus()}		
		}
		else {
			var newwindow=window.open(url,'name','height=400,width=480,toolbar=no,scrollbars=no');
			if (window.focus) {newwindow.focus()}
		}
}

function popup2(url, size)	{

		if (size == 1) {
			var newwindow=window.open(url,'pop2','height=500,width=800,toolbar=no,scrollbars=yes');
			if (window.focus) {newwindow.focus()}
		}
		if (size == 2) {
			var newwindow=window.open(url,'pop2','height=250,width=500,toolbar=no,scrollbars=no');
			if (window.focus) {newwindow.focus()}
		}
		if (size == 3) {
			var newwindow=window.open(url,'pop2','height=500,width=300,toolbar=no,scrollbars=yes');
			if (window.focus) {newwindow.focus()}
		}
		if (size == null) {
			var newwindow=window.open(url,'pop2','height=400,width=480,toolbar=no,scrollbars=no');
			if (window.focus) {newwindow.focus()}
		}
}



function GetElementById(id){
	if (document.getElementById) {
		return (document.getElementById(id));
	} else if (document.all) {
		return (document.all[id]);
	} else {
		if ((navigator.appname.indexOf("Netscape") != -1) && parseInt(navigator.appversion == 4)) {
			return (document.layers[id]);
		}
	}
}

function goTo(optVal){
	if ( optVal == "" ) return false;
	window.location = optVal;
}

function InsertText(domobj, text)
{
	if (domobj.createTextRange && domobj.caretPos){
  		var caretPos = domobj.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) 
== ' ' ? text + ' ' : text;  
	} else if (domobj.getSelection && domobj.caretPos){
		var caretPos = domobj.caretPos;
		caretPos.text = caretPos.text.charat(caretPos.text.length - 1)  
== ' ' ? text + ' ' : text;
	} else {
		domobj.value = domobj.value + text;
  	}
}



function CodeUrl(id, enterUrlPhrase, enterWebsitePhrase){
	if (enterUrlPhrase == null) {
		enterUrlPhrase = "Enter the URL of the link you want to add:";
	}
	var text = prompt(enterUrlPhrase, "");
	var domobj = GetElementById(id);
	if ( text != null && text != "" ) {
		if (enterWebsitePhrase == null) {
			enterWebsitePhrase = "Enter the web site title:";
		}
		var text2 = prompt(enterWebsitePhrase, "");
		if ( text2 != null ) {
			if ( text2 == "" ) {
				var result = "[URL=" + text + "]" + text + "[/URL]";
			} else {
				var pos = text2.indexOf(unescape('%00'));
				if(0 < pos){
					text2 = text2.substr(0,pos);
				}
				var result = "[URL=" + text + "]" + text2 + "[/URL]";
			}
			InsertText(domobj, result);
		}
	}
	domobj.focus();
}

function makeBold(id, makeboldpromt){
	if (makeboldpromt == null) {
		makeboldpromt = "Enter the text you want to make bold:";
	}
	var text = prompt(makeboldpromt, "");
	var domobj = GetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[B]" + text + "[/B]";	
		InsertText(domobj, result);
		domobj.focus();
	}
}

function makeItalic(id, makeItalicpromt){
	if (makeItalicpromt == null) {
		makeItalicpromt = "Enter the text you want to make italic:";
	}
	var text = prompt(makeItalicpromt, "");
	var domobj = GetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[I]" + text + "[/I]";	
		InsertText(domobj, result);
		domobj.focus();
	}
}

function makeTitles(id, makeTitlespromt){
	if (makeTitlespromt == null) {
		makeTitlespromt = "Enter section title:";
	}
	var text = prompt(makeTitlespromt, "");
	var domobj = GetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[T]" + text + "[/T]";	
		InsertText(domobj, result);
		domobj.focus();
	}
}

function makeTitless(id, makeTitlesspromt){
	if (makeTitlesspromt == null) {
		makeTitlesspromt = "Enter subsection title:";
	}
	var text = prompt(makeTitlesspromt, "");
	var domobj = GetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[t]" + text + "[/t]";	
		InsertText(domobj, result);
		domobj.focus();
	}
}

function makeCenter(id, makeCenterpromt){
	if (makeCenterpromt == null) {
		makeCenterpromt = "Enter what to center:";
	}
	var text = prompt(makeCenterpromt, "");
	var domobj = GetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[CENTER]" + text + "[/CENTER]";	
		InsertText(domobj, result);
		domobj.focus();
	}
}



function makeList(id, listNo){
	if (listNo == null) {
		listNo = "Enter number of List Items:";
	}
	var text = prompt(listNo, "");
	var domobj = GetElementById(id);
	if ( text != null && text != "" && parseInt(text)>=1 ) {
		var n=parseInt(text);
		var result = "[UL]";
			if (n>10) {
				n=10;
			}
		var i=1;
			while (i<=n) {
				result = result + "\n[LI]";
				i=i+1;
			}
		result=result + "\n[/UL]";	
		InsertText(domobj, result);
		domobj.focus();
	}}



function makeIndent(id, makeIndentpromt){
	if (makeIndentpromt == null) {
		makeIndentpromt = "Enter what to indent:";
	}
	var text = prompt(makeIndentpromt, "");
	var domobj = GetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[IND]\n" + text + "\n[/IND]";	
		InsertText(domobj, result);
		domobj.focus();
	}
}


function floatLeft(id){
		var domobj = GetElementById(id);
		var result = "[FLL] [/FLL]";	
		InsertText(domobj, result);
		domobj.focus();
}

function floatRight(id){
		var domobj = GetElementById(id);
		var result = "[FLR] [/FLR]";	
		InsertText(domobj, result);
		domobj.focus();
}

function insertPic(id, insertPicpromt){
	if (insertPicpromt == null) {
		insertPicpromt = "Please end the filename of the image (e.g. iguana.gif):";
	}
	var text = prompt(insertPicpromt, "");
	var domobj = GetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[IMG]" + text + "[/IMG]";	
		InsertText(domobj, result);
		domobj.focus();
	}
}


function redirect(URL, time) {
	if (time == null) {
		time=1000;
	}
	else {
		settimeout(redirect2(URL), time);
	}
}

function redirect2(URL) {
	window.location=URL;
	return;
}

checked = false;
function checkAll(id) {
	if (checked == false){
		checked = true
	} 
	else {
		checked = false
	}
	for (var i = 0; i < document.getElementById(id).elements.length; i++) {
		document.getElementById(id).elements[i].checked = checked;
	}
}

function jumpTo(list) {
    var newPage = list.options[list.selectedIndex].value
    if (newPage != "None") {
        location.href=newPage
    }
}

var xmlHttp
function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
  		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}
	catch (e)  {
  		// Internet Explorer
 		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
		
function getFormValues(fobj) {
	var str = "";
	var valueArr = null;
	var val = "";
	var cmd = "";
	for (var i = 0; i < fobj.elements.length; i++) {
   		switch (fobj.elements[i].type) {
			case "text":
				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
				break;
			case "hidden":
				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
				break;
			case "radio":
				if (fobj.elements[i].checked) {
					str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
				}
				break;
			case "textarea":
				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
				break;
			case "select-one":
				str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
               	break;
		}
	}
	str = str.substr(0,(str.length - 1));
	return str;
}

function showElement(id) {
	document.getElementById(id).style.display= 'block';
}
			
function hideElement(id) {
	document.getElementById(id).style.display= 'none';
}

function showHide(id) {
	if (document.getElementById(id).style.display=='none' || document.getElementById(id).style.display=='')
		document.getElementById(id).style.display= 'block';
	else 
		document.getElementById(id).style.display= 'none';
}

// Remember the current position.
function storeCaret(text)
{
	// Only bother if it will be useful.
	if (typeof(text.createTextRange) != "undefined")
		text.caretPos = document.selection.createRange().duplicate();
}


// Surrounds the selected text with text1 and text2.
function surroundText(text1, text2, text3, textarea)
{
	// Can a text range be created?
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
	{
		var caretPos = textarea.caretPos, temp_length = caretPos.text.length;

//		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text1 + text3 + text2 : text1 + caretPos.text + text2;

		if (temp_length == 0)
		{
			caretPos.moveStart("character", -text2.length);
			caretPos.moveEnd("character", -text2.length);
			caretPos.select();
		}
		else
			textarea.focus(caretPos);
	}
	// Mozilla text range wrap.
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);
		var newCursorPos = textarea.selectionStart;
		var scrollPos = textarea.scrollTop;

		textarea.value = begin + text1 + (selection=='' ? text3 : selection) + text2 + end;

		if (textarea.setSelectionRange)
		{
			if (selection.length == 0)
				textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
			else
				textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
			textarea.focus();
		}
		textarea.scrollTop = scrollPos;
	}
	// Just put them on the end, then.
	else
	{
		textarea.value += text1 + text3 + text2;
		textarea.focus(textarea.value.length - 1);
	}
}

