

/***** Functions to sort products tables *****/

// Function to sort products, and job board tables
function sortColumn(strColId, strTable)
{
	// Get script URL & selected state
	switch(strTable)
	{
		case 'research':
			var url = "../../scripts/sortResearch.php";
			var eleCol = document.getElementById(strColId);
			var strSortDirection = eleCol.getAttribute('sort');
			httpRequest("POST", url, true, hr_sortResearch, "&strColId=" + escape(strColId) + "&strSortDirection=" + escape(strSortDirection));
			break;
		case 'rates':
			var url = "../../scripts/sortRates.php";
			var eleCol = document.getElementById(strColId);
			var strSortDirection = eleCol.getAttribute('sort');
			httpRequest("POST", url, true, hr_sortRates, "&strColId=" + escape(strColId) + "&strSortDirection=" + escape(strSortDirection));
			break;
		case 'calculate':
			var url = "../../scripts/sortCalculate.php";
			var eleCol = document.getElementById(strColId);
			var strSortDirection = eleCol.getAttribute('sort');
			httpRequest("POST", url, true, hr_sortCalculate, "&strColId=" + escape(strColId) + "&strSortDirection=" + escape(strSortDirection));
			break;
		case 'certificate':
			var url = "../../scripts/sortCertificate.php";
			var eleCol = document.getElementById(strColId);
			var strSortDirection = eleCol.getAttribute('sort');
			httpRequest("POST", url, true, hr_sortCertificate, "&strColId=" + escape(strColId) + "&strSortDirection=" + escape(strSortDirection));
			break;
		case 'webinars':
			var url = "../scripts/sortWebinars.php";
			var eleCol = document.getElementById(strColId);
			var strSubject = document.getElementById("frmSubject").value;
			var strSortDirection = eleCol.getAttribute('sort');
			httpRequest("POST", url, true, hr_sortWebinars, "&strColId=" + escape(strColId) + "&strSortDirection=" + escape(strSortDirection) + "&strSubject=" + escape(strSubject));
			break;
		case 'questions':
			var url = "../scripts/sortQuestions.php";
			var eleCol = document.getElementById(strColId);
			var strSortDirection = eleCol.getAttribute('sort');
			httpRequest("POST", url, true, hr_sortQuestions, "&strColId=" + escape(strColId) + "&strSortDirection=" + escape(strSortDirection));
			break;
		case 'jobs':
			var url = "../scripts/sortJobs.php";
			var eleCol = document.getElementById(strColId);
			var strState = document.getElementById("frmState").value;
			var strSortDirection = eleCol.getAttribute('sort');
			httpRequest("POST", url, true, hr_sortJobs, "&strColId=" + escape(strColId) + "&strSortDirection=" + escape(strSortDirection) + "&strState=" + escape(strState));
			break;
		case 'articles':
			var url = "../scripts/sortArticles.php";
			var eleCol = document.getElementById(strColId);
			var strIndustry = document.getElementById("frmIndustry").value;
			var strTopic = document.getElementById("frmTopic").value;
			var strSortDirection = eleCol.getAttribute('sort');
			httpRequest("POST", url, true, hr_sortArticles,  "&strColId=" + escape(strColId) + "&strSortDirection=" + escape(strSortDirection) + "&strIndustry=" + escape(strIndustry) + "&strTopic=" + escape(strTopic));
			break;
		default:
			var url = "../../scripts/sortResearch.php";
			var eleCol = document.getElementById(strColId);
			var strSortDirection = eleCol.getAttribute('sort');
			httpRequest("POST", url, true, hr_sortResearch, "&strColId=" + escape(strColId) + "&strSortDirection=" + escape(strSortDirection));
			break;
	}
}

