﻿$(document).ready(function() {
    $(".tabbottom").click(function() {
        $(".tabbottom_selected").removeClass("tabbottom_selected").addClass("tabbottom");
        $(this).removeClass("tabbottom").addClass("tabbottom_selected");
        $(".lefttabbottomcontent_selected").removeClass("lefttabbottomcontent_selected").addClass("lefttabbottomcontent");
        $(".centertabbottomcontent_selected").removeClass("centertabbottomcontent_selected").addClass("centertabbottomcontent");
        $(".righttabbottomcontent_selected").removeClass("righttabbottomcontent_selected").addClass("righttabbottomcontent");
        $(".tabbottom_selected > .lefttabbottomcontent").removeClass("lefttabbottomcontent").addClass("lefttabbottomcontent_selected");
        $(".tabbottom_selected > .centertabbottomcontent").removeClass("centertabbottomcontent").addClass("centertabbottomcontent_selected");
        $(".tabbottom_selected > .righttabbottomcontent").removeClass("righttabbottomcontent").addClass("righttabbottomcontent_selected");
        $(".contentnationals_selected").removeClass("contentnationals_selected").addClass("contentnationals");
        var param = $(this).attr("rel").split('_');
        $("#contentnationals" + param[1]).removeClass("contentnationals").addClass("contentnationals_selected");
    });
    $("#firstpane div.menu_head").click(function() {
        $(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
        $(this).siblings();
    });
    $("#comboqh").change(function() {
    $("#combopx").html('<option value=\'0\'>Tất cả</option>');
        if ($(this).val() != 0) {
            $.getJSON("/tkdn/GetCommunes", { DistrictID: $(this).val() }, function(data) {
                populateDisDropdown($("#combopx"), data);
            });
        }
    });
    $("#combocatparent").change(function() {
        $("#combocatchild").html('<option value=\'0\'>Tất cả</option>');
        if ($(this).val() != 0) {
            $.getJSON("/tkdn/GetCatChild", { ParentID: $(this).val() }, function(data) {
                populateCatDropdown($("#combocatchild"), data);
            });
        }
    });
    $(".combocountries").change(function() {
        $("#result").html('<img src="/Content/Images/lightbox-ico-loading.gif" />');
        $.getJSON("/Nationals/GetListCountries", { ContinentID: $("#combocontinent").val(), AreaID: $("#comboarea").val(), LanguageID: $("#combolanguage").val(), OrganizationID: $("#comboorg").val() }, function(data) {
            $("#result").html('<img src="/Content/Images/ajax-loader.gif" />');
            fillNationals($("#result"), data);
            $("#loader").hide();
        });
    });
    $(".comboproducts").change(function() {
        $("#result").html('<img src="/Content/Images/lightbox-ico-loading.gif" />');
        $.getJSON("/Products/SearchItems", { FactoryID: $("#combofac").val(), CategoriesID: $("#combocatchild").val(), DistrictID: $("#combokv").val(), dh: $("#combodh").val() }, function(data) {
            fillProductsSearch($("#result"), data);
        });
    });
});
function fillNationals(select, data)
{   var result='';
    var i =0
    select.html('');
    $.each(data,function(id, value)
    {
    i++;
        result+='<div class="col_content_tab_bottom">' + i + '. <a href="/Nationals/Details/' + value.name + '" >'  + value.value + '</a></div>';

    });
    if (result == "") {
        result = "<center style=\"color:red\">Không tìm thấy quốc gia phù hợp</center>";
    }
     select.html(result);
 }
 function fillProductsSearch(select, data) {
     var result = '';
     var i = 0;    
     $.each(data, function(id, value) {
         i++;
         var _arrname = value.name.split(',');
         if (_arrname.length > 0) {
             result += "<div class=\"rowlistproduct\"><img src=\"" + _arrname[1] + "\" width=\"120px\" align=\"left\" height=\"80px\" style=\"margin: 10px\" />";
             result += "<strong><a href=\"/Products/Details/" + value.value + "\">" + _arrname[0] + "</a></strong>";
             result += "</div>";
         }
     });
     if (result == "") {
         result = "<center style=\"color:red\">Không tìm thấy sản phẩm phù hợp</center>";
     }
     select.html(result);     
 }
 function setVideoTitle(title) {
     $("#videotitle").html(title);
 }
function ShowPage(page)
{
    $("#result").html('<img src="/Content/Images/lightbox-ico-loading.gif" />');
    /*$.get("/tkdn/getListFactoryPage", { page: page } , function(data)
    {                    
        $("#result").html(data);
    });*/
    $.ajax({
    url: '/tkdn/getListFactoryPage',
    type: 'GET',        
    data: {page: page },     
    success: function(data){
    $("#result").html(data);
    },
    error: function(responseText){
    alert('Có lỗi phát sinh');
    }
    }); 
    }
    function populateCatDropdown(select, data) {
        var parentid = $("#combocatparent").val();
        select.html('<option value=\'' + parentid + '\'>Tất cả</option>');
        $.each(data, function(id, option) {
        select.append($('<option></option>').val(option.value).html(option.name));
});
}
function populateDisDropdown(select, data) {
    var parentid = $("#combocatparent").val();
    select.html('<option value=\'' + parentid + '\'>Tất cả</option>');
    $.each(data, function(id, option) {
        select.append($('<option></option>').val(option.value).html(option.name));
    });
}
function Checking()
{
    $("#result").html('');
    $("#searchcountry").hide();
}
function Checked()
{
    $("#searchcountry").show();        
}
function checkingvote()
{
$("#result").html('');
$("#smb").hide();
}
function checkedvote()
{
$("#smb").hide();
}
function tkdn_checking() {
    $("#view").hide();
    $("#result").html('<img src="/Content/Images/lightbox-ico-loading.gif" />');
    $("#btnSearch").hide();    
}
function tkdn_checked() {   
    $("#view").show();
    $("#result").show();
    $("#btnSearch").show();    
}
stuHover = function() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") != -1)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	var getElm = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<getElm.length; i++) {
		getElm[i].onmouseover=function() {
			this.className+=" iehover";
		}
		getElm[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);


