///<Summary>
///Object required for Warnings and errors
///</Summary>

/**
 *
 * @param {String} message
 * @param {MessageType} messageType
 */
function Message (message, messageType)
{
    this.Message = message;
    this.MessageType = messageType;
}

/// <summary>
/// Enum for the warning severity
/// </summary>
var MessageType =
{
    /// <summary>
    /// Warning is of unspecified type
    /// </summary>
    None : 0,

    /// <summary>
    /// Warning is an error and must not allow action to continue
    /// </summary>
    Error : 1,

    /// <summary>
    /// Warning is an warning and can allow action to continue
    /// </summary>
    Warning : 1,

    /// <summary>
    /// Warning is an warning and can allow action to continue
    /// </summary>
    Information : 2,
    
    /// <summary>
    /// Warning is like information above, but with unescaped HTML encoded message
    /// </summary>
    HTMLInformation : 3
 
};


/// <summary>
/// Enum for the mode for the popup
/// </summary>
var PopupMode =
{
    /// <summary>
    /// Warning is of unspecified type
    /// </summary>
    None : 0,

    /// <summary>
    /// Displaying Errors
    /// </summary>
    ErrorDisplay : 1,

    /// <summary>
    /// Displaying Iframes
    /// </summary>
    IframeDisplay : 2
};

