function vStudentResubmission()
{
	//new grade must be numeric
	if ((document.Form1.tbNewGrade.value== "")||(!IsNumeric(document.Form1.tbNewGrade.value)))
	{
		document.getElementById("lbErr").innerHTML= "Please make sure New Grade is a decimal value.";
		return false;		
	}
	if(!isDate(document.Form1.tbDate.value,1))
	{
		document.getElementById("lbErr").innerHTML= "Date must be in mm/dd/yyyy format.";
		return false;		
	}
	
	return true;
}
function vApplication()
{
	//check student items
	if(document.Form1.ApplicationInfo1_tbStudentName.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter the student Name.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter the student Name.";
		return false;
	}
	if(document.Form1.ApplicationInfo1_tbDOB.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter the student Date of Birth.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter the student Date of Birth.";
		return false;
	}
	if(document.Form1.ApplicationInfo1_tbStudentAddress.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter the student Street Address.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter the student Street Address.";
		return false;
	}
	if(document.Form1.ApplicationInfo1_tbStudentCity.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter the student City.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter the student City.";
		return false;
	}
	if(document.Form1.ApplicationInfo1_tbStudentZIP.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter the student ZIP.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter the student ZIP.";
		return false;
	}
	if(document.Form1.ApplicationInfo1_tbStudentPhone.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter the student Telephone number.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter the student Telephone number.";
		return false;
	}
	if(document.Form1.ApplicationInfo1_tbStudentEmail.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter the student Email.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter the student Email.";
		return false;
	}
	
	//check guardian items - not needed anymore
	/*if(document.Form1.ApplicationInfo1_tbG1N.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter at least one Guardian name.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter at least one Guardian name.";
		return false;
	}
	if(document.Form1.ApplicationInfo1_tbG1R.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter at least one Guardian relationship.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter at least one Guardian relationship.";
		return false;
	}
	if(document.Form1.ApplicationInfo1_tbG1P.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter at least one Guardian Telephone number.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter at least one Guardian Telephone number.";
		return false;
	}
	if(document.Form1.ApplicationInfo1_tbG1E.value == "") 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please enter at least one Guardian Email.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please enter at least one Guardian Email.";
		return false;
	}*/
	
	//check for valid DOB
	if(!isDate(document.Form1.ApplicationInfo1_tbDOB.value,1))
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please make sure you enter a valid Date of Birth (mm/dd/yyyy).";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please make sure you enter a valid Date of Birth (mm/dd/yyyy).";
		return false;
	}
	
	//check for valid e-mails
	if(document.Form1.ApplicationInfo1_tbStudentEmail.value.indexOf("@")<0) 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please make sure you enter a valid student Email.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please make sure you enter a valid student Email.";
		return false;
	}
	/*if(document.Form1.ApplicationInfo1_tbG1E.value.indexOf("@")<0) 
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please make sure you enter a valid guardian Email.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please make sure you enter a valid guardian Email.";
		return false;
	}*/
	
	//check for Single-Quotes
	if ((CheckSQ(document.Form1.ApplicationInfo1_tbStudentName.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbDOB.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbStudentAddress.value))||
		(CheckSQ(document.Form1.ApplicationInfo1_tbStudentCity.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbStudentZIP.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbStudentPhone.value))||
		(CheckSQ(document.Form1.ApplicationInfo1_tbStudentEmail.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbLSN.value))||
		(CheckSQ(document.Form1.ApplicationInfo1_tbG1N.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbG1R.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbG1P.value))||
		(CheckSQ(document.Form1.ApplicationInfo1_tbG1E.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbStudentMobile.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbG2N.value))||
		(CheckSQ(document.Form1.ApplicationInfo1_tbG2R.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbG2P.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbG2E.value))||
		(CheckSQ(document.Form1.ApplicationInfo1_tbComments.value))||(CheckSQ(document.Form1.ApplicationInfo1_tbGoesBy.value)))
	{
		document.getElementById("ApplicationInfo1_lbErr").innerHTML= "Please do not use single quotes ( ' ) on these fields.";
		document.getElementById("ApplicationInfo1_lbErr2").innerHTML= "Please do not use single quotes ( ' ) on these fields.";
		return false;
	}
	
	return true;
}

function ValidateTemplate(lberr, lberr2)
{
	//get all text-boxes
	var inps = document.getElementsByTagName('input');
	if (inps)
	{
		if (checkinput(inps, lberr, lberr2)==false) return false;
	}
	
	var inps2 = document.getElementsByTagName('textarea');
	if (inps2)
	{
		if (checkinput(inps2, lberr, lberr2)==false) return false;
	}
	
	var inps3 = document.getElementsByTagName('select');
	if (inps3)
	{
		if (checkinput(inps3, lberr, lberr2)==false) return false;
	}	
	
	var inps4 = document.getElementsByTagName('table');
	//Radiobuttonlist is rendered as a table on html, defined a new table cssclass rbreq
	if(inps4)
	{
	//alert("table");
	    if(checkradio(inps4,lberr, lberr2)==false) return false;
	}
	
	return true;
}

function checkradio(inps, lberr, lberr2)
{

    for(var i=0; i<inps.length; i++)
    {
    //each radiobutton item is rendered as a child of the table node, extract the children which have the same id as the parent + _# 
        if(inps[i].className != 'reqrb') continue;
        var id = inps[i].id;
        //alert(id);
        var flag = 0;
        for(var j=0; j<20; j++)
        {
        var element = id + "_" + j;
        var child = document.getElementById(element)
        if (child)
            if(child.checked == true){
                flag = 1;
                //alert("Got one");
                }
        }
        if(flag == 0)
        {
				document.getElementById(lberr).innerHTML= "Please make sure you enter the required fields.";
				document.getElementById(lberr).style.color="Red";
				document.getElementById(lberr2).innerHTML = "Please make sure you enter the required fields.";	
				document.getElementById(lberr2).style.color="Red";
				inps[i].style.backgroundColor="Yellow";	
				window.scroll(0,findPos(document.getElementById(inps[i].id)));	
				SetFocus(inps[i].id);	
				return false;
		}
		else
		{
				inps[i].style.backgroundColor="LightYellow";
		}
    }
}