// Function to handle results from table sort
function hr_sortResearch()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblLinks");	// Change id's from table to something useful later
			var eletBody = eleTable.getElementsByTagName("tbody")[0];
			var intTrCnt = eletBody.getElementsByTagName("tr").length;
			var intTrRow = intTrCnt - 1;
			
			// Clear table of previous results
			for(intTrRow; intTrRow >= 0; intTrRow--)
			{
				clearTable(eletBody, intTrRow);
			}
			
			// Results from the server
			var xmlDoc = request.responseXML;
			//alert(xmlDoc);
			
			var rowCnt = xmlDoc.getElementsByTagName('product-info').length;
			var strSortOrder = xmlDoc.getElementsByTagName('sort-order')[0].firstChild.nodeValue;
			var strColId = xmlDoc.getElementsByTagName('column-id')[0].firstChild.nodeValue;
			
			// Loop through results and add rows to table
			for(var intI = 0; intI < rowCnt; intI++)
			{
				// Create link column ids
				var tdIdCompany = "tdCompany" + intI;
				var tdIdDetails = "tdDetails" + intI;
				
				// Get featured number, and create element
				var intFeatured = xmlDoc.getElementsByTagName('featured')[intI].firstChild.nodeValue;
				
				// Check for featured company
				if(intFeatured == 1)
				{
					var strCompany = "<span style=\"font-weight:bold\"><img src=\"../../images/check.gif\" width=\"10\" height=\"10\" border=\"0\" />&nbsp;<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company-name')[intI].firstChild.nodeValue + "</a></span>";
				}
				else
				{
					var strCompany = "<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company-name')[intI].firstChild.nodeValue + "</a>";
				}
				
				// Details link
				var strDetails = "<a href=\"../sales-tax-products-details.php?type=pro&item=" + xmlDoc.getElementsByTagName('details-id')[intI].firstChild.nodeValue + "\" target=\"_blank\">Details</a>";
				
				
				// Format research and publications for empty values
				var strResearchVal = xmlDoc.getElementsByTagName('research')[intI].firstChild.nodeValue;
				var strPublicationVal = xmlDoc.getElementsByTagName('publications')[intI].firstChild.nodeValue;
				(strResearchVal == "-")?(strResearchVal = " "):(strResearchVal);
				(strPublicationVal == "-")?(strPublicationVal = " "):(strPublicationVal);
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdName = document.createElement("td");
				eleTdName.setAttribute('style', 'width:270px');
				//eleTdName.setAttribute('width', '270');
				eleTdName.setAttribute('id', tdIdCompany);
				
				var eleTdDetails = document.createElement("td");
				eleTdDetails.setAttribute('style', 'width:40px');
				//eleTdDetails.setAttribute('width', '40');
				//eleTdDetails.setAttribute('class', 'center');
				eleTdDetails.setAttribute('id', tdIdDetails);
				
				var eleTdPhone = document.createElement("td");
				eleTdPhone.setAttribute('style', 'width:100px');
				//eleTdPhone.setAttribute('width', '100');
				//eleTdPhone.setAttribute('class', 'center');
				
				var eleTdResearch = document.createElement("td");
				eleTdResearch.setAttribute('style', 'width:75px');
				//eleTdResearch.setAttribute('width', '75');
				eleTdResearch.setAttribute('align', 'center');
				
				var eleTdPubs = document.createElement("td");
				eleTdPubs.setAttribute('style', 'width:150px');
				//eleTdPubs.setAttribute('width', '150');
				eleTdPubs.setAttribute('align', 'center');
				
				// Append text nodes to TDs.
				eleTdPhone.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('phone')[intI].firstChild.nodeValue));
				eleTdResearch.appendChild(document.createTextNode(strResearchVal));
				eleTdPubs.appendChild(document.createTextNode(strPublicationVal));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdName);
				eleTr.appendChild(eleTdDetails);
				eleTr.appendChild(eleTdPhone);
				eleTr.appendChild(eleTdResearch);
				eleTr.appendChild(eleTdPubs);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(strColId).setAttribute('sort', strSortOrder);
				document.getElementById(tdIdCompany).innerHTML = strCompany;
				document.getElementById(tdIdDetails).innerHTML = strDetails;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

