﻿function GoHompy(menu, hid) {
	window.open('http://hompy.studymania.com/'+hid+'/?menu='+menu, 'Hompy', 'status=no, resizable=no, scrollbars=no,width=930,height=650')
	return false;
}

function OnImgError(val)
{
  val.title = "원본:" + val.src;
  val.src = "http://file.studymania.com/renewal/images/no_img.gif";
  
}

function GoLogOut()
{
	//if (confirm("로그아웃 하시겠습니까?"))
	//{
		document.location.href="https:://tsl.studymania.com/tso/logout.aspx"
	//}
	return false;
}

function GoMenuDirect(szType)
{
  switch(szType)
  {
    case "mymania":    
		case "mymaniaroom":
		    document.location.href="http://ts.studymania.com/tss/mymania/default.aspx";
		    break;
		case "helpdesk":
		    document.location.href="http://ts.studymania.com/tss/board/thread/list.aspx?cate1=NOTICE";
		    break;
		case "login":
		    document.location.href="https://tsl.studymania.com/tso/login.aspx";
		    break;
		case "register":
		    document.location.href="http://ts.studymania.com/tss/member/MemberJoinPreFrm.aspx";
		    break;

    case "freepoint":
		    document.location.href="http://ts.studymania.com/tss/support/pointguide.aspx";
		    break; 
		    
	  case "studyfaq":
		    document.location.href="http://ts.studymania.com/tss/board/thread/list.aspx?cate1=STUDYFAQ";
		    break; 
			
		case "kmo":
		    document.location.href="http://ts.studymania.com/tss/product/product_view.aspx?cat_id=0301010000&saleinfo_id=19";
		    break; 
		case "smexam":
		    document.location.href="http://ts.studymania.com/tss/product/product_list.aspx?cat_id=0301020000";
		    break; 
		 
	  case "srcbook":
		    document.location.href="http://ts.studymania.com/tss/product/product_view.aspx?cat_id=0401010000&saleinfo_id=20";
		    break; 
		case "communitylevel":
		    document.location.href="http://ts.studymania.com/tss/support/communitylevel.aspx";
		    break; 
		
		case "memberedit":
		    document.location.href="http://ts.studymania.com/tss/member/MemberEditPreFrm.aspx";
		    break;
		
		case "jisikqD":
		    document.location.href="http://ts.studymania.com/tss/board/qna/qna_list.aspx?cate1=D";
		    break; 
		case "pay":
		    document.location.href="http://ts.studymania.com/tss/pay/ChargeCash.aspx";
		    break;
		case "goexam":
		    window.open("http://goexam.studymania.com/", "exam", "", "");
		    break;
	}
}

function addbookmark(){
	bookmarkurl="http://www.StudyMania.com/";
	bookmarktitle="특목고 진학 교육포탈 - 스터디 매니아";
	if (document.all) window.external.AddFavorite(bookmarkurl,bookmarktitle)
	return false;
}

function insertFlashObj(flashUrl, nWidth, nHeight)
{
  var strOut = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + nWidth + '" height="' + nHeight + '">';
  strOut += '<param name="movie" value="';
  strOut += flashUrl + '">';
  strOut += '<param name="quality" value="high" />';
  strOut += '<param name="allowScriptAccess" value="always" />';
  strOut += '<param name="wmode" value="transparent" />';
  strOut += '<embed src="' + flashUrl + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" type="application/x-shockwave-flash" width="' + nWidth + '" height="' + nHeight + '"></embed>';
  strOut += '</object>';
  
  document.write(strOut);
}

function insertFlashObjByID(flashId, flashUrl, nWidth, nHeight) {
  var strOut = '<object id="' + flashId + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + nWidth + '" height="' + nHeight + '">';
  strOut += '<param name="movie" value="';
  strOut += flashUrl + '">';
  strOut += '<param name="quality" value="high" />';
  strOut += '<param name="allowScriptAccess" value="always" />';
  strOut += '<param name="wmode" value="transparent" />';
  strOut += '<embed id="' + flashId + '" src="' + flashUrl + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" type="application/x-shockwave-flash" width="' + nWidth + '" height="' + nHeight + '"></embed>';
  strOut += '</object>';

  document.write(strOut);
}

function isLogin(bLoged)
{
 if(bLoged == "False")
 {     
   alert("로그인 해주세요!");
   return false;
 }        
 else
   return true;
}

function openWin(url, name, w, h)/*{{{*/
{
  var vleft = (screen.width - w)/2;
  var vtop = (screen.height - h)/2-150;
  var oWin = window.open(url, name, "scrollbars=no,resizable=yes,width="+w+",height="+h+", top="+vtop+", left="+vleft );
  try{ oWin.focus(); }catch(Exception){}
}/*}}}*/

