﻿
function memberRegisterLoad(show){
    
   
   if(getCookie("loginid") != "" && getCookie("loginid") != "undefined" && getCookie("loginid") != null){
   //로그인시 member id 있음.
     
 
  if(show == "visible"){
    
        $.ajax({
         type: "POST",
   
         data: {"id": getCookie("loginid"),"member":"information"},
         dataType: "json",
         url: "membershipAjax.aspx",
        
         success: function (data, status) {
          


             $("#memberView1").empty();
          
          Viewinfo(data[0].name,data[0].id,data[0].pass,data[0].phone,data[0].email,data[0].buseo,data[0].icon);
          
          
         },
          error: function (request, status) {
            alert(status);
         }

       });//ajax
         
   
   }
   
   }else{
   //신규.. 또는 로그인 안했을때..
   
   /*
     $(".contentsBody1").empty();
     $(".contentsBody1").append("<table><tr height='80px' valign='middle'><td class=title_ko width=120px >회원등록</td><td class='title_en'>Registration of Membership </td></tr></table>");
     
     $(".contentsBody1").append($("#memberRegister").html());
    
     $(".member_view tr td:nth-child(1)").css("background-color","#F8F8F8");
    
   */
   
    //$("#memberRegister").
   }
 
}


function boxCheck(){

 if($("#name").val() == ""){
           document.getElementById("name").focus();
            alert("이름을 입력하세요.");
            
           }else if($("#memberID").val() == ""){
           
         if($("#inputkind").val() == ""){  
           
             alert("아이디를 입력하세요.");
             document.getElementById("memberID").focus();
           }
           
           }else if($("#memberPass").val() == ""){
           
              if($("#inputkind").val() == ""){
               alert("패스워드를 입력하세요.");
               document.getElementById("memberPass").focus();
             }
           
           }
           else if($("#memberPass2").val() == ""){
            
            if($("#inputkind").val() == ""){
               alert("패스워드 다시 입력하기를 입력해 주세요");
               document.getElementById("memberPass2").focus();
            }
           
           }
           else if($("#phone2").val() == ""){
             alert("전화번호를 입력하세요.");
             document.getElementById("phone2").focus();
           
           }else if($("#phone3").val() == ""){
            alert("전화번호를 입력하세요.");
            document.getElementById("phone3").focus();
           
           }else if($("#email").val() == ""){
            alert("email를  입력하세요.");
            document.getElementById("email").focus();
           }
        
    //confirmp

}

function updateClick2(){
  //$("#memberRegister").show();

}
/*
 $("#btnMember").click(function(){
   document.cookie = "loginid="+"";
 
     alert("d");
     $(".contentsBody").empty(); 
     $(".contentsBody").append("<iframe src='member.aspx' frameborder='0' width='500' height='500' scrolling=no></iframe>");
  });
*/

