﻿var lvlPrice = 0.00;

function processPLAjax(url, type, data, dataType, fn) {
    jQuery.ajax({
        url: url,
        type: type,
        data: data,
        dataType: dataType,
        success: fn
    });
}

function initLevel(startLevel, endLevel, plLevels) {
    lvlPrice = 0.00;
    jQuery("#s_level").children("option:gt(0)").remove();
    jQuery("#e_level").children("option:gt(0)").remove();
    for (var i = startLevel; i <= endLevel; i++)
        jQuery("#s_level").append('<option value="' + i + '">' + i + '</option>');
    for (var i = endLevel; i >= plLevels; i--)
        jQuery("#e_level").append('<option value="' + i + '">' + i + '</option>');
}

function level_Changed() {
    var s_level = jQuery("#s_level").val();
    var e_level = jQuery("#e_level").val();
    var gamecode = jQuery("#hfGameCode").val();
    lvlPrice = 0.00;
    setOnlyCheckTotal();
    if (validateLevel(gamecode, s_level, e_level)) {
        jQuery('#imgWait1').show();
        var url = '/powerleveling/plAjax.aspx';
        var type = 'get';
        var data = 'methodName=GetPriceByLevel&gameCode=' + gamecode + '&sLevel=' + s_level + '&eLevel=' + e_level + '&goldFree=true&rd=' + Math.random();
        var dataType = 'html';
        processPLAjax(url, type, data, dataType, procAjaxData);
    }
    
}

function procAjaxData(html) {

    jQuery('#imgWait1').hide();
    var bok = true;
    if (isNoBlank(html) == false) {
        setOnlyCheckTotal();
        return;
    }
    var data = html.split('|');
    if (data.length < 3) {
        setOnlyCheckTotal();
        return;
    }

    var cstmTotal = getTotalCustom();
    lvlPrice = toFloat(data[0]);
    jQuery('#txtPrice').val(getTotalPrice().toFixed(2));
    var days = splitDays(data[1]);
    days.first += cstmTotal.time;
    days.last += cstmTotal.time;
    if (days.first == days.last) {
        jQuery('#txtDays').val(days.first);
    }
    else {
        jQuery('#txtDays').val(days.first.toString() + '-' + days.last.toString());
    }

    jQuery("#txtGoldFree").val(data[2]);

}


function validateLevel(gamecode, s_level, e_level) {

    if (s_level == undefined || s_level == null || s_level == "-1") {
        return false;
    }

    if (e_level == undefined || e_level == null || e_level == "-1") {
        return false;
    }

    if (gamecode == undefined || gamecode == null || gamecode == "") {
        return false;
    }

    if (parseInt(s_level) >= parseInt(e_level)) {
        return false;
    }

    return true;
}

function splitDays(strDay) {
    var day = { first: 0, last: 0 };
    if (isNoBlank(strDay)) {
        var split = strDay.split('-');
        if (split.length > 1) {
            day.first = toInt(split[0]);
            day.last = toInt(split[1]);
        }
        else {
            day.first = toInt(split);
            day.last = toInt(split);
        }
    }

    return day;
}

function getTotalCustom() {
    var total = { price: 0.0, time: 0 };
    var checks = jQuery("#divCustom input:checked");
    if (checks != undefined && checks != null) {
        checks.each(function() {
            var id = jQuery(this).attr("id");
            if (isNoBlank(id)) {
                var info = getCustomInfo(id);
                total.price += info.money;
                total.time += info.time;
            }
        });
    }

    return total;
}

function getCustomInfo(elmId) {
    var name = jQuery("#" + elmId + "_hidden_name").val();
    var descrip = jQuery("#" + elmId + "_hidden_descrip").val();
    var money = jQuery("#" + elmId + "_hidden_money").val();
    var time = jQuery("#" + elmId + "_hidden_time").val();

    return { name: name, descrip: descrip, money: toFloat(money), time: toInt(time) };
}

