// JScript source code
function isValidEmail(str) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
		return true;
	}
	else {
		return false;
	}
}

function checkquicklogin(){
	var ftxt = '';
	
	if (document.quickloginform.Username.value==''){
		ftxt += '\n- Please enter your Username.';
	}
	
	if (document.quickloginform.Password.value==''){
		ftxt += '\n- Please enter your Password.';
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checkquicksearch(){
	if (document.quicksearch.Criteria.value==''){
		alert('Please enter your Search Criteria.');
		return false;
	}
	else {
		return true;
	}
}

function checkmainsearch(){
	if (document.mainsearch.Criteria.value==''){
		alert('Please enter your Search Criteria.');
		return false;
	}
	else {
		return true;
	}
}

function checkforgottenpassword(){
	var ftxt = '';
	
	if (document.forgottenpassword.fUsername.value==''){
		ftxt += '\n- Please enter your Username.';
	}
	
	if (isValidEmail(document.forgottenpassword.fEmailAddress.value)==false){
		ftxt += '\n- Please enter your Email Address.';
	}

	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function toggleBookingButton(){
	var btn = document.getElementById("RegisterButton")
	var chk = document.registernow.TermsAgreed
	
	if (chk.checked==true){
		btn.disabled=false;
	}
	else {
		btn.disabled=true;
	}
}

var pcrex = new RegExp("^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$","i");

function checkregisterform(){
	var ftxt = '';	
	
	if (document.registernow.rName.value==''){
		ftxt += '\n- Please enter your Name.';
	}
	
	if (isValidEmail(document.registernow.rEmailAddress.value)==false){
		ftxt += '\n- Please enter your Email Address.';
	}
	
	if (document.registernow.rUsername.value==''){
		ftxt += '\n- Please enter a Username.';
	}
	else if (document.registernow.rUsername.value.length<5){
		ftxt += '\n- Please ensure your Username is a minimum of 5 Characters long.';
	}
	
	if (document.registernow.rPassword.value==''||document.registernow.rPasswordRepeat.value==''){
		ftxt += '\n- Please enter a Chosen Password Twice.';
	}
	else if (document.registernow.rPassword.value!==document.registernow.rPasswordRepeat.value){
		ftxt += '\n- Please ensure both Chosen Password\'s Match.';
	}
	else if ((document.registernow.rPassword.value==document.registernow.rPasswordRepeat.value)&&document.registernow.rPassword.value.length<6){
		ftxt += '\n- Please ensure your Password is a minimum of 6 Characters long.';
	}
	
	if (document.registernow.rHouseNumber.value==''){
		ftxt += '\n- Please enter your House/Building Number.';
	}
	
	if (pcrex.test(document.registernow.rPostcode.value)==false){
		ftxt += '\n- Please enter your Postcode.';
	}
	
	if (document.registernow.TermsAgreed.checked==false){
		ftxt += '\n- You must agree to the User Agreement before registering.';
	}
		
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checkpostcodesearch(){
	if (pcrex.test(document.postcodesearchform.Postcode.value)==false||document.postcodesearchform.Radius.value==''){
		alert('Please enter your Postcode and select a Search Radius.');
		return false;
	}	
	else {
		return true;
	}
}

function checkmainlogin(){
	var ftxt = '';
	
	if (document.mainlogin.mUsername.value==''){
		ftxt += '\n- Please enter your Username.';
	}	
	
	if (document.mainlogin.mPassword.value==''){
		ftxt += '\n- Please enter your Password.';
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checkeditform(){
	var ftxt = '';
	
	if (document.editreg.rName.value==''){
		ftxt += '\n- Please enter your Name.';	
	}
	
	if (isValidEmail(document.editreg.rEmailAddress.value)==false){
		ftxt += '\n- Please enter your Email Address.';
	}
	
	if (document.editreg.rPassword.value!==document.editreg.rPasswordRepeat.value){
		ftxt += '\n- Please ensure both New Password\'s Match.';
	}
	else if (document.editreg.rPassword.value.length<6){
		ftxt += '\n- Please ensure your Password is a Minimum of 6 Characters.';
	}
	
	if (document.editreg.rHouseNumber.value==''){
		ftxt += '\n- Please enter your House Number.';
	}
	
	if (pcrex.test(document.editreg.rPostcode.value)==false){
		ftxt += '\n- Please enter your Postcode.';
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function removeitem(submitString){
	if (confirm('Are you sure you want to remove this item from the FreeBaye.com site?')){
		location.href=submitString;
	}
}

function checkgetitem(){
	if (confirm('Are you sure you want to commit to collecting this item from the owner?')){
		return true;
	}
	else {
		return false;
	}
}

function checklistitem(){
	var ftxt = '';
	
	if (document.listitem.CategoryID.value==''){
		ftxt += '\n- Please select a Category.';
	}
	
	if (document.listitem.Name.value==''){
		ftxt += '\n- Please enter a Title.';
	}
	
	if (document.listitem.Description.value==''){
		ftxt += '\n- Please enter a Description.';
	}
	
	if (document.listitem.file.value==''){
		ftxt += '\n- Please select a Photo.';
	}

	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checkcontactform(){
	var ftxt = '';
	
	if (document.contactform.Name.value==''){
		ftxt += '\n- Please enter your Name.';
	}
	
	if (isValidEmail(document.contactform.email.value)==false){
		ftxt += '\n- Please enter your Email Address.';
	}
	
	if (document.contactform.subject.value==''){
		ftxt += '\n- Please select a Subject.';	
	}
	
	if (document.contactform.Comments.value==''){
		ftxt += '\n- Please enter your Comments.';
	}

	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}