﻿// 레뷰걸 이벤트 (EventNo1,EventNo2) 1차(1,2), 2차(3,4), 3차(5,6)로 나뉘어짐

var RevUGirl = {
    EventID : null,
    EventNo : 1,
    Times : 1, // 차수
    Availability : false,
    Join : function(EventNo) {
        if(!this.Availability) {
            alert('이벤트 기간이 아닙니다.');
            return;
        }
    
        var userid = User.UserUID();
        if(userid == null) {
            User.ShowLogin('RevUGirl.Join('+EventNo+')');
            return;
        }
    
        var Keyword = $('Keyword' + EventNo).value.trim();
        
        if(Keyword == '') {
            alert('내용을 입력해주세요');
            return;
        }
    
        var eventno = EventNo + (this.Times - 1) * 2; // 이벤트차수에 따른 실제 이벤트 넘버  
        if(EventNo == 2) {
            var chk = Event_RevUGirl2.CheckKeyword2(eventno, Keyword);
            if(chk && chk.value) {
                if(chk.value.ResultCode != 1) {
                    alert(chk.value.ReturnValue);
                    return;
                }
            }
            else {
                alert('오류가 발생하였습니다.');
                return;
            }
        }
        else if(EventNo == 1) {
            if(Keyword.match(/[\$\@\!\^\*\<\>\|\"\'\,\{\}\[\];]/) != null || Keyword.match(/\../) == null) {
                alert('올바른 URL이 아닙니다');
                return;
            }
            else {
                var chk = Event_RevUGirl2.CheckKeyword1(eventno, Keyword);
                if(chk && chk.value) {
                    if(chk.value.ResultCode != 1) {
                        alert(chk.value.ReturnValue);
                        return;
                    }
                }
                else {
                    alert('오류가 발생하였습니다.');
                    return;
                }         
            }
        }
    
        var result = AjaxEvent.JoinEvent(this.EventID, eventno, Keyword);
        
        if(result && result.value) {
            if(result.value.ResultCode == 1) $('Keyword' + EventNo).value = '';
            alert(result.value.ReturnValue);
        }
        else
            alert('알 수 없는 에러발생');
    },
    GetTalks : function(page) {
        Event_RevUGirl2.GetTalks(page, 10, 'Event_Talks', Util.AjaxCallback);
    },
    ShowCopy : function() {
        var y = Util.Y - 150;
        $('Event_Copy').setStyle({display:'inline',top:y+'px'});
    },
    ScrollTo : function(index) {
        if(index == 2) {
            window.scrollTo(0, document.body.clientHeight - 200);
        }
    },
    ShowFlash : function(url, width, height) {    
        var flash_tag = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
        flash_tag +='codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id="OhMyRevuGirl99028" ';
        flash_tag +='WIDTH="'+width+'" HEIGHT="'+height+'">';
        flash_tag +='<param name="movie" value="'+url+'">';
        flash_tag +='<param name="wmode" value="window"/>';
        flash_tag +='<param name="allowScriptAccess" value="always"/>';
        flash_tag +='<param name="allowFullScreen" value="true"/>';
        flash_tag +='<embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
        flash_tag +='type="application/x-shockwave-flash" wmode="window" WIDTH="'+width+'" HEIGHT="'+height+'" FlashVars="" allowScriptAccess="always" name="OhMyRevuGirl94023" id="OhMyRevuGirl94023" allowFullScreen="true"></embed></object>'

        document.write(flash_tag);
        
        /*var version = CheckFlash().flashVersion;
        
        if(version.match(/^10\.0\./) != null) {
            var v = version.match(/^10\.0\.(\d+)/);
            if(v != null && v.length > 0) {
                var vv = v[1].substring(0,2);
                if((Math.pow(10, 2-vv.length) * parseInt(vv)) < 22) {
                    if(confirm( "해당 Flash 버전에서는 정상 작동하지 않을 수 있습니다.\n최신버전을 다운받으시겠습니까?")) {
                        window.open("http://get.adobe.com/kr/flashplayer/");
                    }
                    return;
                }
            }
        }*/
    },
    Event1Status : function(page) {
        CtlRevUGirl2Status1.GetEventStatus(this.EventID, (this.Times - 1) * 2 + 1, page, 10, 'javascript:RevUGirl.Event1Status(%Page%)', 'Event_Applications', Util.AjaxCallback);
    },
    Event2Status : function(page) {
        CtlRevUGirl2Status2.GetEventStatus(this.EventID, (this.Times - 1) * 2 + 2, page, 45, 'Event_Applications', Util.AjaxCallback);
    },
    ShowStatus : function(index) {
        var userid = User.UserUID();
        if(userid == null) {
            User.ShowLogin('RevUGirl.ShowStatus(' + index + ')');
            return;
        }     
    
        var y = Util.Y - 150;
        $('Event_Applications').setStyle({display:'inline',top:y +'px',background:'url(/images/event/bg_revugirl2_event' + index + '.gif) no-repeat'});
        
        if(index == 1) 
            this.Event1Status(1);
        else if(index == 2)
            this.Event2Status(1);
           
    }
}



				
function CheckFlash() {
    /**
    * Derived from Apple's suggested sniffer.
    * @param {String} desc e.g. Shockwave Flash 7.0 r61
    * @return {String} 7.0.61
    */
    function getFlashVersion(desc) {
	    var matches = desc.match(/[\d]+/g);
        matches.length = 3;  // To standardize IE vs FF
        return matches.join('.');
    }

    var obj = {
        hasFlash : false,
        flashVersion : 'Unknown'
    }

    if (navigator.plugins && navigator.plugins.length) {
        var plugin = navigator.plugins['Shockwave Flash'];
        if (plugin) {
            obj.hasFlash = true;
            if (plugin.description) {
                obj.flashVersion = getFlashVersion(plugin.description);
            }
        }

        if (navigator.plugins['Shockwave Flash 2.0']) {
            obj.hasFlash = true;
            obj.flashVersion = '2.0.0.11';
        }

        } else if (navigator.mimeTypes && navigator.mimeTypes.length) {
            var mimeType = navigator.mimeTypes['application/x-shockwave-flash'];
            obj.hasFlash = mimeType && mimeType.enabledPlugin;
            if (hasFlash) {
                obj.flashVersion = getFlashVersion(mimeType.enabledPlugin.description);
            }
        } 
        else {
        try {
            // Try 7 first, since we know we can use GetVariable with it
            var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7');
            obj.hasFlash = true;
            obj.flashVersion = getFlashVersion(ax.GetVariable('$version'));
        } 
        catch (e) {
            // Try 6 next, some versions are known to crash with GetVariable calls
            try {
                var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
                obj.hasFlash = true;
                obj.flashVersion = '6.0.21';  // First public version of Flash 6
            } 
            catch (e) {
                try {
                    // Try the default activeX
                    var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
                    obj.hasFlash = true;
                    obj.flashVersion = getFlashVersion(ax.GetVariable('$version'));
                } catch (e) {
                        // No flash
                }
            }
        }
    }

    return obj;
}