﻿$(document).ready(function () {
    $('<div class="iLeft"></div><div class="iRight"></div>').appendTo('#iContent .iCtLeft .iTopNews .iSearch');
    var style = 'easeOutElastic';
    var default_left = Math.round($('#iTopMenu li.selected').offset().left - $('#iTopMenu').offset().left);
    var default_width = $('#iTopMenu li.selected').width();
    $('#iTopMenuBg').css({ left: default_left, width: default_width });
    $('#iTopMenu li').hover(function () {
        left = Math.round($(this).offset().left - $('#iTopMenu').offset().left);
        width = $(this).width();
        $('#iTopMenuBg').stop(false, true).animate({ left: left, width: width }, { duration: 1000, easing: style });
    }).click(function () {
        $('#iTopMenu li').removeClass('selected');
        $(this).addClass('selected');
    });
    $('#iTopMenu').mouseleave(function () {
        default_left = Math.round($('#iTopMenu li.selected').offset().left - $('#iTopMenu').offset().left);
        default_width = $('#iTopMenu li.selected').width();
        $('#iTopMenuBg').stop(false, true).animate({ left: default_left, width: default_width }, { duration: 1500, easing: style });
    });
    iViewSearch(1);
});
function OpenLinkweb(form) {
    if (form.ddlLinkweb.selectedIndex > 0) {
        window.open(form.ddlLinkweb.value);
        form.ddlLinkweb.options[0].selected = true;
    }
}
function CheckEmail(sEmail) {
    emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
    if (emailRegExp.test(sEmail)) {
        return true;
    } else {
        return false;
    }
}
function AddEmail(form) {
    if ((document.getElementById('txtEmail').value.length > 0) && (CheckEmail(document.getElementById('txtEmail').value))) {
        alert("Email: " + document.getElementById('txtEmail').value + " đã đăng ký nhận tin thành công.");
    }
    else
        alert("Bạn phải nhập email để nhận tin");
}
function SetMenuItemSelect(idMenu) {
    $('#iTopMenu li').removeClass('selected');
    $('#iTopMenu #iTopMenu' + idMenu).addClass('selected');
}
function SearchOnFocus(field) {
    if (field.value == 'Nhập từ khóa tin tức cần tìm ...') { field.value = ''; }
}
function SearchOnBlur(field) {
    if (field.value == '') { field.value = 'Nhập từ khóa tin tức cần tìm ...'; }
}
function checkEnterSearch(e) {
    var keynum; if (window.event) { keynum = e.keyCode; }
    else if (e.which) { keynum = e.which; }if (keynum == 13) {
        document.getElementById('btnSSearch').onclick();
        e.returnValue = false; e.cancel = true;
    }
}
function SearchInfo() {
    var sSearch = $('#sKey').val();
    if ((sSearch.length == 0) || (sSearch == 'Nhập từ khóa tin tức cần tìm ...'))
    { alert('Bạn phải nhập từ khóa tìm kiếm.'); return false; }
    location = '/SearchNews.aspx?sKey=' + sSearch;
}

function FocusControl(controlId) {
    $(controlId).focus();
}

function qtip_form(selector) {
    $(document).ready(function () {
        $(selector).qtip({
            content: { text: false },
            style: { 'font-size': '11px', 'color': '#333333', 'background': '#ffffff url(images/tooltipbg.gif) repeat-x left bottom', border: { color: '#aaa'} },
            position: {
                corner: { target: 'bottomLeft', tooltip: 'topMiddle' },
                adjust: { y: 10 }
            }
        }).addClass('jtip-registered');
    });
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (!prm.get_isInAsyncPostBack()) {
        prm.add_endRequest(
            function () {
                $(selector).qtip({
                    content: { text: false },
                    style: { 'font-size': '11px', 'color': '#333333', 'background': '#ffffff url(images/tooltipbg.gif) repeat-x left bottom', border: { color: '#aaa'} },
                    position: {
                        corner: { target: 'bottomLeft', tooltip: 'topMiddle' },
                        adjust: { y: 10 }
                    }
                });
            }
        );
    }
};
function iViewSearch(iID) {
    if (iID == 1) {
        document.getElementById('iSJobs').style.display = '';
        document.getElementById('iSWorks').style.display = 'none';
    }
    else {
        document.getElementById('iSWorks').style.display = '';
        document.getElementById('iSJobs').style.display = 'none';
    }
}
function OpenPopUpLogin() {
    $.fancybox({
        href: '/PopUpLogin.aspx',
        type: 'iframe',
        transitionIn: 'fade',
        transitionOut: 'elastic',
        speedIn: 600,
        speedOut: 200,
        enableEscapeButton: false,
        hideOnOverlayClick: false,
        scrolling: 'no',
        centerOnScroll: true,
        width: 350,
        height: 165,
        onClosed: function () { parent.location.reload(true); }
    }).trigger('click');
}
function OpenAddNewZone() {
    $.fancybox({
        href: 'ZoneAdd.aspx',
        type: 'iframe',
        transitionIn: 'none',
        transitionOut: 'none',
        enableEscapeButton: false,
        hideOnOverlayClick: false,
        scrolling: 'no',
        width: 400,
        height: 390
    });
}

