﻿///<reference name="MicrosoftAjax.js"/>
///<reference name="MicrosoftAjaxWebForms.js"/>
///<reference path="jquery/jquery-1.3.2-vsdoc.js" />
﻿Guid=function(){}

    Guid.Empty=function() {
        return "00000000-0000-0000-0000-000000000000";
   }
function IsDefined(obj) {
    return (typeof (obj) + '' == 'undefined' || obj == null) ? false : true;
}
    function launchScheduleViewer(id) {
        window.open("/HourlySchedule.aspx?id="+id, "mywindow", "width=925,height=700, scrollbars=1, resizable=1"); 

    }

function IsElement(id) { return IsDefined($get(id)); }
function Trim(str) {

    return str.replace(/^\s*|\s*$/g, "");
}

function gotoSwitchboard() {
    window.location = "/hhdepot/Switchboard.aspx";
}

function validateMoney(str) {
        var isCurrency_re = /^\s*(\+|-)?((\d+(\.\d\d)?)|(\.\d\d))\s*$/;
        return String(str).search(isCurrency_re) != -1
}
function getNumberFromString(moneyString) {
        return moneyString.replace(/[^0-9\.]+/g,"");
}

function alltrim(str) {
        var re = /^\$|,/g;
        str = str.replace(re, "");
        str = str.replace(/^\s+|\s+$/g, '');
        return str;
    }

function CreateQuickOpp(page, contactId) {
    page = page || "/Opportunity/QuickOpp.aspx";
    if(contactId){
        page += "?contId=" + contactId;
    }
    var hLimit = 680;
    var wLimit = 1150;
    var _height = ((window.screen.availHeight * 0.8) > hLimit) ? window.screen.availHeight * 0.8 : hLimit;
    var _width = ((window.screen.availHeight * 0.8) > wLimit) ? window.screen.availHeight * 0.8 : wLimit;
    var _top = (window.screen.availHeight - _height) / 2;
    var _left = (window.screen.availWidth - _width) / 2;
    openedWindows["Opp"] = window.open(page, "OppDetails", "scrollbars=yes,resizable=yes,height=" + _height + ",width=" + _width + ",toolbar=" + enableToolbar + ",top=" + _top + ",left=" + _left);

}
//The bind function allows us to change the call
//context enabling binding a function to an event handler
//and maintaining the reference to "this"
Function.prototype.bind = function (obj) {
    var method = this,
   temp = function () {
       return method.apply(obj, arguments);
   };
    return temp;
}


function CurrencyFormatted(amount) {
    var i = parseFloat(amount);
    if (isNaN(i)) { i = 0.00; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if (s.indexOf('.') < 0) { s += '.00'; }
    if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
}
// end of function CurrencyFormatted()
function formatCurrency(num) {
if (num==null) return null;
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' +
    num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + num + '.' + cents);
}
function swapDisabledCheckbox(chkBox, ctrl) {
    document.getElementById(ctrl).disabled = !document.getElementById(chkBox).checked;
}
function swapDisplay(id) {
    for (var i = 0; i < arguments.length; i++) {
        var elem = $get(arguments[i]);
        if (elem.style.display == "none") {

            elem.style.display = "inline";
        }
        else {
            elem.style.display = "none";
        }
    }
}
function toggleEnabled(parent, enabled) {
    var elem = $get(parent);
    for (var i = 0; i < elem.all.length; i++) {
        var child = elem.all.item(i);
        if (child.nodeName == "INPUT" || child.nodeName == "SELECT" || child.nodeName == "TEXTAREA") {
            child.disabled = !enabled;
        }
    }
}
if (typeof (jQuery) != 'undefined') {

    jQuery.fn.makeRichEditor=function()
    {
    if (this.ckeditor)
    {
            CKEDITOR.config.wsc_customerId= "1:EmPOD4-flGRr1-OWPda-rjJhQ-JoVFQ2-29Yy43-YYPem1-ScBHt-6BLhC2-ViiyI1-tN8as2-Aa";
            CKEDITOR.config.enterMode = CKEDITOR.ENTER_DIV;

            this.ckeditor(

             {
                 toolbar:
                        [
                            ['Maximize', 'Preview'],
                            ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'SpellChecker'],// 'Scayt'],
                            ['Undo', 'Redo', '-', 'Find', 'Replace'], 
                            ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'],
                            ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
                            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
                            ['Table', 'HorizontalRule', 'SpecialChar', 'PageBreak'],
                            ['Format', 'Font', 'FontSize'],
                            ['TextColor', 'BGColor','Source'] 
                        ]}
         
            );
            }
    }


    jQuery.fn.enable = function () {
        return this.removeAttr('disabled');

    }
    jQuery.fn.disable = function () {
        return this.attr("disabled", "disabled");
    }
    jQuery.fn.disabled = function (setting) {
        if (setting) {
            return this.disable();
        }
        else { return this.enable(); }
    };
    jQuery.fn.check = function (mode) {
        // if mode is undefined, use 'on' as default
        //var mode = mode || 'on';
        if (arguments.length < 1) {
            mode = 'on';
        }


        return this.each(function () {
            switch (mode) {
                case true:
                case 'on':
                    this.checked = true;
                    break;
                case false:
                case 'off':
                    this.checked = false;
                    break;
                case 'toggle':
                    this.checked = !this.checked;
                    break;
            }
        });
    };

    jQuery.fn.checked = function () {

        return this.attr("checked") == true;
    };
}
String.prototype.first = function () {
    if (this.length > 0) {
        return this.charAt(0);
    }
    return "";
}


