var colour_array=new Array();
var colour_foundit =new Boolean(); 
colour_array.push ("1");

var fabric_array=new Array();
var fabric_foundit =new Boolean(); 
fabric_array.push ("1");

var size_array=new Array();
var size_foundit =new Boolean(); 
size_array.push ("1");

	var price_min = 0;
	var price_max = 1000;
	
function sethtml(div,content) 
{ 
    var search = content; 
    var script; 
          
    while( script = search.match(/(<script[^>]+javascript[^>]+>\s*(<!--)?)/i)) 
    { 
      search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length); 
       
      if (!(endscript = search.match(/((-->)?\s*<\/script>)/))) break; 
       
      block = search.substr(0, search.indexOf(RegExp.$1)); 
      search = search.substring(block.length + RegExp.$1.length); 
       
      var oScript = document.createElement('script'); 
      oScript.text = block; 
      document.getElementsByTagName("head").item(0).appendChild(oScript); 
    } 
	
	var newdiv = ""
	newdiv = document.createElement("div");
	newdiv.innerHTML = content;
	
	var container = "";
	container = document.getElementById(div);
	container.innerHTML="";
	container.appendChild(newdiv);
	
	/*
    var newdiv = document.createElement("div");
	newdiv.innerHTML = content;
	var container = document.getElementById(div);
	container.appendChild(newdiv);*/
	
    //document.getElementById(div).innerHTML=content; 
}	

function filter(cat, min_price, max_price, colour, fabric, size){
	var xmlhttp;    
	

	if (min_price != "" && max_price != ""){
		if(min_price == price_min && max_price == price_max){
			price_min = "";
			price_max = "";
		}else{
			price_min = min_price;
			price_max = max_price;
		}
	}
	
	
	/*-------------------COLOUR----------------------*/

	//variables for tracking multiple colour filtering
	
	

	//loop through array to check for multiple manufacturers
	if (colour != ""){
		for (var i = 0; i < colour_array.length; i++) {
			colour_foundit=false;
			if(colour_array[i] == colour){
				colour_foundit = true;
				colour_array.splice(i,1); 
				break;
			}else{
				colour_foundit = false;
			}
		}

		if(colour_foundit == false){
			colour_array.push(colour);
		}

	}

  
	/*-------------------FABRIC----------------------*/
	//variables for tracking multiple colour filtering
	
	

	//loop through array to check for multiple manufacturers
	if (fabric != ""){
		for (var i = 0; i < fabric_array.length; i++) {
			fabric_foundit=false;
			if(fabric_array[i] == fabric){
				fabric_foundit = true;
				fabric_array.splice(i,1); 
				break;
			}else{
				fabric_foundit = false;
			}
		}

		if(fabric_foundit == false){
			fabric_array.push(fabric);
		}

	}
	
	/*-------------------SIZE----------------------*/
	//variables for tracking multiple colour filtering
	
	

	//loop through array to check for multiple manufacturers
	if (size != ""){
		for (var i = 0; i < size_array.length; i++) {
			size_foundit=false;
			if(size_array[i] == size){
				size_foundit = true;
				size_array.splice(i,1); 
				break;
			}else{
				size_foundit = false;
			}
		}

		if(size_foundit == false){
			size_array.push(size);
		}

	}
  
  
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		sethtml("results", xmlhttp.responseText);	
		//document.getElementById("results").innerHTML=xmlhttp.responseText;
		}
	  }
	  
	colour_value = colour_array.toString();  
	fabric_value = fabric_array.toString();  
	size_value = size_array.toString();  

	xmlhttp.open("GET","filter.asp?cat="+cat+"&price_min="+price_min+"&price_max="+price_max+"&colour="+colour_value+"&fabric="+fabric_value+"&size="+size_value,true);
	xmlhttp.send();
}