function goZzim(z_type,z_idx,z_price,z_title,z_cate)
{
	window.open('http://ts.studymania.com/tss/mymania/myzzim.aspx?z_type='+z_type+'&z_idx='+z_idx+'&z_price='+z_price+'&z_title='+z_title+'&z_cate='+z_cate,'ZZim', 'toolbar=no, menubar=no, scrollbars=no, width=250,height=170')
}

function goSubmitLoginFrm()
{
  var fo = document.logFrm;        
  if(fo)
  {
    fo.action="https://tsl.studymania.com/tso/login.aspx";
	  fo.submit();
  }
}

function goAdLink(group, adtype)
{
  try {
    _hwaAd(group,adtype);
    switch(group)
    {
      case "004G":  
        window.open('http://yangseo.hs.kr');
        break;
    }
  } catch (_e) { }
}
  
  // 해당 컨트롤의 글자 수를 확인한다.
  // 한글, 영문 자동 계산한다.
  function checkStrLength(now_str, cnt)
  {
    var now_len = now_str.length; // 글자 수
    var max_len = cnt; // 제한할 최대 글자 수
    var idx = 0;
    var cnt_byte = 0; // 한글일 경우 2, 그외에는 1바이트 수 저장
    var sub_cnt = 0; // substring 할때 사용할 제한 길이를 저장
    var chk_letter = ""; // 현재 한/영 체크할 letter를 저장
    var lmt_str = ""; // 제한된 글자 수만큼 저장
    
    for(idx=0; idx<now_len; idx++)
    {
      // 1글자만 추출
      chk_letter = now_str.charAt(idx);
      
      // 체크문자가 한글일 경우 2byte, 그외의 경우 1byte 증가
      if(escape(chk_letter).length > 4)
        cnt_byte += 2;
      else
        cnt_byte++;
    }
    
    // Max Length Check
    if(cnt_byte <= max_len)
      return true;
    else
      return false;
  }

nWndHeight = -1;
nWndWidth = 600;
nTop = -1;
function setNTop() // TODO : 일단 이런식으로.. 250의 비밀을 밝힐 것
{
  if (window.XMLHttpRequest) {
    nTop = 63;
  } 
  else{
    nTop = 20;
  }
}
function resize_wnd (calltype)/*{{{*/
{
  setNTop();
  try {
    if ('object' != typeof(document.all.blank_img))
      return;
    if (document.all.blank_img.style.display == 'none')
      document.all.blank_img.style.display = 'block';

    if (nWndWidth == 600) nWndWidth = document.body.offsetWidth + 8;
  //  if (nTop < 0) {
  //    window.resizeTo(nWndWidth, 250); // TODO : 왜 250인가...
  //    nTop = 250 - document.body.clientHeight;
  //  }
    var nHeight = 0;
    if (document.all.blank_img) nHeight = document.all.blank_img.offsetTop + nTop;
    document.all.blank_img.style.display = 'none';
    var maxHeight = screen.availHeight;

    if (nHeight > maxHeight) {
      nHeight = maxHeight;
      document.body.scroll= 'yes';
    }
    if (nWndHeight>0)
      nHeight = nWndHeight;
    window.resizeTo(nWndWidth + 10, nHeight);
  } catch(e) {
    if (calltype != 'recall')
    {
      if (typeof(addOnloadHandle) == 'function')
        addOnloadHandle("resize_wnd(\"recall\")");
      else
        setTimeout("resize_wnd(\"recall\")", 1500);
    }
  }
}/*}}}*/
function auto_fit_wnd (nNewWidth, nNewHeight)/*{{{*/
{
  if (nNewWidth) nWndWidth = nNewWidth;
  if (nNewHeight) nWndHeight = nNewHeight;
  document.writeln("<iframe width='100' height='100' frameborder=0 marginheight=0 marginwidth=0 scrolling=no id='blank_img' src='about:blank' onload='resize_wnd();'></iframe>\n");
}/*}}}*/

function auto_fit_wnd_ssl (nNewWidth)/*{{{*/
{
  if (nNewWidth) nWndWidth = nNewWidth;
  document.writeln("<iframe width='100' height='100' frameborder=0 marginheight=0 marginwidth=0 scrolling=no id='blank_img' src='about:blank' onload='resize_wnd();'></iframe>\n");
}/*}}}*/