function toFloat(str) {
    if (isNoBlank(str) == false) {
        return 0.00;
    }
    var number = parseFloat(str);
    if (isNaN(number)) {
        number = 0.00;
    }
    return number;
}

function toInt(str) {
    if (isNoBlank(str) == false) {
        return 0;
    }
    var number = parseInt(str);
    if (isNaN(number)) {
        number = 0;
    }
    return number;
}

function isNoBlank(str) {
    var notBlank = true;
    if (str == undefined || str == null) {
        notBlank = false;
    }
    else {
        var reg = new RegExp(/\S+/);
        notBlank = reg.test(str);
    }
    return notBlank;
}

function setOnlyCheckTotal() {
    //当选择StartLevel时不会删除txtPrice中已经存在的money
    var cstmTotal = getTotalCustom();

    cstmTotal.price += getGoldPrice();
    jQuery("#txtDays").val(cstmTotal.time);
    jQuery("#txtPrice").val(formatNum(cstmTotal.price, 2));
    jQuery("#txtGoldFree").val("0");
}


function formatNum(src, pos) {
    return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
}

function chkBox_Checked() {
    var check = jQuery(this).attr("checked");
    if (check) {
        AddProduct(this);
    }
    else {
        SubProduct(this);
    }
}

function AddProduct(elm) {
    var price = toFloat(jQuery("#txtPrice").val());
    var days = splitDays(jQuery("#txtDays").val());
    var check = getCustomInfo(jQuery(elm).attr("id"));
    days.first += check.time;
    days.last += check.time;
    if (days.first == days.last) {
        jQuery('#txtDays').val(days.first);
    }
    else {
        jQuery('#txtDays').val(days.first.toString() + '-' + days.last.toString());
    }

    
    jQuery('#txtPrice').val(getTotalPrice().toFixed(2));
}

//function SubProduct(elm) {
//    var price = toFloat(jQuery("#txtPrice").val());
//    var days = splitDays(jQuery("#txtDays").val());
//    var check = getCustomInfo(jQuery(elm).attr("id"));
//    price -= check.money;
//    days.first -= check.time;
//    days.last -= check.time;
//    jQuery('#txtPrice').val(getTotalPrice().toFixed(2));
//    if (days.first == days.last) {
//        jQuery('#txtDays').val(days.first);
//    }
//    else {
//        jQuery('#txtDays').val(days.first.toString() + '-' + days.last.toString());
//    }
//}

//function cstmProductReset() {
//    jQuery("#divCustom input:checked").each(function() {
//        jQuery(this).attr("checked", false);
//        SubProduct(this);
//    });
//}

function levelSubmit() {
    jQuery('#goldPrice').val("");
    var price = toFloat(jQuery('#txtPrice').val());
    var days = splitDays(jQuery("#txtDays").val());
    if (price <= 0.00 || days.first < 0 || days.last < 0)
        return false;
    var bOk = false;
    var gamecode = jQuery("#hfGameCode").val();
    if (isNoBlank(gamecode) && validateLevel(gamecode, jQuery("#s_level").val(), jQuery("#e_level").val())) {

        jQuery("#level-s_level").val(jQuery("#s_level").val());
        jQuery("#level-e_level").val(jQuery("#e_level").val());
        jQuery("#level-txtPrice").val(jQuery("#txtPrice").val());
        jQuery("#level-txtDays").val(jQuery("#txtDays").val());

        var checks = jQuery("#divCustom input:checked");
        var infos = getCustomInfos(checks);
        var gold = getGoldInfo();

        if (isNoBlank(infos.names) && isNoBlank(gold.names)) {
            jQuery("#inptDIYName").val(infos.names + '|' + gold.names);
            jQuery("#inptDIYPrice").val(infos.prices + '|' + gold.prices);
            jQuery("#inptDIYTime").val(infos.times + '|' + gold.times);
            jQuery("#inptDIYDescrip").val(infos.descrips + '|' + gold.descrips);
        }
        else if (isNoBlank(infos.names)) {
            jQuery("#inptDIYName").val(infos.names);
            jQuery("#inptDIYPrice").val(infos.prices);
            jQuery("#inptDIYTime").val(infos.times);
            jQuery("#inptDIYDescrip").val(infos.descrips);
        }
        else if (isNoBlank(gold.names)) {
            jQuery("#inptDIYName").val(gold.names);
            jQuery("#inptDIYPrice").val(gold.prices);
            jQuery("#inptDIYTime").val(gold.times);
            jQuery("#inptDIYDescrip").val(gold.descrips);
        }
      
      
        jQuery("#fm_level").attr("action", '/powerleveling/PLOrderInfo.aspx');
        jQuery("#level-pl").val("level");
        jQuery("#level-gameCode").val(gamecode);
        jQuery("#fm_level").submit();

    }
    else {
        alert("Please choose your level!");
    }

    return false;
}

