var WB2 = new Object();

WB2.returnURL = "http://notify.im.statw.com/wblogin.htm";
WB2.wbAPI = 6;
WB2.website = "Notify IM";
WB2.retErr = 1;
WB2.usePopup = 0;
//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
WB2.getPageScroll = function(){
  var yScroll;
  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
  } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
  }
  arrayPageScroll = new Array('',yScroll) 
  return arrayPageScroll;
}

WB2.getPageSize = function(){
  var xScroll, yScroll;
  if (window.innerHeight && window.scrollMaxY) {  
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else {
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }
  
  var windowWidth, windowHeight;
  if (self.innerHeight) {
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) {
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) {
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  } 
  
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else { 
    pageHeight = yScroll;
  }

  if(xScroll < windowWidth){  
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }

  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
  return arrayPageSize;
}

WB2.getCenteredCoords = function (w) {
  return [parseInt((screen.availWidth - w) / 2), 50];
};

WB2.resetIframe = function () {
  var objIFrame = document.getElementById('iLogin_iframe');
  if(objIFrame) {
    objIFrame.src = "javascript:'<html style=\"margin: 0px; padding: 0px;\"><body style=\"margin: 0px; padding: 0px;background-color: #F6F6F6; \"><center><h3 style=\"font-family: sans-serif; margin: 0px; padding: 0.65em; *padding: 0.45em; color: #111; padding-top: 190px\">Processing&nbsp;&nbsp;&nbsp;<img src=\"/pic/wb/loading.gif\" border=0 style=\"display: inline\"/></h3></center></body></html>'";
  }
}

WB2.showLogin = function(objLink)
{
  // prep objects
  var objOverlay = document.getElementById('iLogin_overlay');
  var objIPanel = document.getElementById('iPanel');
    
  var arrayPageSize = WB2.getPageSize();
  var arrayPageScroll = WB2.getPageScroll();

  // set height of Overlay to take up whole page and show
  objOverlay.style.height = (arrayPageSize[1] + 'px');
  objOverlay.style.display = 'block';

  var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 50 - 270) / 2);
  var lightboxLeft = ((arrayPageSize[0] - 350) / 2);
  objIPanel.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
  objIPanel.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
  objIPanel.style.display = 'block';
  var objIContent = document.getElementById('iContent');
  
  objIContent.innerHTML = 
  "<center><div id='iLogin_title'>"+WB2.website+" Login</div><span id='iLogin_Front'><font id='iLogin_subtitle'>Sign in using:</font>"+
  "<ul id='iLogin_OP' class='iLogin_OP'><li id='iLogin_iName' title='A digital identifier designed for&#13;sharing resources and data&#13;across domains and applications&#13;(see http://1id.com)'></li><li id='iLogin_OpenID' title='OpenID URL, an open, decentralized standard&#13;for user authentication and access control&#13;(see http://en.wikipedia.org/wiki/Openid)'></li><li id='iLogin_Email' title='The email address will be converted&#13;into a Community iName in the form of&#13;@e-mail*(John@email.com).'></li></ul></span><div id='iLogin_Panel'></div>"+
  "<iframe id='iLogin_iframe' style='display: none; border: 1px solid #ccc'></iframe></center>"+
  "<span id='iLogin_titlefooter'>Powered by <a class='iLogin_Links' href='http://1id.com' target='_blank'>1id</a></span>"+
  "<a id='iLogin_back'><span>&laquo; back to options</span></a><a id='iLogin_help'><span>Help</span></a>";
  
  var objIName  = document.getElementById('iLogin_iName');
  var objOpenID = document.getElementById('iLogin_OpenID');
  var objEmail  = document.getElementById('iLogin_Email');
 
  WB2.resetIframe();
  
  if(objIName) {
    objIName.onclick = function () {
      WB2.showSubLogin('iname')
    }
  }
  
  if(objOpenID) {
    objOpenID.onclick = function () {
      WB2.showSubLogin('openid');
    }
  }
  
  if(objEmail) {
    objEmail.onclick = function () {
      WB2.showSubLogin('email');
    }
  }
  
  var objBack  = document.getElementById('iLogin_back');
  if (objBack) {
    objBack.onclick = function () {
      var obj  = document.getElementById('iLogin_Front');
      if(obj) obj.style.display="block";
      var objPanel  = document.getElementById('iLogin_Panel');
      objPanel.style.display = "none";
      var objBack  = document.getElementById('iLogin_back');
      if(objBack) objBack.style.display = "none";
      var objHelp = document.getElementById('iLogin_help');
      if(objHelp) objHelp.style.display = "block";
    }
  }
  
  var objHelp  = document.getElementById('iLogin_help');
  if (objHelp) {
    objHelp.onclick = function () { 

      var arrayPageSize = WB2.getPageSize();
      var arrayPageScroll = WB2.getPageScroll();
      var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 50 - 300) / 2);
      var lightboxLeft = ((arrayPageSize[0] - 350) / 2);

      var tmp = document.getElementById('iHelpDesc');
      if(tmp) {
        tmp.style.display = "block";
        tmp.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
        tmp.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
        return;
      }
      var objBody = document.getElementsByTagName("body").item(0);
      var objOverlay = document.getElementById('iLogin_overlay');
  
      // create lightbox div, same note about styles as above
      var objIPanel = document.createElement("div");
      objIPanel.setAttribute('id','iHelpDesc');
      objIPanel.style.position = 'absolute';
      objIPanel.style.zIndex = '9990'; 
      objIPanel.style.width = "350px";
      objIPanel.style.height = "300px";
      objIPanel.style.backgroundColor = "#333";
      objIPanel.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
      objIPanel.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
      objIPanel.style.padding = "5px";
      try { objIPanel.style.borderRadius = "5px"; } catch (e) {}
      objBody.insertBefore(objIPanel, objOverlay.nextSibling);
  
      var objIContent = document.createElement("div");
      objIContent.style.position = 'absolute';
      objIContent.style.width = "340px";
      objIContent.style.height = "290px";
      objIContent.style.backgroundColor = "#fff";
      objIContent.style.padding = "5px";
      try { objIContent.style.borderRadius = "4px 0px 4px 4px"; } catch (e) {}
      objIContent.style.zIndex = '9991';
      objIPanel.appendChild(objIContent); 
      objIContent.innerHTML = '<table border="0" cellspacing="3" cellpadding="0" style="font-size: 13px; line-height: 21px; font-family: Georgia, \'Times New Roman\', Times, serif; color: #444;"><tr valign="top"><td nowrap="nowrap"><b>i-Name</b> - </td><td> a digital identifier designed for sharing resources and data across domains and applications (see <a class="iLogin_Links2" style="font-size: 13px;" href="http://1id.com/" target="_blank">1id.com</a>).</td></tr><tr valign="top"><td nowrap="nowrap"><b>OpenID</b> - </td><td> an open, decentralized standard for user authentication and access control (see <a class="iLogin_Links2" style="font-size: 13px;" href="http://en.wikipedia.org/wiki/Openid" target="_blank">OpenID)</a></td></tr><tr valign="top"><td nowrap="nowrap"><b>Email</b> - </td><td>the email address will be converted into a community iName in the form of <b>@e-mail*(John@email.com)</b>. If you don\'t have a community iName you can register one for free <a class="iLogin_Links2" style="font-size: 13px;" href="http://1id.com/1id.register_c.htm?community=@e-mail" target="_blank">here</a>.</td></tr></table><br/><span style="font-size: 13px; line-height: 21px; font-family: Georgia, \'Times New Roman\', Times, serif">For password recovery click <a class="iLogin_Links2" style="font-size: 13px;" href="http://1id.com/1id.pwdrecover.htm" target="_blank">here</a>.</span>';
      // preload and create close button image
      var imgCloseButton = new Image();

      // if close button image found, 
      imgCloseButton.onload=function(){
        var objCloseButton = document.createElement("img");
        objCloseButton.src = '/pic/wb/close.gif';
        objCloseButton.onclick = function () {document.getElementById('iHelpDesc').style.display="none"; return false;}
        objCloseButton.style.position = 'absolute';
        objCloseButton.style.top = '0px';
        objCloseButton.style.right = '0px';
        objCloseButton.style.zIndex = '9992';
        objCloseButton.style.cursor = 'pointer';
        objIPanel.appendChild(objCloseButton);
        return false;
      }

      imgCloseButton.src = '/pic/wb/close.gif';
    };
  } 
  return false;
}

