
function sign_up_for(day){
		var mydate=new Date()
		var myday=mydate.getDay()         //0=sun; 1=mon; 2=tue ...
		var mytoday=mydate.getDate()    //1 to 31
		var mymonth=mydate.getMonth()+1 //0=jan; 1=feb; 2=mar... to 11=dec
		var myyear=mydate.getYear()
	}

var mm=""; var dd=""; var yyyy=""; 
function charAtDate(xdate) //returns mm, dd, yyyy
			{
		var i=0;
		mm = xdate.charAt(i);		i=i+1;
		if (xdate.charAt(i) == "/"){	i=i+1;}else{mm = mm + xdate.charAt(i); i=i+2;}

		dd = xdate.charAt(i); i=i+1;
		if (xdate.charAt(i) == "/"){	i=i+1;}else{dd = dd + xdate.charAt(i); i=i+2;}
		
		yyyy = xdate.charAt(i); i=i+1;
		yyyy = yyyy + xdate.charAt(i);		i=i+1;
		yyyy = yyyy + xdate.charAt(i);		i=i+1;
		yyyy = yyyy + xdate.charAt(i);		
		return mm, dd, yyyy;
	}

function check_class_date_begun(i){
			mm=""; dd=""; yyyy=""; x=0;

			//the value of the element containt the index number of the class array record
			x = document.rd.rd_classes[i].value;	
			charAtDate(rd_schedule_Array[x][4]); //returns mm, dd, yyyy

			var class_date=new Date(yyyy,mm-1,dd); //converting charAtDate var to date format
			var today_date=new Date(); 

		  if (class_date < today_date){
				  return true;
			}else{
					return false;}
}

//Sundays and Tuesdays Radio Buttons
function rd_class_day_checked(valor){
		 document.rd.rd_class_day[0].checked= valor;
		 document.rd.rd_class_day[1].checked= valor;
		 document.rd.rd_class_day[2].checked= valor;
	}
function rd_class_day_disabled(valor){
		 document.rd.rd_class_day[0].disabled= valor;
		 document.rd.rd_class_day[1].disabled= valor;
		 document.rd.rd_class_day[2].disabled= valor;
	}

//=============================================================================
// Showing available Road Program Courses per Road Class Plan on Attending
function show_courses(day){

      // assigning title to table legend
			if (document.rd.road_program[0].checked){
					document.all.legend_day.innerHTML ='You have being registered for the following ' + transform_dayto(day) + ' Classes:';
				 }else{
					document.all.legend_day.innerHTML ='Please Check which ' + transform_dayto(day) + ' Class(es)  you like to Register:';
			}
			
			var list = "";

						list += '<TABLE WIDTH="500" STYLE="border:0px solid #8FBDFF;" CELLPADDING="0" CELLSPACING="0" border=0>';
						list += '<TR>';
						list += '      <TD width="330" align=left style="padding-left:25px;"><B>Available Courses</B></TD>';
						list += '				<TD width="170" align=left colspan=3><B>Starting On</B></TD>';
						list += '				</TR>';

			// populating rd_classes array
			for (x=0; x < rd_schedule_Array.length ; x++)
			{
						// looking for the starting lesson #1 info
						if (rd_schedule_Array[x][2] == "1" &&
								rd_schedule_Array[x][3] == day)
						{
								list += '<TR>';
								list += '	     <TD align="left" style="padding-left:0px; " width=330" nowrap >';
								list += '	            <INPUT TYPE="checkbox" NAME="rd_classes" disabled="" ';

								//assigning array index (x) to relate this record line to the DAY schedule array
								list += '             value=' + x;
								list += '		           onclick=`check_rd_class_day("'+day+'", this.value);` >'; 
								list += '		           <span  id=field1 >' + rd_schedule_Array[x][1] +'</span></TD>';
								list += '      <TD width=25  nowrap align=left  ><span  id=field3 >' + rd_schedule_Array[x][3] + '</span></TD>';
								list += '      <TD width=75  nowrap align=right><span  id=field4 >' + rd_schedule_Array[x][4] + '</span></TD>';
								list += '      <TD width=70  nowrap align=right><span  id=field5 >' + rd_schedule_Array[x][5] + '</span></TD>';
								list += '</TR>';
						}
			}

						list += '</TABLE>';

			if (document.all)
			    document.all.show_courses_list.innerHTML=list
			else 
				  if (document.getElementById)
			        document.getElementById("show_courses_list").innerHTML= list
//					    else
//			            document.write(list)

      clean_sheet_reminder();
			rd_classes_checked('');
			rd_classes_disabled(day);

	}

