function checkOtherField (strng, errormsg) {
	 var error = "";
	 if (strng == "") {
		error = errormsg;
	 }
	 return error;
}

function checkTextField (strng, errormsg) {
 var error = "";
 if (strng == "") {
    error = errormsg;
 }
 return error;
}

function checkEmail (strng, errormsg) {
	var error = "";
	var emailFilter=/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/;
	if (!(emailFilter.test(strng))) {
	       error = errormsg;
	}
	return error;
}
function checkPhone (strng, errormsg) {
	var error = "";
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
	       error = errormsg;
	}
	return error;
}
function checkRadio (checkvalue, errormsg) {
	var error = "";
	if (checkvalue == "Short term loan") {
	  return "check8and9";
	}
	   if (!(checkvalue)) {
		   error = errormsg;
		}
	return error;
}
function checkDropdown(choice, errormsg) {
    var error = "";
    if (choice == "NULL") {
       error = errormsg;
    }    
return error;
} 

function checkForm(theForm) {
	var why = "";
	var why_errors = "";

	why_errors += checkTextField(theForm.fname.value, "- your first name\n");
	why_errors += checkEmail(theForm.epos.value, "- a valid email address\n");
	why_errors += checkPhone(theForm.tel.value, "- your contact number (digits only)\n");	
	why_errors += checkTextField(theForm.comments.value, "- your comment or enquiry\n");	
	why_errors += checkTextField(theForm.captcha.value, "- the spam prevention code");

    if (why_errors != "") {
       why = "Please fill in:\n"+why_errors;
       alert(why);
       return false;
    }
}

function checkSendToFriendForm(theForm) {
	var why = "";
	var why_errors = "";

	why_errors += checkTextField(theForm.yourname.value, "- your name\n");
	why_errors += checkTextField(theForm.friendname.value, "- your friend's name\n");
	why_errors += checkEmail(theForm.epos.value, "- your (valid) email address\n");
	why_errors += checkEmail(theForm.friendepos.value, "- your friend's (valid) email address\n");
	why_errors += checkTextField(theForm.subject.value, "- the subject of your email\n");	
	why_errors += checkTextField(theForm.message.value, "- your message\n");	
	why_errors += checkTextField(theForm.captcha.value, "- the spam prevention code");

    if (why_errors != "") {
       why = "Please fill in:\n"+why_errors;
       alert(why);
       return false;
    }
}
