function scrollWin() {
  window.scrollTo(0, 750);
}

function _loading(show) {
    if (show) {
        $(".blackBg, .loading").fadeIn('fast');
    } else {
        $(".blackBg, .loading").hide();
    }
}

function ajax_load(url,id) {
	var ajax;
	if (window.XMLHttpRequest) {
		ajax = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		alert("Trình duyệt của bạn không hỗ trợ XMLHTTP!");
	}
	if (ajax) {
		ajax.onreadystatechange = function() {
			document.getElementById(id).innerHTML = "<div align='center'><img src='images/loading.gif' border='0'><br><b>Đang xử lí... Vui lòng chờ</b></div>";
			if (ajax.readyState == 4 && ajax.status == 200) {
				document.getElementById(id).innerHTML = ajax.responseText;
			}
		}
		ajax.open("GET", url, true);
		ajax.send(null);
	}
}

var xhr;

function _pageload(url, data, id) {
    if (xhr && xhr.readystate != 4) {
        xhr.abort();
    }
	ajax_load(url,id);
    xhr = $.ajax({
        url: url,
        type: "GET",
        data: data,
        cache: false,
        beforeSend: function() {
            _loading(1);
            $('#loading').show();
            $('#notice').hide();
        },
        success: function(html) {
            _loading(0);
            $('#loading').hide();
            $('#' + id).html(html);
            $('#' + id).fadeIn('medium');
            _link_notajax();
        }
    });
}

