var nowdrag = false;

function set_reposition(el,ev)
{

    if(nowdrag)
    {
	    //alert(nowdrag);
	    try {
			var obj = document.getElementById('link_popup_layer');

			//var evt = window.event || ev;
			//alert(evt.type);

			if(win_ie_ver)
			{
				var x = window.event.x;
				var y = window.event.y;
			}
			else
			{
				var x = el.pageX;
				var y = el.pageY;
			}

	        //alert('x:'+x+' y:'+y);		

			obj.style.right = '';
			obj.style.left = (x+95)+'px';
			obj.style.top = (y+55)+'px';

		} catch(e) {
		    ;
		}	

    }
}

function set_drag(mo)
{
	if(nowdrag)
    {
		set_reposition('');

	}
    nowdrag = mo;
}

// IE 레이어에서 셀렉트 박스 보이는 문제 
function selectbox_hidden(layer_id) 
{ 
	/*
	eval() 은 fireforx 에서는  인식하지않음..
	var ly=eval(layer_id) -> document.getElementById(layer_id); 로 변경 했음
	*/
	var		ly=document.getElementById(layer_id);

    //레이어 좌표 
    var ly_left = ly.offsetLeft; 
    var ly_top = ly.offsetTop; 
    var ly_right = ly.offsetLeft + ly.offsetWidth; 
    var ly_bottom = ly.offsetTop + ly.offsetHeight; 

    // 셀렉트박스의 좌표 
    var el; 
    for (i=0; i<document.forms.length; i++) 
    { 
        for (k=0; k<document.forms[i].length; k++) 
		{ 
            el = document.forms[i].elements[k]; 
            if (el.type == "select-one") 
		    { 
                var el_left = el_top = 0; 
                var obj = el; 
                if (obj.offsetParent)
				{ 
                    while (obj.offsetParent) 
				    { 
                        el_left += obj.offsetLeft; 
                        el_top += obj.offsetTop; 
                        obj = obj.offsetParent; 
                    } 
                } 
                el_left += el.clientLeft; 
                el_top += el.clientTop; 
                el_right = el_left + el.clientWidth; 
                el_bottom = el_top + el.clientHeight; 

               // 좌표를 따져 레이어가 셀렉트 박스를 침범했으면 셀렉트 박스를 hidden 시킴
               if ( (el_left >= ly_left && el_top >= ly_top && el_left <= ly_right && el_top <= ly_bottom) || (el_right >= ly_left && el_right <= ly_right && el_top >= ly_top && el_top <= ly_bottom) || (el_left >= ly_left && el_bottom >= ly_top && el_right <= ly_right && el_bottom <= ly_bottom) || (el_left >= ly_left && el_left <= ly_right && el_bottom >= ly_top && el_bottom <= ly_bottom) ) 
               el.style.visibility = 'hidden'; 
           } 
       } 
    } 
} 


// 감추어진 셀렉트 박스를 모두 보이게 함 
function selectbox_visible() 
{ 
    for (i=0; i<document.forms.length; i++) 
    { 
        for (k=0; k<document.forms[i].length; k++) 
        { 
            el = document.forms[i].elements[k]; 
            if (el.type == "select-one" && el.style.visibility == 'hidden') el.style.visibility = 'visible'; 
        } 
    }
} 

function do_locate(){
	var o = document.getElementById('div_main_game_clip'); 
	var t = document.body.clientWidth<document.documentElement.clientWidth?document.documentElement:document.body;
	var sl, st;
	var cx, cy;
	if (self.innerHeight) {
		cw = self.innerWidth - 16;
		ch = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		cw = document.documentElement.clientWidth;
		ch = document.documentElement.clientHeight;
	} else if (document.body) {
		cw = document.body.clientWidth;
		ch = document.body.clientHeight;
	}
	if (self.pageYOffset) {
		sl = self.pageXOffset;
		st = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		sl = document.documentElement.scrollLeft;
		st = document.documentElement.scrollTop;
	} else if (document.body) {
		sl = document.body.scrollLeft;
		st = document.body.scrollTop;
	}
	var dx = cw + sl;
	var dy = ch + st;
	var x=dx-config.right-config.width;
	var y=dy-config.bottom-config.height;
	o.style.left=x+"px";
	o.style.top=y+"px";
	//window.status = var_main_game_clip;
	var_main_game_clip = var_main_game_clip + 1;
}


