// JavaScript Document
function popup(page, name, w, h, direct, locate, menu, scroll, status, tool) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
		winprop = 'height='+h+',width='+w+',top='+wint+',left='+winl+',directories='+direct+',location='+locate+',menubar='+menu+',scrollbars='+scroll+',status='+status+',toolbar='+tool+',resizable=yes'
	var win = window.open(page, name, winprop);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	//return win;
}

function additionalAttendees (num) {
	var z = document.getElementById(num)
	var maxsize = z.selectedIndex + 1;
	var addattendee = new Array();
	
	// create the variables
	for (var i=1;i<=maxsize;i++) {
		addattendee[i] = 'additional_attendee' + i;	
		var field = addattendee[i] + '';
		displayOpen(field);
	}
	
	var others = 10 - maxsize;
	var hiddenfields = new Array() ;
	
	for (var t=maxsize + 1;t<=others;t++) {
		hiddenfields[t] = 'additional_attendee' + t;
		var hidden = hiddenfields[t] + '';
		displayClose(hidden);
	}
		
}

function passVariables(original,copy) {
	document.getElementById(copy).value = document.getElementById(original).value;
}
	
function checkPassVariables(copy_to_billing,original,copy) {
	if (copy_to_billing.checked == true) {
	document.getElementById(copy).value = document.getElementById(original).value;
	}
}	
	
function checkDisplay(name1,name2) {
	var t = document.getElementById(name1);
	var z = document.getElementById(name2);

	if (z.selectedIndex == "6") {
		toggleDisplay(name1);
	}
}



function displayOpen(name) {
	var t = document.getElementById(name);
		
	if (t.style.display == "none") {
		t.style.display = "";
	}	
}

function displayClose(name) {
	var t = document.getElementById(name);
	
	if (t.style.display == "") {
		t.style.display = "none";
	}		
}
						
function toggleDisplay(name) {
	var t = document.getElementById(name);
	changeDisplay(name, t.style.display == "");
}


/** change the display **/
function changeDisplay(name, viewable) {
	var t = document.getElementById(name);
	t.style.display = viewable == "" ? "" : "none";
}


function validateForm(form, elementNames) {

	var elNames = elementNames.split(",");
	var good = true;

	for (var i=0; i<elNames.length; i++) {
		var el = form[elNames[i]];
		if (el.type == "text" && el.value.length == 0) {
			good = false;
		}
		else if (el.type == "select-one" && el.selectedIndex == 0) good = false;
		else if (el.type == "checkbox" && el.checked == false) {
			good = false;
		}
	}

	if (form[elNames[0]].value.length == 0) {
		good = false;
		alert("Please fill in your full name.");
	}
	else if (form[elNames[1]].value.length == 0) {
		good = false;
		alert("Please fill in your title.");
	}
	else if (form[elNames[2]].value.length == 0) {
		good = false;
		alert("Please fill in the school or organization you are representing.");		
	}
	else if (form[elNames[3]].value.length == 0) {
		good = false;
		alert("Please fill in your phone number.");
	}
	else if (form[elNames[4]].value.length == 0) {
		good = false;
		alert("Please fill in your email address.");
	}
	else if (form[elNames[5]].value != form[elNames[4]].value) {
		good = false;
		alert("The email addresses you've entered do not match.  Please provide the same email address.");
	}
	else if (form[elNames[6]].checked == false) {
		good = false;
		alert("Please confirm that you have read the Terms & Conditions.");
	}

	return good;
	
}

function validateForm2(form, payment_type, elementNames) {

	var elNames = elementNames.split(",");
	var good = true;

	for (var i=0; i<elNames.length; i++) {
		var el = form[elNames[i]];
	}

    if (form[elNames[0]].value.length == 0) {
		good = false;
		alert("Please fill in your full name.");
	}
	else if (form[elNames[1]].value.length == 0) {
		good = false;
		alert("Please fill in your title.");
	}
	else if (form[elNames[2]].value.length == 0) {
		good = false;
		alert("Please fill in the school or organization you are representing.");		
	}
	else if (form[elNames[3]].value.length == 0) {
		good = false;
		alert("Please fill in your phone number.");
	}
	else if (form[elNames[4]].value.length == 0) {
		good = false;
		alert("Please fill in your email address.");
	}
	else if (form[elNames[5]].value != form[elNames[4]].value) {
		good = false;
		alert("The email addresses you've entered do not match.  Please provide the same email address.");
	}
	else if (form[elNames[6]].checked == false) {
		good = false;
		alert("Please confirm that you have read the Terms & Conditions.");
	}
	else if (payment_type[1].checked == true && form[elNames[7]].value.length == 0) {
		good = false;
		alert("Please fill in your billing name.");
		}
	else if (payment_type[1].checked == true && form[elNames[8]].value.length == 0) {
		good = false;
		alert("Please fill in your billing phone number.");
	}
	else if (payment_type[1].checked == true && form[elNames[9]].value.length == 0) {
		good = false;
		alert("Please fill in your billing email address.");
	}
	else if (payment_type[1].checked == true && form[elNames[9]].value != form[elNames[10]].value) {
		good = false;
		alert("The billing email addresses you've entered do not match.  Please provide the same email address.");
	}
	
	return good;
}





