function input2qs(id,name) {
var el=document.getElementById(id);
if (!el) return '';
return "&"+name+"="+el.value
}
function select2qs(id,name) {
var el=document.getElementById(id);
if (!el) return '';
return "&"+name+"="+el.options[el.selectedIndex].value
}
function search_submit(url, bGrid) {
// Parse out zipcode
var zip=''
var elZip=document.getElementById('id_zip_key');
if (elZip.value!='')
	// user selected value
	zip=elZip.value
else {
	// try and parse out zip
	var elZip=document.getElementById('id_zip');
	if (elZip) {
		arrZip=elZip.value.split(" ");
		for (var i=0; i<arrZip.length; i++)
			if (/^\d{5}$/.test(arrZip[i])) {
				zip=arrZip[i]
				break;
			}
	}
}

var elMiles=document.getElementById("id_miles");
var miles=null;
if (elMiles)
	miles=elMiles.options[elMiles.selectedIndex].value

/* Removed as empty zip should be equal to nationwide search 
if (miles != 'Nationwide' && (zip=='' || zip==null)) {
	alert("Please input a 5 digit Zip or select a Location from the list");
	document.getElementById('id_zip').focus();
	return false;
}
*/

// get local chapter number filter information
if(document.getElementById('filter_local')) {
	var local = document.getElementById('filter_local').value;
	document.getElementById('id_local').value = local;
}
if(document.getElementById('id_local').value == 'Local #'){
	document.getElementById('id_local').value = '';	
}


var qs_xtra=""
if (bGrid) {
	qs_xtra="&grid=1"
}

window.location=url+
input2qs('id_abbr','abbr') + 
input2qs('id_abbr_key','abbr_key') + 
select2qs('id_state','state') + 
select2qs('id_miles','miles') + 
input2qs('id_bizcat','bizcat') + 
input2qs('id_zip','zip') + 
input2qs('id_local','local') + 
"&zip_key=" + zip;
/*
window.open(url+
input2qs('id_abbr','abbr') + 
input2qs('id_abbr_key','abbr_key') + 
select2qs('id_state','state') + 
select2qs('id_miles','miles') + 
input2qs('id_zip','zip') + 
"&zip_key=" + zip
+ qs_xtra, "DOL");
*/	
}


function clearOnClickAndNull(id, nullValue) {
	var input = document.getElementById(id);
	
	if(input.value == nullValue) {
		input.value = '';	
	}
}

function submitOnEnter(event) {
	if(event.which == 13) { // enter key
		document.getElementById('searchInputButton').click();
	}
}
