// chekform5.js
// called from the resume script

// Created for London Executive Consultants by Softouch Information Services 2001-05
// London, Ontario
// w: www.softouch.on.ca
// e: softouch@softouch.on.ca
// v: 519-438-5887

// Checks form data sent from resume script for mandatory fields.
// Generates dynamic job position select list

function Chek4Alpha(what)
{
	var Alpha=0;
	var InString=what.value.toString();
	var InStringLow = InString.toLowerCase();
	var Entry = what.name;
	Match=/[a-zA-Z]/; // we are looking for 1 or more alpha chars in InString
	for (i=0; i < InStringLow.length; i++)
	{
		var MatchWhat=InStringLow.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
		{
			Alpha++;
		}
	}
	if (Alpha >= 1)
	{
		return true;
	}
	else
	{
		alert(Entry + " must have at least 1 alpha.");
		return false;
	}
}		

/////////////////////////
function IsEmpty(what)
{
	var InString = what.value;
	var Entry = what.name;
	if (InString == null || InString == "")
	{
		return true;
	}
	return false;
}
/////////////////////////
function IsDigit(what)  
{
var InString=what.value;
var entry=what.name;

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

///////////////////

function chekForm(F)
{
	// find out what location we are checking
	var Location = document.Resume.Location.text;
	
	// set all booleans to false
	var eMsg = 'The following fields were empty:\n\n';
	var LastnameOK = 'F';
	var AddressOK = 'F';
	var CityOK = 'F';
	var ProvinceOK = 'F';
	var PostalCodeOK = 'F';
	var CountryOK = 'F';
	var HomeAreaCodeOK = 'F';
	var HomePhoneOK = 'F';
	var EmailOK = 'F';
	var LevelOneOK = 'F';

// this is the only one defaulting to true
	var PositionDesiredOK = 'T';

	var EmployedOK = 'F';
	var RecentEmployerOK = 'F';
	var CompanyOK = 'F';
	var IndustryOK = 'F';
	var Years_ExperienceOK = 'F';
	var Reason_For_ChangeOK = 'F';
	var Base_SalaryOK = 'F';
	var Minimum_Accepted_SalaryOK = 'F';
	var FlexibleOK = 'F';
	var CanWorkUSOK = 'F';
	var CanWorkCanadaOK = 'F';
	var WhereFromOK = 'F';
	var OKtoNetworkOK = 'F';
	var UploadOK = 'F';

//	if (IsEmpty(F.First_Name)) // || (!Chek4Alpha(F.First_Name)) )
//	{
//		eMsg += 'First name\r';
//	}
//	else
//	{
//		FirstnameOK = 'T'; // it is false that first name is empty
//	}
	

	if (IsEmpty(F.Last_Name)) // || (!Chek4Alpha(F.Last_Name)) )
	{
		eMsg += 'Last name\r';
	}
	else
	{
		LastnameOK = 'T';
	}

	if (F.Address.value == '')
	{
		eMsg += 'Address\r';
	}
	else
	{
		AddressOK = 'T';
	}

	if (F.City.value == '')
	{
		eMsg += 'City\r';
	}
	else
	{
		CityOK = 'T';
	}

	if (F.PCode.value == '')
	{
		eMsg += 'Postal Code / ZIP\r';
	}
	else
	{
		PostalCodeOK = 'T';
	}

	if (F.Country.options[F.Country.selectedIndex].value == "")
		{
			eMsg += "Country\r";
		}
	else
		{
			CountryOK="T";
		}

	if ((F.Country.options[F.Country.selectedIndex].value == "USA") || (F.Country.options[F.Country.selectedIndex].value == "Canada"))
		{
			if ((F.State.options[F.State.selectedIndex].value == "") 
			|| (F.State.options[F.State.selectedIndex].value == "International"))
			{
				eMsg += "State / Province\r";
			}
			else
			{
				ProvinceOK="T";
				CountryOK="T";
			}
		}
	if (((F.Country.options[F.Country.selectedIndex].value != "USA") 
		&& (F.Country.options[F.Country.selectedIndex].value != "Canada")
		&& (F.Country.options[F.Country.selectedIndex].value != ""))) // if Country not blank and other than USA or Canada : no province required
		{
			{
				F.State.options[F.State.selectedIndex].value="International";
				ProvinceOK="T";
				CountryOK="T";
			}
		}
		

	if (F.Home_AreaCode.value == '')
	{
		eMsg += 'Home Area Code\r';
	}
	else
	{
		HomeAreaCodeOK = 'T';
	}

	if (F.Home_Phone.value == '')
	{
		eMsg += 'Home Phone Number\r';
	}
	else
	{
		HomePhoneOK = 'T';
	}

	if (F.Email.value == '')
	{
		eMsg += 'Email\r';
	}
	else
	{
		EmailOK = 'T';
	}

// Since LEC now accepts multiple position titles
// we must check for them separate
// Use the Location field of Resume to see where we are:

if (F.Location.value == "LEC")
{
//	var EducationPicks="";
//	for (var j=0; j < document.Resume.EducationPicks.options.length; j++)
//	{
//		if (document.Resume.EducationPicks.options[j].selected)
//		{
//			//EducationOK = 'T';
//			EducationPicks += document.Resume.EducationPicks.options[j].text + ',';
//			document.Resume.Education.value = EducationPicks;
//		}
//	}


	var LevelOnePicks="";
	for (var j=0; j < document.Resume.LevelOnePicks.options.length; j++)
	{
		if (document.Resume.LevelOnePicks.options[j].selected)
		{
			LevelOneOK = 'T';
//			LevelOnePicks += document.Resume.LevelOnePicks.options[j].text + ',';
//			document.Resume.LevelOne.value = LevelOnePicks;
		}
	}


	for (var i=0; i < F.CurrentPositionPicks.length; i++)
	{
		if (( F.CurrentPositionPicks.options[i].value == '') && (F.OtherPosition.value == ''))
		{
			PositionDesiredOK = 'F';
		}
	}

// must choose either something in current list OR other position OR both
	for (var i=0; i < F.CurrentPositionPicks.length; i++)
	{
		if ((F.CurrentPositionPicks.options[i].value == 'Other') && (F.OtherPosition.value == ''))
		{
			PositionDesiredOK = 'F';
		}
	}

// is anything other than 'Other' selected?
	for (var i=1; i < F.CurrentPositionPicks.length; i++)
	{
		if (F.CurrentPositionPicks.options[i].selected)
		{
			PositionDesiredOK = 'T';
		}
	}
	
// if there's anything in the other field, everything is OK
	if (! F.OtherPosition.value == '')
	{
		PositionDesiredOK = 'T';
	}
}

else // we are not at LEC
{
		if (F.CurrentPositionPicks.value == '')
		{
			//eMsg += "Position Desired\r";
			PositionDesiredOK = 'F';
		}
		else
		{
			PositionDesiredOK = 'T';
		}
}

	if (PositionDesiredOK == 'F')
	{
		if (F.Location.value == "LEC")
		{
			eMsg += "Most Recent Job Title\r";
		}
		else
		{
			eMsg += "Position Desired\r";
		}
	}


	if (IsEmpty(F.Employed.options[F.Employed.selectedIndex]))
	{
		eMsg += 'Current Employment\r';
	}
	else
	{
		EmployedOK = 'T';
	}

	if (F.Recent_Employer.value == '')
	{
		eMsg += 'Most Recent Employer\r';
	}
	else
	{
		RecentEmployerOK = 'T';
	}

	if (F.Company_Location.value == '')
	{
		eMsg += 'Company Location\r';
	}
	else
	{
		CompanyOK = 'T';
	}

	if (F.Industry.value == '')
	{
		eMsg += 'Industry\r';
	}
	else
	{
		IndustryOK = 'T';
	}

	if (F.Years_Experience.value == '')
	{
		eMsg += 'Years of Experience\r';
	}
	else
	{
		Years_ExperienceOK = 'T';
	}

	if (F.Reason_For_Change.value == '')
	{
		eMsg += 'Reason for Change\r';
	}
	else
	{
		Reason_For_ChangeOK = 'T';
	}

	if ((F.Base_Salary.value == '') || (F.Base_Salary.value == '0'))
	{
		eMsg += 'Base Salary\r';
	}
	else
	{
		Base_SalaryOK = 'T';
	}

	if ((F.Minimum_Accepted_Salary.value == '') || (F.Minimum_Accepted_Salary.value == '0'))
	{
		eMsg += 'Minimum Acceptable Salary\r';
	}
	else
	{
		Minimum_Accepted_SalaryOK = 'T';
	}

	//if (F.Flexible.value=="")
	if (IsEmpty(F.Flexible.options[F.Flexible.selectedIndex]))
	{
		eMsg += 'Moving Flexibility\r';
	}
	else
	{
		FlexibleOK = 'T';
	}

	if (IsEmpty(F.CanWorkUS.options[F.CanWorkUS.selectedIndex]))
	{
		eMsg += 'Work in US\r';
	}
	else
	{
		CanWorkUSOK = 'T';
	}

	if (IsEmpty(F.CanWorkCanada.options[F.CanWorkCanada.selectedIndex]))
	{
		eMsg += 'Work in Canada\r';
	}
	else
	{
		CanWorkCanadaOK = 'T';
	}

	if (IsEmpty(F.WhereFrom.options[F.WhereFrom.selectedIndex]))
	{
		eMsg += 'From Workopolis site\r';
	}
	else
	{
		WhereFromOK = 'T';
	}

	if (F.OKtoNetwork.value == '')
	{
		eMsg += 'OK to Network\r';
	}
	else
	{
		OKtoNetworkOK = 'T';
	}

	if (F.Upload.value == '')
	{
		eMsg += 'File to Upload\r';
	}
	else
	{
		UploadOK = 'T';
	}

//for debugging purposes only ...
/*
alert (
//  '\nFirstnameOK => ' + FirstnameOK + 
  '\nLastnameOK => ' + LastnameOK + 
  '\nAddressOK => ' +	AddressOK + 
  '\nCityOK => ' + CityOK +
  '\nProvinceOK => ' + ProvinceOK +
  '\nCountryOK => ' + CountryOK +
  '\nPostalCodeOK => ' + PostalCodeOK +
  '\nHomeAreaCodeOK => ' + HomeAreaCodeOK +
  '\nHomePhoneOK => ' + HomePhoneOK +
  '\nEmailOK => ' + EmailOK +
  '\nLevelOneOK => ' + LevelOneOK +
  '\nPositionDesiredOK => ' + PositionDesiredOK +
  '\nEmployedOK => ' + EmployedOK +
  '\nRecentEmployerOK => ' + RecentEmployerOK +
  '\nCompanyOK => ' + CompanyOK +
  '\nIndustryOK => ' + IndustryOK +
  '\nYears_ExperienceOK => ' + Years_ExperienceOK +
  '\nReason_For_ChangeOK => ' + Reason_For_ChangeOK +
  '\nBase_SalaryOK => ' + Base_SalaryOK +
  '\nMinimum_Accepted_SalaryOK = ' + Minimum_Accepted_SalaryOK +
  '\nFlexibleOK => ' + FlexibleOK +
  '\nCanWorkUSOK => ' + CanWorkUSOK +
  '\nCanWorkCanadaOK => ' + CanWorkCanadaOK +
  '\nOKtoNetworkOK => ' + OKtoNetworkOK +
  '\nUploadOK => ' + UploadOK +
  '\nWhereFromOK => ' + WhereFromOK
   )
*/

// now check all the booleans
	if (
	(LastnameOK == 'T') &&
	(AddressOK == 'T') &&
	(CityOK == 'T') &&
	(ProvinceOK == 'T') &&
	(CountryOK == 'T') &&
	(PostalCodeOK == 'T') &&
	(HomeAreaCodeOK == 'T') &&
	(HomePhoneOK == 'T') &&
	(EmailOK == 'T') &&
	(PositionDesiredOK == 'T') &&
//	(LevelOneOK == 'T') &&
	(EmployedOK == 'T') &&
	(RecentEmployerOK == 'T') &&
	(CompanyOK == 'T') &&
	(IndustryOK == 'T') &&
	(Years_ExperienceOK == 'T') &&
	(Reason_For_ChangeOK == 'T') &&
	(Base_SalaryOK == 'T') &&
	(Minimum_Accepted_SalaryOK == 'T') &&
	(FlexibleOK == 'T') &&
	(CanWorkUSOK == 'T') &&
	(CanWorkCanadaOK == 'T') &&
	(OKtoNetworkOK == 'T') &&
	(UploadOK == 'T') &&
	(WhereFromOK == 'T')
	)
	{
		return true;
	}
	else
	{
		alert (eMsg);
		return false;
	}
} // end function chekForm

//////////////////////////////////////////////
// simulates creating a 2-dimensional array
function LevelOne(Name)
{
	this.Name = Name;
}

function MakeSelect()
{
// This dynamically creates the <option> values from the TopLevel array
// in the Resume form. It isn't used though.
	var display="";
	for (var i=0; i < TopLevel.length; i++)
	{
		display += "<option>" + TopLevel[i].Name;
	}
	document.write(display);
}


//////////////////////////////////////////////////
// use for debugging
// onSubmit="return chekPosition()"
function chekPosition()
{
var msg = "You chose ";
	// first get the LevelOne choice
	for (var j=0; j < document.Resume.LevelOnePicks.options.length; j++)
	{
		if (document.Resume.LevelOnePicks.options[j].selected)
		{
			msg += document.Resume.LevelOnePicks.options[j].text + "\n";
		}
	}

	// now get the CurrentPositionPicks choice
	for (var i=0;i<document.Resume.CurrentPositionPicks.options.length;i++)
	{
		if (document.Resume.CurrentPositionPicks.options[i].selected)
		{
			msg += document.Resume.CurrentPositionPicks.options[i].text + "\n";
		}
	}
	alert(msg);
	return false;
}


////////////////////////////////////////////////////////
function updateList(what) 
{
	// This dynamically populates the CurrentPositionPicks select box in the resume page
	// depending on what one was selected in the LevelOne select box.
	for (var i=0;i<document.Resume.CurrentPositionPicks.length;i++) // empty the list
	{
		document.Resume.CurrentPositionPicks.options.length=0;
	}

	// LevelOnePicks is the top level select box in the resume form
	// CurrentPositionPicks is the dynamically generated select list
	var CurrentPositionPicks=document.Resume.CurrentPositionPicks;
	for (var i=0;i<document.Resume.LevelOnePicks.length;i++)
	{
		if (document.Resume.LevelOnePicks.options[i].selected)
		{
			var ThisList=eval(TopLevel[i].Name); // get the array name to use
			for (var j=0; j < ThisList.length; j++)
			{
				CurrentPositionPicks.options[j]=new Option;
				CurrentPositionPicks.options[j].text=ThisList[j];
			}
		}
	}
}

////////////////////////////
function BrowseHelp()
{
	doNew();
}

function PositionHelp()
{
	var Message = "To select more than one choice\nhold down the Ctrl key while clicking.";
	alert (Message);
}

function KeyWordsHelp()
{
	var Message = "Use this box to enter words that describe your skills and experience.\n\n";
	Message += "For example, if you were a web application programmer, you might enter:\n";
	Message += "'web, CGI, programmer, Python, Perl, PHP, Java, JavaScript, CSS'";
	alert (Message);
}


function doNew()
{
var MyWin;
var w=700;
var h=500;
var newx=(screen.availWidth - w) / 2;
var newy=(screen.availHeight - h) / 2;
	if (!MyWin || MyWin.closed)
	{
		MyWin=window.open("","result","scrollbars,width=700,height=500");
		MyWin.moveTo(newx,newy);
		MyWin.focus();
	var Message="<html><body bgcolor='#CCCCCC'>\n";
	Message += "<title>Resume Upload</title>\n";
	Message += "<center><font face='verdana,arial,sans-serif' size='4' color='black'>\n";
	Message += "<strong>DO NOT PASTE YOUR RESUME INTO THIS BOX, OR ANY OTHER BOX ON THIS WEBSITE.\n";
	Message += "</strong></center><p>\n";
	Message += "<ol start='1' type='1'>\n";
	Message += "<li>Press the 'Browse' button to see a list of files on your computer.<br>\n";
	Message += "<li>Find the file that is your resume.<br>\n";
	Message += "<li>Select your resume by clicking it once with the left mouse button.<br>\n";
	Message += "<li>Press the 'Open' button in the window - this will fill in the empty box with your file name.<br>\n";
	Message += "<li>Do not edit this box once it has been filled in.<br>\n";
	Message += "<li>Fill out the rest of this form, and press the 'submit' button at the bottom of this form.<br>\n";
	Message += "<li>Wait a minute or so for your resume to be uploaded.<br>\n";
	Message += "<li>You will either see a 'Thank You' page or an error page once completed.<br>\n";
	Message += "<li>An acknowledgement email will be sent to the address you supplied.\n";
	Message += "</ol>\n";
	Message += "<p>\n";
	Message += "NOTE: Acceptable file types of resumes:<p>\n";
	Message += "Text/ASCII<br>\n";
	Message += "Microsoft Word document<br>\n";
	Message += "WordPerfect document<br>\n";
	Message += "RTF file";
	Message += "</font></body></html>";
	MyWin.document.write(Message);
	MyWin.document.close();
	return true;
	}
	else
	{
		MyWin.focus();
	}
}
