﻿$(document).ready(function() {
    CheckStatus();
});
$('.over').each(function(index) {
    var currentImg = $(this).attr('src');
    $(this).mouseover(function() {
        $(this).attr('src', currentImg.replace('_a', '_b'));
        if (index == 1) {
            $("#subMenu").html('');
        }
        else if (index == 2) {
            $("#subMenu").html(Dienthoai());
        }
        else if (index == 3) {
            $("#subMenu").html(Maytinh());
        }
        else if (index == 4) {
            $("#subMenu").html(Khuyenmai());
        }
        else if (index == 5) {
            $("#subMenu").html('');
        }
        else if (index == 6) {
            $("#subMenu").html(Hotro());
        }
        else if (index == 7) {
            $("#subMenu").html(Baohanh());
        }
        else {
            $("#subMenu").html('');
        }
    });
    $(this).mouseout(function() {
        $(this).attr('src', currentImg.replace('_b', '_a'));
    });
});
    function FStore() {
        var result = "";
        result += "<div class='subMenuItem' style='padding-left:70px'>";
        result += "<a href='Store.aspx?m=1'>Điện thoại</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        result += "<a href='Store.aspx?m=2'>Máy tính</a>"; 
        result += "</div>";
        return result;
    }
    function Dienthoai() {
        var result = "";
	    result += "<div class='subMenuItem' style='padding-left:25px'>";
	    result += "<a href='Product.aspx?t=3&c=1'>Sản phẩm mới nhất</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    result += "<a href='Product.aspx?t=3&c=2'>Sản phẩm HOT nhất</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    result += "<a href='Product.aspx?t=3'>Sản phẩm bán hiện có</a>"; 
	    result += "</div>";
	    return result;
	}
	function Maytinh() {
	    var result = "";
	    result += "<div class='subMenuItem' style='padding-left:140px'>";
	    result += "<a href='Product.aspx?t=22'>Máy tính xách tay</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    result += "<a href='Product.aspx?t=23'>Máy tính để bàn</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    result += "<a href='Product.aspx?t=24'>Máy chủ</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    result += "<a href='Product.aspx?t=25'>Máy tính dự án</a>";
	    result += "</div>";
	    return result;
	}
	function Khuyenmai() {
	    var result = "";
	    result += "<div class='subMenuItem' style='padding-left:340px'>";
	    result += "<a href='News.aspx?t=9'>Điện thoại</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    result += "<a href='News.aspx?t=26'>Máy tính</a>";
	    result += "</div>";
	    return result;
	}
	function Tintuc() {
	    var result = "";
	    result += "<div class='subMenuItem' style='padding-left:430px'>";
	    result += "<a href='News.aspx?t=2'>Tuyển dụng</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    result += "<a href='News.aspx?t=1'>Tin tức</a>"; 
	    result += "</div>";
	    return result;
	}
	function Hotro() {
	    var result = "";
	    result += "<div class='subMenuItem' style='padding-left:520px'>";
	    result += "<a href='Help.aspx?h=1'>Điện thoại</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    result += "<a href='Help.aspx?h=2'>Máy tính</a>"; 
	    result += "</div>";
	    return result;
	}
	function Baohanh() {
	    var result = "";
	    result += "<div class='subMenuItem' style='padding-left:590px'>";//590px
	    result += "<a href='CheckCode.aspx?h=1'>Điện thoại</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	    result += "<a href='Info.aspx?t=33'>Máy tính</a>"
	    result += "</div>";
	    return result;
	}
	var timerRunning = false; // boolean flag
	var myTimer = null;
	function ResetAll() {
	    if ($(".over:eq(1)").attr("src") == "images/menu/fstore_b.png") {
	        $("#subMenu").html(FStore());
	    }
	    else if ($(".over:eq(2)").attr("src") == "images/menu/dienthoai_b.png") {
	        $("#subMenu").html(Dienthoai());
	    }
	    else if ($(".over:eq(3)").attr("src") == "images/menu/maytinh_b.png") {
	        $("#subMenu").html(Maytinh());
	    }
	    else if ($(".over:eq(4)").attr("src") == "images/menu/khuyenmai_b.png") {
	        $("#subMenu").html(Khuyenmai());
	    }
	    else if ($(".over:eq(5)").attr("src") == "images/menu/tintuc_b.png") {
	        $("#subMenu").html(Tintuc);
	    }
	    else if ($(".over:eq(6)").attr("src") == "images/menu/hotro_b.png") {
	        $("#subMenu").html(Hotro());
	    }
	    else if ($(".over:eq(7)").attr("src") == "images/menu/baohanh_b.png") {
	        $("#subMenu").html(Baohanh());
	    }
	   else {
	        $("#subMenu").html("");
	     }
    }
    function CheckAll() {
        setTimeout("ResetAll()",600);
    }

    function CheckStatus() {
        var path = window.location.pathname;
        var file = path.substring(path.lastIndexOf('/') + 1).toLowerCase();
        if (file == "info.aspx") {
            if (gup('t') == "17") {
                $("#img_10").attr("src", "images/m10_b.png");
            }
            $("#pageTitle").html(InfoText(gup('t')).toUpperCase());
            var navigateLink = "";
            navigateLink += "<ul>";
            navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
            navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
            navigateLink += "    <li>" + InfoText(gup('t')) + "</li>";
            navigateLink += "</ul>";
            $("#navigate").html(navigateLink);
        }
        else if (file == "store.aspx") {
            $(".over:eq(1)").attr("src", "images/menu/fstore_b.png");
            $("#pageTitle").html("F-Store");
            var navigateLink = "";
            navigateLink += "<ul>";
            navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
            navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
            navigateLink += "    <li>F-Store</li>";
            navigateLink += "</ul>";
            $("#navigate").html(navigateLink);
        }
        else if (file == "checkcode.aspx") {
            $(".over:eq(7)").attr("src", "images/menu/baohanh_b.png");
            $("#pageTitle").html('BẢO HÀNH');
            var navigateLink = "";
            navigateLink += "<ul>";
            navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
            navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
            navigateLink += "    <li>Bảo hành</li>";
            navigateLink += "</ul>";
            $("#navigate").html(navigateLink);
        }
        else if (file == "product.aspx" || file == "productdetail.aspx") {
            if (gup('t') == '3') {
                $(".over:eq(2)").attr("src", "images/menu/dienthoai_b.png");
            }
            else if (gup('t') == '22' || gup('t') == '23' || gup('t') == '24' || gup('t') == '25') {
                $(".over:eq(3)").attr("src", "images/menu/maytinh_b.png");
            }
            if (gup('c') != "") {
                $("#pageTitle").html(ProductText(gup('c')).toUpperCase());
            }
            else {
                $("#pageTitle").html("SẢN PHẨM");
            }
            var navigateLink = "";
            navigateLink += "<ul>";
            navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
            navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
            navigateLink += "    <li><a href='" + file + "'>Sản phẩm</a></li>";
            if (gup('c') != "") {
                navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
                //navigateLink += "    <li><a href='" + file + "?c=" + gup('c') + "'>" + ProductText(gup('c')) + "</a></li>";
                navigateLink += "    <li>" + ProductText(gup('c')) + "</li>";
            }
            if (file == "productdetail.aspx") {
                navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
                //navigateLink += "    <li><a href='" + file + "?c=" + gup('c') + "'>" + ProductText(gup('c')) + "</a></li>";
                navigateLink += "    <li>Chi tiết sản phẩm</li>";
            }
            navigateLink += "</ul>";
            $("#navigate").html(navigateLink);
        }
        else if (((file == "news.aspx") && (gup("t") == 1 || gup("t") == 2)) || (file == "newsdetail.aspx")) {
            $(".over:eq(5)").attr("src", "images/menu/tintuc_b.png");
            $("#pageTitle").html(NewsText(gup('t')).toUpperCase());
            var navigateLink = "";
            navigateLink += "<ul>";
            navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
            navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
            navigateLink += "    <li>Tin tức</li>";
            navigateLink += "</ul>";
            $("#navigate").html(navigateLink);
        }
        else if (file == "news.aspx" && (gup("t") == "9" || gup("t") == "26")) {
            $(".over:eq(4)").attr("src", "images/menu/khuyenmai_b.png");
            $("#pageTitle").html("Khuyến mãi");
            var navigateLink = "";
            navigateLink += "<ul>";
            navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
            navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
            //navigateLink += "    <li><a href='" + file + "&t=" + gup("t") + "'>Khuyến mãi</a></li>";
            navigateLink += "    <li>Khuyến mãi</li>";
            navigateLink += "</ul>";
            $("#navigate").html(navigateLink);
        }
        else if (file == "newsdetail.aspx") {
            $(".over:eq(5)").attr("src", "images/menu/tintuc_b.png");
            $("#pageTitle").html("Tin tức");
            var navigateLink = "";
            navigateLink += "<ul>";
            navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
            navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
            navigateLink += "    <li>Tin tức</li>";
            navigateLink += "</ul>";
            $("#navigate").html(navigateLink);
        }
        else if (file == "register.aspx") {
            $("#pageTitle").html("Đăng ký");
            var navigateLink = "";
            navigateLink += "<ul>";
            navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
            navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
            //navigateLink += "    <li><a href='" + file + "'>Đăng ký</a></li>";
            navigateLink += "    <li>Đăng ký</li>";
            navigateLink += "</ul>";
            $("#navigate").html(navigateLink);
        }
        else if (file == "login.aspx") {
            $("#pageTitle").html("Đăng nhập");
            var navigateLink = "";
            navigateLink += "<ul>";
            navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
            navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
            navigateLink += "    <li>Đăng nhập</li>";
            navigateLink += "</ul>";
            $("#navigate").html(navigateLink);
        }
        else if (file == "help.aspx") {
            $(".over:eq(6)").attr("src", "images/menu/hotro_b.png");
            if (gup('h') == "1") {
                $("#pageTitle").html("Hỗ trợ");
                var navigateLink = "";
                navigateLink += "<ul>";
                navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
                navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
                //navigateLink += "    <li><a href='" + file + "?h=1'>Hỗ trợ điện thoại</a></li>";
                navigateLink += "    <li>Hỗ trợ điện thoại</li>";
                navigateLink += "</ul>";
                $("#navigate").html(navigateLink);
            }
            else if (gup('h') == "2") {
                $("#pageTitle").html("Hỗ trợ");
                var navigateLink = "";
                navigateLink += "<ul>";
                navigateLink += "    <li><a href='./'>Trang chủ</a></li>";
                navigateLink += "    <li>&nbsp;&gt;&nbsp;</li>";
                //navigateLink += "    <li><a href='" + file + "?h=2'>Hỗ trợ máy tính</a></li>";
                navigateLink += "    <li>Hỗ trợ máy tính</li>";
                navigateLink += "</ul>";
                $("#navigate").html(navigateLink);
            }
        }
        ResetAll();
    }
    //
    CheckStatus();
    //
    function gup(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return results[1];
    }
    function containerText(index) {
        var temp = ["Dòng điện thoại F-Mobile", "Tập đoàn FPT", "Lợi ích khách"];
        return temp[index];
    }
    //
    function InfoText(info) {
        if (info == 12) {
            return "Hệ thống các cửa hàng";
        }
        else if (info == 13 || info == 29) {
            return "Trung tâm bảo hành";
        }
        else if (info == 14) {
            return "Văn phòng";
        }
        else if (info == 15) {
            return "Đăng ký làm đại lý";
        }
        else if (info == 17) {
            return "Hỗ trợ";
        }
    }
    function ProductText(product) {
        if (product == 1) {
            return "Sản phẩm mới";
        }
        else if (product == 2) {
            return "Sản phẩm HOT nhất";
        }
        else if (product == 3) {
            return "Sản phẩm bán chạy nhất";
        }
    }
    function NewsText(news) {
        if (news == 1) {
            return "Tin tức";
        }
        else if (news == 2) {
            return "Tuyển dụng";
        }
    }
    function MyphoneText(myPhone) {
        if (myPhone == "documentation.aspx") {
            return "Hướng dẫn sử dụng";
        }
        else if (myPhone == "contacts.aspx") {
            return "Danh bạ";
        }
        else if (myPhone == "datas.aspx") {
            return "Dữ liệu";
        }
    }
