﻿var http = 'https://www.digimonrpg.com'
var https = 'https://www.digimonrpg.com'

function setCookie(name, value)
{
  var path = "/";  
  var expires = 1;  //하루.
  var domain = "";  

  var today = new Date();
  today.setDate(today.getDate() + expires );

  document.cookie = name + "=" + escape(value)+ "; path=" + path ;
}

 

function getCookie(name)
{
  var sCookieName = name + "=";
  var i = 0;
  var j;
  var endOfCookie;
  
  while ( i <= document.cookie.length )
  {
    j = (i+sCookieName.length);

    if ( document.cookie.substring(i,j) == sCookieName )
    {
      if ( (endOfCookie=document.cookie.indexOf( ";", j )) == -1 )
      {
        endOfCookie = document.cookie.length;
      }
      return unescape( document.cookie.substring( j, endOfCookie ) );
    }

    i = document.cookie.indexOf( " ", i ) + 1;
    if (i == 0)
    {
      break;
    }
  }
  return "";
}

function color_change(target)
{   
    var color = '#999998 #8A8A8A #797979 #666666 #525252 #3D3D3E #2A2A2A #191818 #0B0A0B #000000'.split(' ');    
    var tid;
    var cnt=0;
     
    function change()
    {
        if(cnt<10){target.css("background","url('') no-repeat " + color[cnt]); cnt++;}
        else clearInterval(tid);
    }
    tid = setInterval(change, 30);
}

function write_flash(width, height, name)
{
    var html = '';
    html += '<object width="'+ width +'" height="'+ height +'" style="z-index:1;" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + location.protocol + '://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0">';
    html += '    <param name="movie" value="'+ name +'" />';
    html += '    <param name="quality" value="high" />';
    html += '    <param name="wmode" value="transparent" />'; 
    html += '    <embed src="'+ name +'" quality="high" pluginspage="' + location.protocol + '://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ width +'" height="'+ height +'"></embed>';
    html += '</object>';
    document.write(html);
}

function top_flash(main, sub)
{   
    $form = $('#top_url');
    if(main == 0) $form.attr('action',http + '/');
    else if(main == 1){
        if(sub == 1) $form.attr('action',http + '/notice/main.aspx');
        else if(sub == 2) $form.attr('action',http + '/notice/main.aspx');
        else if(sub == 3) $form.attr('action',http + '/notice/update.aspx');
        else if(sub == 4) $form.attr('action',http + '/notice/report.aspx');
        else if(sub == 5) $form.attr('action',http + '/notice/event.aspx');
    }
    else if(main == 2){
        if(sub == 1) $form.attr('action',http + '/guide/main.aspx');
        else {
			alert('준비중입니다.');return;
		}             
    }
    else if(main == 3){
        if(sub == 1) $form.attr('action',http + '/down/main.aspx');
        else if(sub == 2) $form.attr('action',http + '/down/main.aspx');
        else if(sub == 3) $form.attr('action',http + '/down/artwork.aspx');
    }  
    else if(main == 4){
        if(sub == 1) $form.attr('action',http + '/ranking/main.aspx');
        else if(sub == 2) $form.attr('action',http + '/ranking/main.aspx');
        else if(sub == 3) $form.attr('action',http + '/ranking/tamer.aspx');
        else if(sub == 4) $form.attr('action',http + '/ranking/partner.aspx');
        else if(sub == 5) $form.attr('action',http + '/ranking/sub.aspx');
        else if(sub == 6) $form.attr('action',http + '/ranking/digimon.aspx'); 
        else if(sub == 7) $form.attr('action',http + '/ranking/user.aspx');  
    }  
    else if(main == 5){
        if(sub == 1) $form.attr('action',http + '/community/main.aspx');
        else if(sub == 2) $form.attr('action',http + '/community/main.aspx');
        else if(sub == 3) $form.attr('action',http + '/community/knowhow.aspx');
        else if(sub == 4) $form.attr('action',http + '/community/story.aspx');
    }
    else if(main == 6){
        if(sub == 1) $form.attr('action',http + '/shop/main.aspx');
        else if(sub == 2) $form.attr('action',http + '/shop/main.aspx');         
        else if(sub == 3) $form.attr('action',http + '/shop/item_tamer.aspx');
        else if(sub == 4) $form.attr('action',http + '/shop/item_power.aspx');
        else if(sub == 5) $form.attr('action',http + '/shop/item_avatar.aspx');
        else if(sub == 6) $form.attr('action',http + '/shop/list.aspx');  
        else if(sub == 7) $form.attr('action',http + '/shop/notice.aspx');         
    }
    else if(main == 7){
        if(sub == 1) $form.attr('action',http + '/customer/main.aspx');
        else if(sub == 2) $form.attr('action',http + '/customer/main.aspx');
        else if(sub == 3) $form.attr('action',http + '/customer/question.aspx');
        else if(sub == 4) $form.attr('action',http + '/customer/wrong.aspx');
    } 
    $form.submit();
}

