function CheckNumber(num) {
       var czyPoprawny = true;

       if(num.length>=10) {
               var RegNumber=/([0-9]){3}([- ]){1}([0-9]){3}([- ]){1}([0-9]){4}/i;
               var RegNum10 = /([0-9]){10}/i;
               var wynik1 = RegNumber.test(num);
               var wynik2 = RegNum10.test(num);
       } else {
               czyPoprawny = false;
       }

       if ( ((wynik1==false) && (wynik2==false)) || (czyPoprawny == false) ) {
               return false;
       }

       return true;
}




function checkFormSF() {

with (document.forms['formSf']) {
var alertMsg = "Following fields are required:\n";
var testradio = 0;
var x = 0;

if (firstName.value == "") alertMsg += "\nFirst name";
if (lastName.value == "") alertMsg += "\nLast name";
if ((emailAddress.value == "") || (emailAddress.value.indexOf ('@') == -1) || (emailAddress.value.indexOf ('.') == -1)) alertMsg += "\nEmail Address";
if (howHeard.value == "") alertMsg += "\nHow did you hear about us?";

for (x=0; x<coBorrowerYesNo.length; x++) {
	if (coBorrowerYesNo[x].checked) { testradio = 1; }
}

if (testradio == 0) alertMsg += "\nCo-Applicant";

if ((homePhone1.value == "") || (homePhone2.value == "") || (homePhone3.value == "") || ( isNaN(homePhone1.value)) || ( isNaN(homePhone2.value)) || ( isNaN(homePhone3.value))) alertMsg += "\nEvening Phone";

if ( ( isNaN(workPhone1.value)) || ( isNaN(workPhone2.value)) || ( isNaN(workPhone3.value))) alertMsg += "\nWork Phone has a bad format";


if (alertMsg != "Following fields are required:\n") {
alert(alertMsg);
return false;
} else {
return true;
} } 

}



function checkFormsAP(form) {

	var numer1;
	var alertMsg = "Following fields are required:\n";
	
	with (form) {
		
		if (Ap_First_Name.value == "") alertMsg += "\nFirst name";
		if (Ap_Last_Name.value == "") alertMsg += "\nLast name";
		if (! (isNumber(Ap_DOB2.value) && isNumber(Ap_DOB3.value))) alertMsg += "\nDate of birth";
		if (Ap_Marital_Status.value == "") alertMsg += "\nMarital status";
		if (Ap_Dependents.value == "") alertMsg += "\nDependents";
		if (Ap_Address1.value == "") alertMsg += "\nAddress";
		if (Ap_City1.value == "") alertMsg += "\nCity";
		if (Ap_Province1.value == "") alertMsg += "\nProvince";
		if (Ap_Years_At_Address1.value == "") alertMsg += "\nYears there";
		if (Ap_Email.value == "") alertMsg += "\nE-mail address";

		if (CheckNumber(Ap_Home_Phone.value) == false ) alertMsg += "\nHome phone";
		
		if (Ap_Residential_Status.value == "") alertMsg += "\nResidential status";
		if (Ap_Employer.value == "") alertMsg += "\nCurrent employer";
		if (Ap_Occupation.value == "") alertMsg += "\nCurrent occupation";
		
		if (CheckNumber(Ap_Work_Phone.value) == false ) alertMsg += "\nWork phone";

		if (Ap_Work_Address.value == "") alertMsg += "\nCurrent employer address";
		if (Ap_Income.value == "") alertMsg += "\nGross yearly income";
		if (Ap_Years_Employed.value == "") alertMsg += "\nYear there";
	}


		if (alertMsg != "Following fields are required:\n") {
			alert(alertMsg);
			return false;
		} else {
			return true;
		} 

}




function checkContactForm() {

	with (document.forms['contactForm']) {
		var alertMsg = "Following fields are required:\n";

		if (imie.value == "") alertMsg += "\nYour Name";
		if ((email.value == "") || (email.value.indexOf ('@') == -1) || (email.value.indexOf ('.') == -1)) alertMsg += "\nYour Email Address";
		if (mess.value == "") alertMsg += "\nMessage";

		if (alertMsg != "Following fields are required:\n") {
			alert(alertMsg);
			return false;
		} else {
			return true;
		} 
	} 

}


function checkFormWho() {

	with (document.forms['formWho']) {
		var alertMsg = "Following fields are required:\n";

		if (imie.value == "") alertMsg += "\nYour Name";
		if ((email.value == "") || (email.value.indexOf ('@') == -1) || (email.value.indexOf ('.') == -1)) alertMsg += "\nYour Email";

		if (alertMsg != "Following fields are required:\n") {
			alert(alertMsg);
			return false;
		} else {
			//return true;
			submit();
		} 
	} 

}



function checkMultiForm() {

	with (document.forms['multiForm']) {
		var alertMsg = "Following fields are required:\n";

		if (name.value == "") alertMsg += "\nYour Name";
		if ((email.value == "") || (email.value.indexOf ('@') == -1) || (email.value.indexOf ('.') == -1)) alertMsg += "\nYour Email";

		if (alertMsg != "Following fields are required:\n") {
			alert(alertMsg);
			return false;
		} else {
			return true;
		} 
	} 

}


function checkFormQuick() {

	with (document.forms['formQuick']) {
		var alertMsg = "Following fields are required:\n";
		var r1 = new RegExp("[ |(|)|-]+");

		var tel = phone.value.replace(r1, '');
		tel = tel.replace(r1, '');
		tel = tel.replace(r1, '');
		tel = tel.replace(r1, '');
		tel = tel.replace(r1, '');
		tel = tel.replace(r1, '');
		tel = tel.replace(r1, '');
		tel = tel.replace(r1, '');
		tel = tel.replace(r1, '');
		tel = tel.replace(r1, '');

		if (! isNumber(tel) ) tel = '';

		if (loanType.value == "") alertMsg += "\nType of loan";
		if (creditHistory.value == "") alertMsg += "\nCredit history";
		if (monthlyExpenses.value == "") alertMsg += "\nProperty Value";
		if (loanAmount.value == "") alertMsg += "\nLoan Amount";
		if (firstName.value == "") alertMsg += "\nFirst name";
		//if (lastName.value == "") alertMsg += "\nLast Name";
		if (tel.length < 10) alertMsg += "\nPhone (at least 10 digits)";
		if ((email.value == "") || (email.value.indexOf ('@') == -1) || (email.value.indexOf ('.') == -1)) alertMsg += "\nYour Email";

		if (alertMsg != "Following fields are required:\n") {
			alert(alertMsg);
			return false;
		} else {
			return true;
		} 
	 }

}


function isNumber(str) {
  var r1 = new RegExp("^[0-9]+$");
  return (r1.test(str));
}

