
function openWindow(url,x,y) {
         		window.open(url,'member','toolbar=0,menubar=no,location=0,directories=no,resizable=yes,width=' + x + ',height=' + y + ',scrollbars=no');
			}

function popup (url,name,sx,sy) {
		 var winl = (screen.width-sx)/2;
		 var wint = (screen.height-sy)/2;
    popupwin=window.open(url,name,"toolbar=no,location=no,resizable=no,directories=no,status=no,statusbar=no,menubar=no,top="+wint+",left="+winl+",width="+sx+",height="+sy+"");
}

/* function addOnloadEvent()
 * Handle multiple events/functions that needs to happen on page load
 */
function addOnloadEvent( ev ) {
  var init = window.onload;
  window.onload = ( typeof init != 'function' ) ? ev : function() { init(); ev(); };
}

var menuDirection;
/* initMenus() - reusable on all li items of the UL with the id attibute = 'menu'
 * creates dropdown sub menus
 */
function initMenus(menu_direction){
  if (!menu_direction) menuDirection = 'down';
  else                 menuDirection = menu_direction;
  if (!document.getElementById( 'menu' )) return false;
  var aLI = document.getElementById( 'menu' ).getElementsByTagName( 'li' );
  for ( var i=0; i<aLI.length; i++ ) {
    if ( aLI[i].className == 'sub' ) {
      for ( var j=0; j<aLI[i].childNodes.length; j++ ) {
        if ( aLI[i].childNodes[j].nodeName == 'UL' ) {
          aLI[i].menu = aLI[i].childNodes[j];
          var oTrans = document.createElement('DIV');
          oTrans.style.position = 'absolute';
          oTrans.style.top = '0';
          aLI[i].style.zIndex = '1';
          oTrans.style.zIndex = '2';
          aLI[i].menu.style.zIndex = '3';
          aLI[i].appendChild(oTrans);
          aLI[i].trans = oTrans;
          aLI[i].onmouseover = function() {
            this.menu.style.visibility = 'visible';
            this.trans.style.width = this.menu.offsetWidth + 'px';
            this.trans.style.height = this.offsetHeight + this.menu.offsetHeight + 'px';
            this.menu.style.top = ( this.offsetHeight > 25 ) ? this.offsetHeight+'px' : '25px';
            if (winHeight() < height('head')+5) {
              this.menu.style.top = '-' + height(this.menu) + 'px';
            }
          }
          aLI[i].onmouseout = function(e) {
            var t = (e && e.target) || (event && event.srcElement);
            var tmp = t;
            while(tmp.parentNode){
              if (tmp.className) if(tmp.className == 'sub2') return;
              tmp = tmp.parentNode
            }
            this.menu.style.visibility = 'hidden';
            this.trans.style.height = '1px';
            this.trans.style.width = '1px';
            this.menu.style.top = '25px';
          }
          break;
        }
      }
    }
    if ( aLI[i].className == 'sub2' ) {
      for ( var j=0; j<aLI[i].childNodes.length; j++ ) {
        if ( aLI[i].childNodes[j].nodeName == 'UL' ) {
          aLI[i].menu = aLI[i].childNodes[j];
          var oTrans = document.createElement('DIV');
          oTrans.style.position = 'absolute';
          oTrans.style.top = '0';
          aLI[i].style.zIndex = '5';
          oTrans.style.zIndex = '2';
          aLI[i].menu.style.zIndex = '3';
          aLI[i].menu.style.left = '110px';
          aLI[i].appendChild(oTrans);
          aLI[i].trans = oTrans;

          aLI[i].onmouseover = function() {
            this.trans.style.width = this.menu.offsetWidth + 'px';
            if (getTopPos(this) + height(this.menu) > winHeight()) {
              this.menu.style.top = '-' + (getTopPos(this) + height(this.menu) + 3 - winHeight()) + 'px';
            }
            this.menu.style.visibility = 'visible';
          }
          aLI[i].onmouseout = function() {
            this.menu.style.visibility = 'hidden';
            this.trans.style.height = '1px';
            this.trans.style.width = '1px';
            this.menu.style.top = '25px';
          }
          break;
        }
      }
    }
  }
}

// setup scrollers, choose from box types (sizes) below
//left, top, width, height, speed
//type bx0 for transparent wide boxes
//type bx1 for white wide boxes
//type bx2 for white boxes with half occupied with image ( eg. invititation )
//type bx3 for white card boxes ( eg. profile )
var bx0 = new Array (55, 10, 487, 230, 100);
var bx1 = new Array (55, 10, 487, 260, 100);
var bx2 = new Array (285, 10, 275, 260, 100);
var bx3 = new Array (25, 80, 245, 270, 100);
//add by gordon
var bx4 = new Array (5, 10, 550, 230, 100);
var bx5 = new Array (10, 25, 245, 300, 100);
var bx6 = new Array (7,-50, 245, 400, 100);
var bx7 = new Array (20, 30, 550, 290, 100);
var bx8 = new Array (10, 90, 245, 230, 100);

