//Updated 8/27/09




//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called from: Page 1 Next button
function page1fun() {
var p=document.form1;

//1. Validate the Contact Info section
//If there is a problem, the function returns false, otherwise, if all is okay, it returns true
if (p.nm.value == "") {	alert("Please enter something in the \"Name\" field.");
	p.nm.focus(); return (false);}
//Two email fields, one to enter and one to confirm
if (p.em1.value != p.em2.value) { alert("Oops, the email addresses do not match."); 
	p.em2.focus();   return (false); }
if (isEmail(p.em1.value) == false) { alert("Please enter a valid email address.");
	p.em1.focus();   return (false); }
if (p.ph.value == "") {	alert("Please enter something in the \"Phone\" field.");
	p.ph.focus();	return (false); }
if (p.ad.value == "") {	alert("Please enter something in the \"Shipping Address\" field.");
	p.ad.focus();	return (false); }
if (p.ci.value == "") {	alert("Please enter something in the \"City\" field.");
	p.ci.focus();	return (false); }
if (p.st.value == "") {	alert("Please enter something in the \"State/Province\" field.");
	p.st.focus();	return (false); }
if (p.co.value == "") {	alert("Please enter something in the \"Country\" field.");
	p.co.focus();	return (false); }


//Put the contact info inputs into the textfields on Verify page
p.putnm.value=p.nm.value; 
p.putem.value=p.em1.value;
p.putph.value=p.ph.value;
p.putad.value=p.ad.value;
p.putci.value=p.ci.value; 
p.putst.value=p.st.value;
p.putzi.value=p.zi.value;
p.putco.value=p.co.value; 


//Disable on hold or full workshops as needed
//FOLLOWERS FOLLOWERS FOLLOWERS FOLLOWERS FOLLOWERS FOLLOWERS FOLLOWERS
//Friday
enabler('w1b',false);//Impulse and Circulatiry. 
//enabler('w2d',false);//Paradas and Pasadas. 
enabler('w3b',false);//Ganchos for Men and Women. 
//enabler('w4d',false);//Elegant Turns with Entradas. 
enabler('w5b',false);//Walking in an Embrace. 
//enabler('w6d',false);//Combinations of Sacadas and Rebotes. 
enabler('w7b',false);//Colgadas. 
//Saturday
//enabler('w9d',false);//Follower's Technique: Working the Free Leg. 
//enabler('w10b',false);//Improvisation with Ochos and Linear Turns. 
//enabler('w11d',false);//Flexibility of the Embrace. 
enabler('w12b',false);//Particular Musicality: Dancing the Unique Qualities of a Tango. 
enabler('w13d',false);//Interesting Volcadas. 
//Sunday
enabler('w14b',false);//Structure and Combinations of Boleos. 
//enabler('w15d',false);//Tango con Sabor . 
enabler('w16b',false);//Tango Milonguero: Dancing like in Buenos Aires . 
//enabler('w17b',false);//How to Move in Limited Spaces. 
//enabler('w18b',false);//Changes of Embrace. 
enabler('w19d',false);//Milonga con Traspie . 
enabler('w20d',false);//Combinations of Colgadas and Ganchos. 

//LEADERS LEADERS LEADERS LEADERS LEADERS LEADERS LEADERS LEADERS 
//Friday
//enabler('w1a',false);//Impulse and Circulatiry. 
//enabler('w2c',false);//Paradas and Pasadas. 
//enabler('w3a',false);//Ganchos for Men and Women. 
//enabler('w4c',false);//Elegant Turns with Entradas. 
//enabler('w5a',false);//Walking in an Embrace. 
//enabler('w6c',false);//Combinations of Sacadas and Rebotes. 
//enabler('w7a',false);//Colgadas. 
//Saturday
enabler('w8a',false);//Leader's Technique. 
//enabler('w10a',false);//Improvisation with Ochos and Linear Turns. 
//enabler('w11c',false);//Flexibility of the Embrace. 
//enabler('w12a',false);//Particular Musicality: Dancing the Unique Qualities of a Tango. 
enabler('w13c',false);//Interesting Volcadas. 
//Sunday
//enabler('w14a',false);//Structure and Combinations of Boleos. 
//enabler('w15c',false);//Tango con Sabor . 
enabler('w16a',false);//Tango Milonguero: Dancing like in Buenos Aires . 
enabler('w17a',false);//How to Move in Limited Spaces. 
//enabler('w18a',false);//Changes of Embrace. 
//enabler('w19c',false);//Milonga con Traspie . 
enabler('w20c',false);//Combinations of Colgadas and Ganchos. 

//choose next page div to display
showLayer('page6');


return (true); //if no validation problems, we make it to here
}//end of function page1fun







