// JavaScript Document

var globalAll = false;
function loadFun(){
	var id = getCookie('subMenuID');
	if (id == '')
	{
		id = 1;
	}
	var gnbSub = 'gnb_sub_'+id;
	KR('nQuick').style.height = KR('wrap_body').offsetHeight;
	KR('globalAll').style.height = KR('wrap_body').offsetHeight;

	if(KR(gnbSub))
		KR(gnbSub).over();

	if(KR('globalAllViewBtn')){
		KR('globalAllViewBtn').onclick = function(){
			var cont = KR('globalAllCont');
			cont.style.display = (cont.style.display == "none") ? "" : "none";
			return false;
		}
	}
	if(KR('keyword'))
		setInputBg('keyword');
	if(KR('topSpotRow_clinic'))
		setInputBg('topSpotRow_clinic');
}
function setInputBg(id){
	KR(id).onfocus = function(){
		this.className = this.className +  " on";
		this.onblur = function(){
			if(this.value == "")
				this.className = this.className.replace(" on" , "" );
		}
	}
}



/* main contents scrpt  */
function mainNotice(tabID,contClass,listClass){
	var tabLIst = KR(tabID).getElementsByClassName(contClass,'li');
	var conts	= KR(tabID).getElementsByClassName(listClass,'dl');
	var btnMore = KR(tabID).getElementsByClassName("btnMore",'a')

	for (i=0; i<tabLIst.length; i++)
	{	
		var btn = tabLIst[i].first()
		btn.count = i;
		btn.onmouseover = btn.onfocus = function (){
			var tabIMG  = this.first('img');
			for (j=0; j<tabLIst.length; j++ )
			{
				tabLIst[j].first('img').src = tabLIst[j].first('img').src.replace('_on.gif','_off.gif')
				conts[j].style.display = 'none';
				btnMore[j].style.display = 'none';
			}
			//tabA[this.count].style.display = ''
			tabIMG.src = tabIMG.src.replace('_off.gif','_on.gif')
			conts[this.count].style.display = '';
			btnMore[this.count].style.display = '';
			return false;
		}
			btnMore[i].style.display = 'none';
	}
			btnMore[0].style.display = '';
}


function rollingView(btn,contents){
	var btns = KR(btn).child();
	var cont = KR(contents).child();
	btns.num = 1000*btns.length;
	var clear = function(){
		for (i=0;i<cont.length ; i++ )
		{
			cont[i].hide();
		}
	}
	btns[0].onclick = function(){
		clear();
		btns.num++;
		cont[btns.num%cont.length].show();
		return false;
	}
	btns[1].onclick = function(){
		clear();
		btns.num--;
		cont[btns.num%cont.length].show();
		return false;
	}
}

function flashLoad(width,height,id,swf,flashvars,bgcolor){
    var strFlashTag = new String();

	var id = getCookie('subMenuID');
	if (id == '')	{
		id = 0;
	}else{
		id = id-1;
	}

	flashvars = "mNum="+id+"&sNum=";
    
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        strFlashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
        strFlashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=version=8,0,0,0" ';
        strFlashTag += 'id="' + id + '" width="' + width + '" height="' + height + '">';
        strFlashTag += '<param name="movie" value="' + swf + '"/>';
        
        if(flashvars != null) {strFlashTag += '<param name="flashvars" value="' + flashvars + '"/>'};
        strFlashTag += '<param name="quality" value="best"/>';
        strFlashTag += '<param name="bgcolor" value="' + bgcolor + '"/>';
        strFlashTag += '<param name="menu" value="false"/>';
        strFlashTag += '<param name="salign" value="LT"/>';
        strFlashTag += '<param name="scale" value="noscale"/>';
        strFlashTag += '<param name="wmode" value="transparent"/>';
        strFlashTag += '<param name="allowScriptAccess" value="sameDomain"/>';
        strFlashTag += '</object>';
    }
    else
    {
        strFlashTag += '<embed src="' + swf + '" ';
        strFlashTag += 'quality="best" ';
        strFlashTag += 'bgcolor="' + bgcolor + '" ';
        strFlashTag += 'width="' + width + '" ';
        strFlashTag += 'height="' + height + '" ';
        strFlashTag += 'menu="false" ';
        strFlashTag += 'scale="noscale" ';
         strFlashTag += 'id="' + id + '" ';
        strFlashTag += 'salign="LT" ';
       //  strFlashTag += 'wmode="transparent" ';
        strFlashTag += 'allowScriptAccess="sameDomain" ';
        if(flashvars != null) {strFlashTag += 'flashvars="' + flashvars + '" '};
        strFlashTag += 'type="application/x-shockwave-flash" ';
        strFlashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
        strFlashTag += '</embed>';
    }

 document.write(strFlashTag);
}

