

// Function to initalize certain functions
function init()
{
	eleBody = document.getElementsByTagName("body")[0];
	//alert(eleBody);
	
	// Firefox
	//eleBody.setAttribute('oncontextmenu', 'return false');
	eleBody.setAttribute('onmousedown', 'return false');
	
	// IE
	document.oncontextmenu = function() {return false;} // ie
	document.onselectstart = function() {return false;} // ie
	
	//eleBody.setAttribute('onselectstart', 'return false');
	//document.onselectstart();
}

// Function to disable selecting things on the page.
function disableSelection(target)
{
	if(typeof target.onselectstart!="undefined") //IE route
		target.onselectstart=function(){return false}
	else if(typeof target.style.MozUserSelect!="undefined") //Firefox route
		target.style.MozUserSelect="none"
	else //All other route (ie: Opera)
		target.onmousedown=function(){return false}
	target.style.cursor = "default"
}

// Function to check for bad characters.
function checkBadChar(strInput)
{
	var intLength = strInput.length;
	
	// Check for the end or the beginning a element tag
	if((strInput.indexOf('<') >= 0) || (strInput.indexOf('>') >= 0))
	{
		return true;
	}
	else
	{
		return false;
	}
}

// Function to validate emails
function isValidEmail(email)
{
	var validEmailRegExp = /^\w(\.?\w)*@\w(\.?[-\w])*\.([a-z]{3}(\.[a-z]{2})?|a-z]{2}(\.[a-z]{2})?)$/i
	var isValid = validEmailRegExp.test(email);
	return isValid;
}

// Function to check talk to us form
function checkTalkToUsForm()
{
	var strMsgEmpty = "Please fill in all required fields.";
	var strMsgLength = "Sorry! You have exceeded the character limit for a data field";
	var strMsgEmailsNoMatch = "Your emails do not match please re-enter them.";
	var strMsgCharacters = "Please remove any illegal characters in your entries.";
	var strMsgEmailValid = "Please re-enter your emails in a valid format.\nSuch as 'mail@mail.com'";
	var frmTalk = document.frmTalk;
	
	// Check name isn't empty or has bad characters
	if(frmTalk.frmName.value == "")
	{
		alert(strMsgEmpty);
		frmTalk.frmName.focus();
		return false;
	}
	else if(checkBadChar(frmTalk.frmName.value))
	{
		alert(strMsgCharacters);
		frmTalk.frmName.focus();
		return false;
	}
	
	// Check emails aren't empty
	if((frmTalk.frmEmail.value == "") || (frmTalk.frmEmail2.value == ""))
	{
		alert(strMsgEmpty);
		frmTalk.frmEmail.focus();
		return false;
	}
	
	// Check emails are valid
	if((!isValidEmail(frmTalk.frmEmail.value)) || (!isValidEmail(frmTalk.frmEmail2.value)))
	{
		alert(strMsgEmailValid);
		frmTalk.frmEmail.focus();
		return false;
	}
	
	// Check emails match
	if(frmTalk.frmEmail.value != frmTalk.frmEmail2.value)
	{
		alert(strMsgEmailsNoMatch);
		frmTalk.frmEmail.focus();
		return false;
	}
	
	// Check check city isn't empty or has bad characters
	if(frmTalk.frmCity.value == "")
	{
		alert(strMsgEmpty);
		frmTalk.frmCity.focus();
		return false;
	}
	else if(checkBadChar(frmTalk.frmCity.value))
	{
		alert(strMsgCharacters);
		frmTalk.frmCity.focus();
		return false;
	}
	
	// Check state isn't empty or has bad characters
	if(frmTalk.frmState.value == "")
	{
		alert(strMsgEmpty);
		frmTalk.frmState.focus();
		return false;
	}
	else if(checkBadChar(frmTalk.frmState.value))
	{
		alert(strMsgCharacters);
		frmTalk.frmState.focus();
		return false;
	}
	
	// Check zip isn't empty or has bad characters
	if(frmTalk.frmZip.value == "")
	{
		alert(strMsgEmpty);
		frmTalk.frmZip.focus();
		return false;
	}
	else if(checkBadChar(frmTalk.frmZip.value))
	{
		alert(strMsgCharacters);
		frmTalk.frmZip.focus();
		return false;
	}
	
	// Check comment isn't empty or has bad characters
	if(frmTalk.frmComment.value == "")
	{
		alert(strMsgEmpty);
		frmTalk.frmComment.focus();
		return false;
	}
	else if(checkBadChar(frmTalk.frmComment.value))
	{
		alert(strMsgCharacters);
		frmTalk.frmComment.focus();
		return false;
	}
	
	// Check security isn't empty or has bad characters
	if(frmTalk.frmSecurity.value == "")
	{
		alert(strMsgEmpty);
		frmTalk.frmSecurity.focus();
		return false;
	}
	else if(checkBadChar(frmTalk.frmSecurity.value))
	{
		alert(strMsgCharacters);
		frmTalk.frmSecurity.focus();
		return false;
	}
	
	return true;
}