// Function to handle results from table sort
function hr_sortRates()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblLinks");	// Change id's from table to something useful later
			var eletBody = eleTable.getElementsByTagName("tbody")[0];
			var intTrCnt = eletBody.getElementsByTagName("tr").length;
			var intTrRow = intTrCnt - 1;
			
			// Clear table of previous results
			for(intTrRow; intTrRow >= 0; intTrRow--)
			{
				clearTable(eletBody, intTrRow);
			}
			
			// Results from the server
			var xmlDoc = request.responseXML;
			//alert(xmlDoc);
			var rowCnt = xmlDoc.getElementsByTagName('product-info').length;
			var strSortOrder = xmlDoc.getElementsByTagName('sort-order')[0].firstChild.nodeValue;
			var strColId = xmlDoc.getElementsByTagName('column-id')[0].firstChild.nodeValue;
			//alert(rowCnt);
			
			// Loop through results and add rows to table
			for(var intI = 0; intI < rowCnt; intI++)
			{
				// Create link column ids
				var tdIdCompany = "tdCompany" + intI;
				var tdIdDetails = "tdDetails" + intI;
				
				// Get featured number, and create element
				var intFeatured = xmlDoc.getElementsByTagName('featured')[intI].firstChild.nodeValue;
				
				// Check for featured company
				if(intFeatured == 1)
				{
					var strCompany = "<span style=\"font-weight:bold\"><img src=\"../../images/check.gif\" width=\"10\" height=\"10\" border=\"0\" />&nbsp;<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company-name')[intI].firstChild.nodeValue + "</a></span>";
				}
				else
				{
					var strCompany = "<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company-name')[intI].firstChild.nodeValue + "</a>";
				}
				
				// Details link				
				var strDetails = "<a href=\"" + xmlDoc.getElementsByTagName('details-url')[intI].firstChild.nodeValue + "\" target=\"_blank\">Details</a>";
				
				// Format research and publications for empty values
				var strLookVal = xmlDoc.getElementsByTagName('lookup')[intI].firstChild.nodeValue;
				var strRatesVal = xmlDoc.getElementsByTagName('rates')[intI].firstChild.nodeValue;
				var strRatesWRulesVal = xmlDoc.getElementsByTagName('rates-with-rules')[intI].firstChild.nodeValue;
				var strGeoVal = xmlDoc.getElementsByTagName('geo-intell')[intI].firstChild.nodeValue;
				(strLookVal == "-")?(strLookVal = " "):(strLookVal);
				(strRatesVal == "-")?(strRatesVal = " "):(strRatesVal);
				(strRatesWRulesVal == "-")?(strRatesWRulesVal = " "):(strRatesWRulesVal);
				(strGeoVal == "-")?(strGeoVal = " "):(strGeoVal);
				
				 // lookup rates rates-with-rules geo-intell
				
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdName = document.createElement("td");
				eleTdName.setAttribute('style', 'width:335px');
				eleTdName.setAttribute('width', '335');
				eleTdName.setAttribute('id', tdIdCompany);
				
				var eleTdDetails = document.createElement("td");
				eleTdDetails.setAttribute('style', 'width:40px');
				eleTdDetails.setAttribute('width', '40');
				//eleTdDetails.setAttribute('align', 'center');
				eleTdDetails.setAttribute('id', tdIdDetails);
				
				var eleTdPhone = document.createElement("td");
				eleTdPhone.setAttribute('style', 'width:100px');
				eleTdPhone.setAttribute('width', '100');
				//eleTdPhone.setAttribute('align', 'center');
				
				var eleTdLookup = document.createElement("td");
				eleTdLookup.setAttribute('style', 'width:50px');
				eleTdLookup.setAttribute('width', '50');
				eleTdLookup.setAttribute('align', 'center');
				
				var eleTdRates = document.createElement("td");
				eleTdRates.setAttribute('style', 'width:50px');
				eleTdRates.setAttribute('width', '50');
				eleTdRates.setAttribute('align', 'center');
				
				var eleTdRatesWRules = document.createElement("td");
				eleTdRatesWRules.setAttribute('style', 'width:60px');
				eleTdRatesWRules.setAttribute('width', '60');
				eleTdRatesWRules.setAttribute('align', 'center');
				
				var eleTdGeoIntell = document.createElement("td");
				eleTdGeoIntell.setAttribute('style', 'width:40px');
				eleTdGeoIntell.setAttribute('width', '40');
				eleTdGeoIntell.setAttribute('align', 'center');
				
				// Append text nodes to TDs.
				eleTdPhone.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('phone')[intI].firstChild.nodeValue));
				
				eleTdLookup.appendChild(document.createTextNode(strLookVal));
				eleTdRates.appendChild(document.createTextNode(strRatesVal));
				eleTdRatesWRules.appendChild(document.createTextNode(strRatesWRulesVal));
				eleTdGeoIntell.appendChild(document.createTextNode(strGeoVal));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdName);
				eleTr.appendChild(eleTdDetails);
				eleTr.appendChild(eleTdPhone);
				eleTr.appendChild(eleTdLookup);
				eleTr.appendChild(eleTdRates);
				eleTr.appendChild(eleTdRatesWRules);
				eleTr.appendChild(eleTdGeoIntell);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(strColId).setAttribute('sort', strSortOrder);
				document.getElementById(tdIdCompany).innerHTML = strCompany;
				document.getElementById(tdIdDetails).innerHTML = strDetails;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

