function FormValidate(frm) {
	var f;
	var valid = true;
	var found;
	var r;
	//alert('FormValidate triggered');
	if (frm) {
		if (frm.elements) {
			//alert('we have elements');
			for (var i = 0; i < frm.elements.length; i++) {
				f = frm.elements[i];
				if (f) {
					if (f.name != undefined) {
						//alert('checking ' + f.name);
						if (((f.name.indexOf('124101117114116124') > 0) || f.name.indexOf('_required') > 0) && (f.name.substring(0, 2) != 'h.')) {
							switch (f.type) {
								case 'radio' :
									//alert('still have to write a check for radio');
									//found = -1; for(i = 0; i < theform." & q & ".length; i++) {if (theform." & q & "[i].checked) {found = i;}} if (found == -1) {msg = msg + '::  " & JS_REQUIRED & jsStringFormat(qText) & "\n'; isValid = false; setColor(theform." & q & ", false); if (focusField == undefined) {focusField = theform." & q & ";}}" & vbNewLine
									var x = eval('frm.' + f.name + '.length');
									//alert(x);
									if (x == undefined) {
										//alert('single is checked = ' + f.checked);
										valid = f.checked;
									}
									else {
										found = -1;
										for (var j = 0; j < x; j++) {
											r = eval('frm.' + f.name + '[' + j + '].checked');
											//alert('r = ' + r);
											if (r) {
												found = j;
											}
										}
										//alert('found = ' + found);
										valid = (found >= 0);
									}
									break;
								case 'checkbox' :
									// do nothing doesn't make sense to have a required checkbox
									break;
								case 'hidden' :
									// do nothing
									break;
								case 'text' :
								case 'select-one' :
								case 'textarea' :
								case 'file' :
								case 'password' :
									if (f.value == '' || f.value == undefined || !(f.value)) {
										valid = false;
										if (f.style) {
											f.style.backgroundColor = '#ffff00';
										}
									}
									break;
								default :
									alert('default checking of ' + f.type);
									if (f.value == '') {
										valid = false;
										if (f.style) {
											f.style.backgroundColor = '#ffff00';
										}
									}
							}
						}
					}
				}
			}
		}
		else {
			alert('not a form');
		}
	}
	else {
		alert('frm is not defined');
	}
	if (valid == false) {
		alert('Not all required fields have been filled in.');
	}
	//alert('FormValidate returing ' + valid);
	return valid;
}

function ShowRefresh() {
	// show the refresh layer
	var r = document.getElementById("refresh");
	if (r) {
		//alert('found r');
		r.style.visibility = "visible";
		r.style.display = "block";
	}
	else {
		alert('This page is displaying data that has probably changed. Please refresh your browser to see up to date information.');
	}
}

function datePrompt(fieldname, url) {
	var v = prompt('By law we are only able to attempt to recover customers that have had business with the dealership within the last 18 months, what is the most recent date to use?\nmm/dd/yyyy');
	//alert('v is ' + v);
	if (v == '') {
		alert('Invalid date, cannot proceed.');
	}
	else {
		document.location.href = url + '&' + fieldname + '=' + v;
	}
}

var aw;
function NewWindow(url, name, width, height) {
	if (height == '' || height == undefined) {
		height = 640;
	}
	if (width == '' || width == undefined) {
		height = 480;
	}
	if (name == '' || name == undefined) {
		// always open a new window
		window.open(url, name, 'width=' + width + ',height=' + height + ', resizable, scrollbars');
	} 
	else {
		// open in window of same name
		var aw = window.open(url, name, 'width=' + width + ',height=' + height + ', resizable, scrollbars');
		if (aw.opener == null) {
			aw.opener = window;
			}
		else {
			aw.focus();
		}
	}
}