function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function goMenu(Val,Sel)
{
	Sel.value = '';
	if (Val) location=Val;

}

function fnResizePopup(nWidth, nHeight)
{
	var strAgent = navigator.userAgent.toLowerCase();
	var bIE = (strAgent.indexOf("msie") != -1);
	var bXP = (strAgent.indexOf("nt 5.1") != -1);
	var bIE7 = (strAgent.indexOf("msie 7.0") != -1);
	var bSafari = (strAgent.indexOf("konqueror") != -1 || strAgent.indexOf("safari") != -1);
	var bFirefox = (strAgent.indexOf("firefox")!= -1);
	window.resizeTo(nWidth, nHeight + (bXP ? (bIE7 ? 40: 20) : 0));
}
//ÆË¾÷ - Áß¾ÓÀ§Ä¡
function PopWindow(url,target,intWidth,intHeight) {
	var posX = (screen.availWidth/2)-(intWidth/2);
	var posY = (screen.availHeight/2)-(intHeight/2);

	var winoption = "width="+intWidth+",height="+intHeight+",left="+posX+",top="+posY +",scrollbars=no,status=no,resizable=0";
	window.open(url, target, winoption);
	return;
}
/*
function Win_pop(newwin,w,h) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'width='+w+',height='+h+',top='+wint+',left='+winl+',resizable=no,scrollbars=no,status=no,menu=no';
win = window.open(newwin, "new1", winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
*/
// ÆäÀÌÁö focus blur
//function bluring(){
	//if (event.srcElement!=null) {
		//if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus();
	//}
//}
//document.onfocusin=bluring;

/* ÇÃ·¡½Ã */
function ObjFlash(src, width, height, param, addParam) {

	param = param || "";
	addParam = addParam || "";
	document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"" + width + "\" height=\"" + height + "\", id='flash'>");
	document.writeln("	<param name=\"movie\" value=\"" + src + "\">");
	document.writeln("	<param name=\"flashVars\" value=\"" + param + "\">");
	document.writeln("  <param name='allowScriptAccess' value='always' />");
	document.writeln("	<param name='quality' value='high' />");
//	document.writeln("	<param name='scale' value='noscale' />");
	document.writeln("	<param name='salign' value='lt' />");
	document.writeln("	<param name='bgcolor' value='#000000' />");
	document.writeln("	<param name='menu' value='false' />");
	document.writeln("	<param name='wmode' value='opaque' />");
	document.writeln("	<embed  bgcolor='#000000' wmode='opaque' src=\"" + src + "?" + param + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\"></embed>");
	document.writeln("</object>");
}

function ObjFlash_Tr(src, width, height, param, addParam) {//ÇÃ·¡½Ã Åõ¸í Ã³¸®
	param = param || "";
	addParam = addParam || "";
	document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"" + width + "\" height=\"" + height + "\">");
	document.writeln("	<param name=\"movie\" value=\"" + src + "\">");
	document.writeln("	<param name=\"flashVars\" value=\"" + param + "\">");
	document.writeln("  <param name='allowScriptAccess' value='always' />");
	document.writeln("	<param name='quality' value='high' />");
	document.writeln("	<param name='scale' value='noscale' />");
	document.writeln("	<param name='salign' value='lt' />");
	document.writeln("	<param name='bgcolor' value='#000000' />");
	document.writeln("	<param name='menu' value='true' />");
	document.writeln("	<param name='wmode' value='transparent' />");
	document.writeln("	<embed  bgcolor='#000000' wmode='transparent' src=\"" + src + "?" + param + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\"></embed>");
	document.writeln("</object>");
}

