function IsDigit(what)  
{
InString=what.value;
entry=what.name;

	RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  
	{
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
		{
			alert("Please enter digits only\n in " + entry);
			what.focus();
			what.select();
			return false;
		}
	}
	return true;
}
///////////////////////// check phone number for < 7 digits
function chekPhone(what)
{
	var Digits=0;
	var InString=what.value;
	//alert("Instring is >" + InString + "<");
	Match=/[0-9]/; // we are looking for digits in InString
	for (i=0; i < InString.length; i++)
	{
		var MatchWhat=InString.charAt(i); // what are we trying to match against
		var MatchResult=MatchWhat.match(Match); // what is the result of the match
		if (MatchResult != null) // we found a match
		{
			//alert("found a digit");
			Digits++;
		}
	}
	if (Digits >= 7)
	{
		return true;
		PhoneNumberOK = "T";
	}
	else
	{
		alert("Phone Number must have at least 7 digits.");
		PhoneNumberOK = "F";
		what.focus();
		what.select();
		return false;
	}
}		

////////////////////////////////////
function chekAreaCode(what)
{
	var Digits=0;
	var InString=what.value;
	//alert("Instring is >" + InString + "<");
	Match=/[0-9]/; // we are looking for digits only in InString
	for (i=0; i < InString.length; i++)
	{
		var MatchWhat=InString.charAt(i); // what are we trying to match against
		var MatchResult=MatchWhat.match(Match); // what is the result of the match
		if (MatchResult != null) // we found a match
		{
			//alert("found a digit");
			Digits++;
		}
	}
	if (Digits >= 3)
	{
		return true;
		AreaCodeOK = "T";
	}
	else
	{
		alert("Area Code must have at least 3 digits.");
		AreaCodeOK = "F";
		what.focus();
		what.select();
		return false;
	}
}		

////////////////////////////////////////
function isEmpty(input)
{
	if(input == "" || input == null)
	{
		return true;
	}
	alert ("You did not enter a required field.");
	return false;
}

/////////////////////////////////////////
function getToday()
{
    var now = new Date();
	var today = now.getDate();
	var year = now.getFullYear();
	var month = now.getMonth() + 1; // getMonth starts at 0
	timeValue="";
	//timeValue += (year >= 2000) ? year + "-" : "19" + year + "-";
	timeValue += year + "-";
	timeValue +=(month < 10) ? "0" + month + "-" : + month + "-";
	timeValue +=(today <10) ? "0" + today : + today;
//alert("timeValue is >"+timeValue+"<");
    document.interpreter.Today.value = timeValue;
}