//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called from: Dance Package radio buttons on Page 2
function packHit(id) {
var p=document.form1;

//Disable or enable the lecture RSVP checkboxes
if (id=='ffpass225' || id=='ffpass285') {//one of the SFPs just got selected,
	enabler('lecture1',true);//so enable the lecture checkboxes 
	enabler('lecture2',true);
} else {//SDP or "no package" just got checked
	enabler('lecture1',false);//disable and clear the raffle radios
	enabler('lecture2',false);
	p.chlect1.checked=false;
	p.chlect2.checked=false;
}
}//end packHit








//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called from: Back and Next buttons on Page 2
function page2fun(na) {//NAme of button pressed: back2 if going BACK to page1, next2 if going NEXT to page 3
var p=document.form1;

//Disable and clear discount checkboxes if they select the SFP225
if (p.radpack[0].checked) {//SFP225 is checked
	p.chstud.disabled=true; p.chstud.checked=false;
	p.chbts.disabled=true; p.chbts.checked=false;
	showRow(1,"discmess");
	//p.vc.disabled=true; p.vc.value="";
} else { //SFP285, SDP or No Packages is checked
	p.chstud.disabled=false;
	p.chbts.disabled=false;
	showRow(0,"discmess");
	//p.vc.disabled=false;
}

//Put lecture selection on Verify page
showRow(0,"millecA"); //initialize off
showRow(0,"millecB"); 
showRow(0,"millecC");
if (p.chlect1.checked==true && p.chlect2.checked==false) { //Friday's lecture checked, Saturday's blank
	showRow(1,"millecA");}
else if (p.chlect1.checked==false && p.chlect2.checked==true) { //Friday's lecture blank, Saturday's checked
	showRow(1,"millecB");}
else if (p.chlect1.checked==true && p.chlect2.checked==true) { //Friday's lecture checked, Saturday's checked
	showRow(1,"millecC");}

//Needs to be called to show (or hide) the You Chose rows under the workshop page
//Pretty important to do this before displaying the workshop page
updateShops('Afr1');

//This handles the show rows for the workshop page, the milonga page and the Verify page, then it calculates the milonga subtotal.
updateMilonga();

//Display the appropriate next page. Depends on whether NA is back2 or next2. That's it. 
if (na == 'next2') {
	//showLayer('page3'); //skip to workshop page 3
	//comment out the above after workshops no longer available, use this instead
	showLayer('page4'); //skip past workshop page to milonga page 4
	} else {
	showLayer('page1'); //go back to page 1
}

//In Opera, clicking Next on page two cause Verify Name Email to skew to the right, that's bad
}//end page2fun




	//////////////////////////////////////////////////////
	//////////////////////////////////////////////////////
	//////////////////////////////////////////////////////
	//Called from: page2fun, and milonga checkboxes on Page 4
	function updateMilonga() {
	var p=document.form1;
	//The first milonga checkbox (Thursday) is named "thu1". Use findElem to find it's number.
	var fm = findElem(p.thu1.name);
	var nummils = 7;
	//1. Show/Hide appropriate 'You Chose:' rows for A la Carte, SDP or SFP
	if (p.radpack[0].checked || p.radpack[1].checked) { //Springstep Festival Pass
		//Page 3 after workshops
		showRow(0,"shopala1"); showRow(1,"shopsfp1"); 
		showRow(1,"shopnum1"); showRow(0,"shopcost1"); showRow(0,"shopsub1"); 
		//Page 4 after milongas
		showRow(0,"milala1"); showRow(0,"milsdp1"); 
		showRow(1,"milsfp1"); showRow(0,"milsub1"); 
		//Page 7 Verify page
		showRow(0,"shopala2"); showRow(1,"shopsfp2");
		showRow(1,"shopnum2"); showRow(0,"shopcost2"); showRow(0,"shopsub2");
		showRow(0,"milala2"); showRow(0,"milsdp2"); 
		showRow(1,"milsfp2"); showRow(0,"milsub2"); 
		//check all of the milonga checkboxes on page 4. 
		//If they try to deselect one, it calls updateMilonga() which reselects it
		for (var yu=fm; yu<fm+nummils; yu ++) { 
			p.elements[yu].checked = true; 
		} 
	} else if (p.radpack[2].checked) { //Springstep Dance Pass, show some rows, hide others
		//xshopala1 and xshopala2 means first time and second time
		//Page 3 after workshops
		showRow(1,"shopala1"); showRow(0,"shopsfp1");
		showRow(1,"shopnum1"); showRow(1,"shopcost1"); showRow(1,"shopsub1");
		//Page 4 after milongas
		showRow(0,"milala1"); showRow(1,"milsdp1"); 
		showRow(0,"milsfp1"); showRow(1,"milsub1"); 
		//Page 7 Verify page
		showRow(1,"shopala2"); showRow(0,"shopsfp2");
		showRow(1,"shopnum2"); showRow(1,"shopcost2"); showRow(1,"shopsub2");
		showRow(0,"milala2"); showRow(1,"milsdp2"); 
		showRow(0,"milsfp2"); showRow(1,"milsub2"); 
		//check all of the milonga checkboxes on page 4. 
		//If they try to deselect one, it calls updateMilonga() which reselects it
		for (var yu=fm; yu<fm+nummils; yu ++) {
			p.elements[yu].checked = true; 
		}
	} else { //no SDP; no SFP, must be a la carte ("No Package")
		//Page 3 after workshops
		showRow(1,"shopala1"); showRow(0,"shopsfp1");
		showRow(1,"shopnum1"); showRow(1,"shopcost1"); showRow(1,"shopsub1");
		//Page 4 after milongas
		showRow(1,"milala1"); showRow(0,"milsdp1"); 
		showRow(0,"milsfp1"); showRow(1,"milsub1"); 
		//Page 7 Verify page
		showRow(1,"shopala2"); showRow(0,"shopsfp2");
		showRow(1,"shopnum2"); showRow(1,"shopcost2"); showRow(1,"shopsub2");
		showRow(1,"milala2"); showRow(0,"milsdp2"); 
		showRow(0,"milsfp2"); showRow(1,"milsub2"); 
		//reenable all of the checkboxes
		//for (var yu=fm; yu<fm+nummils; yu ++) {
			//p.elements[yu].disabled = false;
		//}
	}
	
	//2. Show/hide the milongas on Verify page under "You chose these milongas"
	for (var yu=fm; yu<fm+nummils; yu ++) { //start the adding procedure (while loop)
		if (p.elements[yu].checked) { //decide if each box is checked, and if it is
			showRow(1,p.elements[yu].id); //show that milonga row
		} else {//if the box is not checked
			showRow(0,p.elements[yu].id); 
		}
	}//end of for
	
	//3. Any milongas chosen at all? 
	//Loop through the milonga checkboxes to see if one is checked
	for (var yu=fm; yu<fm+nummils; yu ++) {
		if (p.elements[yu].checked == true) {
			//alert("Got a Milonga. Element: " + yu);
			showRow(1,"chosemil");
			break;
		} else {
			//alert("Milonga. Element " + yu + " is blank");
			showRow(0,"chosemil");
		}
	}
	
	//4. Calculate the milonga subtotal 
	var mil_tot=0; //initialize
	var mil_totA=0;
	// No matter what, ALWAYS count up the a la carte price anyway. 
	if (p.thu1.checked) {mil_totA += 15; }//add the value to the total
	if (p.fri1.checked) {mil_totA += 10; }//add the value to the total
	if (p.fri2.checked) {mil_totA += 25; }//add the value to the total
	if (p.sat1.checked) {mil_totA += 15; }//add the value to the total
	if (p.sat2.checked) {mil_totA += 35; }//add the value to the total
	if (p.sun1.checked) {mil_totA += 10; }//add the value to the total
	if (p.sun2.checked) {mil_totA += 25; }//add the value to the total
	//Decide if the price should be overruled by a package price 
	if (document.getElementById("ffpass285").checked) {
		mil_tot=285;
	} else if (document.getElementById("ffpass225").checked) {
		mil_tot=225;
	} else if (document.getElementById("dancepass").checked) {
		mil_tot=115;
	} else {// a la carte must be checked!
		mil_tot=mil_totA;
	}
	//alert("The milonga subtotal is: " + mil_tot);
	mil_tot = mil_tot + ""; //was a number, now it's a string
	var mil_tot_str = mil_tot + ((mil_tot.indexOf('.') == -1) ? ".00" : ""); //adds .00 to the amount string
	p.milsub1.value = mil_tot_str; //puts the total in the total box
	p.milsub2.value = mil_tot_str; //puts the total in the total box
	} //end of function updateMilonga
	
	
	
		//////////////////////////////////////////////////////
		//////////////////////////////////////////////////////
		//////////////////////////////////////////////////////
		//Called from: updateMilonga
		function findElem(whichone) {
		var p=document.form1;
		var elnum = 0;
		//alert(whichone); //comment or uncomment this line as desired
		for (var i=0; i<p.elements.length; i++){//start of for
			if (p.elements[i] == p.elements[whichone]) 
				{elnum = i;}	}//end of for
		//alert("The element number \n for the box you just clicked \n is " + elnum + "."); //comment or uncomment this line as desired
		return(elnum);
		}//end findElem






