im_path = "im/"

main_menu = new Array("but_donate_f2.gif")
//rhs_menu_who = new Array("but_rhs_who_f2.gif", "but_rhs_members_f2.gif", "but_rhs_partners_f2.gif")

win_arr = new Array("http://www.internationalfuturesforum.com/im/kitbag_inside1.jpg");

function runCountryCheck(country_var)
{
	id = document.getElementById(country_var);
	div_elem = document.getElementById('counties');
	
	if (county_arr[id.value])
	{
		div_elem.innerHTML = county_arr[id.value];
		document.getElementById('counties').style.position= "relative"
		document.getElementById('counties').style.visibility = "visible"
	}
	else 
	{
		document.getElementById('counties').style.position= "absolute";
		document.getElementById('counties').style.visibility = "hidden";
	}
}

function share (url_str)
{
	newWin('share.php?' + url_str, '600', '350')	
}

//-------- check relatedTarget

function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

function checkMouseEnter (element, evt) {
  if (element.contains && evt.fromElement) {
    return !element.contains(evt.fromElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

function checkMouseLeave (element, evt) {
  if (element.contains && evt.toElement) {
    return !element.contains(evt.toElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}
//-------- /check relatedTarget


//----- fade in/out divs

function SetOpacity(elem, opacityAsInt)
{
	var opacityAsDecimal = opacityAsInt;
	
	if (opacityAsInt > 100)
	opacityAsInt = opacityAsDecimal = 100; 
	else if (opacityAsInt < 0)
	opacityAsInt = opacityAsDecimal = 0; 
	
	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
	opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	
	elem.style.opacity = (opacityAsDecimal);
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")"; 
}

fadeInPattern = new Array(20, 30, 40, 55, 65, 72, 77, 81, 84, 87, 90, 92, 94, 96, 100);
fadeOutPattern = new Array(95, 90, 85, 80, 73, 65, 54, 42, 25, 0, 0, 0, 0, 0, 0);
//fadeOutPattern = new Array(80, 60, 45, 35, 28, 22, 17, 13, 10, 5, 0, 0, 0 ,0 ,0);
var fade_opacity_steps = 15; // length of above arrays

var fade_opacity_stepNum = new Array();
var fade_opacity_inOut = new Array();

function FadeOpacityStep(elemId)
{
	stepNum = fade_opacity_stepNum[elemId];
	inOut = fade_opacity_inOut[elemId];
	
	if (inOut == "in") 
	{
		document.getElementById(elemId).style.visibility = "visible";
		SetOpacity(document.getElementById(elemId), fadeInPattern[stepNum]); 
		stepNum++;
		fade_opacity_stepNum[elemId] = stepNum;
		if (stepNum < fade_opacity_steps) setTimeout("FadeOpacityStep('" + elemId + "')", 30); 
		else fade_opacity_stepNum[elemId] = 0;
	}
	
	if (inOut == "out") 
	{
		SetOpacity(document.getElementById(elemId), fadeOutPattern[stepNum]); 
		stepNum++;
		fade_opacity_stepNum[elemId] = stepNum;
		if (stepNum < fade_opacity_steps) setTimeout("FadeOpacityStep('" + elemId + "')", 30); 
		else
		{
			document.getElementById(elemId).style.visibility = "hidden";
			fade_opacity_stepNum[elemId] = 0;
		}
	}
}

function Fade(elemId, inOut) 
{ 
	var fading_in_progress = 0;
	if (fade_opacity_stepNum[elemId] || fade_opacity_inOut[elemId] == inOut) fading_in_progress = 1; //part way through step sequence or already faded that way
	
	if (!fade_opacity_stepNum[elemId]) fade_opacity_stepNum[elemId] = 0; //definitely to zero (might be undefined as yet);

	//check if reversed fading direction while fading - if so adjust stepNum accordingly to start at opposite end of other array
	if (fading_in_progress && fade_opacity_inOut[elemId] != inOut)
	{
		fade_opacity_stepNum[elemId] = fade_opacity_steps - fade_opacity_stepNum[elemId];
	}
	fade_opacity_inOut[elemId] = inOut; //remember requested state
	
	if (!fading_in_progress) FadeOpacityStep(elemId); 
}

//----------- /fade in/out divs



function showTimer(el)
{
	elem = 	document.getElementById(el); 
	elem.src = "im/timer1.gif";
}

function preload(arr)
{
im = new Array()
  for (n=0; n<arr.length; n++)
  {
    im[n] = new Image()
    im[n].src = im_path + arr[n]
  }
}

function raiseMenuButtons() 
{
  for (n=0; n<raised_buttons.length; n++)
  {
    id = raised_buttons[n]
	document.images[id].src = im_path + id + '_f2.gif'
  }
}

function raiseMenuButton() 
{
  document.images[raised_button].src = im_path + raised_button + '_f2.gif'
}

function raiseMenuLink(thelink, colour)
{
  document.getElementById(thelink).style.color = colour
}

function mout(id)
{
  document.images[id].src = im_path + id + ".gif"
  raiseMenuButtons()
}

function mover(id)
{
  document.images[id].src = im_path + id + "_f2.gif"
}

im_wait = new Image(); im_wait.src =  im_path + "wait_msg.gif"

function show_wait_msg()
{
  document.images['wait_msg'].src = im_path + "wait_msg.gif"
}

var win1

function newWin(url,w,h) {
if (win1 && win1.open || win1 && !win1.closed){win1.close()}
win1 = window.open(url,"win1","width="+w+",height="+h+",toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes")
}

function imwin(w)
{
	newWin('imwin.php?i=' + win_arr[w]);
}


function tdOver1(src){ src.bgColor = "#ECECF4"}

function tdOut(src){ src.bgColor = "#FFFFFF"}

function tdOver2(src){ src.bgColor = "#F0FAFB"}

function goURL(url){ window.location=url}

//CUSTOM TOOLTIP
//Copyright 2004, Sandeep Gangadharan
//For more free scripts go to http://sivamdesign.com/scripts/

function hideIt(id) 
{
	document.getElementById(id).style.visibility='hidden';
}
 
function showIt(id) 
{
	document.getElementById(id).style.visibility='visible'
}
 //end custom tool tip
 
 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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function P7_Snap() { //v2.64 by PVII
 var x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,tw,q0,xx,yy,w1,pa='px',args=P7_Snap.arguments;a=parseInt(a);
 if(document.layers||window.opera){pa='';}for(k=0;k<(args.length);k+=4){
 if((g=MM_findObj(args[k]))!=null){if((el=MM_findObj(args[k+1]))!=null){
 a=parseInt(args[k+2]);b=parseInt(args[k+3]);x=0;y=0;ox=0;oy=0;p="";tx=1;
 da="document.all['"+args[k]+"']";if(document.getElementById){
 d="document.getElementsByName('"+args[k]+"')[0]";if(!eval(d)){
 d="document.getElementById('"+args[k]+"')";if(!eval(d)){d=da;}}
 }else if(document.all){d=da;}if(document.all||document.getElementById){while(tx==1){
 p+=".offsetParent";if(eval(d+p)){x+=parseInt(eval(d+p+".offsetLeft"));y+=parseInt(eval(d+p+".offsetTop"));
 }else{tx=0;}}ox=parseInt(g.offsetLeft);oy=parseInt(g.offsetTop);tw=x+ox+y+oy;
 if(tw==0||(navigator.appVersion.indexOf("MSIE 4")>-1&&navigator.appVersion.indexOf("Mac")>-1)){
  ox=0;oy=0;if(g.style.left){x=parseInt(g.style.left);y=parseInt(g.style.top);}else{
  w1=parseInt(el.style.width);bx=(a<0)?-5-w1:-10;a=(Math.abs(a)<1000)?0:a;b=(Math.abs(b)<1000)?0:b;
  x=document.body.scrollLeft+event.clientX+bx;y=document.body.scrollTop+event.clientY;}}
 }else if(document.layers){x=g.x;y=g.y;q0=document.layers,dd="";for(var s=0;s<q0.length;s++){
  dd='document.'+q0[s].name;if(eval(dd+'.document.'+args[k])){x+=eval(dd+'.left');y+=eval(dd+'.top');
  break;}}}e=(document.layers)?el:el.style;xx=parseInt(x+ox+a),yy=parseInt(y+oy+b);
 if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1){
  xx+=parseInt(document.body.leftMargin);yy+=parseInt(document.body.topMargin);}
 e.left=xx+pa;e.top=yy+pa;}}}
}

var wm_rollover_text = new Array();
function sh(id)
{
	document.getElementById('l1').innerHTML = "<p class=\"norm1\">" + wm_rollover_text[id] + "</p>";
	showIt('l1');	
}

function hi(id)
{
	hideIt('l1');	
}

var exp_div_moving = new Array();
var exp_div_heights = new Array();
var scrolledAlready = 0;
var screenHeight = 0;
var y_offset = 0;

function expand_div(div_id)
{
	//vars and arguments
	expanded_height = exp_div_heights[div_id]; //height of div when shown fully - array element remembers this between calls
	mode = expand_div.arguments[2];
	if (expand_div.arguments[1]) y_offset = expand_div.arguments[1];
	elem = document.getElementById(div_id);
	
	//initial entry into function - no mode defined
	if (!mode) //&& !exp_div_moving[div_id]
	{
		screenHeight = getScreenHeight()
		if (elem.style.visibility == "visible") mode = "c"; else mode = "e"; //collapse if currently visible, else expand
		if (!exp_div_heights[div_id]) exp_div_heights[div_id] = parseInt(elem.offsetHeight); //initialise height to expand to - either full theoretical height or current height if already moving
		expanded_height = exp_div_heights[div_id];
		scrolledAlready = 0;
		exp_div_moving[div_id] = 1; //signify moving
		
		if (mode == "e")
		{
			elem.style.height = '0px';
			elem.style.position='relative';
			elem.style.visibility='visible';
		}		
	}
	
	if (mode == "e") move_inc = 15; else move_inc = -30;
	current_height = parseInt(elem.style.height);
	current_height += move_inc;

	if (mode == "e" && current_height > expanded_height) //stop expanding
	{
		elem.style.height = expanded_height + "px";
		exp_div_moving[div_id] = 0; //stop moving
	}
	else	if (mode == "c" && current_height < 0) //stop collapsing
	{
		elem.style.height = "0px";
		elem.style.position="absolute"
		elem.style.visibility="hidden"
		exp_div_moving[div_id] = 0; //stop moving
	}
	else if (mode == "c" || mode == "e") //expand or collapse
	{
		elem.style.height = current_height + 'px';
		t1 = setTimeout("expand_div('"+div_id+"', '', '"+mode+"')", 10);
		
		//scroll screen down while expanding if bottom of div disappears off bottom of page. Stop scrolling before top disappears though.
		if (mode == "e" && ((mouseY + y_offset + current_height + move_inc) > screenHeight && (mouseY - scrolledAlready - move_inc) > 0))
		{
			new_scroll_position = getScrollPosition() + move_inc
			window.scroll(0, new_scroll_position);
			scrolledAlready += move_inc;
		}
	}
}

var mouseY = 0;

function getMouseCoords(e) 
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (0) //e.pageX || e.pageY) 	
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	
	{
		posx = e.clientX // + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY // + document.body.scrollTop + document.documentElement.scrollTop;
	}
	mouseY = posy;
}


function getScrollPosition()
{
	pos = window.pageYOffset || document.body.scrollTop || 0;
	return pos
}

function getScreenHeight()
{
	if (window.innerHeight) 
	{
		theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) 
	{
		theHeight=document.body.clientHeight;
	}
	return theHeight
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.ONCLICK)
document.onclick = getMouseCoords;