function clearClasses(locations, classes) {
	locations.selectedIndex = 0;
	classes.options.length = 0;
}

function changeSelection(r, locations, classes)
{
	// Radio button for June
	if(r[0].checked) {
		populateJuneClasses(locations, classes);
	}
	else {
		populateJulyClasses(locations, classes);
	}
 } // end changeSelection

function populateJuneClasses(locations, classes) {
	var locationlist = locations; 	
	var myselection = classes;
	myselection.options.length = 0;
	
	if (locationlist.options[locationlist.selectedIndex].value == "ADI") {
		populateJuneADIClasses(locations, classes);
	}
	else if(locationlist.options[locationlist.selectedIndex].value == "ROSE") {
		populateJuneRoseClasses(locations, classes);  
	}
	else if(locationlist.options[locationlist.selectedIndex].value == "CCB") {
		populateJuneCCBClasses(locations, classes);   
	}
	else if(locationlist.options[locationlist.selectedIndex].value == "VBALL") {
		populateJuneVBallRoomClasses(locations, classes);
	}
	else if(locationlist.options[locationlist.selectedIndex].value == "VTFIT") {
		populateJuneBallyClasses(locations, classes);
	}
} // end populateJuneClasses

function populateJulyClasses(locations, classes) {
	var locationlist = locations; 	
	var myselection = classes;
	myselection.options.length = 0;

	// Currently all classes are the same in June and July so use June functions
	// Except for CCB in July
	if (locationlist.options[locationlist.selectedIndex].value == "ADI") {
		populateJuneADIClasses(locations, classes);
	}
	else if(locationlist.options[locationlist.selectedIndex].value == "ROSE") {
		populateJuneRoseClasses(locations, classes);  
	}
	else if(locationlist.options[locationlist.selectedIndex].value == "CCB") {
		populateJulyCCBClasses(locations, classes);   
	}
	else if(locationlist.options[locationlist.selectedIndex].value == "VBALL") {
		populateJuneVBallRoomClasses(locations, classes);
	}
	else if(locationlist.options[locationlist.selectedIndex].value == "VTFIT") {
		populateJuneBallyClasses(locations, classes);
	}

} // end populateJulyClasses

function populateJuneADIClasses(locations, classes) {
	var locationlist = locations; 	
	var myselection = classes;

	myselection.options[myselection.options.length] = 
		new Option("Please select a class...");
		 
	myselection.options[myselection.options.length] = 
	 new Option("ADI MON 7:00PM SALSA, $52", "ADI MON 7:00PM SALSA, $52");
     	myselection.options[myselection.options.length] = 
	 new Option("ADI MON 8:00PM Argentine TANGO I, $52", "ADI MON 8:00PM Argentine TANGO I, $52");
     	myselection.options[myselection.options.length] = 
	 new Option("ADI TUES 7:00PM Smooth Ballroom WALTZ/FOX TROT, $52","ADI TUES 7:00PM Smooth Ballroom WALTZ/FOX TROT, $52");
     	myselection.options[myselection.options.length] = 
	 new Option("ADI TUES 8:00PM Latin Ballroom RUMBA/CHA CHA, $52", "ADI TUES 8:00PM Latin Ballroom RUMBA/CHA CHA, $52");
	myselection.options[myselection.options.length] = 
	 new Option("ADI WED 7:00PM Wedding Slow Dances, $52","ADI WED 7:00PM Wedding Slow Dances, $52");
     	myselection.options[myselection.options.length] = 
	 new Option("ADI WED 8:00PM SALSA, $52", "ADI WED 7:00PM SALSA, $52");
     	myselection.options[myselection.options.length] = 
	 new Option("ADI THURS 8:00PM  SALSA II, $52","ADI THURS 8:00PM  SALSA II, $52");
}

