﻿/** MasterPage **/
function Trim(str) { return str.replace(/^\s+|\s+$/g, "") + ''; }
function ExpandIframe(ifrm, height) {   //callback for iframe height increase
    if (document) {
        uploadIframeObj = document.getElementById(ifrm);
        if (uploadIframeObj) {
            if (typeof (height) == 'undefined') { // IE specific setting
                if (!!(window.attachEvent && !window.opera)) { height = uploadIframeObj.contentWindow.document.documentElement.scrollHeight; }
                else { height = uploadIframeObj.contentWindow.document.documentElement.offsetHeight; }
            }
            uploadIframeObj.style.height = height + 'px';
        }
    }
}
/** SearchBox **/
function clickButton(e, buttonid) {
    var bt = document.getElementById(buttonid);
    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Netscape") > (-1)) {
            if (e.keyCode == 13) {
                bt.click();
                return false;
            }
        }
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            }
        }
    }
    return true;
}
function textBoxClick(e, txtBox) {
    var txtSrch = document.getElementById(txtBox.id);
    document.getElementById('clickStatus').value = "-1";
    //txtSrch.value = '';
    txtSrch.onclick = null;
    return clickButton(e, txtBox.id);
}
function goToSearch() {
    var srchString = Trim(document.getElementById(tSrchBx).value);
    var returnValue = false;
    var errMsg = 'Please specify a valid search string';
    if (document.getElementById('clickStatus').value == '-1') {
        if (srchString == '') {
            alert(errMsg);
        }
        else {
            returnValue = true;
        }
    }
    else {
        alert(errMsg);
    }
    return returnValue;
}
/** Login **/
function gfmCloseLayer() {
    $("#divLogin").hide();
    $("#divFadeLayer").hide();
}
function gfmOpenLayer() {
    $('#txtUsername').val('');
    $('#txtPassword').val('');
    var w = $('div.mainContainer').width();
    var h = $('div.mainContainer').height();
    var lft = parseInt((w - 300) / 2);
    $("#divLogin").css("left", lft + "px").fadeIn('slow');
    $("#divFadeLayer").css("width", w + "px").css("height", h + "px").fadeIn('slow');
}
function ValidateLogin() {
    uname = Trim($('#txtUsername').val());
    $('#spnUErr').hide(); $('#spnPErr').hide(); $('#divLErr').hide();
    if (uname == '') {
        $('#spnUErr').show(); return;
    }
    pwd = Trim($('#txtPassword').val());
    if (pwd == '') {
        $('#spnPErr').show(); return;
    }
    $.post(appPath + "controller.aspx", { a: 'login', uname: uname, pwd: pwd },
                    function(response) {
                        try {
                            if (response == '0') {
                                $('#divLErr').show(); return;
                            }
                            else {
                                var r = response.split('|');
                                if (r.length > 1) {
                                    if (r[0] == "1") {
                                        window.location.href = r[1];
                                        //window.location.reload();
                                        gfmCloseLayer();
                                    }
                                    else
                                        $('#divLErr').show(); return;
                                }
                                else
                                    $('#divLErr').show(); return;
                            }
                        }
                        catch (e) { }
                    });
}

