var JOINS_TV_ROOT_DOMAIN = "http://tv.joins.com";

//¹Ìµð¾îÇÃ·¹ÀÌ¾î
function fn_InsertShowCasePlayer(playerName, width, height, control)
{
	var strWidth = "430";
	var strHeight = "381";
	var strControl = true;

	if(width)
		strWidth = width;

	if(height)
		strHeight = height;

	if(control == false)
		strControl = "none";
	else
		strControl = "full";

	try
	{
		//document.write("<script src=http://provider-cdn.ntomap.com/js.mpx/joins/inventory@pre-default></script\>"); //³ëÃâÅÂ±×ÀÔ´Ï´Ù.
		document.write("<object id=\"" + playerName + "\" name=\"" + playerName + "\" width=\"" + strWidth + "\" height=\"" + strHeight + "\" classid=\"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6\" type=\"application/x-mplayer2\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715,\">");
		//document.write("<param name=\"URL\" value=\"\">");
		//document.write("<param name=\"FileName\" value=\"\">");
		document.write("<param name=\"AutoStart\" value=\"0\">");
		document.write("<param name=\"ShowStatusBar\" value=\"0\">");
		document.write("<param name=\"ShowControls\" value=\"0\">");
		document.write("<param name=\"enableContextMenu\" value=\"0\">");
		document.write("<param name=\"uiMode\" value=\"" + strControl + "\">");
		document.write("<param name=\"stretchToFit\" value=\"0\">");
		document.write("<param name=\"FullScreen\" value=\"0\">");
		document.write("<param name=\"DisplayBackcolor\" value=\"1\">");
		document.write("</object>");
	}
	catch(exception){alert(e.message);}
}



//¿µ»óÁ¤º¸ °¡Á®¿À±â
function fn_GetMovieInfo(movieID)
{
	var strGetMovieInfoUrl = "";
	var strXmlHttpResult = "";
	var strMovieInfoXml = "";
	var domMovieInfo = null;

	try
	{
		//±â»çÁ¤º¸¸¦ ¹Þ¾Æ¿Â´Ù.
		strGetMovieInfoUrl = "/_tv_module/GetMovieInfo.asp?movieID=" + movieID;
		strMovieInfoXml = fn_GetXmlHttpDocument(strGetMovieInfoUrl, "text", "post", null);
		if(strMovieInfoXml != "" && strMovieInfoXml != "false")
		{
			domMovieInfo = fn_XmlToJsonObject(strMovieInfoXml);
			/*<root>				<item>					<mov_id>,<mov_title>,<mov_regdate>,<mov_url>,<mov_cnt>,<mov_reccnt>,<mov_recsum>,<mov_runtime>,<mov_adult>,<mov_offertype>,<mov_credit>,<mov_content>,<mov_adult>,<mve_content_eng>,<mov_status>,<mve_player_script>,<mov_makid>,<mov_img>,<mov_star_count>,<mov_offer_type_name>,<mov_category>,<mov_tag>,<mov_makid>
				</item>
			</root>*/
			return domMovieInfo;
		}
		else
		{
			alert("¿µ»ó Á¤º¸ Á¶È¸Áß ¿¡·¯°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.");
			return null;
		}
	}
	catch(exception){alert(exception.description);}
}

//playerÆäÀÌÁö ÇÃ·¹ÀÌ¾î ¼³¸í ÆË¾÷·¹ÀÌ¾î
function gn_help_tooltip(d_id)
{
	document.getElementById(d_id).style.display = (document.getElementById(d_id).style.display == "none") ? "block" : "none";
}

//ÄíÅ° ¼³Á¤
function fn_SetCookie(name, value, expires, path, domain, secure)
{
	var strCurCookie = "";	
	try
	{
		strCurCookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

		if (!caution || (name + "=" + escape(value)).length <= 4000)
			document.cookie = strCurCookie;
		else
			if (confirm("Cookie exceeds 4KB and will be cut!"))
				document.cookie = strCurCookie;
	}
	catch(exception){}
}

