/*******************************************************************************
 *
 *  Copyright 1998-2008 Today & Tomorrow. All rights reserved.
 *  Page: TTMallBuilder
 *  Date: 2007-02-06
 *
 *  Logs : Global JavaScript Function's
 *
 *******************************************************************************/
/** Global os Function's */
function str2int(d) { // 2ÀÚ¸® ¼ýÀÚ·á º¯°æ
  var str = new String();

  if (parseInt(d) < 10) {
    str = "0" + parseInt(d);
  } else {
    str = "" + parseInt(d);
  }
  return str;
}

function commify(n) {   // ¼ýÀÚ ÀÚ¸®¼ö Ã³¸®
  var reg = /(^[+-]?\d+)(\d{3})/;   // Á¤±Ô½Ä
  n += '';                          // ¼ýÀÚ¸¦ ¹®ÀÚ¿­·Î º¯È¯

  while (reg.test(n))
    n = n.replace(reg, '$1' + ',' + '$2');

  return n;
}

/** Member is Function's **/
function on_idpwd_find() { // È¸¿ø ¾ÆÀÌµð,ºñ¹ø Ã£±â
    window.open('mall.cgi?skin=idpwd_find', '', 'width=300,height=200');
}

function on_logout() { // ·Î±×¾Æ¿ô
    document.location.href = 'mall.cgi?act=Logout';
}

function on_modify() { //È¸¿øÁ¤º¸¼öÁ¤
    document.location.href = 'mall.cgi?skin=member_modify'
}

function on_member_withdraw() { // È¸¿ø Å»Åð
    if (confirm('È¸¿ø Å»Åð½ÅÃ»À» ÇÏ½Ã°Ú½À´Ï±î?\n\nÅ»ÅðÇÏ½Ã¸é ¹Ù·Î Àç°¡ÀÔÀÌ µÇÁö ¾Ê½À´Ï´Ù.  '))
        document.location.href = 'mall.cgi?act=MemberWithdraw&skin=member_withdraw';
}

/** ¼³¹®Á¶»ç Function S */

function onSurveySelect(frm,rPath, sCode, survey_date_end)
{
    if (!sCode) { alert("Á¸ÀçÇÏÁö ¾Ê´Â ¼³¹®Á¶»ç ÀÔ´Ï´Ù.");  return; }

    // ¼³¹®±â°£ Ã¼Å© S
    datToday = new Date();                                  // ÇöÀç ³¯ÀÚ ¼³Á¤
    NowThisYear = datToday.getFullYear();                   // ÇöÀç ³â
    NowThisMonth = datToday.getMonth()+1;                   // ÇöÀç ¿ù
    NowThisDay = datToday.getDate();                        // ÇöÀç ÀÏ
    NowDate =  NowThisYear + "-" + str2int(NowThisMonth).toString() + "-" + str2int(NowThisDay).toString();
    if (survey_date_end < NowDate) { alert("¼³¹®±â°£ÀÌ Áö³µ½À´Ï´Ù.");  return; }
    // ¼³¹®±â°£ Ã¼Å© E

    var bNotSelect = 1;

    if (n_example_select == 0) {
        alert("¿¹½Ã°¡ ¾ø½À´Ï´Ù.");
        return;
    }

    for (var i = 0; i < frm.example_select.length; i++) {
        if (frm.example_select[i].checked == true) {
            bNotSelect = 0;
            break;
        }
    }

    if (bNotSelect) {
        alert("¿¹½Ã¸¦ ÇÏ³ª ¼±ÅÃÇØ ÁÖ½Ê½Ã¿À.");
        return;
    }

    frm.action = "mall.cgi?act=SurveyExampleSelect&skin=survey_example_select&return_path=" + rPath + "&survey_code=" + sCode;
    frm.submit();
}

function onSurveyResult(survey_code) {
    window.open("mall.cgi?skin=survey_result&survey_code="+survey_code+"", "", "scrollbars=yes,width=300,height=250");
}
/** ¼³¹®Á¶»ç Function E */

// ¸ÞÀÎ ÄíÅ°Ã³¸®
function view_getCookieVal(offset)
{
    var endstr = document.cookie.indexOf(';', offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape( document.cookie.substring(offset, endstr) );
}

function view_GetCookie(name)
{
    var arg = name + '=';
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;

    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return view_getCookieVal(j);

        i = document.cookie.indexOf(' ', i) + 1;
        if (i == 0) break;
    }

    return null;
}

