﻿/// <reference path="jquery-1.3.2-vsdoc2.js"/>

//function htmlOuput() {
//    $('body').append('<textarea style="width:900px; height:900px;">' + $('html').html() + '<\/textarea>')
//}

/*--------------------------------------------------------------------------------------------------*/
/*--[ JQUERY ]--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------*/
if (typeof $ !== "undefined") {

    // Extending jQuery with Custom Selector Filters
    //$.expr[":"].startsWith = function(el, i, m) {
    //    var search = m[3];
    //    if (!search) return false;
    //    return eval("/^[/s]*" + search + "/i").test($(el).text());
    //};

    //$.expr[":"].containsNoCase = function(el, i, m) {
    //    var search = m[3];
    //    if (!search) return false;
    //    return eval("/" + search + "/i").test($(el).text());
    //};
    
    /*--------------------------------------------------------------------------------------------------*/

    $.fn.extend({
        /*--------------------------------------------------------------------------------------------------*/
        // $('#tableID tr:not(.head)').overs(); -> default color = '#e5e5e5'
        // $('#tableID tr:not(.head)').overs('#e5e5e5');
        overs: function(color) {
            color = color == undefined ? '#e5e5e5' : color;
            return this
                .hover(
                    function() { $(this).css('backgroundColor', color); },
                    function() { $(this).css('backgroundColor', ''); }
                );
        },
        /*--------------------------------------------------------------------------------------------------*/
        // $('#tableID tr:not(.head)').zebra(); -> default every = 1
        // $('#tableID tr:not(.head)').zebra(every); -> default oddClass = "odd" -> default evenClass = "even" 
        // $('#tableID tr:not(.head)').zebra(every, "odd", "even");
        zebra: function(every, oddClass, evenClass) {
            every = every == undefined ? 1 : every;
            oddClass = oddClass == undefined ? "odd" : oddClass;
            evenClass = evenClass == undefined ? "even" : evenClass;
            var odd = true;

            return this
                .removeClass(oddClass)
                .removeClass(evenClass)
                .each(function(index) {
                    odd = (index % (every * 2)) > (every - 1);
                    $(this)
                        .removeClass(odd ? evenClass : oddClass)
                        .addClass(odd ? oddClass : evenClass);
                });
        }
        /*--------------------------------------------------------------------------------------------------*/
    });

        function $alternateRow(selector, every) {
            $(selector).zebra(every); //, "odd", "even"
        };
        
    /*--------------------------------------------------------------------------------------------------*/

    // Extending jQuery with a KeepAlive method
    // simply call $.keepAlive('/page.aspx', (10 * 60000));
    $.keepAlive = function(url, interval) {
        setTimeout(function() { $keepAlive(url, interval) }, interval);
    };

        // use only if a call should be done immediatly else use $.keepAlive
        function $keepAlive(url, interval) {
            setTimeout(function() { $keepAlive(url, interval) }, interval);
            $.get(url);
        };

//    /*--------------------------------------------------------------------------------------------------*/
//    /*--[ Javascript DEBUG appender ]-------------------------------------------------------------------*/
//    /*--------------------------------------------------------------------------------------------------*/
//    $(function() {
//        if (document.location.toString().toLowerCase().indexOf('xhedradebug') > -1) {
//            if ($('#outputConsole').size() == 0) {
//                $('body').append('<a onclick=\"$(\'#outputConsole\').toggle();\" style=\"cursor:pointer;\">Toggle Console</a> | <a onclick=\"$(\'#outputConsole\').text($(\'html\').html()).css(\'display\', \'block\');\" style=\"cursor:pointer;\">Refesh</a><br /><textarea id=\"outputConsole\" style=\"width:100%;height:300px;display:none;\"></textarea>');
//            }
//        }
//    });

    /*--------------------------------------------------------------------------------------------------*/
    /*--[ UTILS ]---------------------------------------------------------------------------------------*/
    /*--------------------------------------------------------------------------------------------------*/
    function tabToggle(id) {
        $('#tabs>li').removeClass('active');
        $('#divs>div').hide();
        $('#' + id).show();
    }

    function tabToggleWithViewAll(id) {
        $('#tabs>li').removeClass('active');
        $('#divs>div').hide();
        $('#tabViewAll').attr('rel', '0');
        $('#' + id).show();
    }

    function pwdCompare(ctrlID1, ctrlID2) {
        var pwd1 = $('#' + ctrlID1).val();
        var pwd2 = $('#' + ctrlID2).val();

        if (pwd1 != '' && pwd2 == '') {
            $('#' + ctrlID2).addClass('cValError');
            return true;
        }

        return (pwd1 == pwd2);
    }

    function pwdMatch(ctrlID1, ctrlID2) {
        var pwd1 = $('#' + ctrlID1).val();
        var pwd2 = $('#' + ctrlID2).val();

        return (pwd1 == pwd2);
    }

    function pnlCollapsibleToggle(ctrl) {
        var src = $(ctrl).attr('src');
        $(ctrl).attr('src',
            (src.indexOf('-down') > -1
                ? src.replace('-down', '-up')
                : src.replace('-up', '-down')
            )
        );
    }

//    function ddlMasterBindChild(ashxUrl, ddlMasterID, ddlChildID, loaderID) {
//        $('#' + ddlMasterID)
//            .change(function() {
//                var loader = null;
//                if ($('#' + loaderID) != null) {
//                    loader = $('#' + loaderID);
//                    loader.show();
//                }
//                $.getJSON(ashxUrl + $('#' + ddlMasterID).val(), {},
//                    function(result) {
//                        $('#' + ddlChildID).removeOption(/./).addOption(result, false);
//                        if (loader != null) {
//                            loader.hide();
//                        }
//                    }
//                );
//            });
//    }

//    function ddlCountryBind(ashxUrl, ddlCountryID, ddlProvinceID, txtPostalCodeID, loaderID) {
//        $('#' + ddlCountryID)
//            .change(function() {
//                $('#' + loaderID).show();
//                $.getJSON(ashxUrl + $('#' + ddlCountryID).val(), {},
//                    function(result) {
//                        $('#' + ddlProvinceID).removeOption(/./).addOption(result, false);

//                        var code = $('#' + txtPostalCodeID);
//                        
//                        if ($('#' + ddlCountryID).val() == 2) {
//                            code.removeClass('jValPostalCodeCA').addClass('jValPostalCodeUS');
//                        }
//                        else {
//                            code.removeClass('jValPostalCodeUS').addClass('jValPostalCodeCA');
//                        }
//                        code.unbind();

//                        jValBind('#' + txtPostalCodeID);

//                        $('#' + loaderID).hide();
//                    }
//                );
//            });
//    }
}

