
function checkRequiredFields(oForm, arFields, arTitles) {
	var sMessage = "Please fill in the following required fields:\n";
	for (var i = 0; i < arFields.length; i++) {
		if (oForm[arFields[i]].value == "") {
			sMessage += "\n" + arTitles[i];
		}
	}
	if (sMessage != "Please fill in the following required fields:\n") {
		alert(sMessage);
		return false;
	} else return true;
}

function todaysDate(fmt) {
	var sRetVal = "";
	var dtDate = new Date();

	switch (fmt) {
		case 1:
			sRetVal = dtDate.getMonth() + 1 + "/" + dtDate.getDate() + "/" + dtDate.getYear();
			break;
		case 2:
			sRetVal = GetMonth(dtDate.getMonth()) + " " + dtDate.getDate() + ", " + dtDate.getFullYear();
			break;
		case 3:
			sRetVal = dtDate.getMonth() + 1 + "/" + dtDate.getDate() + "/" + dtDate.getFullYear();
			break;
		default:
			sRetVal = dtDate.toString();
	}
	return sRetVal;
}

/*copied from CSScriptLib.js:

// Used for preloading images*/
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/") + 1), 10);

/*NOTE: may conflict with Prototype which adds the findElement function to several objects
// unfortunetly this is used by changeImages().*/
function findElement(n, ly) {
	d = document;
	if (browserVers < 4)
		return d[n];
	if ((browserVers >= 6) && (d.getElementById)) {
		initImgID; return (d.getElementById(n))
	};
	var cd = ly ? ly.document : d;
	var elem = cd[n];
	if (!elem) {
		for (var i = 0; i < cd.layers.length; i++) {
			elem = findElement(n, cd.layers[i]);
			if (elem)
				return elem;
		}
	}
	return elem;
}

/* changeImages is used all over the place, including Security manager and several elements.*/
function changeImages() {
	d = document;
	if (d.images) {
		var img;
		for (var i = 0; i < changeImages.arguments.length; i += 2) {
			img = null;
			if (d.layers) { img = findElement(changeImages.arguments[i], 0); }
			else { img = d.images[changeImages.arguments[i]]; }
			if (img) { img.src = changeImages.arguments[i + 1]; }
		}
	}
}

/*s allong with other JS openWindow variations is used all over the place.*/
function openWindow(URL, windowTitle, windowWidth, windowHeight) {
	var wide = screen.width;
	var high = screen.height;
	var xCoordinate = ((wide / 2) - (windowWidth / 2));
	var yCoordinate = ((high / 2) - (windowHeight / 2));
	var w = window.open(URL, windowTitle, "width=" + windowWidth + ",height=" + windowHeight + ",left=" + xCoordinate + ",top=" + yCoordinate + ",resizable=no,status=no,menubar=no,scrollbars=auto,innerheight=" + windowHeight + ",innerwidth=" + windowWidth + ",screenx=" + xCoordinate + ",screeny=" + yCoordinate + ",toolbar=no");
	w.focus();
	w.opener = window;
}

function openContactWindow(URL, windowTitle) {
	var sWidth;
	var sHeight;

	sWidth = 420;
	sHeight = 660;

	var wide = screen.width;
	var high = screen.height;
	var xCoordinate = ((wide / 2) - (sWidth / 2));
	var yCoordinate = ((high / 2) - (sHeight / 2));
	var w = window.open(URL, windowTitle, "width=" + sWidth + ",height=" + sHeight + ",left=" + xCoordinate + ",top=" + yCoordinate + ",resizable=no,status=no,menubar=no,scrollbars=auto,innerheight=" + sHeight + ",innerwidth=" + sWidth + ",screenx=" + xCoordinate + ",screeny=" + yCoordinate + ",toolbar=no");
	w.focus();
	w.opener = window;
}
function openScrollingWindow(URL, windowTitle, windowWidth, windowHeight) {
	var wide = screen.width;
	var high = screen.height;
	var xCoordinate = ((wide / 2) - (windowWidth / 2));
	var yCoordinate = ((high / 2) - (windowHeight / 2));
	var w = window.open(URL, windowTitle, "width=" + windowWidth + ",height=" + windowHeight + ",left=" + xCoordinate + ",top=" + yCoordinate + ",resizable=yes,status=yes,menubar=no,scrollbars=yes,innerheight=" + windowHeight + ",innerwidth=" + windowWidth + ",screenx=" + xCoordinate + ",screeny=" + yCoordinate + ",toolbar=no");
	w.focus();
	w.opener = window;
	w.resizeTo(windowWidth, windowHeight);

}

/* Used in the body onload event, not sure what effect this has on browser performance,
// will need to look at this. ERE 8/23/2007*/
var arImages = new Array();
var preloadFlag = false;
function preloadImages(arImages) {
	preloadFlag = false;
	if (document.images) {
		var img;

		for (var i = 0; i < arImages.length; i++) {
			img = newImage(arImages[i]);
		}
		preloadFlag = true;
	}
}

