function attendingSwitcher(selection){
	if(selection == "1"){
		document.getElementById("numOfSemesters").style.display = "block";
	}
	if(selection == "0"){
		document.getElementById("numOfSemesters").style.display = "none";
	}
}

function currentlyEnrolledSwitcher(selection){
	if(selection == "1"){
		document.getElementById("enrolledCollegeNameContainer").style.display = "block";
	}
	if(selection == "0"){
		document.getElementById("enrolledCollegeNameContainer").style.display = "none";
		document.getElementById("enrolledCollegeName").value = ""
	}
}

function highSchoolSeniorSwitcher(selection){
	if(selection == "1"){
		document.getElementById("collegeNameContainer").style.display = "block";
		document.getElementById("currentlyEnrolledContainer").style.display = "none";
		document.getElementById("currentlyEnrolled0").checked = false
		document.getElementById("currentlyEnrolled1").checked = false		
	}
	if(selection == "0"){
		document.getElementById("collegeNameContainer").style.display = "none";
		document.getElementById("currentlyEnrolledContainer").style.display = "block";
		document.getElementById("collegeName").value = ""
		document.getElementById("acceptedToCollege0").checked = false
		document.getElementById("acceptedToCollege1").checked = false 
		document.getElementById("enrolledCollegeName").value = ""
	}
}
function nameOfCollegeSwitcher(selection) {
    if (selection == "1") {
        document.getElementById("nameOfCollege").style.display = "block";
    }
    if (selection == "0") {
        document.getElementById("nameOfCollege").style.display = "none";
        document.getElementById("collegeName").value = ""
    }
}

function howDidYouHearSwitcher(selection){
	document.getElementById("heardFromEmployer").style.display = "none";
	document.getElementById("heardFrom210").style.display = "none";
	document.getElementById("heardFromOther").style.display = "none";
	
	if(selection != ""){
		if(selection == "Employer"){
			document.getElementById("heardFromEmployer").style.display = "block";
		}
		if(selection == "Two Ten"){
			document.getElementById("heardFrom210").style.display = "block";
		}
		if(selection == "Other"){
			document.getElementById("heardFromOther").style.display = "block";
		}
	} 
}

function preliminaryAppFormCheck(thisForm){
	error = false
	errorMsg = ""
	
	//who is employed validation
	myOption = -1;
	for (i=thisForm.whoIsEmployed.length-1; i > -1; i--){
		if (thisForm.whoIsEmployed[i].checked) {
			myOption = i; i = -1;
		}
	}
	if (myOption == -1){
		error = true
		errorMsg += "Please indicate who is employed in the footwear, leather or allied industries.\n"
	}
	
	//name of footwear company validation
	if(thisForm.affFootwearCo.value == ""){
		error = true
		errorMsg += "Please provide the name of the footwear company you/your parent is affiliated with.\n"
	}
	
	//date of birth validation
	if(thisForm.DOB.value == ""){
		error = true
		errorMsg += "Please provide your Date of Birth.\n"
	}
	
	//date of birth formatting validation
	if(thisForm.DOB.value != ""){
		if(ValidateForm(thisForm.DOB.value) == false){
		    error = true
			errorMsg += "Please ensure that you have formatted your birthdate correctly.\n"	
		}
	}
	
	//citizen validation
	myOption = -1;
	for (i=thisForm.citizen.length-1; i > -1; i--){
		if (thisForm.citizen[i].checked) {
			myOption = i; i = -1;
		}
	}
	if (myOption == -1){
		error = true
		errorMsg += "Please indicate if you are/are not not a United States citizen/eligible non-citizen.\n"
	}
	
	//enrollment validation
	myOption = -1;
	for (i=thisForm.enroll.length-1; i > -1; i--){
		if (thisForm.enroll[i].checked) {
			myOption = i; i = -1;
		}
	}
	if (myOption == -1){
		error = true
		errorMsg += "Please indicate if you will/will not be enrolled for a two or four year undergraduate degree for the 2009-2010 academic year.\n"
	}
	
	//currently attending school validation
	//myOption = -1;
	//for (i=thisForm.attendingCollege.length-1; i > -1; i--){
	//	if (thisForm.attendingCollege[i].checked) {
	//		myOption = i; i = -1;
	//	}
	//}
	//if (myOption == -1){
	//	error = true
	//	errorMsg += "Please indicate if the student is/is not currently attending college.\n"
	//} 
	
	//number of semesters validation
	if(thisForm.enroll[0].checked == true){
		if(thisForm.numOfSemesters.value == ""){
			error = true
			errorMsg += "Please indicate how many semesters you will have completed by Spring 2009.\n"
		}
	}
	
	//how did you hear about scholarship program validation
	if(thisForm.howDidYouHear.value == ""){
		error = true
		errorMsg += "Please indicate how you first heard about the Two Ten Scholarship Program.\n"
	} else {
		if(thisForm.howDidYouHear.value == "Employer"){
			if(thisForm.heardFromEmployerSelect.value == ""){
				error = true
				errorMsg += "Please indicate how you heard about the Two Ten Scholarship Program from your Employer.\n"
			}
		}
		if(thisForm.howDidYouHear.value == "Two Ten"){
			if(thisForm.heardFrom210Select.value == ""){
				error = true
				errorMsg += "Please indicate how you heard about the Two Ten Scholarship Program from your Two Ten.\n"
			}
		}
		if(thisForm.howDidYouHear.value == "Other"){
			if(thisForm.heardFromOtherText.value == ""){
				error = true
				errorMsg += "Please indicate how you heard about the Two Ten Scholarship Program from another source.\n"
			}
		}
	}
		
	if (error){
		alert(errorMsg)
		return false
	} else {
		//return true
	}	
}

