function cl_xmlHttpObject () {

	var xml_http_object;

	try {
		xml_http_object = new XMLHttpRequest();
	} catch(e) {
		try {
			xml_http_object = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xml_http_object = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				//alert("ERROR: Your browser does not support AJAX.");
				return false;
			}
		}
	}

	return xml_http_object;

}

// set up a var that will match the chatbox we'll be inserting values into
var box = "";

// create functions that can be used from the chatbox page that will set the chatbox to get data from and then redirect to the cl_submit function 
function cl_submit_box1 () {
	box = 1;
	cl_submit();
}

function cl_submit_box2 () {
	box = 2;
	cl_submit();
}

function cl_submit_box3 () {
	box = 3
	cl_submit();
}

function cl_submit() {

	var ajax = new cl_xmlHttpObject();
	if (ajax) {
		//alert(document.getElementById("user").value);
		//alert("here");
		var messageToFind = "message";
		//alert(messageToFind);
		var message = document.getElementById(messageToFind).value;
		//alert(message);
		var chatbox = document.getElementById("chat").value;
		var params = "message=" + message + "&chatbox=" + chatbox;
		//alert(document.getElementById("chat").value);
		//alert(params);
		
		ajax.onreadystatechange = function () {
			var feedbackBox = "feedback";
			var feedback = document.getElementById(feedbackBox);

			feedback.innerHTML = "problem.";
			if (ajax.readyState <4) {
				feedback.innerHTML = "Saving message...";
			} else if (ajax.readyState == 4) {
				if (ajax.responseText == "0") {
					feedback.innerHTML += "Message saved.";
				} else {
					var chatboxToFind = "chatboxs";
					//alert(chatboxToFind);
					document.getElementById(chatboxToFind).value=ajax.responseText.replace(/(^\s*|\s*$)/, "")+"\n"+document.getElementById(chatboxToFind).value;
					document.getElementById(messageToFind).value="";
					feedback.innerHTML = "";
					// update the post count
					//var postCountBox = "num";//+box;
					//alert(document.getElementById(postCountBox).innerHTML);
					//var myNum = strToInt(document.getElementById(postCountBox).innerHTML);
					//document.getElementById(postCountBox).innerHTML= myNum +1;
					if (ajax.responseText == "Message save failed") {
						// redirect to a login specific page
					}
				}
			}
		}
		ajax.open("POST", "process.php", true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", params.length);
		ajax.setRequestHeader("Connection", "close");
		ajax.send(params);
	} else {
		alert('Your browser does not support AJAX. Please turn on Javascript in your browser options/preferences and try again.');
	}
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.registerForm.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		emailID.focus()
		document.getElementById("error").innerHTML = "You must enter a valid email address";
	} else if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		document.getElementById("error").innerHTML = "You must enter a valid email address";
	} else {
		registerForm.submit()
	}
 }
 
/**
* End ...
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */