

function rightTrim(strString) {
    return strString.replace(/\s+$/gi, '');
}



function leftTrim(strString) {
    return strString.replace(/^\s*/gi, '');
}


function trim(strString) {
  strString = strString.replace(/^\s*/gi, '');
  strString = strString.replace(/\s+$/gi, '');
  return strString;
}

function escapeCommas(s) {
  return s.replace(',', '&#44;');
}



function openReferenceWindow(href) {
  var iNode = href.replace(/[^0-9]/ig, '');
  
  var newWin = window.open('cms' + iNode + '.asp', 'reference', 'height=300px, width=300px, title=no')
      newWin.focus();
  

}


function showSubNav(linkObj, objId) {
  var wrapper = linkObj.parentNode;
  var tempNode = wrapper.firstChild;
    

  while (tempNode) {
    if (tempNode.nodeName.toLowerCase() == 'div') {
     tempNode.style.display = 'none';
    }
    tempNode = tempNode.nextSibling;
  }

  document.getElementById(objId).style.display = 'block';
  
}




function clearValidationFlags(oElement) {

  var cSpan = oElement.getElementsByTagName('span')
  for (var i=cSpan.length-1; i>=0; i--) {
    if (cSpan[i].className == 'errorFlag') {
      cSpan[i].parentNode.removeChild(cSpan[i]);
    }
  }
}




function addValidationFlags(oField, aValidation) {

  var oWarning = document.createElement('span');
      oWarning.style.color = 'red';
      oWarning.className = 'errorFlag';
      oWarning.innerHTML = '[*]';

  var node = oField;


  
  while (node && (node.className !== 'label' && node.tagName.toLowerCase() !== 'label')) {
    node = node.parentNode;
  }

  clearValidationFlags(node);

  if (node.getElementsByTagName('p').length > 0) {
    oPara = node.getElementsByTagName('p');
  }
  else {
    oPara = node.getElementsByTagName('span');
  }



  if (oPara[0]) {
    if (oPara[0].getElementsByTagName('span').length > 0) {
        oPara[0].insertBefore(oWarning, oPara[0].getElementsByTagName('span')[0]);
    }
    else {
      oPara[0].appendChild(oWarning);

    }
  }
}



function validateField(oField) {


  if (oField.getAttribute('validation') !== null) {

    aValidation = oField.getAttribute('validation').split(',')

    var blnContinue = true;

    for (var iInt=0; iInt<aValidation.length; iInt++) {


      if (oField.type.toLowerCase() == 'file') {
        if (aValidation[iInt] == 'validateNotEmpty') {
          if (trim(oField.value) == '') {
            if (oField.getAttribute('fileExists') == 'true') {
              return true;
            }
            else {
              return false;
            }
          }
          else {
            return true;
          }
        }
        else {
          return true;
        }
      }

      else if (oField.type.toLowerCase() == 'select-one') {

        if (aValidation[iInt] == 'validateNotEmpty') {


          if (oField.selectedIndex == -1 || oField.options[oField.selectedIndex].value == '') {
            return false;
          }
          else {

            return true;
          }
        }
        else {
          return true;
        }

      }

      else if (oField.type.toLowerCase() == 'radio') {

        if (aValidation[iInt] == 'validateNotEmpty') {
          var blnChecked = false;
          for(var i=0; i<oField.form[oField.name].length; i++) {
            if (oField.form[oField.name][i].checked) {
              blnChecked = true;
            }
          }

          if (blnChecked) {
            return true;
          }
          else {
            return false;
          }
        }
        else {
          return true;
        }
      }
      else if (oField.type.toLowerCase() == 'checkbox') {

        if (aValidation[iInt] == 'validateNotEmpty') {
          if (oField.checked) {
            return true;
          }
          else {
            return false;
          }
        }
        else {
          return true;
        }
      }
      else {
        oField.value = trim(oField.value);

        if (aValidation[iInt] == 'validateEmail') {
          var regEx = new RegExp('\\w+(.|\\w+)*\\@+(-|\\w)+\\.\\w+', 'igm');
        }
        else if (aValidation[iInt] == 'validateNotEmpty') {
          var regEx = new RegExp('.+', 'igm');
        }
        else if (aValidation[iInt] == 'validatePassword') {
          var regEx = new RegExp('^[\\w\\d]{6,21}$', 'igm');
        }
        else {
          var regEx = new RegExp('', 'igm');
        }

        if (!regEx.test(oField.value)) {
          return aValidation;
          break;
        }
        else {
          return true;
        }
      }

    }
  }
  else {
    return true;
  }

}



function validateForm(oForm) {

  var blnMasterContinue = true  

  clearValidationFlags(oForm);


  for (var i=0; i<oForm.length; i++) {

    var validated = validateField(oForm[i]);

    if (validated !== true) {
      blnMasterContinue = false;
      addValidationFlags(oForm[i], validated);
    }
     
  }

  if (blnMasterContinue) {
    return true;
  }
  else {
    alert('Some fields within the form are incomplete.\nPlease review the fields marked with an asterix [*]')
    return false;
  }
}











/*** LIFE CHECK **/

function nodePosition(iNode) {
  for (var i=0; i<aLifeCheck.length; i++) {
    if (iNode.toString() == aLifeCheck[i][0]) {
      return i;
    }
  }
}



function initLifecheckStatement(iNode) {

  var iStatement;
  if (!iNode) {
    iStatement = 0;
    iNode = aLifeCheck[0][0];
  }
  else {
    iStatement = nodePosition(iNode);
  }
  
  var oLifecheck = document.getElementById('lifecheck');
  var oForm = document.forms['lifecheck'];
  var oStatement = document.getElementById('lifecheckStatement');
  var oResponse = document.getElementById('lifecheckResponse');

  oStatement.innerHTML = document.getElementById('statementText' + iNode).innerHTML;

  oResponse.innerHTML = '';

  var oOption = aLifeCheck[iStatement][3];


  for (var i=0; i<oOption.length; i++) {

    oResponse.innerHTML += '<label>';
    oResponse.innerHTML += '<input type="radio" class="radio" name="response" value="' + i + '"/> '
    oResponse.innerHTML += oOption[i][0];
    oResponse.innerHTML += '</label><br/>';

  }


  var oPrevious = document.createElement('input');
      oPrevious.type = 'button';
      oPrevious.value = 'Previous Statement';
      oPrevious.name = 'previousStatement';
      oPrevious.className = 'button';
      oPrevious.setAttribute('iNode', iNode);
      if (oPrevious.attachEvent) {
        oPrevious.attachEvent('onclick', previousStatement);
      }
      else {
        oPrevious.addEventListener('click', previousStatement, false);
      }

      if (iStatement == 0) {
        oPrevious.disabled = true;
      }
  
  oResponse.appendChild(oPrevious);


  var oNext = document.createElement('input');
      oNext.type = 'button';
      oNext.value = 'Next Statement';
      oNext.name = 'nextStatement';
      oNext.className = 'button';
      oNext.setAttribute('iNode', iNode);
      if (oNext.attachEvent) {
        oNext.attachEvent('onclick', testStatement);
      }
      else {
        oNext.addEventListener('click', testStatement, false);
      }

  oResponse.appendChild(oNext);

  var oBreak = document.createElement('br');
      oBreak.className = 'clear';

  oResponse.appendChild(oBreak);

}


function previousStatement(evt) {
  var oBtn = evt.target || evt.srcElement;  
  var iNode = oBtn.getAttribute('iNode');
  var iPos = nodePosition(iNode);

  initLifecheckStatement(aLifeCheck[iPos-1][0]);
}

function testStatement(evt) {
  var oBtn = evt.target || evt.srcElement;
  var oForm = document.forms['lifecheck'];
  var oResponseFields = oForm.elements['response'];

  var iResponse;
  for (var i=0; i<oResponseFields.length; i++) {
    if (oResponseFields[i].checked) {
      iResponse = oResponseFields[i].value;
    }
  }

  if (!iResponse) {
    alert('Please select a response');
    return false;
  }

  var iNode = oBtn.getAttribute('iNode');
  var iStatement = nodePosition(iNode)
  
  if (oForm.elements['statement' + iNode]) {
    oForm.removeChild(oForm.elements['statement' + iNode]);
  }
  if (oForm.elements['pathway' + iNode]) {
    oForm.removeChild(oForm.elements['pathway' + iNode]);
  }


  if (parseInt(aLifeCheck[iStatement][2]) == 1) {  
    oForm.innerHTML += '<input type="hidden" name="statement' + iNode + '" value="' + iResponse + '"/>' ;
  }
  else {
    oForm.innerHTML += '<input type="hidden" name="pathway' + iNode + '" value="' + iResponse + '"/>' ;
  }

  var sRedirect = aLifeCheck[iStatement][3][parseInt(iResponse)][1];
  if (sRedirect !== '') {
    sRedirect = sRedirect.replace(/\D*/igm, '');
    iNode = sRedirect;
    iStatement = nodePosition(iNode);
  }
  else {
    iStatement += 1;
  }

    
  if (aLifeCheck.length > iStatement) {
    iNode = aLifeCheck[iStatement][0];
    initLifecheckStatement(iNode);
  }
  else {
    initLifecheckEnd();
  }
}



