$(document).ready(function(){
   document.body.onload = FuncJqueryToBodyOnLoadSetting;
});

//Body Onload 처리
function FuncJqueryToBodyOnLoadSetting(){
   FuncJqueryToAjaxDefaultReadySetting();    //ICARUSX 처리
   FuncJqueryDeviceRotateWidthSize();        //모바일 디바이스에 따른 사이즈처리
}

//Ajax 를 통해 호출된 테그의 기본설정처리
function FuncJqueryToAjaxDefaultReadySetting(){

   //롤오버 설정
   $("tr[JqueryRollOver=Y]").each(function(){
      if($(this).attr("jQueryDftOver")!="Y"){
         $(this).hover(function(){
            $(this).css({
               "background":"#F9F9F9",
               "cursor":"pointer"
            });
         },
         function(){
            $(this).css("background","");
         });
         $(this).attr({"jQueryDftOver":"Y"});
      }
   });

   //롤오버 설정
   $("td[JqueryRollOver=Y]").each(function(){
      if($(this).attr("jQueryDftOver")!="Y"){
         $(this).hover(function(){
            $(this).css({
               "background":"#F9F9F9",
               "cursor":"pointer"
            });
         },
         function(){
            $(this).css("background","");
         });
         $(this).attr({"jQueryDftOver":"Y"});
      }
   });

   $("td[onclick]").each(function(){
      if($(this).attr("jQueryDftPointer") != "Y"){
         $(this).css({cursor:"pointer"});
         $(this).attr({"jQueryDftPointer":"Y"});
      }
   });

   $("tr[onclick]").each(function(){
      if($(this).attr("jQueryDftPointer") != "Y"){
         $(this).css({cursor:"pointer"});
         $(this).attr({"jQueryDftPointer":"Y"});
      }
   });

   //이벤트 이미지 커서설정
   $("img").each(function(){
      if($(this).attr("jQueryDftAlign") != "Y"){
         $(this).attr("align","absmiddle");
         $(this).attr({"jQueryDftAlign":"Y"});
      }
   });

   $("img[onclick]").each(function(){
      if($(this).attr("jQueryDftPointer") != "Y"){
         $(this).css({cursor:"pointer"});
         $(this).attr({"jQueryDftPointer":"Y"});
      }
   });

   $("img[onmouseover]").each(function(){
      if($(this).attr("jQueryDftPointer") != "Y"){
         $(this).css({cursor:"pointer"});
         $(this).attr({"jQueryDftPointer":"Y"});
      }
   });

   $("img[onkeydown]").each(function(){
      if($(this).attr("jQueryDftPointer") != "Y"){
         $(this).css({cursor:"pointer"});
         $(this).attr({"jQueryDftPointer":"Y"});
      }
   });

   $("div[onclick]").each(function(){
      if($(this).attr("jQueryDftPointer") != "Y"){
         $(this).css({cursor:"pointer"});
         $(this).attr({"jQueryDftPointer":"Y"});
      }
   });

   $("p[onclick]").each(function(){
      if($(this).attr("jQueryDftPointer") != "Y"){
         $(this).css({cursor:"pointer"});
         $(this).attr({"jQueryDftPointer":"Y"});
      }
   });

   $("span[onclick]").each(function(){
      if($(this).attr("jQueryDftPointer") != "Y"){
         $(this).css({cursor:"pointer"});
         $(this).attr({"jQueryDftPointer":"Y"});
      }
   });

   $("div[JqueryDivDrag=Y]").each(function(){
      if($(this).attr("JqueryDivDrag") == "Y"){
         $(this).draggable();    //DIV 드래그처리
         $(this).attr({"JqueryDivDrag":"N"});
         $(this).css({"position":"absolute"});
      }
   });

   $("img[alt]").each(function(){      //Alt 오버주석을 title 로 추가
      if($(this).attr("jQueryDftAlt") != "Y"){
         $(this).attr({"title":$(this).attr("alt")});
         $(this).attr({cursor:"pointer"});
         $(this).attr({"jQueryDftAlt":"Y"});
      }
   });

   $(".JqueryResize").JqueryReSizeHandle();  //텍스트 박스 리사이즈 처리
   $("div[JqueryDivPopup]").hide();          //ajax 리페이지시 닫혀야할 팝업

   FuncJqueryChkInputNumber();   //제이쿼리 번호입력체크
   FuncJqueryToCalender();       //제이쿼리 달력 UI
   FuncJqueryDeviceRotateWidthSize();     //모바일 해상도 변경
}

//제이쿼리 번호입력체크
function FuncJqueryChkInputNumber(){
   //숫자만 입력처리
   for(i=0; i<$("input[jQueryInputNumber=Y]").size(); i++){
      $("input[jQueryInputNumber=Y]").eq(i).each(function(){
         $(this).keyup(function(e){
            if((parseInt(e.keyCode) >= 96) && (parseInt(e.keyCode) <= 105) || (parseInt(e.keyCode) >= 48) && (parseInt(e.keyCode) <= 57) || e.keyCode == 8 || e.keyCode == 189 || e.keyCode == 13 || e.keyCode == 229  ||  e.keyCode == 109 || e.keyCode == 9 || e.keyCode == 16) {
               return true;
            }
            window.alert("숫자만 입력하세요");
            $(this).val("");
            $(this).focus();
            return true;
         });
         $(this).attr({"jQueryInputNumber":"N"});
      });
   }
}

