// Darren Chowles - darren@netdreams.co.uk
// 30 Oct 2007

function trim(text){
	text = text.replace(/^\s+/, "");
	text = text.replace(/\s+$/, "");
	text = text.replace(/\s+/g, " ");
	return text;
}

function sendFeedback(){		

	var objForm = document.getElementById("frmEnquiry");
	
	if (trim(objForm.frm_first.value).length < 2){
		alert("Please enter your first name.");
		objForm.frm_first.value = trim(objForm.frm_first.value);
		objForm.frm_first.focus();
		return false;
	}
	
	if (trim(objForm.frm_sur.value).length < 2){
		alert("Please enter your last name.");
		objForm.frm_sur.value = trim(objForm.frm_sur.value);
		objForm.frm_sur.focus();
		return false;
	}
	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(trim(objForm.frm_email.value)))){
		alert("Please enter a valid email address for yourself.");
		objForm.frm_email.value = trim(objForm.frm_email.value);
		objForm.frm_email.focus();
		return false;
	}
	
	return true;
	
	//new Ajax.Request('code/includes/send_feedback.asp?_r=' + Math.random(), {method: 'post', parameters: $('frmEnquiry').serialize(true), evalScripts: true, onComplete: completeSendFeedback});
	
}

function sendOTP(){		

	var objForm = document.getElementById("frmSub");
	
	if ((trim(objForm.frm_name.value).length < 2) || (trim(objForm.frm_name.value) == "Name:")){
		alert("Please enter your name.");
		objForm.frm_name.value = trim(objForm.frm_name.value);
		objForm.frm_name.focus();
		return false;
	}
	
	if ((trim(objForm.frm_jobtitle.value).length < 2) || (trim(objForm.frm_jobtitle.value) == "Job Title:")){
		alert("Please enter your job title.");
		objForm.frm_jobtitle.value = trim(objForm.frm_jobtitle.value);
		objForm.frm_jobtitle.focus();
		return false;
	}
	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(trim(objForm.frm_email.value))) || (trim(objForm.frm_email.value) == "Email:")){
		alert("Please enter a valid email address for yourself.");
		objForm.frm_email.value = trim(objForm.frm_email.value);
		objForm.frm_email.focus();
		return false;
	}
	
	new Ajax.Request('code/includes/send_otp.asp?_r=' + Math.random(), {method: 'post', parameters: $('frmSub').serialize(true), evalScripts: true, onComplete: completeSendOTP});
	
}
		
function completeSendOTP(transport){
	response = transport.responseText;
	
	$('frmSub').reset();
	
	if (response == "ok"){
		$('alertContentsFeed').innerHTML = 'Thank you for subscribing.<br />&nbsp;<br />&nbsp;';
	}else{
		$('alertContentsFeed').innerHTML = 'An error occurred trying to send feedback.';
	}
	
}





function registerForm(){		

	var objForm = document.getElementById("frmReg");
	
	if (trim(objForm.frm_first.value).length < 2){
		alert("Please enter your first name.");
		objForm.frm_first.value = trim(objForm.frm_first.value);
		objForm.frm_first.focus();
		return false;
	}
	
	if (trim(objForm.frm_sur.value).length < 2){
		alert("Please enter your last name.");
		objForm.frm_sur.value = trim(objForm.frm_sur.value);
		objForm.frm_sur.focus();
		return false;
	}
	
	if (trim(objForm.frm_job.value).length < 2){
		alert("Please enter your job title.");
		objForm.frm_job.value = trim(objForm.frm_job.value);
		objForm.frm_job.focus();
		return false;
	}
	
	if (trim(objForm.frm_contact.value).length < 2){
		alert("Please enter your contact number.");
		objForm.frm_contact.value = trim(objForm.frm_contact.value);
		objForm.frm_contact.focus();
		return false;
	}
	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(trim(objForm.frm_email.value)))){
		alert("Please enter a valid email address for yourself.");
		objForm.frm_email.value = trim(objForm.frm_email.value);
		objForm.frm_email.focus();
		return false;
	}
	
	if (trim(objForm.frm_password.value).length < 2){
		alert("Please enter your desired account password.");
		objForm.frm_password.value = trim(objForm.frm_password.value);
		objForm.frm_password.focus();
		return false;
	}
	
	return true;
	
}