function ctct_ajaxit() // Declare an AJAX variable
{
	var ajaxRequest;

	try
	{
		ajaxRequest = new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				return false;
			}
		}
	}
	return ajaxRequest;
}

function CheckMultiple3(frm, name) // This was included with the form to see if a user entered a first name or not, but it was never actually being used.
{
	for (var i=0; i < frm.length; i++)
	{
		fldObj = frm.elements[i];
		fldId = fldObj.id;
		if (fldId) {
			var fieldnamecheck=fldObj.id.indexOf(name);
			if (fieldnamecheck != -1) {
				if (fldObj.checked) {
					return true;
				}
			}
		}
	}
	return false;
}

function newsletter_form_validate() // This is the original function used to validate an email address. I just copied and pasted as-is, except I renamed it to something more "friendly".
{
	var email_re = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
	if (!email_re.test(document.getElementById('email').value)) {
		alert("Please enter your email address.");
		document.getElementById('email').focus();
		return false;
	}
	return true;
}

function newsletter_form_submit() // This submits the form using AJAX.
{
	
	if (!newsletter_form_validate())
	{
		return false;
	}
	var newsletter_email = document.getElementById('email').value;
	var newsletter_name = document.getElementById('CustomFields_2_46').value;
	var mystring = "newsletter_post.php?email=" + newsletter_email + "&name=" + newsletter_name;
	
	var ajaxRequest = ctct_ajaxit();
	if (!ajaxRequest)
	{
		pagefunction = false;
		alert ("AJAX has failed to initialize. The newsletter form is broken.");
		return false;
	}
	ajaxRequest.onreadystatechange=function()
	{
		if (ajaxRequest.readyState == 4)
		{
			var tresult = ajaxRequest.responseText;
			var objDiv = document.getElementById("newsletter_box");
			
			if (tresult == '0')
			{
				objDiv.innerHTML = '<div style="padding-top: 20px; width:270px; font-size:11px;">Thank you. Your free interview tips will arrive in your inbox shortly. While waiting, continue browsing the site to learn more about InterviewGOLD.</div>';
			}
			else
			{
				objDiv.innerHTML = '<div style="padding-top:20px;">Sign up unsuccessful. If you entered your information properly and are still receiving this message, please contact the webmaster.</div>';
			}
		}
	}
	ajaxRequest.open("GET", mystring, true);
	ajaxRequest.send(null);
	return true;
}