/*--------------------------------------------------------------------------------------------------*/
/*--[ GLOBAL ]--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------*/

//// Toggle dropdown enabled property based on a checkbox value
//function ddlEnabledToggle(chk, ddl) {
//    if (chk.checked) {
//        ddl.selectedIndex = 0;
//        ddl.disabled = true;
//    }
//    else {
//        ddl.disabled = false;
//        ddl.selectedIndex = 0;
//    }
//}

function findPos(obj) {
    var curleft = curtop = 0;

    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;

        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}

//function toDecimalOrEmpty(obj) {
//    var val = parseFloat(obj.value);

//    if (isNaN(val)) {
//        obj.value = '';
//    }
//    else {
//        obj.value = val.toFixed(2);
//    }
//}

function blockNonNumbers(obj, e, allowDecimal, allowNegative) {
    var key;
    var isCtrl = false;
    var keychar;
    var reg;

    if (window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if (e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }

    if (isNaN(key)) return true;

    keychar = String.fromCharCode(key);

    // check for backspace or delete, or if Ctrl was pressed
    if (key == 8 || isCtrl) {
        return true;
    }

    reg = /\d/;
    var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
    var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;

    return isFirstN || isFirstD || reg.test(keychar);
}

/*--------------------------------------------------------------------------------------------------*/
// Time method
/*--------------------------------------------------------------------------------------------------*/
// Adds the specified time to the value of this instance.
function TimePlus(time1, time2)
{
    time1 += time2;

    if ((time1 % 100) >= 60)
    {
        // Remove 60min to add 1 hour (100)
        time1 = (time1 - 60) + 100;
    }
    return time1;
}

// Create a new instance composed of the value of this instance minus a specified time value.
function TimeDiff(time1, time2)
{
    var newTime = time1;

    if ((newTime % 100) < (time2 % 100)) {
        // Here are missing minutes to substract so convert 1 hour into 60 min
        newTime = (newTime - 100) + 60;
    }

    newTime = newTime - time2;

    return newTime;
}

// Removes the specified time to the value of this instance.
function TimeMinus(time1, time2) 
{
    if ((time % 100) < (timeValue % 100)) {
        // Here are missing minutes to substract so convert 1 hour into 60 min
        time = (time - 100) + 60;
    }
    
    time1 -= time2;

    return time1;
}

///*--------------------------------------------------------------------------------------------------*/
//// Static data
///*--------------------------------------------------------------------------------------------------*/
////<![CDATA[
//var workTimeOptions = {
//    "0": "00:00", "15": "00:15", "30": "00:30", "45": "00:45", "100": "01:00", "115": "01:15", "130": "01:30", "145": "01:45",
//    "200": "02:00", "215": "02:15", "230": "02:30", "245": "02:45", "300": "03:00", "315": "03:15", "330": "03:30", "345": "03:45",
//    "400": "04:00", "415": "04:15", "430": "04:30", "445": "04:45", "500": "05:00", "515": "05:15", "530": "05:30", "545": "05:45",
//    "600": "06:00", "615": "06:15", "630": "06:30", "645": "06:45", "700": "07:00", "715": "07:15", "730": "07:30", "745": "07:45",
//    "800": "08:00", "815": "08:15", "830": "08:30", "845": "08:45", "900": "09:00", "915": "09:15", "930": "09:30", "945": "09:45",
//    "1000": "10:00", "1015": "10:15", "1030": "10:30", "1045": "10:45", "1100": "11:00", "1115": "11:15", "1130": "11:30", "1145": "11:45",
//    "1200": "12:00", "1215": "12:15", "1230": "12:30", "1245": "12:45", "1300": "13:00", "1315": "13:15", "1330": "13:30", "1345": "13:45",
//    "1400": "14:00", "1415": "14:15", "1430": "14:30", "1445": "14:45", "1500": "15:00", "1515": "15:15", "1530": "15:30", "1545": "15:45",
//    "1600": "16:00", "1615": "16:15", "1630": "16:30", "1645": "16:45", "1700": "17:00", "1715": "17:15", "1730": "17:30", "1745": "17:45",
//    "1800": "18:00", "1815": "18:15", "1830": "18:30", "1845": "18:45", "1900": "19:00", "1915": "19:15", "1930": "19:30", "1945": "19:45",
//    "2000": "20:00", "2015": "20:15", "2030": "20:30", "2045": "20:45", "2100": "21:00", "2115": "21:15", "2130": "21:30", "2145": "21:45",
//    "2200": "22:00", "2215": "22:15", "2230": "22:30", "2245": "22:45", "2300": "23:00", "2315": "23:15", "2330": "23:30", "2345": "23:45",
//    "2400": "24:00"
//};
////]]>

////<![CDATA[
//var workTimeOptionsWithoutZero = {
//    "15": "00:15", "30": "00:30", "45": "00:45", "100": "01:00", "115": "01:15", "130": "01:30", "145": "01:45",
//    "200": "02:00", "215": "02:15", "230": "02:30", "245": "02:45", "300": "03:00", "315": "03:15", "330": "03:30", "345": "03:45",
//    "400": "04:00", "415": "04:15", "430": "04:30", "445": "04:45", "500": "05:00", "515": "05:15", "530": "05:30", "545": "05:45",
//    "600": "06:00", "615": "06:15", "630": "06:30", "645": "06:45", "700": "07:00", "715": "07:15", "730": "07:30", "745": "07:45",
//    "800": "08:00", "815": "08:15", "830": "08:30", "845": "08:45", "900": "09:00", "915": "09:15", "930": "09:30", "945": "09:45",
//    "1000": "10:00", "1015": "10:15", "1030": "10:30", "1045": "10:45", "1100": "11:00", "1115": "11:15", "1130": "11:30", "1145": "11:45",
//    "1200": "12:00", "1215": "12:15", "1230": "12:30", "1245": "12:45", "1300": "13:00", "1315": "13:15", "1330": "13:30", "1345": "13:45",
//    "1400": "14:00", "1415": "14:15", "1430": "14:30", "1445": "14:45", "1500": "15:00", "1515": "15:15", "1530": "15:30", "1545": "15:45",
//    "1600": "16:00", "1615": "16:15", "1630": "16:30", "1645": "16:45", "1700": "17:00", "1715": "17:15", "1730": "17:30", "1745": "17:45",
//    "1800": "18:00", "1815": "18:15", "1830": "18:30", "1845": "18:45", "1900": "19:00", "1915": "19:15", "1930": "19:30", "1945": "19:45",
//    "2000": "20:00", "2015": "20:15", "2030": "20:30", "2045": "20:45", "2100": "21:00", "2115": "21:15", "2130": "21:30", "2145": "21:45",
//    "2200": "22:00", "2215": "22:15", "2230": "22:30", "2245": "22:45", "2300": "23:00", "2315": "23:15", "2330": "23:30", "2345": "23:45",
//    "2400": "24:00"
//};
////]]>


/*--------------------------------------------------------------------------------------------------*/
// String Prototype
/*--------------------------------------------------------------------------------------------------*/

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
String.prototype.ltrim = function() { return this.replace(/^\s+/, ''); };
String.prototype.rtrim = function() { return this.replace(/\s+$/, ''); };
/////////////////////////////////
String.prototype.contains = function(pattern) { return this.indexOf(pattern) > -1; };
String.prototype.startsWith = function(pattern) { return this.indexOf(pattern) == 0; };
String.prototype.endsWith = function(pattern) 
{
    if (this.lastIndexOf(pattern) != -1) {
        return this.lastIndexOf(pattern) == (this.length - pattern.length);
    }
    return false;
};
/////////////////////////////////
String.prototype.isEmail = function() { return (/^([a-zA-Z0-9_.\-+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/).test(this); };
String.prototype.isPhone = function() { return ((/^1?[\-\ \.]?\(?[1-9]\d{2}\)?[\-\ \.]?\d{3}[\-\ \.]?\d{4}$/).test(this)); };
String.prototype.isPhoneExt = function() { return ((/^1?[\-\ \.]?\(?[1-9]\d{2}\)?[\-\ \.]?\d{3}[\-\ \.]?\d{4}[\-\ \.]?[\#\.]?[\d]?[\d]?[\d]?[\d]?$/).test(this)); };
String.prototype.isCAPostalCode = function() {
    if (this.length == 6 || this.length == 7)
        return (/^[a-zA-Z]\d[a-zA-Z] ?\d[a-zA-Z]\d$/).test(this);
    return false;
};
String.prototype.isUSPostalCode = function() {
    if (this.length == 5)
        return (/^\d{5}$/).test(this);
    if (this.length == 10)
        return (/^\d{10}$/).test(this);
    return false;
};

/////////////////////////////////
String.prototype.nl2br = function() { return this.replace(/\n/gi, "<br />"); };
/////////////////////////////////
String.prototype.format = function() {
    var s = this;
    var c = arguments.length;
    for (var i = 0; i < c; i++) {
        var r = new RegExp('\\{' + (i) + '\\}', 'gm');
        s = s.replace(r, arguments[i]);
    }
    return s;
};
String.prototype.truncate = function(length, suffix) {
    suffix = (typeof (suffix) == "undefined") ? "..." : suffix;
    if (this.length > length) {
        return this.substr(0, length) + suffix;
    }
    return this;
};
/////////////////////////////////

String.prototype.toPhone = function() {
    var phone = this.replace(/[\(\)\.\-\ \#]/g, '');

    if (phone.startsWith('1') && phone.length == 11) {
        phone = phone.substr(1);
    }

    if (phone.length > 10) {
        phone = phone.substr(0, 10);
    }

    return phone.replace(/(...)(...)(....)/g, "($1) $2-$3");
}

//-----------------------------------------------------------------------------------------------
// alert('H1G3Y8'.toCAZipCode());
// alert('H1G 3Y8'.toCAZipCode());
// //return ''
// alert('h1g 3y85'.toCAZipCode());
//-----------------------------------------------------------------------------------------------
String.prototype.toCAZipCode = function() {
    var s = this.toUpperCase().replace(/ /, '');
    var o = '';

    for (var i = 1; i <= s.length; i++) {
        if (i == 4) {
            o += ' ';
        }

        if ((i % 2) == 0) {
            if (isNaN(s.charAt(i - 1)) == false) {
                o += s.charAt(i - 1)
            }
            else return '';
        }
        else {
            if (isNaN(s.charAt(i - 1))) {
                o += s.charAt(i - 1)
            }
            else return '';
        }
    }
    return o;
};

/////////////////////////////////

String.prototype.toNumber = function() {
    var strToTransform = this.toString();
    var sNum;

    if (isNaN("1,1")) {
        sNum = strToTransform.replace(",", ".");
    }
    else {
        sNum = strToTransform.replace(".", ",");
    }

    if (isNaN(sNum)) {
        return 0
    }
    else {
        return Number(sNum)
    }
};

String.prototype.toMoney = function(precision) {
    var s2Trans = this.toString();
    var iNum = s2Trans.toNumber();
    return (iNum.toFixed(precision).toString());
};

String.prototype.toEmail = function() {
    if (this.search(/[0-9|a-z|A-Z|\.]+@[0-9|a-z|A-Z|\-]+\.[0-9|a-z|A-Z|\-]+/) < 0) {
        return ('');
    }
    return (this.replace(/ /gi, ''));
};


/*--------------------------------------------------------------------------------------------------*/
// Int Prototype Special Time Field
/*--------------------------------------------------------------------------------------------------*/
Number.prototype.hour = function() {
    return parseInt(this / 100);
}

Number.prototype.minute = function() {
    return this % 100;
}

Number.prototype.trimMinute = function() {
    return this.hour() * 100;
}

Number.prototype.addHour = function(hourPlus) {
    return this.addTime(hourPlus * 100);
}

Number.prototype.toTimeString = function() {
    return this.hour() + ":" + this.minute();
}

Number.prototype.addTime = function(time) {
    var newTime = this + time;

    if ((newTime % 100) >= 60)
    {
        // Remove 60min to add 1 hour (100)
        newTime = (newTime - 60) + 100;
    }
    return newTime;
}

Number.prototype.removeTime = function(time) {
    //TODO
    var newTime = this + time;

    if ((newTime % 100) >= 60)
    {
        // Remove 60min to add 1 hour (100)
        newTime = (newTime - 60) + 100;
    }
    return newTime;
}

Number.prototype.timeDiff = function(time) {
    var newTime = this;

    if ((newTime % 100) < (time % 100)) {
        // Here are missing minutes to substract so convert 1 hour into 60 min
        newTime = (newTime - 100) + 60;
    }

    newTime = newTime - time;

    return newTime;
}


/*--------------------------------------------------------------------------------------------------*/
// Date Prototype
/*--------------------------------------------------------------------------------------------------*/

Date.prototype.toShortDateString = function() {
    return this.getFullYear() + "\/" + (this.getMonth() + 1) + "\/" + this.getDate();
}

Date.prototype.nextDay = function() {
    var millisecondsPerDay = 1000 * 60 * 60 * 24;
    return new Date(this.setTime(this.getTime() + millisecondsPerDay));
}

Date.prototype.getDayName = function(lang) {
    return (lang == 'fr') ?
                    ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'][this.getDay()] :
                    ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][this.getDay()];
}
Date.prototype.getMonthName = function(lang) {
    return (lang == 'fr') ?
                    ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'][this.getMonth()] :
                    ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][this.getMonth()];
}


/*--------------------------------------------------------------------------------------------------*/
// Array Prototype
/*--------------------------------------------------------------------------------------------------*/

//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(elt /*, from*/) {
        var len = this.length;
        var from = Number(arguments[1]) || 0;
        from = (from < 0)
                ? Math.ceil(from)
                : Math.floor(from);

        if (from < 0)
            from += len;

        for (; from < len; from++) {
            if (from in this && this[from] === elt)
                return from;
        }
        return -1;
    };
}

if (!Array.prototype.getIndexByProperty) {
    Array.prototype.getIndexByProperty = function(prop, val) {
        var len = this.length;
        for (var i = 0; i < len; i++) {
            if (this[i][prop] === val)
                return i;
        }
        return -1;
    };
}

if (!Array.prototype.removeAt) {
    Array.prototype.removeAt = function(i) {
        if (i in this)
            return this.slice(0, i).concat(this.slice(i + 1));
        return this;
    };
}

//if (!Array.prototype.filter) {
//    Array.prototype.filter = function(fun /*, thisp*/) {
//        var len = this.length;
//        if (typeof fun != "function")
//            throw new TypeError();

//        var res = new Array();
//        var thisp = arguments[1];
//        for (var i = 0; i < len; i++) {
//            if (i in this) {
//                var val = this[i]; // in case fun mutates this
//                if (fun.call(thisp, val, i, this))
//                    res.push(val);
//            }
//        }

//        return res;
//    };
//}


/*--------------------------------------------------------------------------------------------------*/
// StringBuilder
/*--------------------------------------------------------------------------------------------------*/

// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
function StringBuilder(value) {
    this.strings = new Array("");
    this.append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function(value) {
    if (value) {
        this.strings.push(value);
    }
}

// Clears the string buffer
StringBuilder.prototype.clear = function() {
    this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function() {
    return this.strings.join("");
}


///*--------------------------------------------------------------------------------------------------*/
//// Yearly Calendar
///*--------------------------------------------------------------------------------------------------*/
//function buildYearlyCalendar(year, firstSelectableDate) {

//    var day = 1;
//    var date = new Date();
//    var dayOfMonth = false;
//    var sb = new StringBuilder();

//    for (var m = 0; m <= 11; m++) {

//        date.setFullYear(year, m, 1);

//        day = date.getDate();

//        sb.append('<div id="month_' + m + '" class="month"><div class="month_header">' + date.getMonthName() + '</div>');

//        for (var w = 0; w <= 5; w++) {

//            sb.append('<div class="week">');

//            for (var d = 0; d <= 6; d++) {

//                dayOfMonth = (date.getMonth() == m) && (date.getDay() == d);

//                if (dayOfMonth) {
//                    sb.append('<div id="day_' + year + '_' + (m + 1) + '_' + date.getDate() + '" class="day_' + (date >= firstSelectableDate ? 'none' : 'disabled') + '">' + day + '</div>');
//                    date = date.nextDay();
//                    day = date.getDate();
//                }
//                else {
//                    sb.append('<div class="day"></div>');
//                }
//            }

//            sb.append('</div>');
//        }

//        sb.append('</div>');
//    }

//    return sb.toString();
//}


///*--------------------------------------------------------------------------------------------------*/
//// Textarea edit in a modal window
///*--------------------------------------------------------------------------------------------------*/
//function tx_Edit(ctl, title, btnCloseText) {
//    var width = $(window).width() - 100;
//    var height = $(window).height() - 150;
//    tb_window({ 
//        width: width, 
//        height: height, 
//        title: title == undefined ? 'Edit' : title,
//        content: '<textarea id="txtEditTextarea" style=\"width:' + (width - 50) + 'px;height:' + (height - 50) + 'px;margin-bottom:10px;\">' + $(ctl).val() + '</textarea>' +
//                 '<input id="btnEditTextareaClose" type="button" class="btn" onclick="$(\'#' + $(ctl).attr('id') + '\').val($(\'#txtEditTextarea\').val());tb_remove();" value="' + (btnCloseText == undefined ? 'Close' : btnCloseText) + '" />'
//    });
//    
//    // Force the paste when clicking outside of the modal
//    $("#TB_overlay").unbind().click(function() { $('#btnEditTextareaClose').click(); });
//    
//    // Quick fix !!!
//    $("#TB_window").css({ marginTop: '-' + parseInt((height / 2) + 35, 10) + 'px' });
//}