function checkinput(inps, lberr, lberr2)
{
	for(var i=0;i<inps.length;i++)
	{
		inps[i].style.borderColor="gainsboro";
		if(inps[i].className == '' || inps[i].className == 'def') continue;
		if (inps[i].className != 'dt' && inps[i].className != 'dtnr' && inps[i].className != 'req' && inps[i].className != 'reqnum' && inps[i].className != 'num' && inps[i].className != 'em' && inps[i].className != 'dd' && inps[i].className != 'ddstylereq' && inps[i].className != 'reqphone') continue
		//This will prevent the user to enter spaces only on a required field. Spaces only will be converted to ""
		inps[i].value = RemoveSpaces(inps[i].value); 
		//dates are always required and should be in the dd/mm/yyyy format
		if (inps[i].className=='dt')
		{
			if (inps[i].value=="")
			{
				document.getElementById(lberr).innerHTML= "Please make sure Dates are valid (MM/DD/YYYY). (YYYY > 1900)";
				document.getElementById(lberr).style.color="Red";
				document.getElementById(lberr2).innerHTML = "Please make sure Dates are valid (MM/DD/YYYY).(YYYY > 1900)";	
				document.getElementById(lberr2).style.color="Red";
				inps[i].style.backgroundColor="Yellow";	
				window.scroll(0,findPos(document.getElementById(inps[i].id)));	
				SetFocus(inps[i].id);	
				return false;
			}
			if (!isDate(inps[i].value,1))
			{
			    document.getElementById(lberr).innerHTML = "Please make sure Dates are valid (MM/DD/YYYY).(YYYY > 1900)";	
				document.getElementById(lberr).style.color="Red";
				document.getElementById(lberr2).innerHTML = "Please make sure Dates are valid (MM/DD/YYYY).(YYYY > 1900)";	
				document.getElementById(lberr2).style.color="Red";
				inps[i].style.backgroundColor="Yellow";	
				window.scroll(0,findPos(document.getElementById(inps[i].id)));
				SetFocus(inps[i].id);		
				return false;
			}
			
			inps[i].style.backgroundColor="LightYellow";
		}
		//date not required
		else if (inps[i].className=='dtnr')
		{
			if (inps[i].value=="")
			{
				continue;
			}
			if (!isDate(inps[i].value,1))
			{
			    document.getElementById(lberr).innerHTML = "Please make sure Dates are valid (MM/DD/YYYY).(YYYY > 1900)";	
				document.getElementById(lberr).style.color="Red";
				document.getElementById(lberr2).innerHTML = "Please make sure Dates are valid (MM/DD/YYYY).(YYYY > 1900)";	
				document.getElementById(lberr2).style.color="Red";
				inps[i].style.backgroundColor="Yellow";	
				window.scroll(0,findPos(document.getElementById(inps[i].id)));	
				SetFocus(inps[i].id);	
				return false;
			}
			
			inps[i].style.backgroundColor="White";
		}
		else if (inps[i].className=='req')
		{
			if (inps[i].value=="")
			{
				document.getElementById(lberr).innerHTML= "Please make sure you enter the required fields.";	
				document.getElementById(lberr).style.color="Red";
				document.getElementById(lberr2).innerHTML= "Please make sure you enter the required fields.";	
				document.getElementById(lberr2).style.color="Red";
				inps[i].style.backgroundColor="Yellow";	
				window.scroll(0,findPos(document.getElementById(inps[i].id)));	
				SetFocus(inps[i].id);					
				return false;
			}
			else
			{
				inps[i].style.backgroundColor="LightYellow";
			}
		}
		else if (inps[i].className=='reqnum')
		{
			if (inps[i].value=="")
			{
				document.getElementById(lberr).innerHTML= "Please make sure you enter the required fields.";	
				document.getElementById(lberr).style.color="Red";
				document.getElementById(lberr2).innerHTML= "Please make sure you enter the required fields.";	
				document.getElementById(lberr2).style.color="Red";
				inps[i].style.backgroundColor="Yellow";	
				window.scroll(0,findPos(document.getElementById(inps[i].id)));	
				SetFocus(inps[i].id);					
				return false;
			}
			else
			{
				if (!IsNumeric(inps[i].value))
				{
					document.getElementById(lberr).innerHTML= "Please make sure you enter a numeric value.";	
					document.getElementById(lberr).style.color="Red";
					document.getElementById(lberr2).innerHTML= "Please make sure you enter a numeric value.";	
					document.getElementById(lberr2).style.color="Red";
					inps[i].style.backgroundColor="Yellow";	
					window.scroll(0,findPos(document.getElementById(inps[i].id)));
					SetFocus(inps[i].id);						
					return false;
				}
				else
				{
					inps[i].style.backgroundColor="LightYellow";
				}
			}
		}
		else if (inps[i].className=='num')
		{
			if (inps[i].value=="")
			{
				continue;
			}
			else
			{
				if (!IsNumeric(inps[i].value))
				{
					document.getElementById(lberr).innerHTML= "Please make sure you enter a numeric value.";	
					document.getElementById(lberr).style.color="Red";
					document.getElementById(lberr2).innerHTML= "Please make sure you enter a numeric value.";	
					document.getElementById(lberr2).style.color="Red";
					inps[i].style.backgroundColor="Yellow";	
					window.scroll(0,findPos(document.getElementById(inps[i].id)));		
					SetFocus(inps[i].id);				
					return false;
				}
				else
				{
					inps[i].style.backgroundColor="LightYellow";
				}
			}
		}
		else if (inps[i].className=='em')
		{
	        if(inps[i].value.search("@")<0) 
			//if (inps[i].value.search(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)==-1)
			{
				document.getElementById(lberr).innerHTML= "Please make sure you enter a valid e-mail.";	
				document.getElementById(lberr).style.color="Red";
				document.getElementById(lberr2).innerHTML= "Please make sure you enter a valid e-mail.";	
				document.getElementById(lberr2).style.color="Red";
				inps[i].style.backgroundColor="Yellow";	
				window.scroll(0,findPos(document.getElementById(inps[i].id)));	
				SetFocus(inps[i].id);					
				return false;
			}
			else
			{
				inps[i].style.backgroundColor="LightYellow";
			}
		}
		else if (inps[i].className == 'dd' || inps[i].className == 'ddstylereq')
		{
		    if (inps[i].value.indexOf("Select") == 0 || inps[i].value.indexOf("Any") == 0 || inps[i].value.indexOf("Type Name...") == 0 || inps[i].value == "null")
			{
				document.getElementById(lberr).innerHTML= "Please make sure you select an option from the marked dropdown.";	
				document.getElementById(lberr).style.color="Red";
				document.getElementById(lberr2).innerHTML= "Please make sure you select an option from the marked dropdown.";	
				document.getElementById(lberr2).style.color="Red";
				inps[i].style.backgroundColor="Yellow";	
				window.scroll(0,findPos(document.getElementById(inps[i].id)));
				SetFocus(inps[i].id);			
				return false;
			}
			else
			{
				inps[i].style.backgroundColor="LightYellow";
			}
		}
		else if (inps[i].className=='reqphone')
		{
			if (inps[i].value=="")
			{
				document.getElementById(lberr).innerHTML= "Please make sure you enter the required fields.";	
				document.getElementById(lberr).style.color="Red";
				document.getElementById(lberr2).innerHTML= "Please make sure you enter the required fields.";	
				document.getElementById(lberr2).style.color="Red";
				inps[i].style.backgroundColor="Yellow";	
				window.scroll(0,findPos(document.getElementById(inps[i].id)));
				SetFocus(inps[i].id);				
				return false;
			}
			else
			{
				if (inps[i].value.search(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/)==-1)
				{
					document.getElementById(lberr).innerHTML= "Please make sure the phone number is in the (###) ###-#### format.";	
					document.getElementById(lberr).style.color="Red";
					document.getElementById(lberr2).innerHTML= "Please make sure the phone number is in the (###) ###-#### format.";	
					document.getElementById(lberr2).style.color="Red";
					inps[i].style.backgroundColor="Yellow";		
					window.scroll(0,findPos(document.getElementById(inps[i].id)));
				    SetFocus(inps[i].id);			
					return false;
				}
				else
					inps[i].style.backgroundColor="LightYellow";
			}
		}
	}
		
	return true;
}