function FlashObject(swf, width, height, bgcolor, id, flashvars)
{
    var strFlashTag = new String();
    
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        strFlashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
        strFlashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=version=8,0,0,0" ';
        strFlashTag += 'id="' + id + '" width="' + width + '" height="' + height + '">';
        strFlashTag += '<param name="movie" value="' + swf + '"/>';
        
        if(flashvars != null) {strFlashTag += '<param name="flashvars" value="' + flashvars + '"/>'};
        strFlashTag += '<param name="quality" value="best"/>';
        strFlashTag += '<param name="bgcolor" value="' + bgcolor + '"/>';
        strFlashTag += '<param name="menu" value="false"/>';
        strFlashTag += '<param name="salign" value="LT"/>';
        strFlashTag += '<param name="scale" value="noscale"/>';
        strFlashTag += '<param name="wmode" value="transparent"/>';
        strFlashTag += '<param name="allowScriptAccess" value="sameDomain"/>';
        strFlashTag += '</object>';
    }
    else
    {
        strFlashTag += '<embed src="' + swf + '" ';
        strFlashTag += 'quality="best" ';
        strFlashTag += 'bgcolor="' + bgcolor + '" ';
        strFlashTag += 'width="' + width + '" ';
        strFlashTag += 'height="' + height + '" ';
        strFlashTag += 'menu="false" ';
        strFlashTag += 'scale="noscale" ';
         strFlashTag += 'id="' + id + '" ';
        strFlashTag += 'salign="LT" ';
       //  strFlashTag += 'wmode="transparent" ';
        strFlashTag += 'allowScriptAccess="sameDomain" ';
        if(flashvars != null) {strFlashTag += 'flashvars="' + flashvars + '" '};
        strFlashTag += 'type="application/x-shockwave-flash" ';
        strFlashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
        strFlashTag += '</embed>';
    }

 document.write(strFlashTag);
}


function roundIcont_tab(tab,cont){
	var tabImg = KR(tab).child();
	var contImg = KR(cont).child();

	for (i=0 ; i<tabImg.length ; i++ )
	{
		tabImg[i].num = i;
		tabImg[i].onmouseover = function(){
			for (j=0 ; j<tabImg.length ; j++ )
			{
				var img = tabImg[j].first('img');
				img.src = img.src.replace('_on','_off');
				contImg[j].hide();			
			}
			var img2 = this.first('img');
			img2.src = img2.src.replace('_off','_on');
			contImg[this.num].show();		
		}
	}
}

function roundIcont_tab2(tab,cont,more){
	var tabImg = KR(tab).child();
	var contImg = KR(cont).child();
	var moreImg = KR(more).child();
	for (i=0 ; i<tabImg.length ; i++ )
	{
		tabImg[i].num = i;
		tabImg[i].onmouseover = function(){
			for (j=0 ; j<tabImg.length ; j++ )
			{
				var img = tabImg[j].first('img');
				img.src = img.src.replace('_on','_off');
				contImg[j].hide();				
				moreImg[j].hide();
			}
			var img2 = this.first('img');
			img2.src = img2.src.replace('_off','_on');
			contImg[this.num].show();			
			moreImg[this.num].show();
		}
	}
}


function familySite_btn(){
	var btn = KR('familySite_btn')
	var cont = KR('familySite_list')
	var contA = KR('familySite_list').getElements('a')
	document.onclick = function(){
		if(cont.style.display == "none") return false;
			cont.style.display =  "none";
	}
	btn.onclick = function(nsEvent){
		var evt =  nsEvent ? nsEvent : window.event;
		cont.style.display = (cont.style.display == "none") ? "" : "none";
		stopEvent(evt);
		return  false;
	}

   function stopEvent(evnt){
    if(evnt.stopPropagation){
     evnt.stopPropagation();
    } else {
     evnt.cancelBubble = true;
    }
   }
}

function familySite_btns(){
	var link = document.getElementById('familySite_list');
	link.style.display = (link.style.display == "none") ? "block" : "none";
}

function goSearch(){
	frm = document.myform;
	if (frm.searchWord.value == ""){
		alert("°Ë»ö´Ü¾î¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä!");
		frm.searchWord.focus();
		return false;
	}
	return true;
}

function allSearch(){
	frm = document.subSearch;
	if (frm.searchWord.value == ""){
		alert("°Ë»ö´Ü¾î¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä!");
		frm.searchWord.focus();
		return false;
	}
	return true;
}
/*
function allSearch(){
	if(document.subSearch.searchWord.value != ""){
		location.href="/utility/search.asp?searchword="+ document.subSearch.searchWord.value;
	}else{
		alert("´Ü¾î¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä")
		document.subSearch.searchWord.focus();
	}
}*/

function sendkey()
{
	if(window.event.keyCode == 13)
	{
		allSearch();
	}
}

function setCookie( name, value, expirehours ) 
{ 
    var todayDate = new Date(); 
    todayDate.setHours( todayDate.getHours() + expirehours ); 
    document.cookie = name + '=' + escape( value ) + '; path=/; expires=' + todayDate.toGMTString() + ';' 
} 

function getCookie( name ){
	var nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length )
	{
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
				endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 )
			break;
	}
	return "";
}