function phoneNumber(areaCode, number, extension, type) {
    //    this.areaCode = areaCode;
    this.number = number;
    this.extension = extension;
    this.type = type;
}
phoneNumber.prototype.setPhoneNumber = function (phone) {
    if (phone != null) {
        //        this.areaCode.value = phone.AreaCode;
        this.number.value = "(" + phone.AreaCode + ")" + phone.Number;
        this.extension.value = phone.Extension;
    }
    else {
        //        this.areaCode.value = '';
        this.number.value = '';
        this.extension.value = '';
    }

}
phoneNumber.prototype.getPhoneNumber = function () {

    if (this.areaCode == null) {
        if (this.number.value != "(___)___-____") {
            var pNum = new Cutter.Domain.PhoneNumber();
            pNum.AreaCode = this.number.value.substr(1, 3);
            pNum.Number = this.number.value.substr(5);
            pNum.Extension = this.extension.value;
            pNum.PhoneNumberType = this.type.value;
            return pNum;

        }


    }
    else if (this.number.value != "___-____") {
        var pNum = new Cutter.Domain.PhoneNumber();
        pNum.AreaCode = this.areaCode.value;
        pNum.Number = this.number.value;
        pNum.Extension = this.extension.value;
        pNum.Type = this.type;
        return pNum;
    }

    return null;

}

phoneNumber.prototype.setType = function(type){
    this.type.value = type;
};

function openDialog(page, name, height, width) {

    var wLimit = 900;

    _height = height || 680;
    _width = width || ((window.screen.availHeight * 0.8) > wLimit) ? window.screen.availHeight * 0.8 : wLimit; ;

    var _top = (window.screen.availHeight - _height) / 2;
    var _left = (window.screen.availWidth - _width) / 2;
    window.open(page, name, "resizable=yes,height=" + _height + ",width=" + _width + ",toolbar=yes,top=" + _top + ",left=" + _left);

}
//This was in bid details but was copied into walktrhough. We should check to see if we can use the openDialog function instead
function launchDialog(page, windowTitle, height) {
    windowTitle = windowTitle || "giddyUpTools";

    if (!page.startsWith("/")) {
        page = "./" + page;
    }
    var hLimit = 680;
    var wLimit = 900;
    
    var _height = 680;
    if(height){
        _height = height;
    }
    else { _height = 680; }

    var _width = ((window.screen.availHeight * 0.8) > wLimit) ? window.screen.availHeight * 0.8 : wLimit;
    var _top = (window.screen.availHeight - _height) / 2;
    var _left = (window.screen.availWidth - _width) / 2;
    window.open(page, windowTitle, "resizable=yes,height=" + _height + ",width=" + _width + ",toolbar=yes,top=" + _top + ",left=" + _left);

}