/*Extend ypSimpleControl Class to initiate the controls*/
ypSimpleScroll.prototype.initControls = function(){
  var d, lyrId3;
  d = document;
  lyrId2 = this.id + "Content"
  lyrId3 = this.id + "Controls";
  this.content = obj2 = this.y.ns4 ? this.container.layers[lyrId2] : this.y.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
  this.controls = this.y.dom ? d.getElementById(lyrId3) : this.y.ie ? d.all[lyrId3] : d.layers[lyrId3];
  var aAnchors = this.controls.getElementsByTagName('A');
  for ( var i=0; i<aAnchors.length; i++ ) {
    aAnchors[i].scrollobj=this;
    if ( aAnchors[i].className.indexOf('up') > -1 ){
      aAnchors[i].onmousedown=function() { this.scrollobj.scrollNorth(); return false; }
    }else{
      aAnchors[i].onmousedown=function() { this.scrollobj.scrollSouth(); return false; }
    }
    aAnchors[i].onmousemove=function() { return false; }
    aAnchors[i].onmouseout=function() { this.scrollobj.endScroll(); }
    aAnchors[i].onmouseup=function() { this.scrollobj.endScroll(); }
    aAnchors[i].onclick=function() { return false; }
  }

  if ( this.content.scrollHeight > this.clipH ) {
    this.controls.style.display = 'block';
  }
}

/* Extend ypSimpleControl Class to refresh the scroller (new content height) if the content...
 * ... of the scrollarea was changed client side (no page reload), eg. collapsable menus
 */
ypSimpleScroll.prototype.refresh = function() {
  this.loaded = false;
  this.load();
  if ( this.content.scrollHeight > this.clipH ) {
    this.controls.style.display = 'block';
  } else {
    this.controls.style.display = 'none';
  }
}

/* functions for cards toggle */
var activecard;
var activecardcontent;

function showCard( id, contentid ) {
  //swap card content
  var currentcardcontent = ( contentid ) ? document.getElementById( contentid ) : null;
  if ( activecardcontent != currentcardcontent ) {
    if ( activecardcontent ) activecardcontent.style.visibility = 'hidden';
    if ( currentcardcontent) currentcardcontent.style.visibility = 'visible';
  }

  // swap cards
  var currentcard = document.getElementById( id );
  currentcard.style.visibility = 'visible';
  if ( activecard != currentcard ) hideCard();

  activecard = currentcard;
  activecardcontent = currentcardcontent;
}

function hideCard( id, contentid ) {
  // hide card of the given id or if no id is passed hide the current active card
  if ( id ) {
    document.getElementById( id ).style.visibility = 'hidden';
    if ( contentid ) document.getElementById( contentid ).style.visibility = 'hidden';
  } else if ( activecard ) {
    activecard.style.visibility = 'hidden';
    if ( activecardcontent ) activecardcontent.style.visibility = 'hidden';
  }
}
/* /functions for cards toggle */

/* function initCollapsableLists() initiates a simple collapse menu with nested lists
 * A list item containing the menu needs a trigger element, eg. a SPAN or A tag
 * <li><span class="trigger">Topic</span><ul><li>items1</li><li>item2</li></ul></li>
 */
function initCollapsableLists() {
  var aULs = document.getElementsByTagName( 'UL' );

  for ( var i=0; i<aULs.length; i++ ) {
    if ( aULs[i].className.indexOf( "collapse" ) > -1 || aULs[i].className.indexOf( "expand" ) > -1 ) {
      var aLIs = document.getElementsByTagName( 'LI' );
      for ( var j=0; j<aLIs.length; j++ ) {
        if ( aLIs[j].getElementsByTagName( 'UL' )[0] ) {

          var trigger;
          for ( var t=0; t<aLIs[j].childNodes.length; t++) {
            if ( aLIs[j].childNodes[t].className && aLIs[j].childNodes[t].className.indexOf( 'trigger' ) > -1 ) {
              trigger = aLIs[j].childNodes[t];
              break;
            }
          }

          if ( trigger ) {
            aLIs[j].list = aLIs[j].getElementsByTagName( 'UL' )[0];
            aLIs[j].state = ( aULs[i].className.indexOf( "collapse" ) > -1 ) ? 'collapse' : 'expand';
            aLIs[j].list.style.display = ( aLIs[j].state == 'collapse' ) ? 'none' : 'block';
            trigger.className = ( aLIs[j].state == 'collapse' ) ? 'triggerclose' : 'triggeropen';

            trigger.onmousedown = function() {
              this.parentNode.state = ( this.parentNode.state == 'collapse' ) ? 'expand' : 'collapse';
              this.parentNode.list.style.display = ( this.parentNode.state == 'collapse' ) ? 'none' : 'block';
              this.className = ( this.parentNode.state == 'collapse' ) ? 'triggerclose' : 'triggeropen';
            }
          }
        }
      }
    }
  }
}
/* /simple collapse menu */

//hide from netscape 4 and ie 4
if ( !document.layers && !( document.all && !document.getElementById ) ) {
  addOnloadEvent( initMenus );
  addOnloadEvent( initCollapsableLists );
}
function winHeight() {
  var myHeight;
  if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function winWidth() {
  var myWidth;
  if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}
function getTopPos(inputObj){		
  inputObj = $(inputObj);
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}

function getLeftPos(inputObj){
  inputObj = $(inputObj);
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
}
function $(pNd){
  try{
    var node;
    switch(typeof (pNd)){
      case 'string':node = document.getElementById(pNd);break;
      case 'object':node = pNd;break;
      default:node = false;break;
    }
	if(node.nodeType == 1){return node;}else{return false;}
  }catch(e){return false;}
}
function height(obj) {
  obj = $(obj);
  if (obj) {
    if(obj.offsetHeight){
      return obj.offsetHeight;
    }
    else if(obj.style.pixelHeight){
      return obj.style.pixelHeight;
    } 
  }
  return 0;
}

function width(obj) {
  obj = $(obj);
  if (obj) {
    if(obj.offsetWidth){
      return obj.offsetWidth;
    }
    else if(obj.style.pixelWidth){
      return obj.style.pixelWidth;
    } 
  }
  return 0;
}

/* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if ((theInput.type == 'password' || theInput.type == 'text') && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}