﻿function openDiv(obj) {
    if (document.getElementById(obj).style.display == "none") {
        document.getElementById(obj).style.display = "inline";
    }
    else {
        document.getElementById(obj).style.display = "none";
    }
}

function closeDiv(obj) {
    document.getElementById(obj).style.display = "none";
}

function openOnlyDiv(obj) {
    document.getElementById(obj).style.display = "inline";
}


function querySt(qs) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");

    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == qs) {
            return ft[1];
        }
    }
}


function openers(page, title, obj) {
    page = page + "?qsObj=" + obj;
    window.open(page, title, 'toolbar=no, status=yes,scrollbars=yes, resizable=yes, width=750, height=600, top=50, left=50');
}


function openPopup(page, w, h, status, scrollbars, resize) {
    window.open(page, "", "toolbar=no, status=" + status + ",scrollbars=" + scrollbars + ", resizable=" + resize + ", width=" + w + ", height=" + h + ", top=100, left=400");
}

function showContent(page, param) {
    param = escape(param);
    window.open(page + '?CustomeType=1&Param=' + param, "", "toolbar=no, status=no,scrollbars=no, resizable=yes, width=850, height=590, top=100, left=400");
}

function showModulePhotoGallery(page, param) {
    param = escape(param);
    window.open(page + '?CustomeType=1&Param=' + param, "", "toolbar=no, status=yes,scrollbars=yes, resizable=yes, width=700, height=590, top=100, left=400");
}


function getRequest(req, d) {
    d = d || document;
    var begin, end;
    var search = d.location.search;
    req = req + "=";
    if (search) {
        begin = search.indexOf(req);
        if (begin != -1) {
            begin += req.length;
            end = search.indexOf("&", begin);
        }
        if (end == -1) {
            end = search.length;
        }
        if (begin == -1 && end == undefined) {
            return null;
        }
        return unescape(search.substring(begin, end));
    }
    return null;
}

function getRequestFromUrl(req, url, d) {
    d = d || document;
    var begin, end;
    var search = url;
    req = req + "=";
    if (search) {
        begin = search.indexOf(req);
        if (begin != -1) {
            begin += req.length;
            end = search.indexOf("&", begin);
        }
        if (end == -1) {
            end = search.length;
        }
        if (begin == -1 && end == undefined) {
            return null;
        }
        return unescape(search.substring(begin, end));
    }
    return null;
}

Number.prototype.formated = function (decimalPoints, thousandsSep, decimalSep) {
    var val = this + '', re = /^(-?)(\d+)/, x, y;
    if (decimalPoints != null) val = this.toFixed(decimalPoints);
    if (thousandsSep && (x = re.exec(val))) {
        for (var a = x[2].split(''), i = a.length - 3; i > 0; i -= 3) a.splice(i, 0, thousandsSep);
        val = val.replace(re, x[1] + a.join(''));
    }
    if (decimalSep) val = val.replace(/\./, decimalSep);
    return val;
}

if (typeof Number.prototype.toFixed != 'function' || (.9).toFixed() == '0' || (.007).toFixed(2) == '0.00') Number.prototype.toFixed = function (f) {
    if (isNaN(f *= 1) || f < 0 || f > 20) f = 0;
    var s = '', x = this.valueOf(), m = '';
    if (this < 0) { s = '-'; x *= -1; }
    if (x >= Math.pow(10, 21)) m = x.toString();
    else {
        m = Math.round(Math.pow(10, f) * x).toString();
        if (f != 0) {
            var k = m.length;
            if (k <= f) {
                var z = '00000000000000000000'.substring(0, f + 1 - k);
                m = z + m;
                k = f + 1;
            }
            var a = m.substring(0, k - f);
            var b = m.substring(k - f);
            m = a + '.' + b;
        }
    }
    if (m == '0') s = '';
    return s + m;
}



function downloadFile(folder, fileName, fileOriginalName) {
    openPopup('../../FileManagement/FileDownloader.aspx?FileName=' + fileName + '&Folder=' + folder + '&FileOriginalName=' + fileOriginalName, 50, 50, 'no', 'no', 'no');
}


function sendMail(Mail) {
    openPopup('../../Mail/Mail/Compose.aspx?to=' + Mail, 800, 500, 'yes', 'yes', 'yes');
}
