/****************************************************************** 
SIMPLE USEFULL FUNCTIONS ( pete jervis ) 
******************************************************************/

   // sets the image height to the td height in a table  
   // gets over problems with IE and opera which cannot
   // render image height="100%"

   function drawsides(idname,img_height,img_height){
    var idname; 
  	growImg = document.getElementById(idname).style;
  	growImg.width= img_width;
  	growImg.height= img_height;
  	
   }
	 
	 // show a random letter image when the page is loaded
   function randomletter(path){
  	 var letter;
  	 
    	 if(!path){
    	   var path = "images/";
    	 }
  	 letter = String.fromCharCode(97 + Math.round(Math.random() * 25));
		 // exclude a letter x as we do not have it yet
		   if(letter == 'x'){
		 	 		letter = 'y';			 
		   }
  	 document.write("<img src='" + path + letter + ".jpg'>");
	 }
	 
// javascript function for pages useing mainSSSsplit.ihtml template
// look in /home/spelling/templates
//	 
       function SetLocate(obj, id)
      {
        if (id.charAt(0) == "#")id = id.slice(1);
        firstLetter = id.charAt(0);
        obj.href += "?j=" + firstLetter.toUpperCase() + "&id=" + id;
	obj.hash = "#" + id;
        return false;
      }

// get values out of the url to use in highltighting links
function getQuery(name){
	var query = self.location.search;
	if(query.length > 0){
		name = name+"=";
		var str = query.substring(1);
		var start = str.indexOf(name);
		if(start == -1) return null;
		start += name.length;
		var end = str.indexOf("#", start);
		if(end == -1) end = str.length;
		return unescape(str.substring(start,end));
	}else{
		return null;
	}
}

// highlight some text of the correct id
function highlight(newClass) {

var id = getQuery("id");
if (id == null){return;}	// added 22/02/05 - JSM
identity=document.getElementById(id);
identity.className=newClass;

}	

function newWindow()
{
	comWindow = window.open("comments.html",
		"comWin", "width=450, height=276");
}

function setForm()
{
	document.comt.comment.focus();
	document.comt.comment.select();
}

function submitIt(theForm)
{
	if (theForm.comment.value == "")
	{
		alert("You must make a comment!");
		obj = document.getElementById("lab1");
		obj.style.color = "red";
		theForm.comment.focus();
		theForm.comment.select();
		return false;
	}
	return confirm("Is the comment correct?");
}

// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();		 
		 
		 
function writeBGbar(){
				 var bgheight;
				 var bgimg;
				 //compensate for some ie weardness
				 if(browser.isIE6up == true){
				  bgheight = 16;// fix image size issues with ie to make the menu look right
				 }else{
				 	bgheight = 18;  
				 }	 		 		
				 //bgimg = '<img src="'+ level + images +'pixelg.gif" hspace="0" border="0" vspace="0" width="800" height="'+ bgheight +'"name="menu_gif" />';
				 document.write(bgheight);
				 //alert(bgheight); //debugging
}
  function doClear()
	{
		setYOB(true);
		setOccupation(false);
		setHowFind(false);
		return true;
	}

  function doCheck(f)
	{
		if (f == 1)
		{
			val = document.memberForm.occupation.value;
			if (val == "other")
				return setOccupation(true);
			return setOccupation(false);
		}
		val = document.memberForm.foundFrom.value;
		if (val == "other")
			return setHowFind(true);
		return setHowFind(false);
	}

  function setAddress(r)
	{
		obj = document.getElementById("addressFieldset");
		if (r)
			obj.style.display = "block";
		else
			obj.style.display = "none";
		return true;
	}

  function setYOB(r)
	{
		if (r)
		{
			setAddress(false);
		}
		else
		{
			setAddress(true);
		}
		return true;
	}

  function setOccupation(r)
	{
		obj = document.getElementById("occupationSpecify");
		if (r)
		{
			obj.className = "visi";
			document.memberForm.occupationSpecify.focus();
		}
		else
		{
			obj.className = "hidi";
			document.memberForm.occupationSpecify.value = "";
		}
		return true;
	}

  function setHowFind(r)
	{
		obj = document.getElementById("foundSpecify");
		if (r)
		{
			obj.className = "visi";
			document.memberForm.foundSpecify.focus();
		}
		else
		{
			obj.className = "hidi";
			document.memberForm.foundSpecify.value = "";
		}
		return true;
	}

  function submitForm(theForm)
	{
		if (validateMember(theForm, opt)) {
			return confirm("Are these details correct?\n\n(N.B. If you do not receive the automated reply\nPlease check your email address and reapply.)");
      }
		return false;
	}

  function validateMember(theForm, opt)
	{
		if (theForm.firstName.value == "")
		{
			alert("*** You must Supply a first name ***");
			obj = document.getElementById("firstNameLbl");
			obj.style.color = "red";
			theForm.firstName.focus();
			theForm.firstName.select();
			return false;
		}
		obj = document.getElementById("firstNameLbl");
		obj.style.color = "green";
      if (theForm.lastName.value == "")
		{
			alert("*** You must Supply a last name ***");
			obj = document.getElementById("lastNameLbl");
			obj.style.color = "red";
			theForm.firstName.focus();
			theForm.firstName.select();
			return false;
		}
		obj = document.getElementById("lastNameLbl");
		obj.style.color = "green";
		if (theForm.emailAddress.value == "")
		{
			alert("*** You must Supply an E-mail address ***");
			obj = document.getElementById("emailAddressLbl");
			obj.style.color = "red";
			theForm.emailAddress.focus();
			theForm.emailAddress.select();
			return false;
		}
		re =  /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
		if (!re.test(theForm.emailAddress.value))
		{
			alert("*** "+theForm.emailAddress.value+" is not a valid E-mail address ***");
			obj = document.getElementById("emailAddressLbl");
			obj.style.color = "red";
			theForm.emailAddress.focus();
			theForm.emailAddress.select();
			return false;
		}
		obj = document.getElementById("emailAddressLbl");
		obj.style.color = "green";
		if (theForm.emailAddress.value != theForm.emailAddress2.value)
		{
			alert("*** E-mail Addresses do not match ***");
			obj = document.getElementById("emailAddress2Lbl");
			obj.style.color = "red";
			theForm.emailAddress2.focus();
			theForm.emailAddress2.select();
			return false;
		}
		obj = document.getElementById("emailAddress2Lbl");
		obj.style.color = "green";
		if (opt != 0)
		{
			if (theForm.address1.value == "")
			{
				alert("*** You must Supply an Address ***");
				obj = document.getElementById("address");
				obj.style.color = "red";
				return false;
			}
			obj = document.getElementById("address");
			obj.style.color = "green";
		}
		obj = document.getElementById("memberTypeLbl");
		obj.style.color = "green";
		return true;
	}
	
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