WB2.showSubLogin = function(type) {
  var obj  = document.getElementById('iLogin_Front');
  if(obj) obj.style.display="none";
  var objPanel  = document.getElementById('iLogin_Panel');
  if(objPanel) {
    objPanel.style.display = "block";
    var src = "";
    if(type == 'email') {
      src='/pic/wb/email_big.png';
    } else if(type == 'openid') {
      src='/pic/wb/openid_big.png';
    } else {
      src='/pic/wb/1id_big.png';
    }
    objPanel.innerHTML = "<div id='iLogin_popbox'><span id='iLogin_errMsg'>Error:</span></div><img width='288' height='77' src='"+src+"' boder='0'/><input type='text' class='iLogin_user_id' id='iLogin_user_id' value='Your E-mail Address' onblur=\"if(this.value==''){this.value='Your E-mail Address';this.style.color='#999'}\" onfocus=\"if(this.value=='Your E-mail Address'){this.value='';this.style.color='#333'}\"><div style='text-align: right'>Remember me <input id='iLogin_remember' type='checkbox' name='remember' value='1'/></div><a class='iLogin_signin' id='iLogin_signin'><span>Sign In &raquo;</span></a>";
    var objLogin = document.getElementById('iLogin_signin');
    if (objLogin) {
      objLogin.onclick = function () {
        var objUserID  = document.getElementById('iLogin_user_id');
        var objRemember  = document.getElementById('iLogin_remember');
        var objPanel  = document.getElementById('iLogin_Panel');
        objPanel.style.display = "none";
        var objBack  = document.getElementById('iLogin_back');
        if(objBack) objBack.style.display = "none";
        var objHelp = document.getElementById('iLogin_help');
        if(objHelp) objHelp.style.display = "block";
        var objError  = document.getElementById('iLogin_popbox');
        if(objError) objError.style.display = 'none';
        WB2.growDiv(objUserID.value, objRemember.checked, type);
      }
    }
  }
  var objBack  = document.getElementById('iLogin_back');
  if(objBack) objBack.style.display = "block";
  var objHelp = document.getElementById('iLogin_help');
  if(objHelp) objHelp.style.display = "none";
}