function OpenPageEditor(el, z, r) {
    $.fancybox({
        href: 'PageEditor.aspx?zid=' + z + '&rid=' + r,
        type: 'iframe',
        transitionIn: 'none',
        transitionOut: 'none',
        enableEscapeButton: false,
        hideOnOverlayClick: false,
        scrolling: 'no',
        width: 650,
        height: 390
    });
}

function ClosePageEditor(data) {
    $.fancybox.close();
    alert(data);
}

function OpenHelp(id) {
    $.fancybox({
        href: 'QuickHelp.aspx?hid=' + id,
        type: 'iframe',
        transitionIn: 'none',
        transitionOut: 'none',
        enableEscapeButton: false,
        scrolling: 'no',
        width: 650,
        height: 390
    });
}
function FloatingMessage(msg, seconds, icon) {
    $.unblockUI();

    var style =
    {
        width: '350px',
        top: '15px',
        left: '',
        cursor: 'pointer',
        right: '15px',
        padding: '10px 10px 10px 45px',
        color: '#fff',
        'font-size': '16px',
        'font-weight': 'normal',
        textAlign: 'left',
        'border': '4px solid #ff9500',
        'background': '#ff9500 url(images/icons/warning-32.png) no-repeat 5px 3px',
        '-webkit-border-radius': '3px',
        '-moz-border-radius': '3px',
        '-moz-box-shadow': '2px 2px 2px #333',
        '-webkit-box-shadow': '2px 2px 2px #333',
        'box-shadow': '2px 2px 2px #333'
    }

    if (icon == "info") {
        style = $.extend(style, {
            border: '4px solid #faffaa',
            color: '#000',
            'background': '#faffaa url(images/icons/info-32.png) no-repeat 5px 3px'
        });
    }

    $.blockUI({
        message: msg,
        fadeIn: 500,
        fadeOut: 750,
        showOverlay: false,
        centerY: false,
        css: style
    });
    $('.blockUI').click($.unblockUI).attr('title', 'Click to close');
    if (seconds == undefined) seconds = 10;
    if (seconds != 0) setTimeout($.unblockUI, seconds * 1000);
}

function start_aspnet_ajax_request() {
    $.unblockUI();
    $.blockUI({
        message: 'Đang xử lý, vui lòng chờ...',
        fadeIn: 0,
        fadeOut: 0,
        showOverlay: false,
        centerY: false,
        css: {
            width: '150px',
            top: '15px',
            left: '',
            cursor: 'pointer',
            right: '15px',
            padding: '5px 10px',
            color: '#fff',
            textAlign: 'left',
            border: '4px solid #ff9500',
            'background': '#ff9500',
            '-webkit-border-radius': '3px',
            '-moz-border-radius': '3px',
            '-moz-box-shadow': '2px 2px 2px #333',
            '-webkit-box-shadow': '2px 2px 2px #333',
            'box-shadow': '2px 2px 2px #333'
        }
    });
}

function end_aspnet_ajax_request(sender, args) {
    var err = args.get_error();
    if (err != null) {
        FloatingMessage('Server Error: ' + err.message, 10, 'warning');
        args.set_errorHandled(true);
    }
}

var prm = Sys.WebForms.PageRequestManager.getInstance();
if (!prm.get_isInAsyncPostBack()) {
    if (typeof($.unblockUI) != 'undefined') prm.add_beginRequest($.unblockUI);
    prm.add_endRequest(end_aspnet_ajax_request);
}

