function FilledOutBad(){
if(document.Reserver["LastName"].value==""||document.Reserver["Phone"].value==""&&document.Reserver["Email"].value==""){message="Please make sure all the fields are filled in"; return true;}
return false;}

function nok(){
okay=false;
document.Reserver.Available.value="Check Availability";
//document.Reserver["EventChoose"].selectedIndex=0;
}

function selectevent(){
okay=false;
if (document.Reserver["EventChoose"].selectedIndex>0){
temp.setTime(special[(document.Reserver["EventChoose"].selectedIndex-1)*4+1]);
timeset(temp);
check();
}
else{nok(); timeset(now);}
}

function timeset(when)
{
document.Reserver["Time"].selectedIndex=when.getHours()%12*4+when.getMinutes()/15;
document.Reserver["Td1"].selectedIndex=when.getMonth();
document.Reserver["Td2"].selectedIndex=when.getDate()-1;
document.Reserver["Td3"].selectedIndex=when.getFullYear()-2004;
document.Reserver["AMPM"].selectedIndex=(when.getHours()-when.getHours()%12)/12;
}

function checkOk(){
if (okay) {alert ("You will receive confirmation within the next business day..."); return true;}
else {alert("please check availability first"); return false;}
}

function specials(when){
for (i=0;i<special.length;i+=4)
	{
	if(when>=special[i+1]&&when<special[i+2])
		{
		message=special[i]+"\n\n"+special[i+3];
		//document.Reserver["EventChoose"].selectedIndex=i/4+1;
		return true;
		}
	}
return (false);
}

function TooLate(when){
if (when<now){
message="Please, don't try to live in the past.";
return true;}
else 
if (when.valueOf()<now.valueOf()+36*3600000){
message="To Make Reservations Less Than 36 Hours in Advance\n\nPlease Call (859)259-2754";
return true;}
return false;
}

function tooMany(){
if (document.Reserver["NumPeople"].selectedIndex>3){
message="To make reservations for parties of 5 or more Please Call (859)259-2754";
return true;}
return false;
}


function opened(when){
switch (when.getDay())
{
case 0:
//message="Sorry we are closed at that time, our hours are 11-9 Monday-Thursday, 11-10 Fridays & Saturdays"; return (false);
case 1:
case 2:
case 3:
case 4:
if(when.getHours()>=11&&when.getHours()<22){
if(when.getHours()>=14&&when.getHours()<17){message="Between 2pm and 5:30pm the kitchen is closed, but desserts and coffee are still available";}
return true;}
else{message="Sorry we are closed at that time, our hours are 11-10"; return (false);}
case 5:
case 6:
if(when.getHours()>=11&&when.getHours()<22){
if(when.getHours()>=14&&when.getHours()<17){message="Between 2pm and 5:30pm the kitchen is closed, but desserts and coffee are still available";}
return true;}
else{message="Sorry we are closed at that time, our hours are 11-10,"; return (false);}
};
}

function check(){
message="";
var when=new Date(Date.parse(document.Reserver["Td1"][document.Reserver["Td1"].selectedIndex].text+" "+document.Reserver["Td2"][document.Reserver["Td2"].selectedIndex].text+", "+document.Reserver["Td3"][document.Reserver["Td3"].selectedIndex].text+" "+document.Reserver["Time"][document.Reserver["Time"].selectedIndex].text+" "+document.Reserver["AMPM"][document.Reserver["AMPM"].selectedIndex].text));

document.Reserver.DatedTime.value=when;
if (FilledOutBad()||TooLate(when)||specials(when)||!opened(when)||tooMany())
{
nok();
}
else
{
if (okay) {checkOk(); document.Reserver.submit(); return;}
okay=true;
document.Reserver.Available.value="Finalize";
message="Available. "+message;
}
if(message!=""){alert(message);}
}