function EmbeddedForm(params) {
    var attrs = {
        width: '100%',
        height: '700px',
        domId: '',
        src: '',
        resize: true
    };

    function initialize() {
        for (key in params) {
            attrs[key] = params[key];
        }
    }

    function waitForHeight() {
        if (window.postMessage){
            if (window.addEventListener) {
                window.addEventListener("message", function(e){
                    resizeIframe(e.data);
                }, false);
            } else if (window.attachEvent) {
                window.attachEvent("onmessage", function(e){
                    resizeIframe(e.data);
                });
            }
        }else{
            setTimeout(loadHeight, 1500);
        }
    }

    function resizeIframe(height) {
        var dom = document.getElementById(attrs.domId);
        if(!dom) return;
        if(!isNaN(parseInt(height))) {
          dom.style.height = (parseInt(height) + 20) + 'px';
        }
        dom.style.width = attrs.width;
    }

    function renderIframe() {
        var html = '<iframe id="' + attrs.domId + '" src="'+ attrs.src +'" style="border:none;height:'+attrs.height+';width:'+attrs.width+'" scrolling="no" frameborder="0"></iframe>';
        document.write(html);
        var node = document.getElementById(attrs.domId);

        if (attrs.resize) {
            if (window.postMessage) {
                waitForHeight(self);
            } else if (window.attachEvent) {
                node.attachEvent("onload", function(e) {
                    waitForHeight(self);
                });
            } else {
                // Cannot determine browser form size.
            }
        }

        node.resizeIframe = resizeIframe;
    }
    
    // Load height in non-HTML5 browser
    function loadHeight() {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = attrs.src.replace(/\/[^\/]*$/, '/height.js?' + new Date().getTime());
        document.getElementById(attrs.domId).parentNode.appendChild(script);
    }

    initialize();
    renderIframe();
}