// Function to check job form
function checkJobForm(eleId)
{
	var strMessage = "Sorry! You have exceeded the character limit for a data field";
	
	// Check which job form was submitted
	if(eleId == "frmJobPost")
	{
		var eleDescription = document.getElementById('frmDescription').value;
		var eleRequirements = document.getElementById('frmRequirements').value;
		var eleBenefits = document.getElementById('frmBenefits').value;
		
		if(eleDescription.length > 1500)
		{
			alert(strMessage + "\n\nYour current count for 'Job Description' is '" + eleDescription.length + "'");
			document.frmJobPost.frmDescription.focus();
			return false;
		}
		
		if(eleRequirements.length > 750)
		{
			alert(strMessage + "\n\nYour current count for 'Key Job Requirements' is '" +eleRequirements.length + "'");
			document.frmJobPost.frmRequirements.focus();
			return false;
		}
		
		if(eleBenefits.length > 750)
		{
			alert(strMessage + "\n\nYour current count for 'Job Benefits' is '" + eleBenefits.length + "'");
			document.frmJobPost.frmBenefits.focus();
			return false;
		}
	}
	else
	{
		var eleDescription = document.getElementById('frmDescription').value;
		var eleQualifications = document.getElementById('frmQualifications').value;
		
		if(eleDescription.length > 1500)
		{
			alert(strMessage + "\n\nYour current count for 'Job Wanted Description' is '" + eleDescription.length + "'");
			document.frmJobWanted.frmDescription.focus();
			return false;
		}
		
		if(eleQualifications.length > 750)
		{
			alert(strMessage + "n\nYour current count for 'Qualifications' is '" + eleQualifications.length + "'");
			document.frmJobWanted.frmQualifications.focus();
			return false;
		}
	}
	return true;
}

// Function to check alerts form
function checkAlertForm()
{
	// Alert messages
	var strMessage = "Please make sure all the following fields are complete:\nContact Name \nContact State \nContact Email \nSignature Name";
	var strMessage1 = "Please check either 'Job Activity Alert' or 'Sales Tax Content Alerts'.";
	var strMessage2 = "Please check either 'Job Available Post' or 'Job Wanted Post'.";
	
	var frmAlerts = document.frmAlerts;
	
	// Contact Name
	if(frmAlerts.frmContact.value == "")
	{
		alert(strMessage);
		return false;
	}
	
	// Email
	if(frmAlerts.frmEmail.value == "")
	{
		alert(strMessage);
		return false;
	}
	
	// Signature Name
	if(frmAlerts.frmSignatureName.value == "")
	{
		alert(strMessage);
		return false;
	}
	
	// Job Activity and Tax Information Activity
	if((frmAlerts.frmActivateContent.checked == false) && (frmAlerts.frmActivateJob.checked == false))
	{
		alert(strMessage1);
		return false;
	}
	
	// If job activity is check then check that post or wanted is checked
	if(frmAlerts.frmActivateJob.checked == true)
	{
		// State 1
		if(frmAlerts.frmState1.value == "")
		{
			alert("Please make sure 'State 1' is filled.");
			return false;
		}
		
		if((frmAlerts.frmJobAvailable.checked == false) && (frmAlerts.frmJobWanted.checked == false))
		{
			alert(strMessage2);
			return false;
		}
	}
	
	return true;
}

