function ValidateTask()
{
	var  ttaskdate, ttaskdesc, ttaskhours
	var valdecimal = /(^\d+\.\d+$)/
	var valnumber = /(^-?\d+$)|(^-?\d+\.\d+$)/
	
	ttaskdate = false;
	ttaskdesc = false;
	ttaskhours = false;
	
	
	strMessage = "Please correct the following:\r\r";

/*date*/
if (GsJsIsDate(document.ProcessProBonoTask.TaskDate.value))
		ttaskdate = true;		
else
		strMessage += "A valid date is required (mm/dd/yyyy).\r";

/*desc*/
if (GsJsIsEmpty(document.ProcessProBonoTask.Task.value))
		strMessage += "A task description is required.\r";
else
		ttaskdesc = true;
		
/*hours*/
/*if (GsJsIsNumeric(document.ProcessProBonoTask.TaskHours.value))
      if (document.ProcessProBonoTask.TaskHours.value.match(valhours)) 
         alert("match found")
		else
			ttaskhours = true
			*/
/*if its a valid number*/
if (document.ProcessProBonoTask.TaskHours.value.match(valnumber))
/*if it has a dot*/
	if (document.ProcessProBonoTask.TaskHours.value.match(valdecimal))
		if ((Right(document.ProcessProBonoTask.TaskHours.value,2) == '00') || (Right(document.ProcessProBonoTask.TaskHours.value,2) == '25') || (Right(document.ProcessProBonoTask.TaskHours.value,2) == '50') || (Right(document.ProcessProBonoTask.TaskHours.value,2) == '75'))
			ttaskhours = true
		else
			strMessage += "Only .25, .50 or .75 can be used for minutes.\r";
			/*alert("dot found");*/
	else
/*valid number but no dot*/	
		ttaskhours = true;
else
/*invalid number*/
	strMessage += "Hours is required and must be numeric.\r";

			
if ( (ttaskdate) && (ttaskdesc) && (ttaskhours))
	{
		return true;
	}
else
	{
		alert(strMessage);
		return false;
	}
}


function ValidateForm()
{
	var tstufname, tstulname, tstuemail
	var tstuyearschool, temporganization, supattorney, tsupemail, strMessage, tsupphone
	var tVerificationCheck, tSignature
	var valPhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
 


	
	
	tstufname = false;
	tstulname = false;
	tstuemail = false;
	tstuyearschool = false;
	temporganization = false;
	supattorney = false;
	tsupemail = false;
	tsupphone = false;
	tVerificationCheck = false;
	tSignature = false;

	
	
	strMessage = "Please correct the following:\r\r";

/*first name*/
if (GsJsIsEmpty(document.ProcessProBonoHours.StuFName.value))
		strMessage += "First name is required.\r"
else
		tstufname = true;		

/*last name*/
if (GsJsIsEmpty(document.ProcessProBonoHours.StuLName.value))
		strMessage += "Last name is required.\r"
else
		tstulname = true;		

/*emai1*/
if (GsJsIsEmail(document.ProcessProBonoHours.StuEmail.value))
	tstuemail = true;
else
	strMessage += "A valid student email address is required.\r";
	

/*yearschool*/


/*
if ((document.ProcessProBonoHours.StuYearShool[0].checked == false) &&
	(document.ProcessProBonoHours.StuYearShool[1].checked == false) &&
	(document.ProcessProBonoHours.StuYearShool[2].checked == false))
		strMessage += "Year of school is required.\r";
else
		tstuyearschool = true;*/
		
/*org*/
if (GsJsIsEmpty(document.ProcessProBonoHours.EmpOrganization.value))
		strMessage += "Employer organization is required.\r";
else
		temporganization = true;		
		
/*attorney*/
if (GsJsIsEmpty(document.ProcessProBonoHours.SupAttorney.value))
		strMessage += "Supervisor attorney is required.\r";
else
		supattorney = true;				

/*sup email*/
if (GsJsIsEmail(document.ProcessProBonoHours.Supemail.value))
	tsupemail = true;
else
	strMessage += "A valid supervisor email is required.\r";
	
/*attorney*/

     if (!valPhoneNumber.test(document.ProcessProBonoHours.SupPhone.value)) 
		strMessage += "Supervisor phone is required and must be in (xxx) xxx-xxxx format.\r";
	else
		tsupphone = true;		
  

/*if (GsJsIsEmpty(document.ProcessProBonoHours.SupPhone.value))
		strMessage += "Supervisor phone is required.\r";
else
		tsupphone = true;			
*/		
if (GsJsIsEmpty(document.ProcessProBonoHours.Signature.value))
		strMessage += "Signature is required.\r";
else
		tSignature = true;			
			
if (document.ProcessProBonoHours.VerificationCheck.checked == true)
		tVerificationCheck = true;		
	else
			strMessage += "You must affirm that this info is correct by placing a check in the box.\r";	
			
if ((tstufname) && (tstulname) && (tstuemail) && (tstuyearschool) && (temporganization) && (supattorney)  && (tsupemail) && (tsupphone) && (tVerificationCheck) && (tSignature))
	{
		return true;
	}
else
	{
		alert(strMessage);
		return false;
	}
}