var openedWindows = [];
var enableToolbar = 'yes';
function SetupAssets() {
    var hLimit = 680;
    var wLimit = 900;
    var _height = 680;
    var _width = ((window.screen.availHeight * 0.8) > wLimit) ? window.screen.availHeight * 0.8 : wLimit;
    var _top = (window.screen.availHeight - _height) / 2;
    var _left = (window.screen.availWidth - _width) / 2;
    openedWindows["Setup"] = window.open("./Setup/GeneralSetup.aspx", "GeneralSetup", "resizable=yes,height=" + _height + ",width=" + _width + ",toolbar=" + enableToolbar + ",top=" + _top + ",left=" + _left);
}

function LaunchSetup(page) {

    var wLimit = 925;
    var _height = 750;
    var _width = ((window.screen.availHeight * 0.8) > wLimit) ? window.screen.availHeight * 0.8 : wLimit;
    var _top = (window.screen.availHeight - _height) / 2;
    var _left = (window.screen.availWidth - _width) / 2;
    openedWindows["Setup"] = window.open("/Setup/" + page, "GeneralSetup", "resizable=yes,height=" + _height + ",width=" + _width + ",toolbar=" + enableToolbar + ",top=" + _top + ",left=" + _left);
}
(function () {

    this.ObjUtil = {};

    // Methods to determine the type of an object.
    ObjUtil.isObject = function (obj) { return Object.prototype.toString.call(obj) === "[object Object]"; };
    ObjUtil.isString = function (obj) { return Object.prototype.toString.call(obj) === "[object String]"; };
    ObjUtil.isNumber = function (obj) { return Object.prototype.toString.call(obj) === "[object Number]"; };
    ObjUtil.isBoolean = function (obj) { return Object.prototype.toString.call(obj) === "[object Boolean]"; };
    ObjUtil.isArray = function (obj) { return Object.prototype.toString.call(obj) === "[object Array]"; };
    ObjUtil.isFunction = function (obj) { return Object.prototype.toString.call(obj) === "[object Function]"; };
    ObjUtil.isDate = function (obj) { return Object.prototype.toString.call(obj) === "[object Date]"; };
    ObjUtil.isRegExp = function (obj) { return Object.prototype.toString.call(obj) === "[object RegExp]"; };

    // Allows for creating method overloads, beware of a slight overhead during method call.  
    // Also note that the only differentiator between functions is their numer of arguments.
    // Thanks to John Resig for the inspiration for this method.
    ObjUtil.addOverload = function (obj, name, func) {
        var old = obj[name];
        obj[name] = function () {
            if (func.length == arguments.length) {
                return func.apply(obj, arguments);
            } else if (typeof old == "function") {
                return old.apply(obj, arguments);
            }
        };
    };

    // A generic comparison operator, to maintain lexicographical order strings are cast 
    // to lower case.
    ObjUtil.compareTo = function (a, b) {
        if (ObjUtil.isString(a)) { a = a.toLowerCase(); }
        if (ObjUtil.isString(b)) { b = b.toLowerCase(); }
        if (a < b) { return -1; }
        if (a > b) { return 1; }
        return 0;
    };

    // A generic memoizer function to help with heavy recursion.
    // Ex: var fibonacci = ObjUtil.memo(function (recur, n) { 
    // return recur(n - 1) + recur(n - 2); }, {"0":0, "1":1});
    ObjUtil.memo = function (func, seed) {
        var cache = seed || {};
        var shell = function (arg) {
            if (!(arg in cache)) {
                cache[arg] = func(shell, arg);
            }
            return cache[arg];
        };
        return shell;
    };

    // Shameless theft of the jQuery.extend method, but it's useful to have it here as well so as
    // not to incur too many dependencies (i.e. things relying on jQuery and extensions.js)
    ObjUtil.merge = function () {
        var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;

        if (typeof target === "boolean") {
            deep = target;
            target = arguments[1] || {};
            i = 2;
        }

        if (typeof target !== "object" && !jQuery.isFunction(target)) {
            target = {};
        }

        if (length == i) {
            target = this;
            --i;
        }

        for (; i < length; i++)
            if ((options = arguments[i]) != null)
                for (var name in options) {
                    var src = target[name], copy = options[name];

                    if (target === copy) { continue; }

                    if (deep && copy && typeof copy === "object" && !copy.nodeType) {
                        target[name] = jQuery.extend(deep,
                            src || (copy.length != null ? [] : {})
                        , copy);
                    } else if (copy !== undefined) {
                        target[name] = copy;
                    }
                }

return target;
};

// Gives us partial functions with currying.  Inspired by Oliver Steele's Functional.js library.
// Parameters to be supplied by the curried function use 'undefined' as a placeholder in the
// defining function.  Ex: var test = someFunction(a, undefined, c) { }; test(b);
if (!Function.partial) {
    Function.prototype.partial = function () {
        var fn = this;
        var args = Array.prototype.slice.call(arguments);
        return function () {
            var arg = 0;
            for (var i = 0; i < args.length && arg < arguments.length; i++) {
                if (args[i] === undefined) {
                    args[i] = arguments[arg++];
                }
            }
            return fn.apply(this, args);
        };
    };
}

// Converts strings to boolean values
if (!String.toBoolean) {
    String.prototype.toBoolean = function () {
        return this.toLowerCase() == "true" || this == "1";
    };
}

// Replaces all instance of 'val' within a string and returns a new string.  The native 
// String.replace method only replaces the first instance of the match.  Unfortunately 
// you cannot assign to 'this' within a prototype so we have to return a new instance 
// of the string.
if (!String.replaceAll) {
    String.prototype.getReplaced = function (val, rep) {
        var s = this.replace(new RegExp(val, "g"), rep);
        return s;
    };
}

// Removes white space from the beginning and end of a string
if (!String.trim) {
    String.prototype.trim = function () {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    };
}

// Copies all items within an array to a new array and returns the new array.  
// If the array contains comlex types then the new array will contain references 
// to the old array.
if (!Array.copy) {
    Array.prototype.copy = function () {
        var c = [];
        this.forEach(function (i) { c.push(i); });
        return c;
    };
}

// Wraps a for loop around an array and passes each item in the loop to the 
// supplied function and calls it.
//    if (!Array.forEach) {
Array.prototype.forEach = function (func) {
    for (var i in this) { if (this.hasOwnProperty(i)) { func(this[i]); } }
};
//    }

// Returns the object matching the criteria function.  Note that the 'func' parameter 
// here must be a function that returns a boolean.
if (!Array.find) {
    Array.prototype.find = function (func) {
        for (var i in this) { if (func(this[i])) { return this[i]; } }
        return null;
    };
}

// Returns an array of objects matching the criteria function.  Note that the 'func' 
// parameter here must be a function that returns a boolean.
if (!Array.findAll) {
    Array.prototype.findAll = function (func) {
        var items = [];
        this.forEach(function (i) { if (!ObjUtil.isFunction(i)) { if (func(i)) { items.push(i); } } });
        return items;
    };
}

// Returns a boolean indicating that the item exists in the array.  If a criteria function is
// passed in it tests each item against the function.
if (!Array.contains) {
    Array.prototype.contains = function (clause) {
        for (var i in this) { if (this[i] == clause) { return true; } }
        return false;
    };
}

// Returns a new array of distinct items from the original array.
if (!Array.distinct) {
    Array.prototype.distinct = function () {
        var items = [];
        this.forEach(function (i) { if (!items.contains(i)) { items.push(i); } });
        return items;
    };
}

// Returns the minimum item in the array including strings.  If the first item is a number it
// is assumed that the entire array is made up of numbers, likewise for strings.
if (!Array.min) {
    Array.prototype.min = function () {
        if (this.length > 0) {
            if (ObjUtil.isNumber(this[0])) { //Assume its an array of numbers
                return Math.min.apply(Math, this);
            } else if (ObjUtil.isString(this[0])) {
                var temp = this.copy();
                temp.sortAscending();
                return temp[0];
            }
        }
        return null;
    };
}

// Returns the maximum item in the array including strings.  If the first item is a number it
// is assumed that the entire array is made up of numbers, likewise for strings.
if (!Array.max) {
    Array.prototype.max = function () {
        if (this.length > 0) {
            if (ObjUtil.isNumber(this[0])) { //Assume its an array of numbers
                return Math.max.apply(Math, this);
            } else {
                var temp = this.copy();
                temp.sortDescending();
                return temp[0];
            }
        }
        return null;
    };
}

// Returns the first item in the array.
if (!Array.first) {
    Array.prototype.first = function () {
        return this.length > 0 ? this[0] : null;
    };
}

// Retunrs the last item in the array;
if (!Array.last) {
    Array.prototype.last = function () {
        return this.length > 0 ? this[this.length - 1] : null;
    };
}

// Sorts the array in ascending order using the Array.compareTo method.
if (!Array.sortAscending) {
    Array.prototype.sortAscending = function () {
        this.sort(function (a, b) { return ObjUtil.compareTo(a, b); });
    };
}

// Sorts the array in descending order using the Array.compareTo method.
if (!Array.sortDescending) {
    Array.prototype.sortDescending = function () {
        this.sort(function (a, b) { return ObjUtil.compareTo(b, a); });
    };
}

// Sorts the array in a random order.
if (!Array.randomize) {
    Array.prototype.randomize = function () {
        this.sort(function () { return 0.5 - Math.random(); });
    };
}

// Returns the length of the array or a count of the items matching a criteria function.
if (!Array.count) {
    Array.prototype.count = function (func) {
        return func == null ? this.length : this.findAll(func).length;
    };
}

// Returns an array containing the delta items of two arrays.
if (!Array.except) {
    Array.prototype.except = function (arr) {
        var items = [];
        var me = this;
        this.forEach(function (i) {
            if (!ObjUtil.isFunction(i)) {
                if (!arr.contains(i)) { items.push(i); }
            }
        });
        arr.forEach(function (i) {
            if (!ObjUtil.isFunction(i)) {
                if (!me.contains(i)) { items.push(i); }
            }
        });
        return items;
    };
}

// Returns an array containing the overlapping items of two arrays.
if (!Array.intersect) {
    Array.prototype.intersect = function (arr) {
        var items = [];
        this.forEach(function (i) {
            if (!ObjUtil.isFunction(i)) {
                if (arr.contains(i)) { items.push(i); }
            }
        });
        return items;
    };
}

// Returns the average of the numbers in a numeric array.
if (!Array.average) {
    Array.prototype.average = function () {
        return this.length > 0 ? this.sum() / this.length : null;
    };
}

// Returns the sum of the numbers in a numeric array.
if (!Array.sum) {
    Array.prototype.sum = function () {
        var sum = 0;
        this.forEach(function (i) { if (ObjUtil.isNumber(i)) { sum += i; } });
        return sum;
    };
}

// Returns a new array combining two others but excluding duplicates.
if (!Array.union) {
    Array.prototype.union = function (arr) {
        var items = [];
        this.forEach(function (i) { items.push(i); });
        arr.forEach(function (i) { items.push(i); });
        return items.distinct();
    };
}

// Adds an item to an array but only if that item doesn't already exist in the array.
if (!Array.safePush) {
    Array.prototype.safePush = function (value) {
        if (!this.contains(value)) { this.push(value); }
    };
}

// Returns a random item from the array.
if (!Array.getRandom) {
    Array.prototype.getRandom = function () {
        return this[Math.floor(Math.random() * this.length)];
    };
}

// Inserts an item into the array at a specific index.
if (!Array.insertAt) {
    Array.prototype.insertAt = function (pos, val) {
        if (pos > -1 && pos < this.length) { this.splice(pos, 0, val); }
        return false;
    };
}

// Removes all items from the array that match the supplied criteria function.
if (!Array.remove) {
    Array.prototype.remove = function (func) {
        for (var i in this) {
            if (func(this[i])) {
                var b = this.slice(0, i);
                var e = this.slice(i + 1, this.length);
                this.length = 0;
                this.push.apply(this, b);
                this.push.apply(this, e);
            }
        }
    };
}

// Returns the index of a specific element in an array.
if (!Array.indexOf) {
    Array.prototype.indexOf = function (val) {
        for (var i in this) { if (this[i] == val) { return i; } }
        return -1; // Indicate that the item was not found.
    };
}
})();

