function go(which) {
    str = which.options[which.selectedIndex].value
    if (str.length > 0)
	{
        document.location = str;
    }
}

function isEmpty(string) {
	var whitespace = " \t\n\r";

	if ((string == null) || (string.length == 0)) {
		return true;
	}
    for (i = 0; i < string.length; i++) {
		var chr = string.charAt(i);
		if (whitespace.indexOf(chr) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}

function tooLong(string, max) {
	if (string.length > max) {
		return true;
	}
}

function stripChars (string, accept) {
// string to clean, acceptable characters
	var i;
	var returnString = "";

	for (i = 0; i < string.length; i++) {
		var chr = string.charAt(i);
		if (accept.indexOf(chr) != -1) returnString += chr;
	}

	return returnString;
}

function showError(ourform, where, warning) {
	ourform.elements[where].focus();
	if (document.getElementById) {
		document.getElementById(where).style.backgroundColor = '#fff';
	}
	alert(warning);
}


function checkForm() {
	ourform = document.forms['contact'];
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;

	if (document.getElementById) {
		document.getElementById('name').style.backgroundColor = '#f3f3f3';
		document.getElementById('position').style.backgroundColor = '#f3f3f3';
		document.getElementById('company').style.backgroundColor = '#f3f3f3';
		document.getElementById('phone').style.backgroundColor = '#f3f3f3';
		document.getElementById('email').style.backgroundColor = '#f3f3f3';
		document.getElementById('message').style.backgroundColor = '#f3f3f3';
	}

	if (isEmpty(ourform.name.value)) {
 		showError(ourform, "name", "Please make sure you enter your name");
		return false;
	}

	if (isEmpty(ourform.email.value)) {
 		showError(ourform, "email", "Please make sure you enter your email address");
		return false;
	}

	if (isEmpty(ourform.message.value)) {
 		showError(ourform, "message", "Please make sure you enter a message");
		return false;
	}

	if (!(filter.test(ourform.email.value))) {
		showError(ourform, "email", "Please check your email address - it does not appear to be valid");
		return false;
	}

	if (tooLong(ourform.name.value, 40)) {
 		showError(ourform, "name", "Sorry, your name exceeds the maximum 40 characters");
		return false;
	}

	if (tooLong(ourform.position.value, 40)) {
 		showError(ourform, "position", "Sorry, your job title exceeds the maximum 40 characters");
		return false;
	}

	if (tooLong(ourform.company.value, 40)) {
 		showError(ourform, "company", "Sorry, your company name exceeds the maximum 40 characters");
		return false;
	}

	if (tooLong(ourform.phone.value, 40)) {
 		showError(ourform, "phone", "Sorry, your phone number exceeds the maximum 100 characters");
		return false;
	}

	else {
		return true;
	}
}

function checkB2(form) {
	if (document.getElementById) {
		document.getElementById('name').style.backgroundColor = '#f3f3f3';
		document.getElementById('position').style.backgroundColor = '#f3f3f3';
		document.getElementById('company').style.backgroundColor = '#f3f3f3';
		document.getElementById('phone').style.backgroundColor = '#f3f3f3';
		document.getElementById('email').style.backgroundColor = '#f3f3f3';
		document.getElementById('invoice').style.backgroundColor = '#f3f3f3';
	}
	if (isEmpty(form.name.value)) {
 		showError(form, "name", "Please make sure you enter your name");
		return false;
	}
	else if (tooLong(form.name.value, 200)) {
 		showError(form, "name", "Sorry, the name you entered exceeds the maximum 200 characters");
		return false;
	}
	if (tooLong(form.position.value, 200)) {
 		showError(form, "position", "Sorry, the position you entered exceeds the maximum 200 characters");
		return false;
	}

	if (tooLong(form.company.value, 200)) {
 		showError(form, "company", "Sorry, the company name you entered exceeds the maximum 200 characters");
		return false;
	}
	if (isEmpty(form.phone.value)) {
 		showError(form, "phone", "Please make sure you enter your phone number\n- it will only be used to contact you regarding this order");
		return false;
	}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	if (isEmpty(form.email.value)) {
 		showError(form, "email", "Please make sure you enter your email address\n- it will only be used to contact you regarding this order");
		return false;
	}
	else if (!(filter.test(form.email.value))) {
		showError(form, "email", "Please check your email address - it does not appear to be valid");
		return false;
	}
	if (isEmpty(form.invoice.value)) {
 		showError(form, "invoice", "Please make sure you enter the name of the\nperson or company who we should invoice - \nwe will contact you before sending an invoice\nthough");
		return false;
	}
	else if (tooLong(form.invoice.value, 200)) {
 		showError(form, "invoice", "Sorry, your invoice name exceeds the maximum 200 characters");
		return false;
	}
	else {
		return true;
	}
}

function checkB3(form) {
	if (document.getElementById) {
		document.getElementById('message').style.backgroundColor = '#f3f3f3';
	}
	if (tooLong(form.message.value, 5000)) {
		if (document.getElementById) {
			document.getElementById(message).style.backgroundColor = '#fff';
		}
 		alert("Sorry, your message exceeds the maximum of 5000 characters\nPlease send any additional info to the email address\nshown at the last step");
		return false;
	}
	if (!form.terms.checked) {
		alert('You must tick the box to indicate that\nyou agree with our terms and conditions\nbefore you can proceed');
		return false;
	}
	return true;
}

function checkC3D3(form) {
	if (document.getElementById) {
		document.getElementById('name').style.backgroundColor = '#f3f3f3';
		document.getElementById('position').style.backgroundColor = '#f3f3f3';
		document.getElementById('company').style.backgroundColor = '#f3f3f3';
		document.getElementById('phone').style.backgroundColor = '#f3f3f3';
		document.getElementById('email').style.backgroundColor = '#f3f3f3';
		document.getElementById('invoice').style.backgroundColor = '#f3f3f3';
		document.getElementById('message').style.backgroundColor = '#f3f3f3';
	}
	if (isEmpty(form.name.value)) {
 		showError(form, "name", "Please make sure you enter your name");
		return false;
	}
	else if (tooLong(form.name.value, 200)) {
 		showError(form, "name", "Sorry, the name you entered exceeds the maximum 200 characters");
		return false;
	}
	if (tooLong(form.position.value, 200)) {
 		showError(form, "position", "Sorry, the position you entered exceeds the maximum 200 characters");
		return false;
	}
	if (tooLong(form.company.value, 200)) {
 		showError(form, "company", "Sorry, the company name you entered exceeds the maximum 200 characters");
		return false;
	}
	if (isEmpty(form.phone.value)) {
 		showError(form, "phone", "Please make sure you enter your phone number\n- it will only be used to contact you regarding this order");
		return false;
	}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	if (isEmpty(form.email.value)) {
 		showError(form, "email", "Please make sure you enter your email address\n- it will only be used to contact you regarding this order");
		return false;
	}
	else if (!(filter.test(form.email.value))) {
		showError(form, "email", "Please check your email address - it does not appear to be valid");
		return false;
	}
	if (isEmpty(form.invoice.value)) {
 		showError(form, "invoice", "Please make sure you enter the name of the\nperson or company who we should invoice - \nwe will contact you before sending an invoice\nthough");
		return false;
	}
	else if (tooLong(form.invoice.value, 200)) {
 		showError(form, "invoice", "Sorry, your invoice name exceeds the maximum 200 characters");
		return false;
	}
	if (tooLong(form.message.value, 5000)) {
		if (document.getElementById) {
			document.getElementById(message).style.backgroundColor = '#fff';
		}
 		alert("Sorry, your message exceeds the maximum of 5000 characters\nPlease send any additional info to the email address\nshown at the last step");
		return false;
	}
	if (!form.terms.checked) {
		alert('You must tick the box to indicate that\nyou agree with our terms and conditions\nbefore you can proceed');
		return false;
	}
	return true;
}
