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 getCookie_multi(name,sval) {
	var multiCookie, arr_Cookies, arr_sval;
	var nameOfCookie = name + "=";
	var x = 0;
	var y;
	while ( x <= document.cookie.length )
	{
		y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie )
		{
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
				endOfCookie = document.cookie.length;
			multiCookie = unescape( document.cookie.substring( y, endOfCookie ) );
			arr_Cookies = multiCookie.split("&");
			for( var i=0; i<arr_Cookies.length; ++i ) {
				if(arr_Cookies[i].indexOf(sval) >= 0) {
					arr_sval = arr_Cookies[i].split("=");
					return arr_sval[1];
				}
			}
		}
		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 )
			break;
	}
	return "";
}

function scrCookie( name, value, expiredays, cookie_num )
{
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
	var eventCookie=getCookie("ANIMATE");
    if(eventCookie.length==0){
    	eventCookie="false/true";
    }
    var arr_pop=new Array(1),new_value;
    arr_pop=eventCookie.split("/");
    arr_pop[parseInt(cookie_num)-1]=value;

    new_value=arr_pop[0]+"/"+arr_pop[1];
    document.cookie = name + "=" + escape( new_value ) + "; domain=megastudy.net ; path=/; expires=" + todayDate.toGMTString() + ";"
}


function setCookie_multi(name, sval, value, expiredays) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );

	var multiCookie, arr_Cookies, arr_sval;
	var val_1=""; val_2="";
	multiCookie = getCookie(name);
	if(multiCookie == "") multiCookie="Chr_Poll"
	arr_Cookies = multiCookie.split("&");
	for( var i=0; i<arr_Cookies.length; ++i ) {
		if(arr_Cookies[i].indexOf(sval) >= 0) {
			arr_sval = arr_Cookies[i].split("=");
			val_1 = arr_sval[0];
			val_2 = arr_sval[1];
			break;
		}
	}
	if( val_1 == "" )
		multiCookie = multiCookie + "&" + sval + "=" + value;
	else
		multiCookie = multiCookie.replace(val_1+"="+val_2, val_1+"="+value);

	document.cookie = name + "=" + escape( multiCookie ) + ";domain=megastudy.net;path=/;expires=" + todayDate.toGMTString() + ";"
}


// 미디어플레이어9
function MakeMMS(Url, width, height){
  document.writeln("<object classid=\"CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\" id=\"MPlayer\" style=\"left:0px; top:0px;\" width=\""+width+"\" height=\""+height+"\" standby=\"상생방송국 www.stb.co.kr\">");
  document.writeln("<param name=\"FileName\" value=\""+Url+"\">");
  document.writeln("<param name=\"EnableContextMenu\"   value=\"false\">");
  document.writeln("<param name=\"TransparentatStart\"    value=\"true\">");
  document.writeln("<param name=\"AutoStart\" value=\"true\">");
  document.writeln("<param name=\"AutoSize\"   value=\"false\">");
  document.writeln("<param name=\"ShowStatusBar\" value=\"true\">");
  document.writeln("<param name=\"ShowDisplay\" value=\"false\">");
  document.writeln("<param name=\"ShowControls\" VALUE=\"true\">");
  document.writeln("</object>");
}

// 플레시 출력 - 컨트롤 박스 헤제
function MakeFlash(Url,Width,Height){
  document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"" + Width + "\" height=\"" + Height + "\">");
  document.writeln("<param name=\"movie\" value=\"" + Url + "\">");
  document.writeln("<param name=\"quality\" value=\"high\" />");
  document.writeln("<param name=\"wmode\" value=\"transparent\">");
  document.writeln("<param name=\"allowScriptAccess\" value=\"sameDomain\">");
  document.writeln("<embed src=\"" + Url + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + Width + "\"  height=\"" + Height + "\">");
  document.writeln("</object>");
}