function vCourseAddSection()
{
	if(document.Form1.tbName.value == "")
	{
		document.getElementById("lbErr").innerHTML= "Please specify a section name.";
		return false;
	}

//	if (document.Form1.tbLMSID.value == "")
//	{
//	    document.getElementById("lbErr").innerHTML = "Please enter the section's GoCourse ID.";
//	    return false;
//	}	

	if(document.Form1.ddProgram.selectedIndex == 0)
	{
		document.getElementById("lbErr").innerHTML= "Please select a program.";
		return false;
	}

	if (document.Form1.ddTeacher.length > 1 &&
	    document.Form1.ddTeacher.selectedIndex == 0)
	{
		document.getElementById("lbErr").innerHTML= "Please select a teacher.";
		return false;
	}
	
	if(document.Form1.ddWeeks.selectedIndex == 0)
	{
		document.getElementById("lbErr").innerHTML= "Please select the number of weeks.";
		return false;
	}
	
	if(document.Form1.ddCredits.selectedIndex == 0)
	{
		document.getElementById("lbErr").innerHTML= "Please select the number of credits.";
		return false;
	}
	
	return true;
}

function vSectionAddStudent()
{
    if (document.Form1.ddStudents.length > 1 &&
        document.Form1.ddStudents.selectedIndex == 0)
	{
		document.getElementById("lbErr").innerHTML= "Please select a student.";
		return false;
	}
}

function vFileshareFolder()
{
	var ErrorMsg = "";
	if(document.Form1.TextBox1.value == "")
	{
		ErrorMsg   += "\n\t Please, provide a name for the folder";
		alert(ErrorMsg);
		return false;
	}
	return true;
}

function showheadertip(idx) {
    var tooltip = (document.getElementById) ?
		document.getElementById('htip' + idx) : eval("document.all['htip" + idx + "']");
    if (tooltip != null) {
        tooltip.style.pixelLeft = mouseX(event);
        tooltip.style.pixelTop = mouseY(event) + 20;
        if (tooltip.innerText != "") tooltip.style.visibility = "visible";
        else tooltip.style.visibility = "hidden";
    }
}

function mouseX(evt) {
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
        return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
    else return null;
}

function mouseY(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
        return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
    else return null;
}

function hideheadertip(idx)
{
	var tooltip = (document.getElementById) ?
	document.getElementById('htip' + idx) : eval("document.all['htip" + idx + "']");
	if (tooltip != null)
	{
		tooltip.style.visibility = "hidden";
	}
}

function TranscriptEdit(val)
{
    window.location = val;
}

function TranscriptDelete(val)
{
    var conf =  confirm("Are you sure you want to delete this course?");
    if(!conf) return;
    window.location = val;
}

