var a;
var p;
function copyAddress(o) {
	f = o.form;
	if(f.checky.checked) {
		if(f.home_address.value=='' && f.home_postcode.value=='') {
			alert('You should check this box after adding your home address details. They will then be copied to your advertised address details');
			event.returnValue = false;
		}
		else {
			p = f.ad_postcode.value;
			a = f.ad_address.value;
			f.ad_address.value = f.home_address.value;
			f.ad_postcode.value = f.home_postcode.value;
		}
	}
	else {
		f.ad_postcode.value = p;
		f.ad_address.value = a;
	}
}

function mapClick(l) {
	s = document.forms['Search'].lselect;
	if(!exists(l, s.options))
		s.options[s.options.length] = new Option(locs[l], l, 0, 0);
}

function mapMove() {
	o = document.getElementById('mapLoc');
	o.style.left = num(event.clientX+document.body.scrollLeft)+3;
	o.style.top = num(event.clientY+document.body.scrollTop)-15;
}

function mapOver(l) {
	o = document.getElementById('mapLoc');
	o.innerHTML = locs[l];
	o.style.display = 'inline';
}

function mapOut(l) {
	o = document.getElementById('mapLoc');
	o.style.display = 'none';
}

function num(s) {
	return parseInt(s, 10);
}

function exists(v, o) {
	for(i=0;i<o.length;i++)
		if(o[i].value==v)
			return true;
	return false;
}

function removeSelectedFromSelect() {
	o = document.forms['Search'].lselect.options;
	for(i=0;i<o.length;i++)
		if(o[i].selected) {
			o[i] = null;
			i--;
		}
}

function selectAll() {
	o = document.forms['Search'].lselect.options;
	l = document.forms['Search'].locations;
	for(i=0;i<o.length;i++) {
		if(l.value!='')
			l.value+='|';
		l.value+=o[i].value;
	}
}

function popUp(url, w, h) {
	win = window.open(url, 'atozWin', 'width='+w+',height='+h+',toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=no');
}

var n = 8;
var h = Array(1, 2, 3, 4);
var j;

function changeImages() {
	cont = true;
	while(cont) {
		cont = false;
		i = Math.ceil(Math.random()*4);
		if(i==j)
			cont = true;
	}
	j = i;
	document.images['img'+i].src = 'images/pic'+genImage(i)+'.jpg';
	setTimeout('changeImages();', 1000);
}

function genImage(i) {
	cont = true;
	while(cont) {
		cont = false;
		g = Math.ceil(Math.random()*n);
		for(c=0;c<h.length;c++)
			if(h[c]==g)
				cont = true;
	}
	h[i] = g;
	return g;
}