/******************/

        function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }



function IsCreditCard(s) {
var v = "0123456789";
var w = "";
for (var i=0; i < s.length; i++) {
x = s.charAt(i);
if (v.indexOf(x,0) != -1)
w += x;
}
var j = w.length / 2;
if (j < 6.5 || j > 8 || j == 7) return false;
var k = Math.floor(j);
var m = Math.ceil(j) - k;
var c = 0;
for (var i=0; i<k; i++) {
a = w.charAt(i*2+m) * 2;
c += a > 9 ? Math.floor(a/10 + a%10) : a;
}
for (var i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
return (c%10 == 0);
}

function IsPhone(strvalue)
{
regstr = /([(])\d{3}([)])([ ])\d{3}([-])\d{4}/;

   OK = regstr.exec(strvalue);
   if (!OK)
		return false;
	else
		return true;
}

function autotab (curr_field, char_count)
{
   var ele_len = document.forms[0].elements.length;  //form length
   var field_legnth = curr_field.value.length;       //field element
                                                     //field length or kepress input count

   for (var z=0; z<ele_len; z++)
       document.forms[0].elements[z].name;

   if (char_count == field_legnth)
   {
      for(var k=0; k<ele_len; k++)
         if(curr_field.name == document.forms[0].elements[k].name)
         {
            document.forms[0].elements[k+1].focus();
            return;
         }
   }
}

/************************************** Trims leading and trailing spaces from a input box **********

									Input:		field as an object
									Output:		changes value of object
									Use: 		on the onchange event; "Trim(this)"
									Modified:   2/13/01
									Mod. By:	LKeas
									
******************************************************************************************************/									

function GsJsTrim(field)
{
	while(''+field.value.charAt(field.value.length-1)==' ')
	{
		field.value=field.value.substring(0,field.value.length-1);
	}
	while(''+field.value.charAt(0)==' ')
	{
		field.value=field.value.substring(1,field.value.length);				
	}
}

/***********************************************************************************************    
			Email Validation
			Verifies if a string passed is a valid email address.  It must contain have text 
			before and after the @ and a 2 or 3 characters following the final .
			Input:		String
			Output:		true or false 	
************************************************************************************************/

function GsJsIsEmail(emailstr)
{

	var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
//Old regexp that didn't quite work/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(emailstr))
		return true;
	else
		return false;
}

/***********************************************************************************************    
			Date Validation
			Checks for the following valid date formats:
				MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
				Also separates date into month, day, and year variables
			Input:		String
			Output:		true or false 	
************************************************************************************************/

function GsJsIsDate(dateStr) 
{

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = dateStr.match(datePat); 		// is the format ok?
	
	if (matchArray == null) 
	{
		//alert("Date is not in a valid format.")
		return false;
	}
	
	month = matchArray[1]; 							// parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	
	if (month < 1 || month > 12) 
	{ 												// check month range
		// alert("Month must be between 1 and 12.");
		return false;
	}
	
	if (day < 1 || day > 31) 
	{
		// alert("Day must be between 1 and 31.");
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		//alert("Month "+month+" doesn't have 31 days!")
		return false;
	}
	
	if (month == 2) 
	{ 
		// check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			// alert("February " + year + " doesn't have " + day + " days!");
			return false;
	   }
	}
	
	return true;  // date is valid

}

/*****************************************************************************************************************

				Check whether string s is empty.
				Input:			string
				Output:			True or False

*****************************************************************************************************************/

function GsJsIsEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

/**********************************************************************************************   
				Numeric Validation
					Input:		String
					Output:		true or false				
***********************************************************************************************/

function GsJsIsNumeric(string)
{
	var valid = "0123456789."
	var ok = "yes";
	var temp;
	
	if (string != "")
	{
		for (var i=0; i<string.length; i++) {
			temp = "" + string.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") ok = "no";
			}
		if (ok == "no" || string == "") {
			return false;
		}
		else
		{
			return true;
		}
	}
	else return false;
}