function _link_notajax() {
    var location = window.location.href;
    if (location.indexOf("index.php?mod") > 0) {
        var location_split = location.split('/');
        var location_arr_length = location_split.length;
        var url_host = '';
        for (i = 0; i < location_arr_length - 1; i++) {
            url_host += location_split[i] + "/";
        }
        $('a').each(function() {
            var thishref = $(this).attr('href');
            $(this).removeAttr("rel").attr('href', url_host + thishref);
        });
    }
}
$(document).ready(function() {
    $('.item_dg_tooltip').tooltip();
    $('input[rel=ajax]').live('click', function() {
        var url = $(this).attr('href');
        if (url.indexOf('#') != -1) {
            var c_url = url.split('#');
            var module = c_url ? c_url[1] : '#';
            _pageload('index2.php?mod=' + module, '', 'BlockLeft');
            var mod_split = module.split('&');
            var mod_pri = mod_split ? mod_split[0] : module;
            var menuactive = mod_pri;
            if (mod_pri = 'event') {
                var act = mod_split[1];
                switch (act) {
                    case 'act=giftcode_rs':
                    case 'act=giftcode_week':
                    case 'act=giftcode_month':
                    case 'act=giftcode_tanthu':
                    case 'act=giftcode_change':
                    case 'act=giftcode_history':
                        menuactive = 'giftcode';
                        break;
                }
            }
            $('#mainmenu a[rel=menuajax]').removeClass('menuactive');
            $('#mainmenu a[href=#' + menuactive + ']').addClass('menuactive');
        }
    });
    $("#Login_Content").on('click', 'li[data-id]', function() {
        var char_choise = $(this).attr("data-id");
        $(".chars li[data-id]").removeClass('active');
        $(this).addClass('active');
        var dataString = "char_choise=" + char_choise;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=char_choise",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $('.loading').show();
            },
            complete: function() {
                $('.loading').hide();
                $(".dropdown-select").fadeOut('fast');
                $(".guideShow").removeClass('guideShow');
            },
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == "OK") {
                    $("#char_view").html(html_split[2]);
                    window.location.href = '#char_manager&' + (new Date).getTime();
                    $("#choise_char_msg").html(""); /* Quest Daily */
                    if (html_split[3] == 0) {
                        $("#qdl_un").removeClass().html('');
                        $("#char_note").removeClass();
                    } else {
                        $("#qdl_un").removeClass().addClass('badge').html(html_split[3]);
                        $("#char_note").removeClass().addClass('note-evt');
                    } /* Event > Nhan thuong */
                    if (html_split[4] == 0) {
                        $("#award_un").removeClass().html('');
                        $("#event_note").removeClass();
                    } else {
                        $("#award_un").removeClass().addClass('badge').html(html_split[4]);
                        $("#event_note").removeClass().addClass('note-evt');
                    }
                } else {
                    $("#choise_char_msg").html("<div class='form-error'>" + html + "</div>");
                }
            }
        });
        return false;
    });
    $("#reload_char").live('click', function() {
        var dataString = "";
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=char_choise",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $('#loading').show();
            },
            complete: function() {
                $('#loading').hide();
            },
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == "OK") {
					$("#char_view").html(html_split[2]);
                    window.location.href = '#char_manager&' + (new Date).getTime();
                    $("#choise_char_msg").html("html_split[2]"); 
					
                     /* Quest Daily */
                     if(html_split[3] == 0) {
                        $("#qdl_un").removeClass().html('');
                        $("#char_note").removeClass();
                    } else {
                        $("#qdl_un").removeClass().addClass('badge').html(html_split[3]);
                        $("#char_note").removeClass().addClass('note-evt');
                    }
                } else {
					_loading(0);
                    alert(html);
                }
            }
        });
        return false;
    });
    $("#btn_rs").live('click', function() {
        var dataString = "action=reset";
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=char_rs",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#rs_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#rs_err").html("");
                $("#btn_rs").attr('disabled', 'disabled');
            },
            complete: function() {
                $("#rs_loading").html("");
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if (html_split[1] == "OK") {
                    $("#rs_content").html("<div class='form-success'>" + html_split[2] + "</div>");
                } else {
                    $("#rs_err").html("<div class='form-error'>" + html + "</div>");
                }
                $("#btn_rs").removeAttr('disabled');
            }
        });
        return false;
    });
    $("#btn_rs_over").live('click', function() {
        var dataString = "action=reset_over";
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=char_rs",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#rs_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#rs_err").html("");
                $("#btn_rs_over").attr('disabled', 'disabled');
            },
            complete: function() {
                $("#rs_loading").html("");
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if (html_split[1] == "OK") {
                    $("#rs_content").html("<div class='form-success'>" + html_split[2] + "</div>");
                } else {
                    $("#rs_err").html("<div class='form-error'>" + html + "</div>");
                }
                $("#btn_rs_over").removeAttr('disabled');
            }
        });
        return false;
    });
    $("#btn_rsvip").live('click', function() {
		var tiente = $('input[name=tiente]:checked').val();
        var dataString = "action=reset_vip&tiente=" + tiente;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=char_rs",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#rs_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#rs_err").html("");
                $("#btn_rsvip").attr('disabled', 'disabled');
            },
            complete: function() {
                $("#rs_loading").html("");
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if (html_split[1] == "OK") {
                    $("#rs_content").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#head_gcoin").html(html_split[3].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_gcoin_km").html(html_split[4].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_vpoint").html(html_split[5].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                } else {
                    $("#rs_err").html("<div class='form-error'>" + html + "</div>");
                }
                $("#btn_rsvip").removeAttr('disabled');
            }
        });
        return false;
    });
    $("#btn_rsvip2").live('click', function(){
        var tiente = $('input[name=tiente]:checked').val();
        var dataString = "action=reset_vip2&tiente=" + tiente;
         $.ajax({
           type: "GET",
           url: "ajax_action.php?ajax=char_rs",
           data: dataString,
           cache: false,
           beforeSend: function() {
                $("#rs_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#rs_err").html("");
                $("#btn_rsvip2").attr('disabled','disabled');
           },
           complete: function() {
                $("#rs_loading").html("");
            
           },
           success: function(html) {
                 var html_split = html.split("<vweb>");
                 if(html_split[1] == "OK") {
                     $("#rs_content").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#head_gcoin").html(html_split[3].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_gcoin_km").html(html_split[4].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_vpoint").html(html_split[5].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                 } else {
                     $("#rs_err").html("<div class='form-error'>" + html + "</div>");
                 }
                 $("#btn_rsvip2").removeAttr('disabled');
           }
        });
        
        return false;
    });

    $("#btn_rs_over_vip").live('click', function() {
        var tiente = $('input[name=tiente]:checked').val();
        
        var dataString = "action=reset_over_vip&tiente=" + tiente;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=char_rs",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#rs_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#rs_err").html("");
                $("#btn_rs_over_vip").attr('disabled', 'disabled');
            },
            complete: function() {
                $("#rs_loading").html("");
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if (html_split[1] == "OK") {
                    $("#rs_content").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#head_gcoin").html(html_split[3].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_gcoin_km").html(html_split[4].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_vpoint").html(html_split[5].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                } else {
                    $("#rs_err").html("<div class='form-error'>" + html + "</div>");
                }
                $("#btn_rs_over_vip").removeAttr('disabled');
            }
        });
        return false;
    });
    $("#btn_trainpcpoint").live('click', function(){
        
        var dataString = "action=trainpcpoint";
        
         $.ajax({
           type: "GET",
           url: "ajax_action.php?ajax=char_rs",
           data: dataString,
           cache: false,
           beforeSend: function() {
                $("#rs_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#rs_err").html("");
                $("#btn_trainpcpoint").attr('disabled','disabled');
           },
           complete: function() {
                $("#rs_loading").html("");
            
           },
           success: function(html) {
                 var html_split = html.split("<vweb>");
                 if(html_split[1] == "OK") {
                     $("#rs_content").html("<div class='form-success'>" + html_split[2] + "</div>");
                 } else {
                     $("#rs_err").html("<div class='form-error'>" + html + "</div>");
                 }
                 $("#btn_trainpcpoint").removeAttr('disabled');
           }
        });
        
        return false;
    });
	
    $("#btn_daojb").live('click', function(){
        var dataString = "action=trainpcpoint";
        
         $.ajax({
           type: "GET",
           url: "ajax_action.php?ajax=char_rs",
           data: dataString,
           cache: false,
           beforeSend: function() {
                $("#jb_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#jb_err").html("");
                $("#btn_daojb").attr('disabled','disabled');
           },
           complete: function() {
                $("#jb_loading").html("");
            
           },
           success: function(html) {
                 var html_split = html.split("<vweb>");
                 if(html_split[1] == "OK") {
                     $("#jb_content").html("<div class='success'>" + html_split[2] + "</div>");
                 } else {
                     $("#jb_err").html("<div class='error'>" + html + "</div>");
                 }
                 $("#btn_daojb").removeAttr('disabled');
           }
        });
        
        return false;
    });
	
	$(document).on("click", "#btn_upresetday", function() {
		var rs_number = parseInt($("#uprs_number").val());
		var dataString = "action=upresetday&rs_number=" + rs_number;
		$.ajax({
			type: "GET",
			url: "ajax_action.php?ajax=char_rs",
			data: dataString,
			cache: false,
			beforeSend: function() {
				$("#rs_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
				$("#rs_err").html("");
				$("#btn_upresetday").attr('disabled','disabled');
			},
			complete: function() { $("#rs_loading").html(""); },
			success: function(html) {
				var html_split = html.split("<vweb>");
				if(html_split[1] == "OK") {
					Dialog(html_split[2], "success", "");
				} else {
					Dialog(html, "error", "");
				}
				$("#btn_upresetday").removeAttr('disabled');
			}
		});
		
		return false;
	});

    $("input[name='tiente']").live('click', function() {
        var tiente = $('input[name=tiente]:checked').val();
        if (tiente == 'gcoin') {
            $('#use_gcoin').show();
            $('#use_vpoint').hide();
        } else {
            $('#use_gcoin').hide();
            $('#use_vpoint').show();
        }
    });
    $("input[name='item']").live('change', function() {
        var x = $("input[name='item']:checked").attr('x');
        var y = $("input[name='item']:checked").attr('y');
        var itemperrow = Math.floor(8 / x);
        var itempercolumn = Math.floor(8 / y);
        var slgmax = itemperrow * itempercolumn;
        var slgitem_choise = "";
        for (i = 1; i <= slgmax; i++) {
            slgitem_choise += "<option value='" + i + "'>" + i + "</option>";
        }
        $('#slg').html(slgitem_choise);
    });
    var timeout = null;
    $(".addpoint").live('keyup', function() {
        clearTimeout(timeout);
        timeout = setTimeout(function() {
            var str = $("#str").val();
            var dex = $("#dex").val();
            var vit = $("#vit").val();
            var ene = $("#ene").val();
            var com = $("#com").val();
            $.get("ajax_action.php", {
                ajax: "addpoint",
                istr: str,
                idex: dex,
                ivit: vit,
                iene: ene,
                icom: com
            }, function(data) {
                var data_split = data.split("|");
                if (data_split[1] == "1") {
                    $("#point_total").html(data_split[2]);
                    $("#SubmitAddPoint").removeClass().addClass("btn btn-green btn-block btn-lg").removeAttr('disabled');
                    $("#addpoint_err").html("");
                } else {
                    if (!data_split[2]) {
                        $("#addpoint_err").html("<font color='red'>" + data + "</font>");
                    } else {
                        $("#point_total").html("<font color='red'>" + data_split[2] + "</font>");
                        $("#SubmitAddPoint").attr('disabled', 'disabled');
                        $("#addpoint_err").html("");
                    }
                }
                $("#str_view").html(data_split[3]);
                $("#dex_view").html(data_split[4]);
                $("#vit_view").html(data_split[5]);
                $("#ene_view").html(data_split[6]);
                $("#com_view").html(data_split[7]);
            });
        }, 500);
    });
    $("#chao").live('change', function() {
        var chao = $("#chao").val();
        var cre = $("#cre").val();
        var blue = $("#blue").val();
        var lvitem = $("#lvitem").html();
        $.get("ajax_action.php", {
            ajax: "itemuplv",
            ichao: chao,
            icre: cre,
            iblue: blue,
            ilvitem: lvitem
        }, function(data) {
            $("#percent").html(data);
        });
    });
    $("#cre").live('change', function() {
        var chao = $("#chao").val();
        var cre = $("#cre").val();
        var blue = $("#blue").val();
        var lvitem = $("#lvitem").html();
        $.get("ajax_action.php", {
            ajax: "itemuplv",
            ichao: chao,
            icre: cre,
            iblue: blue,
            ilvitem: lvitem
        }, function(data) {
            $("#percent").html(data);
        });
    });
    $("#blue").live('change', function() {
        var chao = $("#chao").val();
        var cre = $("#cre").val();
        var blue = $("#blue").val();
        var lvitem = $("#lvitem").html();
        $.get("ajax_action.php", {
            ajax: "itemuplv",
            ichao: chao,
            icre: cre,
            iblue: blue,
            ilvitem: lvitem
        }, function(data) {
            $("#percent").html(data);
        });
    });
    $(".epitem_reg").live('click', function() {
        var serial = $(this).attr("serial");
        var dataString = "action=reg&iserial=" + serial;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=event_epitem",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#loading_" + serial).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#err_" + serial).html("");
            },
            complete: function() {
                $("#loading_" + serial).html("");
            },
            success: function(html) {
                if (html == 'OK') {
                    $("#td_" + serial).html('Ðăng ký thành công');
                } else {
                    $("#err_" + serial).html(html);
                }
            }
        });
        return false;
    });
    $(".epitem_update").live('click', function() {
        var serial = $(this).attr("serial");
        var dataString = "action=up&iserial=" + serial;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=event_epitem",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#loading_" + serial).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#err_" + serial).html("");
            },
            complete: function() {
                $("#loading_" + serial).html("");
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if (html_split[1] == "OK") {
                    if (html_split[2] == "OK") {
                        $("#td_" + serial).html('<strong><font color="#00FFFF">Ðã hoàn thành</font></strong><br />' + html_split[3]).css("background-color", "#121212");
                    } else {
                        $("#err_" + serial).html(html_split[2]);
                    }
                } else {
                    $("#err_" + serial).html(html);
                }
            }
        });
        return false;
    });
    $(".lockitem_lock").live('click', function() {
        var serial = $(this).attr("serial");
        var vitri = $(this).attr("vitri");
        var opd = $("#opd_" + vitri).val();
        if (serial.length == 0) {
            alert('Serial Item không hợp lệ');
        } else if (opd.length == 0) {
            alert('Chưa nhập mật khẩu OPD');
        } else {
            var dataString = "action=lock&iserial=" + serial + "&vitri=" + vitri + "&opd=" + opd;
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=nv_lockitem",
                data: dataString,
                cache: false,
                beforeSend: function() {
                    $("#loading_" + vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                    $("#err_" + vitri).html("");
                },
                complete: function() {
                    $("#loading_" + vitri).html("");
                },
                success: function(html) {
                    var html_split = html.split("|");
                    if (html_split[1] == "OK") {
                        $("#lockinfo_" + vitri).html("<font color='blue'>Item đã bảo vệ</font>");
                        $("#button_" + vitri).html("<input type='button' vitri='" + vitri + "' class='lockitem_unlock' value='Hủy Bảo vệ Item' /> <font color='blue'>Miễn Phí</font>");
                        $("#head_gcoin").html(html_split[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                        $("#head_gcoin_km").html(html_split[3].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    } else {
                        $("#err_" + vitri).html(html);
                    }
                }
            });
        }
        return false;
    });
    $(".lockitem_unlock").live('click', function() {
        var vitri = $(this).attr("vitri");
        var opd = $("#opd_" + vitri).val();
        var price_lock = $("#price_lock").html();
        if (vitri.length == 0) {
            alert('Vị Trí Item không hợp lệ');
        } else if (opd.length == 0) {
            alert('Chưa nhập mật khẩu OPD');
        } else {
            var dataString = "action=unlock&vitri=" + vitri + "&opd=" + opd;
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=nv_lockitem",
                data: dataString,
                cache: false,
                beforeSend: function() {
                    $("#loading_" + vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                    $("#err_" + vitri).html("");
                },
                complete: function() {
                    $("#loading_" + vitri).html("");
                },
                success: function(html) {
                    var html_split = html.split("<vweb>");
                    if (html_split[1] == "OK") {
                        $("#lockinfo_" + vitri).html("<font color='red'><strong>Item chưa được bảo vệ</strong></font>");
                        $("#button_" + vitri).html("<input type='button' vitri='" + vitri + "' serial='" + html_split[2] + "' class='lockitem_lock' value='Bảo vệ Item' /> " + price_lock);
                    } else {
                        $("#err_" + vitri).html(html);
                    }
                }
            });
        }
        return false;
    });
    $(".bid_dgn").live('click', function() {
        var bidid = $(this).attr("bidid");
        var price_min = $(this).attr("price_min");
        var bid_mod = $(this).attr("bid_mod");
        var bid = $("#bid_" + bidid).val();
        bid = parseInt(bid);
        if (bid < price_min) {
            alert('Giá Đấu ' + bid + ' phải lớn hơn hoặc bằng Giá đấu nhỏ nhất');
        } else if (bid % bid_mod != 0) {
            alert('Giá đấu ' + bid + ' phải chia hết cho ' + bid_mod);
        } else {
            var dataString = "action=bid&bidid=" + bidid + "&bid=" + bid;
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=com_daugianguoc",
                data: dataString,
                cache: false,
                beforeSend: function() {
                    $("#loading_" + bidid).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                    $("#notice_" + bidid).html("");
                },
                complete: function() {
                    $("#loading_" + bidid).html("");
                },
                success: function(html) {
                    if (html == "OK") {
                        $("#notice_" + bidid).html("<font color='blue'><strong>Đã đấu : " + bid + " Gcoin</strong><br />Tài khoản của bạn bị <strong>đóng băng " + bid + " Gcoin</strong>. Kết thúc Đấu giá sẽ được hoàn trả.</font>");
                    } else {
                        $("#notice_" + bidid).html("<font color='red'><strong>" + html + "</strong></font>");
                    }
                }
            });
        }
        return false;
    });
    $(".reward_dgn").live('click', function() {
        var bidid = $(this).attr("bidid");
        var dataString = "action=reward&bidid=" + bidid;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=com_daugianguoc",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#loading_reward_" + bidid).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#reward_err_" + bidid).html("")
            },
            complete: function() {
                $("#loading_reward_" + bidid).html("");
            },
            success: function(html) {
                if (html == "OK") {
                    $("#reward_" + bidid).html("<font color='blue'><strong>Đã nhận</strong></font>");
                } else {
                    $("#reward_err_" + bidid).html("<font color='red'><strong>" + html + "</strong></font>");
                }
            }
        });
        return false;
    });
    $('.listbid').live('click', function() {
        $(this).fancybox({
            'titlePosition': 'inside',
            'transitionIn': 'none',
            'transitionOut': 'none'
        }).click();
        return false;
    });
    $(".dgn_bidding_view").live('click', function() {
        var bidid = $(this).attr('bidid');
        var dataString = "action=bidding_view&bidid=" + bidid;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=com_daugianguoc",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#loading_bidding_view_" + bidid).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#notice_bidding_view_" + bidid).html("");
            },
            complete: function() {
                $("#loading_bidding_view_" + bidid).html("");
            },
            success: function(html) {
                $("#notice_bidding_view_" + bidid).html(html);
            }
        });
        return false;
    });
    $(".close_bidding_view").live('click', function() {
        var bidid = $(this).attr('bidid');
        $('#notice_bidding_view_' + bidid).html("");
        return false;
    });
    $(".itembid_up").live('click', function() {
        var vitri = $(this).attr('vitri');
        $("#itembid_unactive_" + vitri).slideUp();
        $("#itembid_active_" + vitri).slideDown();
        return false;
    });
    $(".itembid_down").live('click', function() {
        var vitri = $(this).attr('vitri');
        $("#itembid_unactive_" + vitri).slideDown();
        $("#itembid_active_" + vitri).slideUp();
        return false;
    });
    $(".itembid_send").live('click', function() {
        var vitri = $(this).attr('vitri');
        var item_code = $(this).attr('item_code');
		
        var price_min = $("#price_min_" + vitri).val();
        price_min = parseInt(price_min);
        var price_max = $("#price_max_" + vitri).val();
        price_max = parseInt(price_max);
        var bidday = $("#bidday_" + vitri).val();
        bidday = parseInt(bidday);
        var itempass = $("#itempass_" + vitri).val();
		
        if (vitri < 0) {
            alert('Vị trí Item sai js');
        } else if (item_code.length != 32) {
            alert('Item Code sai');
        } else if (price_min <= 0) {
            alert('Giá khởi điểm ' + price_min + ' phải lớn hơn 0 Gcoin');
        } else if (price_min % 100 != 0) {
            alert('Giá khởi điểm ' + price_min + ' phải chia hết cho 100');
        } else if (price_max <= price_min) {
            alert('Giá mua đứt ' + price_max + ' phải lớn hơn giá khởi điểm ' + price_min);
        } else if (price_max % 100 != 0) {
            alert('Giá mua đứt ' + price_max + ' phải chia hết cho 100');
        } else {
            var dataString = "action=itembid_send&vitri=" + vitri + "&item_code=" + item_code + "&price_min=" + price_min + "&price_max=" + price_max + "&bidday=" + bidday + "&itempass=" + itempass;
			
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=com_daugia",
                data: dataString,
                cache: false,
                beforeSend: function() {
                    $("#itembid_send_loading_" + vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                    $("#itembid_send_view_" + vitri).html("");
                },
                complete: function() {
                    $("#itembid_send_loading_" + vitri).html("");
                },
                success: function(html) {
                    if (html == 'OK') {
                        var notice = "<font color='blue'>Item đã được đưa lên sàn đấu giá<br />";
                        if (itempass.length > 0) notice = notice + "Mật khẩu bảo vệ : <strong>" + itempass + "</strong>";
                        notice = notice + "</font><br /><br />";
                        $("#item_" + vitri).html(notice);
                    } else {
                        $("#itembid_send_view_" + vitri).html(html);
                    }
                }
            });
        }
        return false;
    });
    $(".bid_dg").live('click', function() {
        var bidid = $(this).attr("bidid");
        var bid_gcoin = $(this).attr("bid_gcoin");
        var price_max = $(this).attr("price_max");
        var bid = $("#bid_" + bidid).val();
        var itempass = $("#itempass_" + bidid).val();
        bidid = parseInt(bidid);
        bid_gcoin = parseInt(bid_gcoin);
        price_max = parseInt(price_max);
        bid = parseInt(bid);
        if (bid <= bid_gcoin) {
            alert('Giá Đấu ' + bid + ' Gcoin phải lớn hơn Giá đấu hiện tại ' + bid_gcoin);
        } else if (bid % 100 != 0) {
            alert('Giá đấu ' + bid + ' Gcoin phải chia hết cho 100');
        } else if (bid > price_max) {
            alert('Giá đấu ' + bid + ' Gcoin chỉ được bằng ' + price_max + ' Gcoin để mua đứt Item.');
        } else {
            var dataString = "action=bid&bidid=" + bidid + "&bid=" + bid + "&itempass=" + itempass + "&bid_gcoin=" + bid_gcoin + "&price_max=" + price_max;
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=com_daugia",
                data: dataString,
                cache: false,
                beforeSend: function() {
                    $("#loading_" + bidid).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                    $("#notice_" + bidid).html("");
                },
                complete: function() {
                    $("#loading_" + bidid).html("");
                },
                success: function(html) {
                    if (html == "OK") {
                        $("#notice_" + bidid).html("<font color='blue'><strong>Đã đấu : " + bid + " Gcoin</strong><br />Tài khoản của bạn bị <strong>đóng băng " + bid + " Gcoin</strong>. <br />Khi có người trả giá cao hơn, sẽ được hoàn trả.</font><br /><br />");
                    } else if (html == "OK2") {
                        $("#notice_" + bidid).html("<font color='blue'><strong>Bạn đã mua đứt Item. <br />Vui lòng vào <a href='#com&act=daugia&page=daugia_end' rel='ajax' >Đấu Giá đã tham gia</a> để lấy Item.</font><br /><br />");
                    } else {
                        $("#notice_" + bidid).html("<font color='red'><strong>" + html + "</strong></font>");
                    }
                }
            });
        }
        return false;
    });
    $(".reward_dg").live('click', function() {
        var bidid = $(this).attr("bidid");
        var dataString = "action=reward&bidid=" + bidid;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=com_daugia",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#loading_reward_" + bidid).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#reward_err_" + bidid).html("")
            },
            complete: function() {
                $("#loading_reward_" + bidid).html("");
            },
            success: function(html) {
                if (html == "OK") {
                    $("#reward_" + bidid).html("<font color='blue'><strong>Đã nhận</strong></font>");
                } else {
                    $("#reward_err_" + bidid).html("<font color='red'><strong>" + html + "</strong></font>");
                }
            }
        });
        return false;
    });
    $(".dg_giahan").live('click', function() {
        var bidid = $(this).attr("bidid");
        var bidday = $("#bidday_" + bidid).val();
        var dataString = "action=dg_giahan&bidid=" + bidid + "&bidday=" + bidday;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=com_daugia",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#loading_giahan_" + bidid).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#notice_view_" + bidid).html("")
            },
            complete: function() {
                $("#loading_giahan_" + bidid).html("");
            },
            success: function(html) {
                if (html == "OK") {
                    $("#item_" + bidid).html("<font color='blue'><strong>Đã gia hạn thành công</strong></font>");
                } else {
                    $("#notice_view_" + bidid).html("<font color='red'><strong>" + html + "</strong></font>");
                }
            }
        });
        return false;
    });
    $(".dg_rutitem").live('click', function() {
        var bidid = $(this).attr("bidid");
        var dataString = "action=dg_rutitem&bidid=" + bidid;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=com_daugia",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#loading_rutitem_" + bidid).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#notice_view_" + bidid).html("")
            },
            complete: function() {
                $("#loading_rutitem_" + bidid).html("");
            },
            success: function(html) {
                if (html == "OK") {
                    $("#item_" + bidid).html("<font color='blue'><strong>Đã rút Item thành công</strong></font>");
                } else {
                    $("#notice_view_" + bidid).html("<font color='red'><strong>" + html + "</strong></font>");
                }
            }
        });
        return false;
    });
    
	/*Doi Item ra JB Khoa*/
    $(".doijb_up").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#doijb_unactive_"+ vitri).slideUp();
        $("#doijb_active_"+ vitri).slideDown();
        
        return false;
    });
    
    $(".doijb_down").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#doijb_unactive_"+ vitri).slideDown();
        $("#doijb_active_"+ vitri).slideUp();
        
        return false;
    });
    
    $(".btn_doijb").live('click', function() {
        var vitri = $(this).attr('vitri');
        var item_code = $(this).attr('item_code');
        
		if(item_code.length != 32) {
            alert('Item Code sai JB');
        } else {
            var dataString = "action=doijb&vitri="+  vitri +"&item_code="+ item_code;
             
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=doijb",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#doijb_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#doijb_send_view_"+ vitri).html("");
                },
                complete: function() {
                     $("#doijb_send_loading_"+ vitri).html("");
                },
                success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                        $("#item_"+ vitri).html(html_split[2]);
						$("#itemdoijb_" + vitri).html(html_split[2]);
                    } else {
						$("#doijb_send_view_"+ vitri).html(html);
                    }
                    
                }
            });
        }
        
        return false;
    });
	/*End doi JB Khoa*/
	/*Thanh ly do*/
    $(".btn_thanhlydo").live('click', function() {
        var vitri = $(this).attr('vitri');
        var item_code = $(this).attr('item_code');
        
		if(item_code.length != 32) {
            alert('Item Code sai TL');
        } else {
            var dataString = "action=thanhlydo&vitri="+  vitri +"&item_code="+ item_code;
             
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=thanhlydo",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#thanhlydo_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#thanhlydo_send_view_"+ vitri).html("");
                },
                complete: function() {
                     $("#thanhlydo_send_loading_"+ vitri).html("");
                },
                success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                        $("#item_"+ vitri).html(html_split[2]);
						$("#itemthanhlydo_" + vitri).html(html_split[2]);
						location.reload();
                    } else {
						$("#thanhlydo_send_view_"+ vitri).html(html);
                    }
                    
                }
            });
        }
        
        return false;
    });
	/*End Thanh ly do*/
	
	/*Doi Ngoc*/
    $(".doingoc_up").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#doingoc_unactive_"+ vitri).slideUp();
        $("#doingoc_active_"+ vitri).slideDown();
        
        return false;
    });
    
    $(".doingoc_down").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#doingoc_unactive_"+ vitri).slideDown();
        $("#doingoc_active_"+ vitri).slideUp();
        
        return false;
    });
    
    $(".btn_doingoc").live('click', function() {
        var vitri = $(this).attr('vitri');
        var item_code = $(this).attr('item_code');
        
		if(item_code.length != 32) {
            alert('Item Code sai JB');
        } else {
            var dataString = "action=doingoc&vitri="+  vitri +"&item_code="+ item_code;
             
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=doingoc",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#doingoc_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#doingoc_send_view_"+ vitri).html("");
                },
                complete: function() {
                     $("#doingoc_send_loading_"+ vitri).html("");
                },
                success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                        $("#item_"+ vitri).html(html_split[2]);
						$("#itemdoingoc_" + vitri).html(html_split[2]);
                    } else {
						$("#doingoc_send_view_"+ vitri).html(html);
                    }
                    
                }
            });
        }
        
        return false;
    });
	/*End doi Ngoc*/
	
	/*Mua Ngoc*/
    $(".muangoc_up").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#muangoc_unactive_"+ vitri).slideUp();
        $("#muangoc_active_"+ vitri).slideDown();
        
        return false;
    });
    
    $(".muangoc_down").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#muangoc_unactive_"+ vitri).slideDown();
        $("#muangoc_active_"+ vitri).slideUp();
        
        return false;
    });
    
    $(".btn_muangoc").live('click', function() {
        var vitri = $(this).attr('vitri');
        var item_code = $(this).attr('item_code');
        
		if(item_code.length != 32) {
            alert('Item Code sai JB');
        } else {
            var dataString = "action=muangoc&vitri="+  vitri +"&item_code="+ item_code;
             
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=doingoc",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#muangoc_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#muangoc_send_view_"+ vitri).html("");
                },
                complete: function() {
                     $("#muangoc_send_loading_"+ vitri).html("");
                },
                success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                        $("#item_"+ vitri).html(html_split[2]);
						$("#itemmuangoc_" + vitri).html(html_split[2]);
                    } else {
						$("#muangoc_send_view_"+ vitri).html(html);
                    }
                    
                }
            });
        }
        
        return false;
    });
	/*End mua Ngoc*/
	
    $('.btn_webshop_exl_up').live('mouseenter', function(){
        /* var vitri = $(this).attr('vitri'); */
        $(this).fancybox();
    });
	
	/*Up level item bang JB Khoa*/
    $(".itemuplv_up").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#itemuplv_unactive_"+ vitri).slideUp();
        $("#itemuplv_active_"+ vitri).slideDown();
        
        return false;
    });
    
    $(".itemuplv_down").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#itemuplv_unactive_"+ vitri).slideDown();
        $("#itemuplv_active_"+ vitri).slideUp();
        
        return false;
    });
	
    $(".select_itemuplv").live('change', function() {
        var vitri = $(this).attr('vitri');
		var jbkhoa = $("#jbkhoa" + vitri).val();
		jbkhoa = parseInt(jbkhoa);
		var gcoin = $("#gcoin" + vitri).val();
		gcoin = parseInt(gcoin);
		var lvitem = $("#lvitem" + vitri).val();
		lvitem = parseInt(lvitem);
        $.get("ajax_action.php", {
            ajax: "itemuplv_view",
            ijbkhoa: jbkhoa,
			igcoin: gcoin,
			ilvitem: lvitem
        }, function(data) {
            $("#percent" + vitri).html(data);
        });
    });
    
    $(".btn_itemuplv").live('click', function() {
        var vitri = $(this).attr('vitri');
        var item_code = $(this).attr('item_code');
        var jbkhoa = $("#jbkhoa" + vitri).val();
		jbkhoa = parseInt(jbkhoa);
		var gcoin = $("#gcoin" + vitri).val();
        gcoin = parseInt(gcoin);
		
		if(item_code.length != 32) {
            alert('Item Code sai');
        } else if(jbkhoa < 0) {
            alert('JB Khóa phải lớn hơn 0.');
        } else if(gcoin < 0) {
            alert('Gcoin phải lớn hơn 0.');
        } else {
            var dataString = "action=itemuplv&vitri="+  vitri +"&item_code="+ item_code +"&jbkhoa="+ jbkhoa +"&gcoin="+ gcoin;
             
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=itemuplv",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#itemuplv_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#itemuplv_send_view_"+ vitri).html("");
                },
                complete: function() {
                     $("#itemuplv_send_loading_"+ vitri).html("");
                },
                success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                        $("#item_"+ vitri).html(html_split[2]);
						$("#itemuplv_" + vitri).html(html_split[2]);
						location.reload();
                    } else {
                        $("#itemuplv_send_view_"+ vitri).html(html);
                    }
                    
                }
            });
        }
        
        return false;
    });
	/*End up level item bang jb Khoa*/
	
    $(".award_receive").live('click', function() {
        var award_id = $(this).attr("award_id");
        var dataString = "action=award_receive&award_id=" + award_id;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=event_award",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#loading_" + award_id).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#err_" + award_id).html("")
            },
            complete: function() {
                $("#loading_" + award_id).html("");
            },
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == "OK") {
                    if (html_split[2] <= 0) {
                        $("#award_un").removeClass().html('');
                        $("#event_note").removeClass();
                    } else {
                        $("#award_un").html(html_split[2]);
                    }
                    $("#li_award_" + award_id).removeClass("award-received");
                    //$("#award_receive_" + award_id).addClass("received").html("Đã nhận Item thành công");
					_showPopup('OK','<span class=\'color-green\'>'+ html_split[3] +'</span>');
                } else {
                    //$("#err_" + award_id).html("<font color='red'><strong>" + html + "</strong></font>");
					_showPopup('Lỗi','<span class=\'color-red\'>'+ html +'</span>');
                }
            }
        });
        return false;
    });

    $(".btn_phucloi").live('click', function(){
        var qindex = $(this).attr("qindex");
        var inptab = $(this).attr("inptab");
        
         var dataString = "action=nhanthuong&qindex="+  qindex;
         
          $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=questdaily",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#loading_quest_"+ qindex).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#qsuccess").html("");
                 $("#qerror").html("");
                 $("#btn_quest_" + qindex).attr('disabled','disabled');
            },
            complete: function() {
                 $("#loading_quest_"+ qindex).html("");
            },
            success: function(html) {
                 
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                    
                    $("#head_gcoin").html(html_split[5].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_gcoin_km").html(html_split[6].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_vpoint").html(html_split[7].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_wcoin").html(html_split[8].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_pp").html(html_split[9].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    
                    $("#box_acc_bank_chao").html(html_split[10].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#box_acc_bank_cre").html(html_split[11].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#box_acc_bank_blue").html(html_split[12].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    
                    if(html_split[2] == 0) {
                        
                        $("#qdl_un").removeClass().html('');
                        $("#char_note").removeClass();
                        $("#nvhn_tab1").removeClass().html('');
                        $("#nvhn_tab2").removeClass().html('');
                        $("#nvhn_tab3").removeClass().html('');
                        $("#nvhn_tab4").removeClass().html('');
                        $(".btn_phucloi_stat").html('Đã hết số phần thưởng có thể nhận.');
                        
                    } else {
                        
                        $("#qdl_un").removeClass().addClass('badge').html(html_split[2]);
                        $("#char_note").removeClass().addClass('note-evt');
                        if(inptab == 1) {
                            var nvhn_tab_read = $("#nvhn_tab1").html();
                            var nvhn_tab_redure = parseInt(nvhn_tab_read) - 1;
                            $("#nvhn_tab1").removeClass().addClass('badge').html(nvhn_tab_redure);
                        } else if(inptab == 2) {
                            var nvhn_tab_read = $("#nvhn_tab2").html();
                            var nvhn_tab_redure = parseInt(nvhn_tab_read) - 1;
                            $("#nvhn_tab2").removeClass().addClass('badge').html(nvhn_tab_redure);
                        } else if(inptab == 3) {
                            var nvhn_tab_read = $("#nvhn_tab3").html();
                            var nvhn_tab_redure = parseInt(nvhn_tab_read) - 1;
                            $("#nvhn_tab3").removeClass().addClass('badge').html(nvhn_tab_redure);
                        } else if(inptab == 4) {
                            var nvhn_tab_read = $("#nvhn_tab4").html();
                            var nvhn_tab_redure = parseInt(nvhn_tab_read) - 1;
                            $("#nvhn_tab4").removeClass().addClass('badge').html(nvhn_tab_redure);
                        }
                        
                    }
                    
                    $("#nvhn_finish").html(html_split[3]);
                    
                    $("#btn_spanquest_" + qindex).html("<span class='tag tag-blue'>Đã nhận</span>");
                    
                    _showPopup('Nhận thưởng nhiệm vụ','<span class=\'color-green\'>'+ html_split[4] +'</span>');
                    
                 } else {
                    $("#btn_quest_" + qindex).removeAttr('disabled');

                    _showPopup('Lỗi','<span class=\'color-red\'>'+ html +'</span>');
                 }
                 
            }
         });
         
        
        return false;
    });
	
    $("#btn_pl_change").live('click', function() {
        var pl_point_change = $('#pl_point_change').val();
        if (!pl_point_change) pl_point_change = 0;
        pl_point_change = parseInt(pl_point_change);
        var pl_point_to = $('#pl_point_to').val();
        if (pl_point_change == 0) {
            $("#plchange_error").html("<div class='form-error'>Điểm Phúc Lợi muốn đổi phải lớn hơn 0.</div>");
        } else {
            var dataString = "action=plchange&pl_point_to=" + pl_point_to + "&pl_point_change=" + pl_point_change;
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=questdaily",
                data: dataString,
                cache: false,
                beforeSend: function() {
                    $("#loading_pl_change").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                    $("#plchange_success").html("");
                    $("#plchange_error").html("");
                    $("#btn_pl_change").attr('disabled', 'disabled');
                },
                complete: function() {
                    $("#loading_pl_change").html("");
                },
                success: function(html) {
                    var html_split = html.split("|");
                    if (html_split[1] == "OK") {
                        $("#pl_point").html(html_split[2]);
                        $("#plchange_success").html("<div class='form-success'>" + html_split[3] + "</div>");
                    } else {
                        $("#plchange_error").html("<div class='form-error'>" + html + "</div>");
                    }
                    $("#btn_pl_change").removeAttr('disabled');
                }
            });
        }
        return false;
    });

    $("#btn_pl_ban").live('click', function(){
        var plpoint_ban = $("#plpoint_ban").val();
        var plpoint_gcoin = $("#plpoint_gcoin").val();
        
         var dataString = "action=banpl&plpoint_ban=" + plpoint_ban + "&plpoint_gcoin=" + plpoint_gcoin;
         
          $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=chopl",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#banpl_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#banpl_view").html("");
                 $("#btn_pl_ban").attr('disabled','disabled');
            },
            complete: function() {
                 $("#banpl_loading").html("");
                  $("#btn_pl_ban").removeAttr('disabled');
            },
            success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                    
                    $("#plpoint").html(html_split[2]);
                    $("#banpl_view").html("<div class='form-success'>"+ html_split[3] +"</div>");
                    $("#plpoint_ban").val(0);
                    $("#plpoint_gcoin").val(0);
                        
                 } else {
                    $("#banpl_view").html("<div class='form-error'>"+ html +"</div>");
                 }
            }
         });
        return false;
    });
    
    $(".btn_plmua").live('click', function(){
        var store_id = $(this).attr("store_id");
        
         var dataString = "action=muapl&store_id=" + store_id;
         
          $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=chopl",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#muapl_view_" + store_id).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#btn_plmua_" + store_id).attr('disabled','disabled');
            },
            complete: function() {
                  
            },
            success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                    
                    $("#muapl_view_" + store_id).html("<div class='form-success'>"+ html_split[2] +"</div>");
                    $("#btn_plmua_" + store_id).val("Đã mua");
                        
                 } else {
                    $("#muapl_view_" + store_id).html("<div class='form-error'>"+ html +"</div>");
                    $("#btn_plmua_" + store_id).removeAttr('disabled');
                 }
            }
         });
        return false;
    });
    
    $(".btn_huyban").live('click', function(){
        var store_id = $(this).attr("store_id");
        
         var dataString = "action=huyban&store_id=" + store_id;
         
          $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=chopl",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#huypl_view_" + store_id).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#btn_huyban_" + store_id).attr('disabled','disabled');
            },
            complete: function() {
                  
            },
            success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                    
                    $("#huypl_view_" + store_id).html("<div class='form-success'>"+ html_split[2] +"</div>");
                    $("#plpoint").html(html_split[3]);
                    $("#td_huyban_" + store_id).html("Đã hủy");
                        
                 } else {
                    $("#huypl_view_" + store_id).html("<div class='form-error'>"+ html +"</div>");
                    $("#btn_huyban_" + store_id).removeAttr('disabled');
                 }
            }
         });
        return false;
    });
	
	//Webshop
    $(".webshop_up").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#webshop_unactive_"+ vitri).slideUp();
        $("#webshop_active_"+ vitri).slideDown();
        
        return false;
    });
    
    $(".webshop_down").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#webshop_unactive_"+ vitri).slideDown();
        $("#webshop_active_"+ vitri).slideUp();
        
        return false;
    });
	
    function func_webshop_exl(vitri) {
		var action = 'webshop';
		var act = $("#shoptype_" + vitri).val();
		var opt = $("#opt_" + vitri).val();
		opt = parseInt(opt);
		var lvl = $("#lvl_" + vitri).val();
		lvl = parseInt(lvl);
        var slg = $("#slg_" + vitri).val();
        slg = parseInt(slg);
        var giagoc = $("#giagoc_" + vitri).val();
        giagoc = parseInt(giagoc);
        var Opt1 = '';
        if ($("#Opt1_" + vitri).is(":checked")) {
            var Opt1 = 0;
        }
        var Opt2 = '';
        if ($("#Opt2_" + vitri).is(":checked")) {
            var Opt2 = 1;
        }
        var Opt3 = '';
        if ($("#Opt3_" + vitri).is(":checked")) {
            var Opt3 = 2;
        }
        var Opt4 = '';
        if ($("#Opt4_" + vitri).is(":checked")) {
            var Opt4 = 3;
        }
        var Opt5 = '';
        if ($("#Opt5_" + vitri).is(":checked")) {
            var Opt5 = 4;
        }		
        var Opt6 = '';
        if ($("#Opt6_" + vitri).is(":checked")) {
            var Opt6 = 5;
        }
        var Opt7 = 0;
        if ($("#Opt7_" + vitri).is(":checked")) {
            var Opt7 = 1;
        }
        
        $.get("ajax_action.php", {
            ajax: "webshop_view",
			iaction: action,
			iact: act,
			iopt: opt,
            ilvl: lvl,
			islg: slg,
			igiagoc: giagoc,
			iOpt1: Opt1,
			iOpt2: Opt2,
			iOpt3: Opt3,
			iOpt4: Opt4,
			iOpt5: Opt5,
			iOpt6: Opt6,
			iOpt7: Opt7
			
        }, function(data) {
            $("#sum" + vitri).html(data);
            $("#webshop_send_view_"+ vitri).html(" ");
        });
    }
    
    $('.webshop_exl_exl').live('click', function(){
        var vitri = $(this).attr('vitri');
        func_webshop_exl(vitri);
    });
    
    $('.webshop_exl_lvl, .webshop_exl_slg, .webshop_exl_opt').live('change', function(){
        var vitri = $(this).attr('vitri');
        func_webshop_exl(vitri);
    });
	
    $(".webshop").live('click', function() {
        var vitri = $(this).attr('vitri');
		var act = $(this).attr('act');
		var pass2 = $("#pass2_" + vitri).val();
		var opt = $("#opt_" + vitri).val();
		opt = parseInt(opt);
		var lvl = $("#lvl_" + vitri).val();
		lvl = parseInt(lvl);
        var slg = $("#slg_" + vitri).val();
        slg = parseInt(slg);
        var Opt1 = '';
        if ($("#Opt1_" + vitri).is(":checked")) {
            var Opt1 = 0;
        }
        var Opt2 = '';
        if ($("#Opt2_" + vitri).is(":checked")) {
            var Opt2 = 1;
        }
        var Opt3 = '';
        if ($("#Opt3_" + vitri).is(":checked")) {
            var Opt3 = 2;
        }
        var Opt4 = '';
        if ($("#Opt4_" + vitri).is(":checked")) {
            var Opt4 = 3;
        }
        var Opt5 = '';
        if ($("#Opt5_" + vitri).is(":checked")) {
            var Opt5 = 4;
        }		
        var Opt6 = '';
        if ($("#Opt6_" + vitri).is(":checked")) {
            var Opt6 = 5;
        }
        var Opt7 = 0;
        if ($("#Opt7_" + vitri).is(":checked")) {
            var Opt7 = 1;
        }
		
		if(pass2.length == 0) {
            alert('Chưa nhập mật khẩu web');
        } else if(slg <= 0) {
            alert('Số lượng item mua phải lớn hơn 0.');
        } else {
            var dataString = "action=webshop&act="+  act +"&vitri="+  vitri +"&pass2="+ pass2 +"&lvl="+ lvl +"&slg="+ slg +"&Opt1="+ Opt1 +"&Opt2="+ Opt2 +"&Opt3="+ Opt3 +"&Opt4="+ Opt4 +"&Opt5="+ Opt5 +"&Opt6="+ Opt6 +"&Opt7="+ Opt7 +"&opt="+ opt;
             
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=webshop",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#webshop_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#webshop_send_view_"+ vitri).html("");
					 $("#webshop_" + vitri).attr('disabled','disabled');
                },
                complete: function() {
                     $("#webshop_send_loading_"+ vitri).html("");
					 $("#webshop_" + vitri).removeAttr('disabled');
                },
                success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                        $("#webshop_send_view_"+ vitri).html(html_split[2]);
                        $("#head_gcoin").html(html_split[3].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
						/*location.reload();*/
                    } else {
                        $("#webshop_send_view_"+ vitri).html(html);
						$("#webshop_" + vitri).removeAttr('disabled');
                    }
                    
                }
            });
        }
        
        return false;
    });
	
	//Webshop Set
    $(".webshopset_up").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#webshopset_unactive_"+ vitri).slideUp();
        $("#webshopset_active_"+ vitri).slideDown();
        
        return false;
    });
    
    $(".webshopset_down").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#webshopset_unactive_"+ vitri).slideDown();
        $("#webshopset_active_"+ vitri).slideUp();
        
        return false;
    });
	
    function func_webshopset_exl(vitri) {
		var action = 'webshopset';
		var opt = $("#opt_" + vitri).val();
		opt = parseInt(opt);
		var lvl = $("#lvl_" + vitri).val();
		lvl = parseInt(lvl);
        var giagoc = $("#giagoc_" + vitri).val();
        giagoc = parseInt(giagoc);
        var Opt1 = '';
        if ($("#Opt1_" + vitri).is(":checked")) {
            var Opt1 = 0;
        }
        var Opt2 = '';
        if ($("#Opt2_" + vitri).is(":checked")) {
            var Opt2 = 1;
        }
        var Opt3 = '';
        if ($("#Opt3_" + vitri).is(":checked")) {
            var Opt3 = 2;
        }
        var Opt4 = '';
        if ($("#Opt4_" + vitri).is(":checked")) {
            var Opt4 = 3;
        }
        var Opt5 = '';
        if ($("#Opt5_" + vitri).is(":checked")) {
            var Opt5 = 4;
        }		
        var Opt6 = '';
        if ($("#Opt6_" + vitri).is(":checked")) {
            var Opt6 = 5;
        }
        var Opt7 = 0;
        if ($("#Opt7_" + vitri).is(":checked")) {
            var Opt7 = 1;
        }
        
        $.get("ajax_action.php", {
            ajax: "webshopset_view",
			iaction: action,
			iopt: opt,
            ilvl: lvl,
			igiagoc: giagoc,
			iOpt1: Opt1,
			iOpt2: Opt2,
			iOpt3: Opt3,
			iOpt4: Opt4,
			iOpt5: Opt5,
			iOpt6: Opt6,
			iOpt7: Opt7
			
        }, function(data) {
            $("#sum" + vitri).html(data);
        });
    }
    
    $('.webshopset_exl_exl').live('click', function(){
        var vitri = $(this).attr('vitri');
        func_webshopset_exl(vitri);
    });
    
    $('.webshopset_exl_lvl, .webshopset_exl_opt').live('change', function(){
        var vitri = $(this).attr('vitri');
        func_webshopset_exl(vitri);
    });
	
    $(".webshopset").live('click', function() {
        var vitri = $(this).attr('vitri');
		var pass2 = $("#pass2_" + vitri).val();
		var opt = $("#opt_" + vitri).val();
		opt = parseInt(opt);
		var lvl = $("#lvl_" + vitri).val();
		lvl = parseInt(lvl);
        var Opt1 = '';
        if ($("#Opt1_" + vitri).is(":checked")) {
            var Opt1 = 0;
        }
        var Opt2 = '';
        if ($("#Opt2_" + vitri).is(":checked")) {
            var Opt2 = 1;
        }
        var Opt3 = '';
        if ($("#Opt3_" + vitri).is(":checked")) {
            var Opt3 = 2;
        }
        var Opt4 = '';
        if ($("#Opt4_" + vitri).is(":checked")) {
            var Opt4 = 3;
        }
        var Opt5 = '';
        if ($("#Opt5_" + vitri).is(":checked")) {
            var Opt5 = 4;
        }		
        var Opt6 = '';
        if ($("#Opt6_" + vitri).is(":checked")) {
            var Opt6 = 5;
        }
        var Opt7 = 0;
        if ($("#Opt7_" + vitri).is(":checked")) {
            var Opt7 = 1;
        }
		
		if(pass2.length == 0) {
            alert('Chưa nhập mật khẩu web');
        } else {
            var dataString = "action=webshopset&vitri="+ vitri +"&pass2="+ pass2 +"&lvl="+ lvl +"&Opt1="+ Opt1 +"&Opt2="+ Opt2 +"&Opt3="+ Opt3 +"&Opt4="+ Opt4 +"&Opt5="+ Opt5 +"&Opt6="+ Opt6 +"&Opt7="+ Opt7 +"&opt="+ opt;
             
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=webshopset",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#webshopset_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#webshopset_send_view_"+ vitri).html("");
					 $("#webshopset_" + vitri).attr('disabled','disabled');
                },
                complete: function() {
                     $("#webshopset_send_loading_"+ vitri).html("");
					 $("#webshopset_" + vitri).removeAttr('disabled');
                },
                success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                        $("#item_"+ vitri).html(html_split[2]);
						/*location.reload();*/
                    } else {
                        $("#webshopset_send_view_"+ vitri).html(html);
						$("#webshopset_" + vitri).removeAttr('disabled');
                    }
                    
                }
            });
        }
        
        return false;
    });
	
	//WebshopKC
    function func_webshopkc_exl(vitri) {
		var action = 'webshopkc';
		var act = $("#shoptype_" + vitri).val();
		var opt = $("#opt_" + vitri).val();
		opt = parseInt(opt);
		var lvl = $("#lvl_" + vitri).val();
		lvl = parseInt(lvl);
        var slg = $("#slg_" + vitri).val();
        slg = parseInt(slg);
        var giagoc = $("#giagoc_" + vitri).val();
        giagoc = parseInt(giagoc);
        var Opt1 = '';
        if ($("#Opt1_" + vitri).is(":checked")) {
            var Opt1 = 0;
        }
        var Opt2 = '';
        if ($("#Opt2_" + vitri).is(":checked")) {
            var Opt2 = 1;
        }
        var Opt3 = '';
        if ($("#Opt3_" + vitri).is(":checked")) {
            var Opt3 = 2;
        }
        var Opt4 = '';
        if ($("#Opt4_" + vitri).is(":checked")) {
            var Opt4 = 3;
        }
        var Opt5 = '';
        if ($("#Opt5_" + vitri).is(":checked")) {
            var Opt5 = 4;
        }		
        var Opt6 = '';
        if ($("#Opt6_" + vitri).is(":checked")) {
            var Opt6 = 5;
        }
        var Opt7 = 0;
        if ($("#Opt7_" + vitri).is(":checked")) {
            var Opt7 = 1;
        }
        
        $.get("ajax_action.php", {
            ajax: "webshop_view",
			iaction: action,
			iact: act,
			iopt: opt,
            ilvl: lvl,
			islg: slg,
			igiagoc: giagoc,
			iOpt1: Opt1,
			iOpt2: Opt2,
			iOpt3: Opt3,
			iOpt4: Opt4,
			iOpt5: Opt5,
			iOpt6: Opt6,
			iOpt7: Opt7
			
        }, function(data) {
            $("#sum" + vitri).html(data);
        });
    }
    
    $('.webshopkc_exl_exl').live('click', function(){
        var vitri = $(this).attr('vitri');
        func_webshopkc_exl(vitri);
    });
    
    $('.webshopkc_exl_lvl, .webshopkc_exl_slg, .webshopkc_exl_opt').live('change', function(){
        var vitri = $(this).attr('vitri');
        func_webshopkc_exl(vitri);
    });
	
    $(".webshopkc").live('click', function() {
        var vitri = $(this).attr('vitri');
		var act = $(this).attr('act');
		var pass2 = $("#pass2_" + vitri).val();
		var opt = $("#opt_" + vitri).val();
		opt = parseInt(opt);
		var lvl = $("#lvl_" + vitri).val();
		lvl = parseInt(lvl);
        var slg = $("#slg_" + vitri).val();
        slg = parseInt(slg);
        var Opt1 = '';
        if ($("#Opt1_" + vitri).is(":checked")) {
            var Opt1 = 0;
        }
        var Opt2 = '';
        if ($("#Opt2_" + vitri).is(":checked")) {
            var Opt2 = 1;
        }
        var Opt3 = '';
        if ($("#Opt3_" + vitri).is(":checked")) {
            var Opt3 = 2;
        }
        var Opt4 = '';
        if ($("#Opt4_" + vitri).is(":checked")) {
            var Opt4 = 3;
        }
        var Opt5 = '';
        if ($("#Opt5_" + vitri).is(":checked")) {
            var Opt5 = 4;
        }		
        var Opt6 = '';
        if ($("#Opt6_" + vitri).is(":checked")) {
            var Opt6 = 5;
        }
        var Opt7 = 0;
        if ($("#Opt7_" + vitri).is(":checked")) {
            var Opt7 = 1;
        }
		
		if(pass2.length == 0) {
            alert('Chưa nhập mật khẩu web');
        } else if(slg <= 0) {
            alert('Số lượng item mua phải lớn hơn 0.');
        } else {
            var dataString = "action=webshopkc&act="+  act +"&vitri="+  vitri +"&pass2="+ pass2 +"&lvl="+ lvl +"&slg="+ slg +"&Opt1="+ Opt1 +"&Opt2="+ Opt2 +"&Opt3="+ Opt3 +"&Opt4="+ Opt4 +"&Opt5="+ Opt5 +"&Opt6="+ Opt6 +"&Opt7="+ Opt7 +"&opt="+ opt;
             
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=webshop",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#webshopkc_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#webshopkc_send_view_"+ vitri).html("");
					 $("#webshopkc_" + vitri).attr('disabled','disabled');
                },
                complete: function() {
                     $("#webshopkc_send_loading_"+ vitri).html("");
					 $("#webshopkc_" + vitri).removeAttr('disabled');
                },
                success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                        $("#item_"+ vitri).html(html_split[2]);
						/*location.reload();*/
                    } else {
                        $("#webshopkc_send_view_"+ vitri).html(html);
						$("#webshopkc_" + vitri).removeAttr('disabled');
                    }
                    
                }
            });
        }
        
        return false;
    });
	
	//Webshop Set KC
    function func_webshopsetkc_exl(vitri) {
		var action = 'webshopsetkc'
		var opt = $("#opt_" + vitri).val();
		opt = parseInt(opt);
		var lvl = $("#lvl_" + vitri).val();
		lvl = parseInt(lvl);
        var giagoc = $("#giagoc_" + vitri).val();
        giagoc = parseInt(giagoc);
        var Opt1 = '';
        if ($("#Opt1_" + vitri).is(":checked")) {
            var Opt1 = 0;
        }
        var Opt2 = '';
        if ($("#Opt2_" + vitri).is(":checked")) {
            var Opt2 = 1;
        }
        var Opt3 = '';
        if ($("#Opt3_" + vitri).is(":checked")) {
            var Opt3 = 2;
        }
        var Opt4 = '';
        if ($("#Opt4_" + vitri).is(":checked")) {
            var Opt4 = 3;
        }
        var Opt5 = '';
        if ($("#Opt5_" + vitri).is(":checked")) {
            var Opt5 = 4;
        }		
        var Opt6 = '';
        if ($("#Opt6_" + vitri).is(":checked")) {
            var Opt6 = 5;
        }
        var Opt7 = 0;
        if ($("#Opt7_" + vitri).is(":checked")) {
            var Opt7 = 1;
        }
        
        $.get("ajax_action.php", {
            ajax: "webshopset_view",
			iaction: action,
			iopt: opt,
            ilvl: lvl,
			igiagoc: giagoc,
			iOpt1: Opt1,
			iOpt2: Opt2,
			iOpt3: Opt3,
			iOpt4: Opt4,
			iOpt5: Opt5,
			iOpt6: Opt6,
			iOpt7: Opt7
			
        }, function(data) {
            $("#sum" + vitri).html(data);
        });
    }
    
    $('.webshopsetkc_exl_exl').live('click', function(){
        var vitri = $(this).attr('vitri');
        func_webshopsetkc_exl(vitri);
    });
    
    $('.webshopsetkc_exl_lvl, .webshopsetkc_exl_opt').live('change', function(){
        var vitri = $(this).attr('vitri');
        func_webshopsetkc_exl(vitri);
    });
	
    $(".webshopsetkc").live('click', function() {
        var vitri = $(this).attr('vitri');
		var pass2 = $("#pass2_" + vitri).val();
		var opt = $("#opt_" + vitri).val();
		opt = parseInt(opt);
		var lvl = $("#lvl_" + vitri).val();
		lvl = parseInt(lvl);
        var Opt1 = '';
        if ($("#Opt1_" + vitri).is(":checked")) {
            var Opt1 = 0;
        }
        var Opt2 = '';
        if ($("#Opt2_" + vitri).is(":checked")) {
            var Opt2 = 1;
        }
        var Opt3 = '';
        if ($("#Opt3_" + vitri).is(":checked")) {
            var Opt3 = 2;
        }
        var Opt4 = '';
        if ($("#Opt4_" + vitri).is(":checked")) {
            var Opt4 = 3;
        }
        var Opt5 = '';
        if ($("#Opt5_" + vitri).is(":checked")) {
            var Opt5 = 4;
        }		
        var Opt6 = '';
        if ($("#Opt6_" + vitri).is(":checked")) {
            var Opt6 = 5;
        }
        var Opt7 = 0;
        if ($("#Opt7_" + vitri).is(":checked")) {
            var Opt7 = 1;
        }
		
		if(pass2.length == 0) {
            alert('Chưa nhập mật khẩu web');
        } else {
            var dataString = "action=webshopsetkc&vitri="+ vitri +"&pass2="+ pass2 +"&lvl="+ lvl +"&Opt1="+ Opt1 +"&Opt2="+ Opt2 +"&Opt3="+ Opt3 +"&Opt4="+ Opt4 +"&Opt5="+ Opt5 +"&Opt6="+ Opt6 +"&Opt7="+ Opt7 +"&opt="+ opt;
             
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=webshopset",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#webshopsetkc_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#webshopsetkc_send_view_"+ vitri).html("");
					 $("#webshopsetkc_" + vitri).attr('disabled','disabled');
                },
                complete: function() {
                     $("#webshopsetkc_send_loading_"+ vitri).html("");
					 $("#webshopsetkc_" + vitri).removeAttr('disabled');
                },
                success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                        $("#item_"+ vitri).html(html_split[2]);
						/*location.reload();*/
                    } else {
                        $("#webshopsetkc_send_view_"+ vitri).html(html);
						$("#webshopsetkc_" + vitri).removeAttr('disabled');
                    }
                    
                }
            });
        }
        
        return false;
    });
	
    $('#xoay_longcondor').live('click', function() {
        var dataString = "action=xoay_longcondor";
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=maychao",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#xoay_longcondor_msg").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
            },
            complete: function() {},
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == "OK") {
                    if (html_split[2] == 1) {
                        $("#xoay_longcondor_info").html("<div class='form-success'>" + html_split[3] + "</div>");
                        $("#xoay_longcondor_msg").html("");
                    } else if (html_split[2] == 2) {
                        $("#xoay_longcondor_info").html("<div class='form-error'>" + html_split[3] + "</div>");
                        $("#xoay_longcondor_msg").html("");
                    } else {
                        $("#xoay_longcondor_msg").html("<div class='form-success'>" + html_split[3] + "</div>");
                    }
                } else {
                    $("#xoay_longcondor_msg").html("<div class='form-error'>" + html + "</div>");
                }
            }
        });
        return false;
    });
    $('#trader_quay').live('click', function() {
        var item = $(this).attr('item');
        var tyle = $(this).attr('tyle');
        var dataString = "action=trader_quay&item=" + item + "&tyle=" + tyle;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=maychaos",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#trader_quay_msg").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
            },
            complete: function() {},
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == "OK") {
                    if (html_split[2] == 1) {
                        $("#trader_quay_info").html("<div class='form-success'>" + html_split[3] + "</div>");
                        $("#trader_quay_msg").html("");
                    } else if (html_split[2] == 2) {
                        $("#trader_quay_info").html("<div class='form-error'>" + html_split[3] + "</div>");
                        $("#trader_quay_msg").html("");
                    } else {
                        $("#trader_quay_msg").html("<div class='form-success'>" + html_split[3] + "</div>");
                    }
                } else {
                    $("#trader_quay_msg").html("<div class='form-error'>" + html + "</div>");
                }
            }
        });
        return false;
    });
	
    $('#kickket').live('click', function() {
        var opd = $('#opd').val();
        var dataString = "opd=" + opd;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=kickket",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#kickket_msg").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
            },
            complete: function() {},
            success: function(html) {
                if (html == 'OK') {
                    $("#kickket_msg").html("<div class='form-success'>Đã gửi thông tin Kích Kẹt. Bạn vui lòng đợi trong 5 giây rồi vào Game.</div>");
                } else {
                    $("#kickket_msg").html("<div class='form-error'>" + html + "</div>");
                }
            }
        });
        return false;
    });
    $('input[name=money_type]').live('click', function() {
        var money_type = $('input[name=money_type]:checked').val();
        $.get("ajax_action.php", {
            ajax: "relax_lo",
            action: 'change_money',
            imoney_type: money_type
        }, function(data) {
            $("#lo_diem").html(data);
        });
        $("#diemlo_money").html("0");
    });
    $("#lo_diem").live('change', function() {
        var lo_diem = $("#lo_diem").val();
        var money_type = $('input[name=money_type]:checked').val();
        $.get("ajax_action.php", {
            ajax: "relax_lo",
            ilo_diem: lo_diem,
            imoney_type: money_type
        }, function(data) {
            $("#diemlo_money").html(data);
        });
    });
    $('#relax_lo_danh').live('click', function() {
        var lo_so = $('#lo_so').val();
        var lo_diem = $('#lo_diem').val();
        var money_type = $('input[name=money_type]:checked').val();
        var dataString = "action=danhlo&lo_so=" + lo_so + "&lo_diem=" + lo_diem + "&money_type=" + money_type;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=relax_lo",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#lo_msg").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#relax_lo_danh").removeClass().addClass("NotAccept").attr('disabled', 'disabled');
            },
            complete: function() {},
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == 'OK') {
                    $("#lo_msg").html("<div class='form-success'>Đã đánh " + lo_diem + " điểm lô con " + lo_so + ".<br />Chúc bạn may mắn.</div>");
                    if (money_type == 2) {
                        $("#lo_vpoint").html(html_split[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                        $("#head_vpoint").html(html_split[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    } else {
                        $("#lo_gcoin").html(html_split[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                        $("#head_gcoin").html(html_split[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    }
                    $("#lo_so").val(0);
                    $("#lo_diem").val(0);
                    $("#diemlo_money").html("0");
                } else {
                    $("#lo_msg").html("<div class='form-error'>" + html + "</div>");
                }
                $("#relax_lo_danh").removeClass().addClass("Accept").removeAttr('disabled');
            }
        });
        return false;
    });
    $('#btn_lo_history').live('click', function() {
        var dataString = "action=lo_history";
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=relax_lo",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#lo_history").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
            },
            complete: function() {},
            success: function(html) {
                $("#lo_history").html("<div class='info_noimg'>" + html + "</div>");
            }
        });
        return false;
    });
    $('input[name=money_type_de]').live('click', function() {
        var money_type = $('input[name=money_type_de]:checked').val();
        $.get("ajax_action.php", {
            ajax: "relax_de",
            action: 'change_money',
            imoney_type: money_type
        }, function(data) {
            $("#de_diem").html(data);
        });
    });
    $('#relax_de_danh').live('click', function() {
        var de_so = $('#de_so').val();
        var de_diem = $('#de_diem').val();
        var money_type = $('input[name=money_type_de]:checked').val();
        var dataString = "action=danhde&de_so=" + de_so + "&de_diem=" + de_diem + "&money_type=" + money_type;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=relax_de",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#de_msg").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#relax_de_danh").removeClass().addClass("NotAccept").attr('disabled', 'disabled');
            },
            complete: function() {},
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == 'OK') {
                    if (money_type == 2) {
                        var money_name = "Gcoin";
                        $("#de_vpoint").html(html_split[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                        $("#head_vpoint").html(html_split[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    } else {
                        var money_name = "Gcent";
                        $("#de_gcoin").html(html_split[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                        $("#head_gcoin").html(html_split[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    }
                    $("#de_msg").html("<div class='form-success'>Đã đánh " + de_diem + ".000 " + money_name + " đề con " + de_so + ".<br />Chúc bạn may mắn.</div>");
                    $("#de_so").val(0);
                    $("#de_diem").val(0);
                } else {
                    $("#de_msg").html("<div class='form-error'>" + html + "</div>");
                }
                $("#relax_de_danh").removeClass().addClass("Accept").removeAttr('disabled');
            }
        });
        return false;
    });
    $('#btn_de_history').live('click', function() {
        var dataString = "action=de_history";
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=relax_de",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#de_history").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
            },
            complete: function() {},
            success: function(html) {
                $("#de_history").html("<div class='info_noimg'>" + html + "</div>");
            }
        });
        return false;
    });
    $('.danhhieu_choise').live('click', function() {
        var danhhieu_type = $(this).attr("danhhieu_type");
        var danhhieu_id = $(this).attr("danhhieu_id");
        var dataString = "action=danhhieu_choise&danhhieu_type=" + danhhieu_type + "&danhhieu_id=" + danhhieu_id;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=char_danhhieu",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#msg_" + danhhieu_type + "_" + danhhieu_id).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#btn_" + danhhieu_type + "_" + danhhieu_id).attr('disabled', 'disabled');
            },
            complete: function() {},
            success: function(html) {
                if (html == 'OK') {
                    $("#msg_" + danhhieu_type + "_" + danhhieu_id).html("");
                    $("#danhhieu_col_" + danhhieu_type + "_" + danhhieu_id).html("<font color='red'>Đã kích hoạt.<br />Hãy đổi nhân vật trong Game để có hiệu lực.</font>");
                } else {
                    $("#msg_" + danhhieu_type + "_" + danhhieu_id).html("Lỗi : " + html);
                    $("#btn_" + danhhieu_type + "_" + danhhieu_id).removeAttr('disabled');
                }
            }
        });
        return false;
    });
    $('.event2_doi').live('click', function() {
        var event_type = $(this).attr('event_type');
        var phuongthuc = $(this).attr('phuongthuc');
        var dataString = "action=event2_doi&event_type=" + event_type + "&phuongthuc=" + phuongthuc;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=event2",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#loading_btn_event2_doi_" + event_type + "_" + phuongthuc).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#btn_event2_doi_" + event_type + "_" + phuongthuc).attr('disabled', 'disabled');
            },
            complete: function() {
                $("#loading_btn_event2_doi_" + event_type + "_" + phuongthuc).html("");
            },
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == 'OK') {
                    var item_source_data = html_split[3];
                    var item_source_arr = $.parseJSON(item_source_data);
                    for ($i = 0; $i <= 3; $i++) {
                        $(".item_source_" + $i + "_slg").html(item_source_arr[$i]['slg_api']);
                        if (item_source_arr[$i]['slg_api'] == 0) {
                            if ($i == 1) {
                                $(".event2_doi").attr('disabled', 'disabled');
                            }
                            if ($i == 2) {
                                $(".event2_doi[phuongthuc='2']").attr('disabled', 'disabled');
                                $(".event2_doi[phuongthuc='3']").attr('disabled', 'disabled');
                            }
                            if ($i == 3) {
                                $(".event2_doi[phuongthuc='3']").attr('disabled', 'disabled');
                            }
                            $(".item_source_" + $i).addClass('disabled');
                        }
                    }
                    switch (event_type) {
                        case 'type1':
                            var zen_update = html_split[4];
                            $(".event2_zen").html(zen_update);
                            break;
                        case 'type3':
                            break;
                    }
                    if (html_split[7] != '') {
                        var gcoin_update = html_split[5];
                        var gcoin_km_update = html_split[6];
                        var gcoin_total = html_split[7];
                        $("#head_gcoin").html(gcoin_update.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                        $("#head_gcoin_km").html(gcoin_km_update).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
                        $(".event2_gc").html(gcoin_total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    }
                    $("#head_wcoin").html(html_split[9].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_pp").html(html_split[10].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    $("#head_pp_extra").html(html_split[11].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    var dadoi_count = html_split[12];
                    var dadoi_count_arr = $.parseJSON(dadoi_count);
                    if (dadoi_count_arr['tylemax'][event_type] > 0) {
                        $("#tab_event2_" + event_type).html(dadoi_count_arr['tylemax'][event_type]);
                    } else {
                        $("#tab_event2_" + event_type).removeClass().html('');
                        $(".btn_event2_doi_" + event_type).attr('disabled', 'disabled');
                    }
                    $("#event2_dadoi_all_" + event_type).html(dadoi_count_arr['all'][event_type]);
                    $("#event2_dadoi_daily_all_" + event_type).html(dadoi_count_arr['daily'][event_type]['all']);
                    $("#event2_dadoi_daily_" + phuongthuc + "_" + event_type).html(dadoi_count_arr['daily'][event_type][phuongthuc]);
                    _showPopup('Thông tin đổi Event', '<span class=\'color-green\'>' + html_split[2] + '</span>');
                } else if (html_split[1] == 'Err') {
                    if (html_split[2] == 0) {
                        _showPopup('Lỗi', '<span class=\'color-red\'>' + html_split[3] + '</span>');
                    }
                } else {
                    _showPopup('Lỗi', '<span class=\'color-red\'>' + html + '</span>');
                    $("#btn_event2_doi_" + event_type + "_" + phuongthuc).removeAttr('disabled');
                }
            }
        });
        return false;
    });

	//*Begin warehousesafe*/
    $(".warehouse_up").live('click', function() {
        var vitri = $(this).attr('vitri');
		$("#warehouse_unactive_"+ vitri).slideUp();
        $("#warehouse_active_" + vitri).slideDown();
        return false;
    });
    $(".warehouse_down").live('click', function() {
        var vitri = $(this).attr('vitri');
        $("#warehouse_active_" + vitri).slideUp();
		$("#warehouse_unactive_"+ vitri).slideDown();
        return false;
    });
	
    $(".warehouse_move").live('click', function() {
        var warehouse_type = $(this).attr("warehouse_type"); /* 0 : WareHouse | 1 : WareHouse safe */
        var itemcode = $(this).attr("itemcode"); /* itemcode : Code Item */
        var key = $(this).attr("key");
        if (warehouse_type == 0) {
            var time_gui = 0;
        } else {
            var time_gui = $(this).attr("time_gui");
        }
        var dataString = "action=warehouse_move&warehouse_type=" + warehouse_type + "&itemcode=" + itemcode + "&time_gui=" + time_gui;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=warehousesafe",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $(".warehouse_move").removeClass("warehouse_move").addClass("warehouse_moving");
                $("#" + itemcode + key).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
            },
            complete: function() {
                $("#" + itemcode + key).html("");
            },
            success: function(html) {
                $(".warehouse_moving").removeClass("warehouse_moving").addClass("warehouse_move");
                var html_split = html.split("|");
                if (html_split[1] == "OK") {
                    if (warehouse_type == '0') {
                        $(".warehouse_move[itemcode=" + itemcode + "][key=" + key + "]").attr({
                            warehouse_type: '1',
                            time_gui: html_split[2]
                        });
                        $(".warehouse_move[itemcode=" + itemcode + "][key=" + key + "]").appendTo("#warehouse_safe_list");
                        $("#item_in_warehouse_safe").html(html_split[3]);
                        $("#menu_warehouse_safe_item").html(html_split[3]);
                        if (html_split[4] == '0') {
                            $("#acc_note").removeClass();
                        } else {
                            $("#acc_note").addClass("note-evt");
                        }
                    } else {
                        $(".warehouse_move[itemcode=" + itemcode + "][key=" + key + "]").attr("warehouse_type", '0');
                        $(".warehouse_move[itemcode=" + itemcode + "][key=" + key + "]").appendTo("#warehouse_list");
                        $("#item_in_warehouse_safe").html(html_split[2]);
                        $("#menu_warehouse_safe_item").html(html_split[2]);
                        if (html_split[3] == '0') {
                            $("#acc_note").removeClass();
                        } else {
                            $("#acc_note").addClass("note-evt");
                        }
                    }
                } else {
                    _showPopup('Hòm Đồ An Toàn', '<span class=\'color-red\'>' + html + '</span>');
                }
            }
        });
        return false;
    });
	
    $("#warehouse_extra").live('click', function(){
        var dataString = "action=warehouse_extra";
        var r = confirm("Bạn đang thực hiện mua thêm vị trí items trên Hòm Đồ Ảo!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
			$.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=warehousesafe",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#warehouse_extra_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
            },
            complete: function() {
                 $("#warehouse_extra_loading").html("");
            },
            success: function(html) {
                 var html_split = html.split("|");
                 
                 if(html_split[1] == "OK") {
                    $("#menu_warehouse_secure_slot").html(html_split[2]);
                    $("#page_warehouse_secure_slot").html(html_split[2]);

					} else {
                    _showPopup('Hòm Đồ An Toàn','<span class=\'color-red\'>'+ html +'</span>');
                 }
            }
         });
		}
        return false;
    });
    /*End warehousesafe*/
	
	/* gia han */
	$(".retimeitem_up").live('click', function() {
        var vitri = $(this).attr('vitri');  
        $("#retimeitem_unactive_"+ vitri).slideUp();
        $("#retimeitem_active_"+ vitri).slideDown();
        return false;
    });
	$(".retimeitem_down").live('click', function() {
        var vitri = $(this).attr('vitri');
        
        $("#retimeitem_unactive_"+ vitri).slideDown();
        $("#retimeitem_active_"+ vitri).slideUp();
        
        return false;
    });
	
	$(".retimeitem_send").live('click', function() {
        var vitri = $(this).attr('vitri');
        var item_code = $(this).attr('item_code');
        var retimeitemday = $("#retimeitemday_"+ vitri).val();
            retimeitemday = parseInt(retimeitemday);
        var pass2 = $("#pass2_" + vitri).val();  
		
		if(item_code.length != 32) {
            alert('Item Code sai');
        }else if(retimeitemday<1){
			alert('Ngày gia hạn phải lớn hơn 1');
		}else if(pass2.length==0){
			alert('Vui lòng nhập mật khẩu cấp 2');
		}
		else {
            var dataString = "action=RetimeItem&vitri="+  vitri +"&item_code="+ item_code +"&pass2="+ pass2 +"&retimeitemday="+ retimeitemday +"&GiaHan=1";
            $.ajax({
                type: "GET",
                url: "ajax_action.php?ajax=item_giahan",
                data: dataString,
                cache: false,
                beforeSend: function() {
                     $("#retimeitem_send_loading_"+ vitri).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                     $("#retimeitem_send_view_"+ vitri).html("");
                },
                complete: function() {
                    
                },
				success: function(html) {
					 var html_split = html.split("|");
					 if(html_split[1] == "OK") {
					   $("#retimeitem_send_loading_"+ vitri).html("<div class='success'>"+ html_split[2] +"</div>");
						
					 } else {
						 $("#retimeitem_send_loading_"+ vitri).html("<div class='error'>"+ html +"</div>");
					 }	  
						
				} 
            });
        }
        
        return false;
    });
	/* end gia han */	

	$(".type").live('click', function() {
        var typeid = $('#type').val();
		if(typeid.length==0){
			$("#type_play").html('<input type=text name=num_bet1 id=num_bet1 size=3 maxlength=2 class="form-style num_bet1" style=width:25px/>');
		}
        else if(typeid=='lo'||typeid=='de'){
			$("#type_play").html('<input type=text name=num_bet1 id=num_bet1 size=3 maxlength=2 class="form-style num_bet1" style=width:25px/>');
		}else if(typeid=='loxien2'){
			$("#type_play").html('<input type="text" name="num_bet1" id="num_bet1" size="3" maxlength="2" class="num_bet1" style="width:45px"/> <input type="text" name="num_bet2" id="num_bet2" size="3" maxlength="2" class="num_bet2" style="width:45px"/>');
		}else if(typeid=='loxien3'){
			$("#type_play").html('<input type="text" name="num_bet1" id="num_bet1" size="3" maxlength="2" class="num_bet1" style="width:45px"/> <input type="text" name="num_bet2" id="num_bet2" size="3" maxlength="2" class="num_bet2" style="width:45px"/> <input type="text" name="num_bet3" id="num_bet3" size="3" maxlength="2" class="num_bet3" style="width:45px"/>');
		}else if(typeid=='loxien4'){
			$("#type_play").html('<input tye="text" name="num_bet1" id="num_bet1" size="3" maxlength="2" class="num_bet1" style="width:45px"/> <input type="text" name="num_bet2" id="num_bet2" size="3" maxlength="2" class="num_bet2" style="width:45px"/> <input type="text" name="num_bet3" id="num_bet3" size="3" maxlength="2" class="num_bet3" style="width:45px"/> <input type="text" name="num_bet4" id="num_bet4" size="3" maxlength="2" class="num_bet4" style="width:45px"/>');
		}
        return false;
    });
	$(".lode_ghiso").live('click', function(){
		var typeplay = $('.type').val();
		var type_money = $('.type_money').val();
		var num_bet1,num_bet2,num_bet3,num_bet4;
		if(typeplay=='lo'||typeplay=='de'){
			num_bet1=parseInt($('#num_bet1').val());
			num_bet2=0;num_bet3=0,num_bet4=0;
			$typeplayshow ='Đánh Đề';
		 }else if(typeplay=='loxien2'){
			num_bet1=parseInt($('#num_bet1').val());
			num_bet2=parseInt($('#num_bet2').val());
			num_bet3=0,num_bet4=0;
			$typeplayshow ='Đánh Lô Xiên 2';
		 }else if(typeplay=='loxien3'){
			num_bet1=parseInt($('#num_bet1').val());
			num_bet2=parseInt($('#num_bet2').val());
			num_bet3=parseInt($('#num_bet3').val());
			num_bet4=0;
			$typeplayshow ='Đánh Lô Xiên 3';
		 }else if(typeplay=='loxien4'){
			num_bet1=parseInt($('#num_bet1').val());
			num_bet2=parseInt($('#num_bet2').val());
			num_bet3=parseInt($('#num_bet3').val());
			num_bet4=parseInt($('#num_bet4').val());	
			$typeplayshow ='Đánh Lô Xiên 4';
		 }
		var num_point = parseInt($('#num_point').val());	
		
		var Datavweb = "action=Play_Lode&typeplay="+ typeplay +"&num_bet1="+ num_bet1 +"&num_bet2="+ num_bet2 +"&num_bet3="+ num_bet3 +"&num_bet4="+ num_bet4 +"&num_point="+ num_point +"&type_money="+ type_money;
		$.ajax({
			type: "GET",
			url: "ajax_action.php?ajax=lode_vweb",
			data: Datavweb,
			cache: false,
			beforeSend: function() {
				$("#loading_lode").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
				$("#err_loading_lode").html("")
			},
			complete: function() {
                 $("#loading_lode").html("");
            },
			success: function(html) {
                 var html_split = html.split("<vweb>");
                 if(html_split[1] == "OK") {
                    $ContentShow = html_split[2];
                    Dialog($ContentShow);
                 } else {
                     Dialog(html);
                 }	  
					
            } 
		});		 
		return false;
	});
	$("#check_bet").live('click', function(){
		var lode_id=$(this).attr('lode_id');
		var datebet_id=$(this).attr('datebet_id');
		var Datavweb = "action=CheckBet&lode_id="+ lode_id;
		$.ajax({
			type: "GET",
			url: "ajax_action.php?ajax=lode_vweb",
			data: Datavweb,
			cache: false,
			beforeSend: function() {
				$("#loading_lode").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
				$("#err_loading_lode").html("")
			},
			complete: function() {
                 $("#loading_lode").html("");
            },
			success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                    Dialog(html_split[2]);
					$("#load_content").load("index2.php?mod=relax&act=ketqua&date_bet="+ datebet_id);
                 } else {
                     Dialog(html);
                 }	  
					
            } 
		});		 
		return false;
	});

    $("#btn_upgradevip").live('click', function() {
        var pass2 = $('input[name=pass2]').val();
        var vip_type = $('select[name=type] option:selected').val();
        var vip_plan = $('select[name=plan] option:selected').val();
        var dataString = "action=upgrade_vip&pass2=" + pass2 + "&type=" + vip_type + "&plan=" + vip_plan;
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=vip_system",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#uv_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#uv_err").html("");
                $("#btn_upgradevip").attr('disabled', 'disabled');
            },
            complete: function() {
                $("#uv_loading").html("");
            },
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == "OK") {
                    $("#uv_content").html("<div class='form-success'>" + html_split[2] + "</div>");
                } else {
                    $("#uv_err").html("<div class='form-error'>" + html + "</div>");
                }
                $("#btn_upgradevip").removeAttr('disabled');
            }
        });
        return false;
    });
    $("#btn_vip_receivepl").live('click', function() {
        var dataString = "action=receivepl";
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=vip_system",
            data: dataString,
            cache: false,
            beforeSend: function() {
                $("#uv_loading").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                $("#uv_content").html("");
                $("#btn_vip_receivepl").attr('disabled', 'disabled');
            },
            complete: function() {
                $("#uv_loading").html("");
            },
            success: function(html) {
                var html_split = html.split("|");
                if (html_split[1] == "OK") {
                    $("#uv_content").html("<div class='form-success'>" + html_split[2] + "</div>");
                } else {
                    $("#uv_content").html("<div class='form-error'>" + html + "</div>");
                    $("#btn_vip_receivepl").removeAttr('disabled');
                }
            }
        });
        return false;
    });
    $(".vip ul li").live('click', function() {
        $("li.active").removeClass("active");
        $(this).addClass('active');
        var plan = $(this).attr('id');
        if (plan == 'day') {
            $(".plan_7").hide();
            $(".plan_30").hide();
        } else if (plan == 'week') {
            $(".plan_7").show();
            $(".plan_30").hide();
        } else if (plan == 'month') {
            $(".plan_30").show();
        }
    });
	
    $('#btn_vipvweb_buy').live('click', function(){
        var vip_period = $('#vip_period').val();
		var buy_vip_type = $('#buy_vip_type').val();
		var character = $('input[name=character]').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=vipvweb&vip_period="+ vip_period +"&character="+ character +"&pass2="+ pass2 +"&buy_vip_type="+ buy_vip_type;
        var r = confirm("Bạn đang thực hiện đăng ký VIP cho tài khoản!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=vipvweb",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_vipvweb").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#vipvweb_buy").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_vipvweb").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#vipvweb_buy").removeAttr('disabled');
                    } else {
                    $("#msg_vipvweb").html("<div class='form-error'>" + html + "</div>");
                    $("#vipvweb_buy").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $(".select_svvip").live('change', function() {
		var svvip_choise = $("#svvip_choise").val();
		svvip_choise = parseInt(svvip_choise);
		var viplv_choise = $("#viplv_choise").val();
		viplv_choise = parseInt(viplv_choise);
        $.get("ajax_action.php", {
            ajax: "svvip_view",
            isvvip_choise: svvip_choise,
			iviplv_choise: viplv_choise
        }, function(data) {
            $("#sumvip").html(data);
        });
    });
	
    $('#btn_svvip_buy').live('click', function(){
        var svvip_choise = $('#svvip_choise').val();
		var viplv_choise = $('#viplv_choise').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=svvip_choise&svvip_choise="+ svvip_choise +"&viplv_choise="+ viplv_choise +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện đăng ký Server VIP!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=svvip",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_svvip").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#svvip_buy").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_svvip").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#svvip_buy").removeAttr('disabled');
                    
                    $("#head_gcoin").html(html_split[3].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                } else {
                    $("#msg_svvip").html("<div class='form-error'>" + html + "</div>");
                    $("#svvip_buy").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_buats_buy').live('click', function(){
        var buats_choise = $('#buats_choise').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=buats_choise&buats_choise="+ buats_choise +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện mua Bùa Thiên Sứ!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=char_buats",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_buats").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#buats_buy").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_buats").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#buats_buy").removeAttr('disabled');
                    
                    $("#head_gcoin").html(html_split[3].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                } else {
                    $("#msg_buats").html("<div class='form-error'>" + html + "</div>");
                    $("#buats_buy").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_buass2_buy').live('click', function(){
        var buass2_choise = $('#buass2_choise').val();
		var bua_day_choise = $('#bua_day_choise').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=buass2_choise&buass2_choise="+ buass2_choise +"&bua_day_choise="+ bua_day_choise +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện mua Bùa!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=char_buass2",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_buass2").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#buass2_buy").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_buass2").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#buass2_buy").removeAttr('disabled');
                    
                    $("#head_gcoin").html(html_split[3].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                } else {
                    $("#msg_buass2").html("<div class='form-error'>" + html + "</div>");
                    $("#buass2_buy").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_spin_buy').live('click', function(){
        var money_type = $('#money_type').val();
		var pass2 = $('input[name=pass2]').val();
		var spinnumber = $('input[name=spinnumber]').val();
        var dataString = "action=spin_paid&money_type="+ money_type +"&pass2="+ pass2 +"&spinnumber="+ spinnumber;
        var r = confirm("Bạn đang thực hiện mua số Lần Quay!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=vongquay",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_spin").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#spin_buy").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_spin").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#spin_buy").removeAttr('disabled');
                } else {
                    $("#msg_spin").html("<div class='form-error'>" + html + "</div>");
                    $("#spin_buy").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_relife2kimcuong').live('click', function(){
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=relife2kimcuong&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện mua Đổi Relifes sang Kim Cương!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=relife2kimcuong",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_relife2kimcuong").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#relife2kimcuong").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_relife2kimcuong").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#relife2kimcuong").removeAttr('disabled');
                    
                } else {
                    $("#msg_relife2kimcuong").html("<div class='form-error'>" + html + "</div>");
                    $("#relife2kimcuong").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_master2point').live('click', function(){
		var character = $('input[name=character]').val();
		var point_doi = $('input[name=point_doi]').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=master2point&character="+ character +"&point_doi="+ point_doi +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện mua Đổi Master sang Point!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=master2point",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_master2point").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#master2point").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_master2point").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#master2point").removeAttr('disabled');
                    
                } else {
                    $("#msg_master2point").html("<div class='form-error'>" + html + "</div>");
                    $("#master2point").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_master2goblinpoint').live('click', function(){
		var character = $('input[name=character]').val();
		var point_doi = $('input[name=point_doi]').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=master2goblinpoint&character="+ character +"&point_doi="+ point_doi +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện mua Đổi Master sang GoblinPoint!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=master2goblinpoint",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_master2goblinpoint").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#master2goblinpoint").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_master2goblinpoint").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#master2goblinpoint").removeAttr('disabled');
                    
                } else {
                    $("#msg_master2goblinpoint").html("<div class='form-error'>" + html + "</div>");
                    $("#master2goblinpoint").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_muathenap').live('click', function(){
        var loaithe = $('#loaithe').val();
		var menhgia = $('#menhgia').val();
		var slg = $('#slg').val();
        var dataString = "action=muathenap&loaithe="+ loaithe +"&menhgia="+ menhgia +"&slg="+ slg;
        var r = confirm("Bạn đang thực hiện mua thẻ nạp từ Gcoin!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=muathenap",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_muathenap").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#muathenap_buy").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_muathenap").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#muathenap_buy").removeAttr('disabled');
					
					$("#head_gcoin").html(html_split[3].toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));
                    } else {
                    $("#msg_muathenap").html("<div class='form-error'>" + html + "</div>");
                    $("#muathenap_buy").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_napthe').live('click', function(){
		var act = $('#loaithe').val();
		var menhgia = $('#menhgia').val();
		var card_num = $('#card_num').val();
		var card_serial = $('#card_serial').val();
        var dataString = "action=napthe&act="+ act +"&menhgia="+ menhgia +"&card_num="+ card_num +"&card_serial="+ card_serial;
        var r = confirm("Bạn đang thực hiện nạp thẻ!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=napthe",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_napthe").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#napthe_buy").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_napthe").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#napthe_buy").removeAttr('disabled');
					
                    } else {
                    $("#msg_napthe").html("<div class='form-error'>" + html + "</div>");
                    $("#napthe_buy").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_moddaily_xuly').live('click', function(){
        var option = $('#option').val();
		var name_option = $('input[name=name_option]').val();
		var giatri_plus = $('input[name=giatri_plus]').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=moddaily&option="+ option +"&name_option="+ name_option +"&giatri_plus="+ giatri_plus +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện thêm Gcoin cho tài khoản memb: "+ name_option +"!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=moddaily",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_moddaily").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#moddaily_buy").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_moddaily").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#moddaily_xuly").removeAttr('disabled');
					
                    } else {
                    $("#msg_moddaily").html("<div class='form-error'>" + html + "</div>");
                    $("#moddaily_xuly").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_bank2jewel').live('click', function(){
        var type_jw = $('#type_jw').val();
		var slg_jw = $('input[name=slg_jw]').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=bank2jewel&type_jw="+ type_jw +"&slg_jw="+ slg_jw +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện Rút ngọc từ ngân hàng vào Game!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=bank2jewel",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_bank2jewel").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#bank2jewel").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[0] == "OK") {
                    $("#msg_bank2jewel").html("<div class='form-success'>" + html_split[3] + "</div>");
                    $("#bank2jewel").removeAttr('disabled');
                    
                } else {
                    $("#msg_bank2jewel").html("<div class='form-error'>" + html + "</div>");
                    $("#bank2jewel").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_kiemtranv').live('click', function(){
		var namecheck = $('input[name=namecheck]').val();
        var dataString = "action=kiemtranv&namecheck="+ namecheck;
		
		if(namecheck.length == 0) {
            alert('Chưa nhập tên nhân vật cần kiểm tra.');
        } else {
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=kiemtranv",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_kiemtranv").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#kiemtranv").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[0] == "OK") {
                    $("#msg_kiemtranv").html("<div class='form-success' align='center'>" + html_split[1] + "</div>");
                    $("#kiemtranv").removeAttr('disabled');
                    
                } else {
                    $("#msg_kiemtranv").html("<div class='form-error'>" + html + "</div>");
                    $("#kiemtranv").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_giftcode_change').live('click', function(){
		var giftcode = $('input[name=giftcode]').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=giftcode_change&giftcode="+ giftcode +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện đổi mã GiftCode lấy phần thưởng!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=giftcode_change",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_giftcode_change").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#giftcode_change").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_giftcode_change").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#giftcode_change").removeAttr('disabled');
                } else {
                    $("#msg_giftcode_change").html("<div class='form-error'>" + html + "</div>");
                    $("#giftcode_change").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_items2points').live('click', function(){
		var character = $('input[name=character]').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=items2points&character="+ character +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện đổi phần thưởng!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=items2points",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_items2points").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#btn_items2points").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[0] == "OK") {
                    $("#msg_items2points").html("<div class='form-success'>" + html_split[1] + "</div>");
                } else {
                    $("#msg_items2points").html("<div class='form-error'>" + html + "</div>");
                    $("#btn_items2points").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_doitiente').live('click', function(){
		var giatridoi = $('input[name=giatridoi]').val();
		var character = $('input[name=character]').val();
		var pass2 = $('input[name=pass2]').val();
		var action = $('input[name=action]').val();
        var dataString = "action="+ action +"&giatridoi="+ giatridoi +"&character="+ character +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện đổi tiền!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=doitiente",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_doitiente").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#btn_doitiente").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[0] == "OK") {
                    $("#msg_doitiente").html("<div class='form-success'>" + html_split[1] + "</div>");
                } else {
                    $("#msg_doitiente").html("<div class='form-error'>" + html + "</div>");
                    $("#btn_doitiente").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
    $('#btn_santa_ticket').live('click', function(){
		var character = $('input[name=character]').val();
		var money_type = $('#money_type').val();
		var pass2 = $('input[name=pass2]').val();
        var dataString = "action=santa_ticket&character="+ character +"&money_type="+ money_type +"&pass2="+ pass2;
        var r = confirm("Bạn đang thực hiện đổi mã Vé Santa lấy VPoint!\nBạn có chắc chắn thao tác của mình là đúng?\nNếu đúng hãy bấm OK để tiếp tục hoặc bấm Cancel để xem xét lại.");
		if(r == true){
        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=event_santa_ticket",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_santa_ticket").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#santa_ticket").attr('disabled','disabled');
            },
            complete: function() {
                
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[1] == "OK") {
                    $("#msg_santa_ticket").html("<div class='form-success'>" + html_split[2] + "</div>");
                    $("#santa_ticket").removeAttr('disabled');
                } else {
                    $("#msg_santa_ticket").html("<div class='form-error'>" + html + "</div>");
                    $("#santa_ticket").removeAttr('disabled');
                }
            }
         });
		}
        
        return false;
    });
	
   $(".btn_tichluythe").live('click', function(){
        var gift_thenap = $(this).attr("gift_thenap");
        
        var popupShow = $(this).data('showpopup');

         var dataString = "action=nhanthuong&gift_thenap="+  gift_thenap;
         
          $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=event_tichluythe",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#loading_"+ gift_thenap).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#btn_tichluythe_"+ gift_thenap).attr('disabled','disabled');
            },
            complete: function() {
                 $("#loading_"+ gift_thenap).html("");
            },
            success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                    
                    $("#btn_tichluythe_"+ gift_thenap).prop('value', 'Đã nhận');
                    
                    var ss_html = "<div class='form-success'>"+ html_split[2] +"</div>";
                    
                    $(".box-popup").removeClass('show box-popup-green box-popup-red');
                    var classShow = ".box-popup[data-popup=popup-click-"+popupShow+"]";
                    $(classShow).addClass('show box-popup-green').html(ss_html);


                 } else {
                    $("#btn_tichluythe_"+ gift_thenap).removeAttr('disabled');
                    
                    $(".box-popup").removeClass('show box-popup-green box-popup-red');
                    var classShow = ".box-popup[data-popup=popup-click-"+popupShow+"]";
                    $(classShow).addClass('show box-popup-red').html(html);

                 }
            }
         });
        
        return false;
    });
	
   $(".btn_thangcap").live('click', function(){
        var gift_thangcap = $(this).attr("gift_thangcap");
        
        var popupShow = $(this).data('showpopup');

         var dataString = "action=nhanthuong&gift_thangcap="+  gift_thangcap;
         
          $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=event_thangcap",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#loading_"+ gift_thangcap).html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#btn_thangcap_"+ gift_thangcap).attr('disabled','disabled');
            },
            complete: function() {
                 $("#loading_"+ gift_thangcap).html("");
            },
            success: function(html) {
                 var html_split = html.split("|");
                 if(html_split[1] == "OK") {
                    
                    $("#btn_thangcap_"+ gift_thangcap).prop('value', 'Đã nhận');
                    
                    var ss_html = "<div class='form-success'>"+ html_split[2] +"</div>";
                    
                    $(".box-popup").removeClass('show box-popup-green box-popup-red');
                    var classShow = ".box-popup[data-popup=popup-click-"+popupShow+"]";
                    $(classShow).addClass('show box-popup-green').html(ss_html);


                 } else {
                    $("#btn_thangcap_"+ gift_thangcap).removeAttr('disabled');
                    
                    $(".box-popup").removeClass('show box-popup-green box-popup-red');
                    var classShow = ".box-popup[data-popup=popup-click-"+popupShow+"]";
                    $(classShow).addClass('show box-popup-red').html(html);

                 }
            }
         });
        
        return false;
    });
    
    $('#login_loi').live('click', function(){
		var vweb_security_login_code1 = $('input[name=vweb_security_login_code1]').val();
		var vweb_security_login_code2 = $('input[name=vweb_security_login_code2]').val();
		var vweb_security_login_code3 = $('input[name=vweb_security_login_code3]').val();
		var vImageCodP = $('input[name=vImageCodP]').val();
		var username = $('input[name=username_lg]').val();
		var passType = $('input[name=passType_lg]').val();
		var password = $('input[name=password_lg]').val();
		var login = $('input[name=login]').val();

		if(username.length == 0) {
            alert('Chưa nhập tên tài khoản.');
        }else if(password.length == 0) {
            alert('Chưa nhập mật khẩu.');
        } else {
			var dataString = "login="+ login +"&vweb_security_login_code1="+ vweb_security_login_code1 +"&vweb_security_login_code2="+ vweb_security_login_code2 +"&vweb_security_login_code3="+ vweb_security_login_code3 +"&vImageCodP="+ vImageCodP +"&username_lg="+ username +"&passType="+ passType +"&password_lg="+ password;
			$.ajax({
				type: "GET",
				url: "ajax_action.php?ajax=login",
				data: dataString,
				cache: false,
				beforeSend: function() {
					 $("#msg_login").html("<center><div align='center'><img src='images/loading.gif' border='0' /></div></center>");
				},
				complete: function() {
					
				},
				success: function(html) {
					var html_split = html.split("<vweb>");
					if(html_split[1] == "OK") {
						$("#msg_login").html("<div class='form-success'>Đăng nhập thành công!</div>");
						window.location.href = 'index.php';
					} else {
						window.location.href = '#login';
						$("#msg_login").html("<div class='form-error'>" + html + "</div>");
					}
				}
			 });
		}
        return false;
    });
	
    $('#register').live('click', function(){
		var username = $('input[name=username]').val();
		var thehe = $('input[name=thehe]').val();
		var password = $('input[name=password]').val();
		var quest = $('#quest').val();
		var ans = $('input[name=ans]').val();
		var sno_numb = $('input[name=sno_numb]').val();
		var tel = $('input[name=tel]').val();
		var vImageCodP = $('input[name=vImageCodP]').val();
		var register = $('input[name=register]').val();
        
		if(username.length == 0) {
            alert('Chưa nhập tên tài khoản.');
        }else if(password.length == 0) {
            alert('Chưa nhập mật khẩu.');
        }else if(quest == 0) {
            alert('Chưa nhập câu hỏi bí mật.');
        }else if(ans.length == 0) {
            alert('Chưa nhập câu trả lời bí mật.');
        }else if(sno_numb.length == 0) {
            alert('Chưa nhập 7 số bí mật.');
        }else if(tel.length == 0) {
            alert('Chưa nhập số điện thoại.');
        }else if(vImageCodP.length == 0) {
            alert('Chưa nhập mã kiểm tra.');
        } else {
			var dataString = "register="+ register +"&username="+ username +"&thehe="+ thehe +"&password="+ password +"&quest="+ quest +"&ans="+ ans +"&sno_numb="+ sno_numb +"&tel="+ tel +"&vImageCodP="+ vImageCodP;
			$.ajax({
				type: "GET",
				url: "ajax_action.php?ajax=register",
				data: dataString,
				cache: false,
				beforeSend: function() {
					 $("#msg_register").html("<center><div align='center'><img src='images/loading.gif' border='0' /></div></center>");
				},
				complete: function() {
					
				},
				success: function(html) {
					var html_split = html.split("<vweb>");
					if(html_split[1] == "OK") {
						$("#msg_register").html("<div class='form-success'>" + html_split[2] + "</div>");
					} else {
						$("#msg_register").html("<div class='form-error'>" + html + "</div>");
					}
				}
			 });
		}
        return false;
    });
	
    $('#btn_diemdanh').live('click', function(){
		var action = $('input[name=action]').val();
        var dataString = "action="+ action;

        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=event_diemdanh",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_diemdanh").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#btn_diemdanh").attr('disabled','disabled');
            },
            complete: function() {
                $("#btn_diemdanh").removeAttr('disabled');
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[0] == "OK") {
                    $("#msg_diemdanh").html("<div class='form-success'>" + html_split[1] + "</div>");
					location.reload();
                } else {
                    $("#msg_diemdanh").html("<div class='form-error'>" + html + "</div>");
                    $("#btn_diemdanh").removeAttr('disabled');
                }
            }
         });
        
        return false;
    });
	
    $('#btn_nhanthuong_diemdanh').live('click', function(){
		var action = $('input[name=action]').val();
		var password = $('input[name=password]').val();
        var dataString = "action="+ action +"&password="+ password;

        $.ajax({
            type: "GET",
            url: "ajax_action.php?ajax=event_diemdanh",
            data: dataString,
            cache: false,
            beforeSend: function() {
                 $("#msg_nhanthuong_diemdanh").html("<div align='center'><img src='images/loading.gif' border='0' /></div>");
                 $("#btn_nhanthuong_diemdanh").attr('disabled','disabled');
            },
            complete: function() {
                $("#btn_nhanthuong_diemdanh").removeAttr('disabled');
            },
            success: function(html) {
                var html_split = html.split("<vweb>");
                if(html_split[0] == "OK") {
                    $("#msg_nhanthuong_diemdanh").html("<div class='form-success'>" + html_split[1] + "</div>");
					//location.reload();
                } else {
                    $("#msg_nhanthuong_diemdanh").html("<div class='form-error'>" + html + "</div>");
                    $("#btn_nhanthuong_diemdanh").removeAttr('disabled');
                }
            }
         });
        
        return false;
    });
	
});

