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.freelance.Language.value != "")
		{
		document.freelance.LangStore.value += document.freelance.Language.value + "\n";
		document.freelance.LangForward.value += document.freelance.Language.value + "|";
		StoreLanguages += document.freelance.LangStore.value;
		ForwardLanguages += document.freelance.LangForward.value;
		//alert("StoreLanguages is " + StoreLanguages + "\nForwardLanguages is " + ForwardLanguages);
// now clear the entry field
		document.freelance.Language.value="";
// and put focus back in it
		document.freelance.Language.focus();
// and add it to the Forward hidden field
		//document.freelance.LangForward.value += ForwardLanguages;
		}
// if they try to add an empty field ...
		document.freelance.Language.focus();

}

///////////////////////////////
function DelOneLang()
{
	var lastentry="";
	var StoreLanguages="";
	var ForwardLanguages="";
	var StartWith="";
// first make sure there is something to delete
	if (document.freelance.LangForward.value != "")
	{
// save the original contents
		StartWith=document.freelance.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.freelance.LangStore.value="";
		document.freelance.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.freelance.LangStore.value=StoreLanguages;
		document.freelance.LangForward.value=ForwardLanguages;
		//alert("There are now " + howmany + " elements.");

// get rid of everything if there are no entries left
		if (howmany <=0)
		{
			document.freelance.LangStore.value="";
		}
	}
// put focus back in the first field
		document.freelance.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.freelance.Dialect.value != "")
		{
		document.freelance.DialStore.value += document.freelance.Dialect.value + "\n";
		document.freelance.DialForward.value += document.freelance.Dialect.value + "|";
		StoreDialects += document.freelance.DialStore.value;
		ForwardDialects += document.freelance.DialForward.value;
		//alert("StoreDialects is " + StoreDialects + "\nForwardDialects is " + ForwardDialects);
// now clear the entry field
		document.freelance.Dialect.value="";
// and put focus back in it
		document.freelance.Dialect.focus();
// and add it to the Forward hidden field
		//document.freelance.DialForward.value += ForwardDialects;
		}
// if they try to add an empty field ...
		document.freelance.Dialect.focus();

}

///////////////////////////////
function DelOneDial()
{
	var lastentry="";
	var StoreDialects="";
	var ForwardDialects="";
	var StartWith="";
// first make sure there is something to delete
	if (document.freelance.DialForward.value != "")
	{
// save the original contents
		StartWith=document.freelance.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.freelance.DialStore.value="";
		document.freelance.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.freelance.DialStore.value=StoreDialects;
		document.freelance.DialForward.value=ForwardDialects;
		//alert("There are now " + howmany + " elements.");

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

/////////////////////////////////////
function isDecimalNumber(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 and decimal point only.");
			document.freelance[entry].focus();
			document.freelance[entry].select();
			return false;
		}
	}
	return true;
}

//////////////////////////////////////////
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 chekBirthDate(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 >= 8)
	{
		return true;
		BirthDateOK = "T";
	}
	else
	{
		alert("Birth Date must have at least 8 digits.");
		BirthDateOK = "F";
		what.focus();
		what.select();
		return false;
	}
}		
 
