/*----- Check if a string is only whitespace -----*/

function isBlankString(s){
	for (var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if ((c!= ' ') && (c != '\n') && (c != '\t') && (c != '\r')) return false;
	}
	return true;

}

/*----- Check to see if a field (other than radio) is empty -----*/

function isEmpty(theField) {
        if (
		  (theField.value == "")
		||(theField.value == null)
		||(isBlankString(theField.value))
	   ) 
		{ return true;} 
	else 
		{ return false; }
} 

/*----- Check to see if a radio group is empty -----*/

function isRadioEmpty(theField) {
	for (var i=0;i<theField.length;i++){
		if (theField[i].checked) {return false}
	}
	return true;		
}

/*----- Check to see if access type is student -----*/

function isStudentTypeSelected(theField) {
	if (theField[2].checked) 
		{return true}
	else
		{return false};		
}


/*----- Check fields in a form ---*/

function specialAccountCheck(thisForm) {

        var Empty=false; 
        var errstring="";

        if (isEmpty(thisForm.elements.name)) {
                errstring += "\n Name"; 
                Empty=true; 
        }
        if (isEmpty(thisForm.elements.email)) {
                errstring += "\n Email"; 
                Empty=true; 
        }
        if (isEmpty(thisForm.elements.phone)) {
                errstring += "\n Phone number"; 
                Empty=true; 
        }

	if(	((
        	thisForm.account1_type[2].checked ||
        	thisForm.account2_type[2].checked ||
        	thisForm.account3_type[2].checked ||
        	thisForm.account4_type[2].checked ||
        	thisForm.account5_type[2].checked ||
        	thisForm.account6_type[2].checked ||
        	thisForm.account7_type[2].checked ||
        	thisForm.account8_type[2].checked ||
        	thisForm.account9_type[2].checked ||
        	thisForm.account10_type[2].checked
	   	)||(
        	thisForm.account1_type[3].checked ||
        	thisForm.account2_type[3].checked ||
        	thisForm.account3_type[3].checked ||
        	thisForm.account4_type[3].checked ||
        	thisForm.account5_type[3].checked ||
        	thisForm.account6_type[3].checked ||
        	thisForm.account7_type[3].checked ||
        	thisForm.account8_type[3].checked ||
        	thisForm.account9_type[3].checked ||
        	thisForm.account10_type[3].checked
	   	))
		&& (isEmpty(thisForm.account_details) && isEmpty(thisForm.comments))
	  ){
                errstring += "\n\n \"Comments\/Questions?\" field is required "; 
                errstring +=   "\n when requesting a Student or Visitor Level account."; 
                Empty=true; 
           }


        if (Empty){
			var finalerrstring=""; 
			if (Empty) finalerrstring+="The following information is required:\n\n"+errstring+"\n\n";
            alert(finalerrstring); 
            return false; 
        } else { return true; } 
}
function requestCourseCheck(thisForm) {

        var Empty=false; 
        var errstring="";
		
        if (isEmpty(thisForm.elements.name)) {
                errstring += "\n name"; 
                Empty=true; 
        }
        if (isEmpty(thisForm.elements.email)) {
                errstring += "\n email"; 
                Empty=true; 
        }
        if (isEmpty(thisForm.elements.phone)) {
                errstring += "\n phone number"; 
                Empty=true; 
        }

		if ("blank" == thisForm.elements.semester.value){
                errstring += "\n semester"; 
                Empty=true; 
		}
        if (("other" == thisForm.elements.semester.value)
			 &&(isEmpty(thisForm.elements.comments))) {
                errstring += "\n\n If the semester is Unknown or Other,"; 
                errstring += "\n please explain in the Comments field."; 
                Empty=true; 
        }
        if (Empty){
			var finalerrstring=""; 
			if (Empty) finalerrstring+="The following information is required:\n\n"+errstring+"\n\n";
            alert(finalerrstring); 
            return false; 
        } else { return true; } 
}

function reuseCourseCheck(thisForm) {

        var Empty=false; 
        var errstring="";
		
        if (isEmpty(thisForm.elements.name)) {
                errstring += "\n name"; 
                Empty=true; 
        }
        if (isEmpty(thisForm.elements.email)) {
                errstring += "\n email"; 
                Empty=true; 
        }
        if (isEmpty(thisForm.elements.phone)) {
                errstring += "\n phone number"; 
                Empty=true; 
        }
		
		if ("blank" == thisForm.elements.semester.value){
                errstring += "\n semester"; 
                Empty=true; 
		}
		
        if (("other" == thisForm.elements.semester.value)
			 &&(isEmpty(thisForm.elements.comments))) {
                errstring += "\n\n If the semester is Unknown or Other,"; 
                errstring += "\n please explain in the Comments field."; 
                Empty=true; 
        }

        if (Empty){
			var finalerrstring=""; 
			if (Empty) finalerrstring+="The following information is required:\n\n"+errstring+"\n\n";
            alert(finalerrstring); 
            return false; 
        } else { return true; } 
}

function guestAccountCheck(thisForm) {

        var Empty=false;
        var errstring="";

        if (isEmpty(thisForm.elements.name)) {
                errstring += "\n name";
                Empty=true;
        }
        if (isEmpty(thisForm.elements.email)) {
                errstring += "\n email";
                Empty=true;
        }
        if (isEmpty(thisForm.elements.phone)) {
                errstring += "\n phone number";
                Empty=true;
        }

        if (Empty){
                        var finalerrstring="";
                        if (Empty) finalerrstring+="The following information is required:\n\n"+errstring+"\n\n";
            alert(finalerrstring);
            return false;
        } else { return true; }
}
function studentFeedbackCheck(thisForm) {

        var Empty=false;
        var errstring="";

        if (isEmpty(thisForm.elements.course)) {
                errstring += "\n course";
                Empty=true;
        }
        if (isEmpty(thisForm.elements.comments)) {
                errstring += "\n comments";
                Empty=true;
        }
        if (Empty){
                        var finalerrstring="";
                        if (Empty) finalerrstring+="The following information is required:\n\n"+errstring+"\n\n";
            alert(finalerrstring);
            return false;
        } else { return true; }
}