function getCustomInfos(checks) {
    var DIYPackageName = '';
    var DIYPackagePrice = '';
    var DIYPackageTimeLilit = '';
    var DIYPackageDescrip = '';
    for (var i = 0; i < checks.length; i++) {
        var check = getCustomInfo(jQuery(checks[i]).attr("id"));
        if (i == checks.length - 1) {
            DIYPackageName += check.name;
            DIYPackagePrice += formatNum(check.money, 2).toString();
            DIYPackageTimeLilit += check.time.toString();
            DIYPackageDescrip += check.descrip;
        }
        else {
            DIYPackageName += check.name + '|';
            DIYPackagePrice += formatNum(check.money, 2).toString() + '|';
            DIYPackageTimeLilit += check.time.toString() + '|';
            DIYPackageDescrip += check.descrip + '|';
        }
    }

    return { names: DIYPackageName, prices: DIYPackagePrice, times: DIYPackageTimeLilit, descrips: DIYPackageDescrip };
}
function getGoldInfo() {
    var DIYPackageName = '';
    var DIYPackagePrice = '';
    var DIYPackageTimeLilit = '';
    var DIYPackageDescrip = '';
    var gPrice = getGoldPrice();
    if (gPrice > 0.00 && isNoBlank(jQuery("#plServerName").val())) {
        DIYPackageName += jQuery("#plGameName").val() + ' ' + jQuery("#plServerName").val() + ' ' + jQuery("#ddlProduct option:selected").text();
        DIYPackagePrice += formatNum(gPrice, 2).toString();
        DIYPackageTimeLilit += '0';
        DIYPackageDescrip += 'Gold Product Form PL';
    }
    return { names: DIYPackageName, prices: DIYPackagePrice, times: DIYPackageTimeLilit, descrips: DIYPackageDescrip };
}


function serverKey_Changed() {
    jQuery("#ddlServers option:gt(0),#ddlProduct option:gt(0)").remove();
    jQuery("#ddlServers option:eq(0),#ddlProduct option:eq(0)").attr("selected", "selected");

    lastPrice=0.00;
    jQuery("#txtPrice").val(getTotalPrice().toFixed(2));
    
    var key = jQuery("#ddlServerKey option:selected").val();
    if (isNoBlank(key)) {
        var tempList = jQuery("#ddlHiddenServer option:contains('" + key + "')").clone();
        var cloneList = jQuery.grep(tempList, function(n, i) {
            var text = jQuery(n).text();
            if (isNoBlank(text) == false) {
                return false;
            }
            if (text.indexOf(key) == 0) {
                return true;
            }
            else {
                return false;
            }
        });
        jQuery("#ddlServers").append(cloneList);
    }
}


function getTotalPrice() {
    var cstmPrice = getTotalCustom();
    var levelPrice = toFloat(lvlPrice);
    return cstmPrice.price + levelPrice + getGoldPrice();
}

function getGoldPrice()
{
    return toFloat(jQuery("#ddlProduct option:selected").val());
}
var lvlPrice = 0.00;

function processPLAjax(url, type, data, dataType, fn) {
    jQuery.ajax({
        url: url,
        type: type,
        data: data,
        dataType: dataType,
        success: fn
    });
}

