﻿
function getInnerSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}

function GetCenteredXY(w, h) {
    var ps = getScrollXY();
    var sz = getInnerSize();
    var Left = (sz[0] - w) / 2 + ps[0];
    var Top = (sz[1] - h) / 2 + ps[1];
    return [Math.ceil(Left), Math.ceil(Top)];
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

function getCookie(name) {
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(';', len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

function setCookie(name, value, expires, path, domain, secure) {
    var today = new Date();
    today.setTime(today.getTime());
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));
    document.cookie = name + '=' + escape(value) +
		((expires) ? ';expires=' + expires_date.toGMTString() : '') + //expires.toGMTString()
		((path) ? ';path=' + path : '') +
		((domain) ? ';domain=' + domain : '') +
		((secure) ? ';secure' : '');
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) document.cookie = name + '=' +
			((path) ? ';path=' + path : '') +
			((domain) ? ';domain=' + domain : '') +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

//Open popup window
function Show_Popup(url, title, width, height) {
    var objpopup_window = $('#popup_window'); //Get object popup window
    var document_popup_window = document.getElementById('popup_window'); //Get object document poup window
    var objiframe = document.getElementById("popup_iframe"); //Get object iframe
    var objpopup_title = $('#popup_title'); //Get object popup title

    objpopup_window.width(width); //set popup width
    objpopup_window.height(height); //set popup height
    objpopup_title.text(title); //set popup title

    var ps = getScrollXY(); //Get Scroll X,y
    var sz = getInnerSize(); //Get Innnder Size
    //Set popup top
    document_popup_window.style.top = (ps[1] + (sz[1] / 2) - (height / 2)) + "px";
    //Set popup left
    document_popup_window.style.left = (ps[0] + (sz[0] / 2) - (width / 2)) + "px";

    //Set iframe width
    objiframe.width = (width - 8) + "px";
    //Set iframe height
    objiframe.height = (height - 32) + "px";
    //Clear cache browser
    url = (url.toString().indexOf("?") != -1) == true ? url + "&rnd=" + Math.random() : url + "?rnd=" + Math.random();
    //Set iframe URL
    objiframe.src = url;
    //Move popup window
    objpopup_window.draggable();
    //Resize popup window
    objpopup_window.resizable(
            {
                animate: false,
                resize: function(event, ui) { objiframe.width = (objpopup_window.width() - 8) + "px"; objiframe.height = (objpopup_window.height() - 32) + "px"; }
            });
    objpopup_window.fadeIn('fast'); //fade in popup
}

//Close popup window
function Close_Popup() {
    $('#popup_window').fadeOut('fast');
    var objiframe = document.getElementById("popup_iframe");
    objiframe.src = "/stop.htm";
    return false;
}
function redirect(url) {
    window.location = url;
}
function write_swfXML(Path, strW, strH,xmlPath, Panel) {
    var swfFile = Path+ "?n=" + Math.random();
    var flashvars = {};
    var params = {};
    var attributes = {};
    params.menu = "false";
    params.wmode="transparent";
    flashvars.xmlfile = xmlPath+ "?n=" + Math.random();
    swfobject.embedSWF(swfFile, Panel, strW,strH, "9.0.0", false, flashvars, params, attributes);
}
function write_swf(Path, strW, strH, Panel) {
    $(document).ready(function() {
        var swfFile = Path + "?n=" + Math.random();
        var flashvars = {};
		var params = {};
		var attributes = {};
		params.menu = "false";
		params.scale = "noscale";
		params.salign = "tl";
		params.wmode="transparent";
		swfobject.embedSWF(swfFile, Panel, strW,strH, "9.0.0", false, flashvars, params, attributes);
    });
}
function formatText(index, panel) {
    return index + "";
}
function adjustTextSize(elId, Step) {
    var el = document.getElementById(elId);
    var num = parseInt(el.style.fontSize);
    if (isNaN(num)) num = 13;
    num += Step;
    if (num > 20) num = 20;
    if (num < 9) num = 9;
    el.style.fontSize = (num + "px");
}

 function TopMenu()
   {
    var timer;
    $(function() {
            var $liActive = $('ul#cmsTopMenu li.TopCMSListMenuHighlightedLI');
            var $ulSubmenu=$("ul#cmsTopMenu li ul");
            var $liSubmenu=$("ul#cmsTopMenu li ul li");
            var $liTopMenu;
            main_menu__align($ulSubmenu,$liActive);
            $('#cmsTopMenu li').not($liSubmenu).bind('mouseenter mouseleave', function(ev) {
            var $all = $('#cmsTopMenu li').not($liSubmenu);
            var $li = $(this);
            if (ev.type == 'mouseenter') {
                $all.each(function(){
                    var $t=$(this);
                    if($t.hasClass('TopCMSListMenuHighlightedLI'))
                     {
                        $t.removeClass('TopCMSListMenuHighlightedLI');
                        $t.addClass('TopCMSListMenuLI');
                     }
                });
                $all.removeClass('current');
                $li.addClass('current');
                main_menu__align($ulSubmenu,$li);
                $liTopMenu=$li;
                if(timer)clearTimeout(timer);
                
            } 
            else {
                if(timer)clearTimeout(timer);
                timer=setTimeout(function(){
                                    $all.removeClass('current');
                                    $liActive.removeClass('current');
                                    $liActive.addClass('current');main_menu__align($ulSubmenu,$liActive)
                                },2500);
            }
        });
        $liSubmenu.bind('mouseenter mouseleave', function(ev) {
            if (ev.type == 'mouseenter') {
                if(timer)clearTimeout(timer);
            }
            else{
                timer=setTimeout(function(){
                                    $('#cmsTopMenu li').not($liSubmenu).removeClass('current');
                                    $liActive.removeClass('current');
                                    main_menu__align($ulSubmenu,$liActive);},2500);
            }
        });
    });
    }
    function main_menu__align($sub_menu, $li) {
        var cw = $('#main-menu').outerWidth() - 15;
        var mainleft=$('#main-menu').position().left;
        var mainright=$('#main-menu').position().right;
        var w = $sub_menu.outerWidth(true);
        var x = ($li.position() != null ? $li.position().left : 0 + ($li.width() / 2)) - (w / 2);
        if (x < 15) x = 15; else if (x + w > cw) x = cw - w;
        $sub_menu.css('left', Math.round(x) + 'px');
   }
   
     function onFocusOut(control, tooltip) {
            if(control.value=="" || control.value=="Nhập từ khóa...")
                control.value = tooltip;
        }
    function SetValueOnFocus(control) {
        if (control.value == "Nhập từ khóa...")
            control.value = "";

    }
   
   function OverPlayVideo(VideoOverPlayID,ev)
   {
        var $divVideoPlay=$("#"+VideoOverPlayID);
        if (ev == 's') {
            $divVideoPlay.css("display","block");
        }else{
            $divVideoPlay.css("display","none");
        }
   }

    
