//PNG24 이미지 보이기
function setPng24(obj) {
    obj.width=obj.height=1;
    obj.className=obj.className.replace(/\bpng24\b/i,'');
    obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
    obj.src='';
    return '';
}


//aka makeDesignerHappy(dEl); 오페라 보기
function breakWord(dEl){

    if(!dEl || dEl.nodeType !== 1){

        return false;

    } else if(dEl.currentStyle && typeof dEl.currentStyle.wordBreak === 'string'){

        //Lazy Function Definition Pattern, Peter's Blog
        //From http://peter.michaux.ca/article/3556

        breakWord = function(dEl){
            //For Internet Explorer
            dEl.runtimeStyle.wordBreak = 'break-all';
            return true;
        }

        return breakWord(dEl);

    }else if(document.createTreeWalker){

        //Faster Trim in Javascript, Flagrant Badassery
        //http://blog.stevenlevithan.com/archives/faster-trim-javascript

        var trim = function  (str) {
            str = str.replace(/^\s\s*/, '');
            var ws = /\s/,
            i = str.length;
            while (ws.test(str.charAt(--i)));
            return str.slice(0, i + 1);
        }

        //Lazy Function Definition Pattern, Peter's Blog
        //From http://peter.michaux.ca/article/3556

        breakWord = function(dEl){

            //For Opera, Safari, and Firefox
            var dWalker = document.createTreeWalker(dEl, NodeFilter.SHOW_TEXT, null, false);
            var node,s,c = String.fromCharCode('8203');
            while (dWalker.nextNode())
            {
                node = dWalker.currentNode;
                //we need to trim String otherwise Firefox will display
                //incorect text-indent with space characters
                s = trim( node.nodeValue ) .split('').join(c);
                node.nodeValue = s;
            }
            return true;
        }

        return breakWord(dEl);


    }else{
        return false;
    }
}

function initMoving(target,leftRevision,topRevision) {


    if (target==''){
        return false;
    }

    var obj = document.getElementById(target);
    obj.style.position = "absolute";

    //getTop 함수 정의 (pageYOffest 혹은 scrollTop 혹은 0)
    if (typeof(window.pageYOffset) == "number") {
        obj.getTop = function() {
            return window.pageYOffset;
        }
    } else if (typeof(document.documentElement.scrollTop) == "number") {
        obj.getTop = function() {
            return document.documentElement.scrollTop;
        }
    } else {
        obj.getTop = function() {
            return 0;
        }
    }

    //getHeight 함수 정의 (self.innerHeight 혹은 clientHeight 혹은 500)
    if (self.innerHeight) {
        obj.getHeight = function() {
            return self.innerHeight;
        }
    } else if(document.documentElement.clientHeight) {
        obj.getHeight = function() {
            return document.documentElement.clientHeight;
        }
    } else {
        obj.getHeight = function() {
            return 500;
        }
    }

    //getScreenWidth 함수 정의 (self.innerWidth 혹은 clientWidth 혹은 880)
    if (self.innerWidth) {
        obj.getScreenWidth = function() {
            return self.innerWidth;
        }
    } else if(document.documentElement.clientWidth) {
        obj.getScreenWidth = function() {
            return document.documentElement.clientWidth;
        }
    } else {
        obj.getScreenWidth = function() {
            return 880;
        }
    }

    //getWidth 함수 정의 (obj.offsetWidth 혹은 500)
    if (obj.offsetWidth) {
        obj.getWidth = function() {
            return obj.offsetWidth;
        }
    } else {
        obj.getWidth = function() {
            return 500;
        }
    }

    var posTopout = obj.getTop() + obj.getHeight() / 2 - 110;
    obj.style.top = posTopout +  topRevision + "px";

    var posWidthout = (880-obj.getWidth())/2;
    obj.style.left = posWidthout + leftRevision + "px";


    obj.move = setInterval(function() {
        var topR= topRevision;
        var posTopin = obj.getTop() + obj.getHeight() / 2 - 110;
        obj.style.top = posTopin + topR + "px";
    }, 20)
}