function initLevel(startLevel, endLevel, plLevels) {
  
    lvlPrice = 0.00;
    jQuery("#s_level").children("option:gt(0)").remove();
    jQuery("#e_level").children("option:gt(0)").remove();
    for (var i = startLevel; i <= endLevel; i++)
        jQuery("#s_level").append('<option value="' + i + '">' + i + '</option>');
    for (var i = endLevel; i >= plLevels; i--)
        jQuery("#e_level").append('<option value="' + i + '">' + i + '</option>');
}

function level_Changed() {
    var s_level = jQuery("#s_level").val();
    var e_level = jQuery("#e_level").val();
    var gamecode = jQuery("#hfGameCode").val();
    lvlPrice = 0.00;
    setOnlyCheckTotal();
    if (validateLevel(gamecode, s_level, e_level)) {
        jQuery('#imgWait1').show();
        var url = '/powerleveling/plAjax.aspx';
        var type = 'get';
        var data = 'methodName=GetPriceByLevel&gameCode=' + gamecode + '&sLevel=' + s_level + '&eLevel=' + e_level + '&goldFree=true&rd=' + Math.random();
        var dataType = 'html';
        processPLAjax(url, type, data, dataType, procAjaxData);
    }
    
}

function procAjaxData(html) {

    jQuery('#imgWait1').hide();
    var bok = true;
    if (isNoBlank(html) == false) {
        setOnlyCheckTotal();
        return;
    }
    var data = html.split('|');
    if (data.length < 3) {
        setOnlyCheckTotal();
        return;
    }

    var cstmTotal = getTotalCustom();
    lvlPrice = toFloat(data[0]);
    jQuery('#txtPrice').val(getTotalPrice().toFixed(2));
    var days = splitDays(data[1]);
    days.first += cstmTotal.time;
    days.last += cstmTotal.time;
    if (days.first == days.last) {
        jQuery('#txtDays').val(days.first);
    }
    else {
        jQuery('#txtDays').val(days.first.toString() + '-' + days.last.toString());
    }

    jQuery("#txtGoldFree").val(data[2]);

}


function validateLevel(gamecode, s_level, e_level) {

    if (s_level == undefined || s_level == null || s_level == "-1") {
        return false;
    }

    if (e_level == undefined || e_level == null || e_level == "-1") {
        return false;
    }

    if (gamecode == undefined || gamecode == null || gamecode == "") {
        return false;
    }

    if (parseInt(s_level) >= parseInt(e_level)) {
        return false;
    }

    return true;
}

function splitDays(strDay) {
    var day = { first: 0, last: 0 };
    if (isNoBlank(strDay)) {
        var split = strDay.split('-');
        if (split.length > 1) {
            day.first = toInt(split[0]);
            day.last = toInt(split[1]);
        }
        else {
            day.first = toInt(split);
            day.last = toInt(split);
        }
    }

    return day;
}

function getTotalCustom() {
    var total = { price: 0.0, time: 0 };
    var checks = jQuery("#divCustom input:checked");
    if (checks != undefined && checks != null) {
        checks.each(function() {
            var id = jQuery(this).attr("id");
            if (isNoBlank(id)) {
                var info = getCustomInfo(id);
                total.price += info.money;
                total.time += info.time;
            }
        });
    }

    return total;
}

function getCustomInfo(elmId) {
    var name = jQuery("#" + elmId + "_hidden_name").val();
    var descrip = jQuery("#" + elmId + "_hidden_descrip").val();
    var money = jQuery("#" + elmId + "_hidden_money").val();
    var time = jQuery("#" + elmId + "_hidden_time").val();

    return { name: name, descrip: descrip, money: toFloat(money), time: toInt(time) };
}

function toFloat(str) {
    if (isNoBlank(str) == false) {
        return 0.00;
    }
    var number = parseFloat(str);
    if (isNaN(number)) {
        number = 0.00;
    }
    return number;
}

