// detect browser;
var dom = (document.getElementById) ? true : false;
var nn4 = (document.layers) ? true : false;
var ie4 = (document.all) ? true : false;

// variables
var helpShowing = false;
var offsetX = 15;
var offsetY = 0;

document.onmousemove = updateLayer;

// output layer
if (!nn4) {
	document.write("<DIV ID=\"helpLayer\" STYLE=\"visibility: hidden; position: absolute; z-index: 1000;\"><TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD COLSPAN=\"3\"><IMG WIDTH=\"174\" HEIGHT=\"2\" SRC=\"images/help_top.gif\"></TD></TR><TR><TD WIDTH=\"2\" BACKGROUND=\"images/help_left.gif\"><IMG WIDTH=\"1\" HEIGHT=\"1\" SRC=\"images/dot.gif\"></TD><TD WIDTH=\"170\" BGCOLOR=\"#CCCCCC\"><TABLE WIDTH=\"100%\" HEIGHT=\"100%\"BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD VALIGN=\"TOP\" BACKGROUND=\"images/help_bg.gif\" WIDTH=\"16\"><IMG WIDTH=\"16\" HEIGHT=\"16\" SRC=\"images/help_questionmark.gif\"></TD><TD VALIGN=\"TOP\" WIDTH=\"154\"><TABLE CELLPADDING=\"3\"><TR><TD ID=\"helpLayerContent\" CLASS=\"small\">&nbsp;</TD></TR></TABLE></TD></TR></TABLE></TD><TD WIDTH=\"2\" BACKGROUND=\"images/help_right.gif\"><IMG WIDTH=\"1\" HEIGHT=\"1\" SRC=\"images/dot.gif\"></TD><TR><TD COLSPAN=\"3\"><IMG WIDTH=\"174\" HEIGHT=\"10\" SRC=\"images/help_bottom.gif\"></TD></TR></TABLE></DIV>");
}


// show help layer
function showHelp(type) {
  var content = "";
  helpShowing = true;

  switch(type) {
    case 2:
	  // keyword search
	  content = "Use keyword search to locate the ads on our database submitted by text. Remember that they are text ads and sellers have followed no specifed format.  i.e. You may be looking for a Mercedes Benz 500 SL but a seller may have texted ‘MERC 500 SL’ so search for Mercedes 500 SL, Mercedes Benz 500SL, Merc 500SL, Benz 500SL etc. Website ads will appear if matched.";
	  break;
    default:
	  // car search
	  content = "Choose from the drop down menu and press search to locate a selection of cars available with photos. SMS Text ads will appear if matched.";
  }

  if (ie4) {
    document.all.helpLayerContent.innerHTML = content;
	updateLayer();
	document.all.helpLayer.style.visibility = "";
  } else if (dom) {
    document.getElementById("helpLayerContent").innerHTML = content;
	updateLayer();
    document.getElementById("helpLayer").style.visibility = "";
  }
}

// hide help layer
function hideHelp() {
  helpShowing = false;
  if (ie4) {
	document.all.helpLayer.style.visibility = "hidden";
  } else if (dom) {
    document.getElementById("helpLayer").style.visibility = "hidden";
  }
}

// updates coordinates of the help layer
function updateLayer(e) {
  var mouseX = 0;
  var mouseY = 0;

	if (typeof(e) == "object") {
		mouseX = e.pageX;
		mouseY = e.pageY;
	}

	if (ie4) {
	  mouseX = event.clientX;
	  mouseY = event.clientY;

	  if (helpShowing) {
	    document.all.helpLayer.style.left = mouseX + offsetX;
		document.all.helpLayer.style.top = mouseY + document.body.scrollTop + offsetY;
	  }
	} else if (dom) {
	  if (helpShowing) {
	    document.getElementById("helpLayer").style.left = mouseX + offsetX + 2;
		document.getElementById("helpLayer").style.top = mouseY + offsetY;
	  }
	}
}

if (nn4) {
  document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
}