// Cookie 관련 함수 정의 by amoogi
// Cookie setting시, ts_setCookieField
// Cookie get ts_getCookie
var g_cookie1day = 86400;
var g_domainname = "studymania.com";

// Delete Cookie
function ts_deleteCookie(name)
{
  var value = "";
  var exp = new Date();
  if((name==null)||(value==null)) return false;
  exp.setTime(exp.getTime());
  document.cookie = name+"="+escape(value)+"; "+"expires="+exp.toGMTString()+"; path=/; domain="+g_domainname;
} 

// "name"으로 쿠키를 생성(기존에 있던 필드 그대로 저장)
function ts_setCookieField(name, subname, value, sec) 
{
  var oldcookie = ts_getCookie(name, "");

  if(oldcookie == null)
  {
    ts_setCookie(name, subname+"="+value, sec); // "name" 쿠키가 없었으면 생성
  }
  else
  {
    var carray = oldcookie.split("&");
    var fieldfound = false;
    var newcookie = "";
    
    for(var i=0; i<carray.length; i++) // 현재 쿠키에 해당 필드가 있는지 check
    {
      if( carray[i].indexOf(subname+"=") == 0) // field value에 subname+"="이 올 수 있으므로 정확하게 하기위해  
      {
        fieldfound = true;
        carray[i] = subname + "=" + value;
        break;
      }
    }
    
    if(fieldfound) // 이미 쿠키에 해당 필드가 존재
    {
      for(var i=0; i<carray.length; i++)
      {
        if(newcookie == "")
          newcookie += carray[i];
        else
          newcookie += "&" + carray[i];
      }
    }
    else
    {
      newcookie = oldcookie + "&" + subname + "=" + value; // oldcookie는 항상 null이 아님(위의 If문)
    }
  }
}

// "name" 으로 쿠키를 생성
function ts_setCookie(name,value,sec) 
{
  var exp = new Date();
  if((name==null)||(value==null)) return false; 

  if((sec==null)||(sec=="")||(sec=="0")||(sec==0))
    document.cookie = name+"="+value+"; "+"; path=/; domain="+g_domainname;
  else
  {
    exp.setTime(exp.getTime()+(9*60*60*1000)+(sec*1000)); //9시간 차이가 난다. 
    document.cookie = escape(name)+"="+escape(value)+"; "+"expires="+exp.toGMTString()+"; path=/; domain="+g_domainname;
  }
}

// "name" 으로 쿠키를 생성 (not use escape)
function ts_setCookieNoEscape(name,value,sec) 
{
  var exp = new Date();
  if((name==null)||(value==null)) return false; 
  
  if((sec==null)||(sec=="")||(sec=="0")||(sec==0))
    document.cookie = name+"="+value+"; "+"; path=/; domain="+g_domainname;
  else
  {
    exp.setTime(exp.getTime()+sec);
    document.cookie = name+"="+value+"; "+"expires="+exp.toGMTString()+"; path=/; domain="+g_domainname;
  }
}

// subname == "" or null then return cookie row else return cookie field in cookie row
function ts_getCookie(name, subname) { 
  var prefix = name + "=";
  var cookieStartIndex = document.cookie.indexOf(prefix);
  if (cookieStartIndex == -1)
    return null;
  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
  if (cookieEndIndex == -1)
    cookieEndIndex = document.cookie.length;
    
  if(subname == null || subname == "" || subname == 'undefined')
    return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)); // cookie row
  else
    return ts_getSubCookie(subname, unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))); // cookie field in cookie row
}

// called from ts_getCookie function
function ts_getSubCookie(name, ckstring){
  var prefix = name + "=";
  var cookieStartIndex = ckstring.indexOf(prefix);
  if (cookieStartIndex == -1)
    return null;
  var cookieEndIndex = ckstring.indexOf("&", cookieStartIndex + prefix.length);
  if (cookieEndIndex == -1)
    cookieEndIndex = ckstring.length;
    
  return ckstring.substring(cookieStartIndex + prefix.length, cookieEndIndex);
}

// Layer Popup, by amoogi
function sm_html_move_box(an, box, mtop, mleft) 
{
  //링크된 위치에서 부터의 설정값 지정
  var cleft = mleft;  //왼쪽마진  
  var ctop = mtop;  //상단마진
  var obj = an;
  while (obj.offsetParent) {
    cleft += obj.offsetLeft;
    ctop += obj.offsetTop;
    obj = obj.offsetParent;
  }
  box.style.left = cleft + 'px';
  ctop += an.offsetHeight + 8;
  if (document.body.currentStyle &&
    document.body.currentStyle['marginTop']) {
    ctop += parseInt(
      document.body.currentStyle['marginTop']);
  }
  box.style.top = ctop + 'px';
}

