// JavaScript Document
function fncValidateForm(objForm) {
	var strErrorMsg = "";
	var intErrors = 0;

	if (document.getElementById("employer_id").value == 0) {
		strErrorMsg += " --> Employer / Association\n";
		intErrors++;
	}

	if (document.getElementById("title_id").value == 0) {
		strErrorMsg += " --> Title\n";
		intErrors++;
	}

	var vaString = '^([a-zA-Z ]+)$';
	var regex = new RegExp(vaString);
	var strValidSample = "bob brown";
	var strName = new String(objForm.fname.value);
	var strName = new String(objForm.lname.value);

	if (strValidSample.search(regex) == -1) {
	alert('error name');
	} else {
		if (objForm.fname.value.search(regex) == -1 || strName.length == 0) {
			strErrorMsg += " --> First name\n";
			intErrors++;
		}
		if (objForm.fname.value.search(regex) == -1 || strName.length == 0) {
			strErrorMsg += " --> Surname\n";
			intErrors++;
		}
	}

	if (objForm.address.value == "") {
		strErrorMsg += " --> Address\n";
		intErrors++
		}
		
	/**var daString = '^(19|20)([0-9]{2}-((0[13-9]|1[0-2])-(0[1-9]|[12][0-9]|30)|(0[13578]|1[02])-31|02-(0[1-9]|1[0-9]|2[0-8]))|([2468]0|[02468][48]|[13579][26])-02-29)$';
	var daString ='^([0-9-]+)$';
	var regex = new RegExp(daString);
	var strValidSample = "19-09-1980";
	var strDate = new String(objForm.dob.value);

	if (strValidSample.search(regex) == -1) {
	alert('error date of birth');
	} else {
		if (objForm.dob.value.search(regex) == -1 || strDate.length == 0) {
			strErrorMsg += " --> Date of birth\n";
			intErrors++;
		}
	}**/

	//validate email address
	var reString = /^(\w+([-.]\w)*)+[@]\w+(([-]\w+)*[.]\w+)+$/;
	var regex = new RegExp(reString);
	var strValidSample = "aaa.bbbbbb@cccc.ddd";
	var strEmail = new String(objForm.email.value);
	if (strValidSample.search(regex) == -1) {
		// this is netscape 4.x or early IE 5.0x
		// we'll check for a @, the presence of spaces, a length of at least 6 (a@b.co is the smallest valid email string), the presence of a .
		if((strEmail.indexOf("@") == -1) || (strEmail.indexOf(" ") > -1) || (strEmail.length < 6) || (strEmail.length == 0)  || (strEmail.indexOf(".") == -1)) {
			/* email is not valid */
			strErrorMsg += " --> Email address\n";
			intErrors++;
		}
	} else {
		/* email is empty */
		if (objForm.email.value.search(regex) == -1 || strEmail.length == 0) {
			/* strErrorMsg += " --> Email address\n";
			intErrors++; */
			var email_field = false;
		}
	}

	var vaString = '^([0-9 -]+)$';
	var regex = new RegExp(vaString);
	var strValidSample = "07 827 5968";
	var strPhone = new String(objForm.phone.value);
	var strCellPhone = new String(objForm.cell_phone.value);
	var strWorkPhone = new String(objForm.work_phone.value);
	var strExt = new String(objForm.ext.value);

	if (strValidSample.search(regex) == -1) {
	alert('error phone');
	} else {
		if (objForm.phone.value.search(regex) == -1 && strPhone.length != 0) {
			strErrorMsg += " --> Phone\n";
			intErrors++;
		}
		if (objForm.cell_phone.value.search(regex) == -1 || strCellPhone.length == 0) {
			if(email_field == false)
			{
				strErrorMsg += " --> You must enter an email address or a cell phone\n";
				intErrors++;
			}
		}
		if (objForm.work_phone.value.search(regex) == -1 && strWorkPhone.length != 0) {
			strErrorMsg += " --> Work Phone\n";
			intErrors++;
		}
		if (objForm.ext.value.search(regex) == -1 && strExt.length != 0) {
			strErrorMsg += " --> Ext\n";
			intErrors++;
		}
	}

	var vaString = '^([0-9]+)$';
	var regex = new RegExp(vaString);
	var strValidSample = "10";
	var strRegion = new String(document.getElementById("region_id").value);


	if (strValidSample.search(regex) == -1) {
	alert('error region');
	} else {
		if (document.getElementById("region_id").value.search(regex) == -1 || strRegion.length == 0) {
			strErrorMsg += " --> Region\n";
			intErrors++;
		}
	}

	if (intErrors > 0) {
		alert("Please make valid entries in the following field(s):\n" + strErrorMsg);
		return false;
	}
	else {
		var region = document.getElementById("region_id").value;
		var district = document.getElementById("district_id").value;
		var suburb = document.getElementById("suburb_id").value;
		objForm.region.value = region;
		objForm.district.value = district;
		objForm.suburb.value = suburb;
		return true;
	}
}