function topMenuLink(ln, id)
{
	var mydate = new Date();
	mydate.setTime(mydate.getTime() + -86400000);
	setCookie('subMenuID', id, 12 );
	location.href = ln;
}

function gnbOnOff(id)
{
	var id = getCookie('subMenuID');
	if(id == '') id = 1;
	var aimg = new Array();
	aimg = $('gnb').getElementsByTagName('img');
	for(i=0,n=1; i < aimg.length; i++,n++)
	{
		var src = aimg[i].src;
		if(n == id)
		{
			var tt = src.replace("_off", "_on");
			disp = 'block';
		}
		else
		{
			var tt = src.replace("_on", "_off");
			disp = 'none';
		}
		aimg[i].src = tt;
	}
	if(id < 4){
		var ele = 'gnb_sub_'+id;
		$(ele).style.display = 'block'
	}
}




//Layer POPUP
function getCookieMain(name)
{
	var nameOfCookie = name + "=";
	var x = 0;
	while(x <= document.cookie.length)
	{
		var y = (x + nameOfCookie.length);
		if(document.cookie.substring(x,y) == nameOfCookie)
		{
			if((endOfCookie = document.cookie.indexOf(";",y)) == -1)
			endOfCookie = document.cookie.length;
			return unescape(document.cookie.substring(y,endOfCookie));
		}
		x = document.cookie.indexOf(" ",x) + 1;
		if(x == 0)
		break;
	}
	return "";
}
function setCookieMain(name,value,expiredays){
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate() + expiredays);
	document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}


function closeWinMain(){
	obj = eval('popup_divMain.style');
	obj.visibility = 'hidden';
}
function closeWinMain2(){
	obj = eval('popup_divMain2.style');
	obj.visibility = 'hidden';
}
function closeWinMain3(){
	obj = eval('popup_divMain3.style');
	obj.visibility = 'hidden';
}
function closeWinMain4(){
	obj = eval('popup_divMain4.style');
	obj.visibility = 'hidden';
	document.embeds[0].stop();
}
function popup_moveMain() {
	card=eval("popup_divMain.style");
	c_top = window.event.clientY - document.hdn_frmMain.oy.value - 20;
	c_left = window.event.clientX - document.hdn_frmMain.ox.value - 2;
	if (c_top<1){
		c_top=1;
	}
	if (c_top>500){
		c_top=500;
	}
	if (c_left<1){
		c_left=1;
	}
	if (c_left>720){
		c_left=720;
	}
	if ( (c_left > 240 && c_left < 260) && (c_top > 240 && c_top < 260) ) {
		c_left = 250;
		c_top = 250;
	}
	card.top = c_top;
	card.left = c_left;
}
function xy_saveMain() {
	//alert(window.event.offsetX);
	// i ´Â ÃÑ·¹ÀÌ¾î °¹¼ö ¸¸Å­
	document.hdn_frmMain.ox.value = window.event.offsetX;
	document.hdn_frmMain.oy.value = window.event.offsetY;
}
function dis_popupMain(tmp) {
	//alert(tmp);
	setCookieMain("no_popupMain",tmp,1);
	closeWinMain();
}
function dis_popupMain2(tmp) {
	//alert(tmp);
	setCookieMain("no_popupMain2",tmp,1);
	closeWinMain2();
}
function dis_popupMain3(tmp) {
	//alert(tmp);
	setCookieMain("no_popupMain3",tmp,1);
	closeWinMain3();
}
function dis_popupMain4(tmp) {
	//alert(tmp);
	setCookieMain("no_popupMain4",tmp,1);
	closeWinMain4();
}

//¸¶¿ì½ºmove½Ã ·¹ÀÌ¾î move
isIE  = document.all;
isNN  = !document.all && document.getElementById;
isN4  = document.layers;

var max_zindex = 30;
function drag(mode,e,obj){
        if ( mode == 'start' ){
                obj.offsetx = isIE ? event.clientX : e.clientX;
                obj.offsety = isIE ? event.clientY : e.clientY;
                obj.nowX    = parseInt(obj.style.left);
                obj.nowY    = parseInt(obj.style.top);
                obj.dragable = '1';
                var new_zindex = max_zindex + 1;
                obj.style.zIndex = new_zindex;
                max_zindex = new_zindex;
        } else if ( mode == 'move' ){
                if (obj.dragable == '1'){
                        var x = isIE ? (obj.nowX + event.clientX - obj.offsetx) : (obj.nowX + e.clientX - obj.offsetx);
                        var y = isIE ? (obj.nowY + event.clientY - obj.offsety) : (obj.nowY + e.clientY - obj.offsety);
                        var max_winw = document.body.clientWidth 
                        var max_winh = document.body.clientHeight 
                        if ( x >= 0 && x <=max_winw) obj.style.left = x;
                        if ( y >= 0 && y <=max_winh) obj.style.top  = y;
                }
        } else if ( mode == 'stop' ){
                obj.dragable='0'
        }
}
