function NewWindow(url,windowWidth,windowHeight,scrollbar)
{  
	// set the window features
	var features = "width=" + windowWidth + ",height=" + windowHeight + ",scrollbars=" + scrollbar;
	// open the window
	window.open(url, "popup", features);
}

tags = new Array();

function getarraysize(thearray) {
// replacement for arrayname.length property
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

function arraypush(thearray,value) {
// replacement for arrayname.push(value)
	thearraysize = getarraysize(thearray);
	thearray[thearraysize] = value;
}

function arraypop(thearray) {
// replacement for arrayname.pop()
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function normalmode(theform) {
// checks value of mode radio buttons. returns true if normal mode
	if (theform.mode[0].checked) return true;
	else return false;
}

// places mini-help text into help/error textbox
// strings are stored in vbcode_language.js
function htmlstat(thevalue) {
	document.mycsform.status.value = thevalue;
}

function mycscode(theform,mycscode,prompttext) {
// insert [x]yyy[/x] style markup
	if (!mycscode=="") {
		inserttext = prompt("Enter the text to be formatted:"+"\n["+mycscode+"]xxx[/"+mycscode+"]",prompttext);
		if ((inserttext != null) && (inserttext != ""))
			theform.message.value += "["+mycscode+"]"+inserttext+"[/"+mycscode+"] ";
		}
	else {
		donotinsert = false;
		for (i = 0; i < tags.length; i++) {
			if (tags[i] == mycscode)
				donotinsert = true;
			}
		if (donotinsert)
			stat("<< You already have an open tag of this type >>");
		else {
			theform.message.value += "["+mycscode+"]";
			arraypush(tags,mycscode);
			}
		}
	theform.message.focus();
}

// *******************************************************

function htmlfont(theform,thevalue,thetype) {
// insert two-parameter markup - [x=y]zzz[/x]
	if (theform) {
		if (thevalue != 0) {
			inserttext = prompt("Enter the text to be formatted with the specified"+" "+thetype,"");
			if ((inserttext != null) && (inserttext != ""))
				theform.message.value += "["+thetype+"="+thevalue+"]"+inserttext+"[/"+thetype+"] ";
			}
		}
	else {
		theform.message.value += "["+thetype+"="+thevalue+"]";
		arraypush(tags,thetype);
		}
	theform.sizeselect.selectedIndex = 0;
	theform.fontselect.selectedIndex = 0;
	theform.colorselect.selectedIndex = 0;
	theform.message.focus();
}


// inserts named url or email link - [url=mylink]text[/url]
function htmllink(theform,thetype) {
	linktext = prompt("Enter the text to be displayed for the link (optional)","");
		var prompttext;
		if (thetype == "URL") {
			prompt_text = "Enter the full URL for the link";
			prompt_contents = "http://";
			}
		else {
			prompt_text = "Enter the email address for the link";
			prompt_contents = "";
			}
	linkurl = prompt(prompt_text,prompt_contents);
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != ""))
			theform.message.value += "["+thetype+"="+linkurl+"]"+linktext+"[/"+thetype+"] ";
		else
			theform.message.value += "["+thetype+"]"+linkurl+"[/"+thetype+"] ";
		}
	theform.message.focus();
}

// inserts list with option to have numbered or alphabetical type
function htmllist(theform) {
	listtype = prompt("What type of list do you want? Enter '1' for a numbered list, enter 'a' for an alphabetical list, or leave blank for a list with bullet points.", "");
	if ((listtype == "a") || (listtype == "1")) {
		thelist = "[list="+listtype+"]\n";
		listend = "[/list="+listtype+"] ";
		}
	else {
		thelist = "[list]\n";
		listend = "[/list] ";
		}
	listentry = "initial";
	while ((listentry != "") && (listentry != null)) {
		listentry = prompt("Enter a list item.\nLeave the box empty or press 'Cancel' to complete the list.", "");
		if ((listentry != "") && (listentry != null))
			thelist = thelist+"[*]"+listentry+"\n";
		}
	theform.message.value += thelist+listend;
	theform.message.focus();
}

// inserts smilie text
function smilie(thesmilie) {
	document.mycsform.message.value += thesmilie+" ";
	document.mycsform.message.focus();
}
// handles image rollovers
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		free_trial_over = newImage("http://www.mychurchsite.com/clients/mycsweb/files/free_trial_over.gif");
		home_package_brnz_over = newImage("http://www.mychurchsite.com/clients/mycsweb/files/home_package_brnz_over.gif");
		home_package_slvr_over = newImage("http://www.mychurchsite.com/clients/mycsweb/files/home_package_slvr_over.gif");
		home_package_gold_over = newImage("http://www.mychurchsite.com/clients/mycsweb/files/home_package_gold_over.gif");
		preloadFlag = true;
	}
}
function showCategory(){
	var sdiv; 
	sdiv = document.selectCategory.currDiv.value;
	alert(sdiv);
	if (sdiv != "") {
	document.all[sdiv].className = "hideDiv";
	}
	var ndiv; 
	ndiv = document.selectCategory.categoryChooser.options[document.selectCategory.categoryChooser.options.selectedIndex].value;
	document.all[ndiv].className = "showDiv";
	document.selectCategory.currDiv.value=ndiv;
}
function showTemplate(tmpid){
	var url = "http://www.mychurchsite.net/mycsdemo/index.php?pageid=cr1&tmpid=" + tmpid;
	window.open(url, "title", "toolbar=0, scrollbars=1, location=0, statusbar=1, menubar=0, resizable=1, width=900, height=600");	
}
