/* AUTO-POPULATE SEARCH BOX
 * @param int x - Variable defining the status of the textbox (onBlur/onFocus)
 */
function fillSearch(x){
	var theForm = document.getElementById('searchForm'); // Define form object	
	if(x==1) // OnBlur
	{	if(theForm.searchterm.value=='')
		{	theForm.searchterm.value = 'town, county';
		}
	}else // OnFocus
	{	if(theForm.searchterm.value=='town, county')
		{	theForm.searchterm.value = '';
		}
	}	
}

/* AUTO-POPULATE NEWSLETTER BOX
 * @param int x - Variable defining the status of the textbox (onBlur/onFocus)
 */
function fillNewsletter(y, x){
	var theForm = document.getElementById('nlForm'); // Define form object	
	if(y==1){
		if(x==1) // OnBlur
		{	if(theForm.name.value=='')
			{	theForm.name.value = 'type your name';
			}
		}else // OnFocus
		{	if(theForm.name.value=='type your name')
			{	theForm.name.value = '';
			}
		}
	}else{
		if(x==1) // OnBlur
		{	if(theForm.email.value=='')
			{	theForm.email.value = 'type your e-mail address';
			}
		}else // OnFocus
		{	if(theForm.email.value=='type your e-mail address')
			{	theForm.email.value = '';
			}
		}
	}
}



// ** Popup box hover thingy (c)2005 by Ralph Capper
// ** Free for you to use - but please credit me - www.ralpharama.co.uk
// Start trapping mouse

if (document.layers) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=mtrack;
var ent; // Our floating div
var posx=0; // Our mouseX
var posy=0; // Our mouseY
var offsetX=16; // Offset X away from mouse
var offsetY=16; // Offset Y
var popUp = false; // Is it showing right now??!

// Run upon load
function init() {
// Set up div we will use to hover our text
ent = document.createElement("div");
// Change these to customise your popup
ent.style.color = "#000000";
ent.style.font = "normal xx-small verdana";
ent.style.padding = "1px 1px 1px 1px";
ent.style.background = "#fff588";
ent.style.border = "1px solid black";
// Don't, however, change these
ent.style.left = -100;
ent.style.top = -100;
ent.style.position = 'absolute';
ent.innerHTML = '';
ent.style.zIndex = 10;
document.getElementById("thepage").appendChild(ent);
}
// Keeps mouse x and y in posx and posy

function mtrack(e) {
if (popUp) {
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft;
posy = e.clientY + document.body.scrollTop;
}
ent.style.left = posx + offsetX;
ent.style.top = posy + offsetY;
}
}
// Change floating div to correct text on mouseover

function doText(t, e) {
popUp = true;
ent.innerHTML = t;
}
// Change back to nothing

function doClear() {
popUp = false;
ent.style.left = -100;
ent.style.top = -100;
ent.innerHTML = "";
}


/* DISPLAY / HIDE Price field in JS (Register Advert)
 *
 */
function displayprice(){
	var price = document.getElementById("show_price");
	var type = document.getElementById("det_adtype");
	var field = document.getElementById("fld_price");
	
	/* Show and enable price field */
	if(type.value=="BUYING"){
		field.disabled = true;
		field.value = "";
		price.style.display = 'none';
		
	}
	/* Hide, clear and disable price field */
	if(type.value=="SELLING"){
		price.style.display = 'block';
		field.disabled = false;
	}
}


function termsAndPrivacy(){
	var terms = document.getElementById("det_terms");
	var privacy = document.getElementById("det_privacy");
	if(!privacy.checked || !terms.checked)
	{	alert("You must have read the Terms & Conditions and agree to the Privacy policy to continue.");
		return false;
	}else
	{	return true;	
	}
}