  var theDIV; // we will set this to an id that actually exists in the page

  var http_request = false;
  function fromServer()
  {
    if( http_request.readyState==4 )
    {
      if( http_request.status==200 )
      {
// results from call to the server appear here
// in http_request.responseText;
        e = document.getElementById(theDIV);
        e.innerHTML = http_request.responseText;
      }
      else
      {
// uncomment next line if you want to show any error messages
        //alert('error: ' + http_request.responseText);
      }
    }
  }

  function makeRequest(url, parameters) 
  {
    http_request = false;
    if( window.XMLHttpRequest ) 
    { 
      // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) 
      { http_request.overrideMimeType('text/html');
      }
    } 
    else if (window.ActiveXObject) 
    { // IE
      try 
      { http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } 
      catch (e) 
      { try
        { http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
      }
    }
    if (!http_request) 
    {
// uncomment next line if you want to show any error messages
      //alert('Cannot create XMLHTTP instance');
      return false;
    }
    http_request.onreadystatechange = fromServer;
    http_request.open('GET', url + parameters, true);
    http_request.send(null);
  }

  // theDIV = "aDIV";
  // makeRequest(url,qry); 
  var toggle=0;
  function toggleIt(cid)
  {
    // (local server only without invoking Javascript permission prompt)
    var url = "/addtolist.php"

    theDIV='aDIV';
    if( toggle==0 ) qry = "?show=after&cid=" + cid;
    else qry = "?show=before";

    // results will be returned and acted on above in `fromServer' fx
    makeRequest(url,qry);

    toggle = !toggle;
    return false;
  }

//By: Chris Campbell
//Created: May 20, 2005
//Last Modified: June 27th, 2005
//www.particletree.com


window.onload = attachFormHandlers;

var gShow; //variable holding the id where feedback will be sent to.
var sUrl = "/formvalidation.php?validationtype=ajax&val=";//url is the page which will be processing all of the information.  it is important to make sure validationtype is ajax
var gErrors = 0; //number of errors is set to none to begin with
var http = getHTTPObject();//don't worry about this



function attachFormHandlers()
{
	var form = document.getElementById('listingmailer') 

	if (document.getElementsByTagName)//make sure were on a newer browser
	{
	/*	var objInput = document.getElementsByTagName('input');
		for (var iCounter=0; iCounter<objInput.length; iCounter++)
		objInput[iCounter].onblur = function(){return validateMe(this);} //attach the onblur to each input field
	*/	
		var objInput = document.getElementsByTagName('textarea');
		for (var iCounter=0; iCounter<objInput.length; iCounter++)
		objInput[iCounter].onblur = function(){return validateMe(this);} //attach the onchange to each textarea field\
	
	var emailInput = document.getElementById('Email');
	var nameInput = document.getElementById('Name');
	// var enquiryInput = document.getElementById('Enquiry');
	var validationInput = document.getElementById('Validation');
	
	emailInput.onblur = function(){return validateMe(this);}
	nameInput.onblur = function(){return validateMe(this);}
	// enquiryInput.onblur = function(){return validateMe(this);}
	validationInput.onchange = function(){return validateMe(this);}
	}
	
	// form.onsubmit = function(){ } //attach validate() to the form
}




/*validateMe is the function called with onblur each time the user leaves the input box
passed into it is the value entered, the rules (which you could create your own), and the id of the area the results will show in*/
function validateMe(objInput) {

	sVal = objInput.value; //get value inside of input field
	
	sRules = objInput.className.split(' '); // get all the rules from the input box classname
	sRequired = sRules[1]; // determines if field is required or not
	sTypeCheck = sRules[2]; //typecheck are additional validation rules (ie. email, phone, date)
    gShow = sRules[3]; //gShow is the div id where feedback is sent to.
  
	//sends the rules and value to the php page to be validated
	http.open("GET", sUrl + (sVal) + "&sRequired=" + (sRequired) + "&sTypeCheck=" + sTypeCheck, true);
	http.onreadystatechange = handleHttpResponse; 	// handle what to do with the feedback 
	http.send(null);
}


function handleHttpResponse() {
	//if the process is completed, decide to do with the returned data
	if (http.readyState == 4) {
	//	if (http.status == 200) {
		sResults = http.responseText.split(","); //results is now whatever the feedback from the php page was
		//whatever the variable glo_show's (usermsg for example) innerHTML holds, is now whatever was returned by the php page. 
    	document.getElementById(gShow).innerHTML = "";
		document.getElementById(gShow).innerHTML = sResults[0];
		//document.getElementById(gShow).appendChild(document.createTextNode(sResults[0]));
	//	}
  	}
}

function getHTTPObject() {	
	var xhr = false; //set to false, so if it fails, do nothing	
	if(window.XMLHttpRequest) {//detect to see if browser allows this method		
		var xhr = new XMLHttpRequest();//set var the new request	
	} else if(window.ActiveXObject) {//detect to see if browser allows this method		
		try {
			var xhr = new ActiveXObject("Msxml2.XMLHTTP");//try this method first		
		} catch(e) {//if it fails move onto the next			
				try {				
						var xhr = new ActiveXObject("Microsoft.XMLHTTP");//try this method next			
				} catch(e) {//if that also fails return false.				
						xhr = false;			
				}		
		}		
	}	
	return xhr;//return the value of xhr
}