//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called from: page2fun, from Workshop checkboxes on page 3
function updateShops(box) {
var p=document.form1;
//1. Radio behavior for workshop checkboxes
//Find the first letter and the rest of the letters of the name of the box that got clicked
var lett=box.charAt(0); //eg. "A" from "Asa12"
var day=box.substring(1,3); //substring(start,stop-don't-include) eg. "sa"
var num=parseInt(box.substring(3,box.length));//eg. 12
//Find the letters of the other checkboxes
if (lett=="A") {other="B"; other2="C"; other3="D"; } 
else if (lett=="B") {other="A"; other2="C"; other3="D";}
else if (lett=="C") {other="D"; other2="A"; other3="B";} 
else {other="C"; other2="A"; other3="B";}
//Form the other names eg. "B" + "fr1"
if (lett=="A" || lett=="B") {
	box2 = other + day + num;
	box3 = other2 + day + (num+1);
	box4 = other3 + day + (num+1);
} 
if (lett=="C" || lett=="D") {
	box2 = other + day + num;
	box3 = other2 + day + (num-1);
	box4 = other3 + day + (num-1);
}
//Uncheck the others if they were checked, otherwise don't
if (p.elements[box].checked) { //if checked (cuz if not check then do nothing)...
	if (p.elements[box2]) { if (p.elements[box2].checked) {p.elements[box2].checked=false; } }
	if (p.elements[box3]) {	if (p.elements[box3].checked) {p.elements[box3].checked=false; } }
	if (p.elements[box4]) {	if (p.elements[box4].checked) {p.elements[box4].checked=false; } }
}

//2. Make sure they don't select more than 10 workshops
//An array with the ids of all the possible workshop checkboxes (minus the w for shortness)
var allshops = ['1a','1b','2c','2d','3a','3b','4c','4d','5a','5b','6c','6d','7a','7b',
				 '8a','9d','10a','10b','11c','11d','12a','12b','13c','13d',
				 '14a','14b','15c','15d','16a','16b','17a','17b','18a','18b','19c','19d','20c','20d'];
var selshops = []; //An array that holds only the ones they selected
var inc = 0; //a counter
for(i=0; i<allshops.length; i++) {
	var test = "w" + allshops[i]; //add back the w
	if (document.getElementById(test).checked) {
		selshops[inc]=test; //add each checked box to the array of SELected workSHOPS
		inc=inc+1; 	} 
}
var nshops = selshops.length; //NUMBER of shops
if ((nshops > 10) && (p.radpack[0].checked || p.radpack[1].checked)) {
	alert("The Full Festival Pass includes up to 10 workshops (you've already selected 10).");			 
	p.elements[box].checked=false; //blank the one that just got checked
	selshops.pop(); //remove the last value
	nshops=nshops-1;
}

//Enable 'terms and conditions' checkbox if there is at least one shop selected, else clear and disable it
if (nshops > 0) {
	p.chagree.disabled = false;
} else { 
	p.chagree.checked = false; p.chagree.disabled = true;
}

//3. Deal with Advanced workshop partner fields
//An array with the nums of the advanced partner text input fields
var advfield = ['2','4','6','11','13','15','20'];
for(i=0; i<advfield.length; i++) {
	var currC = "w" + advfield[i] + "c"; //this works as long as all advanced shops get C and D endings
	var currD = "w" + advfield[i] + "d";
	var pfield = "w" + advfield[i] + "partner"; //construct the name text using shop number
	if (document.getElementById(currC).checked || document.getElementById(currD).checked) { //if either adv box is selected
		p.elements[pfield].disabled=false; //enable partner field
		if (p.elements[pfield].value=="") { //if partner field is blank
			p.elements[pfield].style.backgroundColor = '#FF3'; //highlight partner field with yellow background
		} else {
			p.elements[pfield].style.backgroundColor = '#FFF'; //highlight partner field with yellow background
		}
	} else {
		p.elements[pfield].disabled=true; p.elements[pfield].value=""; //else disable and clear partner field
		p.elements[pfield].style.backgroundColor = '#CCC'; //reset background
		//alert(p.elements[pfield].style.backgroundColor.value);
	}
}


//4. Calculate and display subtotal
p.putnum1.value=nshops; 
p.putnum2.value=nshops; //display the number of shops
costea=25; //2008 cost per workshop
var subtot = nshops * costea; //calculate subtotal

//Springstep Festival Pass overrides cost each and subtotal
if (p.radpack[0].checked) {costea=0; subtot=225;}
if (p.radpack[1].checked) {costea=0; subtot=285;}
//otherwise display calculated costeach and subtotal
p.putwper1.value=costea + ".00";
p.putwper2.value=costea + ".00";
p.putwsub1.value=subtot + ".00";
p.putwsub2.value=subtot + ".00";

}//end updateShops