function sumweight()
{
	var all = document.all ? document.all : document.getElementsByTagName('*');
	var elements = new Array();
	var sum = 0;
	for (var e=0;e<all.length;e++)
		if (all[e].className == 'grayinput')
		{
			var val = all[e].value;
			if (!IsNumeric(val))
			{
				document.getElementById("lbErr2").innerHTML= "Please make sure weights are valid decimal numbers (00.000 format).";
				return;
			}
			sum+=1*val+0;
		}
	document.getElementById("lbErr2").innerHTML= "";
	if (sum>100)
	{
		var dif=Math.round((sum*1-100)*1000)/1000;
		document.getElementById("tbWS").innerText = "Weights sum:"+sum+" ("+dif+" more than 100.00)";	
		document.getElementById("tbWS").style.color = "red";	
	}
	else if (sum<100)
	{
		var dif=Math.round((100-sum)*1000)/1000;
		document.getElementById("tbWS").innerText = "Weights sum:"+sum+" ("+dif+" missing to 100.00)";	
		document.getElementById("tbWS").style.color = "red";	
	}
	else
	{
		document.getElementById("tbWS").innerText = "Weights sum:"+sum;	
		document.getElementById("tbWS").style.color = "green";	
	}
}

//opens the calendar POP-UP
function opencal(ctl,val)
{
	window.open('Calendar.aspx?CTL='+ctl+'&SD='+val,'','scrollbars=no,menubar=no,height=300,width=300,resizable=no,toolbar=no');
}

//writes template in the comment field
function Template()
{

    if (document.Form1.CommunicationAddControl1_tbComment.value == "") {
        if (document.Form1.CommunicationAddControl1_ddTemplates.options[document.Form1.CommunicationAddControl1_ddTemplates.selectedIndex].text != 'Select...') {
            document.Form1.CommunicationAddControl1_tbComment.value = document.Form1.CommunicationAddControl1_ddTemplates.options[document.Form1.CommunicationAddControl1_ddTemplates.selectedIndex].text + ': ' + document.Form1.CommunicationAddControl1_tbComment.value;
        }
	}
}

function BillingChange()
{
	if ((document.Form1.ddDesc.selectedIndex==null)||(document.Form1.ddDesc.selectedIndex<1))
	{
		return;
	}
	var Value = document.Form1.ddDesc.options[document.Form1.ddDesc.selectedIndex].text;
	if (Value.indexOf("$")>0)
	{
		var d = Value.indexOf("$");
		var Amt = Value.substring(d+1,Value.length-1);
		document.Form1.tbValue.value = Amt;
	}
}
	
function BillingBulk()
{
    var select = document.getElementById("SelectBox");
    var selIndex = select.selectedIndex;
    if(selIndex < 0) return;
    var Value = select.options[selIndex].value;
	//var Value = document.Form1.ddDesc.options[document.Form1.ddDesc.selectedIndex].text;
	if (Value.indexOf("$")>0)
	{
		var d = Value.indexOf("$");
		var Amt = Value.substring(d+1,Value.length-1);
		document.Form1.tbValue.value = Amt;
	}
}

function vAffAdd()
{
	if(document.Form1.Affiliation1_tbName.value == "")
	{
		document.getElementById("Affiliation1_lbErr").innerHTML= "Please enter the School name.";
		return false;
	}
	if(document.Form1.Affiliation1_tbNumber.value == "")
	{
		document.getElementById("Affiliation1_lbErr").innerHTML= "Please enter the School number.";
		return false;
	}
	return true;
}

function vDisAdd()
{
	if(document.Form1.District1_tbName.value == "")
	{
		document.getElementById("District1_lbErr").innerHTML= "Please enter the District name.";
		return false;
	}
	if(document.Form1.District1_tbNumber.value == "")
	{
		document.getElementById("District1_lbErr").innerHTML= "Please enter the District number.";
		return false;
	}
	return true;
}


function vCommunicationAdd()
{
    var DateValue = document.Form1.CommunicationAddControl1_tbDate.value
    var HourValue = document.Form1.CommunicationAddControl1_tbHour.value
	if(DateValue == "" || HourValue == "")
	{
		document.getElementById("CommunicationAddControl1_lbErr").innerHTML= "Please enter a Date and Time.";
		return false;
	}
	
	if(isFutureDate(DateValue, 1) == 0) 
	{
		document.getElementById("CommunicationAddControl1_lbErr").innerHTML= "The date must be in the MM/DD/YYYY format.";
		return false;
	}
		
	if(isFutureDate(DateValue, 1) == 2) 
	{
		document.getElementById("CommunicationAddControl1_lbErr").innerHTML= "The communication date cannot be in the future.";
		return false;
	}
	
	if(!IsValidTime(HourValue))
	{
		document.getElementById("CommunicationAddControl1_lbErr").innerHTML= "The communication time must be in the HH:MM AM (or PM) format.";
		return false;
	}
	
	if((DateValue != "" && isFutureDate(DateValue, 1) != 1) || (HourValue != "" && !IsValidTime(HourValue)))
	{
		if(DateValue != "")
        {
            if(isFutureDate(DateValue, 1) == 0)
            {
				document.getElementById("CommunicationAddControl1_lbErr").innerHTML= "The communication date must be in the MM/DD/YYYY format.";
				return false;
			}
		    else if(isFutureDate(DateValue, 1) == 2)
		    {
				document.getElementById("CommunicationAddControl1_lbErr").innerHTML= "The communication date cannot be in the future.";
				return false;
			}
        }
		if(HourValue != "" && !IsValidTime(HourValue))
		{
			document.getElementById("CommunicationAddControl1_lbErr").innerHTML= "The communication time must be in the HH:MM AM (or PM) format.";
			return false;
		}
		return false;
	}
	return true;
}