//=============================================================================

function rd_classes_checked(valor){
					for (i=0; i < document.rd.rd_classes.length; i++)
					{
						 document.rd.rd_classes[i].checked= valor;
					}
	}
function rd_classes_disabled(day){
			chk_mb=false;
			chk_byl=false;
			chk_lse=false;
			chk_fyp=false;
			chk_kgc=false;
			chk_tlc=false;
			flag=false;
			flag_any=true;
			count=0;

			for (i=0; i < document.rd.rd_classes.length; i++)
			{
						//validating if class date is begun to disable checkbox
						begun = false;
						begun = check_class_date_begun(i) //return true or false

						//validating if date of the class is begun to disable checkbox
						if (begun==true){
								document.rd.rd_classes[i].disabled="disabled";
								class_style_color(day,i,"off");

								}else{

										x = document.rd.rd_classes[i].value;
										if (document.rd.road_program[0].checked) //COMPLETE ROAD PROGRAM
											{
												   document.rd.fee.value=25.00;

														//positioning the the student on the first road class - membership as starting on point date
														//checking this class once (may two same classes scheduled)
														if (rd_schedule_Array[x][0] == "MB" && chk_mb == false){
																document.rd.rd_classes[i].checked="checked";
																class_style_color(day,i,"on");
																chk_mb = true;
																count += 1;
														}
														if (rd_schedule_Array[x][0] == "BYL" && chk_byl == false){
																document.rd.rd_classes[i].checked="checked";
																class_style_color(day,i,"on");
																chk_byl = true;
																count += 1;
														}
														if (rd_schedule_Array[x][0] == "LSE" && chk_lse == false){
																document.rd.rd_classes[i].checked="checked";
																class_style_color(day,i,"on");
																chk_lse  = true;
																count += 1;
														}
														if (rd_schedule_Array[x][0] == "FYP" && chk_fyp == false){
																document.rd.rd_classes[i].checked="checked";
																class_style_color(day,i,"on");
																chk_fyp = true;
																count += 1;
														}
														if (rd_schedule_Array[x][0] == "KGC" && chk_kgc == false){
																document.rd.rd_classes[i].checked="checked";
																class_style_color(day,i,"on");
																chk_kgc = true;
																count += 1;
														}
														if (rd_schedule_Array[x][0] == "TLC" && chk_tlc == false){
																document.rd.rd_classes[i].checked="checked";
																class_style_color(day,i,"on");
																chk_tlc = true;
																count += 1;
														}
														
														document.rd.rd_classes[i].disabled="disabled";
														
														 if (flag==false)
															 {
																	 fill_out_sheet_reminder(day,x);
																	 flag=true;
																}					

												}else{
																	document.rd.rd_classes[i].disabled="";
																	class_style_color(day,i,"non");
																	
																	//turning off this swich because at least one class available 
																	flag_any = false;

									}//end if rd program
						}//end if begun
			}//end for

			 var msg = "";
			 if (count > 0 && count < 6){ 
				  remaining = 6 - count;
					msg = '<div style="text-align:left;"><font color="red">NOTE:</font>&nbsp;' +
					           'The COMPLETE Road Class Program consists of <b>(6)</b> courses, ' +
					            'you have being registered now for <b>(' + count + ')</b>  Road available courses. ' +
					            'You will also be scheduled for the remaining <b>(' + remaining + ')</b> courses, ' +
										  'please visit us again later or check the information desk for the dates and times.</div><hr>';
					}

				if (document.all)
						document.all.show_sign_up_for_list.innerHTML= msg
				else 
						if (document.getElementById)
								document.getElementById("show_sign_up_for_list").innerHTML= msg
	//								else
	//										document.write(msg)

			

			if ((chk_mb == false && chk_byl == false && 	chk_lse == false && chk_fyp == false && chk_kgc == false && 	chk_tlc == false &&
						document.rd.road_program[0].checked) ||
					  flag_any == true &&
						document.rd.road_program[1].checked) 
				{
					document.rd.rd_class_day[0].checked="";
					document.rd.rd_class_day[0].focus();
			    document.rd.fee.value=0.00;
					clean_sheet_reminder();
					alert('Sorry, No ROAD PROGRAM CLASSES are currently on the calendar on ' + transform_daysto(day).toUpperCase() +
									 ' or  they have already begun! \n\n' +
						       'Please check again later or \n\n' +
									 'Call our MEMBERSHIP DEPARTMENT at (732) 727-9500 x 1405 \n' +
									 'For more information. \n\nThank you..!');
				}

	}

