function ISYMRKEN() {
  $("#fmrImg_Load").click(function () {
    navigateApp("freeNavBar", this.id, "FreeApp", "topFreeMR");
  });

  $("#fmpImg_Load").click(function () {
    navigateApp("freeNavBar", this.id, "FreeApp", "topFreeMP");
  });

  $("#fhrImg_Load").click(function () {
    navigateApp("freeNavBar", this.id, "FreeApp", "topFreeHR");
  });

  $("#pmrImg_Load").click(function () {
    navigateApp("paidNavBar", this.id, "PaidApp", "topPaidMR");
  });

  $("#pmpImg_Load").click(function () {
    navigateApp("paidNavBar", this.id, "PaidApp", "topPaidMP");
  });

  $("#phrImg_Load").click(function () {
    navigateApp("paidNavBar", this.id, "PaidApp", "topPaidHR");
  });

  $("#freeImg_Load").click(function () {
    navigatePrice("free", "paidImg_Load", this.id, "FreeApp", "PaidApp");
  });

  $("#paidImg_Load").click(function () {
    navigatePrice("paid", "freeImg_Load", this.id, "PaidApp", "FreeApp");
  });

  $("#query_kw").click(function () {
    $(this).css("border-color", "white");

    if ($(this).val() == "search applications") $(this).val("");
  });

  $('#query_kw').keyup(function (e) {
       //alert(e.keyCode);
       if (e.keyCode == 13) {
           var kw = $(this).val();

           if (kw.length == 0 || kw == "search applications") {
               $("#query_kw").css("border-color", "red");
           } else {
               if (pagename != "ENDWN") window.open("/Application?keyword=" + kw, "_self");
               else queryApp(kw);
           }
       }
  });
  
  $("#query_app").click(function () {
    var kw = $("#query_kw").val();

    if (kw.length == 0 || kw == "search applications") {
      $("#query_kw").css("border-color", "red");
    } else {
      if (pagename != "ENDWN") window.open("/Application?keyword=" + kw, "_self");
      else queryApp(kw);
    }
 });



}

function ENMBRENDPF() {



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

  $("#tolevel2Ck").change(function () {

    openUpgradeDialog();
  });

  $("#submitBtn").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") {
    //if ($("#profile_country").val() == "0") {
      $("#profileError").attr("innerHTML", "Please select your country!");
      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();
              var paypadid = jsonobj[0].paypad_id;
              var area = $("#profile_lang").val();
              var sex = jsonobj[0].gender;
              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 country = $("#profile_country :selected").val();
              var timezone = "";
              var website = $("#profile_website").val();
              var bankname = jsonobj[0].bankname;
              var billaccount = jsonobj[0].billaccount;
              var bankaba = jsonobj[0].bankABA;
              var bankswift = jsonobj[0].bankSWIFT;
              var notice1 = ($("#profile_notice1").is(":checked")) ? 1 : 0;
              var notice2 = ($("#profile_notice2").is(":checked")) ? 1 : 0;
              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,picture:picture,'sex':sex,bankaba:bankaba,bankswift:bankswift,paymenttype:paymenttype}),
                datatype: "JSON",
                success: function (data) {
                  if (data.status == "success") {
/*
                    if($("#profile_img_name").attr("innerHTML")!=""){
                    window.location = "AndAc.php?pageid=ENMBRENDPF";
                    return;
                    }
                    $("#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 = "/Member/MyProfile";
                    //alert(data);
                  } 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...");
              $("#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);
                $("#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 = "/Member/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 ENDWNDTL() {
  $("#query_kw").click(function () {
    $(this).css("border-color", "white");

    if ($(this).val() == "search applications") $(this).val("");
  });

  $("#query_app").click(function () {
    var kw = $("#query_kw").val();

    if (kw.length == 0 || kw == "search applications") {
      $("#query_kw").css("border-color", "red");
    } else {
      if (pagename != "ENDWN") window.open("/Application?keyword=" + kw, "_self");
      else queryApp(kw);
    }
  });

  $("#downloadBtn").click(function () {
    window.location = "#";
    openDownloadDialog();
  });
}

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

  //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", "");
      //$("#sign_cfEmailCk").attr("innerHTML",checkfield(true));
    }
  });

  //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", "");
    }
  });

  $("#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", "");
    }
  });

  $("#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", "");
    }
  });

  $("#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", "");
    }
  });

  $("#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", "");
    }
  });

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

function ENMBRENDPW() {
  $("#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 ENMBRENDMIL() {
  $("#start_date").datepicker({
    dateFormat: 'yy-mm-dd'
  });
  $("#end_date").datepicker({
    dateFormat: 'yy-mm-dd'
  });
}

function ENMBRENDAD() {
    $("#comment_rate").rating('/Handle/Rating', {
    maxvalue: 5,
    increment: .5
  });
}

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

function ENSUPCNT() {
  $.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 ENMBRENDPWS() {
  $("#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 ENJONREE() {
  $("#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));
  });
}

function ismail(email) {
  var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (regex.test(email)) return true;
  else return false;
}
