/********************************** Validates a form *************************************
function: validateForm()
params:   oForm			- The name of the form to validate
          strAlerts		- Whether or not to display javascript alerts
          seminarChosen - Boolean as to whether to validate if a seminar has been chosen
          details		- Boolean as to whether to validate details in general
          sourceChosen	- Boolean as to whether to validate if a source has been chosen
******************************************************************************************/
function validateForm(oForm, strAlerts, seminarChosen, details, sourceChosen)
{
	if (seminarChosen)
	{
		if (!validateSeminarChosen()) 
		{
			return false;
		}
	}
	
	if (details)
	{
		if (!ValidateClientDetails(oForm, strAlerts)) 
		{
			return false;
		}		
	}
	
	if (sourceChosen)
	{
		if (!validateSourceChosen()) 
		{
			return false;
		}
	}
	return true;

}
/*****************************************************************************************/
/**************************************checks a seminar has been chosen*******************/
/*****************************************************************************************/
function validateSeminarChosen()
{
   if(document.forms[0].seminar) 
   {
		varButton = document.forms[0].seminar;
		varSeminar = 0;

		if (varButton.length) {
			for (var b = 0; b < varButton.length; b++)
				if (varButton[b].checked)
					varSeminar = varButton[b].value;
		}
		else if (varButton.checked) {
			varSeminar = varButton.value;
		}

  		if (varSeminar == 0)
   		{
		  		alert("Please select a seminar!");
		  		return false;
   		}
   	}
   	return true;
}
/*****************************************************************************************/
/**************************************checks a source has been chosen********************/
/*****************************************************************************************/
function validateSourceChosen()
{
	varsource2 = document.forms[0].source.selectedIndex;
	varsource2name = document.forms[0].source.options[varsource2].value;
	
	if ( varsource2name == "" ) 
	{
		alert("Please tell us how you heard about about us");
		document.forms[0].source.focus();      
      	return false;
	}	
	
	return true;
}
/*****************************************************************************************/
/**************************************validates credit card details********************/
/*****************************************************************************************/
function checkCCDetails(oForm, blnAlerts)
{
	if (IsEmpty(oForm.PaymentMethod, "Please select a payment method from the list.", blnAlerts)) {return false;}
	if (IsEmpty(oForm.CC1, "Please enter the first group of credit card numbers.", blnAlerts) || (IsOnlyNumeric(oForm.CC1, "Please enter only numbers for your credit card.", blnAlerts))) {return false;}
	if (oForm.CC1.value.length < 4)
	{
		DisplayError(oForm.CC1, "4 digdssdfits are required.", blnAlerts);
		oForm.CC1.focus();
		return false;		
	}
	if (IsEmpty(oForm.CC2, "Please enter the second group of credit card numbers.", blnAlerts) || (IsOnlyNumeric(oForm.CC2, "Please enter only numbers for your credit card.", blnAlerts))) {return false;}
	if (oForm.CC2.value.length < 4)
	{
		DisplayError(oForm.CC2, "4 digits are required.", blnAlerts);
		oForm.CC2.focus();
		return false;		
	}
	if (IsEmpty(oForm.CC3, "Please enter the third group of credit card numbers.", blnAlerts) || (IsOnlyNumeric(oForm.CC3, "Please enter only numbers for your credit card.", blnAlerts))) {return false;}
	if (oForm.CC3.value.length < 4)
	{
		DisplayError(oForm.CC3, "4 digits are required.", blnAlerts);
		oForm.CC3.focus();
		return false;		
	}	
	if (IsEmpty(oForm.CC4, "Please enter the fourth group of credit card numbers.", blnAlerts) || (IsOnlyNumeric(oForm.CC4, "Please enter only numbers for your credit card.", blnAlerts))) {return false;}			
	if (oForm.CC4.value.length < 2)
	{
		DisplayError(oForm.CC4, "At least 2 digits are required.", blnAlerts);
		oForm.CC4.focus();
		return false;		
	}
	
	var exists = eval(oForm["AuthorityCode"]);
	if (exists) 	
	{
		if (IsEmpty(oForm.AuthorityCode, "Please enter the authority code on the credit card.", blnAlerts)){return false;}	
	}
	if (IsEmpty(oForm.CardHolder, "Please enter the name on the credit card.", blnAlerts) || (!IsAlpha(oForm.CardHolder, "Please enter only alphabetic characters for the card holder.", blnAlerts))){return false;}
	if (IsEmpty(oForm.ExpiryMonth, "Please enter the expiry month for the credit card.", blnAlerts) || (IsOnlyNumeric(oForm.ExpiryMonth, "Please enter only numbers for the expiry month.", blnAlerts))) {return false;}
	if (IsEmpty(oForm.ExpiryYear, "Please enter the expiry year for the credit card.", blnAlerts) || (IsOnlyNumeric(oForm.ExpiryYear, "Please enter only numbers for the expiry year.", blnAlerts))) {return false;}
}
/*****************************************************************************************/
/********* creates FTP link dependent on what browser a user is using ********************/
/*****************************************************************************************/
function downloadLink(filename)
{
	if(navigator.userAgent.indexOf("Firefox") != -1)
	{
		window.location = "ftp://hubbfg.ftptoday.com/" + filename; 
	}
	else
	{
		window.location = "ftp://hubbfg.ftptoday.com/ftp/pub/anonymous/" + filename;	
	}
}