//ÄíÅ° °¡Á®¿À±â
function fn_GetCookie(name)
{
	var strPrefix = "";
	var nCookieStartIndex = -1;
	var nCookieEndIndex = -1;
	
	try
	{
		strPrefix = name + "=";
		nCookieStartIndex = document.cookie.indexOf(strPrefix);
		
		if (nCookieStartIndex == -1)
			return null;
			
		nCookieEndIndex = document.cookie.indexOf(";", nCookieStartIndex + strPrefix.length);
		
		if (nCookieEndIndex == -1)
			nCookieEndIndex = document.cookie.length;
		
		return unescape(document.cookie.substring(nCookieStartIndex + strPrefix.length, nCookieEndIndex));
	}
	catch(exception){}
}

//ÄíÅ° °¡Á®¿À±â(TVÄíÅ°¸¸)
function gfn_GetCookie(name)
{
	var strPrefix = "";
	var nCookieStartIndex = -1;
	var nCookieEndIndex = -1;
	var tolcookie =sfn_GetCookie(name);
	//alert("tolcookie="+tolcookie);
	try
	{
		strPrefix = name + "=";
		nCookieStartIndex = tolcookie.indexOf(strPrefix);
		
		if (nCookieStartIndex == -1)
			return null;
			
		nCookieEndIndex = tolcookie.indexOf(";", nCookieStartIndex + strPrefix.length);
		
		if (nCookieEndIndex == -1)
			nCookieEndIndex = tolcookie.length;
		
		return unescape(tolcookie.substring(nCookieStartIndex + strPrefix.length, nCookieEndIndex));
	}
	catch(exception){}
}


var allcookie =document.cookie;
//ÄíÅ° Á¦°Å(TvÄíÅ°¾Æ´Ñ°Å Á¦°Å)
function sfn_GetCookie(name)
{
	var strPrefix = "";
	var nCookieStartIndex = -1;
	var nCookieEndIndex = -1;		
	var runExit = 0;
	var strcookie ="";
	
	name2 ="_MemArray";	
	try
	{				
		strPrefix = name2 + "=";
		nCookieStartIndex = allcookie.indexOf(strPrefix);		
		if (nCookieStartIndex == -1)
			return allcookie;
			
		nCookieEndIndex = allcookie.indexOf(";", nCookieStartIndex + strPrefix.length);
		
		if (nCookieEndIndex == -1)
			nCookieEndIndex = allcookie.length;
				
		strcookie = allcookie.substring(nCookieStartIndex + strPrefix.length, nCookieEndIndex);
		if(strcookie !="" && strcookie !="undefined" && allcookie !=null)
		       runExit =1;
		else   runExit =0;		  		
		
		allcookie = allcookie.replace(strcookie,"");
		allcookie = allcookie.replace("Patzzi_MemArray=;","");
		//alert("allcookie="+allcookie);
		//if(runExit ==0)		
	 	return allcookie;
	  //else sfn_GetCookie(name2);
	}
	catch(exception){}
}


//ÄíÅ°¿­ Áß¿¡ uName2ÀÇ °ªÀ» ±¸ÇÑ´Ù 
function fn_GetCookie2(uName,uName2)
{
	var strReturnValue = "";
	var strString = "";
	var nFlag = -1;
	var nEnd = -1;
	try
	{
		if(uName=="MemArray")
		{ strString = gfn_GetCookie(uName);			
		}
		else 
		{ strString = fn_GetCookie(uName);			
		}				
		nFlag = strString.indexOf(uName2+'=');
		
		if (nFlag != -1) 
		{ 
			nFlag += uName2.length + 1
			nEnd = strString.indexOf('&', nFlag) 

			if (nEnd == -1) 
				nEnd = strString.length;

			strReturnValue = unescape(strString.substring(nFlag, nEnd));
		}
		else
		{
			strReturnValue = "";
		}
		
		return strReturnValue;
	}
	catch(exception){}
}

//Äí±â°ª Ãß°¡
function fn_CookieAdd(name,value)
{
	try
	{
		fn_SetCookie(name,value, 0,"/","");
	}
	catch(exception){}
}

function fn_deleteCookie( cookieName )
{
    var expireDate = new Date();

    //¾îÁ¦ ³¯Â¥¸¦ ÄíÅ° ¼Ò¸ê ³¯Â¥·Î ¼³Á¤ÇÑ´Ù.
    expireDate.setDate( expireDate.getDate() - 1 );
    document.cookie = cookieName + "= " + "; expires=" + expireDate.toGMTString() + "; path=/ ; domain="+_tv_cookie_domain;
}



