//document.domain = "uway.com";
document.domain = "knou.ac.kr";
//document.title="한국방송통신대학교";	// 타이틀


var IE = (navigator.appName.indexOf("Microsoft")>-1);
var IE6 = (navigator.appName.indexOf("Microsoft")>-1)&&(navigator.userAgent.indexOf("MSIE 6")>-1);
var IE7 = (navigator.appName.indexOf("Microsoft")>-1)&&(navigator.userAgent.indexOf("MSIE 7")>-1);

var depth1="",depth2="",depth3="";	// 각 페이지에 맞게 탑메뉴,좌측메뉴가 자동으로 활성화되게 하기위한 메뉴의 depth 의 값저장
var topMenuCount = 4;	// 탑메뉴갯수 (대학소개, 대학/대학원, 입학안내, 대학생활) 총 4개
var global_topFocusId = "";	// 탑메뉴에서 현재 포커스가 된 객체 ID 임시저장변수
var global_leftFocusId = "";	// 좌측메뉴에서 현재 포커스가 된 객체 ID 임시저장변수
var tmpDepth1 = "";	// 좌측메뉴에서 현재페이지의 depth번호와 메뉴번호를 비고해서 포커스가 있다면 클래스명 끝에 _on 를 붙임

// 플리커현상((flicker prevent) 제거소스
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}


// 모든 페이지에서 현재 페이지의 카테고리번호를 설정 //
function mNavi(hNum,mNum,sNum) {
	if(hNum) {
		depth1 = hNum;
		tmpDepth1 = hNum.toString();
	}
	if(mNum) {
		depth2 = mNum;
		tmpDepth1 += "-" + mNum.toString();

	}
	if(sNum) {
		depth3 = sNum;
		tmpDepth1 += "-" + sNum.toString();
	}
}

function visual(){
	if(depth1 != ""){
		document.write('<div id="visual">');
		flashWrite('/comimg/visual'+depth1+'.swf',700,138,'','#ffffff','transparent')
		document.write('</div>');
		
	}
}


// ----------------------------------------------------
// 로그인 체크
// ----------------------------------------------------
function homepageLoginCheck() {

    var result = false;
	var name = getCookie("knoucommon1");

	if(name != null && name != "") {
        result = true;
	}

	return result;
}

function getCookie(name)
{
	var blank='';
	var cname = name + '=';
	var dc = (document.cookie+';');
	if(dc.length > 0) {
		begin = dc.lastIndexOf(cname);
		if(begin==-1)
			begin=dc.lastIndexOf(name);
		if(dc.charAt(begin+name.length)==';')
			return '';

		if(begin != -1) {
			begin += cname.length;
			end = dc.indexOf(';', begin);
			if(end == -1)
				end = dc.length;
			if(begin==end)
				return blank;
			return unescape(dc.substring(begin, end));
		}
	}
	return null;
}

function ClearCookie(){
	//window.open('http://ep.knou.ac.kr/EP/web/login/login_chk.html?logout=Y&unload=Y','','left=3000,top=3000');
	var now = new Date();
	now.setDate(now.getDate() - 1);
	document.cookie = "knouCookie=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();
	document.cookie = "knouName=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();
	document.cookie = "knouMail=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();

	document.cookie = "knoucommon1=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();
	document.cookie = "knoucommon2=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();
	document.cookie = "knoustudent=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();
	document.cookie = "knouemployee=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();
	document.cookie = "knouemployeedn=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();

	document.cookie = "knouIDGB=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();
	document.cookie = "knouIDDGB=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();
	document.cookie = "knouUid=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();
	document.cookie = "Knou_NewWorld_Info=; path=/; domain=knou.ac.kr; expires=" + now.toGMTString();

	location.reload();
	return;
}

