
// This function checks if the username field
// is at least 6 characters long.
// If so, it attaches class="welldone" to the
// containing fieldset.

function checkUsernameForLength(whatYouTyped, length) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > length) {
		fieldset.className = "welldone";
	}
	else {
		fieldset.className = "";
	}
}


function showHint(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	fieldset.className = "welldone";
}


// If the password is at least 4 characters long, the containing
// fieldset is assigned class="kindagood".
// If it's at least 8 characters long, the containing
// fieldset is assigned class="welldone", to give the user
// the indication that they've selected a harder-to-crack
// password.

function checkPassword(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > 3 && txt.length < 8) {
		fieldset.className = "kindagood";
	} else if (txt.length > 7) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}

// This function checks the email address to be sure
// it follows a certain pattern:
// blah@blah.blah
// If so, it assigns class="welldone" to the containing
// fieldset.

function checkEmail(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt)) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}




// this part is for the form field hints to display
// only on the condition that the text input has focus.
// otherwise, it stays hidden.

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


function prepareInputsForHints() {
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i<inputs.length; i++){
    inputs[i].onfocus = function () {
		this.style.backgroundColor = '#FFFFFF';
      this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
    }
    inputs[i].onblur = function () {
      this.parentNode.getElementsByTagName("span")[0].style.display = "none";
    }
  }
}

var http_obj = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http_obj = new ActiveXObject("Microsoft.XMLHTTP");
}else{
  http_obj = new XMLHttpRequest();
}

function validateCaptcha(){
	http_obj.abort();
	http_obj.open("GET", "current_captcha.php", false);

	http_obj.send(null);

	return http_obj.responseText;
}

function validateFormData(){
	var error = 0;
	var current_captcha = validateCaptcha();

	var msg = "Errors have occurred. Please correct: \r\n\r\n";

	if(document.FrontPage_Form1.LastName.value == ""){
		document.FrontPage_Form1.LastName.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Last Name field is empty\r\n";
	}
	if(document.FrontPage_Form1.FirstName.value == ""){
		document.FrontPage_Form1.FirstName.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your First Name field is empty\r\n";
	}
	if(document.FrontPage_Form1.Address.value == ""){
		document.FrontPage_Form1.Address.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Address field is empty\r\n";
	}
	if(document.FrontPage_Form1.City.value == ""){
		document.FrontPage_Form1.City.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your City field is empty\r\n";
	}
	if(document.FrontPage_Form1.D1.value == "Select State"){
		document.FrontPage_Form1.D1.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"You have not selected a State\r\n";
	}
	if(document.FrontPage_Form1.Zip.value == ""){
		document.FrontPage_Form1.Zip.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"You have not entered your Zip code\r\n";
	}
	if(document.FrontPage_Form1.HousePayment.value == ""){
		document.FrontPage_Form1.HousePayment.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your House Payment field is empty\r\n";
	}
	if(document.FrontPage_Form1.Phone.value == ""){
		document.FrontPage_Form1.Phone.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Phone Number field is empty\r\n";
	}
	if(document.FrontPage_Form1.DOB.value == ""){
		document.FrontPage_Form1.DOB.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Date of Birth field is empty\r\n";
	}
	if(document.FrontPage_Form1.SocialSecurity1.value == ""){
		document.FrontPage_Form1.SocialSecurity1.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Social Security Number field is blank\r\n";
	}
	if(document.FrontPage_Form1.SocialSecurity2.value == ""){
		document.FrontPage_Form1.SocialSecurity2.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Social Security Number field is blank\r\n";
	}
	if(document.FrontPage_Form1.SocialSecurity3.value == ""){
		document.FrontPage_Form1.SocialSecurity3.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Social Security Number field is blank\r\n";
	}
	if(document.FrontPage_Form1.Employer.value == ""){
		document.FrontPage_Form1.Employer.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Employer field is empty\r\n";
	}
	if(document.FrontPage_Form1.Occupation.value == ""){
		document.FrontPage_Form1.Occupation.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Occupation field is empty\r\n";
	}
	if(document.FrontPage_Form1.JobYears.value == ""){
		document.FrontPage_Form1.JobYears.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Time at Current Job field is blank\r\n";
	}
	if(document.FrontPage_Form1.JobMonths.value == ""){
		document.FrontPage_Form1.JobMonths.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Time at Current Job field is blank\r\n";
	}
	if(document.FrontPage_Form1.Busphone.value == ""){
		document.FrontPage_Form1.Busphone.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Business Phone Number field is empty\r\n";
	}
	if(document.FrontPage_Form1.Netpay.value == ""){
		document.FrontPage_Form1.Netpay.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"Your Net Salary field is empty\r\n";
	}
	if(document.FrontPage_Form1.ConsentAgreement.value == ""){
		document.FrontPage_Form1.ConsentAgreement.style.backgroundColor = '#ff6666';
		error = 1;
		msg = msg+"You forgot to sign your form\r\n";
	}
	if(document.FrontPage_Form1.captcha.value != current_captcha){
		error = 1;
		msg = msg+"Captcha entered is incorrect\r\n";
	}
	if(error > 0){
		alert(msg);
		return false;
	}else{
		return true;
	}
}
