

var oBrand = {
	loadBrand : function() {
		eventMake.onclick('leftChInfoTab', function() {

			for (i=0,ii=document.getElementsByName(this.getAttribute("name")).length ;i<ii ;i++ ) {
				if (this==document.getElementsByName(this.getAttribute("name"))[i]) {
					document.getElementsByName(this.getAttribute("name"))[i].className = "on";
					document.getElementsByName("leftChInfoTab_s")[i].style.display = "";
				}else {
					document.getElementsByName(this.getAttribute("name"))[i].className = "off";
					document.getElementsByName("leftChInfoTab_s")[i].style.display = "none";
				}
			}
		}, "name");
		eventMake.onclick("outBrandChannel", function() {oBrand.joinBrand("out")});
		eventMake.onclick("joinBrandChannel", function(){oBrand.joinBrand("join")});
		//eventMake.onclick("joinBrandChannel", functIon(){oCtlJs.buyMovie(this.flvPrgid, "F")});
		eventMake.onclick("joinFixedPrice", function(){oCtlJs.buyMovie(0, "F")});
		try{
			if(document.getElementById("live_plist").style.display=="") document.getElementById("joinFixedPrice").onclick = function() {buyLive()};
		}catch(e){}
		eventMake.onclick("bCLView", function(){oBrand.brandLists() });
		eventMake.onclick("bCLViewTop", function(){oBrand.brandLists() });
	},

	brandLists : function () {
		if (document.getElementById("brandchList").style.display == "") {
			document.getElementById("brandchList").style.display = "none";
		}else {
			document.getElementById("brandchList").style.display = "";
			if (!document.getElementById("bcl").src) {
				document.getElementById("bcl").src = "/_lib/brandChannelList.ptv";
			}
		}
	},

	joinBrand : function (opt) {
		if (!oCookie.get("glb_mem[userid]")) {
			if (confirm(JS_BL[0]+" "+JS_BL[1]))
				chLogin();
			return false;
		}
		if (opt=="join") {
			if (!confirm(JS_BL[2])) {return false;}
			msg = JS_BL[3];
			act = "Join";
		} else if (opt=="joinAuto") {
			act = "Join";
		} else if (opt=="out") {
			if (!confirm(JS_BL[4])) {return false;}
			msg = JS_BL[5];
			act = "Out";
		}
		new AJAX({
			sync : false,
			method : "post",
			url : '/json/v003/GAccount.dll/'+act,
			arequest : encodeURIComponent('json={"ch_userid": "'+CH_ID+'", "login_userid": "'+oCookie.get("glb_mem[userid]")+'"}'),
			rfunction : function (q) {
				eval("returnQuery = "+q);
				if (returnQuery.IsRes>0) {
					if (opt!="joinAuto")
						alert(msg);
					location.href='/my.'+CH_ID;
				}else {
				}
			}
		});
	}
}


var eventMake = {
	onclick : function (oName, runFun, opt) {
		return this.eventLoad.loadDocment(oName, runFun, 'onclick', opt);
	},

	eventLoad : {
		loadDocment : function (oName, runFun, evt, opt) {
			if (opt == "name") {
				var obj = document.getElementsByName(oName);
				for (i=0, ii=obj.length;i<ii ;i++ ) {
					this.loadEvent(obj[i], runFun, evt);
				}
			} else {
				this.loadEvent(document.getElementById(oName), runFun, evt);
			}
		},
		loadEvent : function (obj, runFun, evt) {
			var rtn = true;
			try {
				eval("obj."+evt+" = runFun");
				rtn = true;
			} catch (e) { rtn = false; }
			finally { obj = null; return rtn;}
		}
	}
}