function vStudentTranscript()
{
	//check if all items are there
	if(document.Form1.tbDate.value == "")
	{
		document.getElementById("lbErr").innerHTML= "Please enter a Date in any format.";
		return false;
	}
	
	if (document.Form1.ddSA.options[document.Form1.ddSA.selectedIndex].text=="Select...")
	{
		document.getElementById("lbErr").innerHTML= "Please select a Department.";
		return false;
	}
	
	if(document.Form1.tbFG.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter a Final Grade.";
		return false;
	}
	
	if(document.Form1.tbCourse.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter the Course Name.";
		return false;
	}
	
	if (document.Form1.ddCredits.options[document.Form1.ddCredits.selectedIndex].text=="Select...")
	{
		document.getElementById("lbErr").innerHTML= "Please select the amount of credits earned.";
		return false;
	}
	
	if(document.Form1.tbTakenAt.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter where the Course was taken.";
		return false;
	}
	
	if (document.Form1.ddGradeLevel.options[document.Form1.ddGradeLevel.selectedIndex].text=="Select...")
	{
		document.getElementById("lbErr").innerHTML= "Please select the grade level.";
		return false;
	}
	
	if (document.Form1.ddSemester.options[document.Form1.ddSemester.selectedIndex].text=="Select...")
	{
		document.getElementById("lbErr").innerHTML= "Please select the semester.";
		return false;
	}
	
	return true;
}

function vCreateAccount()
{
	//check if all items are there
	if(document.Form1.tbName.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter your Full Name.";
		return false;
	}
	if(document.Form1.tbEM.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter your E-mail.";
		return false;
	}
	if(document.Form1.tbUserID.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter your User ID.";
		return false;
	}
	if(document.Form1.tbPwd.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter your Password.";
		return false;
	}
	if(document.Form1.tbPss2.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please confirm your Password.";
		return false;
	}
	
	//check pwd
	if(document.Form1.tbPss2.value != document.Form1.tbPwd.value) 
	{
		document.getElementById("lbErr").innerHTML= "Please make sure you enter the same Password twice.";
		return false;
	}
	
	//check for valid e-mails
	if(document.Form1.tbEM.value.indexOf("@")<0) 
	{
		document.getElementById("lbErr").innerHTML= "Please make sure you enter a valid e-mail.";
		return false;
	}
	
	//check for Single-Quotes
	if ((CheckSQ(document.Form1.tbName.value))||(CheckSQ(document.Form1.tbEM.value))||(CheckSQ(document.Form1.tbUserID.value))||
		(CheckSQ(document.Form1.tbPwd.value))||(CheckSQ(document.Form1.tbPss2.value)))
	{
		document.getElementById("lbErr").innerHTML= "Please do not use single quotes ( ' ) on these fields.";
		return false;
	}
	
	return true;
}

function vAdministrationAddUser()
{
	//check if all items are there
	if(document.Form1.tbName.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter your Full Name.";
		return false;
	}
	if(document.Form1.tbEmail.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter your E-mail.";
		return false;
	}
	if(document.Form1.tbUserID.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter your User ID.";
		return false;
	}
	if(document.Form1.tbPassword.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter your Password.";
		return false;
	}
	
	//check for valid e-mails
	if(document.Form1.tbEmail.value.indexOf("@")<0) 
	{
		document.getElementById("lbErr").innerHTML= "Please make sure you enter a valid e-mail.";
		return false;
	}
	
	//check for valid DOB
	if((document.Form1.tbDOB.value !="")&&(!isDate(document.Form1.tbDOB.value,1)))
	{
		document.getElementById("lbErr").innerHTML= "Please make sure you enter a valid Date of Birth (mm/dd/yyyy).";
		return false;
	}

	
	//check for Single-Quotes
	if ((CheckSQ(document.Form1.tbName.value))||(CheckSQ(document.Form1.tbEmail.value))||(CheckSQ(document.Form1.tbUserID.value))||
		(CheckSQ(document.Form1.tbPassword.value))||(CheckSQ(document.Form1.tbPhone.value)))
	{
		document.getElementById("lbErr").innerHTML= "Please do not use single quotes ( ' ) on these fields.";
		return false;
	}
	
	return true;
}

function vStudentInfo()
{
	//check student items
	if(document.Form1.StudentInfo1_tbName.value == "") 
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please enter a student Name.";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please enter a student Name.";
		return false;
	}
	if(document.Form1.StudentInfo1_tbEM.value == "") 
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please enter the student Email.";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please enter the student Email.";
		return false;
	}
		
	//check guardian items
	/*if(document.Form1.StudentInfo1_tbG1N.value == "") 
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please enter at least one Guardian name.";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please enter at least one Guardian name.";
		return false;
	}
	if(document.Form1.StudentInfo1_tbG1R.value == "") 
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please enter at least one Guardian relationship.";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please enter at least one Guardian relationship.";
		return false;
	}
	if(document.Form1.StudentInfo1_tbG1P.value == "") 
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please enter at least one Guardian Telephone number.";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please enter at least one Guardian Telephone number.";
		return false;
	}
	if(document.Form1.StudentInfo1_tbG1EM.value == "") 
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please enter at least one Guardian Email.";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please enter at least one Guardian Email.";
		return false;
	}*/
	
	//check for valid DOB
	if(!isDate(document.Form1.StudentInfo1_tbBirthday.value,1))
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please make sure you enter a valid Date of Birth (mm/dd/yyyy).";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please make sure you enter a valid Date of Birth (mm/dd/yyyy).";
		return false;
	}
	
	//check for valid e-mails
	if(document.Form1.StudentInfo1_tbEM.value.indexOf("@")<0) 
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please make sure you enter a valid student Email.";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please make sure you enter a valid student Email.";
		return false;
	}
	/*if(document.Form1.StudentInfo1_tbG1EM.value.indexOf("@")<0) 
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please make sure you enter a valid guardian Email.";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please make sure you enter a valid guardian Email.";
		return false;
	}*/
	
	//check for Single-Quotes
	if ((CheckSQ(document.Form1.StudentInfo1_tbName.value))||(CheckSQ(document.Form1.StudentInfo1_tbBirthday.value))||(CheckSQ(document.Form1.StudentInfo1_tbEM.value))||
		(CheckSQ(document.Form1.StudentInfo1_tbAdd.value))||(CheckSQ(document.Form1.StudentInfo1_tbCity.value))||(CheckSQ(document.Form1.StudentInfo1_tbState.value))||
		(CheckSQ(document.Form1.StudentInfo1_tbZIP.value))||(CheckSQ(document.Form1.StudentInfo1_tbPhone.value))||(CheckSQ(document.Form1.StudentInfo1_tbMobile.value))||
		(CheckSQ(document.Form1.StudentInfo1_tbCom.value))||(CheckSQ(document.Form1.StudentInfo1_tbG1N.value))||(CheckSQ(document.Form1.StudentInfo1_tbG1R.value))||
		(CheckSQ(document.Form1.StudentInfo1_tbG1P.value))||	(CheckSQ(document.Form1.StudentInfo1_tbG1EM.value))||(CheckSQ(document.Form1.StudentInfo1_tbG2N.value))||
		(CheckSQ(document.Form1.StudentInfo1_tbG2R.value))||(CheckSQ(document.Form1.StudentInfo1_tbG2P.value))||(CheckSQ(document.Form1.StudentInfo1_tbG2EM.value))||
		(CheckSQ(document.Form1.StudentInfo1_tbLSA.value))||(CheckSQ(document.Form1.StudentInfo1_tbLSN.value)))
	{
		document.getElementById("StudentInfo1_lbErr").innerHTML= "Please do not use single quotes ( ' ) on these fields.";
		document.getElementById("StudentInfo1_lbErr2").innerHTML= "Please do not use single quotes ( ' ) on these fields.";
		return false;
	}
	
	return true;
}