function populateJuneRoseClasses(locations, classes) {
	var locationlist = locations; 	
	var myselection = classes;

	myselection.options[myselection.options.length] = 
	  new Option("Please select a class...");
	myselection.options[myselection.options.length] = 
	  new Option("ROSE MON 8:30PM American Style Social Ballroom, $52","ROSE MON 8:30PM American Style Social Ballroom, $52");
	myselection.options[myselection.options.length] = 
	  new Option("ROSE TUES 8:30PM SALSA I, $52","ROSE TUES 8:30PM SALSA I, $52");
	myselection.options[myselection.options.length] = 
	  new Option("ROSE WED 8:30PM SALSA II, $52","ROSE WED 8:30PM  SALSA II, $52");	 
	myselection.options[myselection.options.length] = 
	  new Option("ROSE THURS 8:30PM SALSA III, $52","ROSE THURS 8:30PM  SALSA III, $52");
}

function populateJuneCCBClasses(locations, classes) {
	var locationlist = locations; 	
	var myselection = classes;

	myselection.options[myselection.options.length] = 
 	 new Option("Please select a class...");	 

	myselection.options[myselection.options.length] = 
 	  new Option("CCB SAT 3:00PM Wedding Slow Dances, $52","CCB SAT 3:00PM Wedding Slow Dances, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SAT 4:00PM Night Club Latin, $52","CCB SAT 4:00PM Night Club Latin, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SAT 5:00PM American Style Bronze WALTZ, $52","CCB SAT 5:00PM American Style Bronze WALTZ, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SAT 6:00PM American Style Bronze RUMBA, $52","CCB SAT 6:00PM American Style Bronze RUMBA, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SUN 12:00PM American Style Silver FOXTROT, $52","CCB SUN 12:00PM American Style Silver FOXTROT, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SUN 1:00PM American Style Silver CHA CHA, $52","CCB SUN 1:00PM American Style Silver CHA CHA, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB TUES 7:00PM Beginner Argentine Tango, $52","CCB TUES 7:00PM Beginner Argentine Tango, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB WED 7:00PM Adv Beginner Argentine Tango II, $52","CCB WED 7:00PM Adv Beginner Argentine Tango II, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB THURS 7:00PM Int Argentine Tango III, $52","CCB THURS 7:00PM Int Argentine Tango III, $52");
}

function populateJuneVBallRoomClasses(locations, classes) {
	var locationlist = locations; 	
	var myselection = classes;

	myselection.options[myselection.options.length] = 
	 new Option("Please select a class...");	 
	myselection.options[myselection.options.length] = 
	 new Option("VBALL WED 7:00PM Salsa Aerobics, $52","VBALL WED 7:00PM Salsa Aerobics, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VBALL WED 8:00PM Smooth Ballroom Wedding Dances WALTZ FOXTROT, $52","VBALL WED 8:00PM Smooth Ballroom Wedding Dances WALTZ FOXTROT, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VBALL WED 9:00PM Smooth Ballroom Latin Dances RUMBA CHA CHA, $52","VBALL WED 9:00PM Smooth Ballroom Latin Dances RUMBA CHA CHA, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VBALL WED 9:00PM Salsa, $52","VBALL WED 9:00PM Salsa, $52");
}

function populateJuneBallyClasses(locations, classes) {
	var locationlist = locations; 	
	var myselection = classes;

	myselection.options[myselection.options.length] = 
	 new Option("Please select a class...");	 
	myselection.options[myselection.options.length] = 
	 new Option("VTFIT MON 7:30PM Wedding Slow Dances, $52","VTFIT MON 7:30PM Wedding Slow Dances, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VTFIT MON 8:30PM Salsa III, $52","VTFIT MON 8:30PM Salsa III, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VTFIT TUES 8:00PM Salsa I, $52","VTFIT TUES 8:00PM Salsa I, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VTFIT TUES 9:00PM Salsa II, $52","VTFIT TUES 9:00PM Salsa II, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VTFIT THRUS 8:00PM Wedding Slow Dances, $52","VTFIT THURS 8:00PM Wedding Slow Dances, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VTFIT THURS 9:00PM Salsa I, $52","VTFIT THRUS 9:00PM Salsa I, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VTFIT FRI 7:30PM Smooth Ballroom Wedding Dances WALTZ FOXTROT, $52","VTFIT FRI 7:30PM Smooth Ballroom Wedding Dances WALTZ FOXTROT, $52");
	myselection.options[myselection.options.length] = 
	 new Option("VTFIT FRI 8:30PM Smooth Ballroom Latin Dances RUMBA CHA CHA, $52","VTFIT FRI 8:30PM Smooth Ballroom Latin Dances RUMBA CHA CHA, $52");
}


