/*
    _registrationStuff.js
    
    Copyright Affinity IT Training, LLC 2009.  All Rights Reserved.
*/

function checkForm (form) {
  if (form.fai_firstname.value.length == 0 ||
      form.fai_lastname.value.length == 0) {
	alert ('First Name and Last Name are required');
	return false;
  }
  if (form.fai_company.value.length == 0) {
	alert ('Company is required');
	return false;
  }
  if (form.fai_email.value.length == 0) {
	alert ('Email is required');
	return false;
  }
  return true;
}

function checkRegForm (form) {
  if (form.ParticipantName.value.length == 0 ||
      form.ParticipantName.value.length == 0) {
	alert ('Your name is required for registration.');
	form.ParticipantName.focus();
	return false;
  }
  if (form.ParticipantPhone.value.length == 0 ||
      form.ParticipantPhone.length == 0) {
	alert ('Phone number is required for registration.');
	form.ParticipantPhone.focus();
	return false;
  }
  if (form.ParticipantEmail.value.length == 0 ||
      form.ParticipantEmail.value.length == 0) {
	alert ('Your email address is required');
	form.ParticipantEmail.focus();
	return false;
  }
  if (form.TrainingCreditEmail.value.length == 0 ||
      form.TrainingCreditEmail.value.length == 0) {
	alert ('The email address you used to purchase Training Credits is required.');
	form.TrainingCreditEmail.focus();
	return false;
  }
  if (form.TransactionId.value.length == 0 ||
      form.TransactionId.value.length == 0) {
	alert ('The Receipt Number associated with your purchase of Training Credits is required');
	form.TransactionId.focus();
	return false;
  }
//  if (form.ShipMaterials.checked) {
	  if (form.ShippingAddress1.value.length == 0 ||
	      form.ShippingAddress1.value.length == 0) {
		alert ('Shipping Address is required for course materials shipment to occur');
		form.ShippingAddress1.focus();
		return false;
	  }
	  if (form.ShippingCity.value.length == 0 ||
	      form.ShippingCity.value.length == 0) {
		alert ('City is required for course materials shipment to occur');
		form.ShippingCity.focus();
		return false;
	  }
	  if (form.ShippingState.value.length == 0 ||
	      form.ShippingState.value.length == 0) {
		alert ('State is required for course materials shipment to occur');
		form.ShippingState.focus();
		return false;
	  }
  	  if (form.ShippingZip.value.length == 0 ||
	      form.ShippingZip.value.length == 0) {
		alert ('Zip code is required for course materials shipment to occur');
		form.ShippingZip.focus();
		return false;
	  }
  	  if (form.ShippingCountry.value.length == 0 ||
	      form.ShippingCountry.value.length == 0) {
		alert ('Country is required for course materials shipment to occur');
		form.ShippingCountry.focus();
		return false;
	  }
//  }
  return true;
}

function toggleShippingFields (form)  {

  form.ShippingAddress1.disabled= 	! form.ShipMaterials.checked;
  form.ShippingAddress2.disabled= 	! form.ShipMaterials.checked;
  form.ShippingCity.disabled= 		! form.ShipMaterials.checked;
  form.ShippingState.disabled= 		! form.ShipMaterials.checked;
  form.ShippingZip.disabled= 		! form.ShipMaterials.checked;
  form.ShippingCountry.disabled= 	! form.ShipMaterials.checked;
 
}

function displayThankYou () {
  if (window.location.href.indexOf("registered") != -1) {
    alert ('Your information has been received. Thank you !');
  }
}

function displayTransIncompleteMsg () {
  if (window.location.href.indexOf("cancel") != -1) {
    alert ('Your transaction was cancelled or otherwise not completed.\nPlease try again and contact us if you are having difficulties purchasing Training Credits.');
    document.location.href="/Buy_Web_Training.html";
  }
}

function displayTransSuccessMsg () {
  if (window.location.href.indexOf("complete") != -1) {
    alert ('Thank you for your payment.\n\nYour Training Credit purchase has been completed and a receipt for your purchase has been emailed to you\n\nYou may now register for courses for which you have sufficient Training Credits');
    document.location.href="/Web_Training_Schedule.html";
  }
}

function enableBuyButtons () {

  for (var f=0; f < document.forms.length; f++) 
    if (document.forms['agree'].elements['readAgreement'].checked) 
    	document.forms[f].action="https://www.paypal.com/cgi-bin/webscr";
    else
    	document.forms[f].action="javascript:alert ('You must agree to Terms of Web Training Services Agreement before purchase');void 0;";
}
	


