function RoomAlert(room,adults,children,people,message) { this.room=room; this.adults=adults; this.children=children; this.people=people; this.message=message; } function GuestMessage(room,guests,message) { this.room=room; this.guests=guests; this.message=message; } function get_alert(room,adults,children) { var people=adults+children; var index=-1,max=0; // ok now find appropriate message..... for (var i=0; i < roomAlerts.length; i++) { if (roomAlerts[i].room != room) continue; if (roomAlerts[i].people && roomAlerts[i].people <= people && roomAlerts[i].people >= max) { index=i; max=roomAlerts[i].people; } else if (roomAlerts[i].adults && roomAlerts[i].adults <= adults && roomAlerts[i].adults >= max) { index=i; max=roomAlerts[i].adults; } else if (roomAlerts[i].children && roomAlerts[i].children <= children && roomAlerts[i].children >= max) { index=i; max=roomAlerts[i].children; } } if (index >= 0) return roomAlerts[index].message; else return null; } function get_guestalert(room,guests) { for (var i=0; i < guestMessages.length; i++) if (guestMessages[i].room==room) if (guests > guestMessages[i].guests) return guestMessages[i].message.length ? guestMessages[i].message : 'A maximum of '+guestMessages[i].guests+' people allowed in this room.'; else return null; return null; } function check_alerts(room,adults,children) { var str; // check max guests first - ignore max guests..... if (str=get_guestalert(room,adults+children)) { alert(str); return false; } if (str=get_alert(room,adults,children)) alert(str); return true; } var roomAlerts=new Array(); var guestMessages=new Array(); roomAlerts[0]=new RoomAlert(5,9,0,0,'3 king doubles and 3 king single beds available to sleep 8 adults. Additional people will need to sleep on a mattress in the lounge area or book the bunkhouse as well'); guestMessages[0]=new GuestMessage(5,9,'Maximum of 12 allowed in the mainhouse. Book the bunkhouse as well to cater for up to 20. For larger groups contact us direct.'); guestMessages[1]=new GuestMessage(7,24,'');