// AIM
function track(user,version) {
  var iXz = new (Image)();
   _proxy_jslib_assign('', iXz, 'src', '=', ( '/track.gif?v='+user+':'+version));
}

function error(pfx, msg) {
	var err =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(pfx+'_error');
	 _proxy_jslib_assign('', err, 'innerHTML', '=', ( msg));
}

function claim() {
	openwin('ebuddyid',540,680);
	return true;
}
var EBUDDY_WINDOW = null;

function openwin(pfx,w,h,user) {
    var loc = 'no';
    if (pfx == 'ebuddyid' || pfx == 'aim' || pfx == 'yahoo' || pfx == 'gtalk' || pfx == 'myspace' || pfx == 'msn' || pfx == 'icq') loc = 'yes';

    EBUDDY_WINDOW =  _proxy_jslib_handle(window, 'open', '', 1, 0)('', pfx, 'width='+w+', height='+h+', menubar=no,  toolbar = no, scrollbars=no, resizable=yes, location='+loc, true);

    if (EBUDDY_WINDOW == null) {
        error(pfx, 'A popup blocker prevented the eBuddy window from opening');
        return false;
    }
    
    return true;
}

function isEmailAddr(str) {
	return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
}
function isID(str) {
	return (str.indexOf('@')<0);
}
function clickSecure(type) {
  //var frm = document.getElementById(type+'_form');
  var frm =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(type);
  var s =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(type+'_secure');
  var a =  _proxy_jslib_handle(frm, 'action', '', 0, 0);
  if (s.checked)
     _proxy_jslib_assign('', frm, 'action', '=', (  _proxy_jslib_handle(a, 'replace', '', 1, 0)('http://', 'https://')));
  else
     _proxy_jslib_assign('', frm, 'action', '=', (  _proxy_jslib_handle(a, 'replace', '', 1, 0)('https://', 'http://')));
}
window.getSize = function (win) {
    if (win == null)
        win = window;
     if (win.innerHeight != null)
         return {width: win.innerWidth, height: win.innerHeight};
    if (win.document.documentElement && win.document.documentElement.clientHeight)
        return Element.getDimensions(win.document.documentElement);
    if (win.clientHeight != null)
        return {width: win.clientWidth, height: win.clientHeight};
    return Element.getDimensions( _proxy_jslib_handle(win.document, 'body', '', 0, 0));
};

var EBUDDY_MSG_PASSENC = null;
var EBUDDY_SEL_NETWORK = null;
var EBUDDY_WINDIMS     = [];
var EBUDDY_ENCRYPTED   = false;
var EBUDDY_LOADER      = null;
var EBUDDY_RSA_E       = null;
var EBUDDY_RSA_M       = null;

var EBUDDY_RSA_TAGS    = [];

