	function validate() {
		var valError = false;

		//change button text
		document.getElementById("cSend").value='Sending...';

		//check name
		if (document.getElementById("cName").value == '') {
			valError = true;
			document.getElementById("errName").style.visibility='';
		} else {
			document.getElementById("errName").style.visibility='hidden';
		}

		//validate email
		//var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
		if (reg.test(document.getElementById("cEmail").value) == false) {
			valError = true;
			document.getElementById("errEmail").style.visibility='';
		} else {
			document.getElementById("errEmail").style.visibility='hidden';
		}

		//check message
		if (document.getElementById("cMsg").value == '') {
			valError = true;
			document.getElementById("errMsg").style.visibility='';
		} else {
			document.getElementById("errMsg").style.visibility='hidden';
		}

		if (valError == true) {
			alert('Please double check your contact details');
			document.getElementById("cSend").value='Send'; //change button text
			return false;
		}

		//hide any showing error indicators
		document.getElementById("errName").style.visibility='hidden';
		document.getElementById("errEmail").style.visibility='hidden';
		document.getElementById("errMsg").style.visibility='hidden';

		//send message
		contact();
	}

	function contact() {
		var xmlhttp;
		var params = "name=" + encodeURIComponent(document.getElementById('cName').value) + "&email=" + encodeURIComponent(document.getElementById('cEmail').value) + "&msg=" + encodeURIComponent(document.getElementById('cMsg').value)

		if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
			}
		else
			{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}

		xmlhttp.onreadystatechange=function() {

			//show result span
			showResult(); //show response span

			//check response status
			if (xmlhttp.readyState==4) {
				if (xmlhttp.status==200) {
					document.getElementById("cResp").innerHTML=xmlhttp.responseText; //put HTML into the span
					document.getElementById("cName").value='';
					document.getElementById("cEmail").value='';
					document.getElementById("cMsg").value='';
					document.getElementById("cSend").value='Send'; //change button text

				} else {
					document.getElementById("cResp").innerHTML='<font color="red">Network Error ' + xmlhttp.status + '. Please try again.</font>'; //put HTML into the span
					document.getElementById("cSend").value='Send'; //change button text
				}
			}
		}

		xmlhttp.open("GET", "/contact/contact.php?" + params, true);
		xmlhttp.send();

		/*
		xmlhttp.open("POST", "/logon", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(params);
		*/
	}

	function showResult() {
		// this funciton shows the contact result span for 5 seconds, then hides it again
		document.getElementById("cResp").style.display=''; //show response span
		setTimeout(function() {document.getElementById("cResp").style.display='none';}, 5000);
	}


	function sendcard(vCardName) {
		var valError = false;

		//change button text
		document.getElementById("cSend" + vCardName).value='Sending...';

		//validate email
		//var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
		if (reg.test(document.getElementById("cEmail" + vCardName).value) == false) {
			alert('Sorry, that email address appears to be invalid.');
			document.getElementById("cEmail" + vCardName).select();
			document.getElementById("cEmail" + vCardName).focus();
			document.getElementById("cSend" + vCardName).value='Send'; //change button text
			return false;
		}

		// ====== send vcard via ajax call ======

		var xmlhttp;
		var params = "vcard=1&name=" + encodeURIComponent(vCardName) + "&email=" + encodeURIComponent(document.getElementById('cEmail' + vCardName).value);

		if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
			}
		else
			{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}

		xmlhttp.onreadystatechange=function() {

			// this funciton shows the contact result span for 5 seconds, then hides it again
			document.getElementById("cResp" + vCardName).style.display=''; //show response span
			setTimeout(function() {document.getElementById("cResp" + vCardName).style.display='none';}, 5000);

			//check response status
			if (xmlhttp.readyState==4) {
				if (xmlhttp.status==200) {
					document.getElementById("cResp" + vCardName).innerHTML=xmlhttp.responseText; //put HTML into the span
					document.getElementById("cSend" + vCardName).value='Send'; //change button text
				} else {
					document.getElementById("cResp" + vCardName).innerHTML='<font color="red">Network Error ' + xmlhttp.status + '. Please try again.</font>'; //put HTML into the span
					document.getElementById("cSend" + vCardName).value='Send'; //change button text
				}
			}
		}

		xmlhttp.open("GET", "/contact/sendcard.php?" + params, true);
		xmlhttp.send();
	}