///<Summary>
///Object required for Warnings and errors Collection
///</Summary>
function ErrorCollection ()
{
    MakeElementDraggable(document.getElementById("GenericTopBorder"));

    this.ErrorCollection = new Array();
    this.WarningCollection = new Array();
    this.InformationCollection = new Array();
    this.HTMLInformationCollection = new Array();

    ///<Summary>
    ///Adds an error to the error collection
    ///</Summary>
    /***
     *
     * @param {String} warningMessage
     */
    this.AddError = function (warningMessage)
    {
        var error = new Message(warningMessage, MessageType.Error);
        var includeError = true;

        //make sure this error has not been added already
        for(var i = 0; i < this.ErrorCollection.length; i++)
        {
            if((error.Message === this.ErrorCollection[i].Message) && (error.MessageType === this.ErrorCollection[i].MessageType))
            {
                includeError = false;
            }
        }

        if(includeError)
        {
            this.ErrorCollection.push (error);
        }
    };

    ///<Summary>
    ///Adds an warning to the warning collection
    ///</Summary>
    /**
     *
     * @param {String} warningMessage
     */
    this.AddWarning = function (warningMessage)
    {
        var error = new Message(warningMessage, MessageType.Warning);
        var includeError = true;

        //make sure this error has not been added already
        for(var i = 0; i < this.WarningCollection.length; i++)
        {
            if((error.Message === this.WarningCollection[i].Message) && (error.MessageType === this.WarningCollection[i].MessageType))
            {
                includeError = false;
            }
        }

        if(includeError)
        {
            this.WarningCollection.push (error);
        }
    };

    ///<Summary>
    ///Adds information to the icollection
    ///</Summary>
    /**
     *
     * @param {String} informationMessage
     */
    this.AddInformation = function(informationMessage)
    {
        var information = new Message(informationMessage, MessageType.Information);
        var includeError = true;

        //make sure this error has not been added already
        for(var i = 0; i < this.WarningCollection.length; i++)
        {
            if((information.Message === this.InformationCollection[i].Message) && (information.MessageType === this.InformationCollection[i].MessageType))
            {
                includeError = false;
            }
        }

        if(includeError)
        {
            this.InformationCollection.push(information);
        }
    };
    
    ///<Summary>
    ///Adds unendoded HTML information to the icollection
    ///</Summary>
    /**
     *
     * @param {String} informationMessage
     */
    this.AddHTMLInformation = function(informationMessage)
    {
        var HTMLinformation = new Message(informationMessage, MessageType.HTMLInformation);
        var includeError = true;

        //make sure this error has not been added already
        for(var i = 0; i < this.HTMLInformationCollection.length; i++)
        {
            if((HTMLinformation.Message === this.HTMLInformationCollection[i].Message) && (HTMLinformation.MessageType === this.HTMLInformationCollection[i].MessageType))
            {
                includeError = false;
            }
        }

        if(includeError)
        {
            this.HTMLInformationCollection.push(HTMLinformation);
        }
    };

    htmlEncode = function(string)
    {
        if (string == null) return string;
        return string.replace(/</g, '&lt;').replace(/>/g, '&gt;')
    }

    ///<Summary>
    ///Displays the errors to the user
    ///</Summary>
    /**
     *
     * @param {function} EventToRun
     * @param {Array} args
     * @param {boolen} continueOnErrors
     */
    this.DisplayAll = function(EventToRun, args, continueOnErrors, DisplayClose)
    {
        var okButton = document.getElementById("OkButton");
        var cancelButton = document.getElementById("CancelButton");
        var topCancelButton = document.getElementById("TopCancelButton");
        var errorString = "";
        var warningString = "";
        var informationString = "";
        var errorHeader = document.getElementById("ErrorHeader");
        var errorRow = document.getElementById("ErrorRow");
        var warningHeader = document.getElementById("WarningHeader");
        var warningRow = document.getElementById("WarningRow");
        var informationHeader = document.getElementById("InformationHeader");
        var informationRow = document.getElementById("InformationRow");
        var popup = document.getElementById("GenericPopupDiv");        
		var OuterDiv  =document.getElementById('OuterDiv');
        var popupUsed = false;
        var errors = false;

        okButton.style.display = "";
        cancelButton.style.display = "";
        topCancelButton.style.display = "";
        OuterDiv.style.display = "";

        if(DisplayClose===null)
        {
            DisplayClose = false;
        }

        //If there are errors then add the errors to the error string
        if(this.ErrorCollection.length > 0)
        {
            //Display errors
            for (var i = 0; i < this.ErrorCollection.length; i++)
            {
                errorString += "- " + htmlEncode(this.ErrorCollection[i].Message) + "<br/>";
            }

            errors = true;
            errorHeader.style.display = "";
            errorRow.style.display = "";
            var errorCell = GetElement(errorRow, "ErrorCell", "TD");
            errorCell.innerHTML = errorString;
            popupUsed = true;
        }
        else
        {
            errorHeader.style.display = "none";
            errorRow.style.display = "none";
        }

        //If there are warnings then add the warnings to the warning string
        if(this.WarningCollection.length > 0)
        {
            //Display warnings
            for (var j = 0; j < this.WarningCollection.length; j++)
            {
                warningString += "- " + htmlEncode(this.WarningCollection[j].Message) + "<br/>";
            }
            warningHeader.style.display = "";
            warningRow.style.display = "";
            var warningCell = GetElement(warningRow, "WarningCell", "TD");
            warningCell.innerHTML = warningString;
            popupUsed = true;
        }
        else
        {
            warningHeader.style.display = "none";
            warningRow.style.display = "none";
        }

        //If there is information then add the Information to the information string
        if(this.InformationCollection.length > 0 || this.HTMLInformationCollection.length > 0)
        {
            //Display Information
            for (var k = 0; k < this.InformationCollection.length; k++)
            {
                informationString += "- " + htmlEncode(this.InformationCollection[k].Message) + "<br/>";
            }
            
            //and display any unescaped HTML information
            for (var k = 0; k < this.HTMLInformationCollection.length; k++)
            {
                informationString += "- " + this.HTMLInformationCollection[k].Message + "<br/>";
            }
            
            informationHeader.style.display = "";
            informationRow.style.display = "";
            var informationCell = GetElement(informationRow, "InformationCell", "TD");
            informationCell.innerHTML = informationString;
            popupUsed = true;
        }
        else
        {
            informationHeader.style.display = "none";
            informationRow.style.display = "none";
        }

        //If the popup has been used then display it
        if(popupUsed)
        {
            ShowPopup(popup,PopupMode.ErrorDisplay);
        }

        var continueExecution = false;

        //If continue is true then always continue
        if(continueOnErrors)
        {
            continueExecution = true;
        }
        else if(!continueExecution && !errors) // if not continue and no errors then continue
        {
            continueExecution = true;
        }

        //Set up the default button
        if(typeof page != "undefined")
        {
			if(page != null)
			{
				page.OriginalDefaultElementId = page.DefaultElementId;
				page.DefaultElementId = okButton.id;
            }
        }

        YAHOO.util.Event.removeListener(okButton, "click");
        YAHOO.util.Event.addListener(okButton, "click", function(eventInfo, object)
        {
            HidePopup();
            if(typeof page != "undefined")
            {
				if(page != null)
				{
					page.DefaultElementId = page.OriginalDefaultElementId;
				}
            }
            if(EventToRun != null && continueExecution)
            {
                EventToRun(args);
            }
        }, args, continueExecution);

        if(DisplayClose)
        {
            //If the Ok Is being displayed then change the image to cancel
            cancelButton.src = cancelButton.src.replace("CloseButtonImage.gif","CancelButtonImage.gif");
            cancelButton.style.display = "";
            topCancelButton.style.display = "";
            
            if(typeof page != "undefined")
            {
				if(page != null)
				{
					page.OriginalEscapeElementId = page.EscapeElementId;
					page.EscapeElementId = cancelButton.id;
				}
            }
            
            YAHOO.util.Event.removeListener(cancelButton, "click");
            YAHOO.util.Event.addListener(cancelButton, "click", function(eventInfo, object)
            {
                if(typeof page == "undefined")
                {
					if(page != null)
					{
						page.EscapeElementId = page.OriginalEscapeElementId;
					}
                }
                HidePopup();
            });
        }
        else
        {
            cancelButton.style.display = "none";
            topCancelButton.style.display = "none";
        }

        if (this.ErrorCollection.length === 0 && !popupUsed)
        {
            if(EventToRun !== null)
            {
                EventToRun(args);
            }
            popup.style.display = "none";
        }
        this.ClearAll();
        
        try
        {
			if(this.ErrorCollection.length > 0 || this.WarningCollection.length > 0 || this.InformationCollection.length > 0)
			{
				HideGettingQuotePopUp();
			}
        }
        catch(e){}
    };

	///<Summary>
    ///Displays the errors to the user
    ///</Summary>
    /**
     *
     * @param {function} EventToRun
     * @param {Array} args
     * @param {boolen} continueOnErrors
     */
    this.DisplayAllWithClose = function(OKEventToRun, OKargs, CancelEventToRun, Cancelargs, continueOnErrors, DisplayClose)
    {
        var okButton = document.getElementById("OkButton");
        var cancelButton = document.getElementById("CancelButton");
        var topCancelButton = document.getElementById("TopCancelButton");
        var errorString = "";
        var warningString = "";
        var informationString = "";
        var errorHeader = document.getElementById("ErrorHeader");
        var errorRow = document.getElementById("ErrorRow");
        var warningHeader = document.getElementById("WarningHeader");
        var warningRow = document.getElementById("WarningRow");
        var informationHeader = document.getElementById("InformationHeader");
        var informationRow = document.getElementById("InformationRow");
        var popup = document.getElementById("GenericPopupDiv");        
		var OuterDiv  =document.getElementById('OuterDiv');
        var popupUsed = false;
        var errors = false;

        okButton.style.display = "";
        cancelButton.style.display = "";
        topCancelButton.style.display = "";
        OuterDiv.style.display = "";

        if(DisplayClose===null)
        {
            DisplayClose = false;
        }

        //If there are errors then add the errors to the error string
        if(this.ErrorCollection.length > 0)
        {
            //Display errors
            for (var i = 0; i < this.ErrorCollection.length; i++)
            {
                errorString += "- " + htmlEncode(this.ErrorCollection[i].Message) + "<br/>";
            }

            errors = true;
            errorHeader.style.display = "";
            errorRow.style.display = "";
            var errorCell = GetElement(errorRow, "ErrorCell", "TD");
            errorCell.innerHTML = errorString;
            popupUsed = true;
        }
        else
        {
            errorHeader.style.display = "none";
            errorRow.style.display = "none";
        }

        //If there are warnings then add the warnings to the warning string
        if(this.WarningCollection.length > 0)
        {
            //Display warnings
            for (var j = 0; j < this.WarningCollection.length; j++)
            {
                warningString += "- " + htmlEncode(this.WarningCollection[j].Message) + "<br/>";
            }
            warningHeader.style.display = "";
            warningRow.style.display = "";
            var warningCell = GetElement(warningRow, "WarningCell", "TD");
            warningCell.innerHTML = warningString;
            popupUsed = true;
        }
        else
        {
            warningHeader.style.display = "none";
            warningRow.style.display = "none";
        }

        //If there is information then add the Information to the information string
        if(this.InformationCollection.length > 0 || this.HTMLInformationCollection.length > 0)
        {
            //Display Information
            for (var k = 0; k < this.InformationCollection.length; k++)
            {
                informationString += "- " + htmlEncode(this.InformationCollection[k].Message) + "<br/>";
            }
            
            //and display any unescaped HTML information
            for (var k = 0; k < this.HTMLInformationCollection.length; k++)
            {
                informationString += "- " + this.HTMLInformationCollection[k].Message + "<br/>";
            }
            
            informationHeader.style.display = "";
            informationRow.style.display = "";
            var informationCell = GetElement(informationRow, "InformationCell", "TD");
            informationCell.innerHTML = informationString;
            popupUsed = true;
        }
        else
        {
            informationHeader.style.display = "none";
            informationRow.style.display = "none";
        }

        //If the popup has been used then display it
        if(popupUsed)
        {
            ShowPopup(popup,PopupMode.ErrorDisplay);
        }

        var continueExecution = false;

        //If continue is true then always continue
        if(continueOnErrors)
        {
            continueExecution = true;
        }
        else if(!continueExecution && !errors) // if not continue and no errors then continue
        {
            continueExecution = true;
        }

        //Set up the default button
        if(typeof page != "undefined")
        {
            if (page != null)
            {
            page.OriginalDefaultElementId = page.DefaultElementId;
            page.DefaultElementId = okButton.id;
        }
        }

        YAHOO.util.Event.removeListener(okButton, "click");
        YAHOO.util.Event.addListener(okButton, "click", function(eventInfo, object)
        {
            HidePopup();
            if(typeof page != "undefined")
            {
                if (page != null)
                {
                page.DefaultElementId = page.OriginalDefaultElementId;
            }
            }
            if(OKEventToRun != null && continueExecution)
            {
                OKEventToRun(OKargs);
            }
        }, OKargs, continueExecution);

        if(DisplayClose)
        {
            //If the Ok Is being displayed then change the image to cancel
            cancelButton.src = cancelButton.src.replace("CloseButtonImage.gif","CancelButtonImage.gif");
            cancelButton.style.display = "";
            topCancelButton.style.display = "";
            
            if(typeof page != "undefined")
            {
                if (page != null)
                {
                page.OriginalEscapeElementId = page.EscapeElementId;
                page.EscapeElementId = cancelButton.id;
            }
            }
            
            YAHOO.util.Event.removeListener(cancelButton, "click");
            YAHOO.util.Event.addListener(cancelButton, "click", function(eventInfo, object)
            {
                if(typeof page == "undefined")
                {
                    if (page != null)
                    {
                    page.EscapeElementId = page.OriginalEscapeElementId;
                }
                }
                
                if(CancelEventToRun !== null)
				{
					CancelEventToRun(Cancelargs);
				}
                HidePopup();
            });
        }
        else
        {
            cancelButton.style.display = "none";
            topCancelButton.style.display = "none";
        }

        if (this.ErrorCollection.length === 0 && !popupUsed)
        {
            if(OKEventToRun !== null)
            {
                OKEventToRun(OKargs);
            }
            popup.style.display = "none";
        }
        this.ClearAll();
        
        try
        {
			if(this.ErrorCollection.length > 0 || this.WarningCollection.length > 0 || this.InformationCollection.length > 0)
			{
				HideGettingQuotePopUp();
			}
        }
        catch(e){}
    };

    ///<Summary>
    ///Clears the objects arrays
    ///</Summary>
    this.ClearAll = function()
    {
        //Clear the error Collection
        for (var i = this.ErrorCollection.length; i > -1 ; i--)
        {
            this.ErrorCollection.pop();
        }

        //Clear the warning Collection
        for (var j = this.WarningCollection.length; j > -1; j--)
        {
            this.WarningCollection.pop();
        }

        //Clear the information Collection
        for (var k = this.InformationCollection.length; k > -1 ; k--)
        {
            this.InformationCollection.pop();
        }
    };
}

