function removeFrame() {
	var myHost = top.location.hostname;
	if ((myHost != "www.steger-lewis.net") && (myHost != "www.corraunhouseserver.com") && (myHost != "192.168.1.10")) {
		top.location.href = "http://www.steger-lewis.net/";
	}
}

function validateForm(form) {
	if (form.name.value == "") {
		alert("Please enter your name");
		return false;
	}
	if (form.subject.value == "") {
		alert("Please enter a subject");
		return false;
	}
	if (form.message.value == "") {
		alert("Please enter a message");
		return false;
	}
	if (!(validateEmail(form.email))) {
		return false;
	}
	return true;
}

function validateEmail(email) {
	var emailFilter = /^.+@.+\..+$/;
	var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if ((emailFilter.test(email.value)) && (!(email.value.match(illegalChars)))) {
		return true;
	} else {
    	alert("Please enter a valid email address");
		return false;
	}
}

function sizeContactMessage(message) {
	var chars = message.value.length;
	var lines = Math.floor(chars / 65) + 2;
	message.rows = lines;
}

function check_captcha(form) {
	document.getElementById('bad_captcha').style.visibility = "hidden";
	document.getElementById('bad_captcha').style.display = "none";
	document.getElementById('verify_good').style.visibility = "hidden";
	document.getElementById('verify_good').style.display = "none";
	var xhri = xhrRequest('html');
	var qry = 'captcha_code=' + form.captcha_code.value;
	var url = 'captcha.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				if (xhr[xhri].responseText == "pass") {
					form.captcha_valid.value = "true";
					document.getElementById('verify_good').style.visibility = "visible";
					document.getElementById('verify_good').style.display = "block";
					document.getElementById('submit').disabled = false;
					return true;
				} else {
					form.captcha_valid.value = "false";
					document.getElementById('bad_captcha').style.visibility = "visible";
					document.getElementById('bad_captcha').style.display = "block";
					document.getElementById('captcha').src = 'securimage/securimage_show.php?' + Math.random();
					return false;
				}
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}


// AJAX REQUEST HANDLER

var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE

function xhrRequest(type) {
	if (!type) {
		type = 'html';
	}

	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length;

	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {

		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}

	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;

	// SET UP THE REQUEST
	if (window.XMLHttpRequest) {
		xhr[xhrsend] = new XMLHttpRequest();
		if (xhr[xhrsend].overrideMimeType) {
			xhr[xhrsend].overrideMimeType('text/' + type);
		}
	} else if (window.ActiveXObject) {
		try {
			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return (xhrsend);
}