var Observer = function () {
    this.observations = [];

};

var Observation = function (name, func) {
    this.name = name;
    this.func = func;
};

Observer.prototype = {
    observe: function (name, func) {

        var exists = this.observations.findAll(function (i) {
            return i.name == name && i.func == func;
        }).length > 0;
        if (!exists) { this.observations.push(new Observation(name, func)); }
    },
    unobserve: function (name, func) {
        this.observations.remove(function (i) {
            return i.name == name && i.func == func;
        });
    },
    fire: function (name, data, scope) {
        var funcs = this.observations.findAll(function (i) {
            return i.name == name;
        });
        funcs.forEach(function (i) { i.func.call(scope || window, data); });
    }
};

function ShowPopup(pos, hoveritem) {
    hp = document.getElementById(hoveritem);

    //// Set position of hover-over popup
    hp.style.top = pos.offsetTop + 180;
    hp.style.left = pos.offsetLeft + 200;

    // Set popup to visible
    hp.style.display = "block";
}

function HidePopup(hoveritem) {
    hp = document.getElementById(hoveritem);
    hp.style.display = "none";
}



Date.prototype.AddDays = function (days) {
    var d=new Date(this);
    d.setDate(d.getDate() + days);
    return d;
}

Date.prototype.AddHours = function (hours) {
    var d=new Date(this);
    d.setHours(d.getHours() + hours);
    return d;
}