// Function to handle results from table sort
function hr_sortCalculate()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblLinks");	// Change id's from table to something useful later
			var eletBody = eleTable.getElementsByTagName("tbody")[0];
			var intTrCnt = eletBody.getElementsByTagName("tr").length;
			var intTrRow = intTrCnt - 1;
			
			// Clear table of previous results
			for(intTrRow; intTrRow >= 0; intTrRow--)
			{
				clearTable(eletBody, intTrRow);
			}
			
			// Results from the server
			var xmlDoc = request.responseXML;
			//alert(xmlDoc);
			var rowCnt = xmlDoc.getElementsByTagName('product-info').length;
			var strSortOrder = xmlDoc.getElementsByTagName('sort-order')[0].firstChild.nodeValue;
			var strColId = xmlDoc.getElementsByTagName('column-id')[0].firstChild.nodeValue;
			//alert(rowCnt);
			
			// Loop through results and add rows to table
			for(var intI = 0; intI < rowCnt; intI++)
			{
				// Create link column ids
				var tdIdCompany = "tdCompany" + intI;
				var tdIdDetails = "tdDetails" + intI;
				
				// Get featured number, and create element
				var intFeatured = xmlDoc.getElementsByTagName('featured')[intI].firstChild.nodeValue;
				
				// Check for featured company
				if(intFeatured == 1)
				{
					var strCompany = "<span style=\"font-weight:bold\"><img src=\"../../images/check.gif\" width=\"10\" height=\"10\" border=\"0\" />&nbsp;<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company-name')[intI].firstChild.nodeValue + "</a></span>";
				}
				else
				{
					var strCompany = "<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company-name')[intI].firstChild.nodeValue + "</a>";
				}
				
				// Details link
				var strDetails = "<a href=\"../sales-tax-products-details.php?type=pro&item=" + xmlDoc.getElementsByTagName('details-id')[intI].firstChild.nodeValue + "\" target=\"_blank\">Details</a>";
				
				
				// Format research and publications for empty values
				var strCalcVal = xmlDoc.getElementsByTagName('calculate')[intI].firstChild.nodeValue;
				var strReturnsVal = xmlDoc.getElementsByTagName('returns')[intI].firstChild.nodeValue;
				var strSstpVal = xmlDoc.getElementsByTagName('sstp')[intI].firstChild.nodeValue;
				(strCalcVal == "-")?(strCalcVal = " "):(strCalcVal);
				(strReturnsVal == "-")?(strReturnsVal = " "):(strReturnsVal);
				(strSstpVal == "-")?(strSstpVal = " "):(strSstpVal);
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdName = document.createElement("td");
				eleTdName.setAttribute('style', 'width:285px');
				eleTdName.setAttribute('width', '285');
				eleTdName.setAttribute('id', tdIdCompany);
				
				var eleTdDetails = document.createElement("td");
				eleTdDetails.setAttribute('style', 'width:40px');
				eleTdDetails.setAttribute('width', '40');
				//eleTdDetails.setAttribute('align', 'center');
				eleTdDetails.setAttribute('id', tdIdDetails);
				
				var eleTdPhone = document.createElement("td");
				eleTdPhone.setAttribute('style', 'width:100px');
				eleTdPhone.setAttribute('width', '100');
				//eleTdPhone.setAttribute('align', 'center');
				
				var eleTdCalculate = document.createElement("td");
				eleTdCalculate.setAttribute('style', 'width:80px');
				eleTdCalculate.setAttribute('width', '80');
				eleTdCalculate.setAttribute('align', 'center');
				
				var eleTdReturns = document.createElement("td");
				eleTdReturns.setAttribute('style', 'width:55px');
				eleTdReturns.setAttribute('width', '55');
				eleTdReturns.setAttribute('align', 'center');
				
				var eleTdSstp = document.createElement("td");
				eleTdSstp.setAttribute('style', 'width:115px');
				eleTdSstp.setAttribute('width', '115');
				eleTdSstp.setAttribute('align', 'center');
				
				// Append text nodes to TDs.
				eleTdPhone.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('phone')[intI].firstChild.nodeValue));
				
				eleTdCalculate.appendChild(document.createTextNode(strCalcVal));
				eleTdReturns.appendChild(document.createTextNode(strReturnsVal));
				eleTdSstp.appendChild(document.createTextNode(strSstpVal));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdName);
				eleTr.appendChild(eleTdDetails);
				eleTr.appendChild(eleTdPhone);
				eleTr.appendChild(eleTdCalculate);
				eleTr.appendChild(eleTdReturns);
				eleTr.appendChild(eleTdSstp);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(strColId).setAttribute('sort', strSortOrder);
				document.getElementById(tdIdCompany).innerHTML = strCompany;
				document.getElementById(tdIdDetails).innerHTML = strDetails;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

