// Nav button rollover
function onButton(thisBut) {
	var thisNavButton=document.getElementById('but'+thisBut);
	var thisNavLink=document.getElementById('butlink'+thisBut);
}

function offButton(thisBut) {
	var thisNavButton=document.getElementById('but'+thisBut);
	var thisNavLink=document.getElementById('butlink'+thisBut);
}

function onDropButton(thisBut) {
	var thisNavButton=document.getElementById('dropbut'+thisBut);
	var thisNavLink=document.getElementById('dropbutlink'+thisBut);
}

function offDropButton(thisBut) {
	var thisNavButton=document.getElementById('dropbut'+thisBut);
	var thisNavLink=document.getElementById('dropbutlink'+thisBut);
}

// Menu drops
droplayer=new Array()
droplayer[0]="drop1"

// simple browser check
v4=(parseInt(navigator.appVersion)>=4 && parseInt(navigator.appVersion)<=5)?1:0
ie=(document.all && v4)?1:0
ns=(document.layers && v4)?1:0
dom=(document.getElementById) && !ie;

// code for drops
function getElem(p2) 
{
	var Elem;
   	 Elem = eval(document.getElementById(p2));
     return(Elem);
}

function showdrop(thelayer)
{
	keep=thelayer; hideall(); showitnow=1
	showit(thelayer)
}

function showit(thelayer)
{
	if(ie){ eval(droplayer[thelayer]+'.style.visibility="visible"') }
	if(ns){ eval('document.'+droplayer[thelayer]+'.visibility="show"');}
	if(dom)
	{ 
		var e=getElem(droplayer[thelayer]); 
		e.style.visibility="visible";
	}
}

function hidedrop()
{
	keep=-1; setTimeout('hideall()',500)
}

keep=-1

function hideall(){
	for(i=0;i<droplayer.length;i++)
	{  
		hideit=0; checkmousepos(i)
		if(ie && keep!=i){ 
			if(hideit){ eval(droplayer[i]+'.style.visibility="hidden"') } 
			}
		if(ns && keep!=i){ 
			if(hideit){ eval('document.'+droplayer[i]+'.visibility="hide"') }
			}
		if(dom && keep!=i){ 
			if(hideit)
			{ 
				var e=getElem(droplayer[i]); 
				e.style.visibility="hidden";
			}
		}
	}
}

// deal with cursor over layer
document.onmousemove = getmousepos
if (ns) document.captureEvents(Event.MOUSEMOVE)

function getmousepos(e)
{
	if(ns || dom){mousex=e.pageX; mousey=e.pageY}
	if(ie){mousex=event.clientX; mousey=event.clientY;}
}

function checkmousepos(i)
{          
	if(ns)
	{   //  alert(getElem(droplayer[i]));
		x_min=eval('document.'+droplayer[i]+'.left')
		x_max=x_min+eval('document.'+droplayer[i]+'.clip.width')
		y_min=eval('document.'+droplayer[i]+'.top')
		y_max=y_min+eval('document.'+droplayer[i]+'.clip.height')
	}    
	if( dom)
	{  var e=getElem(droplayer[i]);
		x_min=e.style.left;
		x_min=e.style.right;
		x_max=x_min+e.style.width;
		y_min=e.style.top;
		y_max=y_min+e.style.height;
	}    
	if(ie)
	{     
		x_min=eval(droplayer[i]+'.style.pixelLeft')
		x_max=x_min+eval(droplayer[i]+'.style.pixelWidth')
		y_min=eval(droplayer[i]+'.style.pixelTop')
		y_max=y_min+eval(droplayer[i]+'.style.pixelHeight')
	}
	if (mousex>=x_min && mousex<=x_max && mousey>=y_min && mousey<=y_max)
	{
		hideit=0; setTimeout('hideall()',500)
	}
	else { hideit=1 }
	return hideit
}

// Preload images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// Validate Enquiry form
function validate(f) {
	if (isFilled(f.contactName)==false) {
		alert("Contact Name field cannot be blank");
		f.contactName.focus();
		return false;
	}
	if (isFilled(f.email)==false) {
		alert("Email field cannot be blank!");
		f.email.focus();
		return false;
  	}
  	if (validEmail(f.email.value)==false) {  // check e-mail address is valid
		alert("Invalid email address!");
		f.email.focus();
		f.email.select();
		return false;
  	}
	return true;
}

function isFilled(elm) {
	if (elm.value=="" || elm.value==null) {
		return false;
	} else {
		return true;
	}
}

function validEmail(email) {
	invalidChars = " /:,;";
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = email.indexOf("@",1)	// there must be one "@" symbol
	if (atPos == -1) {
		return false;
	}
	if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		return false;
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {	// and at least one "." after the "@"
		return false;
	}
	if (periodPos+3 > email.length)	{	// must be at least 2 characters after the "."
		return false;
	}
	return true;
}

// Image popup
function popupImg(imgName,imgWidth,imgHeight,imgDescription) {
	var displayImgWin=window.open('','','top=10,left=10,scrollbars=yes,resizable=yes,toolbar=no,status=no,width=' + imgWidth +',height=' + imgHeight);
	displayImgWin.document.write('<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">');
	displayImgWin.document.write('<html xmlns=\"http://www.w3.org/1999/xhtml\">');
	displayImgWin.document.write('<head>');
	displayImgWin.document.write('<title>' + imgDescription + '</title>');
	displayImgWin.document.write('</head>');
	displayImgWin.document.write('<body style="margin:0px;">');
	displayImgWin.document.write('<img src=\"images/' + imgName + '\" width=\"' + imgWidth +'\" height=\"' + imgHeight + '\" alt=\"' + imgDescription + '\" border=\"0\" />');
	displayImgWin.document.write('</body>');
	displayImgWin.document.write('</html>');
	return false;
}
