var xmlHttp;

function selectOptions(type,typecode,ele_id,cat_id,special_option,webcode_override,suppress_block){
	xmlHttp=GetXmlHttpObject();
	
	// this is used for filtering by virtual subactegory on the subcategory pages
	if (typecode == 0 && webcode_override != null){
		//alert('HERE >> ' + ' ' + typecode + ' ' + webcode_override);
		typecode = webcode_override;
	}
	
	//alert('ELEID '+ ele_id + 'TYPE >> ' + type + ' WEBCODE >> ' + typecode + ' CAT ID >> ' + cat_id + ' Special option ' + special_option + ' override webcode ' + webcode_override);
	var url= '/perl/select_option.cgi?type=' + type + '&typecode=' + typecode + '&cat_id=' + cat_id + '&special_option=' + special_option + '&override_webcode=' + webcode_override;	
	//alert('URL >>> ' + url);
	var newid = ele_id + '1';
	var colorid = ele_id + '2';
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 	
			var res_array=xmlHttp.responseText.split("\^\^\^SPLIT\^\^\^");				
			if (suppress_block == 1){
				// do nothing - cheap hack for poste and posteMistress
			}
			else{
				newstr = res_array[0];
				document.getElementById(ele_id).style.display="inline"; // needed to override country selection de-selection
				document.getElementById(ele_id).innerHTML=newstr;
				if (document.getElementById(newid)!=null){ 
					document.getElementById(newid).style.display="inline";
	 				document.getElementById(newid).innerHTML=res_array[1]; 	
				}
			}
			
			// if a virtual subcategory contains only colour elements then the color drop down will be returned
			// in a disabled state
			var found_color = res_array[2]; 
			if (found_color){
				document.getElementById(colorid).style.display="inline";
 				document.getElementById(colorid).innerHTML=found_color; 
			}
 		} 
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
}

function GetXmlHttpObject(){	
  	try {    
	  	// Firefox, Opera 8.0+, Safari    
	  	xmlHttp=new XMLHttpRequest();    
	} catch (e) {    
  		// Internet Explorer    
  		try { 
	  		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  
	  	} catch (e) {      
    		try {  
	    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");    
	    	} catch (e) {        
      			alert("Your browser does not support AJAX!");       
      			return false;        
  			}      
  		}    
  	}  	
  	return xmlHttp;	
}