//제이쿼리 달력 UI
function FuncJqueryToCalender(){
   //달력처리1
   $("input[jQueryInputCalender=Ymd]").datepicker({
      dateFormat:"yymmdd",
      changeMonth:true,
      changeYear:true
   });

   //달력처리2
   $("input[jQueryInputCalender=Y-m-d]").datepicker({
      dateFormat:"yy-mm-dd",
      changeMonth:true,
      changeYear:true
   });
}

//체크박스 일괄선택
function FuncJqueryToCheckBoxAllCheck(allname,name){
   if($("input:checkbox["+allname+"=Y]:checked").length > 0){
      $("input:checkbox["+name+"=Y]").attr("checked","checked");
   }else{
      $("input:checkbox["+name+"=Y]").attr("checked","");
   }
}

//경고출력후 뒤로
function FuncJqueryToAlertGoBack(){
   $("#JqueryMsgAlert").each(function(){
      var msg = $("#JqueryMsgAlert").html();
      $(this).attr("id","");        //중복검사를 방지하기 위해 ID 값을 제거
   });
}

//제이쿼리 텍스트 박스 리사이즈
jQuery.fn.JqueryReSizeHandle = function(){
   return this.each(function(){
   var me = $(this);
   me.after(
   $("<div class='JqueryResizerBar' oncontextmenu='return false' onselectstart='return false' ondragstart='return false'></div>").bind("mousedown", function(e){
      var h = me.height();
      var y = e.clientY;
      var movehandler = function(e){
         me.height(Math.max(40, e.clientY + h - y));
      };
      var uphandler = function(e){
         $("html").unbind("mousemove",movehandler).unbind("mouseup",uphandler);
         };
         $("html").bind("mousemove", movehandler).bind("mouseup", uphandler);
         })
      );
   }),
   //리사이즈 바 CSS
   $(".JqueryResizerBar").css({
      "background-color":"#F4F4F4",
      "cursor":"s-resize",
      "width":"100%",
      "padding":"0.2em 0em 0.2em 0em",
      "border-top":"1px solid #DEDEDE",
      "border-bottom":"1px solid #DEDEDE",
      "background-image":"url('icon_pack/ico_down_arrow.gif')",
      "background-repeat":"no-repeat",
      "background-position":"center"
   }),
   $(this).attr("class","");           //중복실행을 막기위해 Class 명을 변경
}

//아이폰 및 스마트폰 좌우 회전에 따른 넓이및 객체처리
function FuncJqueryDeviceRotateWidthSize(){
   if(SETT_ICARUSX_brower == "Mobile"){

      document.body.onorientationchange = FuncJqueryDeviceRotateWidthSize;    //모바일 디바이스의 경우 회전체크처리

      var Type = window.orientation;
      var width = "";
      var Rotate0 = "";
      var Rotate320 = "";
      var RotateP90 = "";
      var RotateD90 = "";
      var RotateP180 = "";
      var RotateD180 = "";

      /////////////////// 콘솔에 맞는 넓이 변수 //////////////////////
      if(SETT_ICARUSX_brower == "Mobile"){
         Rotate0 = 320;
         Rotate320 = 320;
         RotateP90 = 480;
         RotateD90 = 480;
         RotateP180 = 320;
         RotateD180 = 30;
      }
      /////////////////// 콘솔에 맞는 넓이 변수 //////////////////////

      if(Type == 0){
         width = Rotate0;
      }else if(Type == -90){
         width = RotateD90;
      }else if(Type == 90){
         width = RotateP90;
      }

      //특정 객체내의 이미지를 체크하여 사이즈를 조절시
      $("div[jQueryRotateMobileResize=Y]").each(function(){
         for(i=0; i<$(this).find("img").size(); i++){
            $(this).find("img").eq(i).each(function(){
               if($(this).attr("OldWitdh") > 0){         //백업된 사이즈
                  var oldwidht = $(this).attr("OldWitdh");
               }else{
                  var oldwidht = parseFloat($(this).css("width"));
               }
               if(oldwidht > width){
                  if(!$(this).attr("OldWitdh")){         //사이즈 백업
                     $(this).attr({"OldWitdh":oldwidht});
                  }
                  $(this).css({"width":width});
               }
            });
         }
      });

      /*
      //모든 이미지를 체크하여 사이즈를 조절시
      for(i=0; i<$("img").size(); i++){
         $("img").eq(i).each(function(){
            if($(this).attr("OldWitdh") > 0){         //백업된 사이즈
               var oldwidht = $(this).attr("OldWitdh");
            }else{
               var oldwidht = parseFloat($(this).css("width"));
            }
            if(oldwidht > width){
               if(!$(this).attr("OldWitdh")){         //사이즈 백업
                  $(this).attr({"OldWitdh":oldwidht});
               }
               $(this).css({"width":width});
            }
         });
      }
      */

   }
}

