// JavaScript Document
function ClassCheck(){
	
	inputwebsite=document.form.website.value;
	inputemail=document.form.email.value;
	inputheading=document.form.heading.value;
	inputmessage=document.form.ad.value;
	inputcountry=document.form.country_id[document.form.country_id.selectedIndex].value;
	inputcategory=document.form.category[document.form.category.selectedIndex].value;
		
	if (inputheading==""){
	document.form.heading.focus();
	alert("Type in a heading for your advert");
	return false;
	}
	else if (inputmessage==""){
	document.form.ad.focus();
	alert("Type in some words for your advert");
	return false;
	}	
	else if (inputcountry=="0" && (inputcategory=="8" || inputcategory=="10" || inputcategory=="13")){
	document.form.country_id.focus();
	alert("These adverts require a country");
	return false;
	}
	
	else if (inputcategory==""){
	document.form.category.focus();
	alert("choose an advert category");
	return false;
	}
	else if (inputemail==""){
	document.form.email.focus();
	alert("Type in an email address - this is just so we can contact you.");
	return false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(inputemail))){
	document.form.email.focus();
	alert("This is an invalid email.");
	return false;
	}	
	else if (inputwebsite==""){
	document.form.website.focus();
	alert("Please type in your site address.");
	return false;
	}
	
	else{
	return true;
	}

}
function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit){ // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	}// otherwise, update 'characters left' counter
	else{
	cntfield.value = maxlimit - field.value.length;
	}
}
