
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);	
		
		if (yyyy.length < 4)
		{
			yyyy = 2000 + yyyy*1;
		}

		return mm, dd, yyyy;
	}

function check_reg_date_begins(){
			mm=""; dd=""; yyyy=""; x=0;

			//Reg. Start Date
			charAtDate(fits_schedule_array[0][4]); //returns mm, dd, yyyy

			var reg_date=new Date(yyyy,mm-1,dd); //converting charAtDate var to date format
			var today_date=new Date(); 

		  if (today_date < reg_date){
				  return false;
			}else{
					return true;}
}

function check_reg_date_closed(){
			mm=""; dd=""; yyyy=""; x=0;

			charAtDate(fits_schedule_array[0][5]); //returns mm, dd, yyyy

			var late_date_end=new Date(yyyy,mm-1,dd*1); //converting charAtDate var to date format
			var today_date=new Date(); 

			var ndd=late_date_end.getDate();    //1 to 31
			var nmm=late_date_end.getMonth()+1; //0=jan; 1=feb; 2=mar... to 11=dec
		  var nyy=late_date_end.getYear();

			document.fits.latefeedate.value = fits_schedule_array[0][6];
			document.fits.latefeedate2.value = fits_schedule_array[0][6];
			document.fits.regclosingdate.value = nmm+"/"+ndd+"/"+nyy;
			document.fits.regclosingdate2.value = nmm+"/"+ndd+"/"+nyy;

			if (today_date > late_date_end){
								return true;
					}else{
							return false;}
}

function check_reg_date_late(){
			mm=""; dd=""; yyyy=""; x=0;

			//late start date 
			charAtDate(fits_schedule_array[0][6]); //returns mm, dd, yyyy
			var late_date_start=new Date(yyyy,mm-1,dd); //converting charAtDate var to date format

			var today_date=new Date(); 

	if (today_date < late_date_start){
				  return false;
			}else{
					return true;}
}
//=============================================================================

function check_registrations_date(){

			//validating if registration date begins
			reg_begins = true;
			reg_begins = check_reg_date_begins() //return true or false

			//validating if late date end is over (as a registration closing date) 
			reg_closed = false;
			reg_closed = check_reg_date_closed() //return true or false

  		if (reg_begins==false || reg_closed==true)
				{
					return false;
				}else{
					return true;
					}

	}

