﻿function AjaxGetId(urlPath, idOfItem, idOfDiv, httpType) {
    var param = {
        Id: idOfItem,
        Method: httpType
    };
    var jsonParams = $.toJSON(param);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: urlPath,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
        },
        error: function() {
            ////alert("ajax has error");
        }
    });
}

function AjaxGetItemToDelete(urlPath, idOfItem, idToReplace, idOfDiv, httpType) {
    var param = {
        Id: idOfItem,
        IdToReplace: idToReplace,
        Method: httpType
    };
    var jsonParams = $.toJSON(param);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: urlPath,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function DeleteItem(path, itemId, replaceId, divId, httpType) {
    var param = {
        Id: itemId,
        ReplaceId: replaceId,
        Method: httpType
    };
    var jsonParams = $.toJSON(param)
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: path,
        contentType: "application/json",
        success: function(result) {
            $("#" + divId).html(result.toString());
        },
        error: function() {
            alert("Ajax function delete press error!");
        }
    });
}

function GetContentToEditCategory(urlPath, idOfItem, idOfDiv) {
    var jsonParams = $.toJSON(idOfItem);
    $.ajax({
        type: "POST",
        url: urlPath,
        data: jsonParams,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function GetContentToCreateCategory(urlPath, idOfDiv) {
    $.ajax({
        type: "POST",
        url: urlPath,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function CreateLocalPress(path, pathRedirect, divId, id, title, abs, body, cul, categoryId, httpType) {
    //alert("Address path is: " + path);
    var param = {
        Id: id,
        Title: title,
        Abstract: abs,
        Body: body,
        Culture: cul,
        PressCategoryId: categoryId,
        Method: httpType
    };
    var jsonParams = $.toJSON(param);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: path,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + divId).html(result.toString());
        },
        error: function() {
            alert("Ajax function create localPress has error");
        }
    });
}
function AjaxToCreateOrEditCategory(urlPath, idOfDiv, idOfCate, title, abs, body, cul, fatherId, httpType) {
    var param = { Id: idOfCate,
        Title: title,
        Abstract: abs,
        Body: body,
        Culture: cul,
        FatherId: fatherId,
        Method: httpType
    };
    var jsonParams = $.toJSON(param);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: urlPath,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function GetPress(path, pathRedirect, divId, id, categoryId, title, abs, body, cul, httpType) {
    var param = { Id: id,
        Title: title,
        Abstract: abs,
        Body: body,
        Culture: cul,
        Method: httpType,
        PressCategoryId: categoryId
    };
    var jsonParams = $.toJSON(param);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: path,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + divId).html(result.toString());
            if (httpType == "POST" && pathRedirect != "") {
                //alert("Đã lưu dữ liệu thành công");
                //var url = String(window.location); 
                //window.location = pathRedirect;
            }
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function GetPressRating(path, pathRedirect, divId, id, categoryId, title, abs, body, cul, showRating, httpType) {
    var param = { Id: id,
        Title: title,
        Abstract: abs,
        Body: body,
        Culture: cul,
        Method: httpType,
        PressCategoryId: categoryId,
        ShowRating: showRating
    };
    var jsonParams = $.toJSON(param);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: path,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + divId).html(result.toString());
            if (httpType == "POST" && pathRedirect != "") {
                //alert("Đã lưu dữ liệu thành công");
                //var url = String(window.location); 
                //window.location = pathRedirect;
            }
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function Redirect(path) {
    if (path != "") {
        window.location = path.toString();
    }
}



function AjaxToCreateOrEditItem(urlPath, idOfDiv, idOfCate, title, abs, body, cul, fatherId, service, rank, showRating, httpType) {
    var param = { Id: idOfCate,
        Title: title,
        Abstract: abs,
        Body: body,
        Culture: cul,
        CateogryId: fatherId,
        ServiceId: service,
        Rank: rank,
        ShowRating: showRating,
        Method: httpType
    };
    var jsonParams = $.toJSON(param);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: urlPath,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function GetMenu(urlPath, idOfDiv, menu, color) {
    $.ajax({
        type: "POST",
        url: urlPath,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
            if ((menu != null) && (color != null)) {
                ChangeMenuColor(menu, color);
            }
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function ChangeMenuColor(menu, color) {
        $('#home_page').removeclass('menu_orange');
        $('#company').removeclass('menu_orange');
        $('#service').removeclass('menu_orange');
        $('#partners').removeclass('menu_orange');
        $('#product').removeclass('menu_orange');
        $('#press').removeclass('menu_orange');
        $('#recruit').removeclass('menu_orange');
        $('#contact').removeclass('menu_orange');
    if (menu != null) {
        $('#' + menu.toString()).addClass('menu_' + color.toString());
        //   $('#company').addClass('menu_orange');
    }

    //    $('#' + menu.toString()).addClass('menu_' + color.toString());


}

function Service(urlPath, idOfDiv, idOfService) {
    var jsonParams = $.toJSON(idOfService);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: urlPath,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function ShowService(urlPath, idOfDiv, idOfService, divColor) {

    $("#service_info").removeClass('service_info');
    $("#service_info").removeClass('service_info_blue');
    $("#service_info").removeClass('service_info_orange');
    $("#service_info").removeClass('service_info_green');
    $("#service_info").removeClass('service_info_violet');

    $("#service_info").addClass('service_info_' + divColor.toString());

    var jsonParams = $.toJSON(idOfService);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: urlPath,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function ChangeMenuColor(menu, color) {
    //    $('#home_page').removeClass('menu_orange');
    //    $('#company').removeClass('menu_orange');
    //    $('#service').removeClass('menu_orange');
    //    $('#partners').removeClass('menu_orange');
    //    $('#product').removeClass('menu_orange');
    //    $('#press').removeClass('menu_orange');
    //    $('#recruit').removeClass('menu_orange');
    //    $('#contact').removeClass('menu_orange');

    //$('#company').addClass('menu_orange');

        $('#' + menu.toString()).addClass('menu_' + color.toString());
}

function AjaxToCreateOrEditPartner(urlPath, idOfDiv, idOfCate, title, link, abs, body, cul, fatherId, service, rank, showRating, httpType) {
    var param = { Id: idOfCate,
        Title: title,
        Link: link,
        Abstract: abs,
        Body: body,
        Culture: cul,
        CateogryId: fatherId,
        ServiceId: service,
        Rank: rank,
        ShowRating: showRating,
        Method: httpType
    };
    var jsonParams = $.toJSON(param);
    $.ajax({
        type: "POST",
        data: jsonParams,
        url: urlPath,
        dataType: "html",
        contentType: "application/json",
        success: function(result) {
            $("#" + idOfDiv).html(result.toString());
        },
        error: function() {
            //alert("ajax has error");
        }
    });
}

function ChangeClass(className) {
    $("#menu_tab_one").removeClass('border_top_one');
    $("#menu_tab_two").removeClass('border_top_two');
    $("#menu_tab_three").removeClass('border_top_three');

    $("#menu_tab_one").addClass('border_top_one');
    $("#menu_tab_two").addClass('border_top_two');
    $("#menu_tab_three").addClass('border_top_three');

    if (className.toString() == "one") {
        $("#menu_tab_one").removeClass('border_top_one');
    }
    else if (className.toString() == "three") {
        $("#menu_tab_three").removeClass('border_top_three');
    }
    else {
        $("#menu_tab_two").removeClass('border_top_two');
    }


}