function DVCPWS() {
  $("#new_pass").change(function () {
    if ($.trim($("#new_pass").val()).length < 6 || $("#new_pass").val().toLowerCase().replace(/[^a-z]/g, '').length == 0 || $("#new_pass").val().replace(/[^0-9]/g, '').length == 0) $("#new_passCk").attr("innerHTML", checkfield(false));
    else {
      $("#new_passCk").attr("innerHTML", checkfield(true));
      $("#chgpwdError").attr("innerHTML", "");
    }

    if ($.trim($("#cfnew_pass").val()).length != 0) {
      if ($("#cfnew_pass").val() != $("#new_pass").val()) $("#cfnew_passCk").attr("innerHTML", checkfield(false));
      else {
        $("#cfnew_passCk").attr("innerHTML", checkfield(true));
        $("#chgpwdError").attr("innerHTML", "");
      }
    }
  });

  $("#cfnew_pass").change(function () {
    if ($("#cfnew_pass").val() != $("#new_pass").val()) $("#cfnew_passCk").attr("innerHTML", checkfield(false));
    else $("#cfnew_passCk").attr("innerHTML", checkfield(true));
  });
}

function DVJONS3E() {
  $("#tolevel2Ck").click(function () {
    $("#sign_level2").slideToggle("slow");
  });

  //first name check
  $("#sign_fname").change(function () {
    if ($.trim($("#sign_fname").val()).length == 0) $("#sign_fnameCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_fnameCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  //last name check
  $("#sign_lname").change(function () {
    if ($.trim($("#sign_lname").val()).length == 0) $("#sign_lnameCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_lnameCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  //email check
  $("#sign_email").change(function () {
    if ($.trim($(this).val()).length != 0 && (ismail($(this).val()))) checkUserData("Email", $(this).val(), "sign_emailCk");
    else $("#sign_emailCk").attr("innerHTML", checkfield(false));

    if ($.trim($("#sign_cfEmail").val()).length != 0) {
      if ($("#sign_email").val() != $("#sign_cfEmail").val()) $("#sign_cfEmailCk").attr("innerHTML", checkfield(false));
      else {
        $("#sign_cfEmailCk").attr("innerHTML", checkfield(true));
        $("#signError").attr("innerHTML", "");
      }
    }
  });

  if ($("#signup_provider").html() != "") {
       var provider = eval('(' + $("#signup_provider").html() + ')');
       if (provider.email != null) {
          $("#sign_email").trigger("change");
       }
  }

  //confirm email check
  $("#sign_cfEmail").change(function () {
    if ($("#sign_email").val() != $(this).val()) $("#sign_cfEmailCk").attr("innerHTML", checkfield(false));
    else {
      checkUserData("Email", $(this).val(), "sign_cfEmailCk");
      $("#signError").attr("innerHTML", "");
    }
  });

  //password
  $("#sign_pwd").change(function () {
    if ($.trim($(this).val()).length < 6 || $(this).val().toLowerCase().replace(/[^a-z]/g, '').length == 0 || $(this).val().replace(/[^0-9]/g, '').length == 0) $("#sign_pwdCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_pwdCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }

    if ($.trim($("#sign_cfPwd").val()).length != 0) {
      if ($("#sign_pwd").val() != $("#sign_cfPwd").val()) $("#sign_cfPwdCk").attr("innerHTML", checkfield(false));
      else {
        $("#sign_cfPwdCk").attr("innerHTML", checkfield(true));
        $("#signError").attr("innerHTML", "");
      }
    }
  });

  //confirm password
  $("#sign_cfPwd").change(function () {
    if ($("#sign_pwd").val() != $(this).val()) $("#sign_cfPwdCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_cfPwdCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  //country
  $("#sign_country").change(function () {
    if ($("#sign_country").val() == "0") $("#sign_countryCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_countryCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }

    if ($("#aba_tr").css("display") == "table-row" || $("#swift_tr").css("display") == "table-row") {
      if ($("#sign_country :selected").text() == "USA") {
        $("#swift_tr").css("display", "none");
        $("#aba_tr").css("display", "table-row");
      } else {
        $("#swift_tr").css("display", "table-row");
        $("#aba_tr").css("display", "none");
      }
    }
  });

  $("#sign_councode").change(function () {
    if ($.trim($("#sign_councode").val()).length == 0 || $.trim($("#sign_areacode").val()).length == 0 || $.trim($("#sign_phone").val()).length == 0) $("#sign_phoneCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_phoneCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  $("#sign_areacode").change(function () {
    if ($.trim($("#sign_councode").val()).length == 0 || $.trim($("#sign_areacode").val()).length == 0 || $.trim($("#sign_phone").val()).length == 0) $("#sign_phoneCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_phoneCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  $("#sign_phone").change(function () {
    if ($.trim($("#sign_councode").val()).length == 0 || $.trim($("#sign_areacode").val()).length == 0 || $.trim($("#sign_phone").val()).length == 0) $("#sign_phoneCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_phoneCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  //aba check
  $("#sign_aba").change(function () {
    if ($.trim($("#sign_aba").val()).length == 0) $("#sign_abaCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_abaCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  //swift check
  $("#sign_swift").change(function () {
    if ($.trim($("#sign_swift").val()).length == 0) $("#sign_swiftCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_swiftCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  $("#sign_payment_bank").click(function () {
    $("#paypal_tr").css("display", "none");
    $("#transfer_bankname_tr").css("display", "table-row");
    $("#transfer_billacc_tr").css("display", "table-row");
    $("#sign_bankname").focus();
    $("#sign_paymentCk").attr("innerHTML", checkfield(true));
    $("#signError").attr("innerHTML", "");

    if ($("#sign_country :selected").text() == "USA") {
      $("#swift_tr").css("display", "none");
      $("#aba_tr").css("display", "table-row");
    } else {
      $("#swift_tr").css("display", "table-row");
      $("#aba_tr").css("display", "none");
    }
  });

  $("#sign_payment_paypal").click(function () {
    $("#paypal_tr").css("display", "table-row");
    $("#transfer_bankname_tr").css("display", "none");
    $("#transfer_billacc_tr").css("display", "none");
    $("#sign_paypal").focus();
    $("#sign_paymentCk").attr("innerHTML", checkfield(true));
    $("#signError").attr("innerHTML", "");
    $("#swift_tr").css("display", "none");
    $("#aba_tr").css("display", "none");
  });

  $("#sign_paypal").change(function () {
    if ($.trim($("#sign_paypal").val()).length == 0) $("#sign_paypalCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_paypalCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  $("#sign_bankname").change(function () {
    if ($.trim($("#sign_bankname").val()).length == 0) $("#sign_banknameCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_banknameCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  $("#sign_billacc").change(function () {
    if ($.trim($("#sign_billacc").val()).length == 0) $("#sign_billaccCk").attr("innerHTML", checkfield(false));
    else {
      $("#sign_billaccCk").attr("innerHTML", checkfield(true));
      $("#signError").attr("innerHTML", "");
    }
  });

  $("#sign_councode").numeric();
  $("#sign_areacode").numeric();
  $("#sign_phone").numeric();
  $("#sign_postcode").numeric();
}

function DVMPF() {
    $("#profile_country").change(function () {

        if ($("#profile_country").val() == "0") {
            $("#profileError").attr("innerHTML", "Please select your country!");
            window.location = "#";
        }

    //$("#profile_timezone").val($("#profile_country :selected").attr("item"));
    $.ajax({
      url: "/Handle/iniSession",
      type: "POST",
      cache: false,
      data: ({act:"iniSession"}),
      success: function (data) {
        $.ajax({
          url: serverpath+'/getUserProfileByUserName',
          type: "POST",
          data: ({action:"getUserProfileByUserName",username:data}),
          datatype: "JSON",
          success: function (data) {
            if (data.status == "success") {
              var jsonobj = data.result;

              if (jsonobj[0].ddegree == 2) {
                if ($("#aba_tr").css("display") == "table-row" || $("#swift_tr").css("display") == "table-row") {
                  if ($("#profile_country :selected").text() == "USA") {
                    $("#swift_tr").css("display", "none");
                    $("#aba_tr").css("display", "table-row");
                  } else {
                    $("#swift_tr").css("display", "table-row");
                    $("#aba_tr").css("display", "none");
                  }
                }
              }
            }
          }
        });
      }
    });
  });

  $("#tolevel2Ck").change(function () {
    openUpgradeDialog();
/*
    if($(this).is(":checked")){
    $("#fname_required").attr("innerHTML","*");
    $("#lname_required").attr("innerHTML","*");
    $("#country_required").attr("innerHTML","*");
    $("#phone_required").attr("innerHTML","*");
    } else {
    $("#fname_required").attr("innerHTML","&nbsp;");
    $("#lname_required").attr("innerHTML","&nbsp;");
    $("#country_required").attr("innerHTML","&nbsp;");
    $("#phone_required").attr("innerHTML","&nbsp;");
    }
    */
  });

  $("#profile_payment_bank").click(function () {
    $("#paypal_tr").css("display", "none");
    $("#bankacc_tr").css("display", "table-row");
    $("#billacc_tr").css("display", "table-row");
    if ($("#profile_country").text() == "USA") $("#aba_tr").css("display", "table-row");
    else $("#swift_tr").css("display", "table-row");
    $("#profile_billacc").focus();
  });

  $("#profile_payment_paypal").click(function () {
    $("#paypal_tr").css("display", "table-row");
    $("#bankacc_tr").css("display", "none");
    $("#billacc_tr").css("display", "none");
    $("#swift_tr").css("display", "none");
    $("#aba_tr").css("display", "none");
    $("#profile_paypal").focus();
  });

  $("#submitdevBtn").click(function () {
    $("#profileError").css("color", "red");

    //first name
    if ($("#fname_required").attr("innerHTML") == "*" && $.trim($("#profile_fname").val()).length == 0) {
      $("#profileError").attr("innerHTML", "Please fill your first name!");
      window.location = "#";
      return;
    }

    //last name
    if ($("#lname_required").attr("innerHTML") == "*" && $.trim($("#profile_lname").val()).length == 0) {
      $("#profileError").attr("innerHTML", "Please fill your last name!");
      window.location = "#";
      return;
    }

    //phone number
    if ($("#phone_required").attr("innerHTML") == "*" && ($.trim($("#profile_coun").val()).length == 0 || $.trim($("#profile_area").val()).length == 0 || $.trim($("#profile_phone").val()).length == 0)) {
      $("#profileError").attr("innerHTML", "Please fill your phone number!");
      window.location = "#";
      return;
    }

    if ($.trim($("#profile_coun").val()).length != 0 || $.trim($("#profile_area").val()).length != 0 || $.trim($("#profile_phone").val()).length != 0) {
      if ($.trim($("#profile_coun").val()).length == 0 || $.trim($("#profile_area").val()).length == 0 || $.trim($("#profile_phone").val()).length == 0) {
        $("#profileError").attr("innerHTML", "Incorrect phone number format!");
        window.location = "#";
        return;
      }
    }

    //country
    if ($("#country_required").attr("innerHTML") == "*" && $("#profile_country").val() == "0") {
      $("#profileError").attr("innerHTML", "Please select your country!");
      window.location = "#";
      return;
    }

    //payment type
    if ($("#payment_type_tr").css("display") != "none") {
      if ((!$("#profile_payment_bank").is(":checked")) && (!$("#profile_payment_paypal").is(":checked"))) {
        $("#profileError").attr("innerHTML", "Please select your payment type!");
        window.location = "#";
        return;
      }

      //payment bank
      if ($("#profile_payment_bank").is(":checked")) {
        if ($.trim($("#profile_billacc").val()).length == 0) {
          $("#profileError").attr("innerHTML", "Please fill your bill account!");
          window.location = "#";
          return;
        }

        if ($.trim($("#profile_bankacc").val()).length == 0) {
          $("#profileError").attr("innerHTML", "Please fill your bank name!");
          window.location = "#";
          return;
        }

        //SWIFT Code
        if ($("#swift_tr").css("display") == "table-row" && $.trim($("#profile_swift").val()).length == 0) {
          $("#profileError").attr("innerHTML", "Please fill your SWIFT Code!");
          window.location = "#";
          return;
        }

        //ABA Code
        if ($("#aba_tr").css("display") == "table-row" && $.trim($("#profile_aba").val()).length == 0) {
          $("#profileError").attr("innerHTML", "Please fill your ABA Code!");
          window.location = "#";
          return;
        }
      }

      //payment paypal
      if ($("#profile_payment_paypal").is(":checked")) {
        if ($.trim($("#profile_paypal").val()).length == 0) {
          $("#profileError").attr("innerHTML", "Please fill your paypal ID!");
          window.location = "#";
          return;
        }
      }
    }


    //Update profile
    $.ajax({
      url: "/Handle/iniSession",
      type: "POST",
      data: ({act:"iniSession"}),
      success: function (data) {
        $.ajax({
          url: serverpath+'/getUserProfileByUserName',
          type: "POST",
          data: ({action:"getUserProfileByUserName",username:data}),
          datatype: "JSON",
          success: function (data) {
            if (data.status == "success") {
              var jsonobj = data.result;

              var userid = jsonobj[0].user_id;
              var firstname = $("#profile_fname").val();
              var lastname = $("#profile_lname").val();
              var nickname = jsonobj[0].email;
              var email = jsonobj[0].email;
              var company = $("#profile_company").val();
              var address = $("#profile_addr").val();
              var postcode = $("#profile_postcode").val();
              var phonenumber = jsonobj[0].phone_number;
              if ($.trim($("#profile_coun").val()).length != 0 || $.trim($("#profile_area").val()).length != 0 || $.trim($("#profile_phone").val()).length != 0) phonenumber = $("#profile_coun").val() + "-" + $("#profile_area").val() + "-" + $("#profile_phone").val();
              else phonenumber = jsonobj[0].phone_number;
              var paypadid = $("#profile_paypal").val();
              var area = $("#profile_lang").val();
              var sex = "";
              var ddegree = jsonobj[0].ddegree;
              var mdegree = jsonobj[0].mdegree;
              if ($("#tolevel2Ck").is(":checked")) mdegree = 2;
              var picture = jsonobj[0].picture;
              if ($("#profile_img_name").attr("innerHTML") != "") {
                $.ajax({
                  url: "/Handle/move_picture",
                  type: "POST",
                  data: ({act:"move_picture",filename:$("#profile_img_name").attr("innerHTML")}),
                  success: function (res) {
                      picture = res;
                  }
                });
                  picture = $("#profile_img_name").attr("innerHTML");
              }
              var country = "";
              if ($("#profile_country").val() != "0") country = $("#profile_country :selected").val();
              var timezone = "";
              var website = $("#profile_website").val();
              var bankname = $("#profile_bankacc").val();
              var billaccount = $("#profile_billacc").val();
              var bankaba = $("#profile_aba").val();
              var bankswift = $("#profile_swift").val();
              var notice1 = ($("#profile_notice1").is(":checked")) ? 1 : 0;
              var notice2 = ($("#profile_notice2").is(":checked")) ? 1 : 0;
              var status = jsonobj[0].status;
              var paymenttype = 0;
              if ($("#profile_payment_bank").is(":checked")) paymenttype = 1;
              if ($("#profile_payment_paypal").is(":checked")) paymenttype = 2;

              $.ajax({
                url: serverpath+'/setUserProfile',
                type: "POST",
                data: ({action:"setUserProfile",userid:userid,email:email,firstname:firstname,lastname:lastname,nickname:nickname,company:company,phone:phonenumber,timezone:timezone,postcode:postcode,country:country,website:website,bankname:bankname,billaccount:billaccount,notice1:notice1,notice2:notice2,status:status,ddegree:ddegree,mdegree:mdegree,address:address,paypadid:paypadid,area:area,sex:sex,picture:picture,bankaba:bankaba,bankswift:bankswift,paymenttype:paymenttype}),
                datatype: "JSON",
                success: function (data) {
                  if (data.status == "success") {
/*
                    $("#profileError").attr("innerHTML","Your profile has been updated successfully!");
                    $("#profileError").css("color","green");
                    getMemberProfile();
                    window.location = "#";
                    */
                    alert("Your profile has been updated successfully!");
                    window.location = "/Developer/MyProfile";
                  } else {
                    $("#profileError").attr("innerHTML", "Fail to update your profile, please try again later!");
                    window.location = "#";
                  }
                }
              });
            }
          }
        });
      }
    });
  });

  //upload picture
  new AjaxUpload('file', {
      // Location of the server-side upload script
      // NOTE: You are not allowed to upload files to another domain
      action: '/Handle/tempImage',
      autoSubmit: true,
      responseType: false,
      onSubmit: function (file, extension) {
          if (!(extension && /^(jpg|png|jpeg)$/i.test(extension))) {
              $("#profileError").attr("innerHTML", "Upload only as JPG or PNG files!");
              window.location = "#";
              return false;
          } else {
              $("#profileError").attr("innerHTML", "");
              block_view("Uploading image...");
          }
      },
      onComplete: function (file, response) {
          if (response != "error") {
              $("#origin_icon_file_name").attr("innerHTML", file);
              $("#profile_img").attr("src", userpicpath + "/" + response + "?" + guid());
              //      $("#profile_img").attr("src", response);
              $("#profile_img_name").attr("innerHTML", "users/userpics/" + response);
              end_view("Uploading image...");
              //alert(file);
              $("#cancel_file").css("display", "inline");
              $("#delete_file").css("display", "none");
          }
      }
  });

  //cancel file
  $("#cancel_file").click(function () {
      $.ajax({
          url: "/Handle/iniSession",
          type: "POST",
          cache: false,
          data: ({ act: "iniSession" }),
          success: function (data) {
              $.ajax({
                  url: serverpath + '/getUserProfileByUserName',
                  type: "POST",
                  data: ({ action: "getUserProfileByUserName", username: data }),
                  datatype: "JSON",
                  success: function (data) {
                      if (data.status == "success") {
                          var jsonobj = data.result;

                          if (jsonobj[0].picture != "") {
                              $("#profile_img").attr("src", downloadhost + "/" + jsonobj[0].picture + "?" + guid());
                              $("#delete_file").css("display", "inline");
                          }
                          else {
                              $("#profile_img").attr("src", "../../Content/images/picture.gif");
                          }
                          $("#origin_icon_file_name").attr("innerHTML", "");
                          $("#profile_img_name").attr("innerHTML", "");
                          $("#cancel_file").css("display", "none");
                      }
                  }
              });
          }
      });
  });

  //delete 
  $("#delete_file").click(function () {
    $.ajax({
      url: "/Handle/iniSession",
      type: "POST",
      cache: false,
      data: ({act:"iniSession"}),
      success: function (data) {
        $.ajax({
          url: serverpath+'/getUserProfileByUserName',
          type: "POST",
          data: ({action:"getUserProfileByUserName",username:data}),
          datatype: "JSON",
          success: function (data) {
            if (data.status == "success") {
              var jsonobj = data.result;

              var userid = jsonobj[0].user_id;
              var firstname = jsonobj[0].first_name;
              var lastname = jsonobj[0].last_name;
              var nickname = jsonobj[0].email;
              var email = jsonobj[0].email;
              var company = jsonobj[0].company;
              var address = jsonobj[0].address;
              var postcode = jsonobj[0].postcode;
              var phonenumber = jsonobj[0].phone_number;
              var paypadid = jsonobj[0].paypad_id;
              var area = jsonobj[0].area;
              var sex = jsonobj[0].gender;
              var ddegree = jsonobj[0].ddegree;
              var mdegree = jsonobj[0].mdegree;
              var picture = "";
              var country = jsonobj[0].country;
              var timezone = jsonobj[0].timezone;
              var website = jsonobj[0].website;
              var bankname = jsonobj[0].bankname;
              var billaccount = jsonobj[0].billaccount;
              var bankaba = jsonobj[0].bankABA;
              var bankswift = jsonobj[0].bankSWIFT;
              var notice1 = jsonobj[0].notice1;
              var notice2 = jsonobj[0].notice2;
              var status = jsonobj[0].status;
              var paymenttype = jsonobj[0].paymenttype;

              $.ajax({
                url: serverpath+'/setUserProfile',
                type: "POST",
                data: ({action:"setUserProfile",userid:userid,email:email,firstname:firstname,lastname:lastname,nickname:nickname,company:company,phone:phonenumber,timezone:timezone,postcode:postcode,country:country,website:website,bankname:bankname,billaccount:billaccount,notice1:notice1,notice2:notice2,status:status,ddegree:ddegree,mdegree:mdegree,address:address,paypadid:paypadid,area:area,sex:sex,picture:picture,bankaba:bankaba,bankswift:bankswift,paymenttype:paymenttype}),
                datatype: "JSON",
                success: function (data) {
                  if (data.status == "success") {
                    alert("Your profile has been updated successfully!");
                    window.location = "/Developer/MyProfile";
                  } else {
                    $("#profileError").attr("innerHTML", "Fail to delete your picture, please try again later!");
                    window.location = "#";
                  }
                }
              });
            }
          }
        });
      }
    });
  });

  $("#profile_coun").numeric();
  $("#profile_area").numeric();
  $("#profile_phone").numeric();
  $("#profile_postcode").numeric();
}

function DVMCOHT() {
  $("#start_date").datepicker({
    dateFormat: 'yy-mm-dd'
  });
  $("#end_date").datepicker({
    dateFormat: 'yy-mm-dd'
  });
}

function DVMAPFO() {
  $("#start_date").datepicker({
    dateFormat: 'yy-mm-dd'
  });
  $("#end_date").datepicker({
    dateFormat: 'yy-mm-dd'
  });
}

function selectRegion(related_name, parent_name, checked) {
    if (checked == true) {
        $("input[name='" + related_name + "']").attr("checked", true);
    } else {
        $("#" + parent_name).attr("checked", false);
    }
}

function selectSubRegion(related_name, parent_name, checked) {
    if (checked == true) {
        $("input[class='" + related_name + "']").attr("checked", true);
    } else {
        $("#" + parent_name).attr("checked", false);
        $("#SupportCountry_All").attr("checked", false);
    }
}

function selectCountry(parent_name, checked) {
    if (checked == true) {
        $("input[class='" + related_name + "']").attr("checked", true);
    } else {
        $("#" + parent_name).attr("checked", false);
        $("#SupportCountry_All").attr("checked", false);
    }
}

function selectRegion(id) {
    if ($("#" + id).is(":checked")) {
        $("input[id*='" + id + "']").attr("checked", true);
    } else {
        var dataArray = id.split("_");
        var parent_id = "SupportCountry";
        for (i = 1; i < dataArray.length - 1; i++) {
            parent_id = parent_id + "_" + dataArray[i];
            $("input[id='" + parent_id + "']").attr("checked", false);
        }
    }
}

function DVUPMAP() {
    $("#category").html("Upload Apps - Step 1/2");

    $(function () { //上傳app
        if (jQuery.url.param("app") == undefined || jQuery.url.param("app") == "") {
            $.ajax({
                url: "/Handle/iniSession",
                type: "POST",
                cache: false,
                data: ({ act: "iniSession" }),
                success: function (data) {
                    $.ajax({
                        url: serverpath + '/getUserProfileByUserName',
                        type: "POST",
                        data: ({ action: "getUserProfileByUserName", username: data }),
                        datatype: "JSON",
                        success: function (data) {
                            if (data.status == "success") {
                                var jsonobj = data.result;

                                $("#prg_web").val(jsonobj[0].website);
                                $("#prg_email").val(jsonobj[0].email);

                                $("#prg_web_span").attr("innerHTML", jsonobj[0].website);
                                $("#prg_mail_span").attr("innerHTML", jsonobj[0].email);

                                //jsonobj[0].ddegree=1;
                                if (jsonobj[0].ddegree != 2) $("#prg_price").attr("disabled", "true");
                            }
                        }
                    });
                }
            });
        }
    });

    $("#dev_agree").click(function(){
        $.get("/Eula/DeveloperAgreementIframe", function (data) {
            window.location = "#develop_agree";
            $("body").append(data);
            $("body").css("overflow", "hidden");

            //Get the A tag
            var id = "#dwn_tools_dialog";

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set height and width to mask to fill up the whole screen
            $('#mask').css({
                'width': maskWidth,
                'height': maskHeight
            });

            //transition effect		
            $('#mask').fadeIn(700);
            $('#mask').fadeTo(700, 0.8);

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window to center
            $(id).css('top', 200);
            $(id).css('left', winW / 2 - $(id).width() / 2);

            //transition effect
            $(id).fadeIn(700);

            $(window).resize(function () {
                //Get the A tag
                var id = "#dwn_tools_dialog";

                //Get the screen height and width
                var maskHeight = $(document).height();
                var maskWidth = $(window).width();

                //Set height and width to mask to fill up the whole screen
                $('#mask').css({
                    'width': maskWidth,
                    'height': maskHeight
                });

                //Get the window height and width
                var winH = $(window).height();
                var winW = $(window).width();

                //Set the popup window to center
                $(id).css('top', 200);
                $(id).css('left', winW / 2 - $(id).width() / 2);
            });
        });
    });

    var prg_file_name;
    //upload file restriction
//    $("#prg_file").change(function () {
//        if ($(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "apk") {
//            $("#uploadError").attr("innerHTML", "Upload file only restrict to .APK file!");
//            $(this).val("");
//            window.location = "#";
//            return;
//        } else {
//          //  alert($(this).val());
//            $("#uploadError").attr("innerHTML", "");
//        }
//    });

    new AjaxUpload('prg_file', {
        // Location of the server-side upload script
        // NOTE: You are not allowed to upload files to another domain
        action: '/Handle/uploadAPK',
        name: 'userfile',
        autoSubmit: true,
        responseType: false,
        onSubmit: function (file, extension) {
            //console.log(file.fileSize);
            //            if (!$.browser.msie) {
            //                var f = document.getElementById("prg_file");
            //                fileSize = f.files.item(0).size;
            //                if (fileSize >= 1048576 * 1) {
            //                    $("#uploadError").attr("innerHTML", "Upload apk files maximum 10 MB!");
            //                    return false;
            //                }
            //            }
            if (!(extension && /^(apk)$/i.test(extension))) {
                $("#uploadError").attr("innerHTML", "Upload apk files!");
                window.location = "#";
                return false;
            } else {
                $("#uploadError").attr("innerHTML", "");
                block_view("Uploading apk...");
            }
        },
        onComplete: function (file, response) {
            if (response == "oversize") {
                $("#uploadError").attr("innerHTML", "Upload apk files maximum 50 MB!");
                end_view("Uploading apk...");
            } else if (response == "error" || response.substr(0, 7) != "http://") {
                $("#uploadError").attr("innerHTML", "Upload apk files error ,please try again later!");
                end_view("Uploading apk...");
            } else {
                $("#origin_prg_file_name").attr("innerHTML", file);
                $("#prg_file_name").attr("innerHTML", response);
                $("#prg_fileCk").attr("innerHTML", checkfield(true));
                end_view("Uploading apk...");
            }
        }
    });

    new AjaxUpload('info_file', {
        // Location of the server-side upload script
        // NOTE: You are not allowed to upload files to another domain
        action: '/Handle/uploadInfo',
        name: 'infofile',
        autoSubmit: true,
        responseType: false,
        onSubmit: function (file, extension) {
            //console.log(file.fileSize);
            //            if (!$.browser.msie) {
            //                var f = document.getElementById("prg_file");
            //                fileSize = f.files.item(0).size;
            //                if (fileSize >= 1048576 * 1) {
            //                    $("#uploadError").attr("innerHTML", "Upload apk files maximum 10 MB!");
            //                    return false;
            //                }
            //            }
            if (!(extension && /^(xml)$/i.test(extension))) {
                $("#uploadError").attr("innerHTML", "Upload xml files!");
                window.location = "#";
                return false;
            } else {
                $("#uploadError").attr("innerHTML", "");
                block_view("Uploading component info file...");
            }
        },
        onComplete: function (file, response) {
            if (response == "oversize") {
                $("#uploadError").attr("innerHTML", "Upload component info file maximum 50 MB!");
                end_view("Uploading apk...");
            } else if (response == "error" || response.substr(0, 7) != "http://") {
                $("#uploadError").attr("innerHTML", "Upload component info file error ,please try again later!");
                end_view("Uploading component info file...");
            } else {
                $("#origin_info_file_name").attr("innerHTML", file);
                $("#info_file_name").attr("innerHTML", response);
                $("#info_fileCk").attr("innerHTML", checkfield(true));
                end_view("Uploading component info file...");
            }
        }
    });

    new AjaxUpload('preview_file', {
        // Location of the server-side upload script
        // NOTE: You are not allowed to upload files to another domain
        action: '/Handle/uploadAPKICON',
        name: 'userfile1',
        autoSubmit: true,
        responseType: false,
        onSubmit: function (file, extension) {
            if (!(extension && /^(jpg|png|jpeg)$/i.test(extension))) {
                $("#uploadError").attr("innerHTML", "Preview icon only restrict to .JPG or .PNG file!");
                window.location = "#";
                return false;
            } else {
                $("#uploadError").attr("innerHTML", "");
                block_view("Uploading icon...");
            }
        },
        onComplete: function (file, response) {
            if (response != "error") {
                $("#origin_preview_file_name").attr("innerHTML", file);
                $("#preview_file_name").attr("innerHTML", response);
                response = response.split("/");
                var filepath = "/Content/temp/apk/" + response[response.length - 1];
                $("#icon_preview_image").attr("src", filepath);
                $("#icon_preview").show();
                end_view("Uploading icon...");
            }
        }
    });

    new AjaxUpload('scn_file1', {
        // Location of the server-side upload script
        // NOTE: You are not allowed to upload files to another domain
        action: '/Handle/uploadAPKSCN',
        name:'userfile2',
        autoSubmit: true,
        responseType: false,
        onSubmit: function (file, extension) {
            if (!(extension && /^(jpg|png|jpeg)$/i.test(extension))) {
                $("#uploadError").attr("innerHTML", "Screenshot 1 only restrict to .JPG or .PNG file!");
                window.location = "#";
                return false;
            } else {
                $("#uploadError").attr("innerHTML", "");
                block_view("Uploading Screenshot...");
            }
        },
        onComplete: function (file, response) {
            if (response != "error") {
                $("#origin_scn_file1_name").attr("innerHTML", file);
                $("#scn_file1_name").attr("innerHTML", response);
                response = response.split("/");
                var filepath = "/Content/temp/apk/" + response[response.length - 1];
                $("#scn_file1_preview_image").attr("src", filepath);
                $("#scn_file1_preview").show();
                end_view("Uploading Screenshot...");
            }
        }
    });

    new AjaxUpload('scn_file2', {
        // Location of the server-side upload script
        // NOTE: You are not allowed to upload files to another domain
        action: '/Handle/uploadAPKSCN',
        name: 'userfile3',
        autoSubmit: true,
        responseType: false,
        onSubmit: function (file, extension) {
            if (!(extension && /^(jpg|png|jpeg)$/i.test(extension))) {
                $("#uploadError").attr("innerHTML", "Screenshot 2 only restrict to .JPG or .PNG file!");
                window.location = "#";
                return false;
            } else {
                $("#uploadError").attr("innerHTML", "");
                block_view("Uploading Screenshot...");
            }
        },
        onComplete: function (file, response) {
            if (response != "error") {
                $("#origin_scn_file2_name").attr("innerHTML", file);
                $("#scn_file2_name").attr("innerHTML", response);
                response = response.split("/");
                var filepath = "/Content/temp/apk/" + response[response.length - 1];
                $("#scn_file2_preview_image").attr("src", filepath);
                $("#scn_file2_preview").show();
                end_view("Uploading Screenshot...");
            }
        }
    });

    new AjaxUpload('scn_file3', {
        // Location of the server-side upload script
        // NOTE: You are not allowed to upload files to another domain
        action: '/Handle/uploadAPKSCN',
        name: 'userfile4',
        autoSubmit: true,
        responseType: false,
        onSubmit: function (file, extension) {
            if (!(extension && /^(jpg|png|jpeg)$/i.test(extension))) {
                $("#uploadError").attr("innerHTML", "Screenshot 3 only restrict to .JPG or .PNG file!");
                window.location = "#";
                return false;
            } else {
                $("#uploadError").attr("innerHTML", "");
                 block_view("Uploading Screenshot...");
            }
        },
        onComplete: function (file, response) {
            if (response != "error") {
                $("#origin_scn_file3_name").attr("innerHTML", file);
                $("#scn_file3_name").attr("innerHTML", response);
                response = response.split("/");
                var filepath = "/Content/temp/apk/" + response[response.length - 1];
                $("#scn_file3_preview_image").attr("src", filepath);
                $("#scn_file3_preview").show();
                end_view("Uploading Screenshot...");
            }
        }
    });

    new AjaxUpload('scn_file4', {
        // Location of the server-side upload script
        // NOTE: You are not allowed to upload files to another domain
        action: '/Handle/uploadAPKSCN',
        name: 'userfile5',
        autoSubmit: true,
        responseType: false,
        onSubmit: function (file, extension) {
            if (!(extension && /^(jpg|png|jpeg)$/i.test(extension))) {
                $("#uploadError").attr("innerHTML", "Screenshot 4 only restrict to .JPG or .PNG file!");
                window.location = "#";
                return false;
            } else {
                $("#uploadError").attr("innerHTML", "");
                block_view("Uploading Screenshot...");
            }
        },
        onComplete: function (file, response) {
            if (response != "error") {
                $("#origin_scn_file4_name").attr("innerHTML", file);
                $("#scn_file4_name").attr("innerHTML", response);
                response = response.split("/");
                var filepath = "/Content/temp/apk/" + response[response.length - 1];
                $("#scn_file4_preview_image").attr("src", filepath);
                $("#scn_file4_preview").show();
                end_view("Uploading Screenshot...");
            }
        }
    });

    new AjaxUpload('scn_file5', {
        // Location of the server-side upload script
        // NOTE: You are not allowed to upload files to another domain
        action: '/Handle/uploadAPKSCN',
        name: 'userfile6',
        autoSubmit: true,
        responseType: false,
        onSubmit: function (file, extension) {
            if (!(extension && /^(jpg|png|jpeg)$/i.test(extension))) {
                $("#uploadError").attr("innerHTML", "Screenshot 5 only restrict to .JPG or .PNG file!");
                window.location = "#";
                return false;
            } else {
                $("#uploadError").attr("innerHTML", "");
                block_view("Uploading Screenshot...");
            }
        },
        onComplete: function (file, response) {
            if (response != "error") {
                $("#origin_scn_file5_name").attr("innerHTML", file);
                $("#scn_file5_name").attr("innerHTML", response);
                response = response.split("/");
                var filepath = "/Content/temp/apk/" + response[response.length - 1];
                $("#scn_file5_preview_image").attr("src", filepath);
                $("#scn_file5_preview").show();
                end_view("Uploading Screenshot...");
            }
        }
    });
    
    //icon restriction
//    $("#preview_file").change(function () {
//        if ($(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "jpg" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "gif" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "png") {
//            $("#uploadError").attr("innerHTML", "Preview icon only restrict to .JPG, .GIF or .PNG file!");
//            $(this).val("");
//            window.location = "#";
//            return;
//        } else $("#uploadError").attr("innerHTML", "");
//    });

//    //screen shot 1
//    $("#scn_file1").change(function () {
//        if ($(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "jpg" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "gif" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "png") {
//            $("#uploadError").attr("innerHTML", "Screenshot image only restrict to .JPG, .GIF or .PNG file!");
//            $(this).val("");
//            window.location = "#";
//            return;
//        } else $("#uploadError").attr("innerHTML", "");
//    });

//    //screen shot 2
//    $("#scn_file2").change(function () {
//        if ($(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "jpg" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "gif" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "png") {
//            $("#uploadError").attr("innerHTML", "Screenshot image only restrict to .JPG, .GIF or .PNG file!");
//            $(this).val("");
//            window.location = "#";
//            return;
//        } else $("#uploadError").attr("innerHTML", "");
//    });

//    //screen shot 3
//    $("#scn_file3").change(function () {
//        if ($(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "jpg" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "gif" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "png") {
//            $("#uploadError").attr("innerHTML", "Screenshot image only restrict to .JPG, .GIF or .PNG file!");
//            $(this).val("");
//            window.location = "#";
//            return;
//        } else $("#uploadError").attr("innerHTML", "");
//    });

//    //screen shot 4
//    $("#scn_file4").change(function () {
//        if ($(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "jpg" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "gif" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "png") {
//            $("#uploadError").attr("innerHTML", "Screenshot image only restrict to .JPG, .GIF or .PNG file!");
//            $(this).val("");
//            window.location = "#";
//            return;
//        } else $("#uploadError").attr("innerHTML", "");
//    });

//    //screen shot 5
//    $("#scn_file5").change(function () {
//        if ($(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "jpg" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "gif" && $(this).val().split('.')[$(this).val().split('.').length - 1].toLowerCase() != "png") {
//            $("#uploadError").attr("innerHTML", "Screenshot image only restrict to .JPG, .GIF or .PNG file!");
//            $(this).val("");
//            window.location = "#";
//            return;
//        } else $("#uploadError").attr("innerHTML", "");
//    });


    //price digits limit
//    $("#prg_price").keydown(function () {
//        //alert($(this).val().substring(0,4));
//        if ($(this).val().substring(0, 4) == "0.00") {
//            $(this).val($(this).val().substring($.trim($(this).val()).length));
//            return;
//        }

//        if ($(this).val().split('.').length == 2) {
//            if ($(this).val().split('.')[1].length == 2) $(this).val($(this).val().split('.')[0] + "." + $(this).val().split('.')[1].substring(0, 1));
//        }
//    });

    $("#prg_desc").keyup(function () {
        var max = 1000;
        if ($(this).val().length > max) {
            alert("The description of your application exceeds the total description allotment size of 1000 words. Please reduce the description and try again!");
            $(this).val($(this).val().substr(0, max));
        }
    });

    $("#SelectCountryDiv").jstree({
        "xml_data": {
            "ajax": {
                "url": "/Service/getRegion"
            },
            "xsl": "flat"
        },
        "themes": {
            "theme": "classic",
            "url":"/Scripts/jsTree/themes/classic/style.css"
        },
        "plugins": ["themes", "xml_data", "checkbox"]
    });


    var device;
    $("#nextBtn").click(function (event) { //點選next以後
        $('html, body').scrollTop(0);
        window.location = "#step2";
        //program
        if ($.trim($("#prg_file_name").attr("innerHTML")).length == 0) {
            $("#uploadError").attr("innerHTML", "Please choose your program!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        if ($("input[name='device']").is(":checked") == false) { //device沒選
            $("#uploadError").attr("innerHTML", "Please select device!");
            window.location = "#";
            event.preventDefault();
            return;
        } else {
            var sep = "";
            device = "";
            $("input[name='device']:checked").each(function () {
                device += sep + $(this).val();
                sep = ",";
            });
        }

        //preview icon
        if ($.trim($("#preview_file_name").attr("innerHTML")).length == 0) {
            $("#uploadError").attr("innerHTML", "Please choose your preview icon!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //screen shot
        if ($.trim($("#scn_file1_name").attr("innerHTML")).length == 0) {
            $("#uploadError").attr("innerHTML", "Please choose at least one screenshot!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //program title
        if ($.trim($("#prg_title").val()).length == 0) {
            $("#uploadError").attr("innerHTML", "Please fill your program title!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //program description
        if ($.trim($("#prg_desc").val()).length == 0) {
            $("#uploadError").attr("innerHTML", "Please fill your program description!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //program category
        if ($("#catOption").val() == -1) {
            $("#uploadError").attr("innerHTML", "Please select program category!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //program price
        if ($.trim($("#prg_price").val()).length == 0) {
            $("#uploadError").attr("innerHTML", "Please fill program price!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        if (isNaN($("#prg_price").val())) {
            $("#uploadError").attr("innerHTML", "Price must be a number!");
            window.location = "#";
            event.preventDefault();
            return;
        }


        //        全選$("input[name*='SupportCountry']").attr("checked",true);

        $("#uploadError").attr("innerHTML", "");

        if (jQuery.url.param("app") == undefined || jQuery.url.param("app") == "") {
            $("#category").html("Upload Apps - Step 2/2");
            //$("#updatesubmitdevBtn").hide();
            //$("#nextBtn2").show();
        }else{
            $("#category").html("Edit My Application - Step 2/2");
            //$("#updatesubmitdevBtn").show();
            //$("#nextBtn2").hide();
        }

        $("#step1").hide();
        $("#step2").show();
        $("#uploadTitle1").hide();
        $("#uploadTitle2").show();
    });

    var country;
    $("#nextBtn2").click(function (event) { //點選next以後
        $('html, body').scrollTop(0);
        window.location = "#step3";
        var checked_ids = []; 
           $(".jstree-checked").each(function(){
               if($(this).attr("name")=="CountryItem"){
                   checked_ids.push($(this).attr("value"));
               }
           });
         $("#SupportCountry").val(checked_ids.join(","));


        if ($("#SupportCountry").val()==""){ //country沒選
            $("#uploadError").attr("innerHTML", "Please select Support Country!");
            window.location = "#";
            event.preventDefault();
            return;
        }else{
            country=$("#SupportCountry").val();
        }

        $("#uploadError").attr("innerHTML", "");
        $("#category").html("Upload Apps - Step 3/3");

        $("#step2").hide();
        $("#step3").show();
    });

    $("#prevBtn").click(function (event) { //點選prev以後
        $('html, body').scrollTop(0);

        if (jQuery.url.param("app") == undefined || jQuery.url.param("app") == "") {
            $("#category").html("Upload Apps - Step 1/2");
        } else {
            $("#category").html("Edit My Application - Step 1/2");
        }

        $("#step1").show();
        $("#step2").hide();
        $("#uploadTitle1").show();
        $("#uploadTitle2").hide();
    });

    $("#prevBtn2").click(function (event) { //點選prev以後
        $('html, body').scrollTop(0);
        $("#category").html("Upload Apps - Step 2/3");
        $("#step2").show();
        $("#step3").hide();
    });

    $(".submitdevBtn").click(function (event) { //點選送出以後
        $('html, body').scrollTop(0);
        window.location = "#done";

        var checked_ids = [];
        $(".jstree-checked").each(function () {
            if ($(this).attr("name") == "CountryItem") {
                checked_ids.push($(this).attr("value"));
            }
        });
        $("#SupportCountry").val(checked_ids.join(","));

        if ($("#SupportCountry").val() == "") { //country沒選
            $("#uploadError").attr("innerHTML", "Please select Support Country!");
            window.location = "#";
            event.preventDefault();
            return;
        } else {
            country = $("#SupportCountry").val();
        }

        //program
        if ($.trim($("#prg_file_name").attr("innerHTML")).length == 0 && (jQuery.url.param("app") == undefined || jQuery.url.param("app") == "")) {
            $("#uploadError").attr("innerHTML", "Please choose your program!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //preview icon
        if ($.trim($("#preview_file_name").attr("innerHTML")).length == 0 && (jQuery.url.param("app") == undefined || jQuery.url.param("app") == "")) {
            $("#uploadError").attr("innerHTML", "Please choose your preview icon!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //screen shot
        if ($.trim($("#scn_file1_name").attr("innerHTML")).length == 0 && (jQuery.url.param("app") == undefined || jQuery.url.param("app") == "")) {
            $("#uploadError").attr("innerHTML", "Please choose at least one screenshot!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //program title
        if ($.trim($("#prg_title").val()).length == 0 && (jQuery.url.param("app") == undefined || jQuery.url.param("app") == "")) {
            $("#uploadError").attr("innerHTML", "Please fill your program title!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //program description
        if ($.trim($("#prg_desc").val()).length == 0) {
            $("#uploadError").attr("innerHTML", "Please fill your program description!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //program category
        if ($("#catOption").val() == -1) {
            $("#uploadError").attr("innerHTML", "Please select program category!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //program price
        if ($.trim($("#prg_price").val()).length == 0) {
            $("#uploadError").attr("innerHTML", "Please fill program price!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        if (isNaN($("#prg_price").val())) {
            $("#uploadError").attr("innerHTML", "Price must be a number!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        //program agreement
        if (!$("#prg_agree").is(":checked")) {
            $("#uploadError").attr("innerHTML", "Please check agree!");
            window.location = "#";
            event.preventDefault();
            return;
        }

        if (jQuery.url.param("app") != undefined) {

                block_view("Updating...");

                var appid = jQuery.url.param("app");
                var screenshot = "";
                if ($("#scn_file1_name").attr("innerHTML").length > 0) {
                    screenshot = $("#scn_file1_name").attr("innerHTML");
                }

                if ($("#scn_file2_name").attr("innerHTML").length > 0) {
                    screenshot += "," + $("#scn_file2_name").attr("innerHTML");
                }

                if ($("#scn_file3_name").attr("innerHTML").length > 0) {
                    screenshot += "," + $("#scn_file3_name").attr("innerHTML");
                }

                if ($("#scn_file4_name").attr("innerHTML").length > 0) {
                    screenshot += "," + $("#scn_file4_name").attr("innerHTML");
                }

                if ($("#scn_file5_name").attr("innerHTML").length > 0) {
                    screenshot += "," + $("#scn_file5_name").attr("innerHTML");
                }

                var title = $("#prg_title").val();
                var area = $("#prg_lang").val();
                var author_name = $("#prg_email").val();
                var description = $("#prg_desc").val();
                var price = $("#prg_price").val();
                var categoryId = $("#catOption").val();
                var language = $("#prg_lang").val();
                var apk_url = $("#prg_file_name").html();
                var info_url = $("#info_file_name").html();
                var icon_url = $("#preview_file_name").html();

                $.ajax({
                    url: serverpath+'/updateApp',
                    type: "POST",
                    data: ({ appid: appid, title: title, author_name: author_name, description: description, price: price, apk_url: apk_url,info_url: info_url, area: area, categoryId: categoryId, screenshot: screenshot, icon_url: icon_url, language: language, device: device, country: country }),
                    datatype: "JSON",
                    success: function (data) {
                        if (data.status == "success") {
                            $("#category").html("Update App Succeed");
                            $("#resultDiv").attr("innerHTML", "<table style='margin-left:30px;'><tr><td class=\'error_text\' style='color:green;'>Your program has been updated successfully!</td></tr></table>");
                        } else {
                            $("#category").html("Update App Failed");
                            $("#resultDiv").attr("innerHTML", "<table style='margin-left:30px;'><tr><td class=\'error_text\'>" + data.result + "!</td></tr></table>");
                        }
                        end_view("Updating...");
                    }
                });
        } else {
            block_view("Uploading...");

            var screenshot = "";
            if ($("#scn_file1_name").attr("innerHTML").length > 0) {
                screenshot += $("#scn_file1_name").attr("innerHTML");
            }

            if ($("#scn_file2_name").attr("innerHTML").length > 0) {
                screenshot += "," + $("#scn_file2_name").attr("innerHTML");
            }

            if ($("#scn_file3_name").attr("innerHTML").length > 0) {
                screenshot += "," + $("#scn_file3_name").attr("innerHTML");
            }

            if ($("#scn_file4_name").attr("innerHTML").length > 0) {
                screenshot += "," + $("#scn_file4_name").attr("innerHTML");
            }

            if ($("#scn_file5_name").attr("innerHTML").length > 0) {
                screenshot += "," + $("#scn_file5_name").attr("innerHTML");
            }

            var title = $("#prg_title").val();
            var area = $("#prg_lang").val();
            var author_name = $("#prg_email").val();
            var description = $("#prg_desc").val();
            var price = $("#prg_price").val();
            var categoryId = $("#catOption").val();
            var language = $("#prg_lang").val();
            var apk_url = $("#prg_file_name").html();
            var info_url = $("#info_file_name").html();
            var icon_url = $("#preview_file_name").html();

            $.ajax({
                url: serverpath + '/uploadApp',
                type: "POST",
                data: ({ title: title, author_name: author_name, description: description, price: price, apk_url: apk_url, info_url: info_url, area: area, categoryId: categoryId, screenshot: screenshot, icon_url: icon_url, language: language, device: device, country: country }),
                datatype: "JSON",
                async: false,
                success: function (data) {
                    end_view("Uploading...");
                    if (data.status == "success") {
                        $("#category").html("Upload App Succeed");
                        $("#resultDiv").attr("innerHTML", "<table style='margin-left:30px;'><tr><td class=\'error_text\' align='left' style='color:green;'>Your program has been uploaded successfully!</td></tr></table>");
                    } else {
                        $("#category").html("Upload App Failed");
                        $("#resultDiv").attr("innerHTML", "<table style='margin-left:30px;'><tr><td align='left' class=\'error_text\'>" + data.result + "!</td></tr></table>");
                    }
                }
            });
        } //if

    });
}


function DVCUS() {
  $.ajax({
    url: "/Handle/iniSession",
    type: "POST",
    cache: false,
    data: ({act:"iniSession"}),
    success: function (data) {
      if (data != "guest") {
        $.ajax({
          url: serverpath+'/getUserProfileByUserName',
          type: "POST",
          data: ({action:"getUserProfileByUserName",username:data}),
          datatype: "JSON",
          success: function (data) {
            if (data.status == "success") {

              var jsonobj = data.result;

              $("#con_name").val(jsonobj[0].first_name);
              $("#con_mail").val(jsonobj[0].email);
            }
          }
        });
      }
    }
  });
}




function numbersonly(myfield, e, dec) {

  if ($("#prg_price").val() == ".") {
    $("#prg_price").val("");
    return false;
  } else return true;

  var key;
  var keychar;

  if (window.event) key = window.event.keyCode;
  else if (e) key = e.which;
  else return true;
  keychar = String.fromCharCode(key);

  // control keys
  if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27)) return true;

  // numbers
  else if (((".").indexOf(keychar) > -1)) {
    if ($("#prg_price").val().indexOf('.') > 0) return false;
    else return true;
  }

  // numbers
  else if ((("0123456789").indexOf(keychar) > -1)) return true;

  // decimal point jump
  else if (dec && (keychar == ".")) {
    myfield.form.elements[dec].focus();
    return false;
  }
  else return false;
}

function DVFPWS() {
  $("#pws_email").change(function () {
    if ($.trim($(this).val()).length != 0 && (ismail($(this).val()))) checkUserData2("Email", $(this).val(), "pws_emailCk");
    else $("#pws_emailCk").attr("innerHTML", checkfield(false));
  });
}

function DVJONREE() {
  $("#verify_mail").change(function () {
    if ($.trim($(this).val()).length != 0 && (ismail($(this).val()))) checkUserData2("Email", $(this).val(), "verify_mailCk");
    else $("#verify_mailCk").attr("innerHTML", checkfield(false));
  });
}