//=============================================================================
// Showing available Road Program Courses per Road Class Plan on Attending
function show_courses(day){

//        assigning title to table legend
//				document.all.legend_day.innerHTML ='Please check which ' + transform_dayto(day) + ' course(s)  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="500" align=center colspan=7 style="padding-left:0px;">';
						list += '				<B>SCHEDULE OF CLASSES</B>';
						list += '      </TD></TR>';
						list += '<TR>';
						list += '      <TD width="500" align=center colspan=7 style="padding-left:0px;">';
						list += '				<b>'+ fits_schedule_array[0][1] + '</b>';
						list += '				<br></b>' + fits_schedule_array[0][2] + " - " + fits_schedule_array[0][3] + '</b>';
						list += '    <br><a href="docs/FITS Catalog - part time.pdf" target="_blank">';
						list += '    <img src="img/max.gif" width="9" height="9" border="0">  Download FITS School Catalog</a>';
						list += '      </TD></TR>';

						list += '<TR><TD width="500" align=left colspan=7 style="padding-left:25px;">&nbsp;</TD></TR>';
						list += '<TR>';
						list += '   <TD align=left      colspan=2 style="padding-left:25px;"><B>English Available Courses</B></TD>';
						list += '				<TD align=left      colspan=2><B>Session</B></TD>';
						list += '				<TD align=left      colspan=2 style="padding-left:30px;"><B>Time</B></TD>';
						list += '				<TD align=right    ><B>Fee</B></TD>';
						list += '				</TR>';

			// populating classes array
			//0					    1							       2						         3							       4							       5												  6										     7					  8			       9		    10		 11				12			          13			  14		    15,   16
			//TRI ID,Trimester,Date Start,Date End,Reg. Start,Reg. End, Late Start,Code,Course,Day,Ses.,Time,Instructor,Lang.,Room,Fee,Description

				s_flag = 0;

				for (x=0; x < fits_schedule_array.length-1 ; x++)
				{
							if (fits_schedule_array[x][9] == day)
							{

									if (fits_schedule_array[x][13]=="SP") //spanish
										{
											  if (s_flag == 0)
											  {
														list += '<TR><TD width="500" align=left colspan=7 style="padding-left:25px;">&nbsp;</TD></TR>';
														list += '<TR>';
														list += '   <TD align=left      colspan=2 style="padding-left:25px;"><B>Cursos Disponibles en Español</B></TD>';
														list += '				<TD align=left      colspan=2><B>Sesión</B></TD>';
														list += '				<TD align=left      colspan=2 style="padding-left:30px;"><B>Hora</B></TD>';
														list += '				<TD align=right    ><B>Pago</B></TD>';
														list += '				</TR>';
														s_flag=1;
											  }
									  }// if "SP" end

									//assigning array index (x) to the value of classes table array 
									code = fits_schedule_array[x][7];
								 course = fits_schedule_array[x][8];
								 ses = fits_schedule_array[x][10];
								 time = fits_schedule_array[x][11];
									teacher = fits_schedule_array[x][12];
									fee = fits_schedule_array[x][15];
									desc = fits_schedule_array[x][16];

									list += '<TR>';
//									list += '	     <TD width=75 align=left style="padding-left:0px; " nowrap >';
									list += '	     <TD width=15 align=left style="padding-left:0px; " nowrap >';
									list += '	            <INPUT TYPE="checkbox" NAME="classes" disabled="" value=' + x;
									list += '		           onclick=`check_class_day("'+day+'", this.value);` >'; 
//									list += '		           <span  id=field1 style="font-size:8px;">' + code + '</span></TD>';
									list += '		           <span  id=field1 style="font-size:8px;"></span></TD>';
									
									list += '      <TD width=245 nowrap align=left  >';
									list += '														<span  id=field2 style="font-size:11px;">' + course + '</span>';
									//list += '             <img src="img/max.gif" width="9" height="9" border="0" style="cursor:hand;" title="click here to see more!" ';
									//list += '                      onclick=`row'+ x +'.style.display="";`>';
									list += '      </TD>';
									list += '      <TD width=20   nowrap align=left  ><span  id=field3 style="font-size:8px;">' + day + '</span></TD>';
									list += '      <TD width=20   nowrap align=left  ><span  id=field4 style="font-size:8px;">' + ses + '</span></TD>';
									list += '      <TD width=70   nowrap align=right><span  id=field5 style="font-size:9px;">' + time + '</span></TD>';
									list += '      <TD width=80   nowrap align=right><span  id=field6 style="font-size:9px;">' + teacher + '</span></TD>';
									list += '      <TD width=30  nowrap align=right><span  id=field7 style="font-size:10px;">$' + fee + '</span></TD>';
									list += '</TR>';

									list += '<TR id=row' + x + ' style="display:none;">';
									list += '      <TD align=left colspan=7 style="padding-left:23px; padding-right:40px;">';
									//list += '             <img src="img_fits_courses/' + code + '.jpg" width=70 height=87 border=0 align=left style="margin-right:5px;">';
									//list += '             <img src="img/min.gif" width="9" height="9" border="0" style="cursor:hand;" alt="click here to hide this info!" ';
									//list += '                      onclick=`row'+ x +'.style.display="none";`>&nbsp;' + desc; 
									list += '             </TD>';
									list += '      </TR>';


							}
		
				}//for end


			      list += '</TABLE>';

						return list;

	}

//=====================================================================

function courses_disabled(valor){
		for (i=0; i < document.fits.classes.length; i++)
		{
               document.fits.classes[i].disabled= valor;
//  					 class_style_color(day,i,"off");
		 }
	}

function courses_checked(valor){
		for (i=0; i < document.fits.classes.length; i++)
		{
               document.fits.classes[i].checked= valor;
//  					 class_style_color(day,i,"off");
		 }
	}