function ObjFlash_ID(src, id, width, height, param, addParam) {//ÇÃ·¡½Ã Åõ¸í Ã³¸®
	param = param || "";
	addParam = addParam || "";
	document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"" + id + "\">");
	document.writeln("	<param name=\"movie\" value=\"" + src + "\">");
	document.writeln("	<param name=\"flashVars\" value=\"" + param + "\">");
	document.writeln("  <param name='allowScriptAccess' value='always' />");
	document.writeln("	<param name='quality' value='high' />");
	document.writeln("	<param name='scale' value='noscale' />");
	document.writeln("	<param name='salign' value='lt' />");
	document.writeln("	<param name='bgcolor' value='#000000' />");
	document.writeln("	<param name='menu' value='true' />");
	document.writeln("	<param name='wmode' value='transparent' />");
	document.writeln("	<embed  bgcolor='#000000' wmode='transparent' src=\"" + src + "?" + param + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\" id=\"" + id + "\"></embed>");
	document.writeln("</object>");
}

function ShowhidenLayer(LayName) {
	obj = document.getElementById(LayName);
	// ÆîÄ¡±â
  if (obj.style.display == "none") {
      obj.style.display = "block";
  }
  else if (obj.style.display == "block") {
      obj.style.display = "none";
  }
}

function ShownLayer(LayName) {
	obj = document.getElementById(LayName);
	obj.style.display = "none";
	// ÆîÄ¡±â
  if (obj.style.display == "none") {
      obj.style.display = "block";
  }
  else if (obj.style.display == "block") {
      obj.style.display = "none";
  }
}

function HideLayer(LayName) {
	obj = document.getElementById(LayName);
  // ¼û±â±â
  obj.style.display = "none";
}


function getIEVersion(){
var agent  = navigator.userAgent;
var appver = navigator.appVersion;
var msie   = appver.indexOf("MSIE");
if(msie!=-1 && agent.indexOf("Win") != -1){
	return parseFloat(appver.substring(msie+4));
}
return -1;
}

function openRssLink(aEvent){
	var oLinker = aEvent ? aEvent : window.event;
	window.open(oLinker.innerHTML);
}

function copyRssLink(objLink){
	if(getIEVersion() > 0){
		document.getElementById(objLink).createTextRange().execCommand('copy');
		alert(document.getElementById(objLink).title + " RSS ÁÖ¼Ò°¡ º¹»ç µÇ¾ú½À´Ï´Ù.");
	}
	else{
		var str = document.getElementById(objLink).value;
		prompt("Ctrl+C¸¦ ´­·¯ º¹»çÇÏ¼¼¿ä.", str);
	} 
}

function copyRssLinkInfo(objLink, layerName){
	var oEvent;
	if(getIEVersion() > 0){
		document.getElementById(objLink).createTextRange().execCommand('copy');
		if(document.getElementById('RssMsg_pop'))	HideLayer('RssMsg_pop');
		if(document.getElementById('RssMsg_recom'))	HideLayer('RssMsg_recom');
		if(document.getElementById('RssMsg_best'))	HideLayer('RssMsg_best');
		RssMsgShow(layerName);
	}
	else{
		var str = document.getElementById(objLink).value;
		var presult = prompt("Ctrl+C¸¦ ´­·¯ º¹»çÇÏ¼¼¿ä.", str);

		if(presult == document.getElementById(objLink).value ) {
			RssMsgShow(layerName);
		}
	}

	if(objLink == "best_rss2")
		wiseLog.setWiseLog("QTV001_CTDL02_001");
	else if(objLink == "best_rss1")
		wiseLog.setWiseLog("QTV001_CTDL02_002");
	else if(objLink == "best_atom")
		wiseLog.setWiseLog("QTV001_CTDL02_003");
}


function RssMsgShow(layerName){
	if(document.getElementById('RssMsg_pop'))	HideLayer('RssMsg_pop');
	if(document.getElementById('RssMsg_recom'))	HideLayer('RssMsg_recom');
	if(document.getElementById('RssMsg_best'))	HideLayer('RssMsg_best');
	ShownLayer(layerName);	
}


function RssMsgClose(layerName){
	HideLayer(layerName);
}

