﻿// JScript File

function fetch_object(idname)
{
    if (document.getElementById)
        return document.getElementById(idname);
    else if (document.all)
        return document.all[idname];
    else if (document.layers)
        return document.layers[idname];
    else
        return null;
}

function PerformClick(e, buttonID) 
{
    if (e.which || e.keyCode)
    {
        if ((e.which == 13) || (e.keyCode == 13))
        {
            fetch_object(buttonID).click();
            return false;
        }
    }
    else
        return true;
}

/****************************************************************************************************************************/
/************************************************ Function cho phần search ở header *****************************************/
/****************************************************************************************************************************/
function showTab(tab_active, content_active, tab_hide, content_hide)
{
    var objTabActive = fetch_object(tab_active);
    var objContentActive = fetch_object(content_active);
    var objTabHide = fetch_object(tab_hide);
    var objContentHide = fetch_object(content_hide);
  
    // chuyển tab
    if(objTabActive != null)
        objTabActive.className = "searchActive";
    if(objTabHide != null)
        objTabHide.className = "searchNormal";
    
    // ẩn/hiện content
    if(objContentActive != null)
        objContentActive.style.display = "";
    if(objContentHide != null)
        objContentHide.style.display = "none";        
}
/****************************************************************************************************************************/
/*********************************** Function cho phần hiển thị tin popup và topten *****************************************/
/****************************************************************************************************************************/
function showTop10News(id, catid, title, abst, image)
{
    var url = "~/NewsDetail.aspx?newsid=" + id + "&cat_id=" + catid;
    var lblTitle = fetch_object("lblActiveNews");
    var lblAbstract = fetch_object("lblActiveAbstract");
    var imgNews = fetch_object("imgActiveNews");
    
    if(browserVersion.indexOf("MSIE 6.0") >= 0 || browserVersion.indexOf("MSIE 7.0") >= 0)
    {
        imgNews.style.width = "100px";
        lblAbstract.style.width = "350px";
    }
        
    lblTitle.innerHTML = title;
    lblAbstract.innerHTML = abst;
    if(image == "")
        imgNews.style.display = "none";
    else
    {   
        imgNews.style.display = ""; 
        imgNews.src = image;
    }
}

function showPopupReport(type, stock, industry, source)
{
    var lblType = fetch_object("lblReportType");
    var lblStock = fetch_object("lblReportStock");
    var lblIndustry = fetch_object("lblReportIndustry");
    var lblSource = fetch_object("lblReportSource");
    
    lblType.innerHTML = type;
    lblStock.innerHTML = stock;
    lblIndustry.innerHTML = industry;
    lblSource.innerHTML = source;
}
/****************************************************************************************************************************/
/************************************************** Scroll logo *************************************************************/
/****************************************************************************************************************************/
var logoTimeloop = 15;
var logoDiv1, logoDiv2;
var logoStatus = true;
var logoPos1 = 0, logoPos2 = 0;
var logoWidth = 0;

function initLogoList(prefixImage, div1, div2)
{
    var logo;
    var index = 0;
    do
    {
        logo = fetch_object(prefixImage + index);
        index++;
        if(logo != null)
        {
            var itemWidth = parseInt(logo.style.width.replace("px", "")); 
            logoWidth += itemWidth + 4;
        }
    }while(logo != null);
    
    logoDiv1 = fetch_object(div1);
    logoDiv2 = fetch_object(div2);
    
    if(logoDiv1 == null || logoDiv2 == null)
        return;
        
    logoPos2 = logoWidth;
    logoDiv1.style.width = logoWidth + 'px';
    logoDiv2.style.width = logoWidth + 'px';
        
    scrollLogo();
}

function scrollLogo()
{
    if(!logoStatus)
    {
        setTimeout('scrollLogo()', logoTimeloop);
        return;
    }
    
    logoDiv1.style.left = logoPos1 + 'px';
    logoDiv2.style.left = logoPos2 + 'px';
    
    logoPos1--;
    logoPos2--;
    
    if(logoPos1 == -logoWidth)
    {
        logoPos1 = logoWidth;
    }
    if(logoPos2 == -logoWidth)
    {
        logoPos2 = logoWidth;
    }
    
    setTimeout('scrollLogo()', logoTimeloop);
}

function pauseScroll(pause)
{
    logoStatus = !pause;
}
/****************************************************************************************************************************/
/************************************************* Hiển thị Login ***********************************************************/
/****************************************************************************************************************************/
var pnLogin;
var pnContent;
var pnForgetPass;

var addEvent = function(elem, type, eventHandle) {
    if (elem == null || elem == undefined) return;
    if ( elem.addEventListener ) {
        elem.addEventListener( type, eventHandle, false );
    } else if ( elem.attachEvent ) {
        elem.attachEvent( "on" + type, eventHandle );
    }
};