function vChangePassword()
{
	//check if all items are there
	if(document.Form1.tbCur.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter the current password.";
		return false;
	}
	if(document.Form1.tbNP.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter your new password.";
		return false;
	}
	if(document.Form1.tbCNP.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please confirm your new password.";
		return false;
	}
	
	//check pwd
	if(document.Form1.tbNP.value != document.Form1.tbCNP.value) 
	{
		document.getElementById("lbErr").innerHTML= "Please make sure you enter the same Password twice.";
		return false;
	}
	
	//check for Single-Quotes
	if ((CheckSQ(document.Form1.tbCur.value))||(CheckSQ(document.Form1.tbNP.value))||(CheckSQ(document.Form1.tbCNP.value)))
	{
		document.getElementById("lbErr").innerHTML= "Please do not use single quotes ( ' ) on these fields.";
		return false;
	}
	
	return true;
}

function vStudentAdd()
{
	//check if all items are there
	if(document.Form1.tbName.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter the student name.";
		return false;
	}
	
	//check for Single-Quotes
	if ((CheckSQ(document.Form1.tbName.value))||(CheckSQ(document.Form1.tbCom.value)))
	{
		document.getElementById("lbErr").innerHTML= "Please do not use single quotes ( ' ) on these fields.";
		return false;
	}
	
	return true;
}

function vTeacherInfo()
{
	var ErrorMsg = "In order to edit this teacher's information: \n";
	if(document.Form1.tbName.value == "" || document.Form1.tbEmail.value == ""  || document.Form1.tbLoad.value == "")
	{
		if(document.Form1.tbName.value == "") ErrorMsg   += "\n\t The new teacher's name cannot be blank.";
		if(document.Form1.tbEmail.value == "") ErrorMsg   += "\n\t The new teacher's email cannot be blank.";
		if(document.Form1.tbLoad.value == "") ErrorMsg   += "\n\t The new teacher's contracted load cannot be blank and must be a positive integer.";
		else if(document.Form1.tbLoad.value != ""  && !IsIntegerNonZero(document.Form1.tbLoad.value))  ErrorMsg   += "\n\t The new teacher's contracted load must be a positive integer.";
		alert(ErrorMsg);
		return false;
	}
	else if(document.Form1.tbLoad.value != ""  && !IsIntegerNonZero(document.Form1.tbLoad.value))
	{
		ErrorMsg   += "\n\t The new teacher's contracted load must be a positive integer.";
		alert(ErrorMsg);
		return false
	}
	else if ((document.Form1.tbSince.value !="") && (!isDate(document.Form1.tbSince.value,1)))
	{
		ErrorMsg   += "\n\t The date must be in the dd/mm/yyy format.";
		alert(ErrorMsg);
		return false
	}
	return true;
}

function vEvents()
{
	//check Date
	var Date = document.Form1.tbDate.value;
	if(!isDate(Date,1))
	{
		document.getElementById("lbErr").innerHTML= "Please enter the event date (mm/dd/yyyy).";
		return false;
	}

	//short description
	if (document.Form1.tbShortDescription.value == "")
	{
		document.getElementById("lbErr").innerHTML= "Please enter a short description";
		return false;
	}
	
	return true;
}

function vSlots()
{
	//check from
	var From = document.Form1.tbStart.value;
	var To = document.Form1.tbEnd.value;
	if ((From == "") ||(To == ""))
	{
		document.getElementById("lbErr").innerHTML= "Please enter the Start and End times.";
		return false;
	}

	//len	
	if ((From.length!=5)||(To.length!=5))
	{
		document.getElementById("lbErr").innerHTML= "Please make sure Start and End times are in the HH:MM format.";
		return false;
	}
	
	//index of :
	if ((From.indexOf(":")!=2)||(To.indexOf(":")!=2))
	{
		document.getElementById("lbErr").innerHTML= "Please make sure Start and End times are in the HH:MM format.";
		return false;
	}
	
	//numbers
	if ((!IsNumeric(From.substring(0,2)))||(!IsNumeric(To.substring(3,5))))
	{
		document.getElementById("lbErr").innerHTML= "Please make sure Start and End times are in the HH:MM format.";
		return false;
	}
	
	
	return true;
}

function vMidTerm()
{
	//check if grade is there
	if(document.Form1.tbSem1.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter the 1st semester grade.";
		return false;
	}
	
	return true;
}

function vReportCard()
{
	//check if all items are there
	if(document.Form1.tbFinalGrade.value == "") 
	{
		document.getElementById("lbErr2").innerHTML= "Please enter the final grade.";
		return false;
	}
	
	return true;
}


