function validateFeedback(whichForm){
	feedbackStr = "";
	checkForm(whichForm);
	if (feedbackStr != ""){
		feedbackStr = "Your feedback could not be accepted for the following reasons:\n" + feedbackStr
		alert(feedbackStr);
		return false;
	}else{
		return true;
		//alert("returning true");
	}
}

function checkForm(whichForm){

	whichForm.name.style.background = "none";
	whichForm.email.style.background = "none";
	whichForm.telephone.style.background = "none";
	whichForm.subject.style.background = "none";
	whichForm.message.style.background = "none";
	whichForm.category.style.background = "none";

	if ((whichForm.name.value == "") || (whichForm.name.value == " ")){
		feedbackStr = feedbackStr + "Please supply your full name\n";
		whichForm.name.style.background = "yellow";
	}
	validateEmail(whichForm.email.value, whichForm);
	
//	if ((whichForm.telephone.value == "") || (whichForm.telephone.value == " ")){
//		feedbackStr = feedbackStr + "Please supply your telephone number\n";
//		whichForm.telephone.style.background = "yellow";
//	}
	if ((whichForm.subject.value == "") || (whichForm.subject.value == " ")){
		feedbackStr = feedbackStr + "Please supply a subject for your message\n";
		whichForm.subject.style.background = "yellow";
	}
	if ((whichForm.message.value == "") || (whichForm.message.value == " ")){
		feedbackStr = feedbackStr + "Please supply your message\n";
		whichForm.message.style.background = "yellow";
	}
	if (whichForm.category.value == "none"){
		feedbackStr = feedbackStr + "Please select a category for your message\n";
		whichForm.category.style.background = "yellow";
	}
	if (whichForm.spamcode.value != "Df1a0"){
		feedbackStr = feedbackStr + "Please enter the correct code\n";
		whichForm.spamcode.style.background = "yellow";
	}
}

// checks valid email address and passes this to the validate function
function validateEmail(emailaddress, whichForm){
	var theStr = new String(emailaddress)
	var index = theStr.indexOf("@")
	
	if (index > 0){
		var pindex = theStr.indexOf(".",index)
		if ((pindex > index+1) && (theStr.length > pindex+1)){
			emailGood = 1;
			//alert("Good email")
		}else{
			emailGood = 0;
			feedbackStr = feedbackStr + "You have supplied an invalid email address\n"
			whichForm.email.style.background = "yellow";
		}
	}else{
		feedbackStr = feedbackStr + "Please supply your email address\n"
		whichForm.email.style.background = "yellow";
	}
}


function input_clear(element,placeholder_value){
	var submitted_value = element.value;
	//alert(submitted_value.length);
	//alert(placeholder_value.length);
    if (submitted_value == placeholder_value){
		//alert("matching values");
        element.value="";
    }
} 