function IframeHandler()
{
    MakeElementDraggable(document.getElementById("GenericTopBorder"));
    
    this.GetIframeObject = function()
    {
		var iframe = document.getElementById('GenericIframe');
		if(iframe == null) //try parent
		{
			iframe = window.parent.document.getElementById('GenericIframe');
		}
        return iframe;
    };

    this.DisplayPopup = function(okEventToRun, cancelEventToRun, args)
    {
        var okButton = document.getElementById("OkButton");
        
        //Make sure all buttons not supposed to be displayed are hidden
        var printButton = document.getElementById('PrintButton');
        printButton.style.display = "none";
        var emailButton = document.getElementById('EmailButton');
        emailButton.style.display = "none";
        var saveButton = document.getElementById('SaveButton');
        saveButton.style.display = "none";
        var addNoteButton = document.getElementById('AddNoteButton');
        addNoteButton.style.display = "none";

        //Remove All Click listners on the object then add the new one
        YAHOO.util.Event.removeListener(okButton, "click");

        if(okEventToRun !== null)
        {
            okButton.style.display = "";
            //Set up the Default Buttons
            if(page != null)
            {
                page.OriginalDefaultElementId = page.DefaultElementId;
                page.DefaultElementId = okButton.id;
            }
            
            YAHOO.util.Event.addListener(okButton, "click", function(eventInfo, object)
            {
				if(!isPopupApplicantEditing)
				{
					HidePopup();
				}
				
                if(page!=null)
                {
                    page.DefaultElementId = page.OriginalDefaultElementId;
                }
                if(okEventToRun !== null)
                {
                    okEventToRun(args);
                }
            }, args);
        }
        else    
        {
            okButton.style.display = "none";
        }

        var closeButton = document.getElementById("CancelButton");
        var topCloseButton = document.getElementById("TopCancelButton");

        //Remove All Click listners on the object then add the new one
        YAHOO.util.Event.removeListener(closeButton, "click");

        if(cancelEventToRun !== null)
        {
            if(okButton.style.display == "")
            {
                closeButton.src = closeButton.src.replace("CloseButtonImage.gif","CancelButtonImage.gif");
            }
            else
            {
                closeButton.src = closeButton.src.replace("CancelButtonImage.gif","CloseButtonImage.gif");
            }
            closeButton.style.display = "";
            topCloseButton.style.display = "";
            
            //Default Key
            if(page!=null)
            {
                page.OriginalEscapeElementId = page.EscapeElementId;
                page.EscapeElementId = closeButton.id;
            }
            
            YAHOO.util.Event.addListener(closeButton, "click", function(eventInfo, object)
            {
                HidePopup();
                if(page!=null)
                {
                    page.EscapeElementId = page.OriginalEscapeElementId;
                }
                if(cancelEventToRun !== null)
                {
                    cancelEventToRun(args);
                }
            }, args);
        }
        else
        {
            closeButton.style.display = "none";
        }
        ShowPopup(null,PopupMode.IframeDisplay);   
    };

    this.HidePopup = HidePopup;
}