// Function to handle results from table sort
function hr_sortCertificate()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblLinks");	// Change id's from table to something useful later
			var eletBody = eleTable.getElementsByTagName("tbody")[0];
			var intTrCnt = eletBody.getElementsByTagName("tr").length;
			var intTrRow = intTrCnt - 1;
			
			// Clear table of previous results
			for(intTrRow; intTrRow >= 0; intTrRow--)
			{
				clearTable(eletBody, intTrRow);
			}
			
			// Results from the server
			var xmlDoc = request.responseXML;
			//alert(xmlDoc);
			var rowCnt = xmlDoc.getElementsByTagName('product-info').length;
			var strSortOrder = xmlDoc.getElementsByTagName('sort-order')[0].firstChild.nodeValue;
			var strColId = xmlDoc.getElementsByTagName('column-id')[0].firstChild.nodeValue;
			//alert(rowCnt);
			
			// Loop through results and add rows to table
			for(var intI = 0; intI < rowCnt; intI++)
			{
				// Create link column ids
				var tdIdCompany = "tdCompany" + intI;
				var tdIdDetails = "tdDetails" + intI;
				
				// Get featured number, and create element
				var intFeatured = xmlDoc.getElementsByTagName('featured')[intI].firstChild.nodeValue;
				
				// Check for featured company
				if(intFeatured == 1)
				{
					var strCompany = "<span style=\"font-weight:bold\"><img src=\"../../images/check.gif\" width=\"10\" height=\"10\" border=\"0\" />&nbsp;<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company-name')[intI].firstChild.nodeValue + "</a></span>";
				}
				else
				{
					var strCompany = "<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company-name')[intI].firstChild.nodeValue + "</a>";
				}
				
				// Details link
				var strDetails = "<a href=\"../sales-tax-products-details.php?type=pro&item=" + xmlDoc.getElementsByTagName('details-id')[intI].firstChild.nodeValue + "\" target=\"_blank\">Details</a>";
				
				
				// Format research and publications for empty values
				var strExemptVal = xmlDoc.getElementsByTagName('exempt')[intI].firstChild.nodeValue;
				var strOtherVal = xmlDoc.getElementsByTagName('other')[intI].firstChild.nodeValue;
				(strExemptVal == "-")?(strExemptVal = " "):(strExemptVal);
				(strOtherVal == "-")?(strOtherVal = " "):(strOtherVal);
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdName = document.createElement("td");
				eleTdName.setAttribute('style', 'width:300px');
				eleTdName.setAttribute('width', '300');
				eleTdName.setAttribute('id', tdIdCompany);
				
				var eleTdDetails = document.createElement("td");
				eleTdDetails.setAttribute('style', 'width:40px');
				eleTdDetails.setAttribute('width', '40');
				//eleTdDetails.setAttribute('align', 'center');
				eleTdDetails.setAttribute('id', tdIdDetails);
				
				var eleTdPhone = document.createElement("td");
				eleTdPhone.setAttribute('style', 'width:100px');
				eleTdPhone.setAttribute('width', '100');
				//eleTdPhone.setAttribute('align', 'center');
				
				var eleTdExempt = document.createElement("td");
				eleTdExempt.setAttribute('style', 'width:120px');
				eleTdExempt.setAttribute('width', '120');
				eleTdExempt.setAttribute('align', 'center');
				
				var eleTdOther = document.createElement("td");
				eleTdOther.setAttribute('style', 'width:115px');
				eleTdOther.setAttribute('width', '115');
				eleTdOther.setAttribute('align', 'center');
				
				// Append text nodes to TDs.
				eleTdPhone.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('phone')[intI].firstChild.nodeValue));
				
				eleTdExempt.appendChild(document.createTextNode(strExemptVal));
				eleTdOther.appendChild(document.createTextNode(strOtherVal));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdName);
				eleTr.appendChild(eleTdDetails);
				eleTr.appendChild(eleTdPhone);
				
				eleTr.appendChild(eleTdExempt);
				eleTr.appendChild(eleTdOther);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(strColId).setAttribute('sort', strSortOrder);
				document.getElementById(tdIdCompany).innerHTML = strCompany;
				document.getElementById(tdIdDetails).innerHTML = strDetails;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