///////////////////////////////////////
function chekForm(F)
{
	eMsg = "The following fields were empty:\n\n";
	var DateOK = "F";
		if (F.Today.value == "")
		{
			eMsg += "Date\r";
		}
		else
		{
			DateOK = "T";
		}
	var FirstnameOK = "F";
		if (F.Firstname.value == "")
		{
			eMsg += "First name\r";
		}
		else
		{
			FirstnameOK = "T";
		}
	var LastnameOK = "F";
		if ( F.Lastname.value == "")
		{
			eMsg += "Last name\r";
		}
		else
		{
			LastnameOK = "T";
		}
			
	var Address1OK = "F";
		if (F.Address1.value == "")
		{
			eMsg += "Address\r";
		}
		else
		{
			Address1OK = "T";
		}
	var CityOK = "F";
		if (F.City.value == "")
		{
			eMsg += "City\r";
		}
		else
		{
			CityOK = "T";
		}
	var ProvinceOK = "F";
		if (F.Province.options[F.Province.selectedIndex].value == "")
		{
			eMsg += "Province\r";
		}
		else
		{
			ProvinceOK = "T";
		}
	var PostalCodeOK = "F";
		if (F.PostalCode.value == "")
		{
			eMsg += "Postal Code\r";
		}
		else
		{
			PostalCodeOK = "T";
		}
	var HomeAreaCodeOK = "F";
		if (F.HomeAreaCode.value == "")
		{
			eMsg += "Home Area Code\r";
		}
		else
		{
			HomeAreaCodeOK = "T";
		}
	var HomePhoneOK = "F";
		if (F.HomePhone.value == "")
		{
			eMsg += "Home Phone Number\r";
		}
		else
		{
			HomePhoneOK = "T";
		}
//	var WorkAreaCodeOK = "F";
//		if (F.WorkAreaCode.value == "")
//		{
//			eMsg += "Work Area Code\r";
//		}
//		else
//		{
//			WorkAreaCodeOK = "T";
//		}
//	var WorkPhoneOK = "F";
//		if (F.WorkPhone.value == "")
//		{
//			eMsg += "Work Phone Number\r";
//		}
//		else
//		{
//			WorkPhoneOK = "T";
//		}
	var EmailOK = "F";
		if (F.Email.value == "")
		{
			eMsg += "Email\r";
		}
		else
		{
			EmailOK = "T";
		}
	var CountryOriginOK = "F";
		if (F.CountryOrigin.value == "")
		{
			eMsg += "Country of Origin\r";
		}
		else
		{
			CountryOriginOK = "T";
		}
	var LangForwardOK = "F";
		if (F.LangForward.value == "")
		{
			eMsg += "Languages\r";
		}
		else
		{
			LangForwardOK = "T";
		}
//	var DialForwardOK = "F";
//		if (F.DialForward.value == "")
//		{
//			eMsg += "Dialects\r";
//		}
//		else
//		{
//			DialForwardOK = "T";
//		}

	var Residence1OK = "F";
	var From1OK= "F";
	var To1OK = "F";
	var Language1OK = "F";
		if ((F.Residence1.value == "") ||
			(F.From1.value == "") ||
			(F.To1.value == "") ||
			(F.Language1.value == ""))
		{
			eMsg += "First Country of Residence\r";
		}
		else
		{
			Residence1OK = "T";
			From1OK = "T";
			To1OK = "T";
			Language1OK = "T";
		}
//	var Residence2OK = "F";
//	var From2OK = "F";
//	var To2OK = "F";
//	var Language2OK = "F";
//	var Residence3OK = "F";
//	var From3OK = "F";
//	var To3OK = "F";
//	var Language3OK = "F";
	var LondonYearOK = "F";
		if (F.LondonYear.value == "")
		{
			eMsg += "London arrival year\r";
		}
		else
		{
			LondonYearOK = "T";
		}
	var LondonMonthOK = "F";
		if (F.LondonYear.value == "")
		{
			eMsg += "London arrival month\r";
		}
		else
		{
			LondonMonthOK = "T";
		}
	var EligibleOK = "F";
		if ((F.Eligible[0].checked) ||
			(F.Eligible[1].checked))
			{
				EligibleOK = "T";
			}
		else
		{
			eMsg += "Elibility to work in Canada\r";
		}

	var Days = "";
	var MondayOK = "F";
		if ((F.Monday[0].checked) ||
			(F.Monday[1].checked))
		{
			MondayOK = "T";
		}
		else
		{
			eMsg += "Monday availability\r";
		}
		if (F.Monday[0].checked)
		{
			Days += "Monday|";
		}
	var TuesdayOK = "F";
		if ((F.Tuesday[0].checked) ||
			(F.Tuesday[1].checked))
		{
			TuesdayOK = "T";
		}
		else
		{
			eMsg += "Tuesday availability\r";
		}
		if (F.Tuesday[0].checked)
		{
			Days += "Tuesday|";
		}
	var WednesdayOK = "F";
		if ((F.Wednesday[0].checked) ||
			(F.Wednesday[1].checked))
		{
			WednesdayOK = "T";
		}
		else
		{
			eMsg += "Wednesday availability\r";
		}
		if (F.Wednesday[0].checked)
		{
			Days += "Wednesday|";
		}
	var ThursdayOK = "F";
		if ((F.Thursday[0].checked) ||
			(F.Thursday[1].checked))
		{
			ThursdayOK = "T";
		}
		else
		{
			eMsg += "Thursday availability\r";
		}
		if (F.Thursday[0].checked)
		{
			Days += "Thursday|";
		}
	var FridayOK = "F";
		if ((F.Friday[0].checked) ||
			(F.Friday[1].checked))
		{
			FridayOK = "T";
		}
		else
		{
			eMsg += "Friday availability\r";
		}
		if (F.Friday[0].checked)
		{
			Days += "Friday|";
		}

	F.Days.value=Days;

	var Time="";
		if (F.Time[0].checked)
		{
			Time = "Monday morning|";
		}
		if (F.Time[1].checked)
		{
			Time += "Tuesday morning|";
		}
		if (F.Time[2].checked)
		{
			Time += "Wednsesday morning|";
		}
		if (F.Time[3].checked)
		{
			Time += "Thursday morning|";
		}
		if (F.Time[4].checked)
		{
			Time += "Friday morning|";
		}
		if (F.Time[5].checked)
		{
			Time += "Monday afternoon|";
		}
		if (F.Time[6].checked)
		{
			Time += "Tuesday afternoon|";
		}
		if (F.Time[7].checked)
		{
			Time += "Wednesday afternoon|";
		}
		if (F.Time[8].checked)
		{
			Time += "Thursday afternoon|";
		}
		if (F.Time [9].checked)
		{
			Time += "Friday afternoon|";
		}

		F.Times.value=Time;
		
// now check all the mandatory booleans
	if ((DateOK == "T") &&
		(FirstnameOK == "T") &&
		(LastnameOK == "T") &&
		(Address1OK == "T") &&
		(CityOK == "T") &&
		(ProvinceOK == "T") &&
		(PostalCodeOK == "T") &&
		(HomeAreaCodeOK == "T") &&
		(HomePhoneOK == "T") &&
//		(WorkAreaCodeOK == "T") &&
//		(WorkPhoneOK == "T") &&
		(EmailOK == "T") &&
		(CountryOriginOK == "T") &&
		(LangForwardOK == "T") &&
		(From1OK == "T") &&
		(To1OK == "T") &&
		(LondonYearOK == "T") &&
		(LondonMonthOK == "T") &&
		(EligibleOK == "T") &&
		(MondayOK == "T") &&
		(TuesdayOK == "T") &&
		(WednesdayOK == "T") &&
		(ThursdayOK == "T") &&
		(FridayOK == "T"))
		{
			return true;
		}
		else
		{
//alert("DateOK => " + DateOK + 
//	  "\rFirstnameOK => " + FirstnameOK + 
//	  "\rLastnameOK => " + LastnameOK + 
//	  "\nAddress1OK => " +	Address1OK + 
//	  "\nCityOK => " + CityOK +
//	  "\nProvinceOK => " + ProvinceOK +
//	  "\nPostalCodeOK => " + PostalCodeOK +
//	  "\nHomeAreaCodeOK => " + HomeAreaCodeOK +
//	  "\nHomePhoneOK => " + HomePhoneOK +
//	  "\nWorkAreaCodeOK => " + WorkAreaCodeOK +
//	  "\nWorkPhoneOK => " + WorkPhoneOK +
//	  "\nEmailOK => " + EmailOK +
//	  "\nCountryOriginOK => " + CountryOriginOK +
//	  "\nFrom1OK => " + From1OK +
//	  "\nTo1OK => " + To1OK +
//	  "\nMondayOK => " + MondayOK +
//	  "\nTuesdayOK => " + TuesdayOK +
//	  "\nWednesdayOK => " + WednesdayOK +
//	  "\nThursdayOK => " + ThursdayOK +
//	  "\nFridayOK => " + FridayOK);

			alert (eMsg);
			return false;
		}
}