//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called From: Workshop Page 3 Next button
function page3fun() {
var p=document.form1;
updateShops('Afr1'); //Call it one last time to get any last changes onto the Verify page

//1. Display the shops they chose and their partners for each shop
//An array with the ids of all the possible workshop checkboxes (minus the w for shortness)
var allshops = ['1a','1b','2c','2d','3a','3b','4c','4d','5a','5b','6c','6d','7a','7b',
				 '8a','9d','10a','10b','11c','11d','12a','12b','13c','13d',
				 '14a','14b','15c','15d','16a','16b','17a','17b','18a','18b','19c','19d','20c','20d'];
//Hide all the workshop rows and headers first, to start fresh
for (i=0; i<allshops.length; i++) {
	if (allshops[i].length==2) {var wn = allshops[i].charAt(0);	} 
	else { var wn = allshops[i].substring(0,2);}
	var test = "w" + wn; //add back the w
	showRow(0,test); //hide each workshop row first
}
showRow(0,"fri"); showRow(0,"fri2"); showRow(0,"sat"); showRow(0,"sat2"); //hide headers
showRow(0,"sun"); p.isafri.value=""; p.isasat.value=""; p.isasun.value=""; //clear hidden fields

//Make an array of the workshops they selected
var selshops = []; 
var inc = 0; //a counter
for(i=0; i<allshops.length; i++) {
	var test = "w" + allshops[i]; //add back the w
	if (document.getElementById(test).checked) {//add each checked box to the array of SELected workSHOPS
		selshops[inc]=test; inc=inc+1; 	} 
}
var nshops = selshops.length; //NUMBER of shops

//For each day with a workshop, display the appropriate header and spacer
//GO THROUGH EACH WORKSHOP THAT IS SELECTED
for (i=0; i<selshops.length; i++) {
	//Pull out the Workshop Number (wn), either 1 or 2 digit
	//Also pull out the LEtter
	if (selshops[i].length==3) {//it's 3, ie, w3d
		var wn = selshops[i].charAt(1);
		var le = selshops[i].charAt(2);
	} else { //it's 4
		var wn = selshops[i].substring(1,3);
		var le = selshops[i].charAt(3);
	}
	//While we're in here, display the rows for the chosen workshops
	var theid = "w" + wn;
	showRow(1,theid); //show it
	
	//Display the dance role 
	var roleid = "role" + wn;
	if ((le=="a") || (le=="c")) {
		document.getElementById(roleid).innerHTML = "Lead";
	} else {
		document.getElementById(roleid).innerHTML = "Follow";
	}
	
	//Display the partner names on the Verify page
	var pnameid = "pname" + wn; //ids of verify partner tds
	var partinput = "w" + wn + "partner"; //names of partner fields on workshop form
	var pni = document.getElementById(pnameid);
	if (p.elements[partinput]) { //IF this partner textfield exists...
			if (pni) { pni.innerHTML = p.elements[partinput].value;  }
			if (p.elements[partinput].value=="") { pni.innerHTML = 'Assigned Partner'; 
			} else { pni.innerHTML = p.elements[partinput].value;  }
	} 
	
	//Show the header for the days that have at least one workshop chosen
	//THURSDAY: Thursday rows don't get shown
	var wni = parseInt(wn); //convert the string into an integer
	if (wni <= 7) {//FRIDAY (//fri2 is the spacer <tr>)
		showRow(1,"fri"); showRow(1,"fri2"); p.isafri.value="Friday";
	} else if ((wni >= 8) && (wni <= 13)) {//SATURDAY
		showRow(1,"sat"); showRow(1,"sat2"); p.isasat.value="Saturday";
	} else {//SUNDAY
		showRow(1,"sun"); p.isasun.value="Sunday";
	}
}//end of for (i=0; i<selshops.length; i++)


//4. Any workshops chosen at all?
showRow(0,"choseshop"); //initialize
if (selshops.length==0) {
	showRow(0,"choseshop"); //don't display "you chose..."
	//showRow(0,"shopnote"); //do display "you chose..."
} else {
	showRow(1,"choseshop"); //do display "you chose..."
	//showRow(1,"shopnote"); //do display "you chose..."
}

//Check to see if they have a partner for every advanced class and they have agreed to the terms
if (okay2cont()) {
showLayer('page4');//Go to next page
}

} // end page3fun




	//////////////////////////////////////////////////////
	//////////////////////////////////////////////////////
	//////////////////////////////////////////////////////
	//Called from page3fun
	function okay2cont() {
	var p=document.form1;
	//Prevent them from going to the next page until all enabled partner fields are filled out
	//An array with the nums of the advanced partner text input fields
	var advfield = ['2','4','6','11','13','15','20'];
	for(i=0; i<advfield.length; i++) {
		var pfield = "w" + advfield[i] + "partner"; //construct the name text using shop number
		if (p.elements[pfield].disabled==false && p.elements[pfield].value=="") {
			alert("You must name a partner for every advanced workshop you select.");
			p.elements[pfield].focus(); 
			return (false);
		}
	}
	
	//Prevent from continuing if the 'terms and conditions' checkbox is enabled but not checked
	if (p.chagree.disabled == false && p.chagree.checked == false) {
		alert("You must indicate that you have read the Workshop Level descriptions.");
		p.chagree.focus(); 
		return (false);
	}

	return (true); //if no errors, we make it to here
	}





