/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/
try {
		xgr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
		xgr = new XMLHttpRequest();
	}

xgr.onreadystatechange  = function(){
	if(xgr.readyState  == 4){
    	if(xgr.status  == 200){                
    		// Safely inject CSS3 and give the search results a shadow
    		var cssObj = { 'box-shadow' : '#888 5px 10px 10px', // Added when CSS3 is standard
    			'-webkit-box-shadow' : '#888 5px 10px 10px', // Safari
    			'-moz-box-shadow' : '#888 5px 10px 10px'}; // Firefox 3.5+
    		jQuery("#suggestions").css(cssObj);    		
    		jQuery('#suggestions').html(xgr.responseText); // Fill the suggestions box
    		jQuery('#suggestions').fadeIn(); // Show the suggestions box
    		
    		// Fade out the suggestions box when not active
    		jQuery("input").blur(function(){
    			jQuery('#suggestions').fadeOut();
    		 });
		}
        else 
           if(console)console.log("Error code " + xgr.status);
    }
};

function lookup(inputString) {
	if(inputString.length < 2) {
		jQuery('#suggestions').fadeOut(); // Hide the suggestions box
	} else {
		inputString = encodeURIComponent(inputString);
		xgr.open("POST", "http://www.savoirtoutfaire.com/lib/search/rpc.php", true);
        xgr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
        xgr.send("queryString="+inputString);

	}
}
