
//Window.addEvent('domready',ieFirstChildren);

var strDomain = window.location.hostname.replace("www.", "").replace("fin.", "");
document.pre = document.FIN ? "http://" + strDomain : "";	

window.addEvent('load', function ()
{
	setTimeout(initOverLabels, 50);
}
);
/* 
	look for list items that are the first child, and give 'em a class 
	This is for ie6's benefit, 'cos it doesn't understand 'first-child' in css
*/
function ieFirstChildren()
{
	var kids = new Array();
	
	var breadcrumb 	= document.getElementById('breadcrumb');
	var kid 		= breadcrumb.firstChild.nextSibling; // there's text before this list item
	kids.push(kid);
	
	var misc	 	= document.getElementById('misc');
	var kid 		= misc.firstChild.nextSibling;
	kids.push(kid);
	
	var credits	 	= document.getElementById('credits');
	var kid 		= credits.firstChild.nextSibling;
	kids.push(kid);
	
	for(var i=0; i<kids.length; i++)
	{
		kids[i].className 	= 'firstchild';
	}
}


function paginatePressReleases()
{
	var pressReleases = $$('.pressreleasesummary');
	document.pressReleaseClones = new Array();
	for(var i = 0; i < pressReleases.length; i++)
	{
		if(i > (document.pageSize-1))
		{
			pressReleases[i].remove();			
		}
		document.pressReleaseClones.push(pressReleases[i]);
	}
	if(pressReleases.length > document.pageSize)
	{
		var ul = new Element('ul');
		var liprev = new Element('li');
		liprev.addClass('btn_prev');
		var aprev = new Element('a');
		aprev.setHTML('previous page');
		aprev.setProperty('href','javascript:goToPage('+0+');');
		ul.adopt(liprev);
		liprev.adopt(aprev);		
		for(var i = 0; i < Math.ceil(pressReleases.length/document.pageSize); i++)
		{
			var li = new Element('li');
			var a = new Element('a');
			a.page = i;
			a.setProperty('href','javascript:goToPage('+i+');');
			a.setHTML(i+1);
			li.adopt(a);
			ul.adopt(li);
		}
		var linext = new Element('li');
		linext.addClass('btn_next');
		var anext = new Element('a');
		anext.setHTML('next page');
		anext.setProperty('href','javascript:goToPage('+1+');');
		ul.adopt(linext);
		linext.adopt(anext);
		
		var linkareas = $$('.pagelinks');
		for(var i = 0; i < linkareas.length; i++)
		{
			linkareas[i].adopt(ul.clone());
		}
	}
}

function goToPage(offset)
{
	this.offset = parseInt(offset);

	if(this.offset < 0)
		this.offset = 0;
	if(this.offset >= Math.ceil(document.pressReleaseClones.length/document.pageSize))
		this.offset = Math.ceil(document.pressReleaseClones.length/document.pageSize)-1;
	
	var currentPressReleases = $$('.pressreleasesummary');
	var container = $('pressreleasecontainer');
	for(var i = 0; i < currentPressReleases.length; i++)
	{
		currentPressReleases[i].remove();
	}
	for(var i = 0; i < document.pressReleaseClones.length; i++)
	{
		if((i+1 > document.pageSize*(this.offset)) && (i+1 <= document.pageSize*(this.offset+1)))
		{
			container.adopt(document.pressReleaseClones[i]);
		}
	}
	
	var next = $$('.btn_next a');
	for(var i = 0; i < next.length; i++)
	{
		next.setProperty('href','javascript:goToPage('+(this.offset+1)+');');
	}
	
	var prev = $$('.btn_prev a');
	for(var i = 0; i < prev.length; i++)
	{
		prev.setProperty('href','javascript:goToPage('+(this.offset-1)+');');
	}
}

function setActiveStyleSheet(name) 
{
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == name) a.disabled = false;
    }
  }
}

function changeStyleSheet(name,value)
{
	setProfileCookie(name,value);
	setActiveStyleSheet(value);
}


function setProfileCookie(name,value) 
{
  	var expiration_date = new Date("January 1, 2010");
 	expiration_date = expiration_date.toGMTString();
	setCookie(name, value, expiration_date);
}

function setCookie(name, value, expires)
{
	 document.cookie= name + "=" + escape(value) +
     ((expires) ? "; expires=" + expires : "") + "; path=/" ;
}

function openURL(url, name, width, height, scrollbars)
{
	var str 	= "height=" + height + ",innerHeight=" + height + ",width=" + width + ",innerWidth=" + width + ",statusbar=no,scrollbars=" + (scrollbars?"yes":"no");
	var xpos	= (screen.availWidth-width)/2;
	var ypos	= (screen.availHeight-height)/2;
	newWindow 	= window.open(url,"pic",str);
	newWindow.focus();
}

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; 
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function switchVonne() {
	var membershipList = $('membershipList');
	var value = $('VonneMember').checked;
	var hidden = membershipList.hasClass('hidden');
	if(value)
	{
		if(hidden)
			membershipList.removeClass('hidden');
	}
	else
		if(!hidden)
			membershipList.addClass('hidden');
}




/* 
	Form Label Stuff
*/

