/*
 * HIVEscript Javascript Library, Version 1.0
 * jangsam.com 2009 squall
 * 
 * HIVEscript are licensed under a Creative Commons Attribution 3.0 license.
 * http://creativecommons.org/licenses/by/3.0/deed.ko
 * If you don't want to author Link
 * You must register. Join the HIVEscript license member then you free use HIVEscript
 * http://www.hivescript.com
 */

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* HIVE prototypes */
String.prototype.left = function(strLen){return this.substr(0, strLen);};
Number.prototype.left = function(strLen){return this.toString().substr(0, strLen);};
String.prototype.right = function(strLen){return this.substring(this.length-strLen, this.length);};
Number.prototype.right = function(strLen){return this.toString().substring(this.toString().length-strLen, this.toString().length);};

String.prototype.dec = function(){return decodeURIComponent(this).replace(/\+/g, " ");};
String.prototype.enc = function(){return encodeURIComponent(this);};
String.prototype.object = function(){
  try{
    var res = this.evalJSON();
  }catch(e){
    alert("to object error : "+e.print() + "\n" + this);
  }
  return res;
}
String.prototype.array = function(){
  try{
    var res = "["+this+"]".evalJSON();
  }catch(e){
    alert("to object error : "+e.print() + "\n" + this); 
  }
  return res;
}
Error.prototype.print = function(){
  return "EN:"+(this.number&0xFFFF)+" : "+this+"\n"+this.description;
}
/* HIVE prototypes */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* the HIVE */
var HIVE = {
  Version: "1.0",
  /*
  Browser: (function(){
    var isIE, isFF, isSF, isOP, isCR;
    var suserAgent = navigator.userAgent;
    isIE = (suserAgent.indexOf("MSIE") != -1) ? true : false;
    isFF = (suserAgent.indexOf("Firefox") != -1) ? true : false;
    isSF = (suserAgent.indexOf("Safari") != -1) ? true : false;
    isOP = (suserAgent.indexOf("Opera") != -1) ? true : false;
    isCR = (suserAgent.indexOf("Chrome") != -1) ? true : false;
    if(isIE){
      try{
        var ieAt = /MSIE (\d+\.\d+)/i;
        ieAt.test(suserAgent);
        ieVer = parseFloat(RegExp.$1);
      }catch(e){
        ieVer = 6;
      }
    }
    if(isIE) return "I" + ieVer;
    else if(isFF) return "FF";
    else if(isSF) return "SF";
    else if(isOP) return "OP";
    else if(isCR) return "CR";
  })(),
  */
  dummy: (function(){
   var d, s = "U";
   d = new Date();
   s += d.getUTCHours();
   s += d.getUTCMinutes();
   s += d.getUTCSeconds();
   s += d.getUTCMilliseconds();
   return(s);
  })()
};
/* the HIVE */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* HIVEreq */
var HIVEreq = Class.create({
  initialize: function(url, pars, onsucc){
    var onerr = this.onerror.bind(this);
    new Ajax.Request(url, {method:'post', parameters:pars, onComplete:onsucc, onFailure:onerr});
  },
  onerror: function(req){
    alert("onFail:"+req.responseText);
  }
});
/* HIVEreq */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

/* HIVEreq */

var gdkBodyMask = Class.create();
gdkBodyMask.prototype = {
  initialize: function(){
    this.MaskerTG = window.document.body;
    this.locked = false;
    var MyMask = document.createElement("div");
    MyMask.id = "BodyMaskDiv";
    MyMask.className = "BodyMask";
    this.MaskerTG.appendChild(MyMask);
    this.Masker = $("BodyMaskDiv");
    this.Masker.hide();
    /* Event Observe */
    this.pageResize = this.Resizers.bindAsEventListener(this);
    Event.observe(window, 'resize', this.pageResize);
  },
  setMSG: function(sStr){
    this.Masker.update(sStr);
  },
  ShowMask: function(){
    this.Masker.setStyle({
      display:"",
      width:window.document.body.scrollWidth+"px",
      height:window.document.body.scrollHeight+50+"px"
    });
  },
  HideMask: function(){
    if(!this.locked){
    this.Masker.hide();
    }
  },
  Resizers: function(){
    this.Masker.setStyle({
      width:window.document.body.scrollWidth-1+"px",
      height:window.document.body.scrollHeight+50+"px"
    });
  },
  MaskLock: function(locked){
   this.locked = locked;
  }
} // gdkBodyMask



var gdkImageView = Class.create();
gdkImageView.prototype = {
  initialize: function(){
    this.imageViewerTG = window.document.body;
    
    var attImage = document.createElement("div");
    attImage.id = "attachImageView";
    attImage.className = "ImageViewer";
    this.imageViewerTG.appendChild(attImage);
    this.imageViewer = $("attachImageView");
    this.imageViewer.hide();
    /* //Event Observe 
    this.pageResize = this.Resizers.bindAsEventListener(this);
    Event.observe(window, 'resize', this.pageResize);
    */
  },
  ShowViewer: function(){
    this.imageViewer.setStyle({
      display:""
      /*
      width:window.document.body.scrollWidth+"px",
      height:window.document.body.scrollHeight+50+"px"
      */
    });
  },
  HideViewer: function(){
    this.imageViewer.hide();
  },
  
  //eventStop. Resizers method doesn't work. 
  Resizers: function(){
    this.imageViewer.setStyle({
      width:window.document.body.scrollWidth-1+"px",
      height:window.document.body.scrollHeight+50+"px"
    });
  },
  
  getID: function(){
    return "attachImageView";
  }
  
} // gdkImageView


/*공용?수-------------------------------------*/

//첨??일?인 ??운로드
function attachFileControl(imgRoot, attFileName){
  
  
    var reAt= /\.(jpg|jpeg|gif|bmp)$/ig;
    if (reAt.test(attFileName)){
      var p_out=[];
      p_out.push("<div style=\"width:20px;height:20px;top:0px;right:0px;position:absolute;z-index:2000;text-align:center;background:#fff;\">");
      p_out.push("<img src=\"/admin/images/delFile.gif\" style=\"cursor:pointer;margin-top:2px;\" onclick=\"myImageViewer.HideViewer();\" />");
      p_out.push("</div>");
      p_out.push("<img src=\""+imgRoot+attFileName+"\" />");

      //this.imageViewer.update(p_out.join(''));

      $(myImageViewer.getID()).update(p_out.join(''));
      
      var cTop  = Math.round((window.document.body.scrollHeight-$(myImageViewer.getID()).getHeight())/2);
      var cLeft = Math.round((window.document.body.scrollWidth -$(myImageViewer.getID()).getWidth())/2);
      var cTop2 = window.document.viewport.getScrollOffsets(); 
      //alert(cTop2[1]);
      
      $(myImageViewer.getID()).setStyle({"top":parseInt(cTop2[1]+10)+"px","left":cLeft+"px" });
      myImageViewer.ShowViewer();


//      myMask.ShowMask();
//      alert("mask");
//      $("divContent").update("<img src=\"/_file/collection/"+attFileName+"\">");
//      alert(1);
    }else{
      //??&#65533;?일???님, ?운로드 ?결
      window.open("/admin/inc/fileDown.asp?fileName="+attFileName.enc()+"&imgRoot="+imgRoot, 'fileDownLoad', 'width=100,height=100');
    }
  try{
  }catch(e){
    alert(e.description);
  }
}


