


function checkFormBasic(b){ 
var firstName 	= document.getElementById('firstName');
var lastName 	= document.getElementById('lastName');
var phone 		= document.getElementById('phone');
var email 		= document.getElementById('email');
var alertx		= document.getElementById('alertx');
	
if(email.value == ''){
	email.focus();
	alertx.innerHTML = "Please enter an e-mail address.<BR><BR>";
        return false;
		}else if(firstName.value == ''){
		firstName.focus();
		alertx.innerHTML = "Please enter your first name.<BR><BR>";
		return false;
			}else if(lastName.value == ''){
			lastName.focus();
			alertx.innerHTML = "Please enter your last name.<BR><BR>";
			return false;
					}else{
  //					checkIfExists(b)
					}
 return true;
}



function checkIfExists(b){ 

	var email	= document.getElementById('email');
	var alertx	= document.getElementById('alertx');
	
	var ajaxRequest;
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
		var result = ajaxRequest.responseText;
			if(result == "FAIL_SQL"){
				alertx.innerHTML = "There was an error querying the database.<br/>IT has been alerted of this issue and will investigate the problem. Please come back and try again later.";
				b.disabled = false;
			}else if(result == "INVALID"){
				alertx.innerHTML = "We already have record of your e-mail address in our database.";
				b.disabled = false;
			}else if(result == "VALID"){
				alertx.innerHTML = '';
				confirmSubmit(b);
			}
		
		}else{
		b.disabled = true;
		}
	}
	var queryString = "?email=" + email.value;
	ajaxRequest.open("GET", "ajax/checkMailListExist.php" + queryString, true);
	ajaxRequest.send(null); 
}






function confirmSubmit(b){
	var answer = confirm("Are you sure you wish to submit this form?\n\nPress 'OK' to submit\nPress 'Cancel' to make changes")
	
	if (answer){
	b.value = 'Submitting...';
	b.disabled = true;
	b.form.submit();
	}else{
	b.disabled = false;
	}
}