//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called From: Page 5 Discount checkboxes
function discountFun() {
var p=document.form1;

var disc=0; 
var vol=0;
var oth=0;
var rebaja=0;
var ocodecheck = "valid";
if (p.chstud.checked) {disc += .25;}
if (p.chbts.checked) {disc += .1;} 
var priceala = [15,10,25,15,35,10,25];
var sfpcurr1 = 225;
var sfpcurr2 = 285;
var sdpcurr = 115; 
var shopcurr = 25;

//Recalculate their A La Carte total
var SDPvalue = sumArr(priceala); //135
var SFPvalue = SDPvalue + 10*shopcurr; //385

var sfpyes1 = 0;
var sfpyes2 = 0; 
var sdpyes = 0;
//Find out how they will be paying: 1) SFP225, 2) SFP285, 3) SDP, 4) Ala
if (p.radpack[0].checked) {//SFP225
	sfpyes1 = 1; 
} else if (p.radpack[1].checked) {//SFP285
	sfpyes2 = 1;
} else { //SDP or A la Carte
	if (p.radpack[2].checked) {//SDP
		sdpyes = 1;
	}
}

/*

//array of "other" codes, for guests and 100% volunteers, etc
var ocod = ['fthumil','ffrimix','ffrimil','fsataft','fsatmil','fsunaft','fsunmil',
			'fthufri','fthusat','fthusun','ffrisat','ffrisun','fsatsun',
			'fthfrsa','fthsasu','fthfrsu','ffrsasu',
			'fsdpsfp','fdancep',
			'fonewsh','ftwowsh','fthrwsh','ffouwsh','ffivwsh','fsixwsh','fsevwsh'];
//Decide which code they entered
switch (p.oc.value) {
	case ocod[0]: var subtr = priceala[0]; break; //fthumil
	case ocod[1]: var subtr = priceala[1]; break; //ffrimix
	case ocod[2]: var subtr = priceala[2]; break; //ffrimil
	case ocod[3]: var subtr = priceala[3]; break; //fsataft
	case ocod[4]: var subtr = priceala[4]; break; //fsatmil
	case ocod[5]: var subtr = priceala[5]; break; //fsunaft
	case ocod[6]: var subtr = priceala[6]; break; //fsunmil
	case ocod[7]: var subtr = priceala[0] + priceala[3]; break; //fthufri
	case ocod[8]: var subtr = priceala[0] + priceala[4]; break; //fthusat
	case ocod[9]: var subtr = priceala[0] + priceala[6]; break; //fthusun
	case ocod[10]: var subtr = priceala[2] + priceala[4]; break; //ffrisat
	case ocod[11]: var subtr = priceala[2] + priceala[6]; break; //ffrisun
	case ocod[12]: var subtr = priceala[4] + priceala[6]; break; //fsatsun
	case ocod[13]: var subtr = priceala[0] + priceala[2] + priceala[4]; break; //fthfrsa
	case ocod[14]: var subtr = priceala[0] + priceala[4] + priceala[6]; break; //fthsasu
	case ocod[15]: var subtr = priceala[0] + priceala[2] + priceala[6]; break; //fthfrsu
	case ocod[16]: var subtr = priceala[2] + priceala[4] + priceala[6]; break; //ffrsasu
	case ocod[17]: var subtr = SDPvalue; break; //fsdpsfp
	case ocod[18]: var subtr = SDPvalue; break; //fsdponl //this one should not ever happen
	case ocod[19]: var subtr = 1 * shopcurr; break; //fonewsh
	case ocod[20]: var subtr = 2 * shopcurr; break; //ftwowsh
	case ocod[21]: var subtr = 3 * shopcurr; break; //fthrwsh
	case ocod[22]: var subtr = 4 * shopcurr; break; //ffouwsh
	case ocod[23]: var subtr = 5 * shopcurr; break; //ffivwsh
	case ocod[24]: var subtr = 6 * shopcurr; break; //fsixwsh
	case ocod[25]: var subtr = 7 * shopcurr; break; //fsevwsh
	default: ocodecheck = "invalid";
}

var amountoff = 0;
//Calculate the amount off
if (sfpyes1 == 1) {//SFP225
	amountoff = sfpcurr1 - (SFPvalue - subtr) * (sfpcurr1 / SFPvalue);
} else if (sfpyes1 == 1) {//SFP285
	amountoff = sfpcurr2 - (SFPvalue - subtr) * (sfpcurr2 / SFPvalue);
} else if (sdpyes == 1) {
	amountoff = sdpcurr - (SDPvalue - subtr) * (sdpcurr / SDPvalue);
} else {
	amountoff = subtr;
}

//Other code
if (ocodecheck == "valid") {
	rebaja=amountoff;
	p.choth.disabled=false; p.choth.checked=true; //enable and check the box
} else {//disable it
	p.choth.disabled=true; p.choth.checked=false;
	rebaja=0;
	p.oc.value = ""; //clear the invalid code
}

//Vol code
if (p.vc.value.length==9) {
	var getit=parseInt(p.vc.value.substr(6,3));
} else if (p.vc.value.length==8) {
	var getit=parseInt(p.vc.value.substr(6,2));
} else {
	var getit=0;
}

if (p.vc.value.substr(0,6)=="troilo") {
	if (getit==100) {//and it's exactly 100 percent
		p.chvol.disabled=false; p.chvol.checked=true; //enable and check the box
	} else {//disable it
		p.chvol.disabled=true; p.chvol.checked=false;
	}
}  else if ((p.vc.value.substr(0,6)=="canaro") && 
		(getit%5==0) && //it's evenly divisible by 5
		//(getit!=0) && (getit!=5) && (getit!=10) && (getit!=15) && //it's more than 4 hours
		//I had to kill that requirement since one could volunteer 5 hours, 4 at milonga, then 1 more.
		(getit<=100)) {//and it's not more than 100 percent (thanks Vineet),
	p.chvol.disabled=false; p.chvol.checked=true; //enable and check the box
} else {//disable it
	p.chvol.disabled=true; p.chvol.checked=false;
	getit=0;
	p.vc.value = ""; //clear the invalid code
}


//turn code into a value
if (p.chvol.checked) {
	vol=getit/100; 
	p.dt.value=getit + "%";
}
if (p.choth.checked) {
	oth=rebaja;
}
*/
p.discsub.value = (disc * 100) + "%"; //disc percent text, either .4, .1 or .5
p.volsub.value = (vol * 100) + "%"; //vol percent text, either .25, .5, .75, 1
p.ot.value = "-" + CurrencyFormatted(oth);

//Show or hide discount rows
  showRow(0,"discsel");   showRow(0,"discsub"); //hide all first
  showRow(0,"chosestud"); showRow(0,"choseBTS"); 
  showRow(0,"chosevol");  showRow(0,"choseother");
  showRow(1,"discsub");   showRow(0,"volsub");

// if something got clicked
if ((p.chstud.checked) || (p.chbts.checked) || (p.chvol.checked) || (p.choth.checked)) { 
	showRow(1,"discsel"); } //show the header
if (p.chstud.checked) { showRow(1,"chosestud"); } 
if (p.chbts.checked) { showRow(1,"choseBTS"); } 
if (p.chvol.checked) { showRow(1,"chosevol"); }
if (p.choth.checked) { showRow(1,"choseother"); }
}//end discountFun()