function initOverLabels () {
  if (!document.getElementById) return;  	

  var labels, id, field;

  // Set focus and blur handlers to hide and show 
  // LABELs with 'overlabel' class names.
  labels = document.getElementsByTagName('label');
  
  for (var i = 0; i < labels.length; i++) {
	
    if (labels[i].className == 'overlabel') {
		
	  labels[i].innerHTML = labels[i].innerHTML.substring(0,labels[i].innerHTML.length-1);	

      // Skip labels that do not have a named association
      // with another field.
      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      }

      // Change the applied class to hover the label 
      // over the form field.
      labels[i].className = 'overlabel-apply';

      // Hide any fields having an initial value.
      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }

      // Set handlers to show and hide labels.
      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };

      // Handle clicks to LABEL elements (for Safari).
      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };

    }
  }
};

function hideLabel (field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-10000px' : '0px';
      return true;
    }
  }
}


	// <![CDATA[
    /*------------------------------------------------------------------------------
    Function:       footnoteLinks()
    Author:         Aaron Gustafson (aaron at easy-designs dot net)
    Creation Date:  8 May 2005
    Version:        1.3
    Homepage:       http://www.easy-designs.net/code/footnoteLinks/
    License:        Creative Commons Attribution-ShareAlike 2.0 License
                    http://creativecommons.org/licenses/by-sa/2.0/
    Note:           This version has reduced functionality as it is a demo of 
                    the script's development
    ------------------------------------------------------------------------------*/
    function footnoteLinks(containerID,targetID) {
      if (!document.getElementById || 
          !document.getElementsByTagName ||
          !document.createElement) return false;
      if (!document.getElementById(containerID) ||
          !document.getElementById(targetID)) return false;
      var container = document.getElementById(containerID);
      var target    = document.getElementById(targetID);
      var h2        = document.createElement('h2');
      addClass.apply(h2,['printOnly']);
      var h2_txt    = document.createTextNode('Page Links');
     
      var coll = container.getElementsByTagName('*');
      var ol   = document.createElement('ol');
      addClass.apply(ol,['printOnly']);
      var myArr = [];
      var thisLink;
      var num = 1;
      for (var i=0; i<coll.length; i++) {
		  
		  
        var thisClass = coll[i].className;
        if ( coll[i].getAttribute('href') ||
             coll[i].getAttribute('cite') ) { 
          thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
          var note = document.createElement('sup');
          addClass.apply(note,['printOnly']);
		  
		  
		    // don't want 'links' printed out unless we've actually got some
		 	if(!linksBool)
			{
			 h2.appendChild(h2_txt); 
			 var linksBool = true;
			}
		  
		  
          var note_txt;
          var j = inArray.apply(myArr,[thisLink]);
          if ( j || j===0 ) {
            note_txt = document.createTextNode(j+1);
          } else {
            var li     = document.createElement('li');
            var li_txt = document.createTextNode(thisLink);
            li.appendChild(li_txt);
            ol.appendChild(li);
            myArr.push(thisLink);
            note_txt = document.createTextNode(num);
            num++;
          }
          note.appendChild(note_txt);
          if (coll[i].tagName.toLowerCase() == 'blockquote') {
            var lastChild = lastChildContainingText.apply(coll[i]);
            lastChild.appendChild(note);
          } else {
            coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
          }
        }
      }
      target.appendChild(h2);
      target.appendChild(ol);
      addClass.apply(document.getElementsByTagName('html')[0],['noted']);
      return true;
    }
    // ]]>
    // <![CDATA[
    /*------------------------------------------------------------------------------
    Excerpts from the jsUtilities Library
    Version:        2.1
    Homepage:       http://www.easy-designs.net/code/jsUtilities/
    License:        Creative Commons Attribution-ShareAlike 2.0 License
                    http://creativecommons.org/licenses/by-sa/2.0/
    Note:           If you change or improve on this script, please let us know.
    ------------------------------------------------------------------------------*/
    if(Array.prototype.push == null) {
      Array.prototype.push = function(item) {
        this[this.length] = item;
        return this.length;
      };
    };
    // ---------------------------------------------------------------------
    //                  function.apply (if unsupported)
    //           Courtesy of Aaron Boodman - http://youngpup.net
    // ---------------------------------------------------------------------
    if (!Function.prototype.apply) {
      Function.prototype.apply = function(oScope, args) {
        var sarg = [];
        var rtrn, call;
        if (!oScope) oScope = window;
        if (!args) args = [];
        for (var i = 0; i < args.length; i++) {
          sarg[i] = "args["+i+"]";
        };
        call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
        oScope.__applyTemp__ = this;
        rtrn = eval(call);
        oScope.__applyTemp__ = null;
    	return rtrn;
      };
    };
    function inArray(needle) {
      for (var i=0; i < this.length; i++) {
        if (this[i] === needle) {
          return i;
        }
      }
      return false;
    }
    function addClass(theClass) {
      if (this.className != '') {
        this.className += ' ' + theClass;
      } else {
        this.className = theClass;
      }
    }
    function lastChildContainingText() {
      var testChild = this.lastChild;
      var contentCntnr = ['p','li','dd'];
      while (testChild.nodeType != 1) {
        testChild = testChild.previousSibling;
      } 
      var tag = testChild.tagName.toLowerCase();
      var tagInArr = inArray.apply(contentCntnr, [tag]);
      if (!tagInArr && tagInArr!==0) {
        testChild = lastChildContainingText.apply(testChild);
      }
      return testChild;
    }
    // ]]>
    
	window.addEvent('load', function()
							{
							 //footnoteLinks('content','content');
							});

function switchSelector(title)
{
	$(title).click();
}

function toggleOtherArea()
{
	if($('AreaSelect').value == "Other")
		$('areaFillIn').setStyle('display','');
	else
		$('areaFillIn').setStyle('display','none');	
}