function makeHttpRequest(url, callback_function, return_xml)
{
   var http_request = false;

   if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
       }
   } 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) {
       alert('Unfortunatelly you browser doesn\'t support this feature.');
       return false;
   }
   http_request.onreadystatechange = function() {
       if (http_request.readyState == 4) {
           if (http_request.status == 200) {
               if (return_xml) {
                   eval(callback_function + '(http_request.responseXML)');
               } else {
                   eval(callback_function + '(http_request.responseText)');
               }
           } else {
               alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
   }
   http_request.open('GET', url, true);
   http_request.send(null);
}


function mouseEvent(event)
{  
		document.getElementById('result_img').style.display='none';

	var keyword = document.getElementById('keyword').value;
	var categories_id = document.getElementById('categories_id').value;
	var themes_id = document.getElementById('themes_id').value;
	var products_for = document.getElementById('products_for').value;
    
    if(keyword == 'Enter fragrance name') {
        keyword = '';
    }
	
	min_price ='';
	max_price ='';
	/*
	var min_price = document.getElementById('min_price').value;
	var max_price = document.getElementById('max_price').value;
	*/
	
	var the_url = 'matching_products.php?';
	
	if (keyword) {
	   the_url += 'keyword=' + keyword + '&';
	}
	
	if (categories_id) {
	   the_url += 'categories_id=' + categories_id + '&';
	}
	
	if (themes_id) {
	   the_url += 'themes_id=' + themes_id + '&';
	}
	
	if (products_for) {
	   the_url += 'products_for=' + products_for + '&';
	}
	
	if (min_price) {
	   the_url += 'min_price=' + min_price + '&';
	}
	
	if (max_price) {
	   the_url += 'max_price=' + max_price + '&';
	}
	
	makeHttpRequest(the_url, 'printResult');
}

function printResult(result_string)
{
   var result_div = document.getElementById('search-result');
   result_div.innerHTML = result_string;
}

function deliveryRateLookup(event)
{  
	var postcode = document.getElementById('postcode').value;
	
	var the_url = 'lookup_delivery_cost.php?';
	
	the_url += 'postcode=' + postcode;
	
	makeHttpRequest(the_url, 'printDeliveryRate');
}

function printDeliveryRate(result_string)
{
   var result_div = document.getElementById('result');
   
   result_div.innerHTML = result_string;
}

function setEmpty(field)
{
	value = field.value;
	if ( (value=='Enter Your Email') || (value=='Enter fragrance name') )
	{
		field.value = "";
	}
}