var opened = '';
function MenuOver(id, graphic, colour) {
oid = "menu" + id;
document.getElementById(oid).style.backgroundColor = colour;
imgid = 'img' + id;
if (id == opened) {
  src = 'images/' + graphic + '_downover.gif';
} else {
  src = 'images/' + graphic + '_over.gif';
}
document.getElementById(imgid).src = src;
}

function MenuOut(id, graphic, colour) {
oid = "menu" + id;
document.getElementById(oid).style.backgroundColor = colour;
imgid = "img" + id;
if (id == opened) {
  src = 'images/' + graphic + '_down.gif';
} else {
  src = 'images/' + graphic + '.gif';
}
document.getElementById(imgid).src = src;
}

function MenuClick(id, graphic) {
 oid = "submenu" + id;
 if (id == opened) {  document.getElementById(oid).style.display = 'none';
  opened = '';
  imgid = 'img' + id;
  src = 'images/' + graphic + '_over.gif';
  document.getElementById(imgid).src = src;
 } else {
  if (opened != '') {
   sub = 'submenu' + opened;
   imgid = 'img' + opened;
   src = 'images/' + graphic + '.gif';
   document.getElementById(sub).style.display = 'none';
   document.getElementById(imgid).src = src;
   opened = '';
  }
  document.getElementById(oid).style.display = 'block';
  opened =  id;
  imgid = 'img' + id;
  src = 'images/' + graphic + '_downover.gif';
  document.getElementById(imgid).src = src;
 }
}

function OnLoadMenuClick(id, graphic) {
 oid = "submenu" + id;
 if (id == opened) {  document.getElementById(oid).style.display = 'none';
  opened = '';
  imgid = 'img' + id;
  src = 'images/' + graphic + '_over.gif';
  document.getElementById(imgid).src = src;
 } else {
  if (opened != '') {
   sub = 'submenu' + opened;
   imgid = 'img' + opened;
   src = 'images/' + graphic + '.gif';
   document.getElementById(sub).style.display = 'none';
   document.getElementById(imgid).src = src;
   opened = '';
  }
  document.getElementById(oid).style.display = 'block';
  opened =  id;
  imgid = 'img' + id;
  src = 'images/' + graphic + '_down.gif'; //This line differs from the MenuClick function, the arrow graphic is different.
  document.getElementById(imgid).src = src;
 }
}

function jumpmenuChange(obj) {
 var dest = obj.options[obj.selectedIndex].value;
 document.location = dest;
}

function DoPoll() {
 document.pollform.submit();
}

function DoSearch() {
 if (document.searchform.ss.text != '') {
 	document.searchform.submit();
 }
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		home_btn_over = newImage("images/home_btn-over.jpg");
		home_btn_down = newImage("images/home_btn-down.jpg");
		irishhealth_btn_over = newImage("images/irishhealth_btn-over.jpg");
		clinics_btn_over = newImage("images/clinics_btn-over.jpg");
		preloadFlag = true;
	}
}

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];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function validateForm() {
		if ( document.all || document.getElementById ) {
			var answers = new Array();
			// make sure there is an answer to every question
			with ( document.mainform ) {
				for ( var i = 0; i < elements.length; i++ ) {
					if ( elements[ i ].name != "btn" ) {
						if ( elements[ i ].checked == true ) {
							answers[ answers.length ] = elements[ i ].value;
						}
					}
				}
			}
			if ( answers.length == 5 ) {
				// all questions have been answered
				document.mainform.submit();
			} else {
				alert( "Please select an answer for every question." );
			}
		} else {
			document.elements;
		}
	}

function GoToTopic(obj) {
var id = obj.options[obj.selectedIndex].value;
if (id > 0) {
  var dest = 'http://www.irishhealth.com/index.html?level=4&con=' + id;
  document.location = dest;
}
}

// Dave Maxwell, Medmedia, Sept 2007
function windowOpener(url, name, args) {
  if (typeof(popupWin) != "object"){
    popupWin = window.open(url,name,args);
  } else {
    if (!popupWin.closed){
      popupWin.location.href = url;
    } else {
      popupWin = window.open(url, name,args );
    }
  }
  popupWin.focus();
}