// CSS ¹è°æÀÌ¹ÌÁö ³ªÅ¸³ªÁö ¾Ê´Â Çö»óÀ» ¹æÁö
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

function setPng24(obj) 
{
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,'');
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	obj.src='';
	return '';
}

function flashWiseLog(wiselogCode)
{
	wiseLog.setWiseLog(wiselogCode);
}

var wiseLog = {
	
	logUrl: "/common/qtv/TargetWiseLog.asp",

	setWiseLog: function(strLogParam){
		var param;
		param = "LogSection=" + strLogParam;
		
		new Ajax.Request(this.logUrl, {
			method: 'get',
			asynchronous: true,
			contentType: 'application/x-www-form-urlencoded',
			encoding: 'euc-kr',
			parameters: param,
			onSuccess: function(xmlHttp){
				
			}.bind(this)
		});
	}
}

/*
var fcNewsCtl = Class.create({
	blnStop: false,
	blankPage: g_mainsvr + "/common/FcMain/80/FmBlankPage.asp",

	initialize: function(url, tdom, chmenucd, npage, tpage){
		this.oData = {};
		this.url = url;
		this.nPage = npage;
		this.tPage = tpage;
		this.tDom = tdom;
		this.oChMenuCd = chmenucd;
		this.getData(this.oChMenuCd, this.nPage);
	},
	getData: function(chmenucd, page){
		this.nPage = page;
		this.oChMenuCd = chmenucd;
		if(!this.oData[chmenucd]){
			this.ajax("GET", function(xml){this.setData(xml);}.bind(this), this.url + "?chmenucd=" + this.oChMenuCd + "&page=" + this.nPage + "&t="+ this.dumyTime());
		}else{
			this.display();
		}
	},
	setData: function(res){
		if(res.getResponseHeader("x-valid") != "false"){
			if(!this.oData[this.nPage.toString()])
				this.oData[this.nPage.toString()] = res.responseText;
			this.display();
		}
	},
	display: function(){
		document.getElementById(this.tDom).innerHTML = this.oData[this.nPage.toString()];
		this.setNewsTab();
	},
	next: function(step){
		this.nPage +=  step;
		if(this.nPage > this.tPage) this.nPage = 1;
		if(this.nPage <= 0) this.nPage = this.tPage;
		this.getData(this.oChMenuCd, this.nPage);
		this.blnStop = true;
	},
	autoNews: function(){
		if(!this.blnStop){
			this.next(1);
		}else{
			this.blnStop = false;
		}
	},
	ajax: function(method, callback, url, data, async){
		try{
			new Ajax.Request(url, {
				method: method,
				asynchronous: async ? async : true,
				contentType: 'application/x-www-form-urlencoded',
				encoding: 'euc-kr',
				parameters: data ? data : "",
				onSuccess: function(xmlHttp) {
					callback(xmlHttp);
				}
			});
		}catch(e){}
	},
	dumyTime: function(){
		var nDt = new Date();
		var tempTime = nDt.getFullYear().toString() + nDt.getMonth().toString()  + nDt.getDate().toString() +  nDt.getHours().toString() + nDt.getMinutes().toString() + nDt.getSeconds().toString() + nDt.getMilliseconds().toString();
		return tempTime;
	},	
	setNewsTab: function(){
		var sWiseLogCode;
		var objTab;

		switch(this.oChMenuCd) {
			case "01" :
				sWiseLogCode = "NEWS01_040";
				objTab       = "total";
				break;
			case "02" :
				sWiseLogCode = "NEWS01_041";
				objTab       = "sports";
				break;
			case "03" :
				sWiseLogCode = "NEWS01_042";
				objTab       = "ent";
				break;
			case "04" :
				sWiseLogCode = "NEWS01_043";
				objTab       = "hot";
				break;
			default :
				sWiseLogCode = "NEWS01_040";
				objTab       = "total";
		}

		document.getElementById("total").className  = "";
		document.getElementById("sports").className = "";
		document.getElementById("ent").className    = "";
		document.getElementById("hot").className    = "";
		document.getElementById(objTab).className   = "on";
	}
});
*/