//validate if any classes checked, if yes then fill out or update the reminder sheet information
function check_class_day(day, t){
			
//		clean_sheet_reminder_list();
		count=0;
		savings=0.00;
		fee=0.00;
		latefee=0;
		regfee=10.00
		subtotal=0.00;
		total=0.00;
		flag=false;

		if (!document.fits.xregfee.checked)
		{
				regfee = 0.00;
		}

		for (i=0; i < document.fits.classes.length; i++)
		{
					//classes_value contain the index value on the array for this class row
					if (document.fits.classes[i].checked){

               x = document.fits.classes[i].value;	

							 fee = fits_schedule_array[x][15];
							 fee = fee*1;
							 subtotal = subtotal + fee;
							 count += 1;

							 class_style_color(day,i,"on");
				 }else{
									 class_style_color(day,i,"non");
				 }

//				 if (tfee_count > 5){ 
//						alert("You are registering more than 5 FITS course!")
//				 }

		}// end for		

	 if (count == 3){ savings = 30;}
	 if (count > 3){ savings = 65;}

		//validating if late date fee applicable 
		flag_reg_latefee = false;
		flag_reg_latefee = check_reg_date_late() //return true or false
		if (flag_reg_latefee == true)
			{
			  latefee=25.00;
			}

//calculating subtotal again because savings may be apply
	 subtotal = subtotal - savings;
	 total = subtotal + latefee + regfee;

	 document.fits.count.value = count;
	 document.fits.savings.value = savings;
	 document.fits.fee.value = subtotal;
   document.fits.latefee.value = latefee;
   document.fits.regfee.value = regfee;
   document.fits.total.value = total;

	 document.fits.reg.value = build_item_number();

    fill_out_sheet_reminder_list();

}

//=====================================================================

function class_style_color(day,i,color){
	if (color=="on"){
						 field1[i].style.color="red";
						 field2[i].style.color="red";
						 field3[i].style.color="red";
						 field4[i].style.color="red";
						 field5[i].style.color="red";
						 field6[i].style.color="red";
						 field7[i].style.color="red";
	}

	if (color=="non"){
						 field1[i].style.color="";
						 field2[i].style.color="";
						 field3[i].style.color="";
						 field4[i].style.color="";
						 field5[i].style.color="";
						 field6[i].style.color="";
						 field7[i].style.color="";
	}

	if (color=="off"){
						 field1[i].style.color="silver";
						 field2[i].style.color="silver";
						 field3[i].style.color="silver";
						 field4[i].style.color="silver";
						 field5[i].style.color="silver";
						 field6[i].style.color="silver";
						 field7[i].style.color="silver";
	}
}

function transform_dayto(day){
		if (day=='SUN'){day='Sunday (Domingo)'};
		if (day=='MON'){day='Monday (Lunes)'};
		if (day=='TUE'){day='Tuesday (Martes)'};
		if (day=='WED'){day='Wednesday (Miercoles)'};
		if (day=='THU'){day='Thursday (Jueves)'};
		if (day=='FRI'){day='Friday (Viernes)'};
		if (day=='SAT'){day='Saturday (Sabado)'};
		return day;
}
function transform_daysto(day){
		if (day=='SUN'){day='Sundays (Domingos)'};
		if (day=='MON'){day='Mondays (Lunes)'};
		if (day=='TUE'){day='Tuesdays (Martes)'};
		if (day=='WED'){day='Wednesdays (Miercoles)'};
		if (day=='THU'){day='Thursdays (Jueves)'};
		if (day=='FRI'){day='Fridays (Viernes)'};
		if (day=='SAT'){day='Saturdays (Sabados)'};
		return day;
}

//=====================================================================

