dojo.addOnLoad(function(){
	var findForm = dojo.byId('find');
	var breedSelect = dojo.byId('breed');
	var distanceSelect = dojo.byId('distance');
	var zipcodeTxt = dojo.byId('zipcode');
	
	if(findForm) {
		dojo.connect(findForm, 'onsubmit', function (e) {
			dojo.stopEvent(e);
			
			if(breedSelect.options[breedSelect.selectedIndex].value != '')
			{
				 var action = findForm.action + (breedSelect.options[breedSelect.selectedIndex].value) + '.html';
				 
				 if (distanceSelect.options[distanceSelect.selectedIndex].value != -1)
				 {
					 action = action + '?distance=' + distanceSelect.options[distanceSelect.selectedIndex].value;
					 
					 if (zipcodeTxt.value != '')
					 {
						 action = action + '&zipcode=' + zipcodeTxt.value;
					 }
				 }
				 
				 if(dojo.isIE > 8) {
					 findForm.action = action;
				 } else {
					 document.location.href = action;
				 }
			}
			return false;
		});
	}
	
	var sfindForm = dojo.byId('find_small');
	var sbreedSelect = dojo.byId('breed_small');
	var sDistanceSelect = dojo.byId('distance_small');
	var sZipcodeTxt = dojo.byId('zipcode_small');
	
	if(sfindForm) {
		dojo.connect(sfindForm, 'onsubmit', function (e) {
			dojo.stopEvent(e);
			
			if(sbreedSelect && sbreedSelect.options[sbreedSelect.selectedIndex].value != '')
			{
				 var action = sfindForm.action + (sbreedSelect.options[sbreedSelect.selectedIndex].value) + '.html';
				 
				 if (sDistanceSelect && sDistanceSelect.options[sDistanceSelect.selectedIndex].value != -1)
				 {
					 action = action + '?distance=' + sDistanceSelect.options[sDistanceSelect.selectedIndex].value;
					 
					 if (sZipcodeTxt && sZipcodeTxt.value != '')
					 {
						 action = action + '&zipcode=' + sZipcodeTxt.value;
					 }
				 }
				 
				 if(dojo.isIE > 8) {
					 sfindForm.action = action;
				 } else {
					 document.location.href = action;
				 }
			}
			return false;
		});
	}
	
	var sfindVideosForm = dojo.byId('find_videos');
	if(sfindVideosForm) {
		dojo.connect(sfindVideosForm, 'onsubmit', function (e) {
			dojo.stopEvent(e);
			
			if(breedSelect.options[breedSelect.selectedIndex].value != '')
			{
				 if(dojo.isIE > 8) {
					 sfindVideosForm.action = sfindVideosForm.action + (breedSelect.options[breedSelect.selectedIndex].value) + '.html';
				 } else {
					 document.location.href = sfindVideosForm.action + (breedSelect.options[breedSelect.selectedIndex].value) + '.html';
				 }
			}
			return false;
		});
	}
});