function initLifecheckEnd() {
  var oResponse = document.getElementById('lifecheckResponse');
  var oStatement = document.getElementById('lifecheckStatement');

  oResponse.innerHTML = '';
  oStatement.innerHTML = '<h2>Complete</h2>';
  oStatement.innerHTML += '<p>Please press the button below to see how you have done.</p>';


  var oNext = document.createElement('input');
      oNext.type = 'submit';
      oNext.value = 'Show Results';
      oNext.name = 'complete';
      oNext.className = 'button';

  oResponse.appendChild(oNext);

}




/* END LIFE CHECK */



/* 10 Things */


function showTenThings(iNode) {
  var oContent = document.getElementById('tenThingsContent');

  var oText = document.getElementById('tenThingsItem' + iNode);

  if (oText) {
    oContent.innerHTML = oText.innerHTML;
  }
}


/* END 10 Things */


/* START DISCUSSION FORUMS */


function __RefreshCommunityThread(threadId) {

  
  var d = new Date();

  var iFrame = __CreateIframe(threadId, 'cms1323765.aspx?a=' + d.toString());

}

function __SubmitCommunityPost(oForm, threadId) {

  __CreateIframe(threadId, null);
 
  oForm.submit();  
  return false;

}

function __ClearPosts(threadId) {
  var container = document.getElementById('cms' + threadId);
  var oDivCol = container.getElementsByTagName('div');
  
  for (var i=oDivCol.length-1; i>=0; i--) {
    if (oDivCol[i].className == 'CommunityPost') {
      oDivCol[i].parentNode.parentNode.removeChild(oDivCol[i].parentNode);
    }
  }
}

function __AddPosts(iFrameId, threadId) {
  var container = document.getElementById('cms' + threadId);
  var doc = document.getElementById(iFrameId).contentDocument || window.frames[iFrameId].document;

  var oDivCol = doc.getElementsByTagName('div');

  for (var i=oDivCol.length-1; i>=0; i--) {

    if (oDivCol[i].className == 'CommunityPost') {
      var tmpNode = oDivCol[i].parentNode;
      var oNode = document.createElement(oDivCol[i].parentNode.tagName);      
      for (var j=0; j<tmpNode.attributes; j++) {
        oNode.setAttribute(tmpNode.attributes[j].name, tmpNode.attributes[j].value);
      }

      oNode.innerHTML = tmpNode.innerHTML;
      container.insertBefore(oNode, container.firstChild);

    }
  }
}


function __DeleteIframe(iFrameId) {
  var iFrame = document.getElementById(iFrameId);

  iFrame.parentNode.removeChild(iFrame);

}


function __CreateIframe(threadId, src) {

  var iFrame = null;

  try   { iFrame = document.createElement('<iframe name="CommunityPostFrame">'); }
  catch (e) { iFrame = document.createElement('iframe'); }


  iFrame.id = 'CommunityPostFrame';
  iFrame.name = iFrame.id;
  iFrame.style.height = '1px';  
  iFrame.style.width = '1px';
  

  if (src != null) {
    iFrame.src = src;
  }

  iFrame = document.body.appendChild(iFrame);
  
  if (iFrame.attachEvent) {
    iFrame.attachEvent('onload', function() { __ClearPosts(threadId); __AddPosts(iFrame.id, threadId); __DeleteIframe(iFrame.id); return true; } );
  }
  else {
    iFrame.addEventListener('load', function() { __ClearPosts(threadId); __AddPosts(iFrame.id, threadId); setTimeout(function() {__DeleteIframe(iFrame.id)}, 100); return true;}, true);
  }


  return iFrame;
}


/* END DISCUSSION FORUMS */



/* GENERIC POPUP */

var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;

// ***** popup_mousedown *******************************************************