function goto_page(url)
{
    var form = document.createElement('form');
    form.action = url;
    form.method = 'post'; 
    form.submit();
}

function open_pop(openUrl, width, height)
{
    var cw=width;
    var ch=height;
    var sw=screen.availWidth;
    var sh=screen.availHeight;
    var px=(sw-cw)/2;
    var py=(sh-ch)/2;    
    window.open(openUrl,'','toolbar=no,resizable=no,location=no,menubar=no,scrollbars=no,location=no,width='+cw+',height='+ch+', top='+py+', left='+px+'');
}
function openpop(openUrl, title, width, height)
{
    var cw=width;
    var ch=height;
    var sw=screen.availWidth;
    var sh=screen.availHeight;
    var px=(sw-cw)/2;
    var py=(sh-ch)/2;    
    window.open(openUrl,title,'toolbar=no,resizable=no,location=no,menubar=no,scrollbars=no,location=no,width='+cw+',height='+ch+', top='+py+', left='+px+'');
}

Validate = function()
{   
};
Validate.prototype = {
    user_id : function(value){
        return /^[a-z][a-z0-9]{5,}$/i.test(value);
    },
    password : function(value){
        return /[a-z]/i.test(value) && /\d/i.test(value) && /^[a-z0-9]{5,}$/i.test(value);
    },
    phone_number : function(value){
        return /^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}$/.test(value);
    },
    e_mail : function(value){
        return /^[_a-zA-Z0-9-]+@[._a-zA-Z0-9-]+.[a-zA-Z]+$/.test(value); 
    },
    social_number : function(value){
        a = new Array(13);
        for (var i=0; i < 13; i++)
            a[i] = parseInt(value.charAt(i));
        var k = 11 - (((a[0] * 2) + (a[1] * 3) + (a[2] * 4) + (a[3] * 5) + (a[4] * 6) + (a[5] * 7) + (a[6] * 8) + (a[7] * 9) + (a[8] * 2) + (a[9] * 3) + (a[10] * 4) + (a[11] * 5)) % 11);
        if (k > 9) k -= 10;
        if (k != a[12]) return false;
        else return true; 
    },
    gtcard : function(value){
        return /^[0-9A-Z]{5}$/i.test(value);
    }, 
    evcard : function(value){
        return /^[A-Z]{4}$/i.test(value);
    },
    okcash : function(value){
        return /^[A-Z0-9]{5}$/i.test(value);
    }, 
    key : function(e, keycode){        
        for(var i=0; i<keycode.length; i++) {
            if(e.keyCode == keycode[i]) {
                if(window.event){window.event.keyCode = '';};
                return false;
            } 
        } 
        return true;
    }
}

BorwserSet = function(){};
BorwserSet.prototype = {
    menu_off : function(){
        document.oncontextmenu = function(){return false;} 
    }
}

