﻿//addrow에 쓰는 기본 변수//
var chvote_Obj= null;
var chvote_Rtn;

var rtchvote_Obj= null;
var rtchvote_Rtn;
var btnlist = "";
var btncnt = 0;
    function CVote(MC_ID,MC_NM,MC_CNT)
    {
        if(MC_ID == '')
        {
            alert("캐릭터 정보가 없습니다.");
            return;
        }
        btncnt = noCLick(btnlist,MC_ID);
        
        if(btncnt > 0)
        {
            alert("해당 캐릭터에 이미 투표하셨습니다.");
            return;
        }
        
        var okclick = confirm(MC_NM+"을 투표하시겠습니까?");
        
        if(okclick)
        {
            CharacterVote(MC_ID);
            this.location.reload();
            //window.opener.location.reload();
			
            //eval("cha_"+MC_ID).innerHTML = MC_CNT + 1;
            //eval("cha2_"+MC_ID).innerHTML = MC_TOT + 1;
            //btnlist = btnlist +"|"+ MC_ID +"^";  
        }
    }
    
    function resultCharacterVote_CallBack(res)
    {
        rtchvote_Obj =  res.value;
        rtchvote_Rtn =  res;
        
        setTimeout('ViewCharacter_Vote_Result()',100);
    } 
    
    function ViewCharacter_Vote_Result()
    {
         var ds = rtchvote_Obj;
        // DataSet 오브젝트를 취득        
        if (ds != null && typeof(ds) == "object" ) // NULL 체크 * ds or dt 구분 필요
        { 
          if(ds.Rows.length>0) // 행 갯수분 루프
           {
               alert(ds.Rows[0].ERRMSG);
           }  
        } 
        else {
 
             alert(rtchvote_Rtn.request.responseText+"");
        }
    } 
    
    //투표를 두번 했는지 체크하는 메소드//
    function noCLick(btnlist,MC_ID)
    {
        var returnarr = null;
        var returnUrl = "";
        var cnt = 0;
        var com1 = "";
        var com2 = "";
	    if (btnlist.indexOf("^") >= 0){
	        var tmpparam1 = btnlist.split("^");
	        for(var i = 0 ; i<tmpparam1.length-1;i++)
	        {
	            if(tmpparam1[i] != '')
	            { 
	                com1 = MC_ID;
	                com2 = getBtnList(tmpparam1[i]);;
	                if(com1 == com2)
	                    {
	                        cnt = cnt+1;
                        }
	            }   
	        }
	    }
	    return cnt;
    }
    
    function getBtnList(tmpparam)
    {
        var tmpArr = null;
        var reStr = "";
        tmpArr = tmpparam.split("|");
        reStr = tmpArr[1];
        return reStr;
    } 
    //투표체크하는 메소드 끝//
    
//-----------------캐릭터 정보 출력-------------------//
    function ViewCharacter_Vote_CallBack(res)
    {      
        chvote_Obj =  res.value;
        chvote_Rtn =  res;
        setTimeout('ViewCharacter_Vote_info()',100);
    }
    
    function ViewCharacter_Vote_info()
    {      
         var ds = chvote_Obj;
        // DataSet 오브젝트를 취득        
        if (ds != null && typeof(ds) == "object" ) // NULL 체크 * ds or dt 구분 필요
        { 
            var tbl     = document.all["vote_main"];
            var tbl2     = document.all["char_title"];
              
            deleteRow(tbl); // Table의 Row를 초기화한다.
            AddCharacter_VoteRows(tbl,ds);    // Table의 Data를 Bind 한다.
            deleteRow(tbl2);
            AddCharacter_TitleRows(tbl2,ds);
        } 
        else {
             alert(chvote_Rtn.request.responseText+"");
        }
    }
    
    function AddCharacter_VoteRows(obj,ds) 
    { 
        var tbl = null; 
        var tbltd = null; 
        var dtstring = "";
        var timg = "";
        var ctimg = "";
        var tmPER_NM = "";
        if(ds.Rows.length>0) // 행 갯수분 루프
           {    
            tbl = obj.insertRow();
            tbltd = tbl.insertCell(0);
            dtstring = dtstring
                    +"<table width='560'>"
                    +"<!-- loop -->"
                    +"<tr> "
                    ;
            for (var i = 0; i < ds.Rows.length; i++) {
                    timg = IMG_MOVIE_PATH+ds.Rows[i].IMAGE; 
                    ctimg = rounding(timg,'H100','#');
                    tmPER_NM = ds.Rows[i].PER_NM;
                    if(ds.Rows[i].PER_NM != '')
                    {
                        tmPER_NM = ds.Rows[i].PER_NM;
                    }
                    dtstring = dtstring
                            +"<td width='280' class='vtop'>"
                            +"<!-- pic 내용 -->"
                            +"<table width='265'>"
                            +"<tr> "
                            +"<td width='99' style='padding:0 0 0 0;'>"+ctimg
                            +"<br> "
                            +"<a href=\"javascript:CVote('"+ds.Rows[i].MC_ID+"','"+ds.Rows[i].MC_NM+"');\"><img src='"+Image_PATH+"/images/btn/btn_vote02.gif' alt='투표하기' align='absmiddle' style='margin:5px 0 0 20px;'></a> "
                            +"</td>"
                            +"<td width='166' class='vtop'>"
                            +"<ul> "
                            +"<li class='f14 f_b01 bold ls' style='padding:3px 0 0 0;'>"
                            +"<a href='#' class='f14 f_b01 bold'>"+ds.Rows[i].MC_NM+", "+ds.Rows[i].M_NM+"</a> "
                            +"</li>"
                            +"<li class='f12 bold' style='padding:2px 0 2px 0;'> "
                            +tmPER_NM+" "
                            +"</li>"
                            +"<li class='f11' style='padding:4px 0 0 0;'>"
                            +ds.Rows[i].REMARK+" "
                            +"</li>"
                            +"</ul>"
                            +"</td>"
                            +"</tr>"
                            +"</table> "
                            +"<!-- // pic 내용 --> "
                            +"</td>"
                            ;  
                    if((i%2 == 1)||((i+1) ==  ds.Rows.length))
                    {
                        dtstring = dtstring
                                +"</tr>"
                                +"<tr> "
                                +"<td colspan='2' height='15'></td>"
                                +"</tr>" 
                        ;
                    }   
            }
            dtstring = dtstring 

                    +"<!-- // list loop -->"
                    +"</table> "
                    ;     
            tbltd.innerHTML = dtstring;       
         }      	  
    }
    
    function AddCharacter_TitleRows(obj,ds) 
    { 
        var tbl = null; 
        var tbltd = null; 
        var dtstring = "";
        if(ds.Rows.length>0) // 행 갯수분 루프
           {    
                tbl = obj.insertRow();
                tbltd = tbl.insertCell(0);
                dtstring = dtstring
				         +"<table width='580'>"
				         +"<tr>"
					     +"<td class='f14 bold' style=\"height:23px;color:#ffffff;padding:2px 0 0 10px;background: url('"+Image_PATH+"/images/popup/popup_box04_bg01.gif') no-repeat left top;\">"+ds.Rows[0].M_NM+"을 빛낸 등장인물들 </td>"
				         +"</tr>"
				         +"<tr>"
					     +"<td height='10'></td>"
				         +"</tr>"
				         +"</table>"
				         ;
				tbltd.innerHTML = dtstring;  
            } 
    }      	  
    
    //----------------캐릭터 정보 출력 끝------------------//