// Fucntion to check ask question form
function checkQuestionForm()
{
	var frmQ = document.frmAskQuestion;
	
	// Arrays
	var arrFields = new Array();
	arrFields[0] = frmQ.frmTypeBusiness.value;
	arrFields[1] = frmQ.frmStateQuestion.value;
	arrFields[2] = frmQ.frmHeadState.value;
	arrFields[3] = frmQ.frmHowManyStates.value;
	arrFields[4] = frmQ.frmQuestion.value;
	arrFields[5] = frmQ.frmContactName.value;
	arrFields[6] = frmQ.frmTitle.value;
	arrFields[7] = frmQ.frmCompanyName.value;
	arrFields[8] = frmQ.frmCity.value;
	arrFields[9] = frmQ.frmState.value;
	arrFields[10] = frmQ.frmZip.value;
	arrFields[11] = frmQ.frmEmail.value;
	arrFields[12] = frmQ.frmPhone.value;
	arrFields[13] = frmQ.frmSignatureName.value;
	
	// Alert messages
	var strMessage = "Please make sure all fields are complete.";
	var strMessage1 = "Sorry! You have exceeded the character limit for a data field";
	
	// Loop through array and check fields for blanks.
	for(var intI = 0; intI < arrFields.length; intI++)
	{
		if(arrFields[intI] == "")
		{
			alert(strMessage);
			return false;
		}
	}
	
	// Check charactor count for type of business
	if(arrFields[0].length > 350)
	{
		alert(strMessage1 + "\n\nYour current count for 'Type of Business' is '" + arrFields[0].length + "'");
		return false;
	}
	
	// Check charactor count for question
	if(arrFields[4].length > 1000)
	{
		alert(strMessage1 + "\n\nYour current count for 'Question' is '" + arrFields[4].length + "'");
		return false;
	}
	
	return true;
}

// Function to dispaly new table results
function getAccountantLinks()
{
	// Get script URL & selected state
	var url = "../scripts/getAccountantLinks.php";
	var strState = document.getElementById("frmState").value;	
	httpRequest("POST", url, true, hr_getAccountantLinks, "&strState=" + escape(strState));
}

// Function to dispaly new table results
function hr_getAccountantLinks()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblLinks");
			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('link').length;
			
			// 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
				var strUrl = decodeURI(xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue);
				if(intFeatured == 1)
				{
					var strAName = "<span style=\"font-weight:bold\"><img src=\"../images/check.gif\" width=\"10\" height=\"10\" border=\"0\" />&nbsp;<a href=\"" + unescape(xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue) + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company')[intI].firstChild.nodeValue + "</a></span>";
				}
				else
				{
					var strAName = "<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company')[intI].firstChild.nodeValue + "</a>";
				}
				
				// Details link
				var strADetails = "<a href=\"sales-tax-services-details.php?type=acc&item=" + xmlDoc.getElementsByTagName('company-id')[intI].firstChild.nodeValue + "\" target=\"_blank\">Details</a>";
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdName = document.createElement("td");
				eleTdName.setAttribute('style', 'width:360px');
				eleTdName.setAttribute('width', '360');
				eleTdName.setAttribute('id', tdIdCompany);
				
				var eleTdDetails = document.createElement("td");
				eleTdDetails.setAttribute('style', 'width:60px');
				eleTdDetails.setAttribute('width', '60');
				eleTdDetails.setAttribute('class', 'center');
				eleTdDetails.setAttribute('id', tdIdDetails);
				
				var eleTdPhone = document.createElement("td");
				eleTdPhone.setAttribute('style', 'width:100px');
				eleTdPhone.setAttribute('width', '100');
				
				var eleTdCity = document.createElement("td");
				eleTdCity.setAttribute('style', 'width:120px');
				eleTdCity.setAttribute('width', '120');
				
				var eleTdState = document.createElement("td");
				eleTdState.setAttribute('style', 'width:35px');
				eleTdState.setAttribute('width', '35');
				
				// Append text nodes to TDs.
				eleTdPhone.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('phone')[intI].firstChild.nodeValue));
				eleTdCity.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('city')[intI].firstChild.nodeValue));
				eleTdState.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('state')[intI].firstChild.nodeValue));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdName);
				eleTr.appendChild(eleTdDetails);
				eleTr.appendChild(eleTdPhone);
				eleTr.appendChild(eleTdCity);
				eleTr.appendChild(eleTdState);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(tdIdCompany).innerHTML = strAName;
				//alert(strAName);
				document.getElementById(tdIdDetails).innerHTML = strADetails;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

// Function to dispaly new table results
function getAttorneyLinks()
{
	// Get script URL & selected state
	var url = "../scripts/getAttorneyLinks.php";
	var strState = document.getElementById("frmState").value;
	
	//alert("State information = " + strState);
	
	httpRequest("POST", url, true, hr_getAttorneyLinks, "&strState=" + escape(strState));
}

