
/*************************************************************************************
	THE FOLLOWING FUNCTIONS ARE FOR GENERAL AJAX HANDLING
*************************************************************************************/
var xmlhttp = false;

function requestData(url,param,objID,handlingFunction){
/*
alert("inside requestData");
alert("url = " + url);
alert("param = " + param);
alert("objID = " + objID);
*/


// CREATE A NEW XMLHTTP OBJECT
  	try{
    	xmlhttp = new XMLHttpRequest();
  	}
  	catch(e){
    		try{
      			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    		}
    		catch(e){
      			try{
        			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      			}
      			catch(e){}
    		} // end catch 2
  	}// end catch 1


  	// WHEN CREATING OBJECT FAILED
  	if(!xmlhttp) return false;


  	// OPEN REQUEST AND SEND
  	// POST WITH PARAMETERS; GET WITHOUT PARAMETERS
  	try{
    		if(param){
			//alert(url+"?"+param);
      			// I CANNOT GET THE SEND METHOD TO WORK FOR NETSCAPE 6 UNLESS I COMBINE THE URL AND PARAM AND THEN SEND NULL
      			// THIS IS NOT WHAT I WANT, BUT I AM NOT FINDING A FIX YET
      			xmlhttp.open("POST",url+"?"+param,true);
      			xmlhttp.setRequestHeader("Method","POST " + url + " HTTP/1.1"); // NEEDED FOR NETSCAPE
      			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      			try{
        			xmlhttp.send(null);
				//alert("sending...");
      			}
      			catch(e){alert(e)}
    		} // end if
    		else{
      			xmlhttp.open("GET",url,true);
      			xmlhttp.send(null);
    		} // end else
  	} // end try
  	catch(e){
    		//alert("false = " + e);
    		return false;
  	} // end catch


  	// WHEN EVERYTHING IS READY CALL HANDLING FUNCTION
  	// HANDLING FUNCTION WILL ALWAYS BE FILTERDATA, WHICH WILL BE LOCATED ON THE LOCAL PAGE OR LOCAL JS

	//alert("xmlhttp=" + xmlhttp);
	try{
		//alert("status==200" + (xmlhttp.status==200) );
		//alert(window.location.href.indexOf("http")==-1));
		//alert(window.location.href);
	}
	catch(e){
		alert("error:" + e);
	}


	// FUNCTION DOESN'T FIRE UNTIL READYSTATE = 4
	// YOU WILL GET A NS_ERROR_NOT_AVAILABLE ERROR IF YOU DO NOT HAVE A RETURN FALSE IN THE INITIAL FUNCTION THAT CALLS REQUESTDATA
  	xmlhttp.onreadystatechange = function(){
		//alert("readyState=" + xmlhttp.readyState);
		//alert("status=" + xmlhttp.status);

		try{
			// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
    			if(xmlhttp.readyState == 4 && (xmlhttp.status==200 || window.location.href.indexOf("http")==-1) ){
      				//alert(objID);
				//alert(xmlhttp);
     				if(!handlingFunction) filterData(xmlhttp,objID);
				if(handlingFunction) eval(handlingFunction + "(xmlhttp,objID)");
    			} // end if

		}
		catch(e){
			alert(e);
		}
  	} // end created function

} // END REQUESTDATA FUNCTION



/*************************************************************************************
	THE FOLLOWING FUNCTIONS ARE FOR THE TYPEAHEAD SUGGEST

	http://www.dynamicajax.com/fr/AJAX_Suggest_JavaScript-271_290_312_314.html
	suggestOver, suggestOut, setSearch, and suggest loop all from above
*************************************************************************************/
//Mouse over function
function suggestOver(div_value){
  div_value.className = "suggest_link_over";
}

//Mouse out function
function suggestOut(div_value){
  div_value.className = "suggest_link";
}

// SET POSITION OF TYPEAHEAD SUGGEST DIV
function setPosition(txtBox, divSuggest){
	topPos = document.getElementById(txtBox).offsetTop;
	leftPos = document.getElementById(txtBox).offsetLeft;
	ht = document.getElementById(txtBox).offsetHeight;
	var position = topPos+ht;

	document.getElementById(divSuggest).style.top=position;
	document.getElementById(divSuggest).style.left=leftPos;
	document.getElementById(divSuggest).style.display="block";
}



/*************************************************************************************
	THE FOLLOWING FUNCTIONS ARE FOR GENERAL PURPOSES
*************************************************************************************/

// GET TEXTFIELD VALUE FROM INPUT ONKEYUP
function getValueFromInput(evt){
	var objID = (evt.target) ? evt.target.id : ((evt.srcElement) ? evt.srcElement.id : null);
	var val = document.getElementById(objID).value;
	return val;
}

// CLEAR SUGGEST DIV AREA
function clearDiv(field){
	document.getElementById(field).innerHTML="";
}




