function clearText(thefield){
	if(thefield.defaultValue==thefield.value)
	thefield.value = '';
}
function parseForm(){
	var theform = document.getElementById('mainform');
	var y = theform.elements;
	for(x=0; x<y.length; x++){
		if(y[x].value=='-1'){
			y[x].value = y[x].defaultValue;
		}
	}
}
function checkOnLeave(thefield, type, allowdefault){
	if(thefield.value==''){
		thefield.value = thefield.defaultValue;
	}
	if((allowdefault == 0) && (thefield.value == thefield.defaultValue)){
		alert ("Default value is not allowed in this field.");
	}
	if((thefield.value != '')&&(thefield.value != thefield.defaultValue)){
		switch(type){
			case('email'):
				if(checkEmail(thefield.value)){
					return (true);
				}else{
					alert ("Email address is not valid, please check");
					thefield.focus();
				}
				break;
			case('number'):
				if(checkNumber(thefield.value)){
					return(true);
				}else{
					alert ("Not a valid number, please check");
					thefield.focus();
				}
				break;
		}
	}
}
function checkEmail(inp){
	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(inp)){
		return (true)
	}
	return (false)
}
function checkNumber(inp){
	if(/[^A-Za-z]/.test(inp)){
		return(true);
	}
	return(false);
}
function checkEmpty(inp){
	if(inp == ''){
		 return(false);
	}
	return(true);
}
function sendCheck(theform){
	var y = theform.elements;
	var iserror = 0;
	for(x=0; x<y.length; x++){
		switch(y[x].name){
			//Check Message Field
			case('message'):
				if(checkEmpty(y[x].value)){
					if(y[x].value==y[x].defaultValue){
						formError();
						iserror = 1;
						return false;
					}
				}else{
					formError();
					iserror = 1;
					return false;
				}
				break;
			//End Message Field
		}
	}
	for(x=0; x<y.length; x++){
	if(iserror == 0){
			if(y[x].value==y[x].defaultValue){
				y[x].value='-1';
			}
	}
	}
}
function formError(){
	alert("There is an error on the form, please check all fields are correct and try again.");
}