function _getPlayer(vDOCID, vWiseCode){
	window.open(g_newssvr + '/video/NewsVideoView.asp?DOCID=' + vDOCID + '&LogSection=' + vWiseCode, 'win','top=10,left=10, toolbar=no,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0,width=959,height=620').focus();
}

//°øÀ¯ÇÏ±â
var snsShare = {};
snsShare.LinkSite = function(name, url)
{
	this.name = name;
	this.url = url;
};

snsShare.siteList = [
			new snsShare.LinkSite('twitter', 'http://twitter.com/home?@@params@@'),
			new snsShare.LinkSite('facebook', 'http://www.facebook.com/share.php?@@params@@'),
			new snsShare.LinkSite('me2day', 'http://me2day.net/posts/new?@@params@@'),	
			new snsShare.LinkSite('yozm', 'http://yozm.daum.net/api/popup/prePost?@@params@@'),	
			new snsShare.LinkSite('cyworld', 'http://api.cyworld.com/openscrap/video/v1/?@@params@@'),	
			new snsShare.LinkSite('delicious', 'http://delicious.com/save?@@params@@')
];

snsShare.getLink = function(site_name, title, scrapid , time, content)
{
	var title = encodeURIComponent(title);

	
	viewUrl = location.href;
	if((site_name == 'twitter') || (site_name == 'me2day') || (site_name == 'yozm')){
		viewUrl = getShortURL(scrapid);
		if (site_name == 'me2day'){
			viewUrl = '"' + viewUrl + '":' + viewUrl;
		}
	}
	var writeString = '';
	var url = '';
	var params = '';
	var siteList = snsShare.siteList;
	
	for (var i = 0; i < siteList.length; i++)
	{
		if ( site_name == siteList[i].name )
		{
		  if (site_name == 'twitter') {
    		  params = "status=" + title + " "+encodeURIComponent(viewUrl);
			  //params = "url=" + escape(viewUrl) + "&text=" + title;
		  } else if (site_name == 'facebook') {
    		  params = "u=" + encodeURIComponent(viewUrl) + "&t="+title + "" + encodeURIComponent(viewUrl);
		  } else if (site_name == 'me2day') {
    		  params = "new_post[body]==" + title + encodeURIComponent(viewUrl);
		  } else if (site_name == 'yozm') {
    		  params = "prefix=" + title + encodeURIComponent(viewUrl);
		  } else if (site_name == 'cyworld') {				  
			params = 'vu=' + escape(encodeURI(g_eqsvr + "/flvPlayer.swf?docId="+scrapid+"&serviceId=QT04"))+
					 '&vt=' + encodeURIComponent(title)+
					 '&vp=' + escape(encodeURI(scrapid))+
					 '&vd=' + escape(encodeURI(time))+
					 //'&vl=' + escape(encodeURI(viewUrl))+
					 '&vl=' + escape(encodeURI("http://qtv.freechal.com/movie/QTVMovieView.asp?docid="+scrapid))+
					 '&vc=' + encodeURIComponent(content);
		  } else if (site_name == 'delicious') {
			params = "v=5&amp;noui&amp;jump=close&amp;url=" + encodeURIComponent(viewUrl) + "&amp;title=" + title;
		  }

			url = siteList[i].url.replace('@@params@@', params);
		}
	}
	if(site_name == 'cyworld'){
		window.open(url, 'cyopenscrap', 'width=450,height=450');
	}else{
	window.open(url);
	}
};

function getShortURL(nDocID) {

	var ret = jQuery.ajax({url: g_qtvsvr +'/movie/QTVShortUrl.asp?docid='+nDocID,async:false,dataType:"json",scriptCharset: "euc-kr"}).responseText;
	ret = ret.replace("\n", "");

	return ret;
}