Diary = function(target) 
{   
    this.yol = [ '일','월','화','수','목','금','토' ];
    this.mon = [31,28,31,30,31,30,31,31,30,31,30,31];
    this.Day;
    this.Year;
    this.Month;
    this.Yoil;
    this.fd;
    this.ld;
    this.curMonth = true;
    this.NowDate;
    this.Element = target; 
    this.Target = $(target);
};
Diary.prototype = {
 
    newDate : function(){
        if(this.Target.val() == ''){this.D=new Date();}
        else{this.D=new Date(this.Target.val().split('-')[0], parseInt((this.Target.val().split('-')[1].substring(0,1) == '0' ? this.Target.val().split('-')[1].substring(1,2) : this.Target.val().split('-')[1])) - 1, this.Target.val().split('-')[2]);}
         
        this.NowDate = this.D; //현재 날짜 복사해서 넣어둠
        this.Year=this.D.getFullYear(); //년
        this.Month=this.D.getMonth(); //월
        this.Day=this.D.getDate(); //일
        this.fd=new Date(this.Year,this.Month,1).getDay(); //첫 요일
        this.ld=new Date(this.Year,this.Month+1,0).getDay(); //끝 요일
    },

    confirmCurDay : function(){
        if(this.Year == this.NowDate.getFullYear() && this.Month == this.NowDate.getMonth()) return true;
        else return false;
    },
    nextDate : function(){
        if(this.Month == '11') {this.Year++;this.Month = 0;}
        else this.Month++;
        this.fd=new Date(this.Year,this.Month,1).getDay(); //첫 요일
        this.ld=new Date(this.Year,this.Month+1,0).getDay(); //끝 요일
    },
    prevDate : function(){
        if(this.Month == "0") {this.Year--;this.Month = 11;}
        else this.Month--;
        this.fd=new Date(this.Year,this.Month,1).getDay(); //첫 요일
        this.ld=new Date(this.Year,this.Month+1,0).getDay(); //끝 요일
    },
    prevYearDate : function(){         
        this.Year--;
        this.fd=new Date(this.Year,this.Month,1).getDay(); //첫 요일
        this.ld=new Date(this.Year,this.Month+1,0).getDay(); //끝 요일 
    },
    prevYearDiary : function(){this.prevYearDate();this.printDiary();},
    nextYearDate : function(){
        this.Year++;
        this.fd=new Date(this.Year,this.Month,1).getDay(); //첫 요일
        this.ld=new Date(this.Year,this.Month+1,0).getDay(); //끝 요일 
    },
    nextYearDiary : function(){this.nextYearDate();this.printDiary();},
    curDiary : function(){this.newDate();this.printDiary();},
    nextDiary : function(){this.nextDate();this.printDiary();},
    prevDiary : function(){this.prevDate();this.printDiary();},
    printDiary : function(){
         
        if($('#diary').attr('id') != undefined) $('#diary').empty();
        else $('body').append('<div id="diary" class="diary">').focus();
        
        tag = "";
        tag += "<ul>";
        tag += "     <li>";
        tag += "         <img src=\"/images/b_prev.gif\" alt=\"\" class=\"next\" onclick=\"diary.prevYearDiary();\" />";
        tag += "         <label>"+this.Year+"</label>"; 
        tag += "         <img src=\"/images/b_next.gif\" alt=\"\" class=\"next\" onclick=\"diary.nextYearDiary();\" />&nbsp;";
        tag += "         <img src=\"/images/b_prev.gif\" alt=\"\" class=\"next\" onclick=\"diary.prevDiary();\" />";
        tag += "         <label style=\"width:100px;\">"+((this.Month+1).toString().length == 1 ? '0' : '') + (this.Month+1)+"</label>";
        tag += "         <img src=\"/images/b_next.gif\" alt=\"\" class=\"next\" onclick=\"diary.nextDiary();\" />&nbsp;&nbsp;";
        tag += "         <img src=\"/images/close_d.gif\" alt=\"\" class=\"next\" onclick=\"$('#diary').remove();\" />"; 
        tag += "     </li>";
        tag += "     <li style=\"background-color:#f6f6f6; margin-top:5px;\">";
        tag += "<table cellpadding=\"0\" cellspacing=\"0\">";
        tag += "     <tbody>";
        tag +="          <tr>";
        var cnt=0;
        for(j=0;j<this.yol.length;j++)
        {
            if (j==0) { tag+="<th style='color:red;'>"+this.yol[j]+"</th>"; }
            else if(j==6) { tag+="<th style='color:blue;'>"+this.yol[j]+"</th>"; }
            else { tag+="<th>"+this.yol[j]+"</th>"; }
        } 
        tag += "         </tr>";
        tag += "         <tr>";
        for(i=0;cnt<this.mon[this.Month];i++)
        {
            if(i % 7 == 0 && i >= 7) tag+="</tr><tr>";
            if(i<this.fd) tag+="<td style=\"cursor:default;\">&nbsp;</td>";
            else 
            {
                cnt++;
                tag += "<td valign=middle onclick=\"";
                tag += "$('#"+ this.Target.attr('id') +"').val('" + this.Year + "-" + ((this.Month+1).toString().length == 1 ? '0' : '') + (this.Month+1) + "-" + ((cnt).toString().length == 1 ? '0' : '') + (cnt) + "');";
                tag += "$('#diary').remove();\"";
                if(cnt==this.Day && this.confirmCurDay()) tag+="class=\"today\"";
                else { 
                    if(i%7==0) tag+="class=\"sunday\"";
                    else if(i%7==6) tag+="class=\"tuesday\"";
                }
                tag += ">"+cnt+"</td>"; 
            }
        }
        tag += "         </tr>";
        tag += "     </tbody>";
        tag += "</table>";
        tag += "     </li>"; 
        tag += "</ul>"; 
        $('.diary').css({top : this.Target.offset().top + 20 , left : this.Target.offset().left}).html(tag);
    }
}