/* Used to set the cursor focus to the first element on the form as defined by taborder
// Should be used more often! (from Dale) ERE 8/23/2007*/
function setFormFocus(sFormName) {

	var sFieldName;

	if (sFormName != "") {
		if (document.forms[sFormName]) {
			if (document.forms[sFormName].taborder && !$('elementeditor')) {
				sFieldName = document.forms[sFormName].taborder.value;
				if (sFieldName != "") {
					document.forms[sFormName][sFieldName].focus();
				}
			}
		}
	}
}

/* Used in the image prevew (element displays the image even while the element editor window is open)
// ERE 8/23/2007*/
function resizeImageWidth(form, imagename, imageasppath) {
	if (form.width.value != '') {
		if (form.source.value.indexOf('.jpg') != -1) {
			document.images[imagename].style.width = form.width.value;
			document.images[imagename].style.height = form.height.value;
			document.images[imagename].src = aspResizeImage(imageasppath, form.source.value, form.height.value, form.width.value);
		} else {
			document.images[imagename].style.width = form.width.value;
		}
	} else {
		if (form.source.value.indexOf('.jpg') != -1) {
			document.images[imagename].style.width = form.width.value;
			document.images[imagename].style.height = form.height.value;
			document.images[imagename].src = aspResizeImage(imageasppath, form.source.value, form.height.value, form.width.value);
		} else {
			if (document.images[imagename].style.width != '') {
				document.images[imagename].style.width = 'auto';
			}
		}
	}
}

function resizeImageHeight(form, imagename, imageasppath) {
	if (form.height.value != '') {
		if (form.source.value.indexOf('.jpg') != -1) {
			document.images[imagename].style.width = form.width.value;
			document.images[imagename].style.height = form.height.value;
			document.images[imagename].src = aspResizeImage(imageasppath, form.source.value, form.height.value, form.width.value);
		} else {
			document.images[imagename].style.height = form.height.value;
		}
	} else {
		if (form.source.value.indexOf('.jpg') != -1) {
			document.images[imagename].style.width = form.width.value;
			document.images[imagename].style.height = form.height.value;
			document.images[imagename].src = aspResizeImage(imageasppath, form.source.value, form.height.value, form.width.value);
		} else {
			if (document.images[imagename].style.height != '') {
				document.images[imagename].style.height = 'auto';
			}
		}
	}
}

function aspResizeImage(sResizer, sPath, iHeight, iWidth) {
	return sResizer + escape(sPath) + "-" + iHeight + "x" + iWidth;
}

/*copied from helppane.js:

// Used for the helpfull help button on the admin toolbar.*/
function DoHelp(help_url) {

	var W;
	var H;
	var sWD;
	var sc = screen.width;
	var agent = navigator.userAgent.toLowerCase();
	var app = navigator.appName.toLowerCase();

	/*If screen width is 800 or less and this is not a mac, set width to 180, otherwise set to 230*/
	W = (sc <= 800 && agent.indexOf("mac") == -1) ? 230 : 336;

	/* If using AOL then height = available height - 22 from top, Otherwise height = available height */
	H = (agent.indexOf("windows") > 0 && agent.indexOf("aol") > 0) ? (screen.availHeight - window.screenTop - 22) : screen.availHeight;

	/*sWD="toolbar=0,status=0,menubar=0,width="+W+",height="+H+",left="+(sc-W)+",top=0,resizable=1";*/
	sWD = "toolbar=0,status=0,scrollbars=1,location=0,menubar=0,left=" + (sc - W) + ",top=0,resizable=1";


	h_win = window.open(help_url, 'help', sWD);
	h_win.focus();
	h_win.resizeTo(W, H);

	/*if not using a mac and not using netscape*/
	if (h_win && agent.indexOf("mac") < 0 && app.indexOf("netscape") < 0) 
		h_win.opener = self;  /*IE5+PC*/
	h_win.opener.resizeTo((sc - W), H);
	h_win.opener.moveTo(0, 0);
}

/*EOLAS IE flash workaround*/
function displayFlash(sSource, iHeight, iWidth, sQuality, sPlay, sParams, sLoop, sContentid, sClassid, sCodebase, sPluginspage) {
	document.write('<OBJECT classid="' + sClassid + '" codebase="' + sCodebase + '" id="' + sContentid + '"');
	if (iWidth > 0) {
		document.write(' width="' + iWidth + '"');
	}
	if (iHeight > 0) {
		document.write(' height="' + iHeight + '"');
	}
	document.write('">');
	document.write('<PARAM name="movie" value="' + sSource + '">');
	document.write('<PARAM name="quality" value="' + sQuality + '">');
	document.write('<param name="play" value="' + sPlay + '" / >');
	document.write('<param name="wmode" value="transparent" / >');
	document.write('<param name="flashvars" value="' + sParams + '" />');
	document.write('<EMBED src="' + sSource + '" quality="' + sQuality + '" pluginspage="' + sPluginspage + '" type="application/x-shockwave-flash" name="' + sContentid + '"');
	if (iWidth > 0) {
		document.write(' width="' + iWidth + '"');
	}
	if (iHeight > 0) {
		document.write(' height="' + iHeight + '"');
	}
	document.write(' play="' + sPlay + '" loop="' + sLoop + '" autostart="' + sPlay + '" flashvars="' + sParams + '" wmode="transparent"');
	document.write('</EMBED>');
	document.write('</OBJECT>');
}