// Function to handle results from table sort
function hr_sortWebinars()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblList");	// Change id's from table to something useful later
			var eletBody = eleTable.getElementsByTagName("tbody")[0];
			var intTrCnt = eletBody.getElementsByTagName("tr").length;
			var intTrRow = intTrCnt - 1;
			
			// Clear table of previous results
			for(intTrRow; intTrRow >= 0; intTrRow--)
			{
				clearTable(eletBody, intTrRow);
			}
			
			// Results from the server
			var xmlDoc = request.responseXML;
			//alert(xmlDoc);
			
			var rowCnt = xmlDoc.getElementsByTagName('webinars-info').length;
			var strSortOrder = xmlDoc.getElementsByTagName('sort-order')[0].firstChild.nodeValue;
			var strColId = xmlDoc.getElementsByTagName('column-id')[0].firstChild.nodeValue;
			
			// Loop through results and add rows to table
			for(var intI = 0; intI < rowCnt; intI++)
			{
				// Create link column ids
				var tdIdTitle = "tdWebinarTitle" + intI;
				var tdIdSponsor = "tdWebinarSponsor" + intI;
				
				// Create link for Job Title and Sponsor
				var strWebinarUrl = xmlDoc.getElementsByTagName('title-url')[intI].firstChild.nodeValue;
				var strTitle = xmlDoc.getElementsByTagName('title')[intI].firstChild.nodeValue;
				var strTitleLink = "<a href=\"" + strWebinarUrl + "\" target=\"_blank\">" + strTitle + "</a>";
				
				var strSponsorUrl = xmlDoc.getElementsByTagName('sponsor-url')[intI].firstChild.nodeValue;
				var strSponsor = xmlDoc.getElementsByTagName('sponsor')[intI].firstChild.nodeValue;
				var strSponsorLink = "<a href=\"" + strSponsorUrl + "\" target=\"_blank\">" + strSponsor + "</a>";
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdDate = document.createElement("td");
				//eleTdDate.setAttribute('style', 'width:275px');
				//eleTdDate.setAttribute('width', '275');
				
				var eleTdType = document.createElement("td");
				
				var eleTdTitle = document.createElement("td");
				//eleTdTitle.setAttribute('style', 'width:275px');
				//eleTdTitle.setAttribute('width', '275');
				eleTdTitle.setAttribute('id', tdIdTitle);
				
				var eleTdSubject = document.createElement("td");
				//eleTdSubject.setAttribute('style', 'width:40px');
				//eleTdSubject.setAttribute('width', '40');
				//eleTdSubject.setAttribute('class', 'center');
				
				var eleTdCost = document.createElement("td");
				//eleTdCost.setAttribute('style', 'width:100px');
				//eleTdCost.setAttribute('width', '100');
				//eleTdCost.setAttribute('class', 'center');
				
				var eleTdSponsor = document.createElement("td");
				//eleTdSponsor.setAttribute('style', 'width:75px');
				//eleTdSponsor.setAttribute('width', '75');
				//eleTdSponsor.setAttribute('align', 'center');
				eleTdSponsor.setAttribute('id', tdIdSponsor);
				
				var eleTdCpe = document.createElement("td");
				//eleTdCpe.setAttribute('style', 'width:150px');
				//eleTdCpe.setAttribute('width', '150');
				//eleTdCpe.setAttribute('align', 'center');
				
				// Append text nodes to TDs.
				eleTdDate.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('date')[intI].firstChild.nodeValue));
				eleTdType.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('type')[intI].firstChild.nodeValue));
				eleTdTitle.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('title')[intI].firstChild.nodeValue));
				eleTdCost.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('cost')[intI].firstChild.nodeValue));
				eleTdSponsor.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('sponsor')[intI].firstChild.nodeValue));
				eleTdCpe.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('cpe')[intI].firstChild.nodeValue));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdDate);
				eleTr.appendChild(eleTdType);
				eleTr.appendChild(eleTdTitle);
				eleTr.appendChild(eleTdCost);
				eleTr.appendChild(eleTdSponsor);
				eleTr.appendChild(eleTdCpe);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(strColId).setAttribute('sort', strSortOrder);
				document.getElementById(tdIdTitle).innerHTML = strTitleLink;
				document.getElementById(tdIdSponsor).innerHTML = strSponsorLink;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

