var formSubmitCount = 0;

function trim(s) {
	lTrim = s.replace( /^\s*/, "" );
	rtrim = lTrim.replace( /\s*$/, "" );
	return rtrim;
}

function PrintPage() { window.print(); }	

function goTo(url) {
	window.document.location = url;
}

function showLayer(id) {
	if (document.getElementById(id).style.display == "none") {
		document.getElementById(id).style.display = "block";
	}
}

function hideLayer(id) {
	if (document.getElementById(id).style.display != "none") {
		document.getElementById(id).style.display = "none";
	}
}

function toggleLayer(id) {
	document.getElementById(id).style.display = (document.getElementById(id).style.display == "none") ? "block" : "none";
}

function popup(url,name,w,h,scroll,status,resize) {
	L = (screen.width - w) / 2;
	T = (screen.height - h) / 2;
	winProps = "width=" + w;
	winProps += ",height=" + h;
	winProps += ",scrollbars=" + scroll;
	winProps += ",status=" + status;
	winProps += ",resizable=" + resize;
	winProps += ",left=" + L;
	winProps += ",top=" + T;
	popupWindow = window.open(url,name,winProps);
}

function submitForm(formName,clickValue) {
	if (formSubmitCount == 0) {
		formSubmitCount++;
		formObj = eval("document." + formName);
		formObj.buttonClick.value = clickValue;
		formObj.submit();
	}
}

function preloader() {
	var i = 0;
	imageObj = new Image();
	images = new Array();
	images[0]="../media/images/icon_expand.gif"
	images[1]="../media/images/icon_contract.gif"
	
	for (i=0; i<=3; i++) {
		imageObj.src = images[i];
	}
} 

function imageSwap(img,id) {
	var iconExpand = 0;
	var iconContract = 1;
	document[img].src = images[eval(id)];
}

function deleteRecord(url) {
	if (confirm('Are you sure you want to delete this record?\n\nAll records associated with this record will be deleted as well!')) {
		if ((url != "") && (url != "undefined")) {
			goTo(url);
		} else {
			return true;
		}
	} else {
		return false;
	}
}