function getTitleLimit(title, maxNum) {

    var tLen =title.length;
    var count = 0;  
    var c;
    var s=0;
    
    for(s=0;s<tLen;s++) {      
        c = title.charAt(s);
          if(count > maxNum){
            break;
          }
          
          if(c>127) count +=2;
          else count ++;
    }     
    return (tLen >s)? title.substring(0,s)+"..." : title;
}



function fn_ChackAdult()
	{
		var blnCheckAdult = false;
		try
		{	
			//·Î±×ÀÎ»óÅÂ
			//if (fn_GetCookie("MemArray"))
			if (getCookie4gn("Joins_ValidLogin") == "True")
			{
				// Login »óÅÂ
				if(fn_GetCookie2("MemArray","adult") == "Y")
				{
					blnCheckAdult = true;
				}
				else
				{
					blnCheckAdult = false;
				}
			}
			else
			{
				if (fn_GetCookie("adult%5FYN") == "Y")  // fn_GetCookie("adult%5FYN") == "Y"
				{
					blnCheckAdult = true;
				}
				else
				{
					blnCheckAdult = false;
				}
			}
			return blnCheckAdult;
		}
		catch(exception){return false;}
	}

/*****************************************************************************************************************

	¿À´Ã º» ¿µ»ó ¿ìÃø È÷½ºÅä¸® °ü·Ã ½ÃÀÛ

******************************************************************************************************************/

var _tv_cookie_domain = document.location.host;




//µ¿¿µ»ó È÷½ºÅä¸® ¼³Á¤
function setMovieHistory(mov_id, mov_title, mov_image) 
{

	try
	{	// ±æÀÌ¹®Á¦·Î Å¸ÀÌÆ² »­
		
		viewlist = getCookie4gn("TV_ViewList");
		
		if (viewlist.indexOf(mov_id) == -1)
		{
			arrView = viewlist.split("|");
			arrView.unshift(mov_id+"#"+mov_image);
			
			var totalcnt = arrView.length;
			if (totalcnt > 5) totalcnt = 5;
			newViewList  = "";
			for(i=0;i<totalcnt;i++){
				if(i>0) newViewList = newViewList+"|";
				newViewList = newViewList+arrView[i];
				
			}
			
			setCookie4gn("TV_ViewList", newViewList, _tv_cookie_domain, 1);

		}
		

	}
	catch(exception)
	{
		alert(exception.description);
	}
}


// µ¿¿µ»ó È÷½ºÅä¸® ÃÊ±âÈ­
function clearMovieHistory(){
	
		setCookie4gn("TV_ViewList", "", _tv_cookie_domain, 1);
		if($("#tVM")){
			$("#tVM").text("");		
		}		
	
} 


//µ¿¿µ»ó È÷½ºÅä¸® ¸®½ºÆ® °¡Á®¿À±â
function getMovieHistoryList()
{

			viewlist = getCookie4gn("TV_ViewList");
			arrView = viewlist.split("|");
			strHistory = "";
			var totalcnt = arrView.length;
			if (totalcnt > 5) totalcnt = 5;
			for(i=0;i<totalcnt;i++){
				viewItem = arrView[i];
				arrItem = viewItem.split("#");
				if(arrItem.length > 1){
					mov_id = arrItem[0];
					mov_img = arrItem[1];
					
					strHistory = strHistory + "<li id=\"hl_"+mov_id+"\" >";
					strHistory = strHistory + "<img src=\""+mov_img+"\" onfocus=\"blur();\" style=\"cursor:hand;text-align:center;\"  border=\"0\" width=\"70\" height=\"52\"  onclick=\"javascript:play_player_movie_list('"+mov_id+"', 'bottom');\" >";
					strHistory = strHistory + "</li>";

				}

			}

			if($("#tVM")){
				$("#tVM").html(strHistory);		
			}	

}

function play_player_movie_list(movid, target)
	{
		ifrmPlayer = document.getElementById("ifrmPlayer");
		
		if(!ifrmPlayer) { self.location.replace("/channel/tv_player.asp?mov_id=" + movid); return;}
		if(!ifrmPlayer.play_player_movie) { self.location.replace("/channel/tv_player.asp?mov_id=" + movid); return;}

		ifrmPlayer.play_player_movie(movid, target);
	}