// Function to handle results from table sort
function hr_sortQuestions()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblList");	// Change id's from table to something useful later
			var eletBody = eleTable.getElementsByTagName("tbody")[0];
			var intTrCnt = eletBody.getElementsByTagName("tr").length;
			var intTrRow = intTrCnt - 1;
			
			// Clear table of previous results
			for(intTrRow; intTrRow >= 0; intTrRow--)
			{
				clearTable(eletBody, intTrRow);
			}
			
			// Results from the server
			var xmlDoc = request.responseXML;
			//alert(xmlDoc);
			
			var rowCnt = xmlDoc.getElementsByTagName('questions-info').length;
			var strSortOrder = xmlDoc.getElementsByTagName('sort-order')[0].firstChild.nodeValue;
			var strColId = xmlDoc.getElementsByTagName('column-id')[0].firstChild.nodeValue;
			
			var strQuestionUrl = "sales-tax-help-answers.php?category=3&section=info&sectionid=10&display&rateid=";
			
			// Loop through results and add rows to table
			for(var intI = 0; intI < rowCnt; intI++)
			{		
				// Create link column ids
				var tdIdQuestion = "tdQuestionsQuestion" + intI;
				
				// Create link for Job Title and Sponsor
				var strId = xmlDoc.getElementsByTagName('id')[intI].firstChild.nodeValue;
				var strQuestion = xmlDoc.getElementsByTagName('question')[intI].firstChild.nodeValue;
				var strQuestionLink = "<a href=\"" + strQuestionUrl + strId + "\" target=\"_blank\">" + strQuestion + "</a>";
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdQuestion = document.createElement("td");
				eleTdQuestion.setAttribute('id', tdIdQuestion);
				
				var eleTdCategory = document.createElement("td");
				
				var eleTdState = document.createElement("td");
				
				var eleTdExpert = document.createElement("td");
				
				var eleTdDate = document.createElement("td");
				
				// Append text nodes to TDs.
				eleTdQuestion.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('question')[intI].firstChild.nodeValue));
				eleTdCategory.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('category')[intI].firstChild.nodeValue));
				eleTdState.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('state')[intI].firstChild.nodeValue));
				eleTdExpert.innerHTML = xmlDoc.getElementsByTagName('expert')[intI].firstChild.nodeValue;
				eleTdDate.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('date')[intI].firstChild.nodeValue));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdQuestion);
				eleTr.appendChild(eleTdCategory);
				eleTr.appendChild(eleTdState);
				eleTr.appendChild(eleTdExpert);
				eleTr.appendChild(eleTdDate);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(strColId).setAttribute('sort', strSortOrder);
				document.getElementById(tdIdQuestion).innerHTML = strQuestionLink;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

// Function to handle results from table sort
function hr_sortJobs()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblList");	// Change id's from table to something useful later
			var eletBody = eleTable.getElementsByTagName("tbody")[0];
			var intTrCnt = eletBody.getElementsByTagName("tr").length;
			var intTrRow = intTrCnt - 1;
			
			// Clear table of previous results
			for(intTrRow; intTrRow >= 0; intTrRow--)
			{
				clearTable(eletBody, intTrRow);
			}
			
			// Results from the server
			var xmlDoc = request.responseXML;
			//alert(xmlDoc);
			
			var rowCnt = xmlDoc.getElementsByTagName('jobs-info').length;
			var strSortOrder = xmlDoc.getElementsByTagName('sort-order')[0].firstChild.nodeValue;
			var strColId = xmlDoc.getElementsByTagName('column-id')[0].firstChild.nodeValue;
			
			// Loop through results and add rows to table
			for(var intI = 0; intI < rowCnt; intI++)
			{
				// Create link column ids
				var tdIdTitle = "tdTitle" + intI;
				
				// Create link for Job Title
				var strJobId = xmlDoc.getElementsByTagName('id')[intI].firstChild.nodeValue;
				var strTitle = xmlDoc.getElementsByTagName('title')[intI].firstChild.nodeValue;
				var strTitleLink = "<a href=\"job-board-details.php?jobId=" + strJobId + "\" target=\"_blank\">" + strTitle + "</a>";
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdJobTitle = document.createElement("td");
				eleTdJobTitle.setAttribute('id', tdIdTitle);
				var eleTdCompany = document.createElement("td");
				var eleTdPostType = document.createElement("td");
				var eleTdLocationCity = document.createElement("td");
				var eleTdState = document.createElement("td");
				var eleTdPostDate = document.createElement("td");
				
				// Append text nodes to TDs.
				eleTdJobTitle.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('title')[intI].firstChild.nodeValue));
				eleTdCompany.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('company-recruiter')[intI].firstChild.nodeValue));
				eleTdPostType.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('post-type')[intI].firstChild.nodeValue));
				eleTdLocationCity.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('location-city')[intI].firstChild.nodeValue));
				eleTdState.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('state')[intI].firstChild.nodeValue));
				eleTdPostDate.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('post-date')[intI].firstChild.nodeValue));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdJobTitle);
				eleTr.appendChild(eleTdCompany);
				eleTr.appendChild(eleTdPostType);
				eleTr.appendChild(eleTdLocationCity);
				eleTr.appendChild(eleTdState);
				eleTr.appendChild(eleTdPostDate);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(strColId).setAttribute('sort', strSortOrder);
				document.getElementById(tdIdTitle).innerHTML = strTitleLink;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}



