// Image Swapping Code
menuBullet = new Image();
	menuBullet.src = "images/menuBullet.gif";
menuBulletOver = new Image();
	menuBulletOver.src = "images/menuBulletOver.gif";
menuBulletOn = new Image();
	menuBulletOn.src = "images/menuBulletOn.gif";

function swap(imageName,mouseAction) {
	if (document.images) {
		if (mouseAction == 'over')
			document.images[imageName].src = menuBulletOver.src;
		else
			document.images[imageName].src = menuBullet.src;
	}
}

// Code related to the Mortgage Calculator
function floor(number)
{
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}

function _calc() {
  var mi = document.piti.interest.value / 1200;
  var base = 1;
  var mbase = 1 + mi;
  for (i=0; i<document.piti.years.value * 12; i++)
  {
    base = base * mbase;
  }
  document.piti.p_i.value = floor(document.piti.amt.value * mi / ( 1 - (1/base)));
  document.piti.mtax.value = floor(document.piti.tax.value / 12);
  document.piti.mins.value = floor(document.piti.ins.value / 12);
  document.piti.mhoassn.value = floor(document.piti.hoassn.value / 12);
  var _sum = document.piti.amt.value * mi / ( 1 - (1/base)) +
	document.piti.tax.value / 12 + 
	document.piti.ins.value / 12 +
	document.piti.hoassn.value / 12;
  document.piti.mpay.value = floor(_sum);
}

function clearVal(_field) {
	curVal = _field.value;
	_field.value='';
}

function checkVal(_field) {
	if (_field.value == '') { //if, on exit, the field is blank and a
		if (curVal)			  // previous value exists, re-enter it
		_field.value=curVal;
	}
	else {					  // otherwise check the new value
		var newVal = '';
		var v = _field.value;
		for (i=0;i<v.length;i++) {
			_char = v.substring(i,i+1);  // check each character for num or dot
			if ((!isNaN(_char) && !isNaN(parseInt(_char))) || _char == '.')
				newVal += _char;  // create new value composed of only those chars
		}
		_field.value=newVal;
	}
}

function _reset() {
	document.piti.reset();
}

// Code for Application Form
function checkApp() {
	req_failed = 0; // set required "failed" flag to false;
	requiredFields = new Array('name_first','name_last','SSN1','SSN2','SSN3','phone_home1','phone_home2','phone_home3','street1','city','state','zip');
	displayEquivalents = new Array('First Name','Last Name','Social Security Number','Social Security Number','Social Security Number','Phone Number','Phone Number','Phone Number','Street Address','City','State','Zip Code');
	i=0;
	while (i<requiredFields.length) {
		fieldName = requiredFields[i];
		if (eval('document.app_form.'+fieldName).value == '' || eval('document.app_form.'+fieldName).value == ' ') {
			req_failed = 1;
		}
		if (req_failed) break;
		else i++;
	}
	if (req_failed) { // if any of the required fields are missing, send an alert and stop processing
		alert('\"' + displayEquivalents[i] + '\"' + ' is a required field.');
		eval('document.app_form.'+fieldName).focus();
		return false;
	}
	
	// ensure that numeric fields look like numbers
	num_failed = 0; // set numeric "failed" flag to false;
	numFields = new Array(
					'SSN1','SSN2','SSN3',
					'phone_home1','phone_home2','phone_home3',
					'phone_work1','phone_work2','phone_work3',
					'SSN1_cb','SSN2_cb','SSN3_cb',
					'phone_home1_cb','phone_home2_cb','phone_home3_cb',
					'phone_work1_cb','phone_work2_cb','phone_work3_cb',
					'zip',
					'income_primary_rate','income_other_rate',
					'mortgage','rent'
					);
	numDisplayEquivalents = new Array(
					'Social Security Number','Social Security Number','Social Security Number',
					'Phone Number','Phone Number','Phone Number',
					'Phone Number','Phone Number','Phone Number',
					'Social Security Number','Social Security Number','Social Security Number',
					'Phone Number','Phone Number','Phone Number',
					'Phone Number','Phone Number','Phone Number',
					'Zip Code',
					'Income','Income',
					'Mortgage Rate','Rent Rate'
					);
	ni = 0;
	while (ni<numFields.length) {
		numFieldName = numFields[ni];
		if (eval('document.app_form.'+numFieldName).value != ''){
			if (isNaN(eval('document.app_form.'+numFieldName).value) || isNaN(parseInt(eval('document.app_form.'+numFieldName).value))) {
				num_failed = 1;
			}
		}
		if (num_failed) break;
		else ni++;
	}
	if (num_failed) {
		alert('\"' + numDisplayEquivalents[ni] + '\"' + ' must be numeric.');
		eval('document.app_form.'+numFieldName).focus();
		eval('document.app_form.'+numFieldName).select();
		return false;
	}
	
	// ensure zip code has five digits
	if (document.app_form.zip.value.length != 5) {
			alert('\"Zip Code\"' + ' must have 5 digits.');
			document.app_form.zip.focus();
			document.app_form.zip.select();
			return false;
	}
	
	// ensure state is two characters
	if (document.app_form.state.value.length != 2) {
			alert('\"State\"' + ' must have 2 characters.');
			document.app_form.state.focus();
			document.app_form.state.select();
			return false;
	}
	return true;
}