WB2.grow = function() {
  if(WB2.growInProgress == 1) return;
  WB2.growInProgress = 1;
  var objIPanel = document.getElementById('iPanel');
  var objIContent = document.getElementById('iContent');
  var arrayPageSize = WB2.getPageSize();
  var arrayPageScroll = WB2.getPageScroll();
  
  var w = WB2.width + ( ( (WB2.maxWidth - WB2.width) / WB2.steps) * WB2.cstep);
  var h = WB2.height + ( ( (WB2.maxHeight - WB2.height) / WB2.steps) * WB2.cstep);
  if(w > WB2.maxWidth) w = WB2.maxWidth;
  if(h > WB2.maxHeight) h = WB2.maxHeight;

  var lightboxLeft = parseInt((arrayPageSize[0] - w) / 2);
  var lightboxTop = parseInt(arrayPageScroll[1] + ((arrayPageSize[3] - 50 - h) / 2));
  
  objIPanel.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
  objIPanel.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
  objIPanel.style.display = 'block';
  
  objIPanel.style.width = parseInt(w) + "px";
  objIPanel.style.height = parseInt(h) + "px";
  objIContent.style.width = parseInt(w - 10) + "px";
  objIContent.style.height = parseInt(h - 10) + "px";
  
  WB2.cstep += 1;
  
  if(WB2.cstep <= WB2.steps) {
    setTimeout("WB2.grow()", 10);
  } else {
    var objIFrame = document.getElementById('iLogin_iframe');
    objIFrame.style.width = "99%";
    objIFrame.style.height = "440px";
    objIFrame.style.display = "block";
    var loginUri = "https://1id.com/wb/openid/v1/signin?id="+WB2.wbAPI+"&return_url="+encodeURIComponent(WB2.returnURL)+"&openid_identifier="+encodeURIComponent(WB2.user_id)+"&signin=1";
    if (WB2.checked) {
      loginUri += "&remember=1";
    }
    if(WB2.retErr == 1) {
      loginUri += "&ret_err=1";
    }
    objIFrame.contentWindow.location.replace(loginUri);
  }
  WB2.growInProgress = 0;
}

