
function process_form(postvars) {
	var errors=new Array();
	if (isBlank($('f-name').value)) {
		errors[errors.length]='Please enter your name.';
	}
	var found=false;
	if (!isBlank(byo_string_only_numbers($('f-tel').value))) {
		if (byo_string_only_numbers($('f-tel').value).length<7) {
			errors[errors.length]='Telephone number too short, please enter a longer one.';
		} else { 
			found=true; 
		}
	} else if (!isBlank(byo_string_only_numbers($('f-mobile').value))) {
		if (byo_string_only_numbers($('f-mobile').value).length<7) {
			errors[errors.length]='Mobile number too short, please enter a longer one.';
		} else {
			found=true;
		}
	}
	if (!found) {
		errors[errors.length] = 'Please enter a contact telephone number';
	}
	if (!isBlank($('f-email').value) && !isEmail($('f-email').value)) {
		errors[errors.length] = 'The e-mail address you entered is not valid.'
	}
	if (errors.length > 1) {
		alert('There are '+errors.length+' errors that must be fixed before you can continue.\n\n* '+errors.join('\n* '));
		return;
	} else if (errors.length > 0) {
		alert('There is an error that must be fixed before you can continue.\n\n* '+errors.join('\n* '));
		return;
	}
	new Effect.BlindUp('byo-formdiv', {duration: 1, afterFinish: function() {
			var p=postvars.value.evalJSON();
			p['f-name']=$('f-name').value;
			p['f-email']=$('f-email').value;
			p['f-tel']=$('f-tel').value;
			p['f-mobile']=$('f-mobile').value;
			p['f-additional-notes']=$('f-additional-notes').value;
			p['f-nomailing']=$('f-nomailing').checked;

			$('byo_iframe').contentWindow.document.location = 'iframe_complete.html';
			new Ajax.Updater('byo-formdiv', 'contact_submit.php', {parameters: p, onComplete: function() {
					new Effect.ScrollTo('byo-formdiv-heading', { duration: 1 });
					new Effect.BlindDown('byo-formdiv', {duration: 1 } );
					try {
						pageTracker._trackPageview("/funnel/complete.html"); 
					} catch (err) { }
				}});
			
			}});
}
function isBlank ( txt ) {
	txt = txt.split(' ').join('');
	txt = txt.split('\n').join('');
	txt = txt.split('\r').join('');
	txt = txt.split('\t').join('');
	if (txt == '') { return true; }
	return false;
}

function isEmail( argvalue ) {
  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;
  arrayString = argvalue.split("@");
  if (arrayString[1].indexOf(".") == -1)
    return false;
  else if (arrayString[1].indexOf(".") == 0)
    return false;
  else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
    return false;
  }
  return true;
}

