dojo.addOnLoad(function(){
	var findForm = dojo.byId('find');
	var breedSelect = dojo.byId('breed');
	var disciplineSelect = dojo.byId('discipline');
	var genderSelect = dojo.byId('gender');
	var colorSelect = dojo.byId('color');
	var distanceSelect = dojo.byId('distance');
	var zipcodeSelect = dojo.byId('zipcode');
	
	if(findForm) {
		dojo.connect(findForm, 'onsubmit', function (e) {

			e.stopPropagation();
			e.preventDefault();
			dojo.stopEvent(e);
				
			if(breedSelect.options[breedSelect.selectedIndex].value != '') {
				tmpQry = '';
				if(disciplineSelect.options[disciplineSelect.selectedIndex].value != '')
					tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'discipline=' + (disciplineSelect.options[disciplineSelect.selectedIndex].value);
				if(genderSelect.options[genderSelect.selectedIndex].value != '')
					tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'gender=' + (genderSelect.options[genderSelect.selectedIndex].value);
				if(colorSelect.options[colorSelect.selectedIndex].value != '')
					tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'color=' + (colorSelect.options[colorSelect.selectedIndex].value);
				if(distanceSelect.options[distanceSelect.selectedIndex].value != '')
					tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'distance=' + (distanceSelect.options[distanceSelect.selectedIndex].value);
				if(zipcodeSelect.value != '')
					tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'zipcode=' + (zipcodeSelect.value);
				tmpQry = (tmpQry != '' ? '?' : '') + tmpQry;
				
				var action = findForm.action + (breedSelect.options[breedSelect.selectedIndex].value) + '.html' + tmpQry;
				
				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 sdisciplineSelect = dojo.byId('discipline_small');
    var sgenderSelect = dojo.byId('gender_small');
    var scolorSelect = dojo.byId('color_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.options[sbreedSelect.selectedIndex].value != '')
			{
                tmpQry = '';
                if(sdisciplineSelect && sdisciplineSelect.options[sdisciplineSelect.selectedIndex].value != '')
                    tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'discipline=' + (sdisciplineSelect.options[sdisciplineSelect.selectedIndex].value);
                if(sgenderSelect && sgenderSelect.options[sgenderSelect.selectedIndex].value != '')
                    tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'gender=' + (sgenderSelect.options[sgenderSelect.selectedIndex].value);
                if(scolorSelect && scolorSelect.options[scolorSelect.selectedIndex].value != '')
                    tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'color=' + (scolorSelect.options[scolorSelect.selectedIndex].value);
                if(sdistanceSelect && sdistanceSelect.options[sdistanceSelect.selectedIndex].value != '-1')
                    tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'distance=' + (sdistanceSelect.options[sdistanceSelect.selectedIndex].value);
                if(sZipcodeTxt && sZipcodeTxt.value != '')
                    tmpQry = tmpQry + (tmpQry != '' ? '&' : '') + 'zipcode=' + (sZipcodeTxt.value);
                tmpQry = (tmpQry != '' ? '?' : '') + tmpQry;

                var action = sfindForm.action + (sbreedSelect.options[sbreedSelect.selectedIndex].value) + '.html' + tmpQry;

                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;
		});
	}
});
