﻿function fn_closealert(id) {
    document.getElementById(id).style.visibility = 'hidden';
    //document.getElementById('div_mask').style.display='none';
}

//From Private Collection

function fn_getxmlhttp() {
    try {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();

        if (window.ActiveXObject)
            return new ActiveXObject('Msxml2.XMLHTTP');

        return new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch (e) {
        window.status = e.description;
        return null;
    }
}

function fn_checknumber(e) {
    var unicode = e.keyCode ? e.keyCode : e.charCode
    
    if (unicode == 8 || unicode == 46  || (unicode >= 48 && unicode <= 57))
    {  
        return true;
    } 
    return false;
}


function fn_getasyncdata(method, url, params, callback, errorfunc) {
    try {
        var oHttp = fn_getxmlhttp();

        if (oHttp != null) {
            oHttp.onreadystatechange = function() { fn_checkresponse(oHttp, callback, errorfunc); };
            oHttp.open(method.toUpperCase(), url, true);

            if (method.toUpperCase() == "POST") {
                oHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

            }
            //oHttp.setRequestHeader("CharSet","windows-1255");
            oHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
            oHttp.send(params);
        }
    }
    catch (e) {
        window.status = e.description;
    }
}

function fn_checkresponse(oHttp, callback, errorfunc) {
    if (oHttp.readyState == 4) {
        window.status = oHttp.status + "-" + oHttp.statusText;

        try {
            if (oHttp.status == 200)
                eval(callback + "(oHttp)");
            else {
                eval(errorfunc + "(oHttp)");
                //var w=window.open("", "_blank");
                //w.document.write(oHttp.responseText);
            }
        }
        catch (e) {
            window.status = oHttp.status + "-" + e.description;
        }
    }
}

function fn_copyfromtitle(destid, srcid) {
    var src = document.getElementById(srcid);
    var dest = document.getElementById(destid);

    if (src != null && dest != null) dest.value = src.value.toLowerCase().replace(/ /g, '_');
}

function fn_previewimage(attachment, imgId) {

    if (attachment.files)
        document.getElementById(imgId).src = attachment.files.item(0).getAsDataURL();
    else
        document.getElementById(imgId).src = attachment.value;

}

function fn_clearerror(obj) {
    if (obj.tagName == 'INPUT') {
        obj.style.borderColor = '#cccccc';
        obj.style.backgroundColor = 'white';
    }
    else {
        obj.style.border = 'none';
        obj.style.backgroundColor = 'transparent';
    }
}

function fn_closepopup() {
    var div = document.getElementById("divPopup");
    div.innerHTML = '';
    div.style.display = 'none';
    fn_unblockwindow();
}
function fn_openpopup(src, w, h) {

    fn_blockwindow();
    var frm = document.createElement("IFRAME");
    var div = document.getElementById("divPopup");

    frm.setAttribute("id", "frmPopup");
    frm.setAttribute("src", src);
    frm.setAttribute("width", w);
    frm.setAttribute("height", h);
    frm.setAttribute("frameborder", "0");
    frm.setAttribute("onload", "top.fn_animateopenpopup('divPopup'," + w + "," + h + ")");

    div.appendChild(frm);

    //fn_animatepopup('divPopup', w, h)
}

function fn_animateopenpopup(id, w, h) {

    var div = document.getElementById(id);
    div.style.left = fn_getelementleft(0) + 'px';
    div.style.top = '320px';
    div.style.width = '5px';
    div.style.height = '5px';
    div.style.display = 'block';

    $('#' + id).animate({
        height: h,
        width: w,
        left: fn_getelementleft(w),
        top: 320-(h/2)
    }, 700, function() {
        document.getElementById("frmPopup").onload = null;
    });
}
function fn_getelementleft(w) {
    return Math.round((window.screen.width - w) / 2);
}

function fn_blockwindow() {
    setLayerPosition();

    var shadow = document.getElementById("shadow");

    shadow.style.display = "block";
    shadow = null;

    //document.body.style.marginRight = '25px';
    //document.body.style.overflow = 'hidden';
}

function fn_unblockwindow() {
    var shadow = document.getElementById("shadow");

    shadow.style.display = "none";
    shadow = null;

    //document.body.style.marginRight = '';
    //document.body.style.overflow = '';
}

function getBrowserHeight() {
    var intH = 0;
    var intW = 0;

    if (typeof window.innerWidth == 'number') {
        intH = window.innerHeight;
        intW = window.innerWidth;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        intH = document.documentElement.clientHeight;
        intW = document.documentElement.clientWidth;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        intH = document.body.clientHeight;
        intW = document.body.clientWidth;
    }

    return { width: parseInt(intW), height: parseInt(intH) };
}

function setLayerPosition() {
    var shadow = document.getElementById("shadow");

    var bws = getBrowserHeight();
    shadow.style.width = bws.width + "px";
    shadow.style.height = bws.height + "px";
    shadow = null;
}

window.onresize = setLayerPosition;
