// JavaScript Document
function getBookingDateTimes() {
	//alert("starting...");
	var notice = $('notice');
	var dateTimeObj = document.getElementById('bk_class_date');
	if($('bk_club_name').value!='' && $('bk_class_name').value!=''){
		var classLbl = $('bk_class_name').value;
		classLbl = classLbl.replace(/\+/g," ");
                //classLbl = unescape(classLbl);
		//var url = 'classtimes.php';
		var url = 'http://www.reynoldsgroup.co.uk/health-fitness/classtimes.php';
		//var url = 'http://sittingbourne.reynoldsgroup.co.uk/classtimes.php';
                //var params = 'classname=' + $('bk_class_name').value;
                //Ish changed the param to match the label and sent it by post instead of get
                var params = 'classname=' + classLbl;
		var ajax2 = new Ajax.Request(url, {method: 'post',  parameters: params, onSuccess:
			function(transport) { 
				var myTimes=transport.responseText.strip();
				if(myTimes.indexOf(',')>0 && myTimes.indexOf('|')>0 ){
					var dateNtimes = myTimes.split(',');
					var Loops=dateNtimes.length;
					$('bk_class_date').length=1;
					$('bk_class_date').options[0] = new Option('Choose The Time');
					notice.update('Classes available!').setStyle({ background: '#dfd' });
					for(var i=0; i<Loops; i++){
						j=i+1;
						var timeSet =dateNtimes[i];
						var timeVals=dateNtimes[i].split('|');
						var curDate=timeVals[2].replace(/^\s+|\s+$/g,"").toString();
						var curTime=timeVals[1].replace(/^\s+|\s+$/g,"").toString();
						var curInd=timeVals[0].replace(/^\s+|\s+$/g,"").toString();
						var curDateTime = curDate+' at '+curTime;
						if( (curDate!='undefined') || (curDate!='') || (curDate!=' ') ){
							if(j==1){
								dateTimeObj.options[j] = new Option(curDateTime,curInd,true);
								dateTimeObj.options[j].selected=true;
							}else{
								dateTimeObj.options[j] = new Option(curDateTime,curInd);
							}
						}
					}
				}else if(myTimes.indexOf('|')>0){
					dateTimeObj.options.length=1;
					dateTimeObj.options[0] = new Option('Choose The Time');
					var dateTimeVals=myTimes.split('|');
					var curDate=dateTimeVals[2].replace(/^\s+|\s+$/g,"").toString();
					var curTime=dateTimeVals[1].replace(/^\s+|\s+$/g,"").toString();
					var curInd=dateTimeVals[0].replace(/^\s+|\s+$/g,"").toString();
					var curDateTime = curDate+' at '+curTime;
					notice.update('Class available for your chosen date.').setStyle({ background: '#dfd' });
					dateTimeObj.options[1] = new Option(curDateTime,curInd,true);
					dateTimeObj.options[1].selected=true;
				}else{
					notice.update('There are no classes available for the date selected.').setStyle({ background: '#efefef' });
					dateTimeObj.options.length=1;
					dateTimeObj.options[0] = new Option('Choose The Time');
				}
			}
		}); 
	}else{
		notice.update('').setStyle({ background: '#efefef' });
		dateTimeObj.options.length=1;
		dateTimeObj.options[0] = new Option('Choose The Time');
	}
	//alert("ending...");
}