Date.prototype.AddMilliseconds = function (milliseconds) {
    var d=new Date(this);
    d.setMilliseconds(d.getMilliseconds() + milliseconds);
    return d;
}

Date.prototype.AddMinutes = function (minutes) {
    var d=new Date(this);
    d.setMinutes(d.getMinutes() + minutes, d.getSeconds(), d.getMilliseconds());
    return d;
}

Date.prototype.AddMonths = function (months) {
    var d=new Date(this);
    d.setMonth(d.getMonth() + months, d.getDate());
    return d;
}

Date.prototype.AddSeconds = function (seconds) {
    var d=new Date(this);
    d.setSeconds(d.getSeconds() + seconds, d.getMilliseconds());
    return d;
}

Date.prototype.AddYears = function (years) {
    var d = new Date(this)
    d.setFullYear(d.getFullYear() + years);
    return d;
}

Date.prototype.GetStartOfWeek = function () {
    var d = new Date(this)
    d=d.AddDays(d.getDay() * -1);
    return d._nullOutTime();

}
Date.prototype.GetEndOfWeek = function () {
    var d = new Date(this)
    d=d.AddDays(6 - d.getDay());
    return d._nullOutTime();

}


Date.prototype._nullOutTime = function () {

    this.setHours(0);
    this.setMilliseconds(0);
    this.setMinutes(0);
    this.setSeconds(0);

    return this;

}

