function validateLogin(frm)
{	
	if(!checkField(frm.username,"Please enter your username"))
	{	return false;
	}
	if(!checkField(frm.password,"Please enter your password"))
	{	return false;
	}
	return true;
}

function validateQueryForm(frm)
{	
	if(!checkField(frm.namebox,"Please enter your name"))
	{	return false;
	}
	if(!checkEmail(frm.emailbox,"Please check you have entered a valid email address."))
	{	return false;
	}
	if(!checkField(frm.querybox,"Please enter your query"))
	{	return false;
	}
	return true;
}

function checkField(fld,message)
{
	if(fld.value.length<1)
	{	alert(message);
		fld.focus();
		return false;
	}
	return true
}

function checkEmail(fld,msg)
{	txt = fld.value;
	firstAt = txt.indexOf("@")
	lastAt = txt.lastIndexOf("@")
	firstDot = txt.indexOf(".")
	lastDot = txt.lastIndexOf(".")
	if(firstDot<1 || firstDot<0|| (lastDot-2)<lastAt|| lastDot>txt.length-3|| firstAt!=lastAt)
	{	alert(msg);
		fld.focus();
		return false
	}
	return true;
}
function checkStorefinder(frm)
{
	if(!checkField(frm.place,'Please enter the postcode you want to search for'))
	{	return false;
	}
	return true;
}

function submitStorefinder(frm)
{	if(checkStorefinder(frm))
	{	document.storefinderform.submit()
	}
}

function validateNewsSearch(frm)
{	if(!checkField(frm.searchbox,'Please enter a term to search for.'))
		return false;
	startday = frm.startday.options[frm.startday.selectedIndex].value;
	startmonth = frm.startmonth.options[frm.startmonth.selectedIndex].value;
	startyear = frm.startyear.options[frm.startyear.selectedIndex].value;
	if(!checkDateEntered(startday,startmonth,startyear,"####"))
		return false
	else
		startDateEntered=true
	endday = frm.endday.options[frm.endday.selectedIndex].value;
	endmonth = frm.endmonth.options[frm.endmonth.selectedIndex].value;
	endyear = frm.endyear.options[frm.endyear.selectedIndex].value;
	if(!checkDateEntered(endday,endmonth,endyear,"####"))
		return false
	else
		endDateEntered=true
	return true;

}

function checkDateEntered(daystr,monthstr,yearstr,defaultstr)
{
	if(daystr!=defaultstr||monthstr!=defaultstr||yearstr!=defaultstr)
	{	
		if(daystr==defaultstr||monthstr==defaultstr||yearstr==defaultstr)
		{	alert("Please make sure that any dates entered are valid or leave all fields blank");	
			return false;
		}
	}
	return true;
}
