window.onload = function(){
  var inputs = document.getElementsByName("search_btn");
  for (var i=0; i<inputs.length; i++){
    var input = inputs[i];
    var parent = input.parentNode;
	var inputtxt = input.value;
    var button = document.createElement("a");
    var buttonimg = document.createElement("img");
    var buttontxt = document.createTextNode(inputtxt);
    button.href = "#";
    button.className = "next";
    button.onclick = checkZip;
//    buttonimg.src = "modix-datadir/btn_next.gif";
//    buttonimg.alt = "";
    button.appendChild(buttontxt);
//    button.appendChild(buttonimg);
    parent.appendChild(button);
    parent.removeChild(input);
  }
}
var checkZip = function(){
	var zip_alert = "Please enter a valid ZIP code";
	if (document.body.className == "nl") {zip_alert = "Voer aub een geldige postcode in";};
	if (document.body.className == "fr") {zip_alert = "Veuillez v&#xE9;rifier votre code postal";};
	var theForm = document.getElementById("searchByZip");
	var obj = theForm.elements[0].value;
	if (window.RegExp) {
		if(obj.match(/^[0-9]{4}$/)) theForm.submit();
		else alert(zip_alert);
	} else {
		if(obj.length == 4) theForm.submit();
		else alert(zip_alert);
	}
}
var reloadOptions = function(){
	var optionsForm = document.getElementById('searchOptions');
	optionsForm.action = optionsForm.selfurl.value;
	optionsForm.selfurl.value = '';
	optionsForm.sort.value = '';
	optionsForm.search_vehicles.value = '';
	optionsForm.submit();
}
