base2.DOM.bind(document);

function stopSubmit() {
	var probut = document.matchSingle("#gotopro");
	if (probut) {
		probut.addEventListener('click', prevDef,false);
		probut.addClass('stop_submit');
		var tandc = document.matchSingle("#tanc");
		tandc.addEventListener("click", function(){
			if (this.checked == true) {			
				probut.removeClass('stop_submit');
				probut.removeEventListener('click', prevDef,false);
			} else {
				probut.removeEventListener('click', prevDef,false);
				probut.addEventListener('click', prevDef,false);
				probut.addClass('stop_submit');
			}
		},false);
	}
}

function prevDef(e) {
	e.preventDefault();
}

function setUpSearchField() {
	var searchbox = document.matchAll('.search_term');
	var searchBoxText = "enter search term here";
	searchbox.forEach(function(element){
		element.value = searchBoxText;
	});
	addAutoClear( searchbox, searchBoxText );
	// var advsearch = document.matchSingle('#adv_search_box');
}

function setUpAddBoxes() {
	var addboxes = document.matchAll(".add_to_basket input[type=text]");
	if (addboxes.length) {
		addboxes.forEach(function(element) {
			element.value = 1;
		});
		addAutoClear( addboxes, 1 );
	}
}

function setUpNewWindow() {
	var newWindowLinks = document.matchAll("a[rel=newWindow]");
	if (newWindowLinks.length) {
		newWindowLinks.forEach(function(element){
			element.addEventListener("click", function(e) {
				window.open(element.href);
				e.preventDefault();
			}, false);
		});		
	}

}

function addAutoClear( fieldlist, defaulttext ) {
	if (!fieldlist.length) fieldlist = [fieldlist];
	fieldlist.forEach(function(e) {
		e.onfocus = function() {
			if (this.value == defaulttext) {
				this.value = "";				
			}
		}
		e.onblur = function() {
			if (!this.value) {
				this.value = defaulttext;
			}
		}
	});		
}

function matchAdd() {
	var matchCheck = document.matchSingle("input#matchAdd");
	if ( matchCheck ) {
		matchCheck.onclick = function() {
			var fieldArray = document.matchAll('input[type=text].autofill');
			if (this.checked == true) {
				fieldArray.forEach(function(e){
					var billingId = e.name.substr(7);
					billingId = "delivery" + billingId;
					var billField = document.getElementById(billingId);
					if ( billField ) {
						e.value = billField.value;
					}
				});
			} else {
				fieldArray.forEach(function(e){
					e.value = "";
				});
			}
		};		
	}
}







