function addFormEvent(func) {
  if (!document.getElementById | !document.getElementsByTagName) return
	var oldonload=window.onload
	if (typeof window.onload != 'function') { window.onload=func }
	else {
		window.onload=function() { oldonload(); func() }
	}
}


// --------------------- for text type inputs ------------------------------ //
function attachBorderAndSelect(id){
  var obj0 = document.getElementById(id)
  obj0.onfocus= function() {this.style.border="2px solid #f00"; this.select();}
 obj0.onblur = function() {
                  this.style.border="2px inset #ccc"
                  if (this.value=="") {this.value=this.defaultValue}
                  this.value=this.value
                }
} 
// ----------------------------------------------------------------------------- //


// -------------------------- for radio and checkboxes ------------------------- //
function attachBorderToRadio(id){
  var obj0 = document.getElementById(id)
  obj0.onfocus= function() {this.style.border="2px solid #f00"}
  obj0.onblur = function() {this.style.border="2px solid #fff7dd"}
}
// ----------------------------------------------------------------------------- //


// ------------------------------ for submit buttons --------------------------- //
function attachBorderToButton(id){
  var obj0 = document.getElementById(id)
  obj0.onfocus= function() {this.style.border="2px solid #f00"}
  obj0.onblur = function() {this.style.border="2px outset #fff"}
}
// ----------------------------------------------------------------------------- //


// ----------------------------------------------------------------------------- //

// help clicked therefore show help.
function showHelp(id){
	if (!document.getElementsByTagName) return
	if (document.getElementById(id).style.display=='block'){
		document.getElementById(id).style.display='none'
	}
	else{
		document.getElementById(id).style.display='block'
	}
	//  focus is moved by the href of the link to the start of the help
}


// simple search form
function initSimpleSearch(){
// the search associations
	attachBorderAndSelect('searchterm');
	attachBorderToButton('searchbutton');
 attachBorderToButton('Submit');
 attachBorderToButton('google_submit');
}



// simple login form
function initSimpleLogin(){
// login associations
	attachBorderAndSelect('loginname');
	attachBorderAndSelect('loginpassword');
	attachBorderToButton('loginbutton');
}




// example contact form
function initContact(){
// the simple contact form
	if (!document.getElementsByTagName) return


	// JavaScript is available so hide the help divs


// text type inputs
 attachBorderAndSelect('name');
 attachBorderAndSelect('email');
 attachBorderAndSelect('phone');
 attachBorderAndSelect('site');
 attachBorderAndSelect('google_term');


// textfield
 attachBorderAndSelect('query');

// radio buttons defined individually
// though it does not appear to work (firefox) except in IE
 attachBorderToRadio('rad2_1');
 attachBorderToRadio('rad2_2');

// checkbox
// this does not appear to work except in IE
 attachBorderToRadio('check1_0');

// submit

}

function initGeneral(){

// text type inputs
 attachBorderAndSelect('description1');

// radio buttons
  attachBorderToRadio('rad_0')
  attachBorderToRadio('rad_1')
  attachBorderToRadio('rad_2')
  attachBorderToRadio('rad_3')
  attachBorderToRadio('rad_4')


// checkboxes
  attachBorderToRadio('chk_0')
  attachBorderToRadio('chk_1')


// file upload button
  attachBorderAndSelect('upload')

// required field
// selecting the value does not seem to work in IE
  attachBorderAndSelect('namereq')

// Hide the other help items
  attachBorderAndSelect('simpleselectexample')
  attachBorderAndSelect('simpleselectexample')



}

// ------------------------------------------------------------------------------------
// scroll coordinate
var xpos=0, ypos=0
function getScrollCoords() {
  xpos = (document.all)?document.body.scrollLeft:window.pageXOffset;
  ypos = (document.all)?document.body.scrollTop:window.pageYOffset;
}

function setScrollCoords() {
  window.scrollTo(xpos, ypos);
}




addFormEvent(initSimpleSearch)
addFormEvent(initSimpleLogin)
addFormEvent(initContact)
addFormEvent(initGeneral)