// Function to handle results from table sort
function hr_sortArticles()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblSort");
			var eletBody = eleTable.getElementsByTagName("tbody")[0];
			var intTrCnt = eletBody.getElementsByTagName("tr").length;
			var intTrRow = intTrCnt - 1;
			
			// Clear table of previous results
			for(intTrRow; intTrRow >= 0; intTrRow--)
			{
				clearTable(eletBody, intTrRow);
			}
			
			// Results from the server
			var xmlDoc = request.responseXML;
			//alert(xmlDoc);
			var rowCnt = xmlDoc.getElementsByTagName('articles-info').length;
			var strSortOrder = xmlDoc.getElementsByTagName('sort-order')[0].firstChild.nodeValue;
			var strColId = xmlDoc.getElementsByTagName('column-id')[0].firstChild.nodeValue;
			//alert(rowCnt);
			
			
			// Loop through results and add rows to table
			for(var intI = 0; intI < rowCnt; intI++)
			{
				// Create link column ids
				var tdIdTitle = "tdCompany" + intI;
				var strATitle = "<a href=\"sales-tax-articles-view.php?articleId=" + xmlDoc.getElementsByTagName('id')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\">" + xmlDoc.getElementsByTagName('title')[intI].firstChild.nodeValue + "</a>";
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdTitle = document.createElement("td");
				//eleTdTitle.setAttribute('style', 'width:345px');
				eleTdTitle.setAttribute('width', '345');
				eleTdTitle.setAttribute('id', tdIdTitle);
				
				var eleTdState = document.createElement("td");
				//eleTdState.setAttribute('style', 'width:40px');
				eleTdState.setAttribute('width', '40');
				eleTdState.setAttribute('align', 'center');
				
				var eleTdType = document.createElement("td");
				//eleTdType.setAttribute('style', 'width:70px');
				eleTdType.setAttribute('width', '70');
				eleTdType.setAttribute('align', 'center');
				
				var eleTdCompany = document.createElement("td");
				//eleTdCompany.setAttribute('style', 'width:130px');
				eleTdCompany.setAttribute('width', '130');
				eleTdCompany.setAttribute('align', 'center');
				
				var eleTdDate = document.createElement("td");
				eleTdDate.setAttribute('style', 'width:90px');
				eleTdDate.setAttribute('align', 'center');
				
				
				// Append text nodes to TDs.
				eleTdTitle.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('title')[intI].firstChild.nodeValue));
				eleTdState.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('state')[intI].firstChild.nodeValue));
				eleTdType.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('type')[intI].firstChild.nodeValue));
				eleTdCompany.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('company')[intI].firstChild.nodeValue));
				eleTdDate.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('review_date')[intI].firstChild.nodeValue));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdTitle);
				eleTr.appendChild(eleTdState);
				eleTr.appendChild(eleTdType);
				eleTr.appendChild(eleTdCompany);
				eleTr.appendChild(eleTdDate);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(strColId).setAttribute('sort', strSortOrder);
				document.getElementById(tdIdTitle).innerHTML = strATitle;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

function htmlspecialchars_decode (string, quote_style) {
    // Convert special HTML entities back to characters  
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/htmlspecialchars_decode
    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Mateusz "loonquawl" Zalega
    // +      input by: ReverseSyntax
    // +      input by: Slawomir Kaniecki
    // +      input by: Scott Cariss
    // +      input by: Francois
    // +   bugfixed by: Onno Marsman
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // +      input by: Mailfaker (http://www.weedem.fr/)
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');
    // *     returns 1: '<p>this -> &quot;</p>'
    // *     example 2: htmlspecialchars_decode("&amp;quot;");
    // *     returns 2: '&quot;'
    var optTemp = 0, i = 0, noquotes= false;
    if (typeof quote_style === 'undefined') {
        quote_style = 2;
    }
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE' : 1,
        'ENT_HTML_QUOTE_DOUBLE' : 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE' : 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i=0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            }
            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
        // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
    }
    if (!noquotes) {
        string = string.replace(/&quot;/g, '"');
    }
    // Put this in last place to avoid escape being double-decoded
    string = string.replace(/&amp;/g, '&');
 
    return string;
}