addEvent(window, "resize", function() { initLoginDiv(); } );

function initLoginDiv()
{
    pnLogin = fetch_object("pnLogin");
    pnContent = fetch_object("loginContentPanel");
    pnForgetPass = fetch_object("forgetPassPanel");
      
    var contentWidth = parseInt(pnContent.style.width.replace("px", "")); 
    var contentHeight = parseInt(pnContent.style.height.replace("px", "")); 
    
    // get size of browser 
    getBrowserViewport();
    
    // init position for panels
    var leftPosition = (viewportwidth - contentWidth) / 2;
    var topPosition = (viewportheight - contentHeight) / 2;
    
    // set position for panel
    pnContent.style.left = Math.round(leftPosition) + "px";
    pnContent.style.top = Math.round(topPosition) + "px";
    
    // adjust size for fill browser's window
    if(viewportheight < document.body.clientHeight)
	    viewportheight = document.body.clientHeight;
	if(viewportheight < document.documentElement.clientHeight)
	    viewportheight = document.documentElement.clientHeight;
	    
	if(viewportwidth < document.body.clientWidth)
	    viewportwidth = document.body.clientWidth;
	if(viewportwidth < document.documentElement.clientWidth)
	    viewportwidth = document.documentElement.clientWidth;
	    
	pnLogin.style.width = viewportwidth + "px";
    pnLogin.style.height = viewportheight + "px";    
}

function showLoginPanel()
{
    initLoginDiv();
    pnLogin.style.display = "";
    pnContent.style.display = "";
    pnForgetPass.style.display = "none";
    if(IE6)
    {
        document.getElementsByTagName("html")[0].style.overflow = "hidden";
        // ẩn form đăng ký nếu dùng IE6
        var pnRegistration = fetch_object("divRegistration");
        if(pnRegistration != null)
            pnRegistration.style.display = "none";
    }
    else
        document.body.style.overflow = "hidden";
}

function showForgetPassPanel()
{
    initLoginDiv();    
    pnLogin.style.display = "";
    pnContent.style.display = "";
    pnForgetPass.style.display = "";    
    pnForgetPass.style.left = left + "px";
    pnForgetPass.style.top = top + "px";
    if(IE6)
    {
        document.getElementsByTagName("html")[0].style.overflow = "hidden";
        // ẩn form đăng ký nếu dùng IE6
        var pnRegistration = fetch_object("divRegistration");
        if(pnRegistration != null)
            pnRegistration.style.display = "none";
    }
    else
        document.body.style.overflow = "hidden";
}

function hideLoginPanel()
{
    if(pnLogin == null)
        pnLogin = fetch_object("pnLogin");   
    pnLogin.style.display = "none";
    if(IE6)
    {
        document.getElementsByTagName("html")[0].style.overflow = "auto";
        // ẩn form đăng ký nếu dùng IE6
        var pnRegistration = fetch_object("divRegistration");
        if(pnRegistration != null)
            pnRegistration.style.display = "";
    }
    else
        document.body.style.overflow = "auto";
}

function showLoginForm(loginID, accountID)
{
    var loginForm = fetch_object(loginID);
    var accountForm = fetch_object(accountID);
    if(loginForm != null && accountForm != null)
    {   
        loginForm.style.display = "";
        accountForm.style.display = "none";
    }
}

function showAccountForm(loginID, accountID, lblUserID, nameUser)
{    
    var loginForm = fetch_object(loginID);
    var accountForm = fetch_object(accountID);
    var lblUser = fetch_object(lblUserID);
    
    if(loginForm != null && accountForm != null && lblUser != null)
    {
        lblUser.innerHTML = nameUser + " ▼";
        loginForm.style.display = "none";
        accountForm.style.display = "";        
        hideLoginPanel();
    }
}

function showAccountFormAlert(loginID, accountID, lblUserID, nameUser, message)
{
    alert(message);
    showAccountForm(loginID, accountID, lblUserID, nameUser);
}

function checkRequireField(fieldID)
{
    var fieldObj = fetch_object(fieldID);
    if(fieldObj.value == "")
        return false;
    return true;
}

function checkField(field1, field2)
{
    if(!checkRequireField(field1) || !checkRequireField(field2))
        return false;
    return true;
}
/****************************************************************************************************************************/
/************************************************* Check Null or "" *********************************************************/
/****************************************************************************************************************************/
function checkValueNotNull(objID)
{
    var obj = fetch_object(objID);
    if(obj != null && obj.value != "")
        return true;
    return false;
}
/****************************************************************************************************************************/
/******************************************************* Menu ***************************************************************/
/****************************************************************************************************************************/
function setMenuSelectedStyle(menuID)
{
    var menu = fetch_object(menuID);
    alert("hear");
    if(menu != null)
    {
    
        menu.className = "menuSelected";
        }
}
/****************************************************************************************************************************/

