function dog(formnumber, dogs)
{
document.search.dogs.value = dogs;
document.search.formnumber.value = formnumber;
document.search.action = "search.php#"+formnumber;
document.search.submit();
}

function monthlimit(first_day, first_month, first_year, last_day, last_month, last_year)
{
first_day = first_day * 1;  // makes JS convert string to number (as long as only 0-9 characters) as JS assumes if multiplying must, be number
first_month = first_month * 1;
first_year = first_year * 1;
last_day = last_day * 1;  // makes JS convert string to number (as long as only 0-9 characters) as JS assumes if multiplying must, be number
last_month = last_month * 1;
last_year = last_year * 1;
if ((first_year+1)<last_year || (first_year+1)==last_year && (first_month-9)<last_month ||   first_year==last_year && (first_month+3)<last_month)
{
	alert("If you require a booking of longer than 3 months\n\nPlease call our offices on 01904 400256");
	return false;
}
}

function dateafternow(day, month, year)
{
day = day * 1;  // makes JS convert string to number (as long as only 0-9 characters) as JS assumes if multiplying must, be number
month = month * 1;
year = year * 1;
var currentTime = new Date()
var nowmonth = currentTime.getMonth() + 1
var nowday = currentTime.getDate()
var nowyear = currentTime.getFullYear()
if (year<nowyear || year==nowyear && month<nowmonth || year==nowyear && month==nowmonth && day<nowday+1)
{
	alert("Bookings must be made with 24hrs notice");
	return false;
}
}

function daysinmonth(day, month, year) //test for valid days in month ie not 31 days in feb/apr/june/sept/nov
{
if (month=="04" || month=="06" || month=="09" || month=="11")
{
	if (day=="31")
	{
		alert("Please enter a real date");
		return false;
	}
	else
	{
		return true;
	}
}
else if (month=="02") //february test + leap year check
{
	if (day>"28" && (year%4)!=0)
	{
		alert("Please enter a real date");
		return false;
	}
	else if (day>"29" && (year%4)==0)
	{
		alert("Please enter a real date");
		return false;
	}
}
else
{
	return true;
}
}

//check one date against another, beforedate NOT after afterdate
function dateBeforeAfterCheck(beforeday, beforemonth, beforeyear, afterday, aftermonth, afteryear)
{
if (afteryear<beforeyear)
{
	alert("Please enter a valid date");
	return false;
}
else if (afteryear==beforeyear)
{
	if (aftermonth<beforemonth)
		{
			alert("Please enter a valid date");
			return false;
		}
	else if (aftermonth==beforemonth)
	{
		if (afterday<beforeday)
		{
			alert("Please enter a valid date");
			return false;
		}
	}
}
else
{
	return true;
}
}

function searchformvalidation(thisform)
{
with (thisform)
{

if (emptyvalidation(first_day)==false) {first_day.focus(); return false;};
if (emptyvalidation(first_month)==false) {first_month.focus(); return false;};
if (emptyvalidation(first_year)==false) {first_year.focus(); return false;};
if (emptyvalidation(end_day)==false) {end_day.focus(); return false;};
if (emptyvalidation(last_month)==false) {last_month.focus(); return false;};
if (emptyvalidation(last_year)==false) {last_year.focus(); return false;};
if (daysinmonth(first_day.value, first_month.value, first_year.value)==false) {first_day.focus(); return false;};
if (daysinmonth(end_day.value, last_month.value, last_year.value)==false) {end_day.focus(); return false;};
if (dateafternow(first_day.value, first_month.value, first_year.value)==false) {first_day.focus(); return false;};
if (dateBeforeAfterCheck(first_day.value, first_month.value, first_year.value, end_day.value, last_month.value, last_year.value)==false) {first_day.focus(); return false;};
if (monthlimit(first_day.value, first_month.value, first_year.value, end_day.value, last_month.value, last_year.value)==false) {first_day.focus(); return false;}; 
if (emptyvalidation(persons)==false) {persons.focus(); return false;};

}
}

function searchformvalidationcottages(thisform)
{
with (thisform)
{

if (emptyvalidation(first_day)==false) {first_day.focus(); return false;};
if (emptyvalidation(first_month)==false) {first_month.focus(); return false;};
if (emptyvalidation(first_year)==false) {first_year.focus(); return false;};
if (emptyvalidation(end_day)==false) {end_day.focus(); return false;};
if (emptyvalidation(last_month)==false) {last_month.focus(); return false;};
if (emptyvalidation(last_year)==false) {last_year.focus(); return false;};
if (daysinmonth(first_day.value, first_month.value, first_year.value)==false) {first_day.focus(); return false;};
if (daysinmonth(end_day.value, last_month.value, last_year.value)==false) {end_day.focus(); return false;};
if (dateafternow(first_day.value, first_month.value, first_year.value)==false) {first_day.focus(); return false;};
if (dateBeforeAfterCheck(first_day.value, first_month.value, first_year.value, end_day.value, last_month.value, last_year.value)==false) {first_day.focus(); return false;};
if (monthlimit(first_day.value, first_month.value, first_year.value, end_day.value, last_month.value, last_year.value)==false) {first_day.focus(); return false;}; 
if (emptyvalidation(dogs)==false) {dogs.focus(); return false;};

}
}