function populateJulyCCBClasses(locations, classes) {
	var locationlist = locations; 	
	var myselection = classes;

	myselection.options[myselection.options.length] = 
 	 new Option("Please select a class...");	 

	myselection.options[myselection.options.length] = 
 	  new Option("CCB SAT 3:00PM Wedding Slow Dances, $52","CCB SAT 3:00PM Wedding Slow Dances, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SAT 4:00PM Night Club Latin, $52","CCB SAT 4:00PM Night Club Latin, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SAT 5:00PM American Style Bronze WALTZ, $52","CCB SAT 5:00PM American Style Bronze WALTZ, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SAT 6:00PM American Style Bronze RUMBA, $52","CCB SAT 6:00PM American Style Bronze RUMBA, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SUN 12:30PM American Style Silver FOXTROT, $52","CCB SUN 12:30PM American Style Silver FOXTROT, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB SUN 12:30PM American Style Silver CHA CHA, $52","CCB SUN 12:30PM American Style Silver CHA CHA, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB TUES 7:00PM Beginner Argentine Tango, $52","CCB TUES 7:00PM Beginner Argentine Tango, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB WED 7:00PM Adv Beginner Argentine Tango II, $52","CCB WED 7:00PM Adv Beginner Argentine Tango II, $52");
	myselection.options[myselection.options.length] = 
 	  new Option("CCB THURS 7:00PM Int Argentine Tango III, $52","CCB THURS 7:00PM Int Argentine Tango III, $52");

}

function chgAddr()
{
    if(document.reginfo.checkbox.checked)
	{
	    document.reginfo.streetaddr2.value = document.reginfo.streetaddr.value;
	    document.reginfo.city2.value = document.reginfo.city.value;
	    document.reginfo.state2.value = document.reginfo.state.value;
	    document.reginfo.zipcode2.value = document.reginfo.zipcode.value;
	    document.reginfo.hphone2.value = document.reginfo.hphone.value;
    	document.reginfo.wphone2.focus();
	}
	else
	{
	    document.reginfo.streetaddr2.value = "";
	    document.reginfo.city2.value = "";
	    document.reginfo.state2.value = "";
	    document.reginfo.zipcode2.value = "";
		document.reginfo.hphone2.value = "";
    	document.reginfo.streetaddr2.focus();
	}
	
	return;
}

function leadhelp()
{
    alert("Traditionally, the man leads and the lady follows. We welcome everyone as a leader or a follower.");
} // end function

function updateTotal(inputvalue, inputvalueClass2)
{
	var multiplier = 0;

	// extract dollar value from end of inputvalue string
    var mynumexp = /\d+$/;
    var mytest = mynumexp.exec(inputvalue);
	var class2Selected = mynumexp.exec(inputvalueClass2);

	// check to see if we have a multiplier of 2 because we have a second person
    if((document.reginfo.fname2.value != "") && (document.reginfo.lname2.value != "")) {
		multiplier = 2;
	}
	else {
		multiplier = 1;
	}

	// if first person name blank, then no info yet.  make value = 0
	if((document.reginfo.fname.value == "") && (document.reginfo.lname.value == "")) {
		document.reginfo.amount.value = 0;
	}
	// we have people information entered so calculate a total
    else
    {
		if(class2Selected != null) {
			// give discount  
			// cases one person two classes and two people two classes
			// totals are $94 and $188
			var discount = 10;
			total = ((mytest * 2) * multiplier) - (discount * multiplier);
			document.reginfo.amount.value = total;
		}
		else {
			// cases one person one class and two people one class
			// totals are $52 and $104
			if(multiplier == "2") {
				document.reginfo.amount.value = (mytest * multiplier) - 10;
			}
			else {
				document.reginfo.amount.value = (mytest);
			}
		}
	}  // else we have people info
} // end update total