// Always Center, by amoogi, last modify neowindwiz
function sm_html_center_box(box, mWidth, mHeight) {
  var width = Geometry.getViewportWidth();
  var height = Geometry.getViewportHeight();
  var mHwidth = (width - mWidth) / 2;
  var mHheight = (height - mHeight) / 2;

  var doc = document;
  var xpos = (window.pageXOffset) ? window.pageXOffset : (doc.documentElement && doc.documentElement.scrollLeft) ?
             doc.documentElement.scrollLeft : (doc.body) ? doc.body.scrollLeft : 0;
  var ypos = (window.pageYOffset) ? window.pageYOffset : (doc.documentElement && doc.documentElement.scrollTop) ?
             doc.documentElement.scrollTop : (doc.body) ? doc.body.scrollTop : 0;

  box.style.left = mHwidth + xpos + fn_sm_get_hide_value("left");
  box.style.top = mHheight + ypos + fn_sm_get_hide_value("top");

//  alert("height = " + height + " | mheight = " + mHeight + " | ypos = " + ypos + " | top = " + box.style.top + " | etc = " + fn_sm_get_hide_value("top"));
}

// Call Layer Popup, by amoogi
function sm_html_show_hide_box(an, width, height, borderStyle) {
  var href = an.href;
  var boxdiv = document.getElementById(href);
  if (boxdiv != null) {
    // 오류 Message로 인해, href 재지정
    var ifScp = document.getElementById('ifSmcp');
    ifScp.src = href;
    
    if (boxdiv.style.display == 'none') {
      sm_html_move_box(an, boxdiv, 20, -10);
      boxdiv.style.display = 'block';
    } else
      boxdiv.style.display = 'none';
    return false;
  }

  boxdiv = document.createElement('div');
  boxdiv.setAttribute('id', href);
  boxdiv.style.display = 'block';
  boxdiv.style.position = 'absolute';
  boxdiv.style.width = width + 'px';
  boxdiv.style.height = height + 'px';
  boxdiv.style.border = borderStyle;
  boxdiv.style.backgroundColor = '#fff';

  var contents = document.createElement('iframe');
  contents.id = 'ifSmcp';
  contents.scrolling = 'no';
  contents.frameBorder = '0';
  contents.style.width = width + 'px';
  contents.style.height = height + 'px';
  contents.src = href;

  boxdiv.appendChild(contents);
  document.body.appendChild(boxdiv);
  sm_html_move_box(an, boxdiv, 20, -10);

  return false;
}

var sm_hide_box_top = "0";
var sm_hide_box_left = "0";
function fn_sm_set_hide_box_position(top, left) {
  sm_hide_box_top = top;
  sm_hide_box_left = left;
}

function fn_sm_get_hide_value(type) {
  if ("top" == type)
   return parseInt(sm_hide_box_top);
  else if ("left" == type)
   return parseInt(sm_hide_box_left);
}

function sm_html_show_hide_box_TypeA(an, width, height, borderStyle, sParam) {
  var href = an.href;
  var hrefParam = an.href;

  if (sParam != '')
    hrefParam += "?" + sParam;

  var boxdiv = document.getElementById(href);
  
  if (boxdiv != null) {
    // 오류 Message로 인해, href 재지정
    var ifScp = document.getElementById('ifSmcp');
    ifScp.src = hrefParam; 
    if (boxdiv.style.display == 'none') {
      sm_html_center_box(boxdiv, width, height);
      boxdiv.style.display = 'block';
    } else
      boxdiv.style.display = 'none';
    return false;
  }

  boxdiv = document.createElement('div');
  boxdiv.setAttribute('id', href);
  boxdiv.style.display = 'block';
  boxdiv.style.position = 'absolute';
  boxdiv.style.width = width + 'px';
  boxdiv.style.height = height + 'px';
  boxdiv.style.border = borderStyle;
  boxdiv.style.backgroundColor = '#fff';
  boxdiv.style.zIndex = "1";

  var contents = document.createElement('iframe');
  contents.id = 'ifSmcp';
  contents.scrolling = 'no';
  contents.frameBorder = '0';
  contents.style.width = width + 'px';
  contents.style.height = height + 'px';
  contents.src = hrefParam;

  boxdiv.appendChild(contents);
  document.body.appendChild(boxdiv);
  sm_html_center_box(boxdiv, width, height);

  return false;
}

