﻿var getFFVersion  = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
var FFextraHeight = parseFloat(getFFVersion) >= 0.1 ? 16 : 0;

var hid_evtNo;
var hid_evtRcpStTyp;
var hid_evtRcpPsblYn;
var hid_evtJoinYn;
var hid_evtAplyYn;

var hid_won;
var hid_usd;
var hid_sgd;
var hid_prodCd;
var hid_prodChgSeq;
var hid_prodNmEn;

// 이벤트 보기////////////////////////////////////////////////////
var js_event =
{
    EventInit:function(mode,com,evtNo,RcpStTyp,RcpPsblYn,joinYn,aplyYn,nowPayYn)
    {
    	hid_evtNo			= evtNo;
		hid_evtRcpStTyp		= RcpStTyp;
		hid_evtRcpPsblYn	= RcpPsblYn;
		hid_evtJoinYn		= joinYn;
		hid_evtAplyYn		= aplyYn;

        var f = document.frm ;

		f.txt_event_no.value 		= evtNo;
		f.hid_evt_rcp_st_typ.value 	= RcpStTyp;
		f.hid_evt_rcp_psbl_yn.value = RcpPsblYn;
		f.hid_evt_Join_yn.value 	= joinYn;
		f.hid_evt_Aply_yn.value 	= aplyYn;
		f.txt_now_pay_yn.value 		= nowPayYn;

		//이벤트기간
		if(hid_evtRcpPsblYn == "N") {
			alert(Message.getMessage("MSG00215"));

			return;
		}
		//로그인여부
		if(js_vg_login_id == ""){
			event_common.goLogin('/singles-events/matching-events-view.asp');
			return;
		}
		//기참가여부([승인]상태 아닐시)
		if(hid_evtRcpStTyp != "20")
		{
			if(hid_evtJoinYn == "Y"){
				alert(Message.getMessage("MSG00214"));

				return;
			}
		}
		//회원미만 제한
		if(js_vg_mbr_typ != "03")
		{
			if(confirm(Message.getMessage("MSG00683"))){
		        event_common.goMbrJoin();
		    }
		    return;
		}
		//참가조건
		if(hid_evtAplyYn == "N"){
			alert(Message.getMessage("MSG00322"));
			return;
		}

		if (mode == "APLY" ) {
			//event_offline.specialAccept();
			event_common.specialAccept();
		}
		else if (mode == "PAY" && (com == "KCP"||com == "AUTH"|| com == "eNET"))	{
			//event_offline.specialBuy('KCP');
			event_common.specialBuy(com);
		}
		else if (mode == "PAY" && com == "PAYPAL")	{
			event_common.specialBuy('PAYPAL');
		}
		else if(mode == "PAY" && com == "PAYPAL_ENET"){
		    event_common.specialBuy('PAYPAL_ENET');
		}
		else {
			alert(Message.getMessage("MSG00430"));
		}

    }
}


