// ----------------------------------------
//          Common Java Script
//          dirkill@hanmir.com
//              (2002.8.)
//-----------------------------------------

//=======================================================
//   Dream Weaver Layer °ü·Ã ÇÔ¼ö
//=======================================================

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//=======================================================
// Dream Weaver Layer À§Ä¡, Å©±â °ü·Ã ÇÔ¼ö
//=======================================================

function tmt_findObj(n) {
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	}else{x=document.getElementById(n)}return x;
}

function tmt_DivMove(theDiv, l, t) {
	var x = (document.layers) ? ".left" : ".style.left";
	var y = (document.layers) ? ".top" : ".style.top";
	var fun = (document.getElementById) ? "tmt_findObj" : "MM_findObj";
	var obj = eval(fun+"(theDiv)");if(obj){
	eval(fun+"('"+theDiv+"')"+y+"="+t);
	eval(fun+"('"+theDiv+"')"+x+"="+l);}
}

function tmt_DivResize(theDiv, w, h) {
    var fun = (document.getElementById) ? "tmt_findObj" : "MM_findObj";
	var obj = eval(fun+"(theDiv)");
	if(document.layers && obj)obj.resizeTo(w, h);
  	else{if(obj)obj.style.width = w;obj.style.height = h;}
}

// SAMPLE
// <a href="" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','onimage.gif',1)">
// MM_showHideLayers('Layer1','','show');
// MM_showHideLayers('Layer1','','hide');
// MM_preloadImages('img1.gif', 'img2.gif');
// tmt_DivMove('Layer1','100','100');


// ----- from Namo 4.0
function na_page_width()  { return (navigator.appName.indexOf('Netscape', 0) != -1) ? innerWidth  : document.body.clientWidth; }
function na_page_height() { return (navigator.appName.indexOf('Netscape', 0) != -1) ? innerHeight : document.body.clientHeight; }

//===============================================================
// s : true = Center On Screen, false = Center On Current Window
//===============================================================

function dkCenterWindow(w, h, s) {
	var xp, yp;
	var op = 'width=' + w + ',height=' + h;

	if (s) {
		xp = (screen.width - w) / 2;
		yp = (screen.height - h) / 2;
	} else {
		xp = window.screenLeft + (na_page_width() - w) / 2;
		yp = window.screenTop + (na_page_height() - h) / 2;
	}

	op += ',left=' + xp + ',top=' + yp;

	return op;
}

function dkOpenWindow(url, w, h, bscroll, bresize, winname) {
	var opt = "width=" + w + ",height=" + h + ",scrollbars=" + bscroll + ",resizable=" + bresize;
	var wname = "";
	if (winname) wname = winname;
	var hwin = window.open(url, wname, opt);
	hwin.focus();
	return (hwin);
}

function dkResizeWindow(w, h) {
	window.resizeTo(w, h);
}

//=======================================================
// Cookie Functions
//=======================================================

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 setCookie(name, value) {
	var argc = setCookie.arguments.length;          // setCookie ÇÔ¼öÀÇ ¸Å°³º¯¼ö °³¼ö ±¸ÇÏ±â
	var argv = setCookie.arguments;                 // setCookie ÇÔ¼öÀÇ ¸Å°³º¯¼ö ¹è¿­ ±¸ÇÏ±â
	var expires = (argc > 2) ? argv[2] : null;      // ¸Å°³º¯¼ö°¡ 3°³ ÀÌ»óÀÌ¸é 3¹øÂ° ¸Å°³º¯¼ö´Â expire¸¦ À§ÇÑ °ª
	var path = (argc > 3) ? argv[3] : null;         // ¸Å°³º¯¼ö°¡ 4°³ ÀÌ»óÀÌ¸é 4¹øÂ° ¸Å°³º¯¼ö´Â path¸¦ À§ÇÑ °ª
	var domain = (argc > 4) ? argv[4] : null;       // ¸Å°³º¯¼ö°¡ 5°³ ÀÌ»óÀÌ¸é 5¹øÂ° ¸Å°³º¯¼ö´Â domain¸¦ À§ÇÑ °ª
	var secure = (argc > 5) ? argv[5] : false;      // ¸Å°³º¯¼ö°¡ 6°³ ÀÌ»óÀÌ¸é 6¹øÂ° ¸Å°³º¯¼ö´Â secure¸¦ À§ÇÑ °ª
	document.cookie = name + "=" + escape(value) +
		((expires==null) ? "" : ("; expire=" + expires.toGMTString())) +
		((path==null) ? "" : ("; path=" + path)) +
		((domain==null) ? "" : ("; domain=" + domain)) +
		((secure==true) ? "; secure" :"");          	// cookie Æ¯¼º¿¡ Á¤º¸ ¼³Á¤
}

//=================== ETC
function setUndefined(s, d) { return (typeof s == "undefined" ? d : s); }
function isUndefined(s) { return (typeof s == "undefined"); }

function setStatus(str) {
	window.status = (str=="" ? " " : str);
	return true;
}

function crFunc(func) {
	if (event.keyCode==13) {
		eval(func); return false;
	}
	return true;
}

function countChecked(elem) {
	var tot = 0;
	if (eval(elem)) {
		for (var i=0; i<elem.length; i++) {
			if (elem[i].checked) tot++;
		}
	}
	return tot;
}

function checkFormText(elem, val, msg) {
	if (elem.value==val) {
		alert(msg);
		elem.focus();
		return false;
	}
	return true;
}

function checkFormSelect(elem, val, msg) {
	if (elem.selectedIndex==val) {
		alert(msg);
		elem.focus();
		return false;
	}
	return true;
}

//========= for Roll Menu
function dkRollMenu(id, after) {
	eval(id+'.src="'+after+'";');
}

function dkRollMenuTrans(id, after) {
	eval(id+'.filters.blendTrans.stop();');
	eval(id+'.filters.blendTrans.Apply();');
	eval(id+'.src="'+after+'";');
	eval(id+'.filters.blendTrans.Play();');
}

function addFavoriteSites(url, txt) {
	window.external.AddFavorite(url, txt);
}

// PHP URLEncode ÇÔ¼ö : from phpjs
function URLEncode(str) { var histogram={},tmp_arr=[];var ret=str.toString();var replacer=function(search,replace,str){var tmp_arr=[];tmp_arr=str.split(search);return tmp_arr.join(replace);};histogram["'"]='%27';histogram['(']='%28';histogram[')']='%29';histogram['*']='%2A';histogram['~']='%7E';histogram['!']='%21';histogram['%20']='+';ret=encodeURIComponent(ret);for(search in histogram){replace=histogram[search];ret=replacer(search,replace,ret)} return ret.replace(/(\%([a-z0-9]{2}))/g,function(full,m1,m2){return"%"+m2.toUpperCase();});return ret;}