function view_SetCookie(name, value)
{
    var argv = view_SetCookie.arguments;
    var argc = view_SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path    = (argc > 3) ? argv[3] : null;
    var domain  = (argc > 4) ? argv[4] : null;
    var secure  = (argc > 5) ? argv[5] : false;

    document.cookie = name + '=' + escape (value) +
        ((expires == null) ? '' : ('; expires=' + expires.toGMTString())) +
        ((path    == null) ? '' : ('; path=' + path)) +
        ((domain  == null) ? '' : ('; domain=' + domain)) +
        ((secure  == true) ? '; secure' : '');
}

function view_DeleteCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = view_GetCookie(name);
    document.cookie = name + '=' + cval + '; expires=' + exp.toGMTString();
}

//
// °Ë»ö °ü·Ã
//
function on_search() {
  var frm = document.SearchForm;
  if (frm.srch_word.value == '') {
    alert('°Ë»ö¾î¸¦ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.');
    frm.srch_word.focus();
    return;
    }

    frm.action = 'mall.cgi?skin=search_result';
    frm.submit();
}

function on_search_enter() {
   if (window.event.keyCode == 13) {
      on_search();
    }
}

function on_menu_search() { // »óÇ° °Ë»ö
    var frm = document.MenuSearchForm;
    if (frm.srch_word.value == '') {
        alert('°Ë»ö¾î¸¦ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.');
        frm.srch_word.focus();
        return;
    }

    frm.action = 'mall.cgi?skin=search_result';
    frm.target = '_self';
    frm.submit();
}

function on_menu_search_detail() {
    var frm = document.MenuSearchForm;
    frm.action = 'mall.cgi?skin=search_detail';
    frm.target = '_self';
    frm.submit();
}

function on_menu_search_enter() {
    if (window.event.keyCode == 13) {
        on_menu_search();
    }
}

//ÆË¾÷¸®»çÀÌÁî ÇÔ¼ö Ãß°¡ 2008.1.31 ±è¼º±¸
//ÆË¾÷¿ë( IE7 IE6 FF opera ) - °¡·Î Å©±âµµ °è»ê ( »õ·Î°íÄ§½Ã °è¼Ó ´Ã¾î³ª´Â Çö»ó ¹ß»ý )
function resizepopup()
{
    if(document.all)
    {
        var  height = parseInt(document.body.scrollHeight);
        var  width = parseInt(document.body.scrollWidth);
    }
    else
    {
        var height = parseInt(document.body.offsetHeight);
        var width = parseInt(document.body.offsetWidth);
    }
    var odiv = document.createElement("div");
    odiv.style.position = "absolute";odiv.style.left = "0px";odiv.style.top = "0px";odiv.style.width = "100%";odiv.style.height = "100%";
    document.body.appendChild(odiv);window.resizeBy(width-odiv.offsetWidth+5, height-odiv.offsetHeight);document.body.removeChild(odiv);
}
//°´Ã¼ »çÀÌÁî±¸ÇÏ±â
function getBounds(tag)
{
    var ret = new Object();
    if(document.all) {
    var rect = tag.getBoundingClientRect();
    ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft);
    ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop);
    ret.width = rect.right - rect.left;
    ret.height = rect.bottom - rect.top;
    } else {
    var box = document.getBoxObjectFor(tag);
    ret.left = box.x;
    ret.top = box.y;
    ret.width = box.width;
    ret.height = box.height;
    }
    return ret;
}

//
// ÁÖ¹®»óÇ° ¼±ÅÃ¿É¼Ç ·¹ÀÌ¾î
//
// »óÇ° »ó¼¼³»¿ª ·¹ÀÌ¾î  (IE & FF)
function msgposit_cart(event) {
    isIE=document.all;
    var x = (isIE)?event.x:event.clientX;
    var y = (isIE)?event.y:event.clientY;

    if (isIE==undefined) {
        document.getElementById('message_cart').style.left = x+(Math.max(document.documentElement.scrollLeft, document.body.scrollLeft))+20+'px';
        document.getElementById('message_cart').style.top = y+(Math.max(document.documentElement.scrollTop, document.body.scrollTop))-30+'px';
    } else {
        var box = getBounds(document.getElementById('mBody'));
        document.getElementById('message_cart').style.left = x+box.left+20+'px';
        document.getElementById('message_cart').style.top = y+box.top-30+'px';
    }
}

function msgset_cart(str) {
    if (str == '') return;
    var html= '<div class=cart_item><table><tr><th colspan=2>¼±ÅÃ»ç¾ç</th></tr>'+str+'</table></div>';
    document.getElementById('message_cart').innerHTML = html;
}

function msghide_cart() {
    document.getElementById('message_cart').innerHTML = '';
}