//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
function page6fun(cont) { //CONTinue = false if going back to page5, true if proceeding to page 7
var p=document.form1;
showRow(1,"totaldue");
showRow(1,"subsub");
if (p.choth.checked) { showRow(1,"wsmssub"); } else {showRow(0,"wsmssub");} //but only if they have an "Other discount"
showRow(0,"grandsub"); //don't need grand total because there are no Volunteer discounts here

//Show method of payment
if (p.rdmeth[0].checked) {
  showRow(0,"choseck"); showRow(1,"chosepal");
  } else {
  showRow(1,"choseck"); showRow(0,"chosepal");
  }
//Calculate and display total due
var td=0; var st=0; var sfpcost1 = 225; var sfpcost2 = 285;
var ws = parseFloat(p.putwsub2.value); //workshop subtotal
var ms = parseFloat(p.putmilsub2.value); //milonga subtotal
var di = parseFloat(p.discsub.value) / 100; //Stud + TSB discount
var vo = parseFloat(p.volsub.value) / 100; //Vol discount
var od = parseFloat(p.ot.value); //Other discount

wsms = ws + ms; //workshops + milongas
if (wsms==sfpcost1*2) {//SFP cost was written in twice
	wsms = sfpcost1; //replace with SFP cost
} else if (wsms==sfpcost2*2) {
	wsms = sfpcost2;
}
st = wsms + od;//subtotal = wsms plus other discount (which is negative)

//Use Grand Total field to display subtotal times discount before Volunteer discount is applied
gt = st - (st * di); //grand total includes Stud + TSB
//td = tt - (tt * di);
td = gt - (gt * vo);


//Ben Thoma and Carlos are converting registration form into CD purchase form. 


//Override subtotal
st = 10.0;

//Multiply by quantity
td = st * p.selQuan.value

//Stick number of CDs desired into quantity field
p.putquan.value = p.selQuan.value;
//show this table row
showRow(1,"quan");

//Format the strings as currency
td_str = CurrencyFormatted(td);
st_str = CurrencyFormatted(st);
gt_str = CurrencyFormatted(gt);
wsms_str = CurrencyFormatted(wsms);
p.totaldue.value = td_str; //puts the total in the total box
p.subsub.value = st_str;
p.grandsub.value = gt_str;
p.wsmssub.value = wsms_str;


//Determine the appearance of the comment box
var hank = Math.round(3 + p.cm.value.length/37); 
//alert("putcm textarea will be " + hank + "em tall.");
p.putcm.style.height = hank + "em";
p.putcm.value = p.cm.value;

//Display the appropriate next page. Depends on whether CONT is true/false
if (cont) {
	showLayer('page7');
} else {
	showLayer('page1'); //Intermediate or Not Applicable
}
}//end page6fun











