// Function to dispaly new table results
function hr_getAttorneyLinks()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblLinks");
			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('link').length;
			
			// 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;
				var tdIdSalesTaxLink = "tdSalesTaxLink" + intI;
				
				// Get featured number, and create element
				var intFeatured = xmlDoc.getElementsByTagName('featured')[intI].firstChild.nodeValue;
				
				//
				if(intFeatured == 1)
				{
					var strAName = "<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')[intI].firstChild.nodeValue + "</a></span>";
				}
				else
				{
					var strAName = "<a href=\"" + xmlDoc.getElementsByTagName('company-url')[intI].firstChild.nodeValue + "\" title=\"\" alt=\"\" target=\"_blank\">" + xmlDoc.getElementsByTagName('company')[intI].firstChild.nodeValue + "</a>";
				}
				
				// Details Link
				var strADetails = "<a href=\"sales-tax-services-details.php?type=att&item=" + xmlDoc.getElementsByTagName('company-id')[intI].firstChild.nodeValue + "\" target=\"_blank\">Details</a>";
				
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td and link elements
				var eleTdName = document.createElement("td");
				eleTdName.setAttribute('style', 'width:360px');
				eleTdName.setAttribute('width', '360');
				eleTdName.setAttribute('id', tdIdCompany);
				
				var eleTdDetails = document.createElement("td");
				eleTdDetails.setAttribute('style', 'width:60px');
				eleTdDetails.setAttribute('width', '60');
				eleTdDetails.setAttribute('class', 'center');
				eleTdDetails.setAttribute('id', tdIdDetails);
				
				var eleTdPhone = document.createElement("td");
				eleTdPhone.setAttribute('style', 'width:100px');
				eleTdPhone.setAttribute('width', '100');
				
				var eleTdCity = document.createElement("td");
				eleTdCity.setAttribute('style', 'width:120px');
				eleTdCity.setAttribute('width', '120');
				
				var eleTdState = document.createElement("td");
				eleTdState.setAttribute('style', 'width:35px');
				eleTdState.setAttribute('width', '35');
				
				// Append text nodes to TDs.
				eleTdPhone.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('phone')[intI].firstChild.nodeValue));
				eleTdCity.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('city')[intI].firstChild.nodeValue));
				eleTdState.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('state')[intI].firstChild.nodeValue));
				
				
				// Append TDs to TR
				eleTr.appendChild(eleTdName);
				eleTr.appendChild(eleTdDetails);
				eleTr.appendChild(eleTdPhone);
				eleTr.appendChild(eleTdCity);
				eleTr.appendChild(eleTdState);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
				
				// Insert links into tds
				document.getElementById(tdIdCompany).innerHTML = strAName;
				document.getElementById(tdIdDetails).innerHTML = strADetails;
			}
		}
		else
		{
			// Hide loading box
			//loadingInfo("hide");
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

// Function to dispaly new table results
function getJobsList()
{
	// Get script URL & selected state
	var url = "../scripts/getJobsList.php";
	var strState = document.getElementById("frmState").value;
	httpRequest("POST", url, true, hr_getJobsList, "&strState=" + escape(strState));
}

// Function to dispaly new table results
function hr_getJobsList()
{
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
			// Table elements
			var eleTable = document.getElementById("tblList");
			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;
			
			// 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(tdIdTitle).innerHTML = strTitleLink;
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}

// Function to dispaly new table results
function getWebinarsList()
{
	// Get script URL & selected state
	var url = "../scripts/getWebinarsList.php";
	var strSubject = document.getElementById("frmSubject").value;
	httpRequest("POST", url, true, hr_getWebinarsList, "&strSubject=" + escape(strSubject));
}

// Function to dispaly new table results
function hr_getWebinarsList()
{
	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;
			
			// Check the number of entries and Loop through results and add rows to table
			var strNumEntries = xmlDoc.getElementsByTagName('webinars-entries')[0].firstChild.nodeValue;
			if(strNumEntries == "0")
			{
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td element
				var eleTdNoEntry = document.createElement("td");
				eleTdNoEntry.setAttribute('colspan', "6");
				
				// Append text node to TD
				eleTdNoEntry.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('webinars-no-entries')[0].firstChild.nodeValue));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdNoEntry);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
			}
			else
			{
				for(var intI = 0; intI < rowCnt; intI++)
				{
					// Create link column ids / Text node
					var tdIdTitle = "tdWebinarTitle" + intI;
					var tdIdSponsor = "tdWebinarSponsor" + intI;
					
					// Create link for Job Title and Sponsor / Text node
					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");
					
					var eleTdType = document.createElement("td");
					
					var eleTdTitle = document.createElement("td");
					eleTdTitle.setAttribute('id', tdIdTitle);
					
					var eleTdSubject = document.createElement("td");
					
					var eleTdCost = document.createElement("td");
					
					var eleTdSponsor = document.createElement("td");
					eleTdSponsor.setAttribute('id', tdIdSponsor);
					
					var eleTdCpe = document.createElement("td");
					
					// 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(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 dispaly new table results
function getArticlesLinks()
{
	// Get script URL & selected state
	var url = "../scripts/getArticlesLinks.php";
	var strIndustry = document.getElementById("frmIndustry").value;
	var strTopic = document.getElementById("frmTopic").value;
	//alert("Industry = " + strIndustry +  ", Topic = " + strTopic);
	httpRequest("POST", url, true, hr_getArticlesLinks, "&strIndustry=" + escape(strIndustry) + "&strTopic=" + escape(strTopic));
}

// Function to dispaly new table results
function hr_getArticlesLinks()
{
	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;
			
			
			// Check the number of entries and Loop through results and add rows to table
			var strNumEntries = xmlDoc.getElementsByTagName('articles-entries')[0].firstChild.nodeValue;
			if(strNumEntries == "0")
			{
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td element
				var eleTdNoEntry = document.createElement("td");
				eleTdNoEntry.setAttribute('colspan', "5");
				
				// Append text node to TD
				eleTdNoEntry.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('articles-no-entries')[0].firstChild.nodeValue));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdNoEntry);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
			}
			else
			{
				// 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:300px');
					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:60px');
					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('width', '90');
					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(tdIdTitle).innerHTML = strATitle;
				}
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}