// 플레시 출력 - 컨트롤 박스 헤제, 파라미터
function MakeFlashPara(Url,Width,Height, Para){
  document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"" + Width + "\" height=\"" + Height + "\">");
  document.writeln("<param name=\"movie\" value=\"" + Url + "\">");
  document.writeln("<param name=\"quality\" value=\"high\" />");
  document.writeln("<param name=\"wmode\" value=\"transparent\">");
  document.writeln("<param name=\"flashvars\" value=\""+ Para + "\">");
  document.writeln("<param name=\"allowScriptAccess\" value=\"sameDomain\">");
  document.writeln("<embed src=\"" + Url + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + Width + "\"  height=\"" + Height + "\">");
  document.writeln("</object>");
}

function textarea_decrease(id, row) {
	if (document.getElementById(id).rows - row > 0)
		document.getElementById(id).rows -= row;
}

function textarea_original(id, row) {
	document.getElementById(id).rows = row;
}

function textarea_increase(id, row) {
	document.getElementById(id).rows += row;
}

// a 태그에서 onclick 이벤트를 사용하지 않기 위해
function win_open(url, name, option) {
	var popup = window.open(url, name, option);
	popup.focus();
}

function nwin(URL, name, width, height) {
	newWin = window.open(URL, name, 'width='+width+', height='+height+', toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=auto, resizable=yes');
	newWin.focus();
}

function nwin2(URL, name, width, height) {
	newWin = window.open(URL, name, 'width='+width+', height='+height+', toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=auto, resizable=no');
	newWin.focus();
}

function vodpop(URL, name, width, height) {
	newWin = window.open(URL, name, 'width='+width+', height='+height+', toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no');
	newWin.focus();
}

function vodpop2(URL, name, width, height) {
	newWin = window.open(URL, name, 'width='+width+', height='+height+', toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=auto, resizable=yes');
	newWin.focus();
}

// 안티 스팸
function eMail(email) {
	var emailLength = email.length;
	var keep="";
	for(var i=emailLength;i>=0;i--) {
		var keep = keep + email.substr(i,1);
	}
	location = "mailto:"+keep;
}

// iframe 자동 높이 맞춤
function sync_height(el) {
	el = typeof el == 'string' ? document.getElementById(el) : el;
	if(el.contentWindow.document.body.innerHTML.length != 0) el.setExpression('height','contentWindow.document.body.scrollHeight+20');
	else el.style.height=0;
}


function Scrollon(pos) {
	var cpos = 	contents.document.body.scrollLeft;
	var tpos = 0;
	var i = 0;
	if (pos > cpos) {
		tpos = pos - cpos;
		while(i<=tpos) {
			contents.document.body.scrollLeft += 1;
			i += 1;
		}
	} else {
		tpos = cpos - pos;
		while(i<=tpos) {
			contents.document.body.scrollLeft -= 1;
			i += 1;
		}
	}
}

//function reSize() {
//	var ParentFrame	    =	contents.document.body;
//	var ContentFrame	=	document.all["contents"];
//	ContentFrame.style.height = ParentFrame.scrollHeight + (ParentFrame.offsetHeight - ParentFrame.clientHeight) + 100;
//	var postWidth = ParentFrame.scrollWidth + (ParentFrame.offsetWidth - ParentFrame.clientWidth);
//	document.all.MainDiv.innerHTML = "<table height=10 width=" + postWidth + " border=0><tr><td></td></tr></table>";
	//ContentFrame.style.width = ParentFrame.scrollWidth + (ParentFrame.offsetWidth - ParentFrame.clientWidth);
//}

function flash_movie(src, ids, width, height, wmode)
{
	var wh = "";
	if (parseInt(width) && parseInt(height))
		wh = " width='"+width+"' height='"+height+"' ";
	return "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' "+wh+" id="+ids+"><param name=wmode value="+wmode+"><param name=movie value="+src+"><param name=quality value=high><embed src="+src+" quality=high wmode="+wmode+" type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash' "+wh+"></embed></object>";
}

function obj_movie(src, ids, width, height, wmode)
{
	var wh = "";
	if (parseInt(width) && parseInt(height))
		wh = " width='"+width+"' height='"+height+"' ";
	return "<embed src="+src+" "+wh+"></embed>";
}