//////////////////////////////////////////////////////
//Can I delete this function? Maybe, lemme try the script with this function call commented out
//Called from: page1fun
function fixWinIE() {
if (document.all && window.attachEvent) {
	window.attachEvent("onload",fixWinIE);
	//var beg = "You are using Internet Explorer, which has many bugs. \n Here's a temporary "
	//var mid = "fix: \n Push the F11 key twice to properly view each page of the "
	//var end = "form. \n This will be fixed in a few days. "
	//alert(beg+mid+end); 
}
}//end of fixWinIE


//////////////////////////////////////////////////////
function isEmail(email) {//valid format "a@b.cd"
//alert(email);
var invalidChars = " /;,:";
var the_at = email.indexOf("@"); //with two email fields (firstpart and domain), this is kinda silly
var the_dot = email.indexOf(".");
var a_space = email.indexOf(" ");
if (email == "") {return false;}//first of all, if blank, we're done. 
for (var i=0; i<invalidChars.length; i++)
	{badChar = invalidChars.charAt(i);//for each invalid character
	if (email.indexOf(badChar,0) > -1) //the email better not have it
		{ return false;} //if it does, it's invalid
	}
if ((the_at != -1) && //if there is an '@' (of course there is; I put it there)
	(the_at != 0) && //and it's not at position 0
	(the_dot != -1) && //and there's a '.'
//	(the_dot > the_at+1) && //and somthing between the '@' and '.' //no good cuz could be a.b@c.de
	(the_dot < email.length-1) && //and something after the '.'
	(a_space == -1)) //and there are no spaces
	{return true} //then it's all good
else {return false}
}//end of function isEmail


