function LoginProxy() {
	this.init = function(params) {
		this.options = {
			defaultLoginType: "PWD",
			selectedLoginType: "",
			cookieName: "LHV_LOGIN_TYPE"
		};

        this.isPluginChecked = false;
		this.options = $.extend(this.options, params);

		if (this.options.selectedLoginType == "") {
			this.selectedType = readCookie(this.options.cookieName);
		}
		if (!this.selectedType) {
			this.selectedType = (this.options.selectedLoginType != "") ? this.options.selectedLoginType : this.options.defaultLoginType;
		}
	},

	this.rememberTab = function(type) {
		createCookie(this.options.cookieName, type);
	},

	this.doFormSubmit = function(form, type) {
		createCookie(this.options.cookieName, type);
		if (type == 'IDC'){
			form.action = loginOptions.certUrl;
		} else {
			form.action = loginOptions.Url;
		}
		form.login_type.value = type;
		return true;
	},

	// setup ajax callback
	this.mobileAuth = function (params) {
		var errorHandler = params.errorHandler;
		var sucessHandler = params.successHandler;

        refreshId = setInterval(function()
        {
            $.ajax({
                type: "POST",
                url: "login_m.cfm",
                dataType: "json",
                data: "tmp=1", // needed for Android that don't support empty body
                success: function(result) {
                    if (result.status == 0) {
                        // outstanding transaction, keep polling
                    }
                    else {
                        clearInterval(refreshId);
                        if (result.status == 1) {
                            sucessHandler(result.location);
                        }
                        else{
                            errorHandler(result.msg);
                        }
                    }
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    clearInterval(refreshId);
                    errorHandler(loginOptions.errTechnical);
                }
            });

        }, 5000);

	},

	this.isPluginInstalled = function() {
		try {
            if ($('#idcardcontainer').length == 0)
			    $('body').append("<div id='idcardcontainer'></div>");
			if (this.pluginInstalled() || $.browser.msie) {
				$('#idcardcontainer')[0].innerHTML = '<object id="esteid" type="application/x-esteid" style="width: 1px; height: 1px; visibility: hidden;"></object>';
				$("#esteid")[0].getVersion();
                this.isEidInstalled = true;
			}
            else{
                this.isEidInstalled = false;
            }

		} catch(e) {
            this.isEidInstalled = false;
		}
        return this.isEidInstalled;
	},
			
	this.pluginInstalled = function() {
		navigator.plugins.refresh();
		var idCardMimeType = navigator.mimeTypes["application/x-esteid"];
		return idCardMimeType && idCardMimeType.enabledPlugin;
	},

	// can't be done if main site is not in the whitelist
	this.isCardInserted = function() {
        esteid = $("#esteid")[0];
        try{
            cert = esteid["authCert"];
            return true;
        }
        catch(e) {
            return false;
        }
	}
}