///////////////////////// check for empty field
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.freelance.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 GenderOK = "F";
//		if ((F.Gender[0].checked) ||
//			F.Gender[1].checked)
//		{
//			GenderOK="T";
//		}
//		else
//		{
//			eMsg += "Gender\r";
//		}
			
	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 MornAvailOK = "F";
	var AnoonAvailOK = "F";
		if ((F.MornAvail[0].checked) ||
			(F.MornAvail[1].checked) ||
			(F.AnoonAvail[0].checked) ||
			(F.AnoonAvail[1].checked))
			{
				MornAvailOK = "T";
				AnoonAvailOK = "T";
			}
			else
			{
				eMsg += "Daytime Availability\r";
			}
	var EMGnightsOK = "F";
	var SaturdayOK = "F";
	var SundayOK = "F";
		if ((F.EMGnights[0].checked) ||
			(F.EMGnights[1].checked) ||
			(F.Saturday[0].checked) ||
			(F.Saturday[1].checked) ||
			(F.Sunday[0].checked) ||
			(F.Sunday[1].checked))
			{
				EMGnightsOK = "T";
				SaturdayOK = "T";
				SundayOK = "T";
			}
			else
			{
				eMsg += "Emergency / After Hours Availability\r";
			}
	var UnavailOK = "F";
	var LicenseOK = "F";
		if ((F.License[0].checked) ||
			(F.License[1].checked))
			{
				LicenseOK = "T";
			}
		else
		{
			eMsg += "Driver's License\r";
		}
	var CarOK = "F";
		if ((F.Car[0].checked) ||
			(F.Car[1].checked))
			{
				CarOK = "T";
			}
			else
			{
				eMsg += "Car available\r";
			}
	var OutsideOK = "F";
		if ((F.Outside[0].checked) ||
			(F.Outside[1].checked))
			{
				OutsideOK = "T";
			}
		else
			{
				eMsg += "Out of town assignments\r";
			}
	var Ref1_NameOK = "F";
	var Ref1_OrgOK = "F";
	var Ref1_RelateOK = "F";
	var Ref1_PhoneOK = "F";
//	var Ref2_NameOK = "F";
//	var Ref2_OrgOK = "F";
//	var Ref2_RelateOK = "F";
//	var Ref2_PhoneOK = "F";
//	var Ref3_NameOK = "F";
//	var Ref3_OrgOK = "F";
//	var Ref3_RelateOK = "F";
//	var Ref3_PhoneOK = "F";
	var Reference1OK = "F";
//	var Reference2OK = "F";
//	var Reference3OK = "F";
		if ((F.Ref1_Name.value == "") ||
			(F.Ref1_Org.value == "") ||
			(F.Ref1_Relate.value == "") ||
			(F.Ref1_Phone.value == ""))
//			(F.Ref2_Name.value == "") ||
//			(F.Ref2_Org.value == "") ||
//			(F.Ref2_Relate.value == "") ||
//			(F.Ref2_Phone.value == "") ||
//			(F.Ref3_Name.value == "") ||
//			(F.Ref3_Org.value == "") ||
//			(F.Ref3_Relate.value == "") ||
//			(F.Ref3_Phone.value == ""))
			{
				eMsg += "References\r";
			}
			else
			{
				Reference1OK = "T";
//				Reference2OK = "T";
//				Reference3OK = "T";
			}
				

// now check all the booleans
	if ((DateOK == "T") &&
		(FirstnameOK == "T") &&
		(LastnameOK == "T") &&
//		(GenderOK == "T") &&
		(Address1OK == "T") &&
		(CityOK == "T") &&
		(ProvinceOK == "T") &&
		(PostalCodeOK == "T") &&
		(HomeAreaCodeOK == "T") &&
		(HomePhoneOK == "T") &&
//		(WorkAreaCodeOK == "T") &&
//		(WorkPhoneOK == "T") &&
//		(EmailOK == "T") &&
		(CountryOriginOK == "T") &&
		(LangForwardOK == "T") &&
//		(DialForwardOK == "T") &&
		(Residence1OK == "T") &&
		(MornAvailOK == "T") &&
		(AnoonAvailOK == "T") &&
		(EMGnightsOK == "T") &&
		(SaturdayOK == "T") &&
		(SundayOK == "T") &&
		(LicenseOK == "T") &&
		(CarOK == "T") &&
		(OutsideOK == "T") &&
		(Reference1OK == "T"))