function Viewinfo(name,id,pass,phone,email,buseo,icon){

   pass = "******";
  // alert(pass);
   $("#txtID").attr("value",id);
  
  
// $("#memberRegister").css("visibility","hidden");
$("#memberRegister").hide();
  if(icon != ""){
    var strTable = '<div class="memberView1"><table><tr height="80px" valign="middle"><td class=title_ko width=120px >회원 정보</td><td class="title_en">Personal Information</td></tr></table>'
                   +' <table cellpadding=0 cellspacing=0 border=0 width="480px" class="member_view" >'
                     +'<tr height="3px"><td  width="180px" background="img/sky_line1.gif"></td><td colspan=2 width="300px" background="img/sky_line1.gif"></td> </tr>'                          
                        + '<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;이름:</td><td id="view_name">&nbsp;&nbsp;'+name+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;아이디:</td><td id="view_id" class="view_id">&nbsp;&nbsp;'+id+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;패스워드:</td><td id="view_pass">&nbsp;&nbsp;'+pass+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;휴대폰:</td><td id="view_phone">&nbsp;&nbsp;'+phone+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;이메일 주소:</td><td id="view_email">&nbsp;&nbsp;'+email+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;부서:</td><td id="view_buseo">&nbsp;&nbsp;'+buseo+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;회원등급:</td><td id="view_grade">&nbsp;&nbsp;'+'준회원'+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px" height="120px">&nbsp;&nbsp;&nbsp;&nbsp;사진:</td><td id="view_grade">&nbsp;&nbsp;<img src=gallery/photos/'+icon+' width=80px height=80px ></td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=160px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                    
                        +'</table>'
                        +'</div>';
     
    }else{
    var strTable = "";
    if($("#txtICon").val() == ""){
    
    strTable = '<div class="memberView1"><table><tr height="80px" valign="middle"><td class=title_ko width=120px >회원 정보</td><td class="title_en">Personal Information</td></tr></table>'
                   +' <table cellpadding=0 cellspacing=0 border=0 width="480px" class="member_view" >'
                     +'<tr height="3px"><td  width="180px" background="img/sky_line1.gif"></td><td colspan=2 width="300px" background="img/sky_line1.gif"></td> </tr>'                          
                        + '<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;이름:</td><td id="view_name">&nbsp;&nbsp;'+name+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;아이디:</td><td id="view_id" class="view_id">&nbsp;&nbsp;'+id+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;패스워드:</td><td id="view_pass">&nbsp;&nbsp;'+pass+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;휴대폰:</td><td id="view_phone">&nbsp;&nbsp;'+phone+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;이메일 주소:</td><td id="view_email">&nbsp;&nbsp;'+email+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;부서:</td><td id="view_buseo">&nbsp;&nbsp;'+buseo+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;회원등급:</td><td id="view_grade">&nbsp;&nbsp;'+'준회원'+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px" height="120px">&nbsp;&nbsp;&nbsp;&nbsp;사진:</td><td id="view_grade">&nbsp;&nbsp;<img src=gallery/photos/man.jpg width=80px height=80px ></td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=160px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                    
                        +'</table>'
                        +'</div>'; 
      }else{
      
    strTable = '<div class="memberView1"><table><tr height="80px" valign="middle"><td class=title_ko width=120px >회원 정보</td><td class="title_en">Personal Information</td></tr></table>'
                   +' <table cellpadding=0 cellspacing=0 border=0 width="480px" class="member_view" >'
                     +'<tr height="3px"><td  width="180px" background="img/sky_line1.gif"></td><td colspan=2 width="300px" background="img/sky_line1.gif"></td> </tr>'                          
                        + '<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;이름:</td><td id="view_name">&nbsp;&nbsp;'+name+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;아이디:</td><td id="view_id" class="view_id">&nbsp;&nbsp;'+id+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;패스워드:</td><td id="view_pass">&nbsp;&nbsp;'+pass+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;휴대폰:</td><td id="view_phone">&nbsp;&nbsp;'+phone+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;이메일 주소:</td><td id="view_email">&nbsp;&nbsp;'+email+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;부서:</td><td id="view_buseo">&nbsp;&nbsp;'+buseo+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px">&nbsp;&nbsp;&nbsp;&nbsp;회원등급:</td><td id="view_grade">&nbsp;&nbsp;'+'준회원'+'</td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=180px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                        +'<tr height="40px"><td width="180px" height="120px">&nbsp;&nbsp;&nbsp;&nbsp;사진:</td><td id="view_grade">&nbsp;&nbsp;<img src=gallery/photos/'+$("#txtICon").val()+' width=80px height=80px ></td></tr>'
                        +'<tr><td><img src="img/grid_line.gif" width=160px height=1px ></td><td colspan=2><img src="img/grid_line.gif" width=300px height=1px ></td></tr>'
                    
                        +'</table>'
                        +'</div>'; 
      
      
      
      
      }
    
    }
              document.cookie = "state=view";
    
             $(".contentsBody1").empty();
             $(".contentsBody1").append(strTable); 
             //div_update
             $(".hrefRegister").css("visibility","hidden");
              $("#btnUpdate2").css("visibility","visible");
              
             $("#memberView1").css("visibility","visible");         
             $(".member_view tr td:nth-child(1)").css("background-color","#F8F8F8").css("font-weight","bold");


}