function show_popup_layer(gourl, qstring, width, height) { 
    var obj = document.getElementById("link_popup_layer");

	var config = Array();
	config.right = 0;
	config.bottom = 0;
	config.width = width;
	config.height = height;
	var t = document.body.clientWidth<document.documentElement.clientWidth?document.documentElement:document.body;
	var sl, st;
	var cx, cy;

	if (window.innerHeight) {
		cw = window.innerWidth - 16;
		ch = window.innerHeight;
	} else 
	if (document.documentElement && document.documentElement.clientHeight) {
		cw = document.documentElement.clientWidth;
		ch = document.documentElement.clientHeight;
	} else if (document.body) {
		cw = document.body.clientWidth;
		ch = document.body.clientHeight;
	}

	if (self.pageYOffset){
		sl = self.pageXOffset;
		st = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		sl = document.documentElement.scrollLeft;
		st = document.documentElement.scrollTop;
	} else if (document.body) {
		sl = document.body.scrollLeft;
		st = document.body.scrollTop;
	}

	obj.innerHTML = "";
    obj.style.width  = width;
    obj.style.height = height;         
    obj.style.left = ((cw - width)/2 + sl - 100) + 'px';
    obj.style.top  = ((ch - height)/2 + st - 150) + 'px';
    show_cover();
    obj.style.display = '';
    get_request_text(gourl, qstring, 'link_popup_layer');
	return;
	//return false;
}

//임시적으로 익스 6.0 확인버튼이 안보여서 회원가입폼에서 우편 번호 찾기 는 이함수를 사용한다. 
function show_zippopup_layer(gourl, qstring, width, height) { 
    var obj = document.getElementById("link_popup_layer");
	var config = Array();
	config.right = 0;
	config.bottom = 0;
	config.width = width;
	config.height = height;
	var t = document.body.clientWidth<document.documentElement.clientWidth?document.documentElement:document.body;
	var sl, st;
	var cx, cy;
	if (self.innerHeight) {
		cw = self.innerWidth - 16;
		ch = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		cw = document.documentElement.clientWidth;
		ch = document.documentElement.clientHeight;
	} else if (document.body) {
		cw = document.body.clientWidth;
		ch = document.body.clientHeight;
	}
	if(self.pageYOffset) 
	{
		sl = self.pageXOffset;
		st = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		sl = document.documentElement.scrollLeft;
		st = document.documentElement.scrollTop;
	} else if (document.body) {
		sl = document.body.scrollLeft;
		st = document.body.scrollTop;
	}
	var dx = cw + sl;
	var dy = ch + st;

	if(win_ie_ver == 0)
	{
		//alert(qstring);
		if(qstring == "c=pop_zip&m=zip_form")
		{
			qstring = "c=pop_zip&m=ff_zip_form";
			open_window("zip_code", "/index.php?"+qstring, 100, 150, width, height, 0, 0, 0, 0, 0);
			return;		
		}		
	}
	obj.innerHTML = "";

    obj.style.width  = width;
    obj.style.height = height;         
    obj.style.left = (dx - width)/2+251;
    obj.style.top  = (dy - height)/2+150;
    show_cover();
    obj.style.display = '';

    get_request_text(gourl, qstring, 'link_popup_layer');
    return;
}
function show_popup_write(gourl, qstring, width, height) { 
    var obj = document.getElementById("link_popup_layer");
	
	var config = Array();
	config.right = 0;
	config.bottom = 0;
	config.width = width;
	config.height = height;
	var t = document.body.clientWidth<document.documentElement.clientWidth?document.documentElement:document.body;
	var sl, st;
	var cx, cy;
    if (window.screen) {
        cw = window.screen.width;
        ch = window.screen.height;
    }
	else if (self.innerHeight) {
		cw = self.innerWidth - 16;
		ch = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		cw = document.documentElement.clientWidth;
		ch = document.documentElement.clientHeight;
	} else if (document.body) {
		cw = document.body.clientWidth;
		ch = document.body.clientHeight;
	}
	if (self.pageYOffset) {
		sl = self.pageXOffset;
		st = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		sl = document.documentElement.scrollLeft;
		st = document.documentElement.scrollTop;
	} else if (document.body) {
		sl = document.body.scrollLeft;
		st = document.body.scrollTop;
	}

	obj.innerHTML    = "";
    obj.style.width  = width;
    obj.style.height = height;         
    obj.style.left = ((cw - width)/2 + sl) + 'px';
    obj.style.top  = ((ch - height)/2 + st) + 'px';

    if(((ch - height)/2 + st) > 600)
        obj.style.top = '150px'; 
    
    show_cover();
    obj.style.display = '';
	selectbox_hidden("link_screen_cover");
    get_request_text(gourl, qstring, 'link_popup_layer');
    return;
}