function clean_sheet_reminder_list(){
				document.fits.count.value = 0;
				document.fits.fee.value = 0.00;
				document.fits.savings.value = 0.00;
				document.fits.latefee.value = 0.00;
				document.fits.xregfee.checked = "checked";
				document.fits.regfee.value = 10.00;
				document.fits.total.value = 0.00;
	      document.fits.i_sign_up_for.value = "";
	      document.fits.sheet_reminder_list.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_list(){
				// filling out the Registered Course Names List "sign_up_for_list"
				var hlist = "";
				var list = "";
				var count = 0;
				flag = false;

				document.fits.i_sign_up_for.value = fits_schedule_array[0][1] + "  " + fits_schedule_array[0][2] + " - " + fits_schedule_array[0][3];

				list += '<TABLE WIDTH="500" STYLE="border:0px solid #8FBDFF;" CELLPADDING="0" CELLSPACING="0" border=0>';
				hlist += '<TR><TD height=3    width="500" align=left colspan=7></TD></TR>';
				hlist += '<TR>';
				hlist += '      <TD align=left      colspan=2 style="padding-left:25px;" nowrap><B>Registered Course(s)</B></TD>';
				hlist += '				<TD align=left      colspan=2><B>Session</B></TD>';
				hlist += '				<TD align=left      colspan=2 style="padding-left:30px;"><B>Time</B></TD>';
				hlist += '				<TD align=right    ></TD>';
				hlist += '				</TR>';

				for (i=0; i < document.fits.classes.length; i++)
				{
							//classes_value contain the index value on the array for this class row
							if (document.fits.classes[i].checked){

								  if (flag == false)
								  {
										 list += hlist;
										 flag = true;
								  }

									x = document.fits.classes[i].value;	

									code = fits_schedule_array[x][7];
								  course = fits_schedule_array[x][8];
									day = fits_schedule_array[x][9];
								  ses = fits_schedule_array[x][10];
								  time = fits_schedule_array[x][11];
									teacher = fits_schedule_array[x][12];
									fee = fits_schedule_array[x][15];

									list += '<TR>';
									list += '	     <TD align=left style="padding-left:0px; " width=15 nowrap >';
									list += '	            <INPUT TYPE="checkbox" NAME="sign_up" disabled checked>'; 
//									list += '		          <span  style="font-size:8px;">' + code + '</span>';
									list += '		          </TD>';
									list += '      <TD width=245 nowrap align=left  ><span style="font-size:10px;">' + course + '</span></TD>';
									list += '      <TD width=20   nowrap align=left  ><span style="font-size:8px;">' + day + '</span></TD>';
									list += '      <TD width=20   nowrap align=left  ><span style="font-size:8px;">' + ses + '</span></TD>';
									list += '      <TD width=70   nowrap align=right><span style="font-size:9px;">' + time + '</span></TD>';
									list += '      <TD width=80   nowrap align=right><span style="font-size:9px;">' + teacher + '</span></TD>';
									list += '      <TD width=30   nowrap align=right><span style="font-size:10px;">$' + fee + '</span></TD>';
									list += '</TR>';

						}// end if
				}// end for

				if (flag == true)
				{
						list += '<TR><TD height=1    width="500" align=left colspan=7><hr></TD></TR>';
				}

				list += '</TABLE>';

			  document.fits.sheet_reminder_list.value = list;

				if (document.all)
						document.all.show_sign_up_for_list.innerHTML= list
				else 
						if (document.getElementById)
								document.getElementById("show_sign_up_for_list").innerHTML= 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="-FITS-PT", day="";
			var courses=0, mcourses=0, tcourses=0, som=0;

			for (i=0; i < document.fits.classes.length ; i++)
			{
						if (document.fits.classes[i].checked){
								y = document.fits.classes[i].value;
								if (fits_schedule_array[y][9]=="MON"){	mcourses += 1;}
								if (fits_schedule_array[y][9]=="TUE"){	tcourses += 1;}

								code = fits_schedule_array[y][7]
								code = code.substring(0, 3)
								if (code=="SOM"){	som += 1;}

								courses += 1;
							 }
			}

      day = "-M" + mcourses + "-T" + tcourses + "-SOM" + som;

			fname = document.fits.fname.value;
			fname = fname.toUpperCase();
      if (fname.length > 1)
				{y=1;}else{y=fname.length}
			fname = fname.substring(0, y)

			lname = document.fits.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;
			
			return item_number;

}