function loctype(which) {
	if (which == "country") {
		document.getElementById('country').disabled = false;
		document.getElementById('state').disabled = false;
		document.getElementById('cruisingarea').disabled = true;
	} else {
		document.getElementById('country').disabled = true;
		document.getElementById('state').disabled = true;
		document.getElementById('cruisingarea').disabled = false;		
	}
}
function sortby(what) {
	if (document.getElementById('sortdir').value == "desc") {
		document.getElementById('sortdir').value = "";
	} else {
		document.getElementById('sortdir').value = "desc";
	}
	document.getElementById('sortby').value = what;
	subfrm();
}
function subfrm(resetpage) {
	if (resetpage == true) {
		document.getElementById('startfrom').value = 0;
	}
	document.getElementById('usedboatfrm').submit();
}
function gopage(page) {
	document.getElementById('startfrom').value = page;
	subfrm(false);
}
function advancedsearch() {
	document.getElementById('searchtype').value = "advanced";
	subfrm(true);
}
function basicsearch() {
	document.getElementById('searchtype').value = "basic";
	subfrm(true);
}

function showduplicate(which) {
	document.getElementById('showduplicate').value = which;
	subfrm(false);	
}

function backtoresults() {
	document.getElementById('showduplicate').value = "";
	subfrm(false);	
}

function checksel(whatlst) {
	if (whatlst.selectedIndex == 0) {
		whatlst.selectedIndex = 0;
	}
}
function showstates() {
	countrylist = document.getElementById('multicountry');
	statelist = document.getElementById('multistate');
	statelist.options.length = 0;
	statelist.options[statelist.options.length] = new Option("Any","all",false,true);
	for (i=0;i<countrylist.options.length;i++) {
		opt = countrylist.options[i];
		if (opt.selected) {
			states = countries[opt.text];
			if (states) {
				for (i2=0;i2<states.length;i2=i2+2) {
					statelist.options[statelist.options.length] = new Option(states[i2],states[i2+1]);
				}
			}
		}
	}
	if (statelist.options.length == 1) {
		statelist.options[0].text = "Not applicable for the selected countries";
		statelist.options[0].selected = false;
	}
	if (selectedstates.length > 0 && selectedstates[0] != "all") {
		statelist.options[0].selected = false;
		for (i=0;i<selectedstates.length;i++) {
			for (i2=0;i2<statelist.options.length;i2++) {
				if (statelist.options[i2].value == selectedstates[i]) {
					statelist.options[i2].selected = true;
				}
			}
		}
	}
	selectedstates.length = 0;
	for (i=0;i<statelist.options.length;i++) {
		if (statelist.options[i].selected) {
			selectedstates[selectedstates.length] = statelist.options[i].value;
		}
	}
}

function resetusedboatfrm() {
	document.getElementById('multicountry').selectedIndex = -1;
	document.getElementById('multicruisingarea').selectedIndex = -1;
	document.getElementById('pricefrom').selectedIndex = 0;
	document.getElementById('priceto').selectedIndex = 0;
	document.getElementById('multibrand').selectedIndex = 0;
	document.getElementById('multimtype').selectedIndex = 0;
	document.getElementById('multiloa').selectedIndex = 0;
	statelist = document.getElementById('multistate');
	statelist.options.length = 0;
	statelist.options[statelist.options.length] = new Option("Not applicable for the selected countries","all",false,true);
	statelist.selectedIndex = -1;
}

function subscribe() {
	if (confirm("You have opted to subscribe to receive weekly mailings of used multihulls, from around the web.\r\nThe list of boats you receive will be tailored to your requirements, according to the options you have selected on this page.\r\nIf you want to review the options you have selected, click 'Cancel'. Alternatively, choose 'OK' to confirm your subscription.")) {
		document.getElementById('subaction').value = "subscribe";
		subfrm();
	}
}

function updatesub() {
	if (confirm("You have opted to update your subscription options.\r\nThe list of boats you receive will be tailored to your requirements, according to the options you have selected on this page.\r\nIf you want to review the options you have selected, click 'Cancel'. Alternatively, choose 'OK' to confirm your subscription.")) {
		document.getElementById('subaction').value = "update";
		subfrm();
	}
}

function unsubscribe() {
	if (confirm("Are you sure you want to unsubscribe from the used boat weekly email update?")) {
		document.getElementById('subaction').value = "unsubscribe";
		subfrm();
	}
}