
/* show or hide a div */ 
function showorhide(e)
{
  var d=document.getElementById(e);
  var s=getStyleObject(e);
  var p=document.getElementById('mlmp');
  var x = p.x;
  if (!x)
  {
    x = getRealLeft(p);
  }
  var y = p.y;
  if (!y)
  {
    y = getRealTop(p);
  }
  if(d.className=='yo')
  {
    d.className='no';
  }
  else
  {     
    //alert('y = '+ y + ' m_y_off = ' + m_y_off + ' x = '+ x );
    s.top = eval(y+m_y_off);
    s.left = x+eval(e+'_x');
    d.className='yo';
  }    
}

/* Get distance from Top (Y) of an image */
function getRealTop(imgElem) 
{
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}
/* Get distance from Left (X) of an image */
function getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}
function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject


function popupWindow(url, winname, w, h, child, position, scrollbars, resize, status, toolbar, dependent, alwaysRaised, menubar)
{  
  // Default settings - off/nothing
  var scrollbarsetting = 'no';
  var statusbarsetting = 'no';
  var toolbarsetting   = 'no';
  var dependentsetting = 'no';
  var alwaysRaisedsetting = 'no';
  var menubarsetting = 'no';
  var positionsettings = ''; // If empty, won't be output
  var resizesetting    = '';
  
  // Specify width and height, make it 1/2 of screen
  var width  = ((screen.width) / 2);
  var height = ((screen.width) / 2);
  
  // If w & h specified, override the default width and height...
  if (w != width)
  {
    width = w;
  }
  if (h != height)
  {
    height = h;
  }
  
  // Use these values to center the window on-screen
  var winl   = (screen.width - w) / 2;
  var wint   = (screen.height - h) / 2;
  
  // If we want the window centered, use this. Could extend
  // in future to use some of kind of offest
  if (position == 'center')
  {
    positionsettings = 'top='+wint+',left='+winl+',';
  }
  
  //for the below statements, if 'yes' is sent through, change the default setting
  //from 'no' to 'yes'
  
  if (scrollbars == 'yes')
  {
    scrollbarsetting = 'yes';
  }

  if (resize == 'yes')
  {
    resizesetting = ',resizable';
  }

  if (status == 'yes')
  {
    statusbarsetting = 'yes';
  }

  if (toolbar == 'yes')
  {
    toolbarsetting = 'yes';
  }
  
  if (dependent == 'yes')
  {
    dependentsetting = 'yes';
  }
  
  if (alwaysRaised == 'yes')
  {
    alwaysRaisedsetting = 'yes';
  }
  
  if (menubar == 'yes')
  {
    menubarsetting = 'yes';
  }

  // Define the window properties line
  winprops  = 'height=' +height+ ',width=' +width+ ',' +positionsettings+ 'scrollbars=' +scrollbarsetting+ ',toolbar=' +toolbarsetting+ ',status=' +statusbarsetting+ ',dependent=' +dependentsetting+ ',alwaysRaised=' +alwaysRaisedsetting+ ',menubar=' +menubarsetting+ '' +resizesetting;

  // Decide whether we're opening a dependant or normal window
  if (child == 'yes')
  {
    // Dependant, closes when focus is moved away from its parent
    win = open(url, winname, winprops);
  }
  else
  {
    // Normal window, stays open until shut
    win = window.open(url, winname, winprops);
  }

  // Give the new window focus, if we can
  if (parseInt(navigator.appVersion) >= 4)
  {
    win.window.focus();
  }
}

function updateParent(newURL) 
{
  opener.document.location = newURL;
  obgWindow.close();  
}

var submitcount=0;

function checkFields() 
{                       
  if (submitcount == 0)
  {
    submitcount++;
    //alert(submitcount);
    return true;		
  }
  else 
  {		
    alert("Thankyou, this form has already been submitted.");
    return false;
  }   
}

var submitDone;
submitDone = 0;

function preventDoublePosts(form) 
{
	if (document.all && document.form.SubmitButton) 
  {
		//alert("Please wait..."); 
      document.form.SubmitButton.disabled = true;
		document.form.SubmitButton.value = 'Please wait...';
	}

	if (submitDone == 0) 
  {
		submitDone = 1;
		return true;
	}
}

function setCookie(name, value, expires, path, domain, secure) 
{
  var thisCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = thisCookie;
}

/* removes all non-digit characters */
function cleanNumericField(textField)
{
  var notDigit = /[^0-9]/g;
  textField.value = textField.value.replace(notDigit,'');
}