/***************************************
* top button
***************************************/
ScroolTop = function(className, id) {
  this.IE = document.all ? 1 : 0;
  this.NN = document.layer ? 1 : 0;
  this.N6 = document.getElementById ? 1 : 0;
  if(this.IE) this.layer = document.all(id);
  else if(this.NN) this.layer = document.layer[id];
  else if(this.N6) this.layer = document.getElementById(id);
  else return;
  this.className = className;
  this.top = this.oldY = parseInt(this.layer.style.top,10);
  setInterval(this.className + ".move()", 10);
}
ScroolTop.prototype.move = function() {
//    var diffY = (this.IE) ? document.body.scrollTop+this.top : self.pageYOffset+this.top; // 표준에는 document.documentElement.scrollTop
    var diffY = (this.IE) ? document.documentElement.scrollTop+this.top : self.pageYOffset+this.top; // 표준에는 document.documentElement.scrollTop
    if(diffY != this.oldY) {
        var percentY = .1 * (diffY - this.oldY);
        percentY = (percentY > 0) ? Math.ceil(percentY) : Math.floor(percentY);

        this.oldY += percentY;
        this.layer.style.top = this.oldY + "px";
    }
}

/* 이미지 롤오버 */
function over(obj,type){
	if(type) obj.src = obj.src.replace(".gif","_.gif");
	else  obj.src = obj.src.replace("_.gif",".gif");
}

/* 새창띄우기 */
function newOpen(url,name,mwidth,mheight,top,left,resizable,scrollbars,status,position,msg) {
	// 창 화면가운데로 띄우기 //
	if(position=="C") {
		top = (window.screen.availHeight - mheight) / 2;
		left = (window.screen.availWidth - mwidth) / 2;
		if (top < 0) Top = 0;
		if (left < 0) Left = 0;
	}
		
	if(msg.length > 0) {
		if(confirm(msg)) {
			eval('window.open(url,name,"top='+top+'px,left='+left+'px,width='+mwidth+'px,height='+mheight+'px,resizable='+resizable+',scrollbars='+scrollbars+',status='+status+'")');
		} else { 
			return false; 
		}
	} else {
		eval('window.open(url,name,"top='+top+'px,left='+left+'px,width='+mwidth+'px,height='+mheight+'px,resizable='+resizable+',scrollbars='+scrollbars+',status='+status+'")');
	}
}

function totalsearch(hostPrefix) {
	var searchName = document.all.myhome.kwd.value;
	//alert(searchName);

	
	if( searchName.indexOf("%") != -1 || searchName.indexOf("#") != -1 ||
		searchName.indexOf("@") != -1 || searchName.indexOf("&") != -1 )
	{
		alert("특수문자는 사용할 수 없습니다."); //  특수문자 관련 Message입니다. 
 		return;
	}

	var returl = "http://"+hostPrefix+"potal.knou.ac.kr/portal/eus/search/search.do?kwd=" + searchName ;
	window.open(returl, "userSearch", "scrollbars=yes, resizable=no,scroll=auto, width=800,height=650,status=1,left=0,top=0");	
}