WriteMsg = function()
{
    this.MSGTIMER = 35;
    this.MSGSPEED = 5;
    this.MSGOFFSET = 3;
    this.MSGHIDE = 3;
};
WriteMsg.prototype = {
    inlineMsg : function(target,string,autohide) {
        var self = this;   
        var msg;
        var msgcontent;
        if(!document.getElementById('msg')) {
            msg = document.createElement('div');
            msg.id = 'msg';
            msgcontent = document.createElement('div');
            msgcontent.id = 'msgcontent';
            document.body.appendChild(msg);
            msg.appendChild(msgcontent);
            msg.style.filter = 'alpha(opacity=0)';
            msg.style.opacity = 0;
            msg.alpha = 0;
        }
        else {
            msg = document.getElementById('msg');
            msgcontent = document.getElementById('msgcontent');
        }
        msgcontent.innerHTML = string;
        msg.style.display = 'block';
        var msgheight = msg.offsetHeight;
        var targetdiv = document.getElementById(target);
        targetdiv.focus();
        var targetheight = targetdiv.offsetHeight;
        var targetwidth = targetdiv.offsetWidth;
        var topposition = this.topPosition(targetdiv) - ((msgheight - targetheight) / 2);
        var leftposition = this.leftPosition(targetdiv) + targetwidth + this.MSGOFFSET;         
        msg.style.top = topposition + 'px';
        msg.style.left = leftposition + 'px';
        clearInterval(msg.timer);
        msg.timer = setInterval(function(){self.fadeMsg(1)}, this.MSGTIMER);
        if(!autohide) {
            autohide = this.MSGHIDE;  
        }
        window.setTimeout(function(){self.hideMsg()}, (autohide * 1000));
    },
        
    hideMsg : function(msg){
        var self = this; 
        var msg = document.getElementById('msg');
        if(!msg.timer) {
            msg.timer = setInterval(function(){self.fadeMsg(0)}, this.MSGTIMER);
        } 
    }, 
    fadeMsg : function(flag){
        var self = this; 
        if(flag == null) {flag = 1;}
        var msg = document.getElementById('msg');
        var value;
        if(flag == 1) {value = msg.alpha + this.MSGSPEED;} 
        else {value = msg.alpha - this.MSGSPEED;}
        
        msg.alpha = value;
        msg.style.opacity = (value / 100);
        msg.style.filter = 'alpha(opacity=' + value + ')';
        if(value >= 99) {
            clearInterval(msg.timer);
            msg.timer = null;
        }
        else if(value <= 1) {
            msg.style.display = "none";
            clearInterval(msg.timer);
        }
    },
    topPosition : function (target) {
        var top = 0;
        if(target.offsetParent) {
            while(1) {
                top += target.offsetTop;
                if(!target.offsetParent)
                    break;
                target = target.offsetParent;
            }
        }
        else if(target.y)
            top += target.y;    
        return top;
    },
    leftPosition : function(target) {
        var left = 0;
        if(target.offsetParent) {
            while(1) {
                left += target.offsetLeft;
                if(!target.offsetParent)
                    break;            
                target = target.offsetParent;
            }
        }
        else if(target.x)
            left += target.x;
        return left;
    } 
}
