﻿
if(typeof(Tops) === 'undefined')
    Tops = {};
if(Tops.AjaxLogin === undefined)
    Tops.AjaxLogin = {};
Tops.AjaxLogin.RegisterUserWindow = {};

Tops.AjaxLogin.RegisterUserWindow = function Tops$AjaxLogin$RegisterUserWindow()
{
    this.debug = 0;
    this.state = 0;
    this.IE = document.all?true:false;

    this.RegisterUserWindow = null;
    this.resetPasswordLayer = null;
    
    this.bodyUniqueId = undefined;
    this.body = null;
    
    this.IsUserCreated = false;
}


Tops.AjaxLogin.RegisterUserWindow.getInstance = function Tops$AjaxLogin$RegisterUserWindow$getInstance()
{
    if (arguments.length !== 0) throw Error.parameterCount();
    return Tops.AjaxLogin.RegisterUserWindow._instance || null;
}

Tops.AjaxLogin.RegisterUserWindow._initialize = function Tops$AjaxLogin$RegisterUserWindow$_initialize( windowid, properties )
{
    if (Tops.AjaxLogin.RegisterUserWindow.getInstance()) {
        throw Error('Instance Already Exists.  Cannot have multiple instances.');
    }
    Tops.AjaxLogin.RegisterUserWindow._instance = new Tops.AjaxLogin.RegisterUserWindow();
    var obj = Tops.AjaxLogin.RegisterUserWindow.getInstance();
    
    for (var name in properties)
    {
        var val = properties[name];
        obj[name] = val;
    }
    
    obj._initializeInternal( windowid );
}


// -------------- Object Functions ----------------------

function Tops$AjaxLogin$RegisterUserWindow$_initializeInternal(windowid)
{
    this.RegisterUserWindow = document.getElementById(windowid);

    if((this.bodyUniqueId !== undefined))
    {
        this.body = document.getElementById(this.bodyUniqueId);
    }
    
    // Browser Detection
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
        var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion>=8) {
            this.isIE8 = true;
        } else if (ieversion>=7) {
            this.isIE7 = true;
        } else if (ieversion>=6) {
            this.isIE6 = true;
        } else if (ieversion>=5) {
            this.isIE5 = true;
        }
    }
}

function Tops$AjaxLogin$RegisterUserWindow$prototype$open(location)
{
    if (!location)    
        location = '/toplets/login/RegisterUser.aspx';
    var winfo = getWindowInfo();
    
    this.RegisterUserWindow.style.width = (winfo.width - 300) + "px";
    this.RegisterUserWindow.style.height = (winfo.height - 200) + "px";
    
    this.positionWindow();

    this.RegisterUserWindow.style.display = 'block';

    if(this.state === 0){




        var height = "100%";
        var iframestr = '<IFRAME border="0" name="'+ this.body.id +'_iframe" id="'+ this.body.id +'_iframe" frameborder="0" src="' + location + '" height="' + height +'" width="100%"></IFRAME>';
        this.body.innerHTML = iframestr;
        var iframeEle = document.getElementById(this.body.id +'_iframe');


        if(this.body.clientHeight)
        {
            var p = this.body.parentNode.parentNode.parentNode;
            height = p.clientHeight - p.rows[0].clientHeight;
        }
        var iframestr = '<IFRAME border="0" name="'+ this.body.id +'_iframe" id="'+ this.body.id +'_iframe" frameborder="0" src="' + location + '" height="' + height +'" width="100%"></IFRAME>';
        this.body.innerHTML = iframestr;
        var iframeEle = document.getElementById(this.body.id +'_iframe');
  
    }

}

function Tops$AjaxLogin$RegisterUserWindow$prototype$close()
{
    if(this.IsUserCreated === true)
    {
        document.location.reload(true);
    }

    this.RegisterUserWindow.style.display = 'none';
}

function Tops$AjaxLogin$RegisterUserWindow$prototype$positionWindow()
{
    if(this.RegisterUserWindow){
        var w = getWindowInfo();
        
        this.RegisterUserWindow.style.top = (((w.height - this.RegisterUserWindow.style.height.replace('px','')) / 2) + w.scrollY) + "px";
        this.RegisterUserWindow.style.left = (((w.width - this.RegisterUserWindow.style.width.replace('px','')) / 2) + w.scrollX) + "px";
//        
//        this.RegisterUserWindow.style.display = 'inline';
//        
//        var width = 0;
//        var height = 0;
//        if(this.RegisterUserWindow.offsetWidth) {
//            width = this.RegisterUserWindow.offsetWidth;
//            height = this.RegisterUserWindow.offsetHeight;
//        } else if(this.RegisterUserWindow.style.pixelWidth) {
//            width = this.RegisterUserWindow.style.pixelWidth;
//            height = this.RegisterUserWindow.style.pixelHeight;
//        }
//        
//        this.RegisterUserWindow.style.top = ((w.height / 2) - (parseInt(height)/2) + w.scrollY) + "px";
//        this.RegisterUserWindow.style.left = ((w.width / 2) - (parseInt(width)/2) + w.scrollX) + "px";
        
    }
}

function Tops$AjaxLogin$RegisterUserWindow$prototype$userCreated( hasCreated)
{
    if(!hasCreated)
    {
        hasCreated = true;
    }
    
    if(hasCreated === true)
    {
        this.IsUserCreated = true;
    }
}

// ------------ Register Prototypes ----------------------

Tops.AjaxLogin.RegisterUserWindow.prototype = {
    _initializeInternal: Tops$AjaxLogin$RegisterUserWindow$_initializeInternal,
    open: Tops$AjaxLogin$RegisterUserWindow$prototype$open,
    close: Tops$AjaxLogin$RegisterUserWindow$prototype$close,
    positionWindow: Tops$AjaxLogin$RegisterUserWindow$prototype$positionWindow,
    userCreated: Tops$AjaxLogin$RegisterUserWindow$prototype$userCreated
};


// -------------- Generic functions -----------------------
function getWindowInfo() {
    return {
        "width": (function() {
            if (typeof window.innerWidth !== 'undefined') return window.innerWidth;
            if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
            return document.body.clientWidth;
        })(),
        "height": (function() {
            if (typeof window.innerHeight !== 'undefined') return window.innerHeight;
            if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
            return document.body.clientHeight;
        })(),
        "scrollY": (function() {
            if (typeof window.pageYOffset !== 'undefined') return window.pageYOffset;
            if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop;
            return document.body.scrollTop || 0;
        })(),
        "scrollX": (function() {
            if (typeof window.pageXOffset !== 'undefined') return window.pageXOffset;
            if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft;
            return document.body.scrollLeft || 0;
        })()
    }
}

/*
function getWindowInfo()
{
  var o = new Object();
  
  // Window Width and Height  
  if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    o.width = document.documentElement.clientWidth;
    o.height = document.documentElement.clientHeight;
  } else if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    o.width = window.innerWidth;
    o.height = window.innerHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    o.width = document.body.clientWidth;
    o.height = document.body.clientHeight;
  }

  // Scroll
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    o.scrollY = window.pageYOffset;
    o.scrollX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    o.scrollY = document.body.scrollTop;
    o.scrollX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    o.scrollY = document.documentElement.scrollTop;
    o.scrollX = document.documentElement.scrollLeft;
  } else {
    o.scrollY = 0;
    o.scrollX = 0;
  }


  return o;
}

*/