// JavaScript Document

function showStep(num) {
	var numSteps = 3;
	
	for (var i = 1; i <= numSteps; i++) {
		if (i == num) {
			document.getElementById("step" + i).style.display = "block";	
		} else {
			document.getElementById("step" + i).style.display = "none";	
		}
	}
}

/* Form Validation */

function validate_checkbox(field,alerttxt) {
	if (field.checked == false) {
	  return alerttxt;
	} else {
	  return "";
	}
}
function validate_required(field,alerttxt) {
	with (field) {
	  if (field.value==null||field.value=="") {
		  return alerttxt;
	  } else {
		  return "";
	  }
	}
}
function validate_radio(field,alerttxt) {
	if (field.checked == false) {
	  return alerttxt;
	} else {
	  return "";
	}
}

/* Step 1 Validation */

function validateStepOne() {
	var errMsg = "";
	errMsg += validate_required(document.app.companyName,"- Company Name\n");
	errMsg += validate_required(document.app.companyStreet,"- Street\n");
	errMsg += validate_required(document.app.companyCity,"- City\n");
	errMsg += validate_required(document.app.companyState,"- State\n");
	errMsg += validate_required(document.app.companyZip,"- Zip\n");
	errMsg += validate_required(document.app.contactName,"- Contact Name\n");
	errMsg += validate_required(document.app.contactTitle,"- Contact Title\n");
	errMsg += validate_required(document.app.contactPhone,"- Phone\n");
	errMsg += validate_required(document.app.contactFax,"- Fax\n");
	errMsg += validate_required(document.app.contactEmail,"- Email\n");	
	
	if (errMsg.length == 0) {
		document.MM_returnValue = true;
		showStep(2);
		document.location.hash = 2;
	} else {
		alert("You must fill in the following fields:\n\n" + errMsg);
		document.MM_returnValue = false;
	}
}


function validateStepTwo() {
	var errMsg = "";
	errMsg += validate_required(document.app.officer1Name,"- Officer 1 Name\n");
	errMsg += validate_required(document.app.officer1Title,"- Officer 1 Title\n");
	errMsg += validate_required(document.app.officer1SSN,"- Officer 1 SSN\n");
	errMsg += validate_required(document.app.officer1Ownership,"- Officer 1 % Ownership\n");
	
	errMsg += validate_required(document.app.bankName,"- Bank Name\n");
	errMsg += validate_required(document.app.bankContactName,"- Bank Contact Name\n");
	errMsg += validate_required(document.app.bankPhone,"- Bank Phone\n");
	errMsg += validate_required(document.app.bankCheckingAccount,"- Checking Account #\n");
	
	if (errMsg.length == 0) {
		document.MM_returnValue = true;
		showStep(3);
		document.location.hash = 3;
	} else {
		alert("You must fill in the following fields:\n\n" + errMsg);
		document.MM_returnValue = false;
	}
}

function validateStepThree() {
	if (document.location.hash == "#3") {
		var errMsg = "";
		errMsg += validate_radio(document.app.equipmentNewUsed,"- New/Used\n");
		errMsg += validate_required(document.app.equipmentYear,"- Year\n");
		errMsg += validate_required(document.app.equipmentDesc,"- Description\n");
		errMsg += validate_required(document.app.equipmentCost,"- Estimated Cost\n");
		errMsg += validate_radio(document.app.equipmentWorkingCap,"- Working Capital Question\n");
		errMsg += validate_radio(document.app.equipmentTerm,"- Terms (Months) Requested\n");
		
		errMsg += validate_required(document.app.sellerName,"- Seller Name\n");
		errMsg += validate_required(document.app.sellerStreet,"- Seller Street\n");
		errMsg += validate_required(document.app.sellerCity,"- Seller City\n");
		errMsg += validate_required(document.app.sellerState,"- Seller State\n");
		errMsg += validate_required(document.app.sellerZip,"- Seller Zip\n");
		errMsg += validate_required(document.app.sellerPhone,"- Seller Phone\n");
		errMsg += validate_required(document.app.sellerEmail,"- Seller Email\n");
	
		errMsg += validate_checkbox(document.app.terms,"- Accept Terms and Conditions\n");
		errMsg += validate_required(document.app.termsName,"- Authorized Signature\n");
		errMsg += validate_required(document.app.termsTitle,"- Title\n");
		
		if (errMsg.length == 0) {
			document.MM_returnValue = true;
		} else {
			alert("You must fill in the following fields:\n\n" + errMsg);
			document.MM_returnValue = false;
		}
	} else if (document.location.hash == "#2") {
		document.MM_returnValue = false;
		validationStepTwo();
	} else {
		document.MM_returnValue = false;
		validationStepOne();
	}
}
