// Header
// SiteCatalyst variable
var Prop10 = "Top_Job";
// Set defaults
if (!topjobs_tablewidth) {
	var tableWidth = 150;
}
else {
	var tableWidth = topjobs_tablewidth;
}
if (!topjobs_tableborder) {
var tableBorder = 1;
}
else {
	var tableBorder = topjobs_tableborder;
}
if (!topjobs_tablecellpadding) {
	var tableCellPadding = 1;
}
else {
	var tableCellPadding = topjobs_tablecellpadding;
}
if (!topjobs_tablecellspacing) {
	var tableCellSpacing = 0;
}
else {
	var tableCellSpacing = topjobs_tablecellspacing;
}
if (!topjobs_tablebgcolor) {
	var tableBgcolor = "#ffffff";
}
else {
	var tableBgcolor = topjobs_tablebgcolor;
}

var header = "<LINK REL='STYLESHEET' TYPE='text/css' HREF='http://www.citizentimes.com/topjobs/styles.css'><table border="+tableBorder+" cellpadding="+tableCellPadding+" cellspacing="+tableCellSpacing+" bgcolor="+tableBgcolor+" width="+tableWidth+"><tr><td align=center><table><tr><td align=center class=gcitopjobs><a href='http://citizen-times.gannettonline.com/careerbuilder/index.html' target=_blank><img src='http://www.citizentimes.com/topjobs/header.gif' border=0></a><hr size=1 color=000066 noshade></td></tr>";

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

// All the postings
var allPostings = new Array("placeholder"
, Array('Fuel Truck Driver Needed for Asheville area', '', 'Fuel Truck Driver Needed for Asheville a...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3F38H6C5NBK3MB365W&lr=cbga_ncm&siteid=cbga_ncm060')
, Array('JOBS! ADVANCEMENT! GREAT PAY!', '', 'JOBS! ADVANCEMENT! GREAT PAY! Machine Sh...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3H6NZ6CVRS67VNKRL2&lr=cbga_ncm&siteid=cbga_ncm060')
, Array('FT Bookkeeper/Human Resource', '', 'FT Bookkeeper/ Human Resource Duties inc...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3I05376TGR975476W0&lr=cbga_ncm&siteid=cbga_ncm060')
, Array('ROCKWELL AUTOMATION QUALITY ASSURANCE MANAGER Marion, NC B.S', '', 'ROCKWELL AUTOMATION QUALITY ASSURANCE MA...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3G64270ZD7706QDLNY&lr=cbga_ncm&siteid=cbga_ncm060')
, Array('CONSTRUCTION SUPERINTENDENT', '', 'CONSTRUCTION SUPERINTENDENT Established ...', 'http://www.careerbuilder.com/jobseeker/jobs/JobDetails.aspx?Job_DID=J3F2ZB5Z5MT22SQH6WY&lr=cbga_ncm&siteid=cbga_ncm060')
);
// Footer

var footer = "<tr><td class=gcitopjobs><a href=\"http://citizen-times.gannettonline.com/topjobs/detail/NCM-detail-v1.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><tr><td><center><a href=\"http://citizen-times.gannettonline.com/citizen-times/content/AboutTopJobs.html\" target=_blank><font class=gcitopjobs><b>About Top Jobs</b></font></a></center></td></tr></table></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></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();
