// JavaScript Document
var nr=0;
function numericCheck()
{
	// Eg:  nrl=document.<name of form>.<name of field>.value;
	nr1 = document.pform.no_of_tickets.value;
	flg = 0;
	str = "";
	spc = ""
	arw = "";
	for (var i = 0; i<nr1.length; i++)
	{
		cmp = "0123456789";
		tst = nr1.substring(i,i+1);
		if (cmp.indexOf(tst) < 0)
		{
			flg++;
			str += " " + tst;
			spc += tst;
			arw += "^";
		}
		else
			arw+="_";
	}
	if (flg != 0)
	{
		if (spc.indexOf(" ") > -1)
		{
			str += " and/or a space";
		}
		alert("Please enter a valid number.");
		window.document.pform.no_of_tickets.focus();
		window.document.pform.no_of_tickets.select();

		return false;
	}
	if (window.document.pform.no_of_tickets.value == 0)
	{
		alert("Please enter no. of tickets.");
		window.document.pform.no_of_tickets.focus();
		window.document.pform.no_of_tickets.select();

		return false;
	}
/*	if (window.document.pform.no_of_tickets.value == 1)
	{
		window.document.pform.amount.value = 25;
	}
	else {	
		window.document.pform.amount.value = window.document.pform.no_of_tickets.value * 20;
	}
*/	return true;
}

/*
function workshopCheck()
{
	if (window.document.pform.BBD_WORKSHOP.checked == true)
		{
		window.document.pform.no_of_tickets.value = "1";
		window.document.pform.amount.value = "25"
		}	
}*/
function workshop1()
{
	if (window.document.pform.BBD_WORKSHOP.checked == true)
	{
		window.document.pform.BBD_WORKSHOP_DATE[0].checked = true;
	}
	if (window.document.pform.BBD_WORKSHOP.checked == false)
	{
		window.document.pform.BBD_WORKSHOP_DATE[0].checked = false;
		window.document.pform.BBD_WORKSHOP_DATE[1].checked = false;
	}
}
function workshop2()
{
	if (window.document.pform.BUSINESS_COACH.checked == true)
	{
		window.document.pform.BCOACH_WORKSHOP_DATE.checked = true;
	}
	if (window.document.pform.BUSINESS_COACH.checked == false)
	{
		window.document.pform.BCOACH_WORKSHOP_DATE.checked = false;
	}
}
function workshop3()
{
	if (window.document.pform.SALES_WORKSHOP.checked == true)
	{
		window.document.pform.SALES_WORKSHOP_DATE.checked = true;
	}
	if (window.document.pform.SALES_WORKSHOP.checked == false)
	{
		window.document.pform.SALES_WORKSHOP_DATE.checked = false;
	}
}

function validEmail(email)
{
	invalid = " /:,;"
	for (i=0; i<invalid.length; i++) 
	{
		badChar = invalid.charAt(i)
		if (email.indexOf(badChar,0) > -1) 
		{
			return false
		}
	}
	pos = email.indexOf("@",1)
	if (pos == -1) 
	{
		return false
	}
	if (email.indexOf("@",pos+1) != -1) 
	{
		return false
	}
	dot = email.indexOf(".",pos)
	if (dot == -1) 
	{
		return false
	}
	if (dot+3 > email.length)	
	{
		return false
	}
	dot = email.indexOf(".",dot+1)
	if (dot != -1) 
	{
		if (dot+3 > email.length)	
		{
			return false
		}
	}
	return true
}