$(document).ready(function() {
    function _checkHash() {
        var url = window.location.hash;
        if (url.indexOf('#') != -1) {
            var c_url = url.split('#');
            var c_url_last = c_url.length - 1;
            var module = c_url ? c_url[c_url_last] : 'home';
            _pageload('index2.php?mod=' + module, '', 'BlockLeft');
            var mod_split = module.split('&');
            var mod_pri = mod_split ? mod_split[0] : module;
            var menuactive = mod_pri;
            if (mod_pri = 'event') {
                var act = mod_split[1];
                switch (act) {
                    case 'act=giftcode_rs':
                    case 'act=giftcode_week':
                    case 'act=giftcode_month':
                    case 'act=giftcode_tanthu':
                    case 'act=giftcode_change':
                    case 'act=giftcode_history':
                        menuactive = 'giftcode';
                        break;
                }
            }
            $('.nav-item').removeClass('active');
            $('.nav-item[menu-parent=' + menuactive + ']').addClass('active');
        }
    }
    $(window).hashchange(function() {
        _checkHash();
    });
    
    $(window).hashchange();

    function _initFn() {
        $('a, .money_block span, .bank-icon, .item-box, .ui-tooltipster').tooltipster({
            offsetY: 2
        });
        $(".table-sort").tablesorter();
        $(".menu-main-tabs-news .main-tab").click(function() {
            var myIndex = $(this).index();
            $(".menu-main-tabs .main-tab, .content-main-tabs .content-m-tab").removeClass('active');
            $(this).addClass('active');
            $(".content-main-tabs .content-m-tab:eq(" + myIndex + ")").addClass('active');
        });
        $(".menu-main-tabs .main-tab").click(function() {
            var myIndex = $(this).index();
            $(".menu-main-tabs .main-tab, .content-main-tabs .content-m-tab").removeClass('active');
            $(this).addClass('active');
            $(".content-main-tabs .content-m-tab:eq(" + myIndex + ")").addClass('active');
        });       
        $("input[data-showpopup]").hover(function() {
            var popupShow = $(this).data('showpopup');
            $(".box-popup").removeClass('show');
            var classShow = ".box-popup[data-popup=popup-hover-" + popupShow + "]";
            $(classShow).addClass('show');
        }, function() {
            $(".box-popup").removeClass('show');
        });
        $(window).scroll(function() {
            var self = $(this);
            if ($(".stage-menu").length) {
                var activeTab = $(".content-m-tab.active").index();
                if ($(this).scrollTop() >= $(".content-m-tab:eq(" + activeTab + ") .stage-menu").offset().top - 35) {
                    $(".content-m-tab:eq(" + activeTab + ") .stage-menu").addClass('fix');
                } else {
                    $(".content-m-tab:eq(" + activeTab + ") .stage-menu").removeClass('fix');
                }
                $.each($(".content-m-tab:eq(" + activeTab + ") .trader-block"), function(i, e) {
                    var eachThisTab = $(this).index();
                    if (self.scrollTop() >= $(this).context.offsetTop - 45) {
                        $(".content-m-tab:eq(" + activeTab + ") .stage-menu ul li").removeClass('active');
                        $(".content-m-tab:eq(" + activeTab + ") .stage-menu ul li.stage-m-i:eq(" + eachThisTab + ")").addClass('active');
                    }
                });
            }
        });
        $(".stage-m-i").click(function() {
            var myTab = $(this).data('tab'),
                myRow = $(this).text();
            $("body, html").animate({
                scrollTop: $(".content-m-tab:eq(" + myTab + ") .trader-block:nth-child(" + myRow + ")").offset().top - 43
            }, 300);
        });
        $(".stage-menu ul li.stage-m-i").hover(function() {
            var hvIndex = $(this).index();
            var activeTab = $(".content-m-tab.active").index();
            var myTab = $(this).data('tab'),
                myRow = $(this).text();
            console.log(myTab);
            $(".content-m-tab:eq(" + myTab + ") .trader-block:eq(" + (hvIndex - 1) + ")").addClass('hover');
        }, function() {
            var hvIndex = $(this).index();
            var activeTab = $(".content-m-tab.active").index();
            var myTab = $(this).data('tab'),
                myRow = $(this).text();
            $(".content-m-tab:eq(" + myTab + ") .trader-block:eq(" + (hvIndex - 1) + ")").removeClass('hover');
        });
    }
    $(".Tab-Menu").click(function() {
        if ($(".col-left").hasClass('show')) {
            $(".col-left").removeClass('show');
            $("body").removeClass('menu-left-show');
        } else {
            $(".col-left").addClass('show');
            $("body").addClass('menu-left-show');
        }
    });
    $(".Tab-Char").click(function() {
        $('html, body').animate({
            scrollTop: $("#Login_Content").offset().top
        }, 200);
    });
    $(".Tab-Acc").click(function() {
        if ($(".ResultAcc").hasClass('show')) {
            $(".ResultAcc").removeClass('show');
            $("body").removeClass('menu-left-show');
        } else {
            $(".ResultAcc").addClass('show');
            $("body").addClass('menu-left-show');
        }
    });
    if ($.cookie('left-collap') != undefined) {
        $.each($('*[data-title]'), function() {
            $(this).attr('title', $(this).data('title'));
        });
        _initFn();
        $(".wrap-fluid").addClass('left-collap');
    }
    $(".menu-collap").click(function() {
        if ($(".wrap-fluid").hasClass('left-collap')) {
            $(".wrap-fluid").removeClass('left-collap');
            $.removeCookie('left-collap');
            $.each($('*[data-title]'), function() {
                $(this).removeAttr('title');
            });
            _initFn();
        } else {
            $(".wrap-fluid").addClass('left-collap');
            $.cookie('left-collap', 1, {
                expires: 365
            });
            $.each($('*[data-title]'), function() {
                $(this).attr('title', $(this).data('title'));
            });
            _initFn();
        }
    });
    $(".select-button-character").click(function() {
        if ($(".dropdown-select").is(':visible')) $(".dropdown-select").fadeOut('fast');
        else {
            $(".dropdown-select").fadeIn('fast');
        }
    });
    $("#BlockLeft").on('click', '.head-block-tabs li', function() {
        var myTab = $(this).index();
        $(".head-block-tabs li, .head-sub-tabs .head-sub").removeClass('active');
        $(this).addClass('active');
        $(".head-sub-tabs .head-sub:eq(" + myTab + ")").addClass('active');
    });
    $(".blackBg, .popupClose").click(function() {
        $('.blackBg').hide();
        $(".popupCenter").hide();
        $(".guideShow").removeClass('guideShow');
    });
    $("#BlockLeft").on('click', '#vpoint_gate input[name=card]', function() {
        var this_card = $(this).val().toLowerCase();
        $(".current-card #image-card").attr('class', '').addClass('image-card card-' + this_card);
    });
    _initFn();
    $(document).ajaxComplete(function() {
        _initFn();
    });
});