function show_popup_write_FF(gourl, qstring, width, height)
{ 
    var obj = document.getElementById("link_popup_layer_FF");
	var now_winwidth = document.body.clientWidth;
    var top_start   = 210;
    var left_start  = 780;	
	var left_margin = 0;

    if (now_winwidth > 780) { left_margin = ((now_winwidth - 780)/2) + 150; }  

	//alert(left_margin);
	//alert((now_winwidth - 780));

	obj.innerHTML    = "";
    obj.style.width  = width;
    obj.style.height = height;         
    obj.style.left   = left_margin;
    obj.style.top    = top_start;

	//alert(obj.style.left);
    
    show_cover();
    obj.style.display = '';

    //selectbox_hidden("link_screen_cover");

    get_request_text(gourl, qstring, 'link_popup_layer_FF');

    return;
}

function show_board_reply(theform,tmode,uid)
{ 
	var class_change,method_change,view_layer,gourl,qstring,gnet,guid,gd_uid,gs_uid,gr_uid;

	gnet   = theform.gnet.value;
	guid   = theform.guid.value;
	gd_uid = theform.gd_uid.value;
	gs_uid = theform.gs_uid.value;
	gr_uid = theform.gr_uid.value;

	theform.uid.value = uid;

	class_change  = "groups_board";
	method_change = "board_reply_form";
	view_layer    = "_content_reply_form"+uid;

	gourl   = "/index.php";
	qstring = "c="+class_change+"&m="+method_change+"&gnet="+gnet+"&guid="+guid+"&gd_uid="+gd_uid+"&gs_uid="+gs_uid+"&uid="+uid;

	get_request_text(gourl, qstring, view_layer);
}

function show_layer_text(gourl, qstring, mlayer)
{ 
	//alert(mlayer);
    var obj = document.getElementById(mlayer);

	if(obj.style.display == '') 
	{
		obj.style.display = "none"; 
		return;
	}

	obj.style.display = '';
	get_request_text(gourl, qstring, mlayer);
    return;
}

function show_popup_layer_position(gourl, qstring, width, height, top, left)
{ 
    var obj = document.getElementById("link_popup_layer");

	obj.innerHTML = "";

    obj.style.width  = width;
    obj.style.height = height;         
    obj.style.left = left;
    obj.style.top  = top;
    
    show_cover();
    obj.style.display = '';

    //trace(gourl+'='+qstring+'=link_popup_layer');
    //selectbox_hidden("link_screen_cover");

	//selectbox_hidden("link_popup_layer");
	//selectbox_hidden("pop_message");

    get_request_text(gourl, qstring, 'link_popup_layer');
    return;
}