function vCourseAdd()
{
	//check if all items are there
	if(document.Form1.tbName.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter the course name.";
		return false;
	}

	if (document.Form1.tbLMSID.value == "")
	{
	    document.getElementById("lbErr").innerHTML = "Please enter the course's GoCourse ID.";
	    return false;
	}	

	//check for Single-Quotes
	if (CheckSQ(document.Form1.tbName.value))
	{
		document.getElementById("lbErr").innerHTML= "Please do not use single quotes ( ' ) on the name fields.";
		return false;
	}
	
	return true;
}

function vAssignmentAdd()
{
	//check if all items are there
	if(document.Form1.tbName.value == "") 
	{
		document.getElementById("lbErr").innerHTML= "Please enter an assignment name.";
		return false;
	}
		
	//check for Single-Quotes
	if ((CheckSQ(document.Form1.tbName.value))||(CheckSQ(document.Form1.tbDesc.value)))
	{
		document.getElementById("lbErr").innerHTML= "Please do not use single quotes ( ' ) on these fields.";
		return false;
	}
	
	return true;
}

function setToPaid()
{
	if (document.Form1.ddStatus.value=="PAID")
	{
		var now = new Date();
		var mth = now.getMonth()*1+1;
		var day = now.getDate();
		var yr = now.getFullYear();
		//set paidon date
		//document.getElementById("tbPaidOn").value = mth+"/"+day+"/"+yr;
		
		//set value
		document.getElementById("tbPaid").value = document.Form1.tbValue.value;
	}
}

function vStudentTranscriptAnalysis()
{
	var ErrorMsg = "In order to add a course in the transcript analysis: \n";
	
	if(document.Form1.tbCourse.value == "")
	{
		if( document.Form1.tbCourse.value == "") ErrorMsg   += "\n\t The course name cannot be blank.";
		alert(ErrorMsg);
		return false;
	}
	
	if(!isDate(document.Form1.tbDate.value,1)) 
	{
		alert("The date must be in the mm/dd/yyyy format.");
		return false;
	}
	return true;
}

function Bill_Validate()
{
    if((document.Form1.ddStudent.value=="Select...") ||
	   (document.Form1.tbValue.value == "") ||
	   (document.Form1.tbCalendar.value == "") ||
	   (isFutureDate(document.Form1.tbCalendar.value, 1) == 0) ||
	   (!IsNumeric(document.Form1.tbValue.value)) ||
	   (CheckSQ(document.Form1.tbCom.value)))
	 {
	 var ErrMsg = "";
	    if(document.Form1.ddStudent.value=="Select...") ErrMsg += "Select a student.<br>";
	    if(document.Form1.tbValue.value == "") ErrMsg += "Enter the billing amount.<br>";
		if(document.Form1.tbValue.value != "" && !IsNumeric(document.Form1.tbValue.value)) ErrMsg += "Make sure you enter a numeric amount for the billing item.<br>";
		if(document.Form1.tbCalendar.value == "") ErrMsg += "Make sure you enter a due date for the billing item.<br>";
	    if(document.Form1.tbCalendar.value != "" && isFutureDate(document.Form1.tbCalendar.value, 1) == 0) ErrMsg += "Make sure to enter a valid billing due date in the MM/DD/YYYY format.<br>";
	    if ((CheckSQ(document.Form1.tbCom.value))) ErrMsg += "Please do not use single quotes ( ' ) on the comments.";
	    document.getElementById("lbErr").style.color = "red";
	    document.getElementById("lbErr").innerHTML = ErrMsg;
	    return false;
	 }
	 document.getElementById("lbErr").innerHTML = "";	
	 return true;
}

function Payment_Validate()
{
    if((document.Form1.ddStudent.value=="Select...") ||
	   (document.Form1.tbPaid.value == "") ||
	   (document.Form1.tbCalendar.value == "") ||
	   (isFutureDate(document.Form1.tbCalendar.value, 1) == 0) ||
	   (!IsNumeric(document.Form1.tbPaid.value)) ||
	   (CheckSQ(document.Form1.tbCom.value)))
	 {
	 var ErrMsg = "";
	    if(document.Form1.ddStudent.value=="Select...") ErrMsg += "Select a student.<br>";
	    if(document.Form1.tbPaid.value == "") ErrMsg += "Enter the payment amount.<br>";
		if(document.Form1.tbPaid.value != "" && !IsNumeric(document.Form1.tbPaid.value)) ErrMsg += "Make sure you enter a numeric amount for the payment.<br>";
		if(document.Form1.tbCalendar.value == "") ErrMsg += "Make sure you enter a payment date in theMM/DD/YYYY format.<br>";
	    if(document.Form1.tbCalendar.value != "" && isFutureDate(document.Form1.tbCalendar.value, 1) == 0) ErrMsg += "Make sure to enter a valid payment date in the MM/DD/YYYY format.<br>";
	    if ((CheckSQ(document.Form1.tbCom.value))) ErrMsg += "Please do not use single quotes ( ' ) on the comments.";
	    document.getElementById("lbErr").style.color = "red";
	    document.getElementById("lbErr").innerHTML = ErrMsg;
	    return false;
	 }
	 document.getElementById("lbErr").innerHTML = "";	
	 return true;
}

function CheckSQ(str)
{
	if (str.indexOf("'")>=0) return true;
	return false;
}

/**********************************************************************/ 
/*Function name :isDate(s,f) */ 
/*Usage of this function :To check s is a valid format */ 
/*Input parameter required:s=input string */ 
/* f=input string format */ 
/* =1,in mm/dd/yyyy format */ 
/* else in dd/mm/yyyy */ 
/*Return value :if is a valid date return 1 */ 
/* else return 0 */ 
/*Function required :isPositiveInteger() */ 
/**********************************************************************/
function isDate(s, f) {
    var a1 = s.split("/");
    var a2 = s.split("-");
    var e = true;
    if ((a1.length != 3) && (a2.length != 3)) {
        e = false;
    }
    else {
        if (a1.length == 3)
            var na = a1;
        if (a2.length == 3)
            var na = a2;
        if (isPositiveInteger(na[0]) && isPositiveInteger(na[1]) && isPositiveInteger(na[2])) {
            if (f == 1) {
                var d = na[1], m = na[0];
            }
            else {
                var d = na[0], m = na[1];
            }
            var y = na[2];
            if (((e) && (y < 1900) || y.length > 4))
                e = false
            if (e) {
                v = new Date(m + "/" + d + "/" + y);
                if (v.getMonth() != m - 1)
                    e = false;
            }
        }
        else {
            e = false;
        }
    }
    return e
}

