function searchRecycler(field) {
	field = trimAll(field);
	if (validateZIP(field)) {
		window.location = "SearchRecyclers.aspx?postalcode=" + field;
		return true;
	}
	else
		return false;
}

function searchEvent(field) {
	field = trimAll(field);
	if (validateZIP(field)) {
		window.location = "SearchEvents.aspx?eventpostalcode=" + field;
		return true;
	}
	else
		return false;
}

function pickdate(ctl) {
    var winTop = (screen.height / 2) - 105
    var winLeft = (screen.width / 2 ) - 110
    var settings='width=220,height=210,left=' + winLeft + ',top=' + winTop

    var PopupWindow = null;
    PopupWindow = window.open('DatePicker.aspx?textbox=' + ctl,'cal',settings);
    PopupWindow.focus()
}

function validateZIP(field) {
	// match either Canadian 6 char alphanumeric postal code
	// or US numeric zip with optional dash and 4 char extension
	var match = /^(([0-9]{5})|([0-9]{5}\-[0-9]{4})|([A-Za-z0-9]{3}\s[A-Za-z0-9]{3}))$/.test(field)

	if (!match)
		alert("Please enter your 5 digit or 5 digit+4 zip US zip code or 6 character Canadian postal code.");
		
	return match;
}

function trimAll(sString)  {
	return sString.replace(/^\s+|\s+$/g,"");
}

function GoPressed(e) {
	var characterCode
	if(e && e.which){           // NN4 specific code
		e = e
		characterCode = e.which
	}
	else {
		e = event
		characterCode = e.keyCode // IE specific code
	}
	if (characterCode == 13) {	
		searchRecycler(document.getElementById('uclSideContent_txtZipCode').value);   // Enter key is 13
		window.location.reload(false);
		return false;
	}
}

function GoPressedEvent(e) {
	var characterCode
	if(e && e.which){           // NN4 specific code
		e = e
		characterCode = e.which
	}
	else {
		e = event
		characterCode = e.keyCode // IE specific code
	}
	if (characterCode == 13) {	
		searchEvent(document.getElementById('uclSideContent_txtEventZipCode').value);   // Enter key is 13
		window.location.reload(false);
		return false;
	}
}