function confirmPass(){

  if($("#memberPass").val() != $("#memberPass2").val()){

     alert("비밀번호가 다릅니다. 다시 입력해 주세요.");
    document.getElementById("memberPass").focus();     
  
  }


}

 $(document).ready(function(){
      
      
      $("a[class='hrefPassUpdate']").click(function(){
         $(".trpass").show();   
         document.getElementById("memberPass").focus();  
        // $(this).hide();
        $("#updateMessage").hide();
         
         
      });
      
      $("#memberPass2").blur(function(){
 
        confirmPass();
  
      });
      
       $("#inputkind").hide();
       
      
    $(".idcheck").livequery("click",function(){
 
 
      if($("#memberID").val() != ""){
      $.ajax({
        type: "POST",
        data: {"id": $("#memberID").val(),"check":"ch"},
        dataType: "text",
        url: "login.aspx",
        success: function (data, status) {
    
           $("#txtCheck").attr("value",data);
          
           if(data == "unavailable"){
              
             alert("이미 등록된 아이디 입니다.");
              $("#txtCheck").attr("value","");
           
           }else{
            alert("사용할 수 있는 아이디 입니다.");
           }
           
        },
         error: function (request, status) {
            alert(status);
        }

    });
       
    }else{
      alert("ID를 입력해 주세요");
      document.getElementById("memberID").focus();
    }
 });
    
    function ViewMessage(){
     
    }
    
    function boxContents(){
    
    
            $.ajax({
         type: "POST",
   
         data: {"id": $("#txtID").val(),"member":"information"},
         dataType: "json",
         url: "membershipAjax.aspx",
        
         success: function (data, status) {
      
          
         // Viewinfo(data[0].name,data[0].id,data[0].pass,data[0].phone,data[0].email,data[0].buseo);
          $("#memberID").attr("Text",$("#txtID").val());
          $("#memberPass").attr("Text",data[0].pass);
          $("#name").attr("Text",data[0].name);
          $("#email").attr("Text",data[0].email);
          //$("#buseo").attr("Text",data[0].buseo);
          $("#buseo").attr("Text","이정정희");
          //$("#email").attr("Text",data[0].email);
                    
          
          
         },
          error: function (request, status) {
            alert(status);
         }

       });//ajax

    
    
    
    }
     
     



//btnReg
$(".hrefRegister").livequery("click",function(){

  
    boxCheck();
  
   
                 
   if($("#name").val() != "" && $("#memberID").val() != "" && $("#memberPass").val() != "" && $("#memberPass2").val() != "" && $("#phone2").val() != "" && $("#phone3").val() != "" && $("#email").val() != ""){ 
       
     if($("#inputkind").val() == ""){
     
         if($("#txtCheck").val() != "available" && $("#txtCheck").val() != "unavailable"){
              alert("아이디 중복체크를 하세요.");
              $("#txtCheck").attr("value","");
             
            }else if($("#txtCheck").val() == "unavailable"){
              alert("사용할 수 없는 아이디 입니다.");
              $("#txtCheck").attr("value","");
          }
         
         
           if( $("#txtCheck").val() != "" && $("#txtCheck").val() != "unavailable" && $("#txtCheck").val() != "undefined"){
      
    
      
         $.ajax({
        type: "POST",
        data: {"name":$("#name").val(),"id": $("#memberID").val(),"pass":$("#memberPass").val(),"phone1":$("#ddlPhone").val(),"phone2":$("#phone2").val(),"phone3":$("#phone3").val(),"email":$("#email").val(),"buseo":$("#buseo").val(),"number":$("#inputNum").val()},
        dataType: "text",
        url: "membershipAjax.aspx",
        
        success: function (data, status) {
      
           $("#registerMessage").empty();
      
           if(data == "아래와 같이 등록되었습니다."){
         
         
             $("#memberForm").hide();
             $("#memberView").empty();
         
         
          Viewinfo($("#name").val(),$("#memberID").val(),$("#memberPass").val(),$("option:selected").val()+"-"+$("#phone2").val()+"-"+$("#phone3").val(),$("#email").val(),$("#buseo").val(),$("#txtIcon").val());
         $("#updateb").css("visibility","visible");
         
          
          }else if(data == "이미 등록되어 있는 아이디 입니다."){
          
           $("#registerMessage").empty();
             $("#registerMessage").append(data);
              $("#memberView").empty();
          
          
          }else{
          
              $("#registerMessage").empty();
              $("#registerMessage").append(data);
              $("#memberView").empty();
          }
        },
         error: function (request, status) {
            alert(status);
        }

    });//ajax
    }//idcheck여부
    
    
    }else{
     //Password 있는 update 등록시
     
    
       $.ajax({
        type: "POST",
        data: {"name":$("#name").val(),"id": $("#txtID").val(),"pass":$("#memberPass").val(),"phone1":$("#ddlPhone").val(),"phone2":$("#phone2").val(),"phone3":$("#phone3").val(),"email":$("#email").val(),"buseo":$("#buseo").val(),"number":$("#inputNum").val(),"kind":"update"},
        dataType: "text",
        url: "membershipAjax.aspx",
        
        success: function (data, status) {
       
          if(data == "update"){
           $("#registerMessage").empty();
           $("#registerMessage").append("수정되었습니다.");
        
             $("#memberForm").hide();
           
       
        
           Viewinfo($("#name").val(),$("#txtID").val(),$("#memberPass").val(),$("option:selected").val()+"-"+$("#phone2").val()+"-"+$("#phone3").val(),$("#email").val(),$("#buseo").val(),$("#txtIcon").val());
        
            
           $("#updateb").css("visibility","visible");
          }
         
        
        },
         error: function (request, status) {
            alert(status);
        }

    });
     
   
     
    
    }//else
  
    }//else
    else if($("#name").val() != "" && $("#memberID").val() != "" && $("#phone2").val() != "" && $("#phone3").val() != "" && $("#email").val() != ""){
   
      //pass 없는 update 등록시
      
      
       $.ajax({
        type: "POST",
        //data: {"name":$("#name").val(),"id": $("#txtID").val(),"pass":$("#memberPass").val(),"phone1":$("#ddlPhone").val(),"phone2":$("#phone2").val(),"phone3":$("#phone3").val(),"email":$("#email").val(),"buseo":$("#buseo").val(),"number":$("#inputNum").val(),"kind":"update"},
        
        data: {"name":$("#name").val(),"id": $("#txtID").val(),"phone1":$("#ddlPhone").val(),"phone2":$("#phone2").val(),"phone3":$("#phone3").val(),"email":$("#email").val(),"buseo":$("#buseo").val(),"number":$("#inputNum").val(),"kind":"update"},dataType: "text",
        url: "membershipAjax.aspx",
        
        success: function (data, status) {
       
          if(data == "update"){
           $("#registerMessage").empty();
           $("#registerMessage").append("수정되었습니다.");
        
             $("#memberForm").hide();
            
        
           Viewinfo($("#name").val(),$("#txtID").val(),$("#memberPass").val(),$("option:selected").val()+"-"+$("#phone2").val()+"-"+$("#phone3").val(),$("#email").val(),$("#buseo").val(),$("#txtIcon").val());
        
            
           $("#updateb").css("visibility","visible");
          }
         
        
        },
         error: function (request, status) {
            alert(status);
        }

    });//ajax
     
      
   
   
   
    }
    
             
          
   });//.hrefRegister
        
 });//ready