//=====================================================================
function transform_dayto(day){
		if (day=='Sun'){day='Sunday'};
		if (day=='Mon'){day='Monday'};
		if (day=='Tue'){day='Tuesday'};
		if (day=='Wed'){day='Wednesday'};
		if (day=='Thu'){day='Thursday'};
		if (day=='Fri'){day='Friday'};
		if (day=='Sat'){day='Saturday'};
		return day;
}
function transform_daysto(day){
		if (day=='Sun'){day='Sundays'};
		if (day=='Mon'){day='Mondays'};
		if (day=='Tue'){day='Tuesdays'};
		if (day=='Wed'){day='Wednesdays'};
		if (day=='Thu'){day='Thursdays'};
		if (day=='Fri'){day='Fridays'};
		if (day=='Sat'){day='Saturdays'};
		return day;
}

//validate if any classes checked, if yes then fill out or update the reminder sheet information
function check_rd_class_day(day, t){
			
			clean_sheet_reminder();
      document.rd.fee.value=0.00;
			fee=0.00;
			fee_count=0;
			flag=false;

				for (i=0; i < document.rd.rd_classes.length; i++)
				{
							//rd_classes_value contain the index value on the array for this class row
							x = document.rd.rd_classes[i].value;				
							if (document.rd.rd_classes[i].checked){

			             fee = fee + 15.00;
									 fee_count += 1;
									 document.rd.fee.value=fee;

									//Membership course no fee
									if (rd_schedule_Array[x][0] == "MB"){
											fee = fee - 15.00;
											document.rd.fee.value=fee;
									}

//									 if (fee_count > 4){ 
//										  alert('Your are registering (' + fee_count + ') Road courses with a FEE of: [$ ' + fee + '] \n' + 
//												       'Please we prefer that you register for The COMPLETE Road Class Program ' +
//												       '(All Classes) Fee for complete manual for $25.00.')
//											}

									 class_style_color(day,i,"on");
									 if (flag==false)
										 {
											   fill_out_sheet_reminder(day,x);
												 flag=true;
											}					
						 }else{
									if (document.rd.rd_classes[i].disabled)
										{
											 class_style_color(day,i,"off");
									   }else{
											 class_style_color(day,i,"non");
										 }
						 }
				}// end for		

}

function class_style_color(day,i,color){
	if (color=="on"){
						 field1[i].style.color="red";
						 field3[i].style.color="red";
						 field4[i].style.color="red";
						 field5[i].style.color="red";
	}

	if (color=="non"){
						 field1[i].style.color="";
						 field3[i].style.color="";
						 field4[i].style.color="";
						 field5[i].style.color="";
	}

	if (color=="off"){
						 field1[i].style.color="silver";
						 field3[i].style.color="silver";
						 field4[i].style.color="silver";
						 field5[i].style.color="silver";
	}
}

function clean_sheet_reminder(){
				document.rd.sign_up_for_rd_class.value='';
				document.rd.sign_up_for_rd_day.value='';
				document.rd.sign_up_for_rd_time.value='';
				document.rd.sign_up_for_rd_date.value='';
				document.rd.sign_up_for_rd_room.value='';

				sf_list='';
				if (document.all)
						document.all.show_sign_up_for_list.innerHTML= sf_list
				else 
						if (document.getElementById)
								document.getElementById("show_sign_up_for_list").innerHTML= sf_list

}
function fill_out_sheet_reminder(day, x){
				document.rd.sign_up_for_rd_class.value = rd_schedule_Array[x][1];
				document.rd.sign_up_for_rd_day.value = transform_daysto(rd_schedule_Array[x][3]);
				document.rd.sign_up_for_rd_date.value = rd_schedule_Array[x][4];
				document.rd.sign_up_for_rd_time.value = rd_schedule_Array[x][5];				
				document.rd.sign_up_for_rd_room.value = rd_schedule_Array[x][6];
}