function AddOneLang()
{
var StoreLanguages=""; // this is stored in the LangStore visible textbox
var ForwardLanguages=""; // this is stored in the hidden field LangForward

// first make sure there is something to add
	if (document.interpreter.Language.value != "")
		{
		document.interpreter.LangStore.value += document.interpreter.Language.value + "\n";
		document.interpreter.LangForward.value += document.interpreter.Language.value + "|";
		StoreLanguages += document.interpreter.LangStore.value;
		ForwardLanguages += document.interpreter.LangForward.value;
		//alert("StoreLanguages is " + StoreLanguages + "\nForwardLanguages is " + ForwardLanguages);
// now clear the entry field
		document.interpreter.Language.value="";
// and put focus back in it
		document.interpreter.Language.focus();
// and add it to the Forward hidden field
		//document.interpreter.LangForward.value += ForwardLanguages;
		}
// if they try to add an empty field ...
		document.interpreter.Language.focus();

}

///////////////////////////////
function DelOneLang()
{
	var lastentry="";
	var StoreLanguages="";
	var ForwardLanguages="";
	var StartWith="";
// first make sure there is something to delete
	if (document.interpreter.LangForward.value != "")
	{
// save the original contents
		StartWith=document.interpreter.LangForward.value;
//alert ("StartWith is: " + StartWith);
		var LangArray=StartWith.split("|");
//alert ("LangArray is: " + LangArray);
		var Items=LangArray.length-1;
// how many entries are there?		
		var howmany=(LangArray.length-1);
// where does the last entry StartWith?
		var last=Items;
//alert("We StartWith with " + howmany + " elements");
//alert("last is >" + last + "< LangArray at last-1 is: >" + LangArray[last-1] + "<");

// build the last entry string from the array
		lastentry = LangArray[last-1];
//alert("last entry was " + lastentry);

// delete the contents of the last entry in the array
		LangArray[lastentry]="";
// there is now one less element, but we don't use this anymore
		--howmany;

// erase the contents of both boxes
		document.interpreter.LangStore.value="";
		document.interpreter.LangForward.value="";
// build the contents back without the last entry
		for (i=0;i<=howmany-1;i++)
		{
			StoreLanguages += LangArray[i] + "\n";
			ForwardLanguages += LangArray[i] + "|";
		}
		//alert("StoreLanguages is " + StoreLanguages + "\nForwardLanguages is " + ForwardLanguages);
		document.interpreter.LangStore.value=StoreLanguages;
		document.interpreter.LangForward.value=ForwardLanguages;
		//alert("There are now " + howmany + " elements.");

// get rid of everything if there are no entries left
		if (howmany <=0)
		{
			document.interpreter.LangStore.value="";
		}
	}
// put focus back in the first field
		document.interpreter.Language.focus();
		//alert("StoreLanguages is " + StoreLanguages + "\nForwardLanguages is " + ForwardLanguages);

}

