/*
 * publishing.js
 * @description : 퍼블리싱 관련 스크립트
 */

/**
 * UI 연동 일반 Function
 */

/**
 * flash write
 */

function flashSet(s,w,h,d,bg,t,f,l){

	var code = "";
    code  = "<object type=\"application/x-shockwave-flash\" ";
    code +=         "data=\""+s+"\" ";
    code +=         "width=\""+w+"\" height=\""+h+"\" id=\""+d+"\">";
    code += "<param name=\"movie\" value=\""+s+"\" />";
    code += "<param name=\"quality\" value=\"high\" />";
    code += "<param name=\"wmode\" value=\""+t+"\" />";
    code += "<param name=\"menu\" value=\"false\" />";
    code += "<param name=\"allowScriptAccess\" value=\"always\" />";
    code += "<param name=\"swliveconnect\" value=\"true\" />";
	code += "<param name='scale' value='"+f+"' />";
	code += "<param name='salign' value='"+l+"' />";
    code += "</object>";

	return code;
}
function flashWrite(s,w,h,d,bg,t,f,l) {
	document.write (flashSet(s,w,h,d,bg,t,f,l));
}


/**
 * syncIframe
 * @Description : Iframe 크기조절(iframe의 id 값을 넘김)
 * @author gggl.ko
 * @param frameId - ( frameId )
 * @return event
 */
function syncIframe(frameId,wOr) {
    var h;
    h = document.getElementById(frameId).contentWindow.document.body.scrollHeight;

    //document.getElementById(frameId).style.height = h + 10 + "px";
    document.getElementById(frameId).height = h + "px";
    if (typeof wOr != "undefined") {
        var widthInt;
        widthInt = document.getElementById(frameId).contentWindow.document.body.scrollWidth;
        document.getElementById(frameId).width = widthInt+"px";
    }
}


/**
 * Title : showBox
 * @Description : param 으로 넘어온 두개의 개체의 display 를 교체한다. 세개면 세개
 * @author gggl.ko / 2009-03-25
 * @param obj1, obj2, obj3
 * @return void
 */
function showBox (obj1, focusObj) {
    if(document.getElementById(obj1) != undefined) {

        // 단일일경우는 obj1 의 display만 변경함
        if(document.getElementById(obj1).style.display == "none") {
            document.getElementById(obj1).style.display = "block";
        } else {
            document.getElementById(obj1).style.display = "none";
        }

        if (document.getElementById(focusObj) != undefined) {
            document.getElementById(focusObj).focus();
        }
    }
}

/*
 * 여러 객체의 shwo 변경시
 */
function showBoxs (obj1, obj2, obj3, obj4) {

	// 단일일경우는 obj1 의 display만 변경함
	if (document.getElementById(obj2) == undefined) {
		if(document.getElementById(obj1).style.display == "none") {
			document.getElementById(obj1).style.display = "block";
		} else {
			document.getElementById(obj1).style.display = "none";
		}
	}

	// obj1 만 display
	try { document.getElementById(obj1).style.display = "block";	 } catch (e) {}
	try { document.getElementById(obj2).style.display = "none"; } catch (e) {}
	try { document.getElementById(obj3).style.display = "none"; } catch (e) {}
	try { document.getElementById(obj4).style.display = "none"; } catch (e) {}
}

// show hide
function showLy(id){
    var bx = document.getElementById(id);
    if (bx.style.display == 'block')
        {
            bx.style.display='none';
        }
    else
        {
            bx.style.display='block';
        }
}

// --------------------------------------------------------------------------------------------------------------------------------------