function openPop02(url, name, width, height, noOption) {
	if ( ! noOption ) {
		var pop = window.open(url, name, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,top=0,left=0,width="+ width +",height="+ height);
            pop.location.href=url;

	} else {
		var pop = window.open(url, name);
	}
	try { pop.focus(); } catch(e) {}
}

function openPop_noscroll(url, name, width, height, noOption) {
	if ( ! noOption ) {
		var pop = window.open(url, name, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=1,top=0,left=0,width="+ width +",height="+ height);
            pop.location.href=url;

	} else {
		var pop = window.open(url, name);
	}
	try { pop.focus(); } catch(e) {}
}

//팝업 로그인 페이지 호출
//parameter : returnUrl 로그인 성공시 리턴할 url
function popupLogin(returnUrl,hostPrefix) {
	var wWidth = 500;
	var wHeight = 385;
	var wX = (window.screen.width - wWidth) / 2;
	var wY = (window.screen.width - wHeight) / 2;
	
    
	//guest login시에 최종 return될 페이지 세팅
	if (returnUrl)	{
		strReturnUrl = returnUrl;
	} else {
		strReturnUrl = "http://"+hostPrefix+"www.knou.ac.kr";
	}
	
	//return시 팝업임을 인지하기 위한 파라미터
	var strRtnFrame = "Y";
    
	var w = window.open("http://"+hostPrefix+"ep.knou.ac.kr/popupLogin.do?strReturnUrl=" + strReturnUrl + "&strRtnFrame=" + strRtnFrame, 
		                "popupLoginWin", "directories=no,left=" + wX + ",width=" + wWidth + ",height=" + wHeight + ",scrollbars=yes");
}

//지역대학별 지도 및 위치정보 인쇄
function printMap(id) {
		
}
/*
function adjustIFrameSize2(id) {
	
	var iframeObject = document.getElementById(id);
	//아이프레임 높이 초기화
	iframeObject.height = "540";
	var innerBody = iframeObject.contentWindow.document.body;
	var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);
	
	if (innerHeight > iframeObject.height) {
		iframeObject.height = innerHeight;
		return;
	} else {
		return;
	}

}
//아이프레임 사이즈 자동조절 함수
//parameter : id 해당 아이프레임 요소의 id
function adjustIFrameSize(id) {
	try {
		var iframeObject = document.getElementById(id);
		//아이프레임 높이 초기화
		iframeObject.height = "540";
		var innerBody = iframeObject.contentWindow.document.body;
		var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);
		
		if (innerHeight > iframeObject.height) {
			iframeObject.height = innerHeight;
			return;
		} else {
			return;
		}
	} catch(e) {
	}
}

// 아이프레임 리사이징 //
function adjustIFrameSize_old(id) {
	try {	
	document.domain = "knou.ac.kr";
		
	var myIframe = document.getElementById(id);

   	
	//alert("현재아이프레임높이:" + myIframe.height + "\n" + "아이프레임컨텐츠의높이:" + myIframe.document.body.offsetHeight);

	if (myIframe) {
        if (myIframe.contentDocument && myIframe.contentDocument.body.offsetHeight) {
            // W3C DOM (and Mozilla) syntax
			if(window.opera) {			
				myIframe.height = myIframe.document.body.scrollHeight;
								
			} else {
				myIframe.height = myIframe.contentDocument.body.offsetHeight;    
				
			}
        } else if (myIframe.Document && myIframe.Document.body.scrollHeight) {
            // IE DOM syntax
            myIframe.height = myIframe.Document.body.scrollHeight;
        }

		// bind onload events to iframe
        if (myIframe.addEventListener) {			
            myIframe.addEventListener("load", resizeIframe, false);
        } else {
            myIframe.attachEvent("onload", resizeIframe);
        }
   }
   } catch(e) {
	}
}
*/

function adjustIFrameSize (id) {
	var iframe = document.getElementById(id);
	
	var ht = 480;
        var sh;
	// 고정크기 지정
	try {
  
  		if( iframe.contentWindow) {
			var doc = iframe.contentWindow.document;
		} else {
			var doc = iframe.document;
		}
		var sTop = doc.body.scrollTop;
		var oh = doc.body.offsetHeight;
		//var sh = doc.body.scrollHeight;
                if(navigator.userAgent.indexOf("MSIE") > -1){
                    sh = doc.body.scrollHeight;
                }else{
                    sh = doc.documentElement.scrollHeight;
                }
		ht = Math.max( oh, sh); 
		ht = sh;
		ht = ht + "px";
		if( iframe.style.height!=ht) {
			iframe.style.height=ht;
		}

		doc.body.scrollHeight = sTop;
		
	} catch(e) {
		try {
//iframe.style.height="800px";
		} catch(e) {
		}
	} 
}

//도메인설정 함수 
function setDomain() {
	try {
	document.domain = "knou.ac.kr";
	} catch(e) {
	}
}
/*
function resizeIframe(evt) {
	try {
    evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;

    // take care of W3C event processing from iframe's root document

    if (target.nodeType == 9) {
      if (evt.currentTarget && evt.currentTarget.tagName.toLowerCase() == "iframe") {
            target = evt.currentTarget;    
        }
    }

    if (target) {
        adjustIFrameSize(target.id);
    }
	} catch(e) {
	}
}
*/

// F9키로 아이프레임으로 포커스 이동 //
function iframeFocus(e) {
	var IE = "",keyCode = "";
	
	if(navigator.appName != "Microsoft Internet Explorer") 	IE = false;
	else IE = true;

	if(IE) 	keyCode = event.keyCode;	 // IE
	else keyCode = e.which;	// FF/netscape//opera

	// 펑션키 F9
	if(keyCode == 120) window.frames.uwayFrame.focus();	
}