function fill_out_sheet_reminder_list(day, x){
				// filling out the Registered Course Names List "rd_sign_up_for_list"
				var sf_list = "";
				var count = 0;

							sf_list += '<TABLE WIDTH="500" CELLPADDING="0" CELLSPACING="0" border=0>';
							sf_list += '<TR>';
							sf_list += '      <TD width="300"><B>Registered Courses List</B></TD>';
							sf_list += '				<TD width="155" colspan=3><B>Starting On</B></TD>';
							sf_list += '				<TD width="45" ><B>Room</B></TD>';
							sf_list += '</TR>';

				for (i=0; i < document.rd.rd_classes.length ; i++)
				{
							if (document.rd.rd_classes[i].checked){

									y = document.rd.rd_classes[i].value;

									sf_list += '<TR>';
									sf_list += '	   <TD align="left" style="padding-left:0px; " width=300 nowrap >';
									sf_list += '	     <INPUT TYPE="checkbox" NAME="rd_sign_up_for_list" value=' + y + ' disabled  checked >';
									sf_list += '	     <span  id=sf1 >' + rd_schedule_Array[y][1] +'</span></TD>';
									sf_list += '     <TD width=25  nowrap align=left  ><span  id=sf3 >' + rd_schedule_Array[y][3] + '</span></TD>';
									sf_list += '     <TD width=70  nowrap align=right><span  id=sf4 >' + rd_schedule_Array[y][4] + '</span></TD>';
									sf_list += '     <TD width=60  nowrap align=right><span  id=sf5 >' + rd_schedule_Array[y][5] + '</span></TD>';
									sf_list += '     <TD width=45  nowrap align=right><span  id=sf6 >' + rd_schedule_Array[y][6] + '</span></TD>';
									sf_list += '</TR>';

									count += 1;
								 
								 }
				}

				if (document.rd.road_program[0].checked) //complete road program
					{
								 if (count > 0 && count < 6){ 
										remaining = 6 - count;
										msg = '<font color="red"><b>NOTE:</b></font>&nbsp;' +
															 'The COMPLETE Road Class Program consists of <b>(6)</b> courses, ' +
																'you have being registered now for <b>(' + count + ')</b>  Road available courses. ' +
																'You will also be scheduled for the remaining <b>(' + remaining + ')</b> courses, ' +
																'please visit us again later or check the information desk for the dates and times.';

										sf_list += '<TR>';
										sf_list += '	   <TD align="left" style="padding-left:0px; " colspan=5 >';
										sf_list += '	     <INPUT TYPE="checkbox" NAME="rd_sign_up_for_list" disabled  checked > &nbsp;';
										sf_list += '	     <span>' + msg +'</span></TD>';
										sf_list += '</TR>';
								 }
					 }


							sf_list += '</TABLE>';
							sf_list += '<HR>';

							return sf_list;

//				if (document.all)
//						document.all.show_sign_up_for_list.innerHTML= sf_list
//				else 
//						if (document.getElementById)
//								document.getElementById("show_sign_up_for_list").innerHTML= sf_list
//					    else
//			            document.write(list)

}

function tS(){ x=new Date(); x.setTime(x.getTime()); return x; } 
function lZ(x){ return (x>9)?x:'0'+x; } 
function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } 

function build_item_number(){
			var mydate=new Date()
			var date_day=mydate.getDay()         //0=sun; 1=mon; 2=tue ...
			var date_dd=mydate.getDate()         //1 to 31
			var date_mm=mydate.getMonth()+1 //0=jan; 1=feb; 2=mar... to 11=dec
			var date_yyyy=mydate.getYear()

      var date_hh=lZ(mydate.getHours())
			var date_ms=lZ(mydate.getMinutes())

      var item_number="", program="COM", day="";
			var courses="", fee="0";

      if (document.rd.road_program[0].checked){program="-RD-C"}
      if (document.rd.road_program[1].checked){program="-RD-I"}
      if (document.rd.rd_class_day[0].checked){day="-SUN"}
      if (document.rd.rd_class_day[1].checked){day="-TUE"}

			for (i=0; i < document.rd.rd_classes.length ; i++)
			{
						if (document.rd.rd_classes[i].checked){
								y = document.rd.rd_classes[i].value;
								course = rd_schedule_Array[y][0];
								course = course.substring(0, 1)
								courses = courses + "-" + course;
							 }
			}

			fname = document.rd.fname.value;
			fname = fname.toUpperCase();
      if (fname.length > 1)
				{y=1;}else{y=fname.length}
			fname = fname.substring(0, y)

			lname = document.rd.lname.value;
			lname = lname.toUpperCase();
      if (lname.length > 3)
				{y=3;}else{y=lname.length}
			lname = lname.substring(0, y)
			
			if (date_mm < 10){date_mm = "0"+date_mm;}
			if (date_dd  < 10){date_dd   = "0"+date_dd;}

			item_number = lname + "-" + fname + date_mm + date_dd + date_hh + date_ms + program + day + courses;
			
			return item_number;

}