/**********************************************************************/ 
/*Function name :isFutureDate(s,f) */ 
/*Usage of this function :To check s is a valid format and if s is future date*/ 
/*Input parameter required:s=input string */ 
/* f=input string format */ 
/* =1,in mm/dd/yyyy format */ 
/* else in dd/mm/yyyy */ 
/*Return value :if is a valid date not in the future return 1 */ 
/*Return value :if is a valid date in the future return 2 */ 
/* else return 0 */ 
/*Function required :isPositiveInteger() */ 
/**********************************************************************/ 
function isFutureDate(s,f) 
{
    var a1=s.split("/"); 
    var a2=s.split("-"); 
    var e=true;
    var r=0; 
    if ((a1.length==3) || (a2.length==3)) 
    {
        if (a1.length==3) 
            var na=a1; 
        if (a2.length==3) 
            var na=a2; 
        if (isPositiveInteger(na[0]) && isPositiveInteger(na[1]) && isPositiveInteger(na[2])) 
        {
            if (f==1) 
            {
                var d=na[1],m=na[0]; 
            } 
            else 
            {
                var d=na[0],m=na[1]; 
            } 
            var y=na[2];
            if (y>1000 && y.length==4) 
            { 
                v=new Date(m+"/"+d+"/"+y); 
                if (v.getMonth()==m-1 && v.getDate()==d) 
                {
                    var today = new Date();
                    if(v <= today) r = 1;
                    else r = 2;    
                }                
            } 
        } 
    } 
    return r 
}
 
function checkDate(v) 
{ 
var s=v.a.value; 
if (isDate(s,0)) //dd/mm/yyyy format 
alert("The inputted date value is valid!"); 
else 
alert("The inputted date value is not valid!"); 
return false; 
} 

/*************************************************************************/ 
/*Function name :isPositiveInteger(theString) */ 
/*Usage of this function :test for an +ve integer */ 
/*Input parameter required:thedata=string for test whether is +ve integer*/ 
/*Return value :if is +ve integer,return true */ 
/* else return false */ 
/*function require :isDigit */ 
/*************************************************************************/ 
function isPositiveInteger(theString) 
{ 
var theData = new String(theString) 

if (!isDigit(theData.charAt(0))) 
if (!(theData.charAt(0)== '+')) 
return false 

for (var i = 1; i < theData.length; i++) 
if (!isDigit(theData.charAt(i))) 
return false 
return true 
}

/**********************************************************************/ 
/*Function name :isDigit(theDigit) */ 
/*Usage of this function :test for an digit */ 
/*Input parameter required:thedata=string for test whether is digit */ 
/*Return value :if is digit,return true */ 
/* else return false */ 
/**********************************************************************/ 
function isDigit(theDigit) 
{ 
var digitArray = new Array('0','1','2','3','4','5','6','7','8','9'),j; 

for (j = 0; j < digitArray.length; j++) 
{if (theDigit == digitArray[j]) 
return true 
} 
return false 
}

function IsNumeric(sa)
{
	var IsNumber=true;
	var Char;
	var i;
	var ValidChars = "0123456789.-";
	var PtCnt = 0;
	for (i = 0; i < sa.length && IsNumber == true; i++)   
	{
	    Char = sa.charAt(i);

	    if (Char == ".") {
	        PtCnt++;
	        if (PtCnt > 1) return false;
	    }

        //WJK 1/11/2010 - allow negative numbers.
		if (Char == "-") {
		    if (i > 0) return false;
		}
		
		if (ValidChars.indexOf(Char) == -1) IsNumber = false;
	}
	return IsNumber;
}

//This will prevent the user to enter spaces only on a required field. Spaces only will be converted to ""
function RemoveSpaces(sa) {//J to avoid only spaces in required field 7/17/09
    if (sa == "") return "";
    var Char;
    var i;
    for (i = 0; i < sa.length; i++) {
        Char = sa.charAt(i);
        if (Char != " ") return sa;
    }
    return "";
}

function IsIntegerNonZero(sa)
{
	var IsNumber=true;
	var Char;
	var i;
	var ValidChars = "0123456789";
	for (i = 0; i < sa.length && IsNumber == true; i++)   
	{
		Char = sa.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) IsNumber = false;
	}
	if (IsNumber)
	{
		if(sa < 1) return false;
	}
	return IsNumber;
}

function IsValidTime(timeStr)
{
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null)
{
    return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
//alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
//alert("You must specify AM or PM.");
return false;
   }
}
if  (hour > 12 && ampm != null) {
//alert("You can't specify AM or PM for military time.");
return false;
}
if (minute<0 || minute > 59) {
//alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
//alert ("Second must be between 0 and 59.");
return false;
}
return true;
}

function ShowDiv(DivToShow) 
{
    var DivEle = document.getElementById(DivToShow);
    if (DivEle != null)
    {
        DivEle.style.visibility = "visible";
    }
}

function HideDiv(DivToHide)
{
    var DivEle = document.getElementById(DivToHide);
    if (DivEle != null)
    {
        DivEle.style.visibility = "hidden";
    }
}


//finds Y co-ordinate of obj
function findPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		curtop = curtop - 100;
	return [curtop];
	}
}

function SetFocus(obj)
{
    if(document.getElementById(obj) != null)
    {
    document.getElementById(obj).focus();
    }
}