WB2.debug = function (msg) {
  var objDebug = document.getElementById('debug');
  if(objDebug) objDebug.value += msg+"\n";
}

WB2.shrink = function() {
  if(WB2.shrinkInProgress == 1) return;
  WB2.shrinkInProgress = 1;
  var objIPanel = document.getElementById('iPanel');
  var objIContent = document.getElementById('iContent');
  var arrayPageSize = WB2.getPageSize();
  var arrayPageScroll = WB2.getPageScroll();
  
  var w = WB2.maxWidth - ( ( (WB2.maxWidth - WB2.width) / WB2.steps) * WB2.cstep);
  var h = WB2.maxHeight - ( ( (WB2.maxHeight - WB2.height) / WB2.steps) * WB2.cstep);
  if(w < WB2.width) w = WB2.width;
  if(h < WB2.height) h = WB2.height;
  
  var lightboxLeft = parseInt((arrayPageSize[0] - w) / 2);
  var lightboxTop = parseInt(arrayPageScroll[1] + ((arrayPageSize[3] - 50 - h) / 2));

  objIPanel.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
  objIPanel.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
  objIPanel.style.display = 'block';
  
  objIPanel.style.width = parseInt(w) + "px";
  objIPanel.style.height = parseInt(h) + "px";
  objIContent.style.width = parseInt(w - 10) + "px";
  objIContent.style.height = parseInt(h - 10) + "px";
  
  WB2.cstep += 1;
  
  if(WB2.cstep <= WB2.steps) {
    setTimeout("WB2.shrink()", 10);
  } else {
    WB2.showErrorPanel();
  }
  WB2.shrinkInProgress = 0;
}

WB2.showErrorPanel = function () {
    WB2.showSubLogin(WB2.type);
    var objUserID  = document.getElementById('iLogin_user_id');
    if(objUserID) {
      objUserID.value = WB2.user_id;
      objUserID.style.color = '#333';
    }
    var objRemember = document.getElementById('iLogin_remember');
    if(objRemember && WB2.checked) objRemember.checked = true;
    var objError  = document.getElementById('iLogin_popbox');
    if(objError) objError.style.display = 'block';
    var objErrMsg  = document.getElementById('iLogin_errMsg');
    var errors = {
      'InvalidEmailAddressCommError' : "Malformed e-mail address.",
      'InvalidInameError' : "Malformed iName.",
      'InvalidOpenIDError' : "Malformed OpenID url.",
      'NonExistentEmailCommunityInameError' : "Non-existent Community iName.<br/>Register one <a class='iLogin_Links2' href='http://1id.com/1id.register_c.htm?community=@e-mail' target='_blank'>here</a> for free.",
      'NonExistentCommunityInameError' : "Non-existent Community iName.<br/>Register one <a class='iLogin_Links2' href='http://1id.com/1id.register_c.htm?community=@e-mail' target='_blank'>here</a> for free.",
      'NonExistentInameError' : "Non-existent iName.<br/>Register one <a class='iLogin_Links2' href='http://1id.com' target='_blank'>here</a>.",
      'NotAnOpenIDUrlError' : "The provided login ID is not an OpenID URL or iName.",
      'AuthResError' : "Couldn't resolve the OpenID URL or iName.",
      'OpenIDSessionExpired' : "OpenID session expired. Retry again."
    };

    var dispErr = errors[WB2.errMsg];
    if(errors[WB2.errMsg] == "undefined") {
      dispErr = "Server error. Plase retry later."
    } 

    if(objErrMsg && WB2.errMsg) objErrMsg.innerHTML = "Error: " + dispErr;
};