function show_popup_layer_FF(gourl, qstring, width, height)
{ 
    var obj = document.getElementById("link_popup_layer");

	//alert(win_ie_ver);

	if(win_ie_ver == 0)
	{
		//alert(qstring);

		if(qstring == "c=pop_zip&m=zip_form")
		{
			qstring = "c=pop_zip&m=ff_zip_form";
			open_window("zip_code", "/index.php?"+qstring, 100, 150, width, height, 0, 0, 0, 0, 0);
		
		}
		return;
	}

	obj.innerHTML = "";

    obj.style.width  = width;
    obj.style.height = height;         
    obj.style.left = (screen.width)?(screen.width - width)/2:150;
    obj.style.top  = document.body.scrollTop + 210;
    
    show_cover();
    obj.style.display = '';

    //trace(gourl+'='+qstring+'=link_popup_layer');
    //selectbox_hidden("link_screen_cover");

	//selectbox_hidden("link_popup_layer");
	//selectbox_hidden("pop_message");

    get_request_text(gourl, qstring, 'link_popup_layer');
    return;
}

function hide_popup_layer()
{    
    var obj = document.getElementById("link_popup_layer");
    obj.style.display = "none";
}

function hide_popup_layer_FF()
{    
    var obj = document.getElementById("link_popup_layer_FF");
    obj.style.display = "none";
}

function show_cover() {    
    var obj = document.getElementById("link_screen_cover");
	var height = 0;
	if (window.innterWidth) height = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight) height = document.documentElement.clientHeight;
	if (document.body.scrollHeight) {
		if (document.body.scrollHeight > height) height = document.body.scrollHeight;
	} else if (document.documentElement && document.documentElement.scrollHeight) {
		if (document.documentElement.scrollHeight > height) height = document.documentElement.scrollHeight;
	}
	obj.style.height = height + 'px';
	obj.style.display = "";
}
  
function hide_cover()
{  
    var obj = document.getElementById("link_screen_cover");
    obj.style.display = "none";    
}

function hide_pop_message()
{  
    var obj = document.getElementById("pop_message");
    obj.style.display = "none";    
}

function cover_click()
{ 
    var obj = document.getElementById("submit_waiting");
    //var obj2 = document.getElementById("link_popup_layer_FF");
    selectbox_visible();
	hide_pop_message();
    hide_popup_layer();

	if(obj.style.display == "none")
	{
		hide_cover(); 
	}
	//if(obj2 != "null")
	//{
	//	hide_popup_layer_FF(); 
	//}
	//return false;
	return;
}


function show_submit_waiting()
{ 
    var obj = document.getElementById("submit_waiting");
    
    show_cover();
    obj.style.display = '';
    //selectbox_hidden("link_screen_cover");
}

function hide_submit_waiting()
{ 
    var obj = document.getElementById("submit_waiting");
    obj.style.display = "none";  
    hide_cover();
}



function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity; 
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")"; 
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100; 
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100; 
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
} 

function document_write(s){
        document.write(document.getElementById(s).value);
}

var sUserAgent = navigator.userAgent;
var isOpera = sUserAgent.indexOf("Opera") > -1;
var isIE = sUserAgent.indexOf("compatible") > -1
           && sUserAgent.indexOf("MSIE") > -1
           && !isOpera;

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return document.getElementById(movieName);
    }
    else {
        return document[movieName];
    }
}

function copyUrl(url) {
	try {
		//alert('주소가 복사되었습니다.');
		//alert(thisMovie('clipboardPoter'));
		thisMovie('clipboardPoter').setClipBoard(url);
	} catch(e) {
		if(isIE) {
			window.clipboardData.setData('Text',url);
			window.alert("주소가 복사되었습니다.");
		}
	}
}

function onClipBorad(result) {
	alert(result ? "주소가 복사되었습니다." : "주소 복사를 실패했습니다.");
}

function set_bookmark(title,url) { 
	if (window.sidebar) // firefox 
		window.sidebar.addPanel(title, url, ""); 
	else if(window.opera && window.print){ // opera 
		var elem = document.createElement('a'); 
		elem.setAttribute('href',url); 
		elem.setAttribute('title',title); 
		elem.setAttribute('rel','sidebar'); 
		elem.click(); 
	} else if(document.all) // ie
		window.external.AddFavorite(url, title); 
} 