function toInt(str) {
    if (isNoBlank(str) == false) {
        return 0;
    }
    var number = parseInt(str);
    if (isNaN(number)) {
        number = 0;
    }
    return number;
}

function isNoBlank(str) {
    var notBlank = true;
    if (str == undefined || str == null) {
        notBlank = false;
    }
    else {
        var reg = new RegExp(/\S+/);
        notBlank = reg.test(str);
    }
    return notBlank;
}

function setOnlyCheckTotal() {
    //当选择StartLevel时不会删除txtPrice中已经存在的money
    var cstmTotal = getTotalCustom();
    cstmTotal.price += getGoldPrice();
    jQuery("#txtDays").val(cstmTotal.time);
    jQuery("#txtPrice").val(formatNum(cstmTotal.price, 2));
    jQuery("#txtGoldFree").val("0");
}


function formatNum(src, pos) {
    return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
}

function chkBox_Checked() {
    var check = jQuery(this).attr("checked");
    if (check) {
        AddProduct(this);
    }
    else {
        SubProduct(this);
    }
}

function AddProduct(elm) {
    var price = toFloat(jQuery("#txtPrice").val());
    var days = splitDays(jQuery("#txtDays").val());
    var check = getCustomInfo(jQuery(elm).attr("id"));
    days.first += check.time;
    days.last += check.time;
    if (days.first == days.last) {
        jQuery('#txtDays').val(days.first);
    }
    else {
        jQuery('#txtDays').val(days.first.toString() + '-' + days.last.toString());
    }

    
    jQuery('#txtPrice').val(getTotalPrice().toFixed(2));
}

function SubProduct(elm) {
    var price = toFloat(jQuery("#txtPrice").val());
    var days = splitDays(jQuery("#txtDays").val());
    var check = getCustomInfo(jQuery(elm).attr("id"));
    price -= check.money;
    days.first -= check.time;
    days.last -= check.time;
    jQuery('#txtPrice').val(getTotalPrice().toFixed(2));
    if (days.first == days.last) {
        jQuery('#txtDays').val(days.first);
    }
    else {
        jQuery('#txtDays').val(days.first.toString() + '-' + days.last.toString());
    }
}

function cstmProductReset() {
    jQuery("#divCustom input:checked").each(function() {
        jQuery(this).attr("checked", false);
        SubProduct(this);
       // InitDIYData();
        var Packname='';
		        var PackPrice='';
		        var PackTime='';
		        var PackDescrip='';				
		        $j('#inptDIYName').val(Packname);
		        $j('#inptDIYPrice').val(PackPrice);
		        $j('#inptDIYTime').val(PackTime);
		        $j('#inptDIYDescrip').val(PackDescrip);
    });
}

function levelSubmit() {
    jQuery('#goldPrice').val("");
    var price = toFloat(jQuery('#txtPrice').val());
    var days = splitDays(jQuery("#txtDays").val());
    if (price <= 0.00 || days.first < 0 || days.last < 0)
        return false;
    var bOk = false;
    var gamecode = jQuery("#hfGameCode").val();
    if (isNoBlank(gamecode) && validateLevel(gamecode, jQuery("#s_level").val(), jQuery("#e_level").val())) {

        jQuery("#level-s_level").val(jQuery("#s_level").val());
        jQuery("#level-e_level").val(jQuery("#e_level").val());
        jQuery("#level-txtPrice").val(jQuery("#txtPrice").val());
        jQuery("#level-txtDays").val(jQuery("#txtDays").val());

        var checks = jQuery("#divCustom input:checked");
        var infos = getCustomInfos(checks);
        var gold = getGoldInfo();

        if (isNoBlank(infos.names) && isNoBlank(gold.names)) {
            jQuery("#inptDIYName").val(infos.names + '|' + gold.names);
            jQuery("#inptDIYPrice").val(infos.prices + '|' + gold.prices);
            jQuery("#inptDIYTime").val(infos.times + '|' + gold.times);
            jQuery("#inptDIYDescrip").val(infos.descrips + '|' + gold.descrips);
        }
        else if (isNoBlank(infos.names)) {
            jQuery("#inptDIYName").val(infos.names);
            jQuery("#inptDIYPrice").val(infos.prices);
            jQuery("#inptDIYTime").val(infos.times);
            jQuery("#inptDIYDescrip").val(infos.descrips);
        }
        else if (isNoBlank(gold.names)) {
            jQuery("#inptDIYName").val(gold.names);
            jQuery("#inptDIYPrice").val(gold.prices);
            jQuery("#inptDIYTime").val(gold.times);
            jQuery("#inptDIYDescrip").val(gold.descrips);
        }
        
      
      
        jQuery("#fm_level").attr("action", '/powerleveling/PLOrderInfo.aspx');
        jQuery("#level-pl").val("level");
        jQuery("#level-gameCode").val(gamecode);
        jQuery("#fm_level").submit();

    }
    else {
        alert("Please choose your level!");
    }

    return false;
}