var freeMake = {
	fixed_data : ""
	,live_data : ""
	,tabs : ""
	,arr_freeDays : new Array("1", "7", "30", "90", "180", "365")
	,set_fixPay : function(fType) {
		
		payCnt = 1;
		if(fType=="vod") {

			if(this.tabs=="on") document.getElementById("freeTab").innerHTML = "<a href='javascript:freeMake.set_fixPay(\"vod\")'><strong>VOD 정액권</strong></a> | <a href='javascript:freeMake.set_fixPay(\"live\")'>라이브 정액권</a>";
			
			for(var i=0, len=this.fixed_data.price.length; i < len; i++) {
				plist = document.getElementById("pay0"+payCnt);
				plist.innerHTML = "";
				plist.style.display = "none";
				if(this.fixed_data.price[i] < 1) continue;				
				
				plist.innerHTML = "<span>"+this.number_format(this.fixed_data.price[i])+"원</span><input type='radio'  name='freePrice' value='freePrice0"+(i+1)+"'  /> "+this.arr_freeDays[i]+"일";
				plist.style.display = "";
				
				payCnt++;
			}

			document.getElementById("joinFixedPrice").onclick = function() {oCtlJs.buyMovie(0, "F")};
		} else {
			if(this.tabs=="on") document.getElementById("freeTab").innerHTML = "<a href='javascript:freeMake.set_fixPay(\"vod\")'>VOD 정액권</a> | <a href='javascript:freeMake.set_fixPay(\"live\")'><strong>라이브 정액권</strong></a>";

			for(var i=0, len=this.live_data.price.length; i < len; i++) {
				plist = document.getElementById("pay0"+payCnt);
				plist.innerHTML = "";
				plist.style.display = "none";
				if(this.live_data.price[i] < 1) continue;

				plist.innerHTML = "<span>"+this.number_format(this.live_data.price[i])+"원</span><input type='radio'  name='freePrice' value='freePrice0"+i+"'  /> "+this.arr_freeDays[i]+"일";
				plist.style.display = "";
				
				payCnt++;
			}

			document.getElementById("joinFixedPrice").onclick = function() {buyLive()};
		}

		if(payCnt==1) {
			try{
				document.getElementById("joinFixedPrice").style.display = "none";
			}catch(e){}
		}
	}

	,number_format : function(str) {
		var tmp = '';
        var number = '';
        var cutlen = 3;
        var comma = ',';
        var i;
      
        len = str.length;
        mod = (len % cutlen);
        k = cutlen - mod;
        for (i=0; i<str.length; i++)
        {
            number = number + str.charAt(i);
           
            if (i < str.length - 1)
            {
                k++;
                if ((k % cutlen) == 0)
                {
                    number = number + comma;
                    k = 0;
                }
            }
        }

        return number;
	}
}


function popWin(u, n, w, h, o) {

	Top  = (window.screen.availHeight - parseInt(h)) / 2;
	Left = (window.screen.availWidth - parseInt(w)) / 2;
	popOption = "width="+w+", height="+h+", left="+Left+", top="+Top;
	win = window.open(u, n,popOption);
	win.focus();
}

function ToggleDiv(Objid, act)
{
	var Obj = document.getElementById(Objid);
	if (act == "on")
		Obj.style.display = "";
	else
		Obj.style.display = "none";
}

function mentFrameSet(prgid)
{
	ToggleDiv('reply', 'off');
	document.getElementById("mentFrame").src = "/IncludePHP/mentList.ptv?ch_userid="+CH_ID+"&prgid="+prgid;
}

function listAjax(u, p, tg)
{
	new AJAX(
	{
		sync : false,
		method : "POST",
		url : u,
		arequest : p,
		rfunction : function (q) {document.getElementById(tg).innerHTML = q;}
	});
}



function aBold(aname, afocus)
{
	for (i=0;i<document.getElementsByName(aname).length ;i++ )
		document.getElementsByName(aname)[i].style.fontWeight = "";
	afocus.style.fontWeight = "bold";
}