function ChangeButtonImageFileName(button,fileName)
{

    var Source = button.src.split("/");
    //Lenght minus 1 to exclude the last item
    var newSrc="";
    for (var i=0;i<Source.length-1;i++)
    {
        newSrc+=Source[i] + "/";
    }
    newSrc+= fileName;
    button.src = newSrc;
}

function ShowPopup(popupDiv,mode)
{
    //gets the available width (Available Width)
    
    var availableWidth;
    var availableHeight;

    if( typeof( window.innerWidth ) == 'number' ) 
    {
        availableWidth = window.innerWidth;
        availableHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {
        availableWidth = document.documentElement.clientWidth;
        availableHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
    {
        availableWidth = document.body.clientWidth;
        availableHeight = document.body.clientHeight;
    }


    //divides the width by 2 (Center Width)
    var positionWidth = availableWidth/2;
    var positionHeight = availableHeight/2;

    var iframeTable = document.getElementById("IframeTable");
    var errorTable = document.getElementById("ErrorTable");
    switch(mode)
    {
        case PopupMode.ErrorDisplay:
        {
            iframeTable.style.display='none';
            errorTable.style.display='';
            break;
        }
        case PopupMode.IframeDisplay:
        {
            iframeTable.style.display='';
            errorTable.style.display='none';
            break;
        }
        default:
        {
            iframeTable.style.display='none';
            errorTable.style.display='none';
            break;
        }
    }

    if(popupDiv==null)
    {
        popupDiv = document.getElementById("GenericPopupDiv");
    }

    popupDiv.style.display = "";
    var divWidth = popupDiv.clientWidth / 2;
    var divHeight = popupDiv.clientHeight / 2;

    var topPosition = (positionHeight + topOffSet) - divHeight;
    var leftPosition = positionWidth - divWidth;
    var width = popupDiv.clientWidth;
    var height = popupDiv.clientHeight;

    if(leftPosition<0)
    {
        leftPosition = leftPosition * -1;
    }

    var blankIFrame = document.getElementById('BlankIFrame');
   if(blankIFrame  != null)
   {
        blankIFrame.style.display="";
        blankIFrame.style.top=topPosition + 'px';
        blankIFrame.style.left=leftPosition + 'px';
        blankIFrame.style.height=height + 'px';
        blankIFrame.style.width=width + 'px';
    }
    popupDiv.style.zIndex=1;
    popupDiv.style.top = topPosition + 'px';
    popupDiv.style.left = leftPosition + 'px';
}

function HidePopup()
{
    var popupDiv = document.getElementById("GenericPopupDiv");
    popupDiv.style.display = "none";
    var blankIFrame = document.getElementById('BlankIFrame');
    if(blankIFrame != null)
    {
        blankIFrame.style.display="none";
		blankIFrame.src = blankPagePath; 
    }
    
}

/**
 *
 * @param {EventObject} e
 */
var alterTop = null;
var alterLeft = null;
function InitiateDrag(e)
{
    var evt = e || window.event;
    var startX = parseInt(evt.x);
    var startY = parseInt(evt.y);
    var obj = document.getElementById("GenericPopupDiv");
    var blankIFrame = document.getElementById('BlankIFrame');

    alterTop = (parseInt(obj.style.top)-startY);
    alterLeft = (parseInt(obj.style.left)-startX);

    obj.style.top = parseInt(startY + alterTop) + 'px';
    obj.style.left = parseInt(startX + alterLeft) + 'px';

    if (blankIFrame)
    {
        blankIFrame.top = parseInt(startY + alterTop) + 'px';
        blankIFrame.style.left = parseInt(startX + alterLeft) + 'px';
    }

    obj.onmousemove = Drag;
    obj.onmouseup = Drop;
   // obj.setCapture(true);
    if (IsMozilla()) {
        if (document.body.addEventListener) {

            window.addEventListener("mousemove", MovePopup, true);
        }
    }
    else {
    obj.setCapture(true);        
    }
    return false;
}

/**
 *
 * @param {EventObject} e
 */
function Drag(e)
{
    // only drag when the mouse is down
    var evt = e || window.event;
    var startX = parseInt(evt.clientX);
    var startY = parseInt(evt.clientY);
    var obj = document.getElementById("GenericPopupDiv");
    var blankIFrame = document.getElementById('BlankIFrame');
    
    obj.style.top = parseInt(startY + alterTop) + 'px';
    obj.style.left = parseInt(startX + alterLeft) + 'px';
    
    if (blankIFrame)
    {
        blankIFrame.style.top =obj.style.top;
        blankIFrame.style.left = obj.style.left;
    }
}

function Drop(e)
{
    var obj = document.getElementById("GenericPopupDiv");
    obj.onmouseup = null;
    obj.onmousemove = null;
    // obj.releaseCapture();

    if (IsMozilla()) {
       
if (document.body.removeEventListener) {
            window.removeEventListener("mousemove", MovePopup, true);
        }
    }
    else { obj.releaseCapture();
        
    }
    //Reset The values
    alterTop = null;
    alterLeft = null;
}

/**
 * Makes the element dragable
 * @param {HTML Element} element
 */
function MakeElementDraggable(element)
{
    YAHOO.util.Event.addListener(element, "mousedown", function (eventInfo, object)
    {
        InitiateDrag(eventInfo);
    });
}

function GetButtonElement(buttonId)
{
	var button = document.getElementById(buttonId);
		
	if(button == null)
	{
		button = window.parent.document.getElementById(buttonId);
	}
	return button;
}

///<Summary>
///This will either show or hide a button on the generic popup "taskbar"
///</Summary>
function ShowHideButton(buttonId, show)
{
	var button = window.parent.document.getElementById(buttonId);
	
	if(button != null)
	{
		if(show)
		{
			button.style.display = "";
		}
		else
		{
			button.style.display = "none";
		}
	}
}

function SetupButtons()
{
	var backButton = GetButtonElement('BackButton');
	var nextButton = GetButtonElement('NextButton');
		
	YAHOO.util.Event.addListener(backButton, "click", function(eventInfo, object)
														{
															ButtonEventHandler(eventInfo.srcElement.id);
														});
	YAHOO.util.Event.addListener(nextButton, "click", function(eventInfo, object)
														{
															ButtonEventHandler(eventInfo.srcElement.id);
														});
}

function ButtonEventHandler(buttonId)
{
	switch(buttonId)
	{
		case "NextButton":
		{
			var nextButton = GetFrameElement('NextPostBackButton');			
			if(nextButton != null)
			{
				nextButton.click();
			}
			break;
		}
		case "BackButton":
		{
			var backButton = GetFrameElement('BackPostButton');			
			if(backButton != null)
			{
				backButton.click();
			}
			
			break;
		}
	}
}


function SetupInnerPopup()
{
	//Hide Buttons
	var sendButton = document.getElementById('EmailButton');
	var printButton = document.getElementById('PrintButton');
	var saveButton = document.getElementById('SaveButton');
	var backButton = document.getElementById('BackButton');
	var nextButton = document.getElementById('NextButton');
	var popupDiv = document.getElementById('OuterDiv');
	popupDiv.visible = false;
	
	//sendButton.style.display = "none";
	printButton.style.display = "none";
	saveButton.style.display = "none";
	backButton.style.display = "none";
	nextButton.style.display = "none";
	popupDiv.style.display = "none";
}
function IsMozilla() {
    return navigator.userAgent.indexOf("Firefox") != -1;
   
}
