var ShowComponent = 
{
	closeAll : function()
	{
		$$('.listen_mb_wrap').each(function(el) {
			el.style.display = 'none';	
		}, this);
	},
	
	PhoneVite : function(SONG_NUM)
	{
		window.open("/Listen/Song/SongContent/PhoneVite/?SONG_NUM="+SONG_NUM,"popup");
	},
	
	viewSendTO : function(SONG_NUM,LAYERNAME,LAYERCOUNT, CONTEST_NUM)
	{
		var Param = { 
			'SONG_NUM' : SONG_NUM,
			'CONTEST_NUM' : CONTEST_NUM
			};
		Param.onComplete = function()
		{
			if(LAYERNAME != undefined)
			{
				for(var idx=1;idx<=LAYERCOUNT;idx++)
				{
					var TARGETNAME = "ShareContent" + idx;
					if(TARGETNAME != LAYERNAME)
					{
						$(TARGETNAME).innerHTML = "";
					}
				}
			}
			this.closeAll();
			$('sendto').style.display = 'block';
		}.bind(this);
		
		if(LAYERNAME != undefined)
		{
			AutoRun.setDocument($(LAYERNAME), Param , '/Listen/Song/SongContent/ajax.sendto.php');
		}
		else
		{
			AutoRun.setDocument($('ShareContent'), Param , '/Listen/Song/SongContent/ajax.sendto.php');
		}
	},
	
	BuyItem : function(song_num)
	{
		alert(song_num);
		this.closeAll();

		/*
		var param = {'kkk' : 333};
		param.aaa = 333
		*/
		var Param = { 'SONG_NUM' : song_num };

		var result = Ajax.exec("/listen/Song/SongContent/ajax.buy.php", Param);  
		// var result = Ajax.exec();
		if(result.text == "OK")
		{
			$('buy_complete').style.display = "block";
		}
		else
		{
			alert('kkk');
		}
	},
	
	getShareLayerUrl : function()
	{
		return '/Listen/Song/SongContent/ShareLayer.php';
	},
	
	openShareEmbed : function(ShareType, ShareNum)
	{
		Share.ShareType = ShareType;
		Share.ShareNum = ShareNum;
		
		Share.Windows = _Window.showPopUp();
		Share.Windows.style.width    = '484px';
		
		var Param = {  'MODE' : 'Call'  };
		
		Param["Type"] =  "Page";
		Param["File"] =  this.getShareLayerUrl();
		Param.onComplete = function ()
		{
			Share.setValue();
			UI.setScreenCenter(this);
			Clipboard.init();
		}.bind(Share.Windows);

        AutoRun.setDocument(Share.Windows, Param, '/Listen/Song/SongContent/ShareLayer.php');
	},
	openShareEmail : function(ShareType, ShareNum)
	{
		Share.ShareType = ShareType;
		Share.ShareNum = ShareNum;
		
		Share.Windows = _Window.showPopUp();
		Share.Windows.style.width = '484px';
		
		var Param = {  'MODE' : 'Call'  };
		
		Param["Type"] =  "Page";
		Param.onComplete = function ()
		{
			Share.setValue();
			Share.viewEmail();
			UI.setScreenCenter(this);
		}.bind(Share.Windows);
        	  
        AutoRun.setDocument(Share.Windows, Param, '/Listen/Song/SongContent/ShareLayer.php');
	},
	submitShare : function()
	{
		var F =  document.ShareForm;
		
		
		if (F.TO.value.trim() == '')
		{
			alert('받는 사람의 이메일을 적어 주세요.');
			F.TO.focus();
			return false;
		}
		
		var From = F.TO.value.split('\,');
		
		for(var i = 0, len = From.length ; i < len ; i++)
		{
			if(!isEmail(From[i]))
			{
				alert('받는 사람의 이메일이 유효한 이메일 주소가 아닙니다.');
				return false;
			}
		}
		
		if (!isEmail(F.FROM.value))
		{
			alert('보내는 사람의 이메일이 유효한 이메일 주소가 아닙니다.');
		}
		else if (F.CONTENT.value.trim() == '')
		{
			alert('내용을 적어 주세요.');
		}
		else
		{
			var Result = Ajax.exec(getComponentURL('FormMail') + 'Component.php', {
				'MAIL': 'SHAREMAIL',
				'SHARE_TYPE': Share.ShareType,
				'SHARE_NUM': Share.ShareNum,
				'TO': F.TO.value,
				'FROM': F.FROM.value,
				'CONTENT': F.CONTENT.value
			});
			
			F.reset();
			if(Result.text == 'OK')
			{
				alert('메일이 발송 되었습니다.');
				_Window.closePopUp();
			}
			else
			{
				alert(Result.text);
			}
		}
	},
	viewEmail : function ()
	{
		$('EmailBox').style.display = "block";
		$('EmbedBox').style.display = "none";
	},
	
	viewEmbed : function ()
	{
		$('EmailBox').style.display = "none";
		$('EmbedBox').style.display = "block";
	},
	
	setValue : function()
	{
		var F =  document.ShareForm;
		var embedurl = 'http://'+document.location.hostname+'/musicshakePlayer.swf?DIR='+this.ShareType+'/'+this.ShareNum+'&NUM=1&lang=kor&auto='+(F.AUTO.checked?1:0);
		$('share_url_link').value = document.location.href;
		$('embedtag').value = getFlashCode(embedurl, 'flashPlayer', 375, 150);
	},
	copyString : function(Str)
	{
		
	},
	
	resizeImages : function ()
	{
	    
	    if(!$('ContentArea')) return false;
	    
	    var Imgs = $('ContentArea').getElementsByTagName('img');
	    
	    for(var i=0; i<Imgs.length; i++)
	    {
	        var Img = Imgs[i];
	        
	        var Size = UI.getObjSize(Img);
	        if(Size.w > 700)
	        Img.style.width = '100%';
	    }
	    
	}
	
	
}


var Report =
{
    showReportBox : function(Type, Num)
    {
       
        if(Type == 'CONTEST')
        {
            $('CONTEST_REPORT').appendChild($('ReportForm'));
        }
        
        $('ReportForm').style.display ='block';
        
    },
    
    closeReortBox : function()
    {
         $('ReportForm').style.display ='none';
    }
    
       
}



addEvent(window, 'load', ShowComponent.resizeImages)
