﻿(function($)
{
    jQuery.fn.setfocus = function()
    {
        return this.each(function()
        {
            // due to variable scope problem, we need put 'this' into a tmp variable so taht setTimeout deligate should catch this type
            var dom = this;
            
            setTimeout(function()
            {
                try { dom.focus(); } catch (e) { } 
            }, 0);
        });
    };
})(jQuery);


function openwin(src, w_name, w_width, w_height, w_opt)
{
    if (!w_opt) w_opt = 'resizable=1,scrollbars=1,status=1';

    if (!w_width) w_width = 700;
    if (!w_height) w_height = 500;

    w_opt += ',width=' + w_width + ',height=' + w_height;

    if (typeof (screen) != 'undefined')
    {
        w_left = parseInt((screen.width - w_width) / 2);
        w_top = parseInt((screen.height - w_height) / 2);

        w_opt += ',left=' + w_left + ',top=' + w_top;
    }

    wobj = window.open(src, w_name, w_opt);
    wobj.focus();

    return wobj;
}

function JsLoginSSO()
{
    var alias = document.loginForm.username.value.replace(/ /, '');

    var regex = /^[A-Za-z]\d{9}/;

    // 判斷是否為「身份證字號」登入
    if (regex.test(alias))
    {
        LoginSSO(document.loginForm.username.value, document.loginForm.password.value, 'ARES_SSO', '/SSOLogin/sso_verify.aspx');
    }
    else
    {
        // 若非「身份證字號」登入就從 /Home/GetUID 取得真正的身份證號登入
        $.post("/Home/GetUID", { account: alias }, function(emp_id)
        {
            LoginSSO(emp_id, document.loginForm.password.value, 'ARES_SSO', '/SSOLogin/sso_verify.aspx');
        });
    }
}

$(function() {
    $('table.list-Style-blue tbody tr:odd').addClass('odd');
    $("table.list-Style-green tbody tr:odd").addClass("odd");
    $("table.GridViewStyle1 tbody tr:odd").addClass("odd");
    /*$("table.DetailViewStyle1 tr:odd").addClass("odd");*/
});


function CheckPermissionGetAPTicket(pageTime, pageTimeout, appMsg, apName, Domain, apPath, apTarget, userId) 
{
    if (Date.parse(pageTime).addMinutes(pageTimeout) < Date.now()) {
        alert(appMsg);
        return;
    }

    if (typeof (userId) == undefined || userId == null || userId == "") {
        /**/GetAPTicket(apName, Domain, apPath, apTarget);
    } else {
        /**/GetAPTicket(apName, Domain, apPath, apTarget, userId);
    }
}
