﻿var ok = false;
function detectUploadCmd() {
    var input = document.getElementById("ctl00_cBody_Uploader_uploadfile0");
    if (input == null) {
        input = document.getElementById("uploadfile0");
    }

    if (input == null) {
        var j = 0;
        for (j=0; j<= 10; j++) {

            if (input == null) {
                input = document.getElementById("ctl00_cBody_uploadfile" + j);
            }
        }
    }

    input = input.value;
    input = input.replace(/^\s+|\s+$/g, '');
    if (input.length < 1) {
        alert("Xin vui lòng chọn 1 file cụ thể để tải lên");
        return false;
    }
    else {
        return true;
    }
}

function CheckUploadedFileSize(progressArea, args) {
    var size = document.getElementById("idFileSize").innerHTML;
    size = size.replace(',', '');
    size = size.replace('.','');
    
    if (args.get_progressData().RadUpload.RequestSize > parseInt(size * 1024)) {
        progressArea.cancelRequest();
        alert('Kích thước tập tin quá lớn');
    }
    else {

        var div = document.getElementById("divForm");
        if (div == null) {
            div = document.getElementById("divFileInput");
        }

        var divPgs = document.getElementById("divProgress");
        if (divPgs != null) {
            divPgs.style.display = 'block';
        }
        
        div.style.display = "none";
    }
}


function _enable(_this) {
    if (document.getElementById('_sup').nextSibling != null)
        document.getElementById('_sup').nextSibling.disabled = !_this.checked;
    
    else if (document.getElementById('_sup').firstChild != null)
        document.getElementById('_sup').firstChild.disabled = !_this.checked;
}

// -- Close or open div
imgout = new Image(25, 19);
imgin = new Image(25, 19);

imgout.src = "/Images/Plus.gif";
imgin.src = "/Images/Except.gif";

function filter(imagename, objectsrc) {
    if (document.images) {
        document.images[imagename].src = eval(objectsrc + ".src");
    }
}
function ShowDiv(id) {

    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(id).style.display == "none") {
            document.getElementById(id).style.display = 'block';
            filter(("img" + id), 'imgin');
        } else {
            filter(("img" + id), 'imgout');
            document.getElementById(id).style.display = 'none';
        }
    } else {
        if (document.layers) {
            if (document.id.display == "none") {
                document.id.display = 'block';
                filter(("img" + id), 'imgin');
            } else {
                filter(("img" + id), 'imgout');
                document.id.display = 'none';
            }
        } else {
            if (document.all.id.style.visibility == "none") {
                document.all.id.style.display = 'block';
            } else {
                filter(("img" + id), 'imgout');
                document.all.id.style.display = 'none';
            }
        }
    }
}


function FireDownload(url) {
    window.open(url, '_fireDownload', 'width=10, height=10');
    return false;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        } 
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}
//Insert Smiley
function GetTagMemo(str) {
    insertAtCursor(document.getElementById('TagInsert').nextSibling == null ? document.getElementById('TagInsert').firstChild : document.getElementById('TagInsert').nextSibling, str)
    
}
function insertAtCursor(myField, myValue) {
    //IE support
    if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
    }
    //MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)
			+ myValue
			+ myField.value.substring(endPos, myField.value.length);
    } else {
        myField.value += myValue;
    }
}
//AddtoFavorites

function AddToFavorites() {
    if (document.all)
        window.external.AddFavorite(location.href, document.title);
    else if (window.sidebar) window.sidebar.addPanel
            ('Maxup', location.href, '');
}

// Show dialog info
function ShowDialogInfo(page, id) {
    var pageLink = "/" + page + "/" + id + "/";
    window.dialog(pageLink, 'DialogInfo', 'width=530,height=400,toolbars=0,resizable=0', true);
}


String.prototype.isArgument = function() {
    return /^([a-zA-Z]){1,}=([0-9]){1,}$/.test(this);
}


function dialog(url, name, feature, isModal) {
    if (url == null) { return false; }
    url = url
    if (name == null) { name = "" }
    if (feature == null) { feature = "" };
    if (window.showModelessDialog) {
        var WindowFeature = new Object();
        WindowFeature["width"] = 400;
        WindowFeature["height"] = 400;
        WindowFeature["left"] = "";
        WindowFeature["top"] = "";
        WindowFeature["resizable"] = "";

        if (feature != null && feature != "") {
            feature = (feature.toLowerCase()).split(",");

            for (var i = 0; i < feature.length; i++) {
                if (feature[i].isArgument()) {
                    var featureName = feature[i].split("=")[0];
                    var featureValue = feature[i].split("=")[1];

                    if (WindowFeature[featureName] != null) { WindowFeature[featureName] = featureValue; }
                }
            }
        }

        if (WindowFeature["resizable"] == 1 || WindowFeature["resizable"] == "1" || WindowFeature["resizable"].toString().toLowerCase() == "yes") { WindowFeature["resizable"] = "resizable:1;minimize:1;maximize:1;" }
        if (WindowFeature["left"] != "") { WindowFeature["left"] = "dialogLeft:" + WindowFeature["left"] + "px;"; }
        if (WindowFeature["top"] != "") { WindowFeature["top"] = "dialogTop:" + WindowFeature["Top"] + "px;"; }
        if (window.ModelessDialog == null) { window.ModelessDialog = new Object(); };
        if (name != "") {
            if (window.ModelessDialog[name] != null && !window.ModelessDialog[name].closed) {
                window.ModelessDialog[name].focus();
                return window.ModelessDialog[name];
            }
        }
        var F = WindowFeature["left"] + WindowFeature["top"] + "dialogWidth:" + WindowFeature["width"] + " px;dialogHeight:" + WindowFeature["height"] + "px;center:1;help:0;" + WindowFeature["resizable"] + "status:0;unadorned:0;edge: raised; ;border:thick;"
        if (isModal) {
            window.showModalDialog(url, self, F);
            return false;
        }
        else {
            window.ModelessDialog[name] = window.showModelessDialog(url, self, F);
            return window.ModelessDialog[name];
        }
    }
    else {
        if (document.getBoxObjectFor) {


            if (isModal) {
                var Modal = window.open(url, name, "modal=1," + feature);
                var ModalFocus = function() {
                    if (!Modal.closed) { Modal.focus(); }
                    else { Modal = null; window.removeEventListener(ModalFocus, "focus"); ModalFocus = null; };
                }
                window.addEventListener("focus", ModalFocus, false);
                return false;
            }
            else {
                return window.open(url, name, "modal=1," + feature);
            }
        }
        else {
            return window.open(url, name, feature);
        }
        //
    }
    return null;
}


function modal(url, feature) {
    dialog(url, "", feature, true);
    return false;
}