function ValidateForm(dateValue){
	var dt=dateValue;
	if (isDate(dt)==false){
		//dt.focus()
		return false
	}
	return true
}

var dtCh= "/";
var minYear=1900;
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("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 scholarshipAppFormCheck(thisForm){
//	error = false
//	errorMsg = ""
//	
//	//SSN validation
//	if(thisForm.SSN.value == ""){
//		error = true
//		errorMsg += "Please enter the last 4 digits of your Social Security Number.\n"
//	}				
//	//Sex validation
//	myOption = -1;
//	for (i=thisForm.sex.length-1; i > -1; i--){
//		if (thisForm.sex[i].checked) {
//			myOption = i; i = -1;
//		}
//	}
//	if (myOption == -1){
//		error = true
//		errorMsg += "Please indicate your sex.\n"
//	}				
//	//Home Phone validation
//	if(thisForm.homePhone.value == ""){
//		error = true
//		errorMsg += "Please enter your Home Telephone.\n"
//	}				
//	//City validation
//	if(thisForm.city.value == ""){
//		error = true
//		errorMsg += "Please enter your City.\n"
//	}	
//	//State validation
//	if(thisForm.state.value == ""){
//		error = true
//		errorMsg += "Please select your State.\n"
//	}	
//	//Zip Code validation
//	if(thisForm.state.value == ""){
//		error = true
//		errorMsg += "Please enter your Zip Code.\n"
//	}	
//	//Ever Applied validation
//	myOption = -1;
//	for (i=thisForm.everApplied.length-1; i > -1; i--){
//		if (thisForm.everApplied[i].checked) {
//			myOption = i; i = -1;
//		}
//	}
//	if (myOption == -1){
//		error = true
//		errorMsg += "Please indicate if you have ever applied for a Two Ten Scholarship.\n"
//	}		
//	//Awarded Scholarship/Honorary Award validation
//	myOption = -1;
//	for (i=thisForm.awarded.length-1; i > -1; i--){
//		if (thisForm.awarded[i].checked) {
//			myOption = i; i = -1;
//		}
//	}
//	if (myOption == -1){
//		error = true
//		errorMsg += "Please indicate if you have ever been awarded a Two Ten Scholarship or Honorary Award.\n"
//	}		
//	
//	if (error){
//		alert(errorMsg)
//		return false
//	} else {
//		return true
//	}	
//}
function isEmailValid(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }	
	 return true					
}
function loginFormCheck(thisForm){
	error = false
	errorMsg = ""		
	
	//email address/username validation
	if (!isEmailValid(thisForm.username.value)){
		error = true
		errorMsg += "Please enter a valid Email Address.\n"
	}
	
	//password validation
	if(thisForm.password.value == ""){
		error = true
		errorMsg += "Please enter your password.\n"
	} 
	
	if (error){
		alert(errorMsg)
		return false
	} 
	return true
}
function createAccountFormCheck(thisForm){
	error = false
	errorMsg = ""		
	
	//first name validation
	if(thisForm.fname.value == ""){
		error = true
		errorMsg += "Please provide your first name.\n"
	}
	
	//last name validation
	if(thisForm.lname.value == ""){
		error = true
		errorMsg += "Please provide your last name.\n"
	}
	
	//email address validation
	if (!isEmailValid(thisForm.email.value)){
		error = true
		errorMsg += "Please enter a valid Email Address.\n"
        }
        //re-type email validation
        if (thisForm.email.value != thisForm.email2.value) {
            error = true
            errorMsg += "Please ensure that you re-typed your email address correctly.\n"
        }
	
	//password validation
	if(thisForm.password.value == "" && thisForm.password2.value == ""){
		error = true
		errorMsg += "Please create a password.\n"
	} else{
		//re-type password validation
		if(thisForm.password.value != thisForm.password2.value){
			error = true
			errorMsg += "Please ensure that you re-typed your password correctly.\n"
		}
	}
	
	if (error){
		alert(errorMsg)
		return false
	} 
	return true
}
function forgotPasswordCheckForm(thisForm) {
    error = false
    errorMsg = ""

    //email address
    if (!isEmailValid(thisForm.username.value)) {
        error = true
        errorMsg += "Please provide a correctly formatted email address.\n"
    }

    if (error) {
        alert(errorMsg)
        return false
    } else {
        //return true
    }
}