function verifyfields(form)
{
    var flag = 0;
    if(form.fname.value == "") 
    {
        alert("Please enter FIRST NAME");
		form.fname.focus();
        flag = 1; return;
    }
    if(form.lname.value == "") 
    {
        alert("Please enter LAST NAME");
		form.lname.focus();
        flag = 1; return;
    }
    if( (form.streetaddr.value == "") ||
		(form.city.value == "") || 
		(form.state.value == "") || 
		(form.zipcode.value == "") )
    {
		alert("Please complete all address information");
		form.streetaddr.focus();
		flag = 1;
        return;
	}
	if( (form.hphone.value == "") && (form.wphone.value == "") && (form.ophone.value == "") )
    {
		alert("Please enter at least one contact phone number");
		form.hphone.focus();
        flag = 1; return;
    }
	else if(form.leader.selectedIndex == 0) 
    {
        alert("Please select leader or follower.  Click on *need help* if you need assistance");
		flag = 1; return;
    }
    input = form.emailaddr.value;
    if(input == "")
    {
        alert("Please provide a valid email address");
		form.emailaddr.focus();
		flag = 1;
        return;
    }
    else if (input.indexOf("@")<3)
	{
		alert("I'm sorry. This email address seems wrong. Please"
				+" check the prefix and '@' sign.");
   		form.emailaddr.focus();
        flag = 1;
        return;
	}
	if (form.fname2.value != "") 
    {
	    if(form.lname2.value == "") 
 		{
			alert("Please enter LAST NAME for the 2nd person");
			form.lname2.focus();
			flag = 1; return;
	    }
		if( (form.hphone2.value == "") && (form.wphone2.value == "") && (form.ophone2.value == "") )
		{
			alert("Please enter at least one contact phone number for the 2nd person");
			form.hphone2.focus();
			flag = 1; return;
		}
        if( (form.streetaddr2.value == "") ||
            (form.city2.value == "") || 
            (form.state2.value == "") || 
            (form.zipcode2.value == "") )
        {
            alert("Please complete all address information for 2nd person");
			form.streetaddr2.focus();
            flag = 1;
            return;
        }
    input2 = form.emailaddr2.value;



    if(input2 == "")

    {

        alert("Please provide a valid email address for the 2nd person");

		form.emailaddr2.focus();

	flag = 1;

        return;

    }

 

    else if (input2.indexOf("@")<3)

	{

   alert("I'm sorry. The 2nd person email address seems wrong. Please"

   +" check the prefix and '@' sign.");

   		form.emailaddr2.focus();

        flag = 1;

        return;

   }

   

   //emailreg = /^[\w\.\-]{2,}\@[\w\-\.]{2,}\.[a-z]{2,3}$/i;

   

   //if (emailreg.exec(input2));

   // {

   //     alert("There seems to be an error in the 2nd person email address.  Please check it again for validity.");

	//	form.emailaddr2.focus();

	//flag = 1;

    //    return;

    //}

	//

    } // end if 2nd person

    if ( form.myselection.value == 0)

    {

        alert("Please select a location then a class for registration");

        form.mylocation.value = 0;

		flag = 1; return;

    }



    if ( form.myselection.value == null)

    {

        alert("Please select a location then a class for registration");

        form.mylocation.value = 0;

		flag = 1; return;

    }



    //updateTotal(form.myselection.value);

	

	if(form.amount.value == 0) 

    {

        alert("Please select a location first, then a class for registration");

		flag = 1; return;

    }



    //updateTotal(form.myselection.value);




    // Check for payment method



    if( (form.method.value == 0) )

    {

       alert("Please select a payment method");

      flag = 1;

      return;

    }

 

	

    if(flag == 0)

    {

       form.submit();

    }	

	

} // end function verifyfields





//	 else if(locationlist.options[locationlist.selectedIndex].value == "JOMBT") 

//	 {

//		 myselection.options.length = 0;

//	     newURL = "Registration for this class is online at Joy of Motion Dance Center.  Would you like to link there now?";

//		 if( confirm(newURL) )

//		     document.location.href = "jom.html";

//	 }

//	 	 else if(locationlist.options[locationlist.selectedIndex].value == "JOMDC") 

//	 {

//		 myselection.options.length = 0;

//	     newURL = "Registration for this class is online at Joy of Motion Dance Center.  Would you like to link there now?";

//		 if( confirm(newURL) )

//		     document.location.href = "jom.html";

//	 }