alpha = new Object
alpha = {
    clear  : function() {
                alpha.create().style.display = "none"
                //document.getElementsByTagName('HTML')[0].style.overflow = "hidden";
                //document.getElementsByTagName('HTML')[0].style.overflow = "visible";
                document.getElementsByTagName('HTML')[0].style.overflow = "auto";
                //document.getElementsByTagName('HTML')[0].style.overflow = "scroll";
        },
    apply  : function(op,co) {
                var Alpha = alpha.create()
                var alphacolor = co ? co : "#000000"
                var opacity = op ? op : "100"
                document.getElementsByTagName('HTML')[0].style.overflow = "hidden";
                //document.getElementsByTagName('HTML')[0].style.overflow = "scroll";
                with (Alpha.style) {
                    width	  = document.body.scrollWidth + "px";
                    height	 = document.documentElement.scrollHeight + "px";
                    background = alphacolor;
                    filter	 = "alpha(opacity=" + opacity + ")";
                    opacity	= 0.5;
                    display	= "block";
                }
        },
    create : function() {
                if (!document.getElementById('alpha')) {
                    var alphaDiv = document.createElement('div');
                    alphaDiv.setAttribute('id', 'alpha');
                    alphaDiv.onClick="alpha.clear()";
                    alphaDiv.setAttribute('onClick', 'alpha.clear()');
                    with(alphaDiv.style) {
                        display  = "none";
                        position = "absolute";
                        top	  = "0";
                        left	 = "0";
                        zindex   = "90";
                    }
                    document.body.appendChild(alphaDiv)
                    window.onresize = alpha.resize
                }
                return document.getElementById('alpha')
        },
    resize : function() {
                var Alpha = alpha.create();
                with (Alpha.style) {
                    width	  = document.body.scrollWidth + "px";
                    height	 = document.documentElement.scrollHeight + "px";
                }
        }
}



/**
 * iframe shadowbox 처리
 * @검증중
 */
document.write("<div style=\"position: absolute; left:0%; top:0%; z-index:999; width:100%; height:100%; text-align:center;padding-top:0px;display:none;\" id=\"shadowLayer\" onclick=\"alpha.clear(); document.getElementById('shadowLayer').style.display='none';\"></div>");
function shadowIframe(src) {

    alpha.apply();
    document.getElementById('shadowLayer').style.display="";

	var targetName = "ajlahtl2"; //랜덤하게, 안겹치게
    var html = '<iframe src="'+src+'" width="100%" height="100%" id="' + targetName + '" name="' + targetName + '" frameborder="0" marginwidth="0" marginheight="0" ' +
        'scrolling="auto"';
    html += '></iframe>';

    document.getElementById('shadowLayer').innerHTML = html;
    syncIframe(targetName);
}



/**
 * AJAX POPUP
 * @param : url -> 경로, wname -> 윈도우명, width -> 가로, height -> 세로, scrl -> 스크롤표시여부
 * window.openCenter
 *
 *    //alert(document.title = document.documentElement.clientWidth +'//'+document.documentElement.clientHeight +'//'+document.documentElement.scrollTop +'/////'+document.body.clientWidth +'//'+document.body.clientHeight +'//'+document.body.scrollTop +'//');
 *
 */
window.openFull = function(url) {
    window.openEx(url, "FULL");
    return false;
}

window.openEx = function(url, wname, wid, hei, ifrmpadding, hs) {

    if (arguments.length == 3) {
        ifrmpadding = hei;
        hei = wid;
        wid = wname;
    }

    var zIdx = 9998;
    var alpahVal = 20;
    //var alpahVal = -1;

    // 디버깅시에는 "" 운영때에는 none 로
    document.getElementById('shadowLayer').style.display="none";

    if(typeof ifrmpadding == "undefined") ifrmpadding = 0;
    var scrolling = "auto";

    // 높이가 퍼센트일경우 무조건 현재창의 클라이언트 높이보다 짧겠지?
    if (typeof wname !="undefined" && wname == "FULL") {
        wid = "80%";
        hei = "80%";
        ifrmpadding = "10%";
        hs = 70;
    }

    if (typeof hei != "undefined" && hei.isNaN == true && hei.indexOf('%') > 0) {
        ifrmpadding = 10;
        hs = 70;
        document.getElementById('shadowLayer').scrolling = "no";
    }
          
    var html = '<iframe scrolling="'+scrolling+'" id="' + wname + '" name="' + wname + '" frameborder="0"  marginwidth="0" marginheight="0" ' + 'scrolling="auto" align="middle" src="'+url+'"';
    
    if (typeof wid == "undefined") {
        html += ' onload="syncIframe(this.id,true)"';
    } else {
         html += 'height="'+hei+'px" '+'width="'+wid+'px"';
    }
    html += ' style="z-index:'+zIdx+';padding:'+ifrmpadding+'px;"></iframe>';

    document.getElementById('shadowLayer').innerHTML = html;
    document.getElementById('shadowLayer').style.zIndex = 9999;

    // ///////////////////////////////////////////////////////////////////////////////////

    var h=hei;
    var st = document.documentElement.scrollTop;
    var heightInt = document.documentElement.clientHeight;
    var height2 = Math.ceil(heightInt/2);
    var h2 = Math.ceil(h/2);
    var pt = height2-h2;

    // alert(document.getElementById(wname).contentWindow.document.body.scrollHeight);
    try {
        if(typeof hei == "undefined") {
            h = document.getElementById(wname).contentWindow.document.body.scrollHeight;
            h2 = Math.ceil(h/2);
            pt = height2-h2;
        }
    } catch (e) {
        h= 400;
        pt = height2-200;
    }
    // alert(pt+h +":"+ heightInt);
    if (pt+h > heightInt) {
        pt = 150;
    }
    
    if (typeof hs != "undefined") {
        pt = hs;
    }
    
    //alert(height+" : " + height2 + " : " + h + " : " + h2 + " : " + pt + " : "+ document.documentElement.scrollTop);
    if (pt < 200) {
        document.getElementById('shadowLayer').style.paddingTop=pt+st+"px";
    } else {
        document.getElementById('shadowLayer').style.paddingTop=st+200+"px";
    }    
    document.getElementById('shadowLayer').style.display="";
    alpha.apply(alpahVal);
    
    return false;
}

