﻿iFrame = function() { };

/* Private Properties */
iFrame.prototype.__validContext = true;
iFrame.prototype.__frameName = '__content_frame';
iFrame.prototype.__frameObject = null;
iFrame.prototype.__inRequest = false;

/* Public Properties */
iFrame.prototype.ServiceName = null;
iFrame.prototype.PageContainer = null;

/* Initialize Request */
iFrame.prototype.initializeRequest = function() {
    if (this.PageContainer != null) {
        if (typeof (this.PageContainer) != Object) {
            this.PageContainer = YAHOO.util.Dom.get(this.PageContainer);

            if (this.PageContainer == null) {
                this.__validContext = false;
            }
        }
    } else {
        this.__validContext = false;
    }

    if (this.ServiceName == null) {
        this.__validContext = false;
    }

    if (this.__validContext == true) {
        var url = this.buildUrl();

        YAHOO.util.Event.onDOMReady(function() {
            iFrame.submitRequest(url);
        });
    }
};

/* Build URL */
iFrame.prototype.buildUrl = function() {
    var url = this.ServiceName + '.aspx';
    return url;
};

/* Submit Request */
iFrame.prototype.submitRequest = function(url) {
    if (this.__frameObject === null) {
        this.__frameObject = YAHOO.util.Dom.get(this.__frameName);
    }

    if (this.__inRequest == false) {
        this.__inRequest = true;
        this.__frameObject.src = url;
    }
};

/* Send Request */
iFrame.prototype.sendRequest = function() {
     if (this.__inRequest === true) {
        return;
    } else {
        var url = this.buildUrl();
        this.submitRequest(url);
    }

    return false;
};

/* Receive Request */
iFrame.prototype.receiveRequest = function(content) {
    if (content === null) {
        return false;
    } else {
        this.__inRequest = false;
        this.PageContainer.innerHTML = content;
    }
};

/* Send Response */
iFrame.prototype.sendResponse = function(contentId) {
    if (contentId === null) {
        return;
    } else {
        var __iFrame = document.getElementById(contentId);

        if (__iFrame == null) {
            return;
        } else {
            parent.iFrame.receiveRequest(__iFrame.innerHTML);
        }
    }
};