WB2.growDiv = function(userid, checked, type) {
  WB2.user_id = userid;
  if(checked) {
    WB2.checked = 1;
  } else {
    WB2.checked = 0;
  }
  WB2.type = type;
  if (WB2.usePopup) {
    var p = WB2.getCenteredCoords(700);
    var loginUri = "https://1id.com/wb/openid/v1/signin?id="+WB2.wbAPI+"&return_url="+encodeURIComponent(WB2.returnURL)+"&openid_identifier="+encodeURIComponent(userid)+"&signin=1";
    if (checked) {
      loginUri += "&remember=1";
    }
    if(WB2.retErr == 1) {
      loginUri += "&ret_err=1";
    }
    var win = window.open(loginUri, "_blank", "width=" + 700 + ",height=" + 500 + ",status=1,location=1,resizable=yes,left=" + p[0] + ",top=" + p[1]);
    if(win) {
     var inID;
     inID = window.setInterval(function () {
        if (win.closed) {
          clearInterval(inID);
          WB2.showSubLogin(WB2.type);
          var objUserID  = document.getElementById('iLogin_user_id');
          if(objUserID) {
            if(WB2.user_id) {
              objUserID.value = WB2.user_id;
              objUserID.style.color = '#333';
            }
          }
        }
      }, 500);
      return;
    }
  }
  WB2.width = 350;
  WB2.height = 270;
  WB2.steps = 16;
  WB2.cstep = 0;
  WB2.maxWidth = 700;
  WB2.maxHeight = 500;
  WB2.growInProgress = 0;
  setTimeout("WB2.grow()", 10);
}

WB2.shrinkDiv = function() {
  var objIFrame = document.getElementById('iLogin_iframe');
  WB2.resetIframe();
  objIFrame.style.display = "none";
  WB2.shrinkInProgress = 0;
  WB2.cstep = 0;
  setTimeout("WB2.shrink()", 10);
}

WB2.hideLogin = function ()
{
  // get objects
  var objOverlay = document.getElementById('iLogin_overlay');
  var objIPanel = document.getElementById('iPanel');
  var objIContent = document.getElementById('iContent');

  objIPanel.style.width = "350px";
  objIPanel.style.height = "270px";
  objIPanel.style.display = 'none';
  objIContent.style.width = "340px";
  objIContent.style.height = "260px";
  objIContent.innerHTML = " ";
  objOverlay.style.display = 'none';
  WB2.resetIframe();
}

WB2.doRefresh = function () {
  location.reload(true);
}

WB2.showError = function (msg) {
  WB2.errMsg = msg;
  WB2.cstep = 0;
  if (WB2.usePopup) {
    var objIFrame = document.getElementById('iLogin_iframe');
    WB2.resetIframe();
    if(objIFrame) objIFrame.style.display = "none";
    WB2.shrinkInProgress = 0;
    WB2.cstep = 0;
    WB2.showErrorPanel();
  } else {
    WB2.shrinkDiv();
  }
}