function getCustomInfos(checks) {
    var DIYPackageName = '';
    var DIYPackagePrice = '';
    var DIYPackageTimeLilit = '';
    var DIYPackageDescrip = '';
    for (var i = 0; i < checks.length; i++) {
        var check = getCustomInfo(jQuery(checks[i]).attr("id"));
        if (i == checks.length - 1) {
            DIYPackageName += check.name;
            DIYPackagePrice += formatNum(check.money, 2).toString();
            DIYPackageTimeLilit += check.time.toString();
            DIYPackageDescrip += check.descrip;
        }
        else {
            DIYPackageName += check.name + '|';
            DIYPackagePrice += formatNum(check.money, 2).toString() + '|';
            DIYPackageTimeLilit += check.time.toString() + '|';
            DIYPackageDescrip += check.descrip + '|';
        }
    }

    return { names: DIYPackageName, prices: DIYPackagePrice, times: DIYPackageTimeLilit, descrips: DIYPackageDescrip };
}
function getGoldInfo() {
    var DIYPackageName = '';
    var DIYPackagePrice = '';
    var DIYPackageTimeLilit = '';
    var DIYPackageDescrip = '';
    if (getGoldPrice() > 0.00 && isNoBlank(jQuery("#plServerName").val()) && isNoBlank(jQuery("#ddlProduct option:selected").val())) {
        DIYPackageName += jQuery("#plGameName").val() + ' ' + jQuery("#plServerName").val() + ' ' + jQuery("#ddlProduct option:selected").text();
        DIYPackagePrice += formatNum(getGoldPrice(), 2).toString();
        DIYPackageTimeLilit += '0';
        DIYPackageDescrip += 'Gold Product Form PL';
    }
    return { names: DIYPackageName, prices: DIYPackagePrice, times: DIYPackageTimeLilit, descrips: DIYPackageDescrip };
}


function serverKey_Changed() {
    jQuery("#ddlServers option:gt(0),#ddlProduct option:gt(0)").remove();
//    jQuery("#ddlServers option:eq(0),#ddlProduct option:eq(0)").attr("selected", "selected");
  
    lastPrice=0.00;
    jQuery("#txtPrice").val(getTotalPrice().toFixed(2));
    
    var key = jQuery("#ddlServerKey option:selected").val();
    if (isNoBlank(key)) {
        var tempList = jQuery("#ddlHiddenServer option:contains('" + key + "')").clone();
        var cloneList = jQuery.grep(tempList, function(n, i) {
            var text = jQuery(n).text();
            if (isNoBlank(text) == false) {
                return false;
            }
            if (text.indexOf(key) == 0) {
                return true;
            }
            else {
                return false;
            }
        });
        jQuery("#ddlServers").append(cloneList);
        jQuery("#ddlServers option:eq(0),#ddlProduct option:eq(0)").attr("selected", "selected");
    }
}


function getTotalPrice() {
    var cstmPrice = getTotalCustom();
    var levelPrice = toFloat(lvlPrice);
    return cstmPrice.price + levelPrice + getGoldPrice();
}