function AddOneDial()
{
var StoreDialects=""; // this is stored in the DialStore visible textbox
var ForwardDialects=""; // this is stored in the hidden field DialForward

// first make sure there is something to add
	if (document.interpreter.Dialect.value != "")
		{
		document.interpreter.DialStore.value += document.interpreter.Dialect.value + "\n";
		document.interpreter.DialForward.value += document.interpreter.Dialect.value + "|";
		StoreDialects += document.interpreter.DialStore.value;
		ForwardDialects += document.interpreter.DialForward.value;
		//alert("StoreDialects is " + StoreDialects + "\nForwardDialects is " + ForwardDialects);
// now clear the entry field
		document.interpreter.Dialect.value="";
// and put focus back in it
		document.interpreter.Dialect.focus();
// and add it to the Forward hidden field
		//document.interpreter.DialForward.value += ForwardDialects;
		}
// if they try to add an empty field ...
		document.interpreter.Dialect.focus();

}

///////////////////////////////
function DelOneDial()
{
	var lastentry="";
	var StoreDialects="";
	var ForwardDialects="";
	var StartWith="";
// first make sure there is something to delete
	if (document.interpreter.DialForward.value != "")
	{
// save the original contents
		StartWith=document.interpreter.DialForward.value;
//alert ("StartWith is: " + StartWith);
		var DialArray=StartWith.split("|");
//alert ("DialArray is: " + DialArray);
		var Items=DialArray.length-1;
// how many entries are there?		
		var howmany=(DialArray.length-1);
// where does the last entry StartWith?
		var last=Items;
//alert("We StartWith with " + howmany + " elements");
//alert("last is >" + last + "< DialArray at last-1 is: >" + DialArray[last-1] + "<");
// build the last entry string from the array
		lastentry = DialArray[last-1];
//alert("last entry was " + lastentry);

// delete the contents of the last entry in the array
		DialArray[lastentry]="";
// there is now one less element, but we don't use this anymore
		--howmany;
// erase the contents of both boxes
		document.interpreter.DialStore.value="";
		document.interpreter.DialForward.value="";
// build the contents back without the last entry
		for (i=0;i<=howmany-1;i++)
		{
			StoreDialects += DialArray[i] + "\n";
			ForwardDialects += DialArray[i] + "|";
		}
		//alert("StoreDialects is " + StoreDialects + "\nForwardDialects is " + ForwardDialects);
		document.interpreter.DialStore.value=StoreDialects;
		document.interpreter.DialForward.value=ForwardDialects;
		//alert("There are now " + howmany + " elements.");

// get rid of everything if there are no entries left
		if (howmany <=0)
		{
			document.interpreter.DialStore.value="";
		}
	}
// put focus back in the first field
		document.interpreter.Dialect.focus();
		//alert("StoreDialects is " + StoreDialects + "\nForwardDialects is " + ForwardDialects);
}

/////////////////////////////////////////////
function chekPCode2(what)
{
	var Chars=0;
	var InString=what.value;
	InString=InString.toUpperCase();
	//alert("Instring is >" + InString + "<");
	//Match=/([A-Z][0-9][A-Z][ ][0-9][A-Z][0-9])/; // we are looking for a format of NAN ANA only in InString
	var PostalCode=/([A-Z][0-9][A-Z] [0-9][A-Z][0-9])/;
	//for (i=0; i < InString.length; i++)
	//{
		//var MatchWhat=InString.charAt(i); // what are we trying to match against
		var MatchWhat=InString;
		var MatchResult=MatchWhat.match(PostalCode); // what is the result of the match
		if (MatchResult != null) // we found a match
		{
			//alert("found a correct character");
			return true;
			pCodeOK = "T";
		}
		else
		{
			alert("Postal Code in wrong format.\rYou entered " + InString);
			pCodeOK = "F";
			what.focus();
			what.select();
			return false;
		}
}		
