function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

function copyToClipboard(url) {
	
	if($.browser.msie) {
		window.clipboardData.setData("Text",url);
		alert('已成功复制地址！', '提示');	
	}else{
		alert('非IE浏览器请手动复制以下地址!\n'+url, '提示');	
		
		return;
	}

}

function copyZhuanFaToClipboard(title,url) {
	var html = "我分享了一个好视频：\n";
	html += title + "\n";
	html += url;
	if($.browser.msie) {
		window.clipboardData.setData("Text",html);
		alert('已成功复制地址！', '提示');	
	}else{
		alert('非IE浏览器请手动复制以下地址!\n'+html, '提示');	
		
		return;
	}
	
}

function copyPlayToClipboard(id){
	var url = document.getElementById(id).value;
	if($.browser.msie) {
		window.clipboardData.setData("Text",url);
		alert('复制成功。现在您可以粘贴（Ctrl + V）到Blog或BBS中了 ！', '提示');
	}else{
		alert('非IE浏览器请手动复制以下地址!\n'+url, '提示');	
		return;
	}
}

function SetHome(obj,vrl){
    try{
            obj.style.behavior='url(#default#homepage)'; 
            obj.setHomePage(vrl);
    }
    catch(e){
            if(window.netscape) {
                    try {
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
                    }  
                    catch (e)  { 
                            alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");  
                    }
                    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                    prefs.setCharPref('browser.startup.homepage',vrl);
             }
    }
}

function del(url){
	if( confirm("确认要删除！") ){
		location.href = url;
	}
	return false;
}

function go(url){
	location.href = url;
	return false;
}

function wopen(url){
	window.open(url);
}

/* var emotion_images_url在页面页面头部定义*/
function showemotion(em,pid) {
    $("#"+em).html('<span><a href="javascript:void(0);" onclick="emotion(\''+em+'\',\''+pid+'\',\'(微笑)\')"><img alt="微笑" title="微笑" src="'+emotion_images_url+'emotion/face1.gif"/></a></span><span><a href="javascript:void(0);" onclick="emotion(\''+em+'\',\''+pid+'\',\'(喜欢)\')"><img alt="喜欢" title="喜欢" src="'+emotion_images_url+'emotion/face2.gif"/></a></span><span><a href="javascript:void(0);" onclick="emotion(\''+em+'\',\''+pid+'\',\'(生气)\')"><img alt="生气" title="生气" src="'+emotion_images_url+'emotion/face3.gif"/></a></span><span><a href="javascript:void(0);" onclick="emotion(\''+em+'\',\''+pid+'\',\'(鄙视)\')"><img alt="鄙视" title="鄙视" src="'+emotion_images_url+'emotion/face4.gif"/></a></span><span><a href="javascript:void(0);" onclick="emotion(\''+em+'\',\''+pid+'\',\'(疑惑)\')"><img alt="疑惑" title="疑惑" src="'+emotion_images_url+'emotion/face5.gif"/></a></span><span><a href="javascript:void(0);" onclick="emotion(\''+em+'\',\''+pid+'\',\'(哭泣)\')"><img alt="哭泣" title="哭泣" src="'+emotion_images_url+'emotion/face6.gif"/></a></span><span><a href="javascript:void(0);" onclick="emotion(\''+em+'\',\''+pid+'\',\'(汗)\')"><img alt="汗" title="汗" src="'+emotion_images_url+'emotion/face7.gif"/></a></span><span><a href="javascript:void(0);" onclick="emotion(\''+em+'\',\''+pid+'\',\'(淡定)\')"><img alt="淡定" title="淡定" src="'+emotion_images_url+'emotion/face8.gif"/></a></span>');
    var p = $("#"+pid);
    var position = p.position();
    $('#'+em).css("top",position.top+85);
    $('#'+em).css("left",position.left);
}
function emotion(em,id,emo) {
    $("#"+id).val($("#"+id).val()+emo);
    //closeemotion(em);
}

function closeemotion(id) {
     $("#"+id).html('');
}

function searchVideo(idStr,typeStr){
	var keyword = $("#"+idStr).val();
	if($.trim(keyword)){
		location.href = webUrl+'search?vtype='+$('#'+typeStr).attr('vtype')+'&keyword='+encodeURIComponent(keyword);
	}else{
		alert('关键词不能为空！');
	}
}

function modify_video_size(id,width,height){
	
}

function logoutYouku(){
	jQuery.getJSON('http://u.youku.com/QUser/~ajax/logout?__callback=?', function(data){
		if (data) {
			//alert('登出成功');
			//window.location="/";
		}
	});
}

function user_logout(){
	//优酷账号登出
	logoutYouku();
	$.ajax({
   	 url: webUrl + 'login/logout',
  		 type: 'POST',
        data:'',
        error: function(){
          alert('错误,请重试！');
        },
    	success: function(msg){
			alert(msg);
			location.href = location.href;
  		}
	});
}

jQuery(function($) {
		//绑定优酷账号登出
		jQuery("#login_out").attr("onclick","");
		jQuery("#login_out").bind("click",function(){
			jQuery.getJSON('http://u.youku.com/QUser/~ajax/logout?__callback=?', function(data){
				window.location.href='http://u.766.com/navigation/new/login.php?logout&service='+window.location.href;
			});
			
		});
		
	});
