// Header
var header = "<table><tr><td align=center class=gcitopjobs><a href='http://tennessean.gannettonline.com/careerbuilder/index.html' target=_blank><img src='http://www.tennessean.com/topjobs/images/topjobs.jpg' border=0></a><hr size=1 color=000066 noshade></td></tr>";

var allHeader = "<html><head><LINK REL='STYLESHEET' TYPE='text/css' HREF='http://www.tennessean.com/styles/main.css'><title>Top Jobs</title></head><body><table width=250><tr><td align=center><a href='http://tennessean.gannettonline.com/careerbuilder/index.html' target=_blank><img src='http://www.tennessean.com/topjobs/images/topjobs.jpg' border=0></a><hr size=1 color=000066 noshade></td></tr>";

// All the postings
var allPostings = new Array("placeholder"
, Array('R.N. Nurse ManagerSeeking applicants', '', 'R.N. Nurse Manager Seeking applicants fo...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X3F86BHC6QGFJ17VP&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Recruiting Open House', '', 'Recruiting Open House Wednesday, Februar...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X7326N3BVV87Z9X0P&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Mechanic', '', 'Mechanic Northwest-based trucking co. is...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X2B66B71FHV303FL8&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Tire Maintenance Specialist', '', 'Tire Maintenance Specialist Northwest-ba...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X49N6BL31B3PN6ZFN&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('RNPRN circulator position available', '', 'RN PRN circulator position available at ...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W0ZP6MWPXJ677RTJ3&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('CNT\'s', '', 'West Meade Place, 120 bed facility in Be...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W24P691MMV2KYZ95V&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Psychiatric nurse practitioner', '', 'Psychiatric nurse practitioner Needed to...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X0K16C34DRV72YQBZ&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Medical salesGrowing respiratory', '', 'Medical sales Growing respiratory servic...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X4CZ6RRNKCZH00RFY&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Shelton State Community College', '', 'Shelton State Community College is accep...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X2H86N5M8SZ8TF0D8&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Technologist AssistantImaging center', '', 'Technologist Assistant Imaging center is...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X7FF6NNXCSJ0TH4RX&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('RNs', '', 'ALL SHIFTS for SNF and ICF nursing home....', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X4BB713K3G50FDF0V&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('RNs', '', 'ALL SHIFTS for SNF and ICF nursing home....', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X77Y7535WVJR0VV07&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Med Lab Tech', '', 'Genetic Assays has FT/PT openings for da...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X1F865PL2BWWNQ1K6&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('COLLECTORNeeded for healthcare company in Brentwood', '', 'COLLECTOR Needed for healthcare company ...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X65560QTB9ZQHLS8F&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('HISTOTECHNOLOGISTPrivate laboratory', '', 'HISTOTECHNOLOGIST Private laboratory see...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X2HJ5Y02LKKZYXYBS&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('The State of Tennessee Department', '', 'The State of Tennessee Department of Env...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X0F261JRH105VS0X1&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('SENIOR GEOTECHNICAL', '', 'SENIOR GEOTECHNICAL ENGINEER Engineering...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W1WS70NYYC78VP76Q&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('ACCOUNTING MANAGER', '', 'ACCOUNTING MANAGER Parman Lubricants is ...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W7FY64SL6DHB91WB1&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('RN/LPN', 'Mt. Juliet Health Care', 'RN/LPN If you want to make a positive im...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X6696CR7MXRHHB5S4&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('ADMISSIONS COORDINATOR', 'Mt. Juliet Healthcare', 'ADMISSIONS COORDINATOR 100 Bed SNF seeks...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W10D5VY2X2C17VTGF&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Manufacturing Engineer', '', 'Manufacturing Engineer Small aggressive ...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W41W72XDVNSLN5N2H&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Admin Assistant', '', 'Part-time Admin Assist needed for growin...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X42973WCKDSPJCCM1&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('MORTGAGE LOAN', '', 'MORTGAGE LOAN OFFICERS Sign on bonus to ...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W7BP6SPVCXXD3Z6TZ&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Customer Service', '', 'Customer Service Representative Growing ...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W7GT65NDDKQ0YKFLC&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('We\'re Growing Again at ST Paul Travelers!!!', '', 'D...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W0SG64FQ0XV2X4DJY&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Meeting Planning DirectorUnited Methodist agency seeks Conf', '', 'Meeting Planning Director United Methodi...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W43R6YWFLS7LSC4PL&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Registered', '', 'Technologist Busy orthopaedic clinic see...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W2QS6908J85X1QYNB&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Dental ReceptionistExperienced', '', 'Dental Receptionist Experienced Needed f...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X27H785DC379MLY4H&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('CIVIL CAD TECH4', '', 'CIVIL CAD TECH 4 years experience in gen...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X5N46SPL26WT4BKW8&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('CUSTOMER', '', 'CUSTOMER SERVICE Excellent professional ...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X7D271KH27377RP96&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Construction Supervisor', '', '...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3X4N26F5B94BGL8QVW&lr=cbga_tnt&siteid=cbga_tnt060')
, Array('Customer Service SupervisorEstablished', '', 'Customer Service Supervisor Established ...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3W7W46CGFC8CN9FWMZ&lr=cbga_tnt&siteid=cbga_tnt060')
);
// Footer

var footer = "<tr><td class=gcitopjobs><a href=\"http://tennessean.gannettonline.com/topjobs/detail/TNT-detail.html?topjobscount=99999\" target=\"topjobs\" onClick=\"window.open('','topjobs','directories=no,height=500,width=300,scrollbars=1,location=no,resizable=yes,screenx=15,screeny=15,toolbar=no,opener=orig')\">All Top Jobs</a></td></tr></table>";

var allFooter = "</table></body></html>";

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

function display_postings() {

	// Handle no postings situation

	if (allPostings.length == 1) {
		document.write(header);
	document.write("<tr><td><center><font class=gcitopjobs>Watch for Top Jobs coming to this space soon.</font></center><hr size=1 color=000066 noshade></td></tr>");
	document.write("</table>");
	return;
}


if (!FORM_DATA['topjobscount']) {
	if (!topjobs_count) {
		var displayCount = 5;
	}
	else {
		var displayCount = topjobs_count;
	}
}
else {
	var displayCount = FORM_DATA['topjobscount'];
}
// Create target array
var displayPostings;
var allPostingsCount = allPostings.length;
var i;
if (displayCount == 99999) {
	document.write(allHeader);
	// Remember array entry 0 is placeholder, so start at index 1
	for (i = 1; i < allPostingsCount; i++) {
		if (!allPostings[i][1]) {
			document.write("<tr><td><font class=gcitopjobs><a href='" + allPostings[i][3] + "'target=_blank><b>" + allPostings[i][0] + "</b><br>" +
				allPostings[i][2] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
		}
		else {
			document.write("<tr><td><font class=gcitopjobs><a href='" + allPostings[i][3] + "'target=_blank><b>" + allPostings[i][0] + "</b><br>" +
				allPostings[i][1] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
		}
	}
	document.write(allFooter);
}
else {
	// Delete array entry 0 ("placeholder")
	for (i = 0; i < allPostings.length - 1; i++)
		allPostings[i] = allPostings[i + 1];
		allPostingsCount--;

		document.write(header);
		displayPostings = new Array();
		while (displayCount > 0 && allPostingsCount > 0) {
			// Move a random entry from allPostings to displayPostings
			var targetIndex = Math.floor(Math.random() * allPostingsCount %
				allPostingsCount);
			displayPostings[displayPostings.length] = allPostings[targetIndex];

			for (i = targetIndex; i < allPostings.length - 1; i++)
				allPostings[i] = allPostings[i + 1];
			allPostingsCount--;
			displayCount--;
		}
		// Display Job Title only
		if (topjobs_option == 1) {
			for (i = 0; i < displayPostings.length; i++) {
				document.write("<tr><td><font class=gcitopjobs><a href='" +
					displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][0] +
					"</b><br></a></font><hr size=1 color=000066 noshade></td></tr>");
			}
		}
		// Display Employer Name only. If Employer name does not exist display Job Title
		else if (topjobs_option == 2) {
			for (i = 0; i < displayPostings.length; i++) {
				if (!displayPostings[i][1]) {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][0] +
						"</b><br></a></font><hr size=1 color=000066 noshade></td></tr>");
				}
				else {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][1] +
						"</b><br></a></font><hr size=1 color=000066 noshade></td></tr>");
				}
			}
		}
		// Display Description only
		else if (topjobs_option == 3) {
			for (i = 0; i < displayPostings.length; i++) {
				document.write("<tr><td><font class=gcitopjobs><a href='" +
					displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][2] +
					"</b><br></a></font><hr size=1 color=000066 noshade></td></tr>");
			}
		}
		// Display Job Title followed by Employer Name. If Employer name does not exist display Job Description
		else if (topjobs_option == 4) {
			for (i = 0; i < displayPostings.length; i++) {
				if (!displayPostings[i][1]) {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][0] + "</b><br>" +
						displayPostings[i][2] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
				else {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][0] + "</b><br>" +
						displayPostings[i][1] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
			}
		}
		// Display Job Title followed by Job Description
		else if (topjobs_option == 5) {
			for (i = 0; i < displayPostings.length; i++) {
				document.write("<tr><td><font class=gcitopjobs><a href='" +
					displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][0] + "</b><br>" +
					displayPostings[i][2] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
			}
		}
		// Display Employer Name followed by Job Title. If Employer name does not exist display Job Description
		else if (topjobs_option == 6) {
			for (i = 0; i < displayPostings.length; i++) {
				if (!displayPostings[i][1]) {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][2] + "</b><br>" +
						displayPostings[i][0] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
				else {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][1] + "</b><br>" +
						displayPostings[i][0] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
			}
		}
		// Display Employer Name followed by Job Description. If Employer name does not exist display Job Title
		else if (topjobs_option == 7) {
			for (i = 0; i < displayPostings.length; i++) {
				if (!displayPostings[i][1]) {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][0] + "</b><br>" +
						displayPostings[i][2] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
				else {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][1] + "</b><br>" +
						displayPostings[i][2] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
			}
		}
		// Display Job Description followed by Job Title
		else if (topjobs_option == 8) {
			for (i = 0; i < displayPostings.length; i++) {
				document.write("<tr><td><font class=gcitopjobs><a href='" +
					displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][2] + "</b><br>" +
					displayPostings[i][0] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
			}
		}
		// Display Job Description followed by Employer Name. If Employer name does not exist display Job Title
		else if (topjobs_option == 9) {
			for (i = 0; i < displayPostings.length; i++) {
				if (!displayPostings[i][1]) {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][2] + "</b><br>" +
						displayPostings[i][0] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
				else {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][2] + "</b><br>" +
						displayPostings[i][1] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
			}
		}
		// Default to Job Title followed by Employer Name. If Employer name does not exist display Job Description
		else {
			for (i = 0; i < displayPostings.length; i++) {
				if (!displayPostings[i][1]) {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][0] + "</b><br>" +
						displayPostings[i][2] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
				else {
					document.write("<tr><td><font class=gcitopjobs><a href='" +
						displayPostings[i][3] + "' target=_blank><b>" + displayPostings[i][0] + "</b><br>" +
						displayPostings[i][1] + "</a></font><hr size=1 color=000066 noshade></td></tr>");
				}
			}
		}
		document.write(footer);
	}
}


function createRequestObject() {
	FORM_DATA = new Object();
	// The Object (Array) where our data will be stored.
	separator = ',';
	// The token used to separate data from multi-select inputs
	query = '' + this.location;
	qu = query
	// Get the current URL so we can parse out the data.
	// Adding a null-string '' forces an implicit type cast
	// from property to string, for NS2 compatibility.
	query = query.substring((query.indexOf('?')) + 1);
	// Keep everything after the question mark '?'.
	if (query.length < 1) { return false; } // Perhaps we got some bad data?
	keypairs = new Object();
	numKP = 1;
	// Local vars used to store and keep track of name/value pairs
	// as we parse them back into a usable form.
	while (query.indexOf('&') > -1) {
		keypairs[numKP] = query.substring(0,query.indexOf('&'));
		query = query.substring((query.indexOf('&')) + 1);
		numKP++;
		// Split the query string at each '&', storing the left-hand side
		// of the split in a new keypairs[] holder, and chopping the query
		// so that it gets the value of the right-hand string.
	}
	keypairs[numKP] = query;
	// Store what's left in the query string as the final keypairs[] data.
	for (i in keypairs) {
		keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
		// Left of '=' is name.
		keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
		// Right of '=' is value.
		while (keyValue.indexOf('+') > -1) {
			keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
			// Replace each '+' in data string with a space.
		}
		keyValue = unescape(keyValue);
		// Unescape non-alphanumerics
		if (FORM_DATA[keyName]) {
			FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
			//document.write('The value of ' +keyName+ ' is:'+FORM_DATA[keyName]+'<br>');
			// Object already exists, it is probably a multi-select input,
			// and we need to generate a separator-delimited string
			// by appending to what we already have stored.
		}
		else {
			FORM_DATA[keyName] = keyValue;
			//document.write('The value of ' +keyName+ ' is:'+FORM_DATA[keyName]+'<br>');
			// Normal case: name gets value.
		}
	}
	return FORM_DATA;
}


// MAINLINE

FORM_DATA = createRequestObject();
// This is the array/object containing the GET data.
// Retrieve information with 'FORM_DATA [ key ] = value'.

// Display jobs 
display_postings();