function LoadKetQuaXoSo(date){
	$("#load_content").load("index2.php?mod=relax&act=ketqua&date_bet="+date);
}

function SearchItem(value){
	$("#shop_content").load("index2.php?mod=webshop&act="+value);
}

function Show_Dialog(Content){
	setTimeout("Dialog(\'"+Content+"\')",800);
}

function _showPopup(title, content, callback) {
    if (typeof title == 'undefined') title = 'Thông báo';
    if (typeof content == 'undefined') title = '';
    $(".popupContent").html(content);
    $(".popupCaption").html(title);
    $(".popupCenter, .blackBg").fadeIn('fast', function() {
        if (typeof callback == 'function') callback();
    });
}

function Dialog(Content)
{
	$.fx.speeds._default = 800;
	$("#dialog-content").empty().append(Content);	
	$(function() {
		$( '#dialog:ui-dialog' ).dialog( 'destroy' );
	
		$( '#dialog-message' ).dialog({
			show: 'explode',
			hide: 'explode',
			modal: true,
			buttons: {
				Ok: function() {
					$( this ).dialog( 'close' );
				}
			}
		});
	});
}
function Dialog2(Content)
{
	$.fx.speeds._default = 800;
	$("#dialog-content").empty().append(Content);	
	$(function() {
		$( '#dialog:ui-dialog' ).dialog( 'destroy' );
	
		$( '#dialog-message' ).dialog({
			show: 'fold',
			hide: 'explode',
			modal: true,
			buttons: {
				Ok: function() {
					$( this ).dialog( 'close' );
				}
			}
		});
	});
}
