/**
 * 
 * george javascript framework
 * 
 * jasis - Event - Validate
 * 
 * with no dependancy
 */
var Jasis={
      Resource : { LOG : "/common/log_js.jsp" }
,
Event : {
   isNumberKey : function(e){ 
      // 한글막기 which = keyCode
      if((e.which >= 12592) && (e.which <= 12687)){
         return false;
      } 
   
      // 영문막기
      if( (65 <= e.which && e.which <= 65 + 25)
            || (97 <= e.which && e.which <= 97 + 25) ){
          return false;  
      }
   
      return true;
      // 숫자일때만.
      //if(  (e.which >= 48) && (e.which <= 57) ){
      //    return true;
      //}else{
      //    return false;
      //}
   }
,
   isEmailKey : function(e){
      // 한글막기 which = keyCode
      if((e.which >= 12592) && (e.which <= 12687)){
         return false;
      } 
   
      // 영문일때도
      if( (65 <= e.which && e.which <= 65 + 25)
            || (97 <= e.which && e.which <= 97 + 25) ){
          return true;  
      }
      
      // - _ 
      if(  (e.which == 95) || (e.which == 45) ){
         return true;
      }
      // 숫자일때도
      if(  (e.which >= 48) && (e.which <= 57) ){
          return true;
      }
      
      return false;
      
   }
}
,

Validate : {
   /** 주민등록번호가 올바른지 체크. */
   isJumin : function(resno){

      // 주민번호의 형태와 7번째 자리(성별) 유효성 검사
      fmt = /^\d{6}-[1234]\d{6}$/;
      if (!fmt.test(resno)) {
      //  alert("잘못된 주민등록번호입니다."); return;
         return false;
      }
      
      // 날짜 유효성 검사
      birthYear = (resno.charAt(7) <= "2") ? "19" : "20";
      birthYear += resno.substr(0, 2);
      birthMonth = resno.substr(2, 2) - 1;
      birthDate = resno.substr(4, 2);
      birth = new Date(birthYear, birthMonth, birthDate);
   
      if ( birth.getYear() % 100 != resno.substr(0, 2) ||
           birth.getMonth() != birthMonth ||
           birth.getDate() != birthDate) {
      //  alert("잘못된 주민등록번호입니다."); return;
         return false;
      }
   
      // Check Sum 코드의 유효성 검사
      buf = new Array(13);
      for (i = 0; i < 6; i++) buf[i] = parseInt(resno.charAt(i));
      for (i = 6; i < 13; i++) buf[i] = parseInt(resno.charAt(i + 1));
   
      multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
      for (i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]);
   
      if ((11 - (sum % 11)) % 10 != buf[12]) {
        //alert("잘못된 주민등록번호입니다."); return;
         return false;
      }
      
      return true;
      //alert("정상적인 주민등록번호입니다.");
   }
,   
   isEmail : function(fullEmail){
      var reg_email=/^[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[@]{1}[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[.]{1}[A-Za-z]{2,5}$/;
      return reg_email.test(fullEmail);
   }
}
,
Browser : {  
   Version: function() {    
     var version = 999; // we assume a sane browser
     if (navigator.appVersion.indexOf("MSIE") != -1){      // bah, IE again,
                                                            // lets downgrade
                                                            // version number
        version = parseFloat(navigator.appVersion.split("MSIE")[1]);
     }    
     return version;  
   }
   ,
   isIE : function(){
      return (navigator.appVersion.indexOf("MSIE") != -1); 
   }
}
,   
TextArea : {
   highlight:function(txtArea, str){
       
   }
}
,
Log : {
   write : function(message){
      var newMessage = message + " [From:" + location.href+"]"; 
      try{
         $.ajax({
            url: Jasis.Resource.LOG,
            data : {msg:newMessage},
            dataType: "json",
            success: function(data){
               
            },
            error : function (XMLHttpRequest, textStatus, errorThrown) {
             alert(textStatus + ":"+XMLHttpRequest.status  + " => 문제가 발생했습니다.");
            }
          });
      }catch(e){
         alert(e.message);
      }
   }
   ,
   debug : function(msg){
      this.write(msg);
   }
}
,
Form :{
   checkAll : function(checkbox_name){
      var chk = $("input[name="+checkbox_name+"]"); 
      if( chk.attr("checked") ){
         //$("input["+checkbox_name+"]").removeAttr( "checked" );
         chk.attr("checked",false);
      }else{
         chk.attr("checked",true);
      }
   }
,
   isCheckedAtLeast : function(checkbox_name){
      dateFormat
      var chk = $("input[name="+checkbox_name+"][checked]"); 
      return (chk.length > 0);
   } 
} // end Form
,
Date : {
   parse : function(dateString, dateFormat0) {
      var date = new Date();
      var reg = new RegExp();
      if(dateString == undefined){
         alert("인자를 넣으삼");
         return "";
      }
      if(dateFormat0 == undefined){
         reg = /([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/i;
      }
      if(dateString.length == 10){
         reg = /([0-9]{4})-([0-9]{2})-([0-9]{2})/i;
      }
      
      var arr = reg.exec(dateString);
      date.setFullYear(arr[1], arr[2]-1, arr[3]);
      date.setHours(arr[4], arr[5], arr[6], 0);
      
      return date;
   }
   ,
   format : function(dateString, date){
      return "";
   }
} // end Date
};