//		(Reference2OK == "T") &&
//		(Reference3OK == "T"))
		{
			return true;
		}
		else
		{
//alert("DateOK => " + DateOK + 
//	  "\rFirstnameOK => " + FirstnameOK + 
//	  "\rLastnameOK => " + LastnameOK + 
//	  "\nGenderOK => " + GenderOK + 
//	  "\nAddress1OK => " +	Address1OK + 
//	  "\nCityOK => " + CityOK +
//	  "\nProvinceOK => " + ProvinceOK +
//	  "\nPostalCodeOK => " + PostalCodeOK +
//	  "\nHomeAreaCodeOK => " + HomeAreaCodeOK +
//	  "\nHomePhoneOK => " + HomePhoneOK +
//	  "\nWorkAreaCodeOK => " + WorkAreaCodeOK +
//	  "\nWorkPhoneOK => " + WorkPhoneOK +
//	  "\nEmailOK => " + EmailOK +
//	  "\nCountryOriginOK => " + CountryOriginOK +
//	  "\nLangForwardOK => " + LangForwardOK +
//	  "\nDialForwardOK => " + DialForwardOK +
//	  "\nResidence1OK => " + Residence1OK +
//	  "\nMornAvailOK => " + MornAvailOK +
//	  "\nAnoonAvailOK => " + AnoonAvailOK +
//	  "\nEMGnightsOK => " + EMGnightsOK +
//	  "\nSaturdayOK => " + SaturdayOK +
//	  "\nSundayOK => " + SundayOK +
//	  "\nLicenseOK => " + LicenseOK +
//	  "\nCarOK => " + CarOK +
//	  "\nOutsideOK => " + OutsideOK +
//	  "\nReference1OK => " + Reference1OK +
//	  "\nReference2OK => " + Reference2OK +
//	  "\nReference3OK => " + Reference3OK);

			alert (eMsg);
			return false;
		}
}

////////////////////////////////// Check postal code format ANA NAN
function chekPcode(userInput)
{
//alert("now entering postal code check");
	var codeOK="F";
	pcodeIn=userInput.value;
	entry=userInput.name;
	pcodeIn=pcodeIn.toUpperCase();
	if ((pcodeIn.length < 7) || (pcodeIn == ""))
		{
		 codeOK="F";
		}
	if (pcodeIn.length == 7)
		{
		  codeOK="T";
		  if ((pcodeIn.charAt(0) < "A") || (pcodeIn.charAt(0) > "Z"))
			{
			  codeOK = "F";
//			  alert("Postal Code 1st character: improper format");
//			  eMessage=eMessage+"Postal Code: Improper format\r";
			}
		  if ((pcodeIn.charAt(1) < "0") || (pcodeIn.charAt(1) > "9"))
			{
			  codeOK = "F";
//			  alert("Second character must be a number");
//			  eMessage=eMessage+"2nd character in Postal Code must be a number\r";
			}
		  if ((pcodeIn.charAt(2) < "A") || (pcodeIn.charAt(2) > "Z"))
			{
			  codeOK = "F";
//			  alert("Third character must be a letter");
//			  eMessage=eMessasge+"3rd character in Postal Code must be a letter\r";
			}
		  if (pcodeIn.charAt(3) != " ")
		  {
			  codeOK = "F";
//			  alert("Fourth character must be a space");
		  }
		  if ((pcodeIn.charAt(4) < "0") || (pcodeIn.charAt(4) > "9"))
			{
			  codeOK = "F";
//			  alert("Fifth character must be a number");
//			  eMessage=eMessage+"4th character in Postal Code must be a number\r";
			}
		  if ((pcodeIn.charAt(5) < "A") || (pcodeIn.charAt(5) > "Z"))
			{
			  codeOK = "F";
//			  alert("Sixth character must be a letter");
//			  eMessage=eMessage + "5th character in Postal Code must be a letter\r";
			}
		  if ((pcodeIn.charAt(6) < "0") || (pcodeIn.charAt(6) > "9"))
			{
			  codeOK = "F";
//			  alert("Seventh character must be a number");
//			  eMessage=eMessage+"6th character in Postal Code must be a number\r";
			}
		}
		if (codeOK == "T")
		{
			return true;
		}
		else 
		{
			userInput.focus();
			userInput.select();
			alert ("Postal code must be in ANA NAN format.\rYou entered " + pcodeIn);
			return false;
		}
	
}

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;
		}
}		
 