var Encryption = {
    keyPair: null,
    timer : null,
    text : "",
   
    start: function(network, width, height) {
        Encryption.reset();
        
        if (typeof window.stop == "function")
            window.stop();
        else if ( _proxy_jslib_handle(document, 'execCommand', '', 0, 0))
             _proxy_jslib_handle(document, 'execCommand', '', 1, 0)('Stop');

        EBUDDY_SEL_NETWORK = network;
        EBUDDY_WINDIMS = [width, height];
        
        this.toggleProgress(true);
        //keysize = 512, thus 77 precision
        Crypt.BigInt.setMaxDigits(77);
        
        var oHead     =  _proxy_jslib_handle(document, 'getElementsByTagName', '', 1, 0)('head')[0];
        var oForm     =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(EBUDDY_SEL_NETWORK);
        var encTarget =  _proxy_jslib_handle( _proxy_jslib_handle(oForm, 'action', '', 0, 0), 'replace', '', 1, 0)(/login\.jsp/, 'secure_js.jsp?').appendRandomNumber(9);
        //var encTarget = String("http://delta.ebuddy.com/oberon_latest/secure_js.jsp?").appendRandomNumber(9); //TESTING
        
        //first remove the OLD scripttags from the HEAD
        for (var i = 0; i < EBUDDY_RSA_TAGS.length; i++) {
            if ( _proxy_jslib_handle(EBUDDY_RSA_TAGS, (i), 0, 0)) {
                 _proxy_jslib_handle(EBUDDY_RSA_TAGS, (i), 0, 0).parentNode.removeChild( _proxy_jslib_handle(EBUDDY_RSA_TAGS, (i), 0, 0));
                 _proxy_jslib_assign('', EBUDDY_RSA_TAGS, (i), '=', ( null));
            }
        }
        
        var encScript    = oHead.appendChild(document.createElement('script'));
         _proxy_jslib_assign('', encScript, 'src', '=', ( encTarget));
        encScript.type = "text/javascript";
        EBUDDY_RSA_TAGS.push(encScript);
        
        Encryption.fetchKeys(window);
    },
    end: function() {
        this.toggleProgress(false);
        EBUDDY_ENCRYPTED = true;
    },
    fetchKeys: function(win) {
        if (this.timer) clearTimeout(this.timer);
        if (!EBUDDY_RSA_E | !EBUDDY_RSA_M) {
            this.timer =  _proxy_jslib_handle(window, 'setTimeout', '', 1, 0)(function() {
                Encryption.fetchKeys(win);
            }, 50);
            return;
        }
        
        var oForm =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(EBUDDY_SEL_NETWORK);
        this.keyPair = new (Crypt.RSA.getKeyPair)(
          win.EBUDDY_RSA_E, '',
          win.EBUDDY_RSA_M
 );
        
        var s = Crypt.RSA.encrypt(this.keyPair,  _proxy_jslib_handle( _proxy_jslib_handle(oForm.elements, ('pwd'), 0, 0), 'value', '', 0, 0));
        Encryption.text =  _proxy_jslib_assign('',  _proxy_jslib_handle(oForm.elements, ('challenge'), 0, 0), 'value', '=', ( s));
        
        Encryption.end();
        //oForm.action = "http://delta.ebuddy.com/oberon_latest/login.jsp";//TESTING
        doLogin(EBUDDY_SEL_NETWORK, EBUDDY_WINDIMS[0], EBUDDY_WINDIMS[1]);
    },
    toggleProgress: function(visible) {
        if (typeof visible == "undefined") visible = true;
        
        if (!EBUDDY_LOADER) {
            //tooltip to show password-encryption status:
            var oDims = window.getSize();
            EBUDDY_LOADER = new (Tooltip)('tooltip_encryption', null, {
                classTopLeft : 'tooltip_silver_topleft',
                classBottomLeft : 'tooltip_silver_bottomleft',
                classContent : 'tooltip_silver_content',
                classTopRight : 'tooltip_silver_topright',
                classBottomRight : 'tooltip_silver_bottomright',
                classBottomMiddle: 'tooltip_silver_bottommiddle',
                classDisabled : 'tooltip_silver_disabled',
                classArrow : 'tooltip_silver_arrow',
                pathToContent : EBUDDY_CONTENTPATH + "/_images/",
                offsetX : (oDims.width / 2) - 200,
                offsetY : 292,
                width : 'auto',
                height : 61,
                showCloseButton : false,
                animate : false
 });
        }
        
        if (visible)
            EBUDDY_LOADER.show(null, '<img src="' + EBUDDY_CONTENTPATH
 + '/_images/tooltip/tooltip_padlock.gif" border="" alt="" />'
 + EBUDDY_MSG_ENCRYPTING, '');
        else
            EBUDDY_LOADER.hide();
    },
    reset: function() {
        Encryption.text = "";
        Encryption.keyPair = EBUDDY_SEL_NETWORK = EBUDDY_LOADER = EBUDDY_RSA_E = EBUDDY_RSA_M = null;
        EBUDDY_WINDIMS = [];
        EBUDDY_ENCRYPTED = false;
    }
};

var console = window.console || {
    log:function() { },
    info:function() { },
    warn:function() { },
    group:function() { },
    groupEnd:function() { },
    dir:function() { }
};
 ;
_proxy_jslib_flush_write_buffers() ;