$(document).ready(function() {

if(window.location.hash != '')
  {
  	var hash = window.location.hash.substr(8);
  	var mode = hash.substr(0,1);
  	var form = '';
  	if(mode == 'a')
  	{
  		form = '#frmSubject';
  		mode = 'subject';
  	}
  	else
  	{
  		form = '#frmIndustry';
  		mode = 'industry';
  	}
  	var strHash = unescape(hash.substr(1));
  	strHash = strHash.split('-');
  	
  	$(form + ' option:eq(' + strHash[0] + ')').attr('selected','selected');
  	//alert('strHash = ' + strHash[0]);
  	getQuestionsList(mode);
  }
});


// Function to dispaly new table results
function getQuestionsList(mode)
{
	// Get script URL & selected state
	var url = "../scripts/getQuestionsList.php";
	if(mode == 'subject')
	{
		var strSearch = document.getElementById("frmSubject").value;
		httpRequest("POST", url, true, hr_getQuestionsList, "&m=subject&strQuery=" + escape(strSearch));
	}
	else if(mode == 'industry')
	{
		var strSearch = document.getElementById("frmIndustry").value;
		httpRequest("POST", url, true, hr_getQuestionsList, "&m=industry&strQuery=" + escape(strSearch));
	}
	else
	{
		httpRequest("POST", url, true, hr_getQuestionsList, '');
	}
	var originalString = strSearch;
	var pos = originalString.indexOf("-");
	var newString = originalString.substr(pos+1);
	var prefix = originalString.substr(0,pos);
	
	
	newString = newString.trim().toLowerCase();
	newString = newString.replace(/[\.\,\?\(\)\/\-!]/g, " ");
	newString = newString.replace(/\s\s+/g, ' ');
	newString = newString.replace(/\s+/g, '-');
	//newString = encodeURIComponent(newString);	
	//newString = newString.replace("-", "#");
	//newString = newString.trim();
	//newString = newString.replace(/[\s+\/]/g, "-");
	//newString = newString.replace(/\s+/g, "-");
	//newString = newString.replace("#", "-");
	
	/*
	var tmp = strSearch.replace(/[\.\,\?\(\)!]/g, "");
	tmp = tmp.replace("-", "#");
	var tmp1 = tmp.trim().split('#');
	strSearch = tmp1[1].replace(/[\s+\/]/g, " ");
	strSearch = strSearch.replace(/\s+/g, "-");
	*/
	window.location.hash = 'search=' + prefix + '-' + newString;
}