//공통 //////////////////////////////////////////////////////////////////////////////
var event_common =
{
	//공통_ 전역변수 값 설정
	init:function() {

		var f = document.frm;

		//hid_evtNo			= f.txt_event_no.value;
		//hid_evtRcpStTyp		= f.hid_evt_rcp_st_typ.value;
		//hid_evtRcpPsblYn	= f.hid_evt_rcp_psbl_yn.value;
		//hid_evtJoinYn		= f.hid_evt_Join_yn.value;
		//hid_evtAplyYn		= f.hid_evt_Aply_yn.value;

		hid_won			= f.hid_won.value;
		hid_usd			= f.hid_usd.value;
		hid_sgd			= f.hid_sgd.value;
		hid_prodCd		= f.hid_prod_cd.value;
		hid_prodChgSeq	= f.hid_prod_chg_seq.value;
		hid_prodNmEn	= f.hid_prod_nm_en.value;

	},

	//공통_ 파일 다운
	fileDown:function(param1,param2,param3) {
		var f = document.frm;

		f.method = "post";
		f.target = "_self";
		f.action = "/common/fileDown.asp?param1="+param1+"&param2="+param2+"&param3="+param3;
		f.submit();
	},

	//공통_ 이벤트 로그인페이지가기
	goLogin:function(curUrl)
	{
		var selfUrl = location.href;
		var param = "{QUESTION}"+selfUrl.substring(selfUrl.indexOf(".asp?")+5);
		param = param.replace(/\&/gi,"{AND}");

		var rtnUrl = curUrl + param;
		//alert("/common/login_event.asp?rtnurl="+rtnUrl+"&evtno="+hid_evtNo+"&won="+hid_won+"&usd="+hid_usd);
		// location.href = "/common/login_event.asp?rtnurl="+rtnUrl+"&evtno="+hid_evtNo+"&won="+hid_won+"&usd="+hid_usd;
		//location.href = "/common/login.asp?rtnurl="+rtnUrl;
		Login_RtnUrl('');
	},

	//공통_ 리스트 이동
    goList:function(goUrl) {
  		var f = document.frm;
		var curPage = f.txt_curPage.value;

		location.href = goUrl + "?txt_curPage="+curPage;
    },

	//공통_ 클래스 변경하기
	setClass:function(obj,v_class) {
	    obj.className = v_class;
	},

	//공통_ 회원가입가기
	goMbrJoin:function() {
        location.href = "/join/questionnaires.asp";
    },

    //이벤트신청하기
    specialAccept:function()
	{
		if (confirm(Message.getMessage("MSG00206")) == false)
		{
        	return;
		}

		var f = document.frm ;

		f.amount.value			= f.hid_usd.value;

		f.method = "post";
		f.target = "if_special";
		f.action = "/singles-events/singles-events-view-proc.asp";
		f.submit();
	},

    specialBuy:function(com)
    {
    	var f = document.frm;
		var v_com = com;

        if(f.txt_now_pay_yn.value == "Y")
        {
            alert(Message.getMessage("MSG00503"));  //참가비를 결제하면 참가 신청이 완료됩니다.
        }

    	//var top  = screen.height/2 - 560/2
    	var top  = 0;
	    var left = screen.width/2 - 500/2
		//국내
	    var sFeatures = "top=" + top + ",left=" + left + ",width=440,height=560,scrollbars=no,menubar=no,status=no,resizable=no";
		//해외
	    var sFeatures2= "top=0"+ ",left=0" + ",width=950,height=900,scrollbars=yes,menubar=no,status=no,resizable=no";

        if(com=="eNET"){
            f.txt_pay_amt.value		= hid_sgd + ".00";
    		f.amount.value			= hid_sgd ;
    		f.txt_crrcy_gbn.value   = "SGDOLLAR";
        }
        else if(com=="PAYPAL_ENET"){
            f.txt_pay_amt.value		= hid_sgd + ".00";
    		f.amount.value			= hid_sgd ;
    		f.txt_crrcy_gbn.value   = "SGD";
        }
        else{
            f.txt_pay_amt.value		= hid_usd + ".00";
    		f.amount.value			= hid_usd ;
    		f.txt_crrcy_gbn.value   = "DOLLAR";
        }


		// 결제금액확인
		if(isEmpty(f.txt_pay_amt.value) || f.txt_pay_amt.value == "0.00") {
			alert(Message.getMessage("MSG00216"));
			return;
    	}

		//국내
		f.txt_paygate_gbn.value  = com;
	    f.txt_prod_cd.value      = hid_prodCd;
		f.txt_prod_chg_seq.value = hid_prodChgSeq;
    	f.txt_prod_cnt.value     = "1";
		f.txt_prod_nm.value	     = hid_prodNmEn;
	    f.txt_pay_amt.value		 = hid_usd;
	    f.txt_crrcy_gbn.value       = "DOLLAR";

		//해외
		f.item_number.value     = hid_prodCd;
		f.os0.value				= hid_prodChgSeq;
    	f.quantity.value		= "1";

		if( v_com=="KCP" || v_com=="AUTH")
		{
			window.open("", "popSettlement", sFeatures);

			f.method = "post";
			f.target = "popSettlement";
			f.action = "/payment/popSettlement.asp";
			f.submit();
		}
		else if(v_com=="eNET"){

            window.open("", "popSettlement", sFeatures);

            f.method = "post";
			f.target = "popSettlement";
			f.action = "/common/popSettlement_eNets.asp";
			f.submit();
		}
		else
		{
//		    alert("business="+f.business.value);
//		    alert("item_name="+f.item_name.value);
//		    alert("item_number="+f.item_number.value);
//		    alert("on0="+f.on0.value);
//		    alert("on1="+f.on1.value);
//		    alert("os0="+f.os0.value);
//		    alert("os1="+f.os1.value);
//		    alert("amount="+f.amount.value);
//		    alert("quantity="+f.quantity.value);
//		    alert("currency_code="+f.currency_code.value);
//		    alert("first_name="+f.first_name.value);
//		    alert("last_name="+f.last_name.value);



			window.open("", "online_evt", sFeatures2);

			f.method = "post";
			f.target = "online_evt";
			f.action = "http://www.paypal.com/cgi-bin/webscr";
			f.submit();
		}
    },

		//오프라인_ 서비처리후 결과 리턴
	specialAplyRslt:function(flag,msg,reUrl) {
        var f = document.frm;

        message(msg);

        if(flag == "True") {

			//회원가입가기
			if (js_vg_mbr_typ != "03")
			{
				event_common.goMbrJoin();
			}
			else
			{
				f.method = "post";
				f.target = "_self";
				f.action = "/singles-events/matching-events-view.asp?"+reUrl;
				f.submit();
			}
        }
    }

}
