

submitCount = 0;

function openWindow(strUrl) {

// var intLeft = (screen.width / 2)
// intLeft = screen.width - intLeft - (intLeft/2)
// var intTop = (screen.height / 2) - 285;

	intLeft = 0
	intTop = 0
	
	var strParam = "toolbars=no,scrollbars=yes,resizable=no,width=520,height=500,left=" + intLeft + ",top=" + intTop;
	
	window.open(strUrl, "popup", strParam);
}
	
function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber = true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function IsValid(sText) {
	var IsValid = true;
	var Char;
	if (sText.charAt(0) == "0") {
		IsValid = false;
	}
	if (sText.charAt(0) == "1") {
		IsValid = false;
	}
	return IsValid;   
}

function onlyOnce() {
	if (bolError = false) {
		submitCount += 1;
		if (submitCount > 1) {
	        var strMessage = "Please be patient. You have already submitted this form. Pressing submit multiple times will result in your information being submitted multiple times. You will receive a response momentarily.";
			if (submitCount == 2) {
				strMessage = "DO NOT PRESS SUBMIT MULTIPLE TIMES! YOUR ACCOUNT WILL BE SENT EACH TIME YOU PRESS SUBMIT! Due to high traffic processing may take up to one minute.";
			}
			alert(strMessage);
			return false;
		} else {
			return true;
		}
	}
}

function validateInfo() {
	
	var strNetMonthly = document.onlineConsult.net_monthly_income.value;
	re = /^\$|,/g;
	strNetMonthly = strNetMonthly.replace(re,"");
	
	var strTotalMonthly = document.onlineConsult.total_monthly_exp.value;
	strTotalMonthly = strTotalMonthly.replace(re,"");
	
	bolDebt = false;
	bolError = false;
	strError = "The following required fields are missing or have errors:\n";
		
	if (document.onlineConsult.first_name.value.length < 2) {
	strError  += "- First Name\n";
		bolError = true;
	}

	if (document.onlineConsult.last_name.value.length < 2) {
		strError += "- Last Name\n";
		bolError = true;
	}
	
// Home Phone Exists
	if (document.onlineConsult.home_areacode.value.length < 3) {
		strError += "- Home Phone Area Code\n";
		bolError = true;
	}
	if (document.onlineConsult.home_prefix.value.length < 3) {
		strError += "- Home Phone Prefix\n";
		bolError = true;
	}
	if (document.onlineConsult.home_phone.value.length < 4) {
		strError += "- Home Phone\n";
		bolError = true;
	}

// Numeric Check - Home Phone
	if (IsNumeric(document.onlineConsult.home_phone.value) == false) {
		strError += "- Home Phone must contain only numbers\n";
		bolError = true;
	}
	if (IsNumeric(document.onlineConsult.home_areacode.value) == false) {
		strError += "- Home Phone Area Code must contain only numbers\n";
		bolError = true;
	}
	if (IsNumeric(document.onlineConsult.home_prefix.value) == false) {
		strError += "- Home Phone Prefix must contain only numbers\n";
		bolError = true;
	}

// Numeric Check, Zero of One - Home Phone
	if (IsValid(document.onlineConsult.home_areacode.value) == false) {
		strError += "- Home Phone Area Code must not contain a zero or one for the first number\n";
		bolError = true;
	}
	if (IsValid(document.onlineConsult.home_prefix.value) == false) {
		strError += "- Home Phone Prefix must not contain a zero or one for the first number\n";
		bolError = true;
	}
	
// Numeric Check - Work Phone
	if (IsNumeric(document.onlineConsult.work_phone.value) == false) {
		strError += "- Work Phone must contain only numbers\n";
		bolError = true;
	}
	if (IsNumeric(document.onlineConsult.work_areacode.value) == false) {
		strError += "- Work Phone Area Code must contain only numbers\n";
		bolError = true;
	}
	if (IsNumeric(document.onlineConsult.work_prefix.value) == false) {
		strError += "- Work Phone Prefix must contain only numbers\n";
		bolError = true;
	}

// Numeric Check, Zero of One - Work Phone
	if (IsValid(document.onlineConsult.work_areacode.value) == false) {
		strError += "- Work Phone must not contain a zero or one for the first number\n";
		bolError = true;
	}
	if (IsValid(document.onlineConsult.work_prefix.value) == false) {
		strError += "- Work Phone Prefix must not contain a zero or one for the first number\n";
		bolError = true;
	}
	
// Numeric Check - Other Phone
	if (IsNumeric(document.onlineConsult.other_phone.value) == false) {
		strError += "- Cell Phone must contain only numbers\n";
		bolError = true;
	}
	if (IsNumeric(document.onlineConsult.other_areacode.value) == false) {
		strError += "- Cell Phone Area Code must contain only numbers\n";
		bolError = true;
	}
	if (IsNumeric(document.onlineConsult.other_prefix.value) == false) {
		strError += "- Cell Phone Prefix must contain only numbers\n";
		bolError = true;
	}

// Numeric Check - Zero of One - Other Phone
	if (IsValid(document.onlineConsult.other_areacode.value) == false) {
		strError += "- Cell Phone Area Code must not contain a zero or one for the first number\n";
		bolError = true;
	}
	if (IsValid(document.onlineConsult.other_prefix.value) == false) {
		strError += "- Cell Phone Prefix must not contain a zero or one for the first number\n";
		bolError = true;
	}

// Check state
	if (document.onlineConsult.state.selectedIndex == 0) {
		strError += '- State\n';
		bolError = true;
	}
	if (document.onlineConsult.email.value == '') {
		strError += "- Email\n";
		bolError = true;
	}
	
	for (i = 0; i <= 9; i++) {
		if (document.onlineConsult.total_unsecured_debt[i].checked == true) {
			bolDebt = true;
		}
	}

	if (document.onlineConsult.total_unsecured_debt.selectedIndex == 0) {
		strError += '- Debt has to be $7,500 or greater\n';
		bolError = true;
	}
	
	if (bolError) {
		alert(strError);
		return false;
	} else {
		document.onlineConsult.submit();
	}
}


