var xmlHttp

//The purpose of the function is to solve the problem of creating different XMLHTTP objects for different browsers.
function GetXmlHttpObject()
{
	try
	{
		// Opera 8.0+, Firefox, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			//IE 6 +
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			//IE 5.5
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}



function stateChanged()
{
	if (xmlHttp.readyState==4)
	{
		//lets get a grip on the XML document using DOM
		var xmlDoc = xmlHttp.responseXML.documentElement;
		
		//firstly, check if any RV subtype sales exist..ie if the XML document returned an <empty> tag then we assume
		//no sales exist
		var empty = xmlDoc.getElementsByTagName('empty');
		if (empty.length)
		{
			//get a handle to our subtype menu
			var our_form = document.ozrvsearch.rv_subtype	
			//remove all options by setting the options array's length to 0
			//new Option(text, value, defaultSelected, selected)	
			our_form.options.length=0	
			our_form.options[0]=new Option("All subtypes","all_subtypes",true, false)
		}
		else
		{
		
			//get a handle to our subtype menu
			var our_form = document.ozrvsearch.rv_subtype	
			//remove all options by setting the options array's length to 0		
			our_form.options.length=0	
			
			//get the name of RV type the user chose
			var rv_type_name = xmlDoc.getElementsByTagName("rv_type_name")[0].childNodes[0].nodeValue;
			//create an entry in the subtype menu to display an "all" option
			our_form.options[0]=new Option("All " + rv_type_name + "subtypes", "all_subtypes", false, false)
			
			//declare some variables
			var subtype_id, subtype_name, sales_count			
			//how many subtype tags did our XML document return?
			var length = xmlDoc.getElementsByTagName('subtype').length;
			
			//alert("length = " + length);
				
			//repopulate the select menu with new options (aka content), using the Option() constructor on each option
			//loop through based on how many subtype tags we have
			
			var j = 1
			for (var i=0; i < length; i++)
			{
				//alert("i = " + i);			
				subtype_id = xmlDoc.getElementsByTagName("subtype_id")[i].childNodes[0].nodeValue;
				subtype_name = xmlDoc.getElementsByTagName("subtype_name")[i].childNodes[0].nodeValue;
				sales_count = xmlDoc.getElementsByTagName("sales_count")[i].childNodes[0].nodeValue;
				
				//the Option() constructor supports the following four parameters, the later two optional:
				//new Option(text, value, defaultSelected, selected)
				our_form.options[j]=new Option(subtype_name + " (" + sales_count + ") ", subtype_id, false, false)
				j = j + 1

			}//for	
				
		}//else
		
	}//if (xmlHttp.readyState==4)
	
}//function stateChanged()


function get_menu(id)
{

	//If the user chose "All types" we don't want to invoke any AJAX logic
	if (id == "all_types") 
	{		
		//get a handle to our subtype menu
		var our_form = document.ozrvsearch.rv_subtype	
		//remove all options by setting the options array's length to 0
		//new Option(text, value, defaultSelected, selected)	
		our_form.options.length=0	
		our_form.options[0]=new Option("All subtypes","all_subtypes",true, false)
	}
	
	//the user choose an RV type, so lets rock with some AJAX!!!
	else
	{
		//create object via function call
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		
		
		//create querystring to our ASP script - pass the 'id' of the RV type
		var url="get_subtype_menu.asp?id=" + id;
		//alert(url);
		
		//The onreadystatechange Property
		//After a request to the server, we need a function that can receive the data that is returned by the server.
		//The onreadystatechange property stores the function that will process the response from a server.
		//The following code sets the onreadystatechange property to the function:
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}	
}

function submit_form()
{

		  //var nr1=document.ozrvsearch.rv_postcode.value;
		  //alert(nrl);
		
}

var MAXHEIGHT = 85; // set these to whatever you want 
var MAXWIDTH  = 181; 

function imgfix(i) 
{ 
   var h = i.height; 
   var w = i.width; 
   if ( h > MAXHEIGHT ) 
   { 
       w = parseInt( w * MAXHEIGHT / h ); 
       h = MAXHEIGHT; 
   } 
   if ( w > MAXWIDTH ) 
   { 
       h = parseInt( h * MAXWIDTH / w ); 
       w = MAXWIDTH; 
   } 
   i.height = h; 
   i.width = w; 
   i.style.visibility = "visible"; 
} 