function initCenter(target,leftRevision,topRevision) {

    if (target==''){
        return false;
    }

    var obj = document.getElementById(target);
    obj.style.position = "absolute";

    //getTop 함수 정의 (pageYOffest 혹은 scrollTop 혹은 0)
    if (typeof(window.pageYOffset) == "number") {
        obj.getTop = function() {
            return window.pageYOffset;
        }
    } else if (typeof(document.documentElement.scrollTop) == "number") {
        obj.getTop = function() {
            return document.documentElement.scrollTop;
        }
    } else {
        obj.getTop = function() {
            return 0;
        }
    }

    //getHeight 함수 정의 (self.innerHeight 혹은 clientHeight 혹은 500)
    if (self.innerHeight) {
        obj.getHeight = function() {
            return self.innerHeight;
        }
    } else if(document.documentElement.clientHeight) {
        obj.getHeight = function() {
            return document.documentElement.clientHeight;
        }
    } else {
        obj.getHeight = function() {
            return 500;
        }
    }

    //getScreenWidth 함수 정의 (self.innerWidth 혹은 clientWidth 혹은 880)
    if (self.innerWidth) {
        obj.getScreenWidth = function() {
            return self.innerWidth;
        }
    } else if(document.documentElement.clientWidth) {
        obj.getScreenWidth = function() {
            return document.documentElement.clientWidth;
        }
    } else {
        obj.getScreenWidth = function() {
            return 880;
        }
    }

    //getWidth 함수 정의 (obj.offsetWidth 혹은 500)
    if (obj.offsetWidth) {
        obj.getWidth = function() {
            return obj.offsetWidth;
        }
    } else {
        obj.getWidth = function() {
            return 500;
        }
    }

    var posTopout = obj.getTop() + obj.getHeight() / 2 - 110;
    obj.style.top = posTopout +  topRevision + "px";

    var posWidthout = (880-obj.getWidth())/2;
    obj.style.left = posWidthout + leftRevision + "px";

    var topR= topRevision;
    var posTopin = obj.getTop() + obj.getHeight() / 2 - 110;
    obj.style.top = posTopin + topR + "px";
}

//new Window
function windowOpen(url, popupname, x, y)
{
    window.open(url,popupname,"toolbar=no,width="+x+",height="+y+ ",top="+ (screen.availheight- y )/2+",left="+(screen.availwidth- x)/2 +",directories=no,status=no,scrollbars=yes,resizable=no,menubar=no");
}

//new Window
function windowOpen2(url, popupname, x, y)
{
    window.open(url,popupname,"toolbar=no,width="+x+",height="+y+ ",top="+ (screen.availheight- y )/2+",left="+(screen.availwidth- x)/2 +",directories=no,status=no,scrollbars=no,resizable=no,menubar=no");
}

function addCommas(str){
  str = ""+str+"";
  var retValue = "";
  for(i=0; i<str.length; i++){
      if(i > 0 && (i%3)==0) {
          retValue = str.charAt(str.length - i -1) + "," + retValue;
      } else {
          retValue = str.charAt(str.length - i -1) + retValue;
      }
  }
  return retValue;
}

function removeCommas(str){
      str = ""+str+"";
      var retValue = "";
      for(i=0; i<str.length; i++){
          if(str.charAt(i)==",") continue;
          retValue += str.charAt(i);
      }
      return retValue;
}

function windowClose(isConfirm){
    if(isConfirm){
        if(!confirm("그냥 종료하시면 입력하신 내용이 사라집니다.\n정말로 종료하시겠습니까?")) {
            return;
        }
    }
    window.close();
}

function getFormElementLength(form,inputName){
    elementLength = 0;

    try {
        gameOrderObj=form[inputName];
        try {
            if(gameOrderObj.length==undefined){
                elementLength=1;
            }else{
                elementLength=gameOrderObj.length;
            }
        } catch (e) {
            elementLength=1;
        }
    } catch (e) {
    }

    return elementLength;
}


function convertComma(Obj,arg1){
        var paramPoint = Obj.value;
        if(paramPoint=="") paramPoint=0;
        var tempPointInt = parseInt(removeCommas(paramPoint),10);
        paramPoint=addCommas(tempPointInt);
        Obj.value = paramPoint;
        document.getElementById(arg1).value=tempPointInt;
}

/* 20080528 Javascript */
function lightBox() {
    WindowHeight = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
    OffWidth = document.documentElement.scrollWidth;
    OffHeight = document.documentElement.scrollHeight;
    if ( OffHeight < WindowHeight ) { OffHeight = WindowHeight; 	}

    var spinBox = document.createElement('div');
    spinBox.style.backgroundColor = "#000000";
    spinBox.id = "ThumbnailScroll_Box";
    spinBox.style.width = OffWidth + "px";
    spinBox.style.height = OffHeight + "px";
    spinBox.style.position = "absolute";
    spinBox.style.zIndex = 50;
    spinBox.style.left = spinBox.style.top = 0 + "px";
    if ( navigator.appName.indexOf("Explorer") != -1 ) {
        spinBox.style.filter="Alpha(opacity=30)";
    } else {
        spinBox.style.opacity=0.3;
    }
    document.documentElement.getElementsByTagName("body")[0].appendChild(spinBox);
}

function lightBoxclose() {
    document.documentElement.getElementsByTagName("body")[0].removeChild(document.getElementById("ThumbnailScroll_Box"));
    return;
}