WB2.preloadImages = function() {
  var image_url = new Array();
  image_url[0] = '/pic/wb/1id_big.png';
  image_url[1] = '/pic/wb/buttonbg.png';
  image_url[2] = '/pic/wb/close.gif';
  image_url[3] = '/pic/wb/email_big.png';
  image_url[4] = '/pic/wb/loading.gif';
  image_url[5] = '/pic/wb/openid_big.png';
  image_url[6] = '/pic/wb/overlay.png';
  image_url[7] = '/pic/wb/panelbg.png';
  image_url[8] = '/pic/wb/submitbg.png';
  image_url[9] = '/pic/wb/popbox.gif';
  var i = 0;
  for (i=0; i<=9; i++){ var preload = new Image(); preload.src = image_url[i]; }
}

//
// initILogin()
// Function runs on window load, going through link tags looking for rel="ilogin".
// These links receive onclick events that enable the ilogin display for their targets.
// The function also inserts html markup at the top of the page which will be used as a
// container for the overlay pattern and the inline image.
//
WB2.initLogin = function()
{
  WB2.preloadImages();

  if (!document.getElementsByTagName){ return; }
  var anchors = document.getElementsByTagName("a");

  // loop through all anchor tags
  for (var i=0; i<anchors.length; i++){
    var anchor = anchors[i];

    if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "iLogin")){
      anchor.onclick = function () {WB2.showLogin(this); return false;}
    }
  }

  var objBody = document.getElementsByTagName("body").item(0);
  
  // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
  var objOverlay = document.createElement("div");
  objOverlay.setAttribute('id','iLogin_overlay');
  objOverlay.style.display = 'none';
  objOverlay.style.position = 'absolute';
  objOverlay.style.top = '0';
  objOverlay.style.left = '0';
  objOverlay.style.zIndex = '200';
  objOverlay.style.width = '100%';
  objBody.insertBefore(objOverlay, objBody.firstChild);
  
  var arrayPageSize = WB2.getPageSize();
  var arrayPageScroll = WB2.getPageScroll();

  // create lightbox div, same note about styles as above
  var objIPanel = document.createElement("div");
  objIPanel.setAttribute('id','iPanel');
  objIPanel.style.display = 'none';
  objIPanel.style.position = 'absolute';
  objIPanel.style.zIndex = '201'; 
  objIPanel.style.width = "350px";
  objIPanel.style.height = "270px";
  objIPanel.style.backgroundColor = "#333";
  objIPanel.style.padding = "5px";
  try { objIPanel.style.borderRadius = "5px"; } catch (e) {}
  objBody.insertBefore(objIPanel, objOverlay.nextSibling);
  
  var objIContent = document.createElement("div");
  objIContent.setAttribute('id','iContent');
  objIContent.style.position = 'absolute';
  objIContent.style.width = "340px";
  objIContent.style.height = "260px";
  objIContent.style.backgroundColor = "#fff";
  objIContent.style.padding = "5px";
  try { objIContent.style.borderRadius = "4px 0px 4px 4px"; } catch (e) {}
  objIContent.style.zIndex = '202';
  objIPanel.appendChild(objIContent); 

  // preload and create close button image
  var imgCloseButton = new Image();

  // if close button image found, 
  imgCloseButton.onload=function(){

    var objCloseButton = document.createElement("img");
    objCloseButton.src = '/pic/wb/close.gif';
    objCloseButton.onclick = function () {WB2.hideLogin(); return false;}
    objCloseButton.setAttribute('id','iLogin_closeButton');
    objCloseButton.style.position = 'absolute';
    objCloseButton.style.top = '0px';
    objCloseButton.style.right = '0px';
    objCloseButton.style.zIndex = '203';
    objCloseButton.style.cursor = 'pointer';
    objIPanel.appendChild(objCloseButton);

    return false;
  }

  imgCloseButton.src = '/pic/wb/close.gif';
}

function addLoadEvent(func)
{ 
  var oldonload = window.onload;
  if (typeof window.onload != 'function'){
      window.onload = func;
  } else {
    window.onload = function(){
      oldonload();
      func();
    }
  }
}

addLoadEvent(WB2.initLogin);