window.closeEx = function() {
    alpha.clear();
    document.getElementById('shadowLayer').style.display="none";
}

window.openEx.destory = function() {
    window.closeEx();
}


// ////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * @Title : selectbox 직접입력등의 편의를 위한 함수
 * @Description :
 * @Create : 2010-05-25 / gggl.ko
 * @param : trueFalse 는 객체를 넘길수도 있다. 객체로 넘어올때는 빈값의 검증임
 *
 */
function showBoxEx(obj1E, trueFalse, val) {
    
    var obj1 = obj1E;
    if (document.getElementById(obj1E) != "undefined") {
        obj1 = document.getElementById(obj1E);
    }

    var objFalg = false;

    if (typeof trueFalse == "object") {
        var obj = trueFalse;
        trueFalse = obj.value == "";
        objFalg = true;
    }

    if (trueFalse == true) {
        obj1.style.display="";
        obj1.value = "";
        obj1.focus();
    } else {
        obj1.style.display="none";

        if (objFalg == true && val != undefined) {

            if(val == "{t}") {
                obj1.value = obj[obj.selectedIndex].text;
            } else if(val == "{v}") {
                obj1.value = obj[obj.selectedIndex].value;
            } else {
                obj1.value = val;
            }
        }
    }
}

//<![CDATA[
/* hasClass */
function hasClass(element,value) {
    var re = new RegExp("(^|\\s)" + value + "(\\s|$)");
    return re.test(element.className); // 정규식.test('테스트할문자열') 있으면 true 반환
}

/* getElementsByClass('노드/생략[윈도우]', '태그/생략[*]', '클래스명'); */
function getElementsByClass(node, tagName, srchClass) {
    node = node || window.document;
    tagName = tagName ? tagName.toUpperCase() : "*";
    var eles = node.getElementsByTagName(tagName);
	
	if(!srchClass) return eles;

    var arr = new Array;
    for (var i=0; i<eles.length; i++) {
        if (hasClass(eles[i],srchClass)) arr.push(eles[i]);
    }
    return arr;
}

function faqList(obj){
	var obj = document.getElementById(obj);
	var menuLink = getElementsByClass(obj, "A", "tab"); // A태그 추출
	
	for(i=0; i<menuLink.length; i++){
		thismenu = menuLink[i];
		thismenu.container = obj;
		thismenu.targetName = document.getElementById(menuLink[i].href.split("#")[1]);
		thismenu.targetName.style.display = "none";
		thismenu.onclick = function(){
			currentMenu = this.container.current;
			if(currentMenu){
				if(this == currentMenu && currentMenu.targetName.style.display == "none"){
					currentMenu.targetName.style.display = "";
				} else {
					currentMenu.targetName.style.display = "none";
				}
			}
			
			if(this != currentMenu) this.targetName.style.display = "";

			this.container.current = this;
			return false;
		}
	}
}
//]]>

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 '';
}

function openPopup(url,name){
	window.open(url,name,'width=560, height=570');
}
