// JavaScript Document

function checkForm() {
	if (!checkName()) {
		document.mailform.name.focus();
		return false;
	} 

	if (!checkComp()) {
		document.mailform.comp.focus();
		return false;
	}

	if (!checkPos()) {
		document.mailform.pos.focus();
		return false;
	}


	if (!checkPer()) {
		document.mailform.per.focus();
		return false;
	}

	if (!checkCity()) {
		document.mailform.city.focus();
		return false;
	}

	if (!checkMail()) {
		document.mailform.email.focus();
		return false;
	}

	if (!checkCell()) {
		document.mailform.cell.focus();
		return false;
	}

	return true;

}



function checkName() {
	var name = document.mailform.name.value;
	if (checkBlank(name)) {
		alert("Please enter your name!");
		return false;
	}
	return true;
}

function checkComp() {
	var comp = document.mailform.comp.value;
	if (checkBlank(comp)) {
		alert("Please enter your Current Employer!");
		return false;
	}
	return true;
}

function checkPos() {
	var pos = document.mailform.pos.value;
	if (checkBlank(pos)) {
		alert("Please enter your position!");
		return false;
	}
	return true;
}

function checkPer() {
	var per = document.mailform.per.value;
	if (checkBlank(per)) {
		alert ("Please enter your current period of employment!");
		return false;
	}
	return true;
}


function checkCity() {
	var city = document.mailform.city.value;
	if (checkBlank(city)) {
		alert ("Please enter the city that you live in!");
		return false;
	}
	return true;
}


function checkCell() {
	var cell = document.mailform.cell.value;
	if (checkBlank(cell)) { 
		alert ("Please enter your cell phone number or alternative number!");
		return false;
	}
	return true;
}

function checkBlank(string) {
	if (string.length == 0)
		return true;
	for (var i = 0; i <= string.length-1; i++)
		if (string.charAt(i) != " ")
			return false;
	return true;
}

function checkMail() {

	var email = document.mailform.email.value;
	if (checkBlank(email)) {
		alert("Please enter your e-mail address!")
		return false;
	}

	var at = email.indexOf("@");
	if (at == -1) 	{
		alert("Please enter a valid email address with an @!")
		return false;
	}

	if (email.indexOf(".",at) == -1) {
		alert("Please enter a valid domain after the @!")
		return false;
	}

	return true;
}