function server_Changed() {
 
    jQuery("#ddlProduct option:gt(0)").remove();
    jQuery("#ddlProduct option:eq(0)").attr("selected", "selected");
  
    lastPrice = 0.00;
    jQuery("#txtPrice").val(getTotalPrice().toFixed(2));
    var gameServerCode = jQuery("#ddlServers option:gt(0):selected").val();
    if (gameServerCode != '-1') {
        jQuery("#plServerName").val(jQuery("#ddlServers option:gt(0):selected").text());
        processPLAjax('/powerleveling/plAjax.aspx', 'get', 'methodName=GetCustomerGoldPrice&gameServerCode=' + gameServerCode + '&date=' + new Date(), 'json', getGoldProduct);

    }
}

function getGoldProduct(json) {
    if (json != null && json.length > 0) {
        var name, code, option;
        for (var i = 0; i < json.length; i++) {
            name = json[i].ProductName;
            code = json[i].SaleProductPrice;
           option = "<option value=" + code + ">" + name +"<span  style=\"color:Red\"> $"+parseFloat(code).toFixed(2)+"</span></option>";
           // option = "<option value=" + code + ">" + name + "</option>";
            jQuery("#ddlProduct").append(option);
        }
    }
}

function product_Changed() {
  
    jQuery("#txtPrice").val(getTotalPrice().toFixed(2));
}

function submitShop() {
debugger
    jQuery("#hd_s_level").val(jQuery("#s_level").val());
    jQuery("#hd_e_level").val(jQuery("#e_level").val());
var price = toFloat(jQuery('#txtPrice').val());
    var days = splitDays(jQuery("#txtDays").val());
    if (price <= 0.00 || days.first < 0 || days.last < 0)
        return false;
    var bOk = false;
    var gamecode = jQuery("#hfGameCode").val();
    if (isNoBlank(gamecode) && validateLevel(gamecode, jQuery("#hd_s_level").val(), jQuery("#hd_e_level").val())) {
        var checks = jQuery("#divCustom input:checked");
        var infos = getCustomInfos(checks);
        if (isNoBlank(infos.names)) {
            jQuery("#inptDIYName").val(infos.names);
            jQuery("#inptDIYPrice").val(infos.prices);
            jQuery("#inptDIYTime").val(infos.times);
            jQuery("#inptDIYDescrip").val(infos.descrips);
            

        }
//        else{
//          var Packname='';
//		        var PackPrice='';
//		        var PackTime='';
//		        var PackDescrip='';				
//		        $j('#inptDIYName').val(Packname);
//		        $j('#inptDIYPrice').val(PackPrice);
//		        $j('#inptDIYTime').val(PackTime);
//		        $j('#inptDIYDescrip').val(PackDescrip);

//        
//        }
        AddLevelToCart();
    }
    else {
        alert("Please choose your level!");
    }
}

//function InitDIYData()
//		{
//			var Packname='';
//			var PackPrice='';
//			var PackTime='';
//			var PackDescrip='';
//			var name='';
//			var price='';
//			var time='';
//			var descrip='';
//			$j("input[type=checkbox]").each(function(i){
//				if($j(this).attr("checked"))
//				{
//					var cid=$j(this).attr("id");
//					name=$j('#'+cid+'_hidden_name').val();
//					price= $j('#'+cid+'_hidden_money').val();
//					time=$j('#'+cid+'_hidden_time').val();
//					descrip=$j('#'+cid+'_hidden_descrip').val();
//					Packname+=name+"┠";
//					PackPrice+=price+"┠";
//					PackTime+=time+"┠";
//					PackDescrip+=descrip+"┠";
//				}
//			});
//			$j('#inptDIYName').val(Packname);
//			$j('#inptDIYPrice').val(PackPrice);
//			$j('#inptDIYTime').val(PackTime);
//			$j('#inptDIYDescrip').val(PackDescrip);
//			//$j('#formpllevel').submit();
//		}