function popup_mousedown(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  popup_mouseposX = ie ? window.event.clientX : e.clientX;
  popup_mouseposY = ie ? window.event.clientY : e.clientY;
}


// ***** popup_mousedown_window ************************************************

function popup_mousedown_window(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  if ( ie && window.event.button != 1) return;
  if (!ie && e.button            != 0) return;

  popup_dragging = true;
  popup_target   = this['target'];
  popup_mouseX   = ie ? window.event.clientX : e.clientX;
  popup_mouseY   = ie ? window.event.clientY : e.clientY;

  if (ie)
       popup_oldfunction = document.onselectstart;
  else popup_oldfunction = document.onmousedown;

  if (ie)
       document.onselectstart = new Function("return false;");
  else document.onmousedown   = new Function("return false;");
}


// ***** popup_mousemove *******************************************************

function popup_mousemove(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);
  var mouseX  = ie ? window.event.clientX : e.clientX;
  var mouseY  = ie ? window.event.clientY : e.clientY;

  if (!popup_dragging) return;

  element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
  element.style.top  = (element.offsetTop +mouseY-popup_mouseY)+'px';

  popup_mouseX = ie ? window.event.clientX : e.clientX;
  popup_mouseY = ie ? window.event.clientY : e.clientY;
}

// ***** popup_mouseup *********************************************************

function popup_mouseup(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  if (!popup_dragging) return;

  popup_dragging = false;

  if (ie)
       document.onselectstart = popup_oldfunction;
  else document.onmousedown   = popup_oldfunction;
}

// ***** popup_exit ************************************************************

function popup_exit(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  popup_mouseup(e);

  document.body.removeChild(element);
}


// ***** popup_show ************************************************************

function popup_show(oDiv, position, relativeTo, x, y, position_id)
{
  var element      = oDiv;
  var drag_element = document.getElementById(oDiv.id + '_drag');
  var exit_element = document.getElementById(oDiv.id + '_exit');


  if (relativeTo == 'screen') {
    var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
    var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
  }
  else {
    var width        = document.body.innerWidth  ? document.body.innerWidth  : document.body.clientWidth;
    var height       = document.body.innerHeight ? document.body.innerHeight : document.body.clientHeight;
  }



  element.style.position = "absolute";
  element.style.display  = "block";

  if (position == "element" || position == "element-right" || position == "element-bottom")
  {
    var position_element = document.getElementById(position_id);

    for (var p = position_element; p; p = p.offsetParent)
      if (p.style.position != 'absolute')
      {
        x += p.offsetLeft;
        y += p.offsetTop;
      }

    if (position == "element-right" ) x += position_element.clientWidth;
    if (position == "element-bottom") y += position_element.clientHeight;

    element.style.left = x+'px';
    element.style.top  = y+'px';
  }

  if (position == "mouse")
  {
    element.style.left = (document.documentElement.scrollLeft+popup_mouseposX+x)+'px';
    element.style.top  = (document.documentElement.scrollTop +popup_mouseposY+y)+'px';
  }

  if (position == "top-left")
  {
    element.style.left = (document.documentElement.scrollLeft+x)+'px';
    element.style.top  = (document.documentElement.scrollTop +y)+'px';
  }

  if (position == "center")
  {
    element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2+x)+'px';
    element.style.top  = (document.documentElement.scrollTop +(height-element.clientHeight)/2+y)+'px';
  }

  if (position == "bottom-right")
  {
    element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )  +x)+'px';
    element.style.top  = (document.documentElement.scrollTop +(height-element.clientHeight)  +y)+'px';
  }


  drag_element['target']   = oDiv.id;
  drag_element.onmousedown = popup_mousedown_window;

  exit_element.onclick     = popup_exit;
}


