   // JavaScript Document

   // Hide none calenar format
   function hidecal()
   {
       cal.style.position = "absolute";
	   cal.style.visibility = 'hidden';
	   window.print();
	   
	   return true;
   }
   
   function enrollers(employees)
   {	
   		var employees_per_enroller = 25;
		var num_of_enrollers = 0;
		
		// Admin needs to see the number of enrollers needed prior to rounding off. May not always be true
		// Based off of executive decision
   	    num_of_enrollers = document.getElementById('emp_id').innerHTML = employees / employees_per_enroller;
		
		// Round of number of enrollers to enter into DB.
		num_of_enrollers = Math.round(num_of_enrollers);
		
		// Since rounding is based on > .5 to go up or down, we check to for zero. This is the only time we force
		// the system to make an executive decision rather then the admin. Obviously there must always be at least
		// one enroller per site.
		if(num_of_enrollers == 0)
		{
		    num_of_enrollers = num_of_enrollers + 1;
		}
		
		// Assign value to "Number of enrollers text box". However the admin still is able to override this decision
		// based on the calcuations she is given.
		document.getElementById('enr_id').value = num_of_enrollers;
   }
   
   function is_empty(txt_value)
   {
	  if (txt_value == "" || txt_value == null) 
	  {
		   return false;
	  }
	  
	  return true;
   }
	
	function checkEmail (id_name) 
	{
		var error = "";
		
		switch (id_name)
		{
			case "email": 
			  txt_field = "Email";
			break;
			case "confirm_email": 
			  txt_field = "Confirm Email";
			break;
			default : "Email";
		}
		
		txt_value = document.getElementById(id_name).value;
		var email = document.getElementById("confirm_email").value;
		
		if (txt_value != email) 
		{
		   return "Email addresses do not match.\n";
		}
		
		if (false == is_empty(txt_value)) 
		{
		   return txt_field + " address is empty.\n";
		}
		
		var emailFilter=/^.+@.+\..{2,3}$/;
		
		if (!(emailFilter.test(txt_value))) 
		{ 
		   return txt_field + " contains an invalid email address.\n";
		}
		else 
		{
		    //test email for illegal characters
		    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
			
			if (txt_value.match(illegalChars)) 
			{
			    return txt_field + " contains illegal characters.\n";
		    }
		}
		
		return error;    
    }

	/* phone number - strip out delimiters and check for 10 digits
	*
	*/
	function chk_phone (id_name, empty, label) 
	{
		var error = "";
		
		ph_num = document.getElementById(id_name).value;
				
		if (false == is_empty(ph_num) && empty == "no") 
		{
		   return label + " is empty.\n";
		}
		
		//strip out acceptable non-numeric characters
		var stripped = ph_num.replace(/[\(\)\.\-\ ]/g, ''); 
		
		if (isNaN(parseInt(stripped)) && ph_num != "") 
		{
		   return label + " # contains illegal characters.\n";
		}
		
		if (!(stripped.length == 10) && ph_num != "")
		{
			return label + " is invalid -- i.e. ##########.\n";
		}
		 
		return error;
	}

	// chk_alpha
	function chk_alpha(id_name, empty, label, filter) 
	{
	    var error = "";
				
		txt_value = document.getElementById(id_name).value;
		
		if (false == is_empty(txt_value) && empty == "no") 
		{
		   return label + " is empty.\n";
		}
		
		if (filter == "yes") 
		{
		    //strip out acceptable non-numeric characters
			var illegalChars = /^[0-9]|[\(\)\<\>\,\;\:\\\"\[\]\!\@\#\$\%\^\&\*\~\`\_\-\=\+]/;
	
			if (illegalChars.test(txt_value) && txt_value != "")
			{
			   error = label + " contains illegal characters (i.e. #,-, etc...).\n";
			}
		}
		
		return error;	  
	}
	
	// chk_alpha_num
	function chk_alpha_num(id_name, empty, label, filter) 
	{
	    var error = "";
		
		txt_value = document.getElementById(id_name).value
		
		if (false == is_empty(txt_value) && empty == "no") 
		{
		   return label + " is empty.\n";
		}
		
		if (filter == "yes") 
		{
		    //strip out acceptable non-numeric characters
			var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]\!\@\#\$\%\^\&\*\~\`\_\-\=\+]/;
			
			if (illegalChars.test(txt_value) && txt_value != "")
			{
			   error = label + " contains illegal characters (i.e. #,-, etc...).\n";
			}
		}
		
		return error;	  
	}
	
	// chk_num
	function chk_num(id_name, empty, label, filter) 
	{
	    var error = "";
		
		txt_value = document.getElementById(id_name).value
		
		if (false == is_empty(txt_value) && empty == "no") 
		{
		   return label + " is empty.\n";
		}
		
		if (filter == "yes") 
		{
		    //strip out acceptable non-numeric characters
			var illegalChars = /^[a-z]|[A-Z]|[\(\)\<\>\,\;\:\\\"\[\]\!\@\#\$\%\^\&\*\~\`\_\-\=\+]/;

			if (illegalChars.test(txt_value) && txt_value != "")
			{
			   error = label + " contains illegal characters.\n";
			}
		}
		
		return error;	  
	}

	function val_form() 
	{
		var fix = "";
		
		fix += chk_alpha("fname", "no", "First Name", "yes");
		fix += chk_alpha("mi", "yes", "Middle Initial", "yes");
		fix += chk_alpha("lname", "no", "Last Name", "yes");
		fix += checkEmail("email");
		fix += checkEmail("confirm_email");
		fix += chk_alpha_num("add_1", "no", "Address 1", "yes");
		fix += chk_alpha_num("add_2", "yes", "Address 2", "yes");
		fix += chk_alpha("city", "no", "City", "yes");
		fix += chk_num("zip", "no", "Zip", "yes");
		fix += chk_phone("work_ph", "no", "Work Phone");
		fix += chk_phone("cell_ph", "yes", "Cell Phone");
		fix += chk_phone("hm_ph", "yes", "Home Phone");
		fix += chk_phone("fax_ph", "yes", "Fax Number");
		fix += chk_alpha("lang", "yes", "Language", "yes");
		fix += chk_num("rsl_num", "yes", "RSL Number", "no");
		fix += chk_num("lic_type", "yes", "License Type", "no");
		fix += chk_num("yrs_exp", "yes", "Enrolling Years Exp.", "yes");
		fix += chk_alpha("airport", "yes", "Airport", "yes");

		if (fix != "") 
		{
		   alert("Please validate the following:\n\n" + fix);
		   return false;
		}
		
		return true;
	}
	
	function val_client_form() 
	{
		var fix = "";
		
		fix += chk_alpha("contact_name", "no", "Contact Name", "no");
		fix += chk_alpha("client_name", "no", "Client Name", "no");
		fix += chk_alpha_num("add_1", "no", "Address 1", "no");
		fix += chk_alpha_num("add_2", "yes", "Address 2", "no");
		fix += chk_alpha("city", "no", "City", "no");
		fix += chk_num("zip", "no", "Zip", "no");
		fix += chk_phone("hm_ph", "no", "Home Phone");
		fix += chk_phone("fax_ph", "yes", "Fax Number");

		if (fix != "") 
		{
		   alert("Please validate the following:\n\n" + fix);
		   return false;
		}
		
		return true;
	}
	
	var RE_NUM = /^\/?\d+$/;
	
	// date parsing function
	function val_cal_date (id_name, empty, label) 
	{
	    txt_value = document.getElementById(id_name).value
		
		if (false == is_empty(txt_value) && empty == "no") 
		{
		   return label + " is empty.\n";
		}
		
		if (txt_value != "") 
		{
		    var arr_date = txt_value.split('/');
		
			if (arr_date.length != 3) return "Invalid date format: '" + txt_value + "' on " + label + ".\nFormat accepted is mm/dd/yyyy.\n";
			if (!arr_date[0]) return "Invalid date format: '" + txt_value + "' on " + label + ".\nNo day of month value can be found.\n";
			if (!RE_NUM.exec(arr_date[0])) return "Invalid day of month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.\n";
			if (!arr_date[1]) return "Invalid date format: '" + txt_value + "'.\nNo month value can be found.\n";
			if (!RE_NUM.exec(arr_date[1])) return "Invalid month value: '" + arr_date[1] + "' on " + label + ".\nAllowed values are unsigned integers.\n";
			if (!arr_date[2]) return "Invalid date format: '" + txt_value + "'.\nNo year value can be found.\n";
			if (!RE_NUM.exec(arr_date[2])) return "Invalid year value: '" + arr_date[2] + "' on " + label + ".\nAllowed values are unsigned integers.\n";
	
			var dt_date = new Date();
			dt_date.setDate(1);
		
			if (arr_date[0] < 1 || arr_date[0] > 12) return "Invalid month value: '" + arr_date[0] + "' on " + label + ".\nAllowed range is 01-12.\n";
			dt_date.setMonth(arr_date[0]-1);
			 
			if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
			dt_date.setFullYear(arr_date[2]);
		
			var dt_numdays = new Date(arr_date[2], arr_date[0], 0);
			dt_date.setDate(arr_date[1]);
			if (dt_date.getMonth() != (arr_date[0]-1)) return "Invalid day of month value: '" + arr_date[1] + "' on " + label + ".\nAllowed range is 01-"+dt_numdays.getDate()+".\n";
	
			// return (dt_date)
		}
		
	    return "";
	}

    // Validate "Add Job" form
	function val_job_form() 
	{
		var fix = "";
		
		fix += val_cal_date ("sdate", "no", "Start Date");
		fix += val_cal_date ("edate", "yes", "End Date");
		fix += val_cal_date ("train_date", "yes", "Training Date");

		if (fix != "") 
		{
		   alert("Please validate the following:\n\n" + fix);
		   return false;
		}
		
		return true;
	}
	
	function val_sub_form() 
	{
		var fix = "";
		
		fix += chk_alpha("loc_name", "no", "Location Name", "yes");
		fix += chk_alpha_num("add_1", "no", "Address 1", "yes");
		fix += chk_alpha_num("add_2", "yes", "Address 2", "yes");
		fix += chk_alpha("city", "no", "City", "yes");
		fix += chk_num("zip", "no", "Zip", "yes");
		fix += chk_alpha("contact_name", "no", "Contact Name", "yes");
		fix += chk_phone("work_ph", "no", "Work Phone");
		fix += val_cal_date ("enroll_date", "yes", "Enrollment Date");
		//fix += chk_alpha("stime", "no");
		//fix += chk_alpha("etime", "no");
		fix += chk_num("num_of_emp", "no", "# of employees", "yes");
		
		if (fix != "") 
		{
		   alert("Please validate the following:\n\n" + fix);
		   return false;
		}
		
		return true;
	}