/*===============================================================================
	registrant.js
	  Created 04/27/2008 by Greg Spry
	
	All front-end registrant-specific Javacript for Wonderware

===============================================================================*/
window.addEvent('domready', function() {
																		 
	registrantClassDetailsPopUp = new PopUpWindow('', {
		injectLocation: $('registrantClassDetailsPopUpInjectDiv'),
		onClose: closeRegistrantClassDetailsPopUp,
		zIndex: 30000,
		top: '120px',
		left: '75px',
		width: '100%',
		opacity: '1'
	});
																		 
});

/*===============================================================================*/
function verifyRegistrantCreationInfo() {
	name = $('username').value;
	new Ajax('admin/adminAJAXLoad.asp', {
		method: 'post',
		data: 'ajaxAction=checkRegistrantName&RegistrantName=' + name,
		onComplete: function() {
    	continueToVerifyRegistrantCreationInfo(this.response.text);
  	},
		evalScripts: false
	}).request();
	return false;
}
function continueToVerifyRegistrantCreationInfo(usernameResponse){
	theForm = $('registrantCreationForm');
	with(theForm){
		if (username.value == ''){
			alert('Please enter a username.');
		}
		else if(usernameResponse == 'exists'){
			alert('Please select a different username.');
		}
		else if(password.value == ''){
			alert('Please enter a password.');
		}
		else if(password.value != confirmPassword.value){
			alert('Password and confirm password fields do not match.');
		}
		else if(firstName.value == ''){
			alert('Please enter your first name.');
		}
		else if(lastName.value == ''){
			alert('Please enter your last name.');
		}
		else if(phone.value == ''){
			alert('Please enter your primary contact number.');
		}
		else if(email.value == ''){
			alert('Please enter your last name.');
		}
		else if(!isValidEmailAddress(email.value)){
			alert('Please enter a valid email address.');
		}
		else if(address1.value == ''){
			alert('Please enter line 1 of your street address.');
		}
		else if(city.value == ''){
			alert('Please enter your city of residence.');
		}
		else if(ZIP.value == ''){
			alert('Please enter your zip code.');
		}
		else{
			theForm.submit();
		}
	}
}

/*===============================================================================*/
function verifyRegistrantUpdateInfo() {
	name = $('username').value;
	ID = $('RegistrantID').value;
	new Ajax('admin/adminAJAXLoad.asp', {
		method: 'post',
		data: 'ajaxAction=checkRegistrantName&RegistrantName=' + name + 
																			  '&RegistrantID=' + ID +
																				'&isRegistrantEditor=true',
		onComplete: function() {
    	continueToVerifyRegistrantUpdateInfo(this.response.text);
  	},
		evalScripts: false
	}).request();
	return false;
}
function continueToVerifyRegistrantUpdateInfo(usernameResponse){
	theForm = $('registrantUpdateForm');
	with(theForm){
		if (username.value == ''){
			alert('Please enter a username.');
		}
		else if(usernameResponse == 'exists'){
			alert('Please select a different username.');
		}
		else if((password.value != '') && (password.value != confirmPassword.value)){
			alert('Password and confirm password fields do not match.');
		}
		else if(firstName.value == ''){
			alert('Please enter your first name.');
		}
		else if(lastName.value == ''){
			alert('Please enter your last name.');
		}
		else if(phone.value == ''){
			alert('Please enter your primary contact number.');
		}
		else if(email.value == ''){
			alert('Please enter your last name.');
		}
		else if(!isValidEmailAddress(email.value)){
			alert('Please enter a valid email address.');
		}
		else if(address1.value == ''){
			alert('Please enter line 1 of your street address.');
		}
		else if(city.value == ''){
			alert('Please enter your city of residence.');
		}
		else if(ZIP.value == ''){
			alert('Please enter your zip code.');
		}
		else{
			theForm.submit();
		}
	}
}

/*===============================================================================*/
function summonRegistrantClassDetailsPopUp(classID) {
	//showLoadingMessage('Opening...');
	new Ajax('admin/adminAJAXLoad.asp', {
		method: 'post',
		data: 'ajaxAction=registrantClassDetailsPopUp&ClassID=' + classID,
		update: registrantClassDetailsPopUp.getContentDiv(),
		evalScripts: true,
		onComplete: function() {
			registrantClassDetailsPopUp.open();
			hideLoadingMessage();
		}
	}).request();
}

function closeRegistrantClassDetailsPopUp() {
	registrantClassDetailsPopUp.close();
	hideLoadingMessage();
}
/*===============================================================================*/
function cancelRegistrantClass(classID, registrantID, isWaiting) {
	if (confirm('Are you sure you want to cancel your registration in this class?')) {
		
		showLoadingMessage('Canceling...');
		new Ajax('admin/adminAJAXLoad.asp', {
			method: 'post',
			data: 'ajaxAction=cancelRegistrantClass' +
						'&ClassID=' + classID +
						'&RegistrantID=' + registrantID +
						'&isWaitingList=' + isWaiting,
			update: $('registrantClassListInjectDiv'),
			evalScripts: false,
			onComplete: completeRegistrantClassCanceling
		}).request();
	}
}

function completeRegistrantClassCanceling() {
	hideLoadingMessage();
}
/*===============================================================================*/