// ***** Attach Events *********************************************************

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmousedown', popup_mousedown);
else document.addEventListener('mousedown', popup_mousedown, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmousemove', popup_mousemove);
else document.addEventListener('mousemove', popup_mousemove, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmouseup', popup_mouseup);
else document.addEventListener('mouseup', popup_mouseup, false);

/* END POPP UP */



function showSwf(swf) {
  var oDiv = document.createElement('div');
  oDiv.id = 'popup'
  oDiv.innerHTML = '<div id="popup"><div id="popup_drag">drag<div id="popup_exit">close</div></div><div id="popup_content"></div></div>';
  oDiv = document.body.appendChild(oDiv);
  
  var s1 = new SWFObject(swf, "single", "520", "320", "7");
  s1.addVariable("wmode","transparent");
  s1.write("popup_content");

  popup_show(oDiv, 'center', 'screen', 0, 0);
}





function showImageGallery(aImage) {

  var oGallery = document.getElementById('thickboxImageGallery');

  if (oGallery) {
    oGallery.parentNode.removeChild(oGallery);
  }

  var oDiv = document.createElement('div');
  oDiv.id = 'thickboxImageGallery';

  s = '';

  for (var i in aImage) {
    var sImg = aImage[i][0].replace(/^\s*/, '')
    s += '<a href="' + sImg + '" rel="gallery" title="' + aImage[i][1] + '" class="thickbox">&nbsp;</a>';
  }  

  oDiv.innerHTML = s;
  document.body.appendChild(oDiv);
  oDiv.style.display = 'none';

  tb_init('a.thickbox, area.thickbox, input.thickbox');
  imgLoader = new Image();// preload image
  imgLoader.src = tb_pathToImage;


  sPath = document.location.protocol + '//' + document.location.hostname + '/';


  tb_show(aImage[0][1], sPath + aImage[0][0].replace(/^\s*/, ''), 'gallery');
}


function showSwfGallery(aFiles) {
  var sSwf = aFiles.split(",")[0];
  var sPpt = aFiles.split(",")[1];

  var oGallery = document.getElementById('thickboxSwfGallery');

  if (oGallery) {
    oGallery.parentNode.removeChild(oGallery);
  }

  var oDiv = document.createElement('div');
  oFlash = document.createElement('div');
  oDiv.id = 'thickboxSwfGallery';
  oFlash.id = 'thickboxSwfGalleryFile';
  document.body.appendChild(oDiv);
  oDiv.appendChild(oFlash);
  
  var oFlash = new SWFObject(sSwf, "single", '550', '450', "7");
      oFlash.write("thickboxSwfGalleryFile");

  if (sPpt) {
    oDiv.innerHTML += '<div class="powerpointLink"><a href="' + sPpt + '">Download as Powerpoint</a></div>'
  }

  tb_init('a.thickbox, area.thickbox, input.thickbox');
  imgLoader = new Image();// preload image
  imgLoader.src = tb_pathToImage;

  oDiv.style.display = 'none';

  tb_show('', '#TB_inline?height=500&width=560&inlineId=thickboxSwfGallery', '');
}




/* SHOW SOCIAL BOOKMARKS */


$(document).ready(function() {

  $("#footerLinks > ul > li.share > a").click(function(e) {

    var sDiv = this.parentNode.className;

    var height = $('#' + sDiv).height();
    var width = $('#' + sDiv).width();

    leftVal= $(this).position().left;
    topVal=e.pageY-(height/2)+"px";

    $('#' + sDiv).css({left:leftVal,top:topVal}).show();

    $('#' + sDiv).mouseleave(function(){
      $(this).fadeOut('slow');
    })

    return false;
  });

});

/* END SHOW SOCIAL BOOKMARKS */


/* THUMBNAILS */


$(document).ready(function(){

  $(".thumb > a").hover(function() {

    var oHolder = this.parentNode.parentNode;
    var oSpan = $(oHolder).children('div:first').children('span');

    $(oSpan).html($(this).children('div:first').html());
    $(oSpan).show();

    $(this).mouseleave(function(){
      $(oSpan).hide();
    })

    return false;
  });

});

/* END THUMBNAILS */




/* FIELD DEFAULTS */

$.fn.search = function() {

  return this.focus(function() {
    if( this.value == this.defaultValue && this.type != 'submit' && this.type != 'button') {
      this.value = "";
      $(this).addClass('edited');
    }
  }).blur(function() {
    if( !this.value.length ) {
      this.value = this.defaultValue;
      $(this).removeClass('edited');
    }
  });
};

$("#s").search();


$(function() {
  $("form > label > input:not(.stdDefault)").search();
  $("form > fieldset > label > input:not(.stdDefault)").search();
});

/* END FIELD DEFAULTS */


/* COLLAPSIBLE MENU */

function initMenus() {
  $('ul.collapsibleMenu ul').hide();
  $.each($('ul.collapsibleMenu'), function(){
    $('#' + this.id + '.expandfirst ul:first').show();
  }
);
 
$('ul.collapsibleMenu li a').click(

function() {

  var checkElement = $(this).next();
  var parent = this.parentNode.parentNode.id;


  if(parent && $('#' + parent).hasClass('noaccordion')) { 
    $(this).next().slideToggle('normal');
  return false;
  }
 
  if((checkElement.is('ul')) && (checkElement.is(':visible'))) { 
    if($('#' + parent).hasClass('collapsible')) {
      $('#' + parent + ' ul:visible').slideUp('normal');
    }
   return false;
  }
 
  if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
    $('#' + parent + ' ul:visible').slideUp('normal');
    checkElement.slideDown('normal'); 
    return false;
  }
}
);
}
 
$(document).ready(function() {initMenus();});

/* END COLLAPSIBLE MENU */




/* NEWS SCROLLER */



$(document).ready(function() {
    headline_rotate();
    var headline_interval = setInterval(headline_rotate,16000);
});
function headline_rotate() {
    $('#newsScroller ul').css('top', '170px');
    $('#newsScroller ul').show();

    $('#newsScroller ul').animate({top: -200},15000, function() {
      $(this).fadeOut('slow');
    });
}




/* END NEWS SCROLLER */



function validateConferenceEmailForm(oForm) {
  var sResult = '';
  var regEx = new RegExp('\\w+(.|\\w+)*\\@+(-|\\w)+\\.\\w+', 'igm');


  if (! regEx.test(oForm.email.value)) {
    sResult += ' - Please enter a valid email address\n';
  }
  
  if (oForm.country.options[oForm.country.selectedIndex].value == '') {
    sResult += ' - Please select a country\n';
  }

  if (sResult != '') {
    alert('There are some errors with the form:\n' + sResult);
    return false;
  }
  return true;

}


function showLoginShortcutLogout() {
  var oForm = document.getElementById('loginShortcut');
  oForm['function'].value = 'logout';
  oForm.submit();
  return false;
}


function showLoginShortcutReminder(oLink) {

  var oForm = document.getElementById('loginShortcut');

  if (oForm.getElementsByTagName('div')[0]) {
    oForm.getElementsByTagName('div')[0].style.display = 'none';
  }

  if (oForm['function'].value == 'login') {
    oForm['function'].value = 'reminder';    
    $('#loginShortcut .password').hide();
    oLink.setAttribute('defaultText', oLink.innerHTML);
    oLink.setAttribute('defaultLink', oLink.href);
    oLink.innerHTML = 'Back to login';
    oLink.href = oLink.href.replace('?reminder=true', '');
    oForm.getElementsByTagName('h5')[0].innerHTML = 'Password reminder';
  }
  else {
    oForm['function'].value = 'login';    
    $('#loginShortcut .password').show();
    oLink.innerHTML = oLink.getAttribute('defaultText');
    oLink.href = oLink.getAttribute('defaultLink');
    oForm.getElementsByTagName('h5')[0].innerHTML = 'Login';
  }

  return false;
}



function toggleBulletinSubscription(oBtn, show) {
  var oForm = document.forms['subscriptionForm'];
  var oFSet = oForm.getElementsByTagName('fieldset');


  var oBtns = oBtn.parentNode.getElementsByTagName('A');
  for (var i=0; i<oBtns.length; i++) {
    oBtns[i].className = 'switchbutton inactive';
  }

  var oMsg;

  if (show == 'unsubscribe') {
    oBtn.className = 'switchbutton';
    oFSet[2].style.display = 'none';
    oFSet[1].style.display = 'block';

    oForm.field1290761.setAttribute('validation', 'validateNotEmpty');
    oForm.field1290762.setAttribute('validation', 'validateNotEmpty');
    oForm.field1290756.setAttribute('validation', 'validateEmail,validateNotEmpty');
    oForm.field1290793.setAttribute('validation', '');
    
  }
  else {
    oBtn.className = 'switchbutton';
    oFSet[1].style.display = 'none';
    oFSet[2].style.display = 'block';

    oForm.field1290756.setAttribute('validation', '');
    oForm.field1290761.setAttribute('validation', '');
    oForm.field1290762.setAttribute('validation', '');
    oForm.field1290793.setAttribute('validation', 'validateEmail,validateNotEmpty');
  }


}



$(document).ready(function() {

  $(function() {

    $("div.object156").each(
      function( intIndex ) {

        var sId = $(this).attr('id');
        var oSCut = document.getElementById(sId);        

        var oDiv = document.createElement('div');

        var o = oSCut.childNodes;
        var iLen = o.length;
        for (var i=o.length-1; i>=0; i--) {

          if (o[i].nodeType == 1) {
            var oTmp = oDiv.appendChild(o[i]);

            if ((iLen % 2 == 1 && i % 2 == 1) || (iLen % 2 == 0 && i % 2 == 0)) {
              oTmp.className += ' odd'; 
            }
          }

        }

        oDiv = oSCut.appendChild(oDiv);
        oDiv.className = 'wrapper';

        var sNext = 'next' + sId;
        var sPrev = 'prev' + sId;
        var oPaging = document.createElement('ul');
            oPaging.innerHTML = '<li><a href="#" id="' + sPrev + '">&#171;</a></li><li><a href="#" id="' + sNext + '">&#187;</a></li>';
            oPaging = oSCut.appendChild(oPaging);
            oPaging.className = 'btns';
            oPaging.id = 'btns' + sId;


        sNext = '#' + sNext;
        sPrev = '#' + sPrev;


        var i = 2000 + Math.floor(Math.random() * 10001);

        $('div.wrapper', this).cycle({fx:'fade',speed:'slow',pause:1,next:sNext,prev:sPrev,timeout: i});

        $('ul', this).fadeTo('fast', 0.0);

        if ( $('.object143', this).size() > 1 ) {
          $('a img', this).mouseenter( function() { $('#btns' + sId).stop(); $('#btns' + sId).fadeTo('fast', 1); } );
          $('a img', this).mouseleave( function() { $('#btns' + sId).stop(); $('#btns' + sId).fadeTo('slow', 0.0); } );
        }


        $('ul', this).hover( function() { $(this).stop(); $(this).show(); } );
        $('ul', this).mouseleave( function() { $(this).stop();  $(this).fadeTo('slow', 0.0); } );


      }

    );    

  });

});



function togglePasswordField(oLink) {
  var oFSet = oLink.parentNode;
  var oLabel = oFSet.getElementsByTagName('label')[0];
  var oInput = oFSet.getElementsByTagName('input')[0];

  if (oLabel.style.display == 'none') {
    oLabel.style.display = 'block';
    oInput.setAttribute('validation', 'validatePassword');
  }
  else {
    oLabel.style.display = 'none';
    oInput.removeAttribute('validation');
  }
}




/* ORGANISATION */



$(document).ready(function(){

  $(".organisation .desc.english").show();

});


function showDesc(sLang) {

  $(".organisation .desc").hide();

  $( ".organisation .desc." + sLang.toLowerCase() ).show();
  
}


function showOrg(oLink) {

  var sLoad = "<div class=\"loader\"><img src=\"files/file1030060.gif\"/></div>";
 
  $(oLink).parents("div.rslt").children(".location").hide();
  $(oLink).parents("div.rslt").children(".org").remove();
  $(oLink).parents("div.rslt").append("<div class=\"org\"/>");

  var oOrg = $(oLink).parents("div.rslt").children(".org");
      oOrg.html(sLoad);



  $.ajax({
    url: oLink.href,
    type: "GET",
    success: function(data) {
      var d = $("<div/>");
      $("body").append(d);
      $(d).hide();
      $(d).html(data);    


      $(".organisation h2", d).remove();
      $(".organisation h3", d).remove();

      var oHtml = oOrg.html($(".organisation", d));

      if (oHtml.size() == 0) {
        oOrg.html("<p>Sorry, an error occurred.</p>"); 
      }
      else {
        oOrg.html(oHtml.html());
      }

      $(d).remove();
    },

    error: function(httpRequest, textStaus, errorThrown) {
      oOrg.html("<p>Sorry, an error occurred.</p>");
      return false;
    }

  });


  return false;
}


/* ORGANISATION */



$(document).ready( function() {

  $("#leftColumn a[href = javascript:showThumbImage(this); ]").each( function() {


    $(this).click( function() {
      var src = $(this).children("img").attr("src");
          src = src.replace(/\?[\d\w=&]+/igm, "?w=800");

      tb_show( "", src );
    });

    $(this).attr("href", "#");

  });

});




$(document).ready( function() {

  $("ul.tabs .tabContent:not(:first)").hide();

  $("ul.tabs li:first").addClass("selected");
  
  $("input.number").keyup( function() {

    this.value = this.value.replace(/[^0-9]/g, '');

  });

})

function setTabHeight(oTab) {
  
}



function showTab(oLink) {

  $("li", $(oLink).parents("ul")).removeClass("selected");

  $(".tabContent", $(oLink).parents("ul")).hide();

  $(oLink).parents("li").children(".tabContent").show();
  $(oLink).parents("li").addClass("selected");

  return false;

}


function showArticle(oLink) {
  $("div.article").hide();
  $("div.article." + $(oLink).parent().attr("class")).show();

  return false;

}



function addToClinicBasket(oLink) {
  var sTitle = $(oLink).prevAll("h6").html();
  var Img = $(oLink).parent().prevAll("a").children("img").attr("src");
  var sId = $(oLink).parent().parent().attr("id");
  var iCnt = $(oLink).parent().children("input").attr("value");
  var sItem = "<div class=\"item " + sId + "\"><input type=\"hidden\" name=\"product\" value=\"" + sId.replace("item", "") +  "\"/><input type=\"hidden\" name=\"number\" value=\"" + iCnt +  "\"/><img src=\"" + Img + "\"/><span class=\"holder\">" + sTitle + " <span>" + iCnt + " copies <a href=\"#\" onclick=\"$(this).parents('div.item').remove(); return false;\">[remove]</a></span></span></div>";



  if ( $("." + sId, $("#dropZone")).size() > 0 )  {
    $("." + sId, $("#dropZone div.scroller")).after(sItem).remove();
  }
  else {
    $("#dropZone div.scroller").append($(sItem));    
  }

  

  return false;
}


function addAllToClinicBasket(oLink) {
  $(".detail",  $(oLink).parents(".scroller") ).each( function() {

   $(this).children("input").attr("value", $(oLink).parent().children("input").attr("value"));

     addToClinicBasket($(this).children("a:first")[0]);

  });

  return false;
}

function setProductOptions(oSelect) {
  var oTgt = oSelect.form["field1331008"];

  $(oTgt).children().remove();

  $(oTgt).append("<option value=\"All\">All</option>");

  $(aPdct).each( function() {
 
    if ( $(this)[1] == oSelect.options[oSelect.selectedIndex].value ) {
      $(oTgt).append("<option value=\"" + $(this)[0] + "\">" + $(this)[0] + "</option>");
    }

  });

}


function handleDonateOther(oField) {

  oField.form['amount'][3].checked = true;

  oField.value = oField.value.replace(/[^0-9\.]/g, '');
  
  oField.form['amount'][3].value = oField.value;

}



$(document).ready(function() {

  if ($("#donateCorner").size() == 0 ) {
    $("body").append("<div id=\"donateCorner\"><a href=\"cms1036964.aspx\"><span>Donate</span></a></div>");
  }

  if ( $("body").width() < (760 + 200) ) {
    $("#donateCorner").hide();
  }
});


$(document).ready(function(){    
  $("p strong:last-child").addClass("last");    
  $("em strong:last-child").addClass("last");    
  $("p strong:first-child").addClass("first");  
  $("em strong:first-child").addClass("first");  
});



$(document).ready(function(){ 
  
  $(".gayeCalc input.amount").keyup( function() {
    this.value = this.value.replace(/[^0-9\.]/g, '');
  });

});



function gayeCalc(oField) {
  var i = oField.form["amount"].value;
  var rate = oField.form["rate"].options[oField.form["rate"].selectedIndex].value;


  if ( isNaN(parseFloat(i)) ) {
    $("div.figures").html("");
    $("div.error").html("Please enter your donation amount, using only numbers");
  }
  else {
    i = parseFloat(i);
    var s =  "<p>Cost of this donation to you</p> <span>&pound;" + (Math.round((i * (1-rate)) * 100) / 100).toFixed(2) + "</span><br class=\"clear\"/>";
        s += "<p>Amount contributed by the taxman</p> <span>&pound;" + (Math.round((i * (rate)) * 100) / 100).toFixed(2) + "</span><br class=\"clear\"/>";
        s += "<p>Total value to NAM</p> <span>&pound;" + (Math.round(i * 100) / 100).toFixed(2) + "</span>";
        s += "<div><input type=\"submit\" name=\"submit\" value=\"Make your payroll giving pledge\" class=\"button pledgeButton\"/></div>";
    $("div.figures").html(s);
    $("div.error").html("");
  }


}




