function smallNewWindow(a) {
  if (window.popUp1 && window.popUp1.open && !window.popUp1.closed) {
    popUp1.location = a.href;
    popUp1.focus();

    }

   else {
    popUp1=window.open(a.href,
    '', 'width=370, height=350, resizable=yes, toolbar=no, menubar=no, location=no, scrollbars=yes')
    popUp1.focus();
    
    

  }

}

function photoWindow(a) {
    if (window.popUp2 && window.popUp2.open && !window.popUp2.closed) {
    popUp2.location = a.href;
    popUp2.focus();

    }

   else {
    popUp2=window.open(a.href,
    '', 'width=700, height=450, resizable=yes, toolbar=no, menubar=no, location=no, scrollbars=no')
    popUp2.focus();
    
    

  }

}


function longNewWindow(a) {
    if (window.popUp2 && window.popUp2.open && !window.popUp2.closed) {
    popUp1.location = a.href;
    popUp1.focus();

    }

   else {
    popUp2=window.open(a.href,
    '', 'width=150, height=450, resizable=yes, toolbar=no, menubar=no, location=no, scrollbars=yes')
    popUp2.focus();
    
    

  }

}

// created by Byungjae Kim for Dining Services Reservation Form Validation
// -----------------------------------------------------------------------

function checkFormWFC(theForm) 
{

 var why = "";

 // check school
 var checkvalue = 0;
 for (i=0, n=theForm.SCHOOL.length; i<n; i++) {
    if (theForm.SCHOOL[i].checked) {
       checkvalue = theForm.SCHOOL[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Enter your school.\n";
 }

 // check year
 var checkvalue = 0;
 for (i=0, n=theForm.YEAR.length; i<n; i++) {
    if (theForm.YEAR[i].checked) {
       var checkvalue = theForm.YEAR[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Enter your year.\n";
 }

 // check currently living in wien
 var checkvalue = 0;
 for (i=0, n=theForm.CURRENTLY_IN_WIEN.length; i<n; i++) {
    if (theForm.CURRENTLY_IN_WIEN[i].checked) {
       var checkvalue = theForm.CURRENTLY_IN_WIEN[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Specify whether or not you are currently living in Wien.\n";
 }
 else if ((checkvalue == "NO") && (theForm.WHERE_IF_NOT.value == "")) {
    why += "Specify where you are currently living.\n";
 } else if (( checkvalue == "YES") && (theForm.WHERE_IF_NOT.value != "")) {
    theForm.WHERE_IF_NOT.value = "";
 }
 
 // check frequency
 var checkvalue = 0;
 for (i=0, n=theForm.FREQUENCY_OF_VISIT.length; i<n; i++) {
    if (theForm.FREQUENCY_OF_VISIT[i].checked) {
       var checkvalue = theForm.FREQUENCY_OF_VISIT[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Please enter how often you visit the Wien Food Court.\n";
 }

 // check satisified_with_wfc
 var checkvalue = 0;
 for (i=0, n=theForm.SATISFIED_WITH_WFC.length; i<n; i++) {
    if (theForm.SATISFIED_WITH_WFC[i].checked) {
       var checkvalue = theForm.SATISFIED_WITH_WFC[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Enter whether or not you are satisfied with the Wien food court.\n";
 } else if ( theForm.REASONS_FOR_SATISFIED_WITH_WFC_ANSWER.value == "") {
    why += "Briefly describes your reasons whether or not you are satisfied.\n";
 }

 // check alternative option
 var checkvalue = 0;
 for (i=0, n=theForm.ALTERNATIVE_CHOICE.length; i<n; i++) {
    if (theForm.ALTERNATIVE_CHOICE[i].checked) {
       var checkvalue = theForm.ALTERNATIVE_CHOICE[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Specify your top choice of replacing the Wien food court.\n";
 }
 else if ((checkvalue == "OTHER") && (theForm.ALTERNATIVE_CHOICE_OTHER.value == "")) {
    why += "Specify your alternative option.\n";
 } else if (( checkvalue != "OTHER") && (theForm.ALTERNATIVE_CHOICE_OTHER.value != "")) {
    theForm.ALTERNATIVE_CHOICE_OTHER.value = "";
 }

 // check gym
 var checkvalue = 0;
 for (i=0, n=theForm.WOULD_USE_IT_IF_GYM.length; i<n; i++) {
    if (theForm.WOULD_USE_IT_IF_GYM[i].checked) {
       var checkvalue = theForm.WOULD_USE_IT_IF_GYM[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Mark whether or not you would use it if it were a gym.\n";
 }

 // check mini rest
 var checkvalue = 0;
 for (i=0, n=theForm.WOULD_USE_IT_IF_MINI_REST.length; i<n; i++) {
    if (theForm.WOULD_USE_IT_IF_MINI_REST[i].checked) {
       var checkvalue = theForm.WOULD_USE_IT_IF_MINI_REST[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Mark whether or not you would use it if it were a mini-restaurant.\n";
 }

 // check blue java
 var checkvalue = 0;
 for (i=0, n=theForm.WOULD_USE_IT_IF_BLUE_JAVA.length; i<n; i++) {
    if (theForm.WOULD_USE_IT_IF_BLUE_JAVA[i].checked) {
       var checkvalue = theForm.WOULD_USE_IT_IF_BLUE_JAVA[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Mark whether or not you would use it if it were a Blua Java.\n";
 }

 // check blue your choice
 var checkvalue = 0;
 for (i=0, n=theForm.WOULD_USE_IT_IF_YOUR_CHOICE.length; i<n; i++) {
    if (theForm.WOULD_USE_IT_IF_YOUR_CHOICE[i].checked) {
       var checkvalue = theForm.WOULD_USE_IT_IF_YOUR_CHOICE[i].value;
       break;
    } 
 }
 if (checkvalue == 0) {
    why += "Mark whether or not you would use it if it were your choice specified above.\n";
 }


 // check to see if error occurred.
 if (why != "") {
    alert(why);
    return false;
 }
 theForm.submit();
}

function checkFormCCSC(theForm) {
var why = "";
    why += checkUni(theForm.uni.value);
    why += checkName(theForm.name.value);
    why += checkMealPlan(theForm.mealplan.selectedIndex);
    
    if (why != "") {
       alert(why);
       return false;
    }
    theForm.submit();
}

function checkFormFBC(theForm) {
    var why = "";
    why += checkUni(theForm.uni.value);
    why += checkName(theForm.name1.value);
    why += checkPhone(theForm.phone.value);
    why += checkEmail(theForm.rmail.value);
    why += checkEventDate(theForm.eventDate.selectedIndex);
    
    // Remove the comment lines if there are two seatings
 
    // for (i=0, n=theForm.seating.length; i<n; i++) {
    //    if (theForm.seating[i].checked) {
    //        var checkvalue = theForm.seating[i].value;
    //        break;
    //    } 
    //}
    // why += checkRadio(checkvalue);

    why += checkPartyNames(theForm.party.value, theForm.name2.value, theForm.name3.value, theForm.name4.value);
    
    if (why != "") {
       alert(why);
       return false;
    }
    theForm.submit();
}

function checkFormJJ(theForm) {
    var why2 = "";
    why2 += checkUni(theForm.uni.value);
    why2 += checkName(theForm.name1.value);
    why2 += checkEventDate(theForm.eventDate.selectedIndex);
    
    // Remove the comment lines if there are two seatings
 
    //for (i=0, n=theForm.seating.length; i<n; i++) {
    //    if (theForm.seating[i].checked) {
    //        var checkvalue = theForm.seating[i].value;
    //        break;
    //    } 
    //}
    //why2 += checkRadio(checkvalue);

    why2 += checkPartyNames(theForm.party.value, theForm.name2.value, theForm.name3.value, theForm.name4.value, theForm.name5.value, theForm.name6.value, theForm.name7.value, theForm.name8.value);
    
    if (why2 != "") {
       alert(why2);
       return false;
    }
    theForm.submit();
}


function checkUni (strng) {
    var error = "";
    if (strng == "") {
       error = "UNI: Enter an valid UNI.\n";
    }
    var illegalChars = /[\W_]/;  // allow letters and numbers only
    if ((strng.length < 2) || (strng.length > 10)) {
       error = "UNI: Enter your UNI.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "UNI: Enter your UNI.\n";
    } 
return error;
} 

function checkEmail (strng) {
    var error="";
    if (strng == "") {
       error = "EMail: Enter an valid email.\n";
    }
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Email: Enter your email.\n";
    }
    else {
       var illegalChars= /[\ \(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "Email: Enter your email\n";
       }
    }
    return error;    
}

function checkPhone (strng) {
    var error = "";
    if (strng == "") {
       error = "Phone: Enter your valid campus ext.\n";
    }

    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "Phone: Enter your campus ext.\n";
    }
    if (!(stripped.length == 5)) {
	error = "Phone: Enter your campus ext.\n";
    } 
    return error;
}

function checkName (strng) {
    var error = "";
    if (strng == "") {
       error = "Name: Enter your name.\n";
    }
    return error;
}

function checkEventDate(choice) {
    var error = "";
    if (choice == 0) {
       error = "Date: Pick a date.\n";
    }    
    return error;
}

function checkMealPlan(choice) {
    var error = "";
    if (choice == 0) {
       error = "Meal Plan: Select your meal plan.\n";
    }    
    return error;
}

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Seating: Pick a seating.\n";
    }
return error;    
}


function checkPartyNames(strng1, strng2, strng3, strng4, strng5, strng6, strng7, strng8) {
    
	var error = "";
	if (strng1 == 0) {
	   error = "Party: Select a number of people.\n"
	}

	if ( (strng1 == 2 ) && ( (strng2 == "") ) ) {
	   error = "Names of People: Enter names for your party.\n";
	}
	if ( (strng1 == 3 ) && ( (strng2 == "") || (strng3 == "") ) ) {
	   error = "Names of People: Enter names for your party.\n";
	}
  
	if ( (strng1 == 4 ) && ( (strng2 == "") || (strng3 == "") || (strng4 == "") ) ) {
	   error = "Names of People: Enter names for your party.\n";
	}

	if ( (strng1 == 5 ) && ( (strng2 == "") || (strng3 == "") || (strng4 == "") || (strng5 == "") ) ) {
	   error = "Names of People: Enter names for your party.\n";
	}

	if ( (strng1 == 6 ) && ( (strng2 == "") || (strng3 == "") || (strng4 == "") || (strng5 == "") || (strng6 == "") ) ) {
	   error = "Names of People: Enter names for your party.\n";
	}

	if ( (strng1 == 7 ) && ( (strng2 == "") || (strng3 == "") || (strng4 == "") || (strng5 == "") || (strng6 == "") || (strng7 == "") ) ) {
	   error = "Names of People: Enter names for your party.\n";
	}

	if ( (strng1 == 8 ) && ( (strng2 == "") || (strng3 == "") || (strng4 == "") || (strng5 == "") || (strng6 == "") || (strng7 == "") || (strng8 == "")) ) {
	   error = "Names of People: Enter names for your party.\n";
	}
	return error;
}

// --------------------------------------------------------------------------