// Function to dispaly new table results
function hr_getQuestionsList()
{
	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;
			
			// Check the number of entries and Loop through results and add rows to table
			var strNumEntries = xmlDoc.getElementsByTagName('questions-entries')[0].firstChild.nodeValue;
			if(strNumEntries == "0")
			{
				// Create row
				var eleTr = document.createElement("tr");
				
				// Create td element
				var eleTdNoEntry = document.createElement("td");
				eleTdNoEntry.setAttribute('colspan', "3");
				
				// Append text node to TD
				eleTdNoEntry.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('questions-no-entries')[0].firstChild.nodeValue));
				
				// Append TDs to TR
				eleTr.appendChild(eleTdNoEntry);
				
				// Append TR to TABLE
				eletBody.appendChild(eleTr);
			}
			else
			{
				for(var intI = 0; intI < rowCnt; intI++)
				{
					// Create link column ids / Text node
					var tdIdTitle = "tdQuestionTitle" + intI;
					
					// Create link for Questions
					var strQuestionUrl = xmlDoc.getElementsByTagName('url')[intI].firstChild.nodeValue;
					var strTitle = xmlDoc.getElementsByTagName('title')[intI].firstChild.nodeValue;
					var strTitleLink = "<a href=\"" + strQuestionUrl + "\">" + strTitle + "</a>";
					var strExpert = unescape(xmlDoc.getElementsByTagName('expert')[intI].firstChild.nodeValue);
					
					// Create row
					var eleTr = document.createElement("tr");
					
					// Create td and link elements
					var eleTdTitle = document.createElement("td");
					eleTdTitle.setAttribute('id', tdIdTitle);
					
					var eleTdExpert = document.createElement("td");
					
					var eleTdDate = document.createElement("td");
					
					// Append text nodes to TDs.
					eleTdTitle.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('title')[intI].firstChild.nodeValue));
					//eleTdExpert.appendChild(document.createTextNode(xmlDoc.getElementsByTagName('expert')[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(eleTdTitle);
					eleTr.appendChild(eleTdExpert);
					eleTr.appendChild(eleTdDate);
					
					// Append TR to TABLE
					eletBody.appendChild(eleTr);
					
					// Insert links into tds
					document.getElementById(tdIdTitle).innerHTML = strTitleLink;
				}
			}
		}
		else
		{
			alert("A problem occurred with communicating between the XMLHTTPrequest object and the server programme.");
		}
	}
}


/********** Clear table body results **********/

// Function to clear the TABLE of previous results
function clearTable(eletBody, intRowNum)
{
	clearTableText(eletBody, intRowNum);
	clearTableCells(eletBody, intRowNum);
	clearTableRows(eletBody, intRowNum);
}

// Functions to clear TR's
function clearTableRows(eletBody, intRowNum)
{
	var trCnt = eletBody.getElementsByTagName("tr").length;
	eletBody.removeChild(eletBody.getElementsByTagName("tr")[intRowNum]);
}

// Functions to clear TD's
function clearTableCells(eletBody, intRowNum)
{
	var trRow = eletBody.getElementsByTagName("tr")[intRowNum];
	var tdCnt = trRow.getElementsByTagName("td").length;
	
	// Loop through cells and clear the text
	for(var intI = 0; intI < tdCnt; intI++)
	{
		clearNodes(trRow);
	}
}

// Functions to clear TD's
function clearTableText(eletBody, intRowNum)
{
	var trRow = eletBody.getElementsByTagName("tr")[intRowNum];
	var tdCnt = trRow.getElementsByTagName("td").length;
	
	// Loop through cells and clear the text
	for(var intI = 0; intI < tdCnt; intI++)
	{
		clearNodes(trRow.getElementsByTagName("td")[intI])
	}
}

// Function to clear child nodes from element past to it.
function clearNodes(ele)
{
	// Remove child nodes
	if(ele != null)
	{
		if(ele.childNodes)
		{
			for(var intI = 0; intI <ele.childNodes.length; intI++)
			{
				var childNode = ele.childNodes[intI];
				ele.removeChild(childNode);
			}
		}
	}
}

// Function to open a new popup window.
function openNewWindow(theURL, winName, features)
{
	// Open window and the give it the focus
	objWin = window.open(theURL,winName,features);
	objWin.moveTo(0, 0);
	objWin.focus();
}

// Function to change disclaimer page to terms or use page.
function getTermsPage()
{
	window.location = "termsPop.php";
}

