var onchange2done = 0;

function contact_result() 

{ 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

	 { 

		val=xmlHttp.responseText;

		//alert(val);

		document.getElementById('change_cats2').innerHTML = val;

		document.getElementById('change_cats1').style.display = 'none';

		document.getElementById('change_cats2').style.display = 'block';

	 } 

}

function contact_result1() 

{ 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

	 { 

		val=xmlHttp.responseText;

		document.getElementById('breed21').innerHTML = val;

		document.getElementById('breed21').style.display = 'block';

	 }
}

function GetXmlHttpObject()

{

	var xmlHttp=null;

	try

	 {

	 // Firefox, Opera 8.0+, Safari

	 xmlHttp=new XMLHttpRequest();

	 }

	catch (e)

	 {

	 //Internet Explorer

	 try

	  {

	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

	  }

	 catch (e)

	  {

	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

	  }

	 }

	return xmlHttp;

}

function OnCatChange1() {

//alert("Hai");

	var cat = document.getElementById('cat').value;

	

	xmlHttp=GetXmlHttpObject();

	if(xmlHttp===null)

	{

		alert("Browser does not support HTTP Request");

		return;

	}

	var url = "wp-content/plugins/find a friend widget/faf_controller.php";

	url=url+"?work=catchange1";

	url=url+"&id="+cat;

	xmlHttp.onreadystatechange=contact_result;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);

}

function OnCatChange2() {

	if(document.getElementById('select21').selectedIndex==1)

{

	cat = document.getElementById('cat').value;
	if (cat==14) { rehomeid = 20; } //dog
	if (cat==15) { rehomeid = 27; } //cat
	if (cat==16) { rehomeid = 99; } //small animal
	if (cat==54) { rehomeid = 131; } //horse and farm
	if (cat==135) { rehomeid = 130; } //bird
	if (cat==136) { rehomeid = 97; } //fish
	window.location = "/?cat="+rehomeid;

}

	else if(document.getElementById('select21').selectedIndex==2)

{

	cat = document.getElementById('cat').value;

	xmlHttp=GetXmlHttpObject();

	if(xmlHttp===null)

	{

		alert("Browser does not support HTTP Request");

		return;

	}

	var url = "wp-content/plugins/find a friend widget/faf_controller.php";

	url=url+"?work=catchange2";

	url=url+"&id="+cat;

	xmlHttp.onreadystatechange=contact_result1;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);

	onchange2done = 1;

}

}

function goToBreed() {

var breed = document.getElementById('select22').value;
url= "/?cat="+breed;
window.location = url;
}

function OnCatChange3() {

if((document.getElementById('select21').selectedIndex==2)&&(onchange2done==1))

{

	cat = document.getElementById('cat').value;



	xmlHttp=GetXmlHttpObject();

	if(xmlHttp===null)

	{

		alert("Browser does not support HTTP Request");

		return;

	}

	var url = "wp-content/plugins/find a friend widget/faf_controller.php";

	url=url+"?work=catchange2";

	url=url+"&id="+cat;

	xmlHttp.onreadystatechange=contact_result1;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);

}

}