function aBold2(aname, iname)
{
	for (i=0;i<document.getElementsByName(aname).length ;i++ )
	{
		if (iname==document.getElementsByName(aname)[i].getAttribute("cateCode"))
			document.getElementsByName(aname)[i].style.fontWeight = "bold";
		else
			document.getElementsByName(aname)[i].style.fontWeight = "";
	}
}



function reSizeiFrm(iFrmName)
{
	try
	{
		var objFrm = document.getElementById(iFrmName);

		if(document.all) var objBody = frames[iFrmName].document.body;
		else  var objBody= objFrm.contentDocument.body;
		ifrmHeight = objBody.scrollHeight;// + (objBody.offsetHeight - objBody.clientHeight);
		objFrm.height=ifrmHeight;
	}
	catch (e) {}
}



function reSizeChild()
{
	reSizeiFrm("brandbbsFrm");
}



function brandbbs(url)
{
	try
	{
		document.getElementById("brandbbsFrm").src = url;
	}
	catch (e)
	{
		var q = '<iframe name="brandbbsFrm" id="brandbbsFrm" src="'+url+'" width="100%" scrolling="no" frameborder=0 allowTransparency="true" onLoad="reSizeiFrm(this.id)"></iframe>';
		document.getElementById('main').innerHTML = q;
	}
}



function mentListView(a, b)
{
	document.getElementById('mentViewNum').innerHTML = a;
	rollUrl= "";
	Roll.set("mentViewText", b, rollUrl, 280, 15, 10, 2000, 1);
}


function closeDiv(did)
{
	document.getElementById(did).style.display='none';
}

function buyLive() {
	popWin("/live/buyLive.ptv?ch_userid="+CH_ID, "liveBuy", 390, 440);
}

function set_fixPay(fType, name) {
	
	if(fType=="vod") {
		document.getElementById("freeTab").innerHTML = "<a href='javascript:set_fixPay(\"vod\", \""+name+"\")'><strong>VOD"+name+"</strong></a> | <a href='javascript:set_fixPay(\"live\", \""+name+"\")'>라이브"+name+"</a>";

		document.getElementById("fixed_plist").style.display = "";
		document.getElementById("live_plist").style.display = "none";

		document.getElementById("joinFixedPrice").onclick = function() {oCtlJs.buyMovie(0, "F")};
	} else {
		document.getElementById("freeTab").innerHTML = "<a href='javascript:set_fixPay(\"vod\", \""+name+"\")'>VOD"+name+"</a> | <a href='javascript:set_fixPay(\"live\", \""+name+"\")'><strong>라이브"+name+"</strong></a>";

		document.getElementById("live_plist").style.display = "";
		document.getElementById("fixed_plist").style.display = "none";
		//document.getElementById("live_plist").style.display = "block";

		document.getElementById("joinFixedPrice").onclick = function() {buyLive()};
	}

	/*
	if(fType=="vod") {
		document.getElementById("freeTab").innerHTML = "<a href='javascript:set_fixPay(\"vod\", \""+name+"\")'><strong>VOD"+name+"</strong></a> | <a href='javascript:set_fixPay(\"live\", \""+name+"\")'>라이브"+name+"</a>";

		document.getElementById("pay_list").innerHTML = document.getElementById("fixed_plist").innerHTML;

		document.getElementById("joinFixedPrice").onclick = function() {oCtlJs.buyMovie(0, "F")};
	} else {
		document.getElementById("freeTab").innerHTML = "<a href='javascript:set_fixPay(\"vod\", \""+name+"\")'>VOD"+name+"</a> | <a href='javascript:set_fixPay(\"live\", \""+name+"\")'><strong>라이브"+name+"</strong></a>";
alert(document.getElementById("live_plist").innerHTML);
alert(document.getElementById("pay_list"));
		document.getElementById("pay_list").innerHTML = document.getElementById("live_plist").innerHTML;
alert(document.getElementById("pay_list").innerHTML);

		document.getElementById("joinFixedPrice").onclick = function() {buyLive()};
	}*/
}