Date.prototype.GetLastDayOfMonth = function () {

    var d = new Date(this);


    d=d.AddMonths(1).AddDays((d.getDate() * -1));


    return d._nullOutTime();


}

Date.prototype.GetFirstDayOfMonth = function () {
    var d = new Date(this);
    d=d.AddDays(d.getDate() * -1 + 1);
    return d._nullOutTime();
}

Expressions = function () {

    //    this.numRegEx = /^[-+]?(?:\d*|\d{1,3}(?:,\d{3})*)(?:\.\d+)?$/;

    //    return new Expressions.Impl();

}

Expressions.Numeric = /^[-+]?(?:\d*|\d{1,3}(?:,\d{3})*)(?:\.\d+)?$/;


window.setInterval(checkIfSessionStillValid, 120000);
var sessionValidErrorCount = 0;
function checkIfSessionStillValid() {


    function checkSessionSuccess(rst) {
        if (!rst.IsValid) {

            var url;
            if (rst.Reason==Cutter.Web.Bid.Services.CheckSessionResponseType.DuplicateUser)
            {
                url="/Errors/DuplicatedSession.aspx";
            }
            else
            {
                url="/Errors/ForceLogOff.aspx";
            }
            for (i in openedWindows) {
                try {
                    openedWindows[i].location.replace(url);
                }
                catch (e) { }
            }
            window.location.replace(url);
        }
    }
    function checkSessionFailed() {

        sessionValidErrorCount++;
        if (sessionValidErrorCount > 10) {
            alert("We have been unable to contact the server. Please logout and try again later");
        }
    }

    //This prevents this from running on multiple pages at same time.
    if (window.parent != null && !window.parent.closed && window.parent.checkIfSessionStillValid && window.parent!=window) {
        return;
    }
    if(typeof (Utilities)!=='undefined')
    {
        Utilities.CheckIfSessionStillValid(checkSessionSuccess, checkSessionFailed);
    }


  

}
    function closeIframe(dialog) {
        dialog.set_contentUrl("about:blank");
        dialog.close();
        $("body").css("margin-right", "8px");
    }

  function showSavingToast(options) {
        if ($("#savingToast").length==0)
        {
            //alert("HERE");
            $("body").append("<div id='savingToast'></div>");
        }

        //$("body").append("<div id='savingToast'></div>")
        //.find("#savingToast")
        $("#savingToast")
        .html(options.text).fadeIn("slow", function () {
            $("#savingToast").fadeOut(2200, function () {
                //$("#contactSaved").hide();
                if (typeof options.callBack=="function")
                {
                    if (options.callBack) { options.callBack(); };
                }
                $(this).remove();
            });
        });
//        debugger;
//        $("#savingToast").html(options.text);
//        $("#savingToast")
    }    



    function ClipBoard(elemToCopy) 
    {
        Copied = elemToCopy.createTextRange();
        Copied.execCommand("Copy");
        Copied.execCommand("RemoveFormat");
        Copied.execCommand("Copy");
    }
 



    /*
    options.text= Inner Content
    options.title= title bar
    options.ok = ok callback function
    */
    function showAlertBox(options) 
    {
        if ($("#alertBox").length==0)
        {
            $("body").append("<div id='alertBox' style='background:white;'><div class='header' style='height:25px; font-size:12px;'></div><div id='alertBoxContent' style='background:white; color:#333'></div><div style='width:75px; margin-left:auto; margin-bottom:10px; margin-right:auto;'><input type='button' class='button' value='Ok'></div></div>");
        }

        var abox=$("#alertBox");

        abox.fadeIn("slow", function () {
            $("#alertBox input").click(function () {
                $("#alertBox").fadeOut("slow",function(){
                 $(this).remove();
                 if (options.ok){options.ok();}
                });
            });
        }).children("#alertBoxContent").html(options.text);
        abox.children(".header").html("<span style='position:relative; top:3px; text-indent:3px;'>" + options.title + "</span>");
//        debugger;
        //$("#savingToast").html(options.text);
//        $("#savingToast")
    }
    
    function showConfirmBox(options){
        if ($("#confirmBox").length==0)
        {
            $("body").append("<div id='confirmBox' style='background:white;'><div class='header' style='height:25px; font-size:12px;'></div><div id='confirmBoxContent' style='background:white; color:#333'></div><div style='width:154px; margin-left:auto; margin-bottom:10px; margin-right:auto;'><input type='button' style='margin-right:4px;' class='button confirmBoxYes' value='Yes'><input type='button' class='button confirmBoxNo' value='No' /></div></div>");
        }

        var cbox=$("#confirmBox");

        cbox.fadeIn("fast", function () {
            $(".confirmBoxYes").click(function () {
                $("#confirmBox").fadeOut("fast",function(){
                 $(this).remove();
                 if (options.yes){options.yes();}
                });
            });
            $(".confirmBoxNo").click(function () {
                $("#confirmBox").fadeOut("fast",function(){
                 $(this).remove();
                 if (options.no){options.no();}
                });
            });
        }).children("#confirmBoxContent").html(options.text);
        cbox.children(".header").html("<span style='position:relative; top:3px; text-indent:3px;'>" + options.title + "</span>");
    }    




if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