//////////////////////////////////////////////////////
//Called from: page1fun, page1bfun
var currentLayer = 'page1'; 
function showLayer(lyr) { //lyr = 'page4'
hideLayer(currentLayer); //"currentlayer" is a global variable
document.getElementById(lyr).style.display = "block";
window.scroll(0,0); //puts user at the top of each page
currentLayer = lyr;
}//end showLayer

	//////////////////////////////////////////////////////
	//Called from: showLayer
	function hideLayer(lyr) {
	document.getElementById(lyr).style.display = "none";
	}//end hideLayer




//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called from: updataMilonga and updateShops
function showRow(up,y) {//give it a 'm1' or a 'milala1'
var n="x" + y;
//alert(n);
var row = document.getElementById(n);
//alert(n);
if (up==1) {
	if (isItIE()) {row.style.display = "block"; }
	else {row.style.display = "table-row"; }
} else {row.style.display = "none";
}
}//end showRow

	//////////////////////////////////////////////////////
	//////////////////////////////////////////////////////
	//////////////////////////////////////////////////////
	//Called from: showRow
	function isItIE() {
	if (document.all && window.attachEvent) { //alert("This is Internet Explorer");
		return true;
	} else {//alert("This is not Internet Explorer"); 
		return false;
	}
	}//end ifItIE




//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called from: partInfo, packHit
function enabler(someone,updown) { //SOMEONE is the string of an element's id, UPDOWN is True for enable, False for disable
var e = document.getElementById(someone);
if (updown) {
	e.disabled = false;
} else {
	e.disabled = true;
	if (someone=='onepartner' && updown==0) { e.value=""; } //specific to this element
}
}//end of enabler





//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called from: Page 1 and Page 1D
function popup(mylink, windowname) {
if (! window.focus) return true;
var href;
if (typeof(mylink) == 'string') {
	href=mylink; //it is a string, such as "pop_level09.html"
} else { 
	href=mylink.href; //it is not a string but rather an element like a or area, so get its href attribute
}
window.open(href, windowname, 'width=640,height=600,left=20,scrollbars=yes');
return false; //so that the click does not follow the link
}





//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called from: discountFun and page6fun
function CurrencyFormatted(amount) { //will take strings or numbers
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}
// end of function CurrencyFormatted()




//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
function sumArr(a) {
for(var i=0,sum=0; i<a.length; sum+=a[i++]);
return sum;
}





//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//Called first in reg form; hides all the pages, then shows page 1
function initHide() {
var p = document.form1;
var g=1; //1 to hide 'em, 0 to show 'em all
var t=0; //1 to populate page 1 fields for testing, 0 for blank
if (g==1) {
	document.getElementById("page2").style.display="none";
	document.getElementById("page3").style.display="none";
	document.getElementById("page4").style.display="none";
	document.getElementById("page5").style.display="none";
	document.getElementById("page6").style.display="none";
	document.getElementById("page7").style.display="none";
}
//alert("Just ran initHide.");
if (t==1) {
	p.nm.value = "Tester Guy";
	p.em1.value = "soyelmoreno@aol.com";
	p.em2.value = "soyelmoreno@aol.com";
	p.ci.value = "Seattle";
	p.st.value = "NY";
	p.co.value = "Senegal";
	p.ph.value = "817-345-9812";
}	

}//end initHide



