﻿/**
 * UUSEE.Client.utf8
 * client interface
 */
// document.write('<OBJECT ID="UUPlayer" WIDTH=0 HEIGHT=0 CLASSID="CLSID:77910CD3-5447-4CCB-92DE-35BA8198BE81"></OBJECT>');
/*
if(!UUPlayer)
{
	document.writeln("<OBJECT ID=\"UUPlayer\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:77910CD3-5447-4CCB-92DE-35BA8198BE81\">");
}

try
{
	UUPlayer;
}
catch (e)
{
	document.writeln("<OBJECT ID=\"UUPlayer\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:77910CD3-5447-4CCB-92DE-35BA8198BE81\">");

}
*/
if(typeof(UUPlayer)=='undefined')
{
	document.write('<OBJECT ID="UUPlayer" WIDTH=0 HEIGHT=0 CLASSID="CLSID:77910CD3-5447-4CCB-92DE-35BA8198BE81"></OBJECT>');
}
if ( !UUSEE )
{
	var UUSEE = {};
}

if ( UUSEE.Client )
{
	// noting
}
else
{
	UUSEE.Client = {
		play_url	:	'uusee://Play({[@guid@]},[@title@],,[@stype@],,,/#[@protocol@],,)',
		record_url	:	'uuseerec://Add({[@guid@]},[@title@],,102,,,/#1,,,[@time@],[@length@])',
		notify_url	:	'uuseenotify://Add({[@guid@]},[@channel_name@],,102,,,/#1,,[@video_name@],[@stime@])',
		Collection_url	:	'uusee://Add({[@guid@]},[@title@],1,[@stype@],,,/#[@protocol@],)',
		init		:	function(){
			UUSEE.Client._status = false;
			if ( !UUSEE_CHANNEL_GUID )
			{
				return false;
			}
		},
		saveFavourite	:	function(sGuid,sTitle,iProtocol){





// 1 : living , default
			// 2 : order
			if ( !iProtocol )
			{
				iProtocol = 1;	
			}
			if ( !sGuid || !sTitle )
			{
				return false;
			}
			if ( iProtocol !=1 )
			{
				var type = 212;
			}
			else
			{
				var type = 102;
			}
			var s = UUSEE.Client.Collection_url.replace('\[@title@\]' , sTitle);
			s = s.replace('\[@guid@\]' , sGuid);
			s = s.replace('\[@protocol@\]' , iProtocol);
			s = s.replace('\[@stype@\]' , type);

			return UUSEE.Client.run(s);
//结束




//			if ( !s ) s = location.href;
//			window.external.addFavorite(s,t);
		},
		setClipboard	:	function(s){
			if ( !s )
			{
				s = location.href;
			}
			window.clipboardData.setData('text', s);
			alert('此页已经成功复制到您的剪贴板！');
			return true;
		},
		notify		:	function(sGuid, sChannel_name, sVideo_name, sTime){
			if ( !sGuid || !sChannel_name || !sVideo_name || !sTime)
			{
				return false;
			}

			var s = UUSEE.Client.notify_url.replace('\[@channel_name@\]' , sChannel_name);
			s = s.replace('\[@guid@\]' , sGuid);
			s = s.replace('\[@video_name@\]' , sVideo_name);
			s = s.replace('\[@stime@\]' , UUSEE.Client.time(sTime) );

			return UUSEE.Client.run(s);
		},
		rec		:	function(sGuid, sTitle,sTime,iLength){
			if ( !iLength )
			{
				iLength = 30;
			}
			if ( !sGuid || !sTitle || !sTime)
			{
				return false;
			}

			var s = UUSEE.Client.record_url.replace('\[@title@\]' , sTitle);
			s = s.replace('\[@guid@\]' , sGuid);
			s = s.replace('\[@time@\]' , UUSEE.Client.time(sTime) );
			s = s.replace('\[@length@\]' , iLength);

			return UUSEE.Client.run(s);
		},
		play		:	function(sGuid, sTitle, iProtocol){
			// 1 : living , default
			// 2 : order
			if ( !iProtocol )
			{
				iProtocol = 1;
				
			}
			if ( !sGuid || !sTitle )
			{
				return false;
			}
			if ( iProtocol !=1 )
			{
				var type = 212;
			}
			else
			{
				var type = 102;
			}
			var s = UUSEE.Client.play_url.replace('\[@title@\]' , sTitle);
			s = s.replace('\[@guid@\]' , sGuid);
			s = s.replace('\[@protocol@\]' , iProtocol);
			s = s.replace('\[@stype@\]' , type);

			return UUSEE.Client.run(s);
		},
		run		:	function(s){
			if ( !UUSEE.Client.ocxstatus() )
			{
				if( UUSEE.Client.is_ie() )
				{
					var tt = confirm("您没有安装UUPlayer客户端！请进入软件下载页面，下载本软件！");

					if(tt==true)
					{
						window.open("http://player.uusee.com/download/");
					}
					else
					{
						return false;
					}

					//location.href="http://player.uusee.com/download/";
				}
				else
				{
					alert("如果您使用FireFox无法正常观看，请使用IE浏览器打开此页面！");
					return false;
				} 
			}
			else
			{
				window.open(s,'_self');
			}
			return true;
		},
		time		:	function(i){
			var date = new Date();
			date.setTime(i*1000);
			return date.getFullYear() + "-" + ( date.getMonth() + 1 ) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes();
		},
		status		:	function(){
			if ( !UUSEE.Client._status )
			{
				return 'SILENT';
			}
			return UUSEE.Client._status;
		},// check client installed
		is_ie		:	function(){
			var agt = navigator.userAgent.toLowerCase();
			var ie = ( ( agt.indexOf("msie") != -1) );
			if ( ie )
			{
				return true;
			}
			else
			{
				return false;
			}
		},
		ocxstatus	:	function(){
			var UUPObj;
			var newUUPObj;
			try
			{
				//UUPObj = new ActiveXObject("UPDATEC2.UpdateC2Ctrl.1");
				UUPObj = new ActiveXObject("UUPLAYEROCX.UUPlayerOCXCtrl.1");
				if ( !UUPObj )
				{
					newUUPObj = null;
					UUPObj = null;
					return false;
				}
				else
					{
						if (! (UUPlayer.CheckVersion('UUPlayer') || UUPlayer.CheckVersion('UUPlayer_2008')))
						{
								newUUPObj = null;
								UUPObj = null;
								return false;	
						}
						UUPObj = null;
						return true;
					}
					newUUPObj = null;
					UUPObj = null;
					return false;
			}
			catch(e)
			{
				newUUPObj = null;
				UUPObj = null;
				return false;
			}
			UUPObj = null;
		},
		// nothing
		foo		:	function(){}
	};
}

