function checkForm() {

var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
var x = document.forms[0].email.value;

	if (document.getElementById) {
		document.getElementById('name').style.backgroundColor = '#fff';
		document.getElementById('email').style.backgroundColor = '#fff';
		document.getElementById('phone').style.backgroundColor = '#fff';
	}

	if (document.forms[0].name.value.length == 0) { 
		document.forms[0].name.focus();
		if (document.getElementById) {
			document.getElementById('name').style.backgroundColor = '#fc3';
		}
		alert("Please make sure you enter your name"); 
		return false; 
	}

	if (document.forms[0].name.value.length > 120) { 
		document.forms[0].name.focus(); 
		if (document.getElementById) {
			document.getElementById('name').style.backgroundColor = '#fc3';
		}
		alert("Your name is longer than the maximum 120 characters"); 
		return false; 
	}

	if (document.forms[0].email.value.length == 0) { 
		document.forms[0].email.focus(); 
		if (document.getElementById) {
			document.getElementById('email').style.backgroundColor = '#fc3';
		}
		alert("Please make sure you enter your email address"); 
		return false; 
	}

	if (!(filter.test(x))) {
		document.forms[0].email.focus();
		if (document.getElementById) {
			document.getElementById('email').style.backgroundColor = '#fc3';
		}
		alert("Please check your email address - it does not appear to be valid");
		return false;
	}

	if (document.forms[0].email.value.length > 120) { 
		document.forms[0].email.focus(); 
		if (document.getElementById) {
			document.getElementById('email').style.backgroundColor = '#fc3';
		}
		alert("Your email address is longer than the maximum 120 characters"); 
		return false; 
	}

	if (document.forms[0].phone.value.length > 50) { 
		document.forms[0].phone.focus(); 
		if (document.getElementById) {
			document.getElementById('phone').style.backgroundColor = '#fc3';
		}
		alert("Your phone number is longer than the maximum 50 characters"); 
		return false; 
	}

	if (document.forms[0].message.value.length == 0) { 
		document.forms[0].message.focus(); 
		if (document.getElementById) {
			document.getElementById('message').style.backgroundColor = '#fc3';
		}
		alert("Please make sure you enter a message!"); 
		return false; 
	}

	else return true;
}

function getamount() {
	var query = window.location.search.substring(1);
	if (query.length > 0) {
	document.forms[0].val1.value = query;
	convertform(document.forms[0]);
	}
}

function convertform(form){
    var firstvalue = 0;
    for (var i = 0; i <= 3; i++) {
       // Find first non-blank entry
       if (form.elements[i].value != null && form.elements[i].value.length != 0) {
          if (i == 0 && form.elements[1].value != "") return false;
          firstvalue = form.elements[i].value / form.elements[i].factor;
          break;
       }
    }
    if (firstvalue == 0) {
       clearform(form);
       return false;
    }
    for (var i = 0; i <= 2; i++)
       form.elements[i].value = roundtwo(firstvalue * form.elements[i].factor);
    return true;
}

function roundtwo(n) {
// rounds number to 2 decimal places
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}

function resetform(form) {
    clearform(form);
    form.elements[0].value = 1;
    convertform(form);
    return true;
}

function clearform(form) {
    for (var i = 0; i <= 2; i++) form.elements[i].value = "";
    return true;
}

function showdollars() {
	document.write(document.forms[0].val2.factor);
}

function showeuros() {
	document.write(document.forms[0].val3.factor);
}
