function myEmailValidation(obj, BlankWarning)
{
	addlen = obj.value.length;
	invalidchar = 0;
	usernamelength = 0;
	ampcount = 0;
	ampposition = 0;
	domainlength = 0;
	domaindotcount = 0;
	lastdomaindot = 0;
	 if((addlen < 1)&&(BlankWarning==1))
	 {
	 	return confirm("Are you sure that you wish to completely remove your e-Mail address from the system?\n\nClick\"OK\" to remove or \"Cancel\" to return.");
	 }else if(addlen < 1)
	 {
	 	return;
	 }
	 
	 for(i = 0;i < addlen;i++)	
	 {
	 	thischar = obj.value.substring(i,i+1);  
		if (/^\w|-|\.|@$/.test(thischar))	
		{
			if (ampcount == 0 && thischar != "@")	
			{
				usernamelength++;
			}
			if (thischar == "@")	
			{
				ampcount++;
				ampposition = i;
			}
			if (ampcount == 1 && thischar != "@")	
			{
				domainlength++;
			}
			if (ampcount == 1 && thischar == ".")	
			{
				if (i == ampposition+1 || i == lastdomaindot+1)	
				{
					invalidchar++;
				}
				domaindotcount++;
				lastdomaindot = i;
			}
		}
		else	
		{
			invalidchar++;
		}
	}
	if (!(invalidchar == 0 && usernamelength >= 1 && ampcount == 1 && ampposition != 0 && domaindotcount >= 1 && lastdomaindot+3 <= addlen && lastdomaindot+5 >= addlen && domainlength >= 4))
	{
		alert("You have entered an invalid email address.\nPlease enter a valid address.");
		obj.focus();
		return false;
	}else
	return true;
}
function emptyFieldValidation(obj, displayText)
{
	addlen = obj.value.length;
	 if(addlen < 1)
	 {
		alert(displayText + " is a required field.")
		obj.focus();
	 	return false;
	 }
}
function deleteThis(id, YearID, GroupID)
{
	if(confirm("Are you sure that you want to delete this person?\nClick OK to delete or Cancel to return")==true)
	{
		document.location="dn_ProgramResidentList.asp?ID=" + id + "&YearID=" + YearID + "&GroupID=" + GroupID;
	}
}
function CheckPWLength(obj)
{
	addlen = obj.value.length;
	 if(!(addlen > 0))
	 {
		alert("Passwords must be at least 1 character long.")
		obj.focus();
	 	return false;
	 }
}
function CheckPWMatch(obj1,obj2, obj3)
{
	pw1 = obj1.value;
	pw2 = obj2.value;
	pw1len = obj1.value.length;
	pw2len = obj2.value.length;
	oldlen = obj3.value.length;
	if (pw1len > 0 && pw2len > 0 && oldlen==0)
	{
		alert("Please enter your old password.");
		obj3.select();
		obj3.focus();
	 	return false;
	}
	 if(!(pw1==pw2))
	 {
		alert("Passwords do not match.")
		obj1.select()
		obj1.focus();
	 	return false;
	 }
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=2000;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Please enter an evaluation date.  The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}


function ValidateNewSDOT(obj1, obj2, obj3)
{
	if(obj1.selectedIndex == 0) {alert("You must select a Faculty member from the list"); obj1.select(); return false;}
	if(obj2.selectedIndex == 0) {alert("You must select a Resident from the list"); obj2.select(); return false;}
	if(isDate(obj3.value)==false){obj3.select; return false;}

	return true;
}

function ValidateCompletedForm(obj1, itemCount)
{
	if (obj1["TimeSpent"].value==""){alert("You must specify the amount of time that was spent with the resident."); return false;}
	if (obj1["PatientEncounters"].value==""){alert("You must specify the number of patient encounters that were observed."); return false;}
	if (obj1["PatientComplaint"].value==""){alert("You must specify the primary patient complaint."); return false;}

	for (var i=1; i<=itemCount; i++)
	{
		var btnName
		btnName = "Question" + i
		var btn = obj1[btnName];
		var valid
		for (var x=0;x<btn.length;x++) 
		{
			valid = btn[x].checked;
			if (valid) {break;}
		}
		if (!valid) 
		{
			alert("Please select an answer for question" + i + ".");
			break;
		}
	}
	if (valid)
	{return true;}else
	{return false;}
}

function ValidateProcedures(obj1)
{
	var NotAccurate
	var oProc = obj1["oArth"].value
	var dProc = obj1["dArth"].value
	var tProc = obj1["tArth"].value
	if ((!(oProc==""))||(!(dProc=="")))
	{
	
		if (!(Math.abs(oProc)+Math.abs(dProc)==Math.abs(tProc))) {NotAccurate = true;}
	}
	
	oProc = obj1["oChest"].value
	dProc = obj1["dChest"].value
	tProc = obj1["tChest"].value
	if ((!(oProc==""))||(!(dProc=="")))
	{
	
		if (!(Math.abs(oProc)+Math.abs(dProc)==Math.abs(tProc))) {NotAccurate = true;}
	}

	oProc = obj1["oCLine"].value
	dProc = obj1["dCLine"].value
	tProc = obj1["tCLine"].value
	if ((!(oProc==""))||(!(dProc=="")))
	{
	
		if (!(Math.abs(oProc)+Math.abs(dProc)==Math.abs(tProc))) {NotAccurate = true;}
	}
	oProc = obj1["oConSed"].value
	dProc = obj1["dConSed"].value
	tProc = obj1["tConSed"].value
	if ((!(oProc==""))||(!(dProc=="")))
	{
	
		if (!(Math.abs(oProc)+Math.abs(dProc)==Math.abs(tProc))) {NotAccurate = true;}
	}
	oProc = obj1["oIntub"].value
	dProc = obj1["dIntub"].value
	tProc = obj1["tIntub"].value
	if ((!(oProc==""))||(!(dProc=="")))
	{
	
		if (!(Math.abs(oProc)+Math.abs(dProc)==Math.abs(tProc))) {NotAccurate = true;}
	}
	oProc = obj1["oLumbar"].value
	dProc = obj1["dLumbar"].value
	tProc = obj1["tLumbar"].value
	if ((!(oProc==""))||(!(dProc=="")))
	{
	
		if (!(Math.abs(oProc)+Math.abs(dProc)==Math.abs(tProc))) {NotAccurate = true;}
	}
	oProc = obj1["oRMed"].value
	dProc = obj1["dRMed"].value
	tProc = obj1["tRMed"].value
	if ((!(oProc==""))||(!(dProc=="")))
	{
	
		if (!(Math.abs(oProc)+Math.abs(dProc)==Math.abs(tProc))) {NotAccurate = true;}
	}
	oProc = obj1["oRTrauma"].value
	dProc = obj1["dRTrauma"].value
	tProc = obj1["tRTrauma"].value
	if ((!(oProc==""))||(!(dProc=="")))
	{
	
		if (!(Math.abs(oProc)+Math.abs(dProc)==Math.abs(tProc))) {NotAccurate = true;}
	}
	if (NotAccurate==true)
	{
		return confirm("Some of the totals entered do not match the sum of the number observed and the number directed/performed.\nClick 'OK' to submit anyways or 'Cancel' to return to the page and adjust these numbers.")
	}
}