//<![CDATA[

// Name:        WebFactory.WebApplications.Framework.js
// Assembly:    WebFactory.dll
// Version:     1.5.0.0
// FileVersion: 1.5.0.0
//-----------------------------------------------------------------------
// Copyright (C) Web Factory Live Limited. All rights reserved.
//-----------------------------------------------------------------------

/* #Region " Private Fields " */

var __dialogHeight = 570;
var __dialogWidth = 800;

// Resize dialog window for IE6 and below.
if (__isInternetExplorer() && (__getInternetExplorerVersion() < 7)) {
    __dialogHeight = 670;
}

/* #End Region

/* #Region " Private Methods " */

function __isFirefox() {
    return (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent));
}

function __isInternetExplorer() {
    return (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
}

function __getFirefoxVersion() {
    if (__isFirefox()) {
        var ffversion = new Number(RegExp.$1);
        return ffversion;
    }
    else
        return null;
}

function __getInternetExplorerVersion() {
    if (__isInternetExplorer()) {
        var ieversion = new Number(RegExp.$1)
        return ieversion
    }
    else
        return null;
}

function __showModalPopup(url, height, width) {
    return window.showModalDialog(url, "", "dialogWidth=" + width + "px;dialogHeight=" + height + "px;scroll=no;border=thin;status=no;help=no;center:yes;resizable:no");
}

function __showPopup(url, height, width) {
    if (navigator.appName != "Netscape") {
        window.showModelessDialog(url, "", "dialogWidth=" + width + "px;dialogHeight=" + height + "px;scroll=no;border=thin;status=no;help=no;center:yes;resizable:no");
    }
    else {
        window.open(url, "", "width=" + width + ",height=" + height + ",location=no,menubar=no,resizable=no,scrollbars=no,status=no");
    }
}

/* #End Region */

/* #Region " Public Methods " */

/// <summary>
/// Repositions the UpdateProgress panel over the element that initiated an asynchronous post back.
/// </summary>
function asyncPostBack_Begin(sender, args) {
    // Find the position of the active element
    var obj = document.activeElement;
    var coors = findPosition(obj);

    // Position the update progress panel near the active element
    $get("UpdateProgress").style.top = coors[1] + 'px';
    $get("UpdateProgress").style.left = coors[0] + 'px';
}

/// <summary>
/// Intercepts and prevents duplicate form submissions.
/// </summary>
function catchDuplicatePostBacks(sender, message) {
    if (sender.value == message) {
        alert('The server is already working on your previous request.\n\nPlease wait for the server to respond.');
        sender.disabled = true;
        return false;
    }
    else {
        sender.value = message;
        return true;
    }
}

/// <summary>
/// Closes the window and sets the windows return value to the passed value.
/// </summary>
function closeWindow(value) {
    window.returnValue = value;
    window.close();
}

/// <summary>
/// Prompts the user before closing the window.
/// </summary>
function closeWindowWithConfirmation(prompt, value) {
    if (confirm(prompt)) {
        closeWindow(value);
    }
}

/// <summary>
/// Copies the passed value to the clipboard.
/// </summary>
function copyToClipboard(value) {
    var helper = document.createElement("textarea");
    helper.appendChild(document.createTextNode(value));

    var range = helper.createTextRange()
    range.execCommand("Copy");
}

/// <summary>
/// Returns the co-ordinates of the passed object.
/// </summary>
function findPosition(obj) {
    var curleft = curtop = 0;
    if (obj) {
        if (obj.offsetParent) {
            curleft = obj.offsetLeft;
            curtop = obj.offsetTop;

            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            }
        }
        return [curleft, curtop];
    }
    else
        return [0, 0];
}

/// <summary>
/// Navigates to the specified url.
/// </summary>
function navigateTo(url) {
    window.location = url;
}

/// <summary>
/// Opens a modal pop-up window to the specified url.
/// </summary>
function showModalPopup(url) {
    return __showModalPopup(url, __dialogHeight, __dialogWidth);
}

/// <summary>
/// Opens a pop-up window to the specification url.
/// </summary>
function showPopup(url) {
    return __showPopup(url, __dialogHeight, __dialogWidth);
}
/* #End Region */
//]]>