function existing(dates){
window.open ("monthselb.php?sort=two", "NewWin", "scrollbars=1, width=320, height=500");
}

function checkAll(field){
var x=0;
var room=new Array();
room[0]="Chapel";
room[1]="Lounge";
room[2]="Kitchen";
room[3]="Youth Hall";
room[4]="Upstairs";
room[5]="Back Rooms";
var rooms="";
var problem=0;
var storprob=0;

if (document.myform.dates.value==""){alert ('No dates selected');return false}
for (i = 0; i < field.length; i++) 
{
if (field[i].checked==1){rooms=rooms+room[i]+"\r\n";x++;} ;
}
if (x==0){alert ('No facilities have been selected!!');return false;};
if (document.all.who.value=="") {alert ('No group has been selected!!');return false};
if (document.myform.HrStart.options[myform.HrStart.selectedIndex].text==document.myform.HrEnd.options[myform.HrEnd.selectedIndex].text && document.myform.MinStart.options[myform.MinStart.selectedIndex].text==document.myform.MinEnd.options[myform.MinEnd.selectedIndex].text && document.myform.APStart.options[myform.APStart.selectedIndex].text==document.myform.APEnd.options[myform.APEnd.selectedIndex].text){alert ('Start & end times are the same!!');return false};
timeHStart=parseInt(document.myform.HrStart.options[myform.HrStart.selectedIndex].text);
timeHEnd=parseInt(document.myform.HrEnd.options[myform.HrEnd.selectedIndex].text);
timeMStart=parseInt(document.myform.MinStart.options[myform.MinStart.selectedIndex].text);
timeMEnd=parseInt(document.myform.MinEnd.options[myform.MinEnd.selectedIndex].text);

if (document.myform.APStart.options[myform.APStart.selectedIndex].text=="PM"){timeHStart+=12;};
if (document.myform.APEnd.options[myform.APEnd.selectedIndex].text=="PM"){timeHEnd+=12;};
timeSt=timeHStart*100+timeMStart;
timeEd=timeHEnd*100+timeMEnd;
var y=7;var temp= new Array();
var tempB= new Array();
for (x=1;x<=document.myForm.total.value;x++){
var thold="oltime"+x;
temp=document.getElementById(thold).value.split(':');
temp[0]=temp[0]*100 +parseInt(temp[1]);
thold="olduration"+x;
tempB=document.getElementById(thold).value.split(':');
tempB[0]=tempB[0]*100+parseInt(tempB[1]);
//alert (temp[0] +" " + tempB[0]+ " " + " "+  timeSt+" "+timeEd);
if (timeSt>=temp[0]  && timeSt < tempB[0]){problem=conflict(rooms,x);} else {
if (timeEd> temp[0]  && timeEd <= tempB[0]){problem=conflict(rooms,x);} else{
if (timeSt<=temp[0]  && timeEd >= tempB[0]){problem=conflict(rooms,x);} else {var myRow="myrow"+x;
document.getElementById(myRow).style.backgroundColor='#ffffff';
 }
};
};
if (problem==2){storprob++;};
y+=12;

};
timeHStart=timeHStart+":"+document.myform.MinStart.options[myform.MinStart.selectedIndex].text+":00";
timeHEnd=timeHEnd+":"+document.myform.MinEnd.options[myform.MinEnd.selectedIndex].text+":00";
rooms=escape(rooms);
if (document.myform.comment.value==""){alert ('I need some form of contact details to be listed');storprob++;};
//alert ('store '+storprob);
if (storprob==0){
//alert (document.myform.dates.value);
self.document.location.href="subentry.php?step=3&dates="+document.myform.dates.value+"&event="+document.all.who.value+"&rooms="+rooms+"&timeSt="+timeHStart + "&timed="+timeHEnd+"&comment="+escape(document.myform.comment.value);
} else {storprob=0;}
}

function conflict(rooms,x ){
var problem=0;
thold="olroom"+x;
var tempC=new Array();
//alert (parent.frames[0].document.myForm.item(y-4).value);
tempC=document.getElementById(thold).value.split('\r\n');
var tempD=new Array();
tempD=rooms.split('\r\n');
for (z=0;z<=tempC.length-2;z++){
//alert ("here -" + tempC[z]);
for (b=0;b<=tempD.length-2;b++){
//alert ('there'+tempD[b]);
var myRow="myrow"+x;
myTble=document.getElementById(myRow);
if (tempC[z]==tempD[b]){ alert('Conflict with booking ' +x); problem=2;myTble.style.backgroundColor='#c0c0c0';
return problem;};
}
}
return problem;
}
function openwin(){
OpenorNot=window.open ('monthselb.php?sort=two', 'NewWin', 'scrollbars=1, width=320, height=500');

}