// Ensure that ESSENTIAL FIELDS have been filled in.
function CheckFields(pform)
{
	// The fields are checked for blanks
	if ( window.document.pform.FIRSTNAME.value   == "" ||
		window.document.pform.SURNAME.value  == "" ||
		window.document.pform.POSITION.value  == "" ||
		window.document.pform.COMPANY.value  == "" ||
		window.document.pform.INDUSTRY.value  == "" ||
		window.document.pform.LENGTH_YEARS.value  == "" ||
		window.document.pform.ADDRESS.value  == "" ||
		window.document.pform.POSTCODE.value  == "" ||
		window.document.pform.WORK_PHONE.value  == "" ||
		window.document.pform.MOBILE.value    == "" ||
		window.document.pform.EMAIL.value    == "" ||
		window.document.pform.ADVERTISING_SOURCE.value   == "" ) 
	{
		alert( "Please ensure that all required fields are filled in." );
		return false;
	}

	// check for no of staff details	
	if ( window.document.pform.STAFF[0].checked == false &&
		window.document.pform.STAFF[1].checked == false &&
		window.document.pform.STAFF[2].checked == false &&
		window.document.pform.STAFF[3].checked == false &&
		window.document.pform.STAFF[4].checked == false &&
		window.document.pform.STAFF[5].checked == false &&
		window.document.pform.STAFF[6].checked == false &&
		window.document.pform.STAFF[7].checked == false &&
		window.document.pform.STAFF[8].checked == false &&
		window.document.pform.STAFF[9].checked == false )
	{
		alert( "Please select the no. of staff in your business." );
		return false;
	}
	
	// check for workshop date
/*	if ( window.document.pform.BBD_WORKSHOP.checked == false &&
		window.document.pform.BUSINESS_COACH.checked == false &&
		window.document.pform.SALES_WORKSHOP.checked == false)
	{
		alert("Please select a workshop.");
		return false;
	}
*/
	// check for how did you hear about us
	if ( window.document.pform.ADVERTISING_SOURCE[0].checked == false &&
		window.document.pform.ADVERTISING_SOURCE[1].checked == false &&
		window.document.pform.ADVERTISING_SOURCE[2].checked == false &&
		window.document.pform.ADVERTISING_SOURCE[3].checked == false &&
		window.document.pform.ADVERTISING_SOURCE[4].checked == false &&
		window.document.pform.ADVERTISING_SOURCE[5].checked == false &&
		window.document.pform.ADVERTISING_SOURCE[6].checked == false &&
		window.document.pform.ADVERTISING_SOURCE[7].checked == false &&
		window.document.pform.ADVERTISING_SOURCE[8].checked == false &&
		window.document.pform.ADVERTISING_SOURCE[9].checked == false )
	{
		alert( "Please select how you heard about us." );
		return false;
	}

	// check for specific entry
   	if ( window.document.pform.ADVERTISING_SOURCE[9].checked == true &&
	 	window.document.pform.OTHER_SPECIFIC.value  == "" )
	{
		alert( "Please specify how you heard about us." );
		window.document.pform.OTHER_SPECIFIC.focus();
		window.document.pform.OTHER_SPECIFIC.select();
		return false;
	}
      	
	// check for valid email address
	if (!validEmail(window.document.pform.EMAIL.value)) 
		{
			alert("Please enter a valid email.");
			window.document.pform.EMAIL.focus();
			window.document.pform.EMAIL.select();
			return false;
		}

/*   if ( window.document.pform.Payment.value   == "") 
	{
		alert( "Please Select your payment method." );
		return false;
	}

   if ( window.document.pform.Payment.value   == "credit")              
	{

	// check for credit card details
	if ( window.document.pform.card[0].checked == false &&
		window.document.pform.card[1].checked == false &&
		window.document.pform.card[2].checked == false &&
		window.document.pform.card[3].checked == false )
	{
		alert( "Please enter your credit card details." );
		return false;
	}

	if ( window.document.pform.Credit_Card_Number.value   == "" ||
		window.document.pform.Name_on_Card.value   == "" ||			
	 	window.document.pform.Expiry_Date.value   == "")
	{
		alert( "Please enter your credit card details." );
		return false;
	}

	// check for valid no of tickets
	if (window.document.pform.no_of_tickets.value == "")
	{
		alert("Please enter no. of tickets.");
		window.document.pform.no_of_tickets.focus();
		window.document.pform.no_of_tickets.select();
		return false;
	}
*/
	else
		return true;
}
