
function checkform(form){
  if (form.fullname.value.length < 4){
    alert("Please enter a Full name & title.");
      return false}

  if (form.address.value.length < 5){
    alert("Please enter a  address.");
  return false;}
  if ((form.email.value.length < 9) || (form.email.value.indexOf('@') == -1) || (form.email.value.indexOf('.') == -1)){
    alert("Please enter a valid email address like you@domain.com");
  return false;}

  if (form.confirm.checked == false){
    alert("You need to read and agree to the terms of service.");
  return false;
	}
}


function checkbook(){
if(document.bookform.btype.value=='bookhight') return true;
sday = document.bookform.sdated.value;
smonth = document.bookform.sdatem.value;
syear =document.bookform.sdatey.value;

eday = document.bookform.edated.value;
emonth = document.bookform.edatem.value;
eyear =document.bookform.edatey.value;

if (smonth == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (isleap) {
			snday=29;
		}else{
			snday=28;
		}
}else if ((smonth==4 || smonth==6 || smonth==9 || smonth==11) ) {
		snday=30;
}else{
		snday=31;
}



if(isDate(sday,smonth,syear)&&isDate(eday,emonth,eyear)){
	
	if(syear==eyear){	
		if(smonth<=emonth){
			if(smonth==emonth&&(parseInt(eday)-parseInt(sday))<2){
				alert('minimum 2 night .');
				return false;
			}else{
					all=(parseInt(snday)-parseInt(sday))+parseInt(eday);
					if(all<2){
						alert('minimum 2 night .');
						return false;
					}
			}
					
		}else{
		alert('invalid  booking.');
		return false;
		}
	}else{
			if(smonth=='12'&&emonth=='1'){
				if(((31-parseInt(sday))+parseInt(eday))<2){
					alert('minimum 2 night .');
					return false;
				}
			}
	}
}
}

function isbookDate() {

sday = document.bookform.sdated.value;
smonth = document.bookform.sdatem.value;
syear =document.bookform.sdatey.value;

eday = document.bookform.edated.value;
emonth = document.bookform.edatem.value;
eyear =document.bookform.edatey.value;

isDate(sday,smonth,syear);
isDate(eday,emonth,eyear)

return true; // date is valid
}


function isDate(day,month,year) {


if (month < 1 || month > 12) { // check month range
alert('Month must be between 1 and 12.');
return false;
}

if (day < 1 || day > 31) {
alert('Day must be between 1 and 31.');
return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert('Month '+month+' doesn`t have 31 days!');
return false;
}

if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
		alert('February ' + year + ' doesn`t have ' + day + ' days!');
		return false;
		}
	}
	return true; // date is valid
}
