// Stuff for the popup boxes on the replies to the Wanted ads
//
function jshideid(me)
{
  hp = document.getElementById(me);
  hp.style.display = "none";
}
function jsshowid(me)
{
  hp = document.getElementById(me);
  hp.style.display = "block";
}
function jsfocus(me)
{
	document.getElementById(me).focus();	
}
function cwait()
{
	this.style.cursor = "wait";
}
function WantedDisable()
  {
  if (document.wantedform.wanted.value != "Part")
    {
    document.wantedform.quantity.disabled = true;
    document.wantedform.partenter.disabled = true;
    document.wantedform.colour.disabled = true;
    document.wantedform.partcond.disabled = true;
    document.wantedform.meccano.disabled = true;
    document.wantedform.original.disabled = true;
    document.wantedform.opm.disabled = true;
    }
  else
    {
    document.wantedform.quantity.disabled = false;
    document.wantedform.partenter.disabled = false;
    document.wantedform.colour.disabled = false;
    document.wantedform.partcond.disabled = false;
    document.wantedform.meccano.disabled = false;
    document.wantedform.original.disabled = false;
    document.wantedform.opm.disabled = false;
   
    }
  }

function makeCurrentNav(name,linkname)
{
	document.getElementById(name).style.background= 'url(light1x63.gif)';
	document.getElementById(linkname).style.color= "#ffffcc";
	document.getElementById(linkname).style.cursor= "default";
}
function navRollOver(obj, state) {
  document.getElementById(obj).className = (state == 'on') ? 'nav-highlight' : 'navtable';
}
function xstooltip_findPosX(obj) 
{
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}


function xstooltip_findPosY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
function xstooltip_show(tooltipId, parentId, posX, posY)
{
    it = document.getElementById(tooltipId);
    
    if ((it.style.top == '' || it.style.top == 0) 
        && (it.style.left == '' || it.style.left == 0))
    {
        // need to fixate default size (MSIE problem)
        it.style.width = it.offsetWidth + 'px';
        it.style.height = it.offsetHeight + 'px';
        
        img = document.getElementById(parentId); 
    
        // if tooltip is too wide, shift left to be within parent 
        if (posX + it.offsetWidth > img.offsetWidth- 190) posX = img.offsetWidth - it.offsetWidth;
        if (posX < 0 ) posX = 0; 
        
        x = xstooltip_findPosX(img) + posX - 190;
        y = xstooltip_findPosY(img) + posY - 100;
        
        it.style.top = y + 'px';
        it.style.left = x + 'px';
    }

    it.style.visibility = 'visible'; 
}
function xstooltip_hide(id)
{
    it = document.getElementById(id); 
    it.style.visibility = 'hidden'; 
}
var newwindow;
var wheight = 0, wwidth = 0;

function popitup(url, title, iwidth, iheight, colour) {
var pwidth, pheight;

if ( !newwindow || newwindow.closed ) {
pwidth=iwidth+50;
pheight=iheight+80;
newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=yes,scrollbars=yes,top=20,left=20');
wheight=iheight;
wwidth=iwidth;
}

if (wheight!=iheight || wwidth!=iwidth ) {
pwidth=iwidth+50;
pheight=iheight+120;
newwindow.resizeTo(pwidth, pheight);
wheight=iheight;
wwidth=iwidth;
}

newwindow.document.clear();
newwindow.focus();
newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>');
newwindow.document.writeln('<img src=\"' + url + '\" title=\"' + title + '\" alt=\"' + title + '\" >');
newwindow.document.writeln('<small><br/>'+title)
newwindow.document.writeln('<\/center> <\/body> <\/html>');
newwindow.document.close();
newwindow.focus();
}
// newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>');

// Routines to tidy up popup windows when page is left
// Call with an onUnload="tidy5()" in body tag

function tidy() {
if (newwindow && !newwindow.closed) { newwindow.close(); }
}
function initblanklinks() {
	
		// Fetch all the a elements in the document.
		var links = document.getElementsByTagName('a');

		// Loop through the a elements in reverse order
		// for speed.
		for (var i = links.length; i != 0; i--) {
			
			// Pull out the element for this iteration.
			var a = links[i-1];
			
			// If the element doesn't have an href, skip it.
			if (!a.href) continue;

			// If the element has a className that contains
			// 'external' attach the onclick handler.
			if (a.className && a.className.indexOf('blanktarget') != -1) a.onclick = PopWinBlank;
		// Same again for all linked areas
//    var links = document.getElementsByTagName('area');
//		for (var i = links.length; i != 0; i--) {
//			var a = links[i-1];
//			if (!a.href) continue;
//			if (a.className && a.className.indexOf('blanktarget') != -1) a.onclick = PopWinBlank;
		}
	}
	
	function PopWinBlank(e) {
	
		// Accommodate IE's non-standard event handling.
		if (!e) var e = window.event;
		var a = e.target ? e.target : e.srcElement;

		// Open a new window with the link's href.
		var newwin = window.open(a.href);

		// The thought is that if the new window didn't
		// (popups blocked or whatever) we want to return
		// true so the link is follow normally. Not sure
		// if this works, but it doesn't seem to hinder.
		return !newwin;                               
	}
//
//  This one is for checking the number of characters in a textarea field
//
function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
      field.value = field.value.substring(0, maxlimit);
    else 
      countfield.value = maxlimit - field.value.length;
    }
//
// Could we get nzmeccano to start being well-behaved?  Let's try doing things properly...
//
var alreadyloaded = false;
function init() {
	if (alreadyloaded) return;
	alreadyloaded = true;
	initblanklinks();
}
//function addLoadEvent(func) {
//  var oldonload = init;
//  init = function() {
      //oldonload();
      //func();
  //}
//}
window.onload = init;
window.onunload = tidy;
//
//	Now, we should be able to just shove in any functions we like here...  and if we're paranoid we should
//	call init() through a script at the end of every page...
//
//addLoadEvent(initblanklinks);