// Layer Close
function sm_html_show_hide_box_parent_close(an) {
  var href = an.href;
  var boxdiv = parent.document.getElementById(href);
  if (boxdiv != null) {
    boxdiv.style.display = 'none';
    return false;
  }
}

// position object, by neowindwiz
var Geometry = {};
if (window.screenLeft != undefined) { // IE 등의 브라우저에서는
  Geometry.getWindowX = function() { return window.screenLeft; };
  Geometry.getWindowY = function() { return window.screenTop; };
}
else if (window.screenX) { // 파이어복스 등의 브라우저에서는
  Geometry.getWindowX = function() { return window.screenX; };
  Geometry.getWindowY = function() { return window.screenY; };
}

if (window.innerWidth) { // IE를 제외한 모든 브라우저에서는
  Geometry.getViewportWidth = function() { return window.innerWidth; };
  Geometry.getViewportHeight = function() { return window.innerHeight; };
  Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
  Geometry.getVerticalScroll = function() { return window.pageYOffset; };
}
else if (document.documentElement && document.documentElement.clientWidth) {
  Geometry.getViewportWidth = function() { return document.documentElement.clientWidth; };
  Geometry.getViewportHeight = function() { return document.documentElement.clientHeight; };
  Geometry.getHorizontalScroll = function() { return document.documentElement.scrollLeft; };
  Geometry.getVerticalScroll = function() { return document.documentElement.scrollTop; };
}
else if (null != document.body && document.body.clientWidth) {
  Geometry.getViewportWidth = function() { return document.body.clientWidth; };
  Geometry.getViewportHeight = function() { return document.body.clientHeight; };
  Geometry.getHorizontalScroll = function() { return document.body.scrollLeft; };
  Geometry.getVerticalScroll = function() { return document.body.scrollTop; };
}

// number format
function numberFormatStr(text) {
  if (text == "" || text == null || text == "undefined")
    return;
    
  text = text.split("").reverse().join("");
  var output = "";
  var j = 0;
  for (var i = 0; i < text.length; i++) {
    output += text.charAt(i);
    j++;
    if (j == 3 && i != text.length - 1) {
      output += ",";
      j = 0;
    }
  }
  output = output.split("").reverse().join("");
  return output;
}

// javascript Click URL
function goOnClickUrl(sUrl, sTarget) {
  switch (sTarget) {
    case "top":
      top.location.href = sUrl;
      break;
    case "self":
      self.location.href = sUrl;
      break;
    case "parent":
      parent.location.href = sUrl;
      break;
    default:
      document.location.href = sUrl;
  }
  return false;
}

// e하이스트 강좌정보 자세히 보기
function goLecture(sCatID, sSaleinfoID) {
  var winLec = window.open("/Tss/Product/Ehighest/eh_product_detail.aspx?cat_id=" + sCatID + "&saleinfo_id=" + sSaleinfoID, "강좌정보", "width=740, height=400, menubar=no, directories=no, resizable=yes, status=no, scrollbars=no");
  if (winLec)
    winLec.focus();
}

// e하이스트 교재몰 교재 자세히 보기
function goEhBook(sCatID, sSaleinfoID) {
  var winLec = window.open("/Tss/Product/Ehighest/eh_product_book_detail.aspx?cat_id=" + sCatID + "&saleinfo_id=" + sSaleinfoID, "교재정보", "width=550, height=700, menubar=no, directories=no, resizable=yes, status=no, scrollbars=no");
  if (winLec)
    winLec.focus();
}

// javascript Click URL
function goOnClickUrlByFlag(sUrl, sTarget, sOpen) {
  switch (sTarget) {
    case "top":
      top.location.href = sUrl;
      break;
    case "self":
      self.location.href = sUrl;
      break;
    case "parent":
      parent.location.href = sUrl;
      break;
    default:
      if (sOpen == "new") {
        var openNewWin = window.open("about:blank");
        openNewWin.location.href = sUrl;
      }
      else {
        document.location.href = sUrl;
      }
  }
  return false;
}

function fn_open_popup(name, url, width, height, attributes, isfocus) { 
  
  if(undefined == attributes || attributes.length <= 0)
    var attributes = "menubar=no, directories=no, resizable=yes, status=no, scrollbars=no";
  
  var features = "";
  features += (width > 0 ? "width=" + width : "");
  features += (features.length > 0 ? "," : "") + (height > 0 ? "height=" + height : "");
  features += (features.length > 0 ? "," : "") + (undefined != attributes ? attributes : "");
  
  var openWnd = window.open(url, name, features);

  if (undefined != isfocus && true == isfocus && undefined == openWin && null != openWin)
    openWin.focus();

  return false;
}