function validate(id){
// this function generates the http request that will validate input
	// get the id of the element that is being typed in
	var currClass = $(id).attr("class");

	// create ajax object
        var ajaxRequest;  
        try{
                // Opera 8.0+, Firefox, Safari
                ajaxRequest = new XMLHttpRequest();
        } catch (e){
                // Internet Explorer Browsers
                try{
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                // Something went wrong
                                alert("There appears to have been a problem, please reload the page.");
                                return false;
                        }
                }
        }
	
        //function that will receive data sent from the validation php file
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){

	        	if(ajaxRequest.responseText == 0) {

		        	$(function() {
	        		$(id).removeClass(currClass)
		        	$(id).addClass("form_bad")
	        		});
       			} else if(ajaxRequest.responseText == 1) {
        	
				$(function() {
        			$(id).removeClass(currClass)
        			$(id).addClass("form_good")
        			});

        		}
                }
        }
	
	// assign variables, dependant on which form field we are dealing with
	selected_field = $(id).attr("id");

	// check to see if it is the number captcha to validate
	if(selected_field == "capid") {
	        var keyCap1 = document.getElementById('cap1').value;
       		var keyCap2 = document.getElementById('cap2').value;
	        var keyAnswer = document.getElementById('capid').value;
	        var queryString = "?keyCap=true&cap1=" + keyCap1 + "&cap2=" + keyCap2 + "&answer=" + keyAnswer;
	        ajaxRequest.open("GET", "validation/form_code.php" + queryString, true);
	        ajaxRequest.send(null);
	};

	 // check to see if it is the name to validate
        if(selected_field == "nameid") {
		var keyName = document.getElementById('nameid').value;
	        var queryString = "?keyName=" + keyName;
        	ajaxRequest.open("GET", "validation/form_code.php" + queryString, true);
	        ajaxRequest.send(null);
	};

	 // check to see if it is the email address to validate
        if(selected_field == "emailid") {
		var keyEmail = document.getElementById('emailid').value;
	        var queryString = "?keyEmail=" + keyEmail;
	        ajaxRequest.open("GET", "validation/form_code.php" + queryString, true);
	        ajaxRequest.send(null);
	};

	 // check to see if it is the message to validate
        if(selected_field == "nachrichtid") {
		var keyMessage = document.getElementById('nachrichtid').value;
	        var queryString = "?keyMessage=" + keyMessage;
	        ajaxRequest.open("GET", "validation/form_code.php" + queryString, true);
	        ajaxRequest.send(null);	
	};

} // end of function

