
function fbLoginPopup(){
	/*
	FB.Connect.requireSession(function(){
		
			// it will prompt a permission form
			FB.ensureInit(function () {
			
				// auto run you function
				notifyCenter("登入中...");
				document.location=document.location+"";			
				
			});
		});
		
		*/
		
	/*	
	if(1 ){
		//alert("new;")
		var url="http://graph.facebook.com/oauth/authorize?client_id=62889096073&redirect_uri=http://forum.vlshk.com/ajax_login.php&scope=publish_stream,offline_access&display=popup&method=permissions.request";
		window.open(url,"","width=560,height=370");
	
	}
	
	*/
	
	FB.login(function(response) {
	  if (response.authResponse) {
		if (response.scope) {
		  // user is logged in and granted some permissions.
		  // perms is a comma separated list of granted permissions
		  
		} else {
		  // user is logged in, but did not grant any permissions
		
		  fbLoginforum();
		}
	  } else {
		// user is not logged in
		
	  }
	}, {scope:'publish_stream,offline_access'});


};


function funGetMD5(){
	
	/* get md5 from server */		
	$.ajax({
		type: "GET",
		data: "uid="+$("#uid").val(),
		url: "ajax_getmd5.php",
		success: function(msg){
			$("#ph").val(msg);
		}
	});	
}
function fbGetMemberInfo_v1(){
}
function fbGetMemberInfo_v1XXX(){

//alert(FB.Connect.get_loggedInUser());

 var api = FB.Facebook.apiClient;
 
   //alert(api.get_session());
     


	var uid = FB.Connect.get_loggedInUser();
		if(uid!=null){
			var friends;
			var info;
			var all="";
	
				/* get friend */
				 FB.Facebook.apiClient.friends_get(null, function(friends_ids) {
					if (friends_ids) {
						friends=friends_ids.join(',')
					} else {
						friends='';
					}
				
					/*========*/
					
					/* get info */
					FB.Facebook.apiClient.users_getInfo(uid,['first_name','last_name','name','birthday','sex','pic_square','profile_url'], function(result, ex){
						/*window.alert("Exception :"+ex);*/
						
						var str="";
						var myArray=result[0];
						for ( var key in  myArray) {
							str+="&"+key+"="+encodeURIComponent(myArray[key]);
						}
						info=str;
						
			
							 
						 all+=info;
						 all+="&friends="+friends;
						 
						 
						 
						 /* pass to server */
						//alert(all);
						
						
							/* pass to server */
							
							$.ajax({
								type: "POST",
								url: "ajax_updatefacebookinfo2db.php",
								data: all,
								success: function(msg){
									
									document.title+=".";
									//alert(msg);
									
							
								}
							});	
	
					});
					
					/*========*/
				
				
				});
				
			
					
				
							
								
		}
    

	
	
    
}
 
 
function fbGetMemberInfo_v2(){
	
	fbCheckLogin(function(){
		/*alert(response.authResponse.access_token);*/
		var all="";	
		FB.api('/me', function(response) {
	
			var str="";
			var myArray=response;
			for ( var key in  myArray) {
				str+="&"+key+"="+encodeURIComponent(myArray[key]);
			}
			//alert(str);
			all+="&info="+str;		
		//	alert("1"+all);
		});
		
		
		FB.api('/me/friends', function(response) {
	
			var str="";
			//response.data.length
			var length=response.data.length;
			for(var i=0;i<length;i++){
		
				if(i==0){
					str+=(response.data[i].id);
				}else{
					str+=","+(response.data[i].id);
				}
			}
			//alert("2"+str);
			//alert(str);
			//str='1,2';
			all+="&friends="+str;
		//	alert(all);		
				
				/* pass to server */	
	
				$.ajax({
					type: "POST",
					url: "ajax_updatefacebookinfo2db.php",
					data: all,
					success: function(msg){						
						//alert(msg);				
					}
				});
					
		});	
	});	
		
}	
		
	



function funCheckFan(){
var isfan=false;
FB.api({ method: 'fql.query', query: 'SELECT uid FROM page_fan WHERE uid='+$("#uid").val()+' AND page_id=62889096073' },
    function(result) {
        if (result.length)
        { 
			isfan=true;
			notifyCenter("已加入粉絲。");
        
        } else { isfan=false;;
			
			var url="http://www.facebook.com/connect/connect.php?id=62889096073&amp;connections=14&amp;stream=0&amp;locale=";
						
							$.fn.colorbox({
							transition:'none', 
							title:"加入粉絲",
							overlayClose:false,
							iframe:true,
							href:url,
							width:420,
							height:278,
							onClosed:function(){
								
							},
							opacity:0.4
							
							
							},function(){
							$("#cboxLoadedContent").css("background-color","#ffffff");
							});
							
							
         }
    });
    

	fbCheckLogin(function(){
			
			
			
	});

	return false;		
}




function funCheckPermission(autopost){


	FB.ui({
		method: 'permissions.request',
		scope: 'publish_stream,offline_access',
		display: "popup"
		},function(response) {
			var flag=false;
			if (response && response.perms) {
				//alert('Permissions granted: '+response.perms);
		
				notifyCenter("已允許分享。");
				flag=true;
			} else if (!response.perms){
				//alert('User did not authorize permission(s).');
				
				flag=false;
			}
			
			/*================*/
			if(flag) {
					var str="publish_stream=1";
				$.ajax({
					type: "POST",
					url: "ajax_setuserpermission.php",
					data: str,
					success: function(msg){
					//	alert("ok"+msg);	
					
					}
				});
				/* save */
				notifyCenter("已允許分享。");
				//funCheckMemberFBstatus();
			
			}else{
			
			
				var str="publish_stream=0";
				$.ajax({
					type: "POST",
					url: "ajax_setuserpermission.php",
					data: str,
					success: function(msg){
						//alert("ok"+msg);	
					
					}
				});
				/* save */

			}
			
	});
};








function funCheckPermissionXX(autopost){


	
			
	FB.ui({
		method: 'permissions.request',
		scope: 'publish_stream,offline_access',
		display: "popup"
		},function(response) {
			
			if (response && response.perms) {
				alert('Permissions granted: '+response.perms);
				//callbackFunc(true);
				notifyCenter("已允許分享。");
				flag=true;
			} else if (!response.perms){
				alert('User did not authorize permission(s).');
				//callbackFunc(false);
				flag=false;
			}
			
			/*================*/
			if(flag) {
					var str="publish_stream=1";
				$.ajax({
					type: "POST",
					url: "ajax_setuserpermission.php",
					data: str,
					success: function(msg){
						alert("ok"+msg);	
					
					}
				});
				/* save */
				notifyCenter("已允許分享。");
				//funCheckMemberFBstatus();
			
			}else{
			
			
				var str="publish_stream=0";
				$.ajax({
					type: "POST",
					url: "ajax_setuserpermission.php",
					data: str,
					success: function(msg){
						alert("ok"+msg);	
					
					}
				});
				/* save */

			}
			/*================*/
			
	});



var ispublish_stream=false;
var isbookmarked=false;



	fbCheckLogin(function(){
	
		var  uid=$("#uid").val();
	    var query = FB.Data.query('select publish_stream from permissions where uid={0}', uid);
		query.wait(function(rows) {
			if(rows[0].publish_stream == 1 ) {
				ispublish_stream=true;
			} else {
				// false
			}
			
			/*===============*/
			if(ispublish_stream){
			
				notifyCenter("已允許分享。");
				/*facebook_prompt_permission('publish_stream', function(accepted) {
				
				});*/
		   }else{
					
				facebook_prompt_permission('publish_stream', function(accepted) {
				
				
					var flag=false;
					alert("xx"+accepted);
					/*if(accepted!=null && accepted.indexOf("publish_stream")>=0){
						flag=true;
					}*/
					
					if(flag) {
						var str="publish_stream=1";
						$.ajax({
							type: "POST",
							url: "ajax_setuserpermission.php",
							data: str,
							success: function(msg){
								alert("ok"+msg);	
							
							}
						});
						/* save */
						notifyCenter("已允許分享。");
						//funCheckMemberFBstatus();
					
					}else{
					
					
						var str="publish_stream=0";
						$.ajax({
							type: "POST",
							url: "ajax_setuserpermission.php",
							data: str,
							success: function(msg){
								alert("ok"+msg);	
							
							}
						});
						/* save */

					}
				});				
					
		   }
		   /*===============*/
		});
		
					 
	});
	return false;
}

function funCheckBookmark(){
var ispublish_stream=false;
var isbookmarked=false;

FB.ui({ method: 'bookmark.add' }, function (response) {


	if(response.bookmarked==1){
	notifyCenter("已添加書簽。");
	}else{
	}
}); 


	
}



function fbLoginPermission(callbackFunc){
var ispublish_stream=false;
var isbookmarked=false;	
	fbCheckLogin(function(){
	
		
		/*=========================*/
		var uid=$("#uid").val();
		var sql = "select uid,bookmarked,publish_stream  from permissions  where uid="+uid;
		FB.Facebook.apiClient.fql_query(sql, function(result, ex) {
			//Do something with result
			if(result && result[0].bookmarked==1){
			isbookmarked=true;
			
		   }
			   
		   if(result && result[0].publish_stream==1){
			ispublish_stream=true;
		   }
		   
			if(ispublish_stream){
			   
					callbackFunc(true);
					
		    }else{
					
					
				facebook_prompt_permission('publish_stream', function(accepted) {
				
					var flag=false;
					if(accepted!=null && accepted.indexOf("publish_stream")>=0){
						flag=true;
					}
					
					
					if(flag) {
						var str="publish_stream=1";
						$.ajax({
							type: "POST",
							url: "ajax_setuserpermission.php",
							data: str,
							success: function(msg){
								//alert("ok"+msg);	
								callbackFunc(true);
							}
						});
						/* save */
					
					}else{
						var str="publish_stream=0";
						$.ajax({
							type: "POST",
							url: "ajax_setuserpermission.php",
							data: str,
							success: function(msg){
								//alert("ok"+msg);	
								callbackFunc(true);
							}
						});
						/* save */

					}
				});				
				/* ================== */	
				
							
		    }
			   		   
		   
		});		
		
		
		/*=========================*/
	
	});
		
	
	
}

function fbCheckLogin(callbackFunc){


	FB.getLoginStatus(function(response) {

	
	  if (response.authResponse) {
			var uid = response.authResponse.userID;
			// logged in and connected user, someone you know
			$("#uid").val(uid);
			funGetMD5();
			
	
			// auto run you function
		
			callbackFunc();
			//funCheckMemberFBstatus();
		
		
	  } else {
		// no user session available, someone you dont know
		fbLoginPopup();
		
	  }
	  
	  
	  
	});
    


	return false;
}

function fbCheckLoginBackUp(callbackFunc){
	FB.init("526e408de8de93056b64ed280aef08ff", "include/xd_receiver.htm");
	
		
	var uid = FB.Connect.get_loggedInUser();
	


	if (uid == null){
	
		FB.Connect.requireSession(function(){
			// it will prompt a permission form
				uid = FB.Connect.get_loggedInUser();
				$("#uid").val(uid);
				funGetMD5();
		
				FB.ensureInit(function () {
			
				// auto run you function
				callbackFunc();
				funCheckMemberFBstatus();
			});
		});
	}else{
	
		$("#uid").val(uid);
		funGetMD5();
		
		FB.ensureInit(function () {
			// auto run you function
			callbackFunc();
			funCheckMemberFBstatus();
			
		});
	}

	return false;
}




/*


var str="publish_stream=1";
$.ajax({
	type: "POST",
	url: "ajax_setuserpermission.php",
	data: str,
	success: function(msg){
		//alert("ok"+msg);	
	}
});
*/
/*http://wiki.developers.facebook.com/index.php/Facebook_IP_Addresses*/


function facebook_prompt_permission(permission, callbackFunc) {

	FB.ui({
		method: 'permissions.request',
		scope: 'publish_stream,offline_access',
		display: "popup"
		},function(response) {
			
			if (response && response.perms) {
				alert('Permissions granted: '+response.perms);
				callbackFunc(true);
			} else if (!response.perms){
				alert('User did not authorize permission(s).');
				callbackFunc(false);
			}
			
	});

/*
    var rs=FB.Facebook.apiClient.users_hasAppPermission("offline_access",  function(result) {
        // prompt offline permission

        if (result == 0) {
			//alert("no permission");
            // render the permission dialog
            //alert("offline_access");
            FB.Connect.showPermissionDialog(permission+",offline_access", function(result){
				callbackFunc(true);
            });
        } else {
			//alert("has permission");
            // permission already granted.
            callbackFunc(true);
        }
    });
*/


}


function funPublishFeed(){

		


		/* ==================*/
		/* ==================*/		
				
	  var cid=$("#cid").val();
	  var url=$("#topic_url").val();
	  var  ph=$("#ph").val();
	  var url_from=url+"&from=main&ph="+ph;
	  var url_action=url+"&from=main&share=1&ph="+ph;
	  
	  if( $("#uid").val()=="" ){
		url_from=url+"&from=main";
		url_action=url+"&from=main&share=1";
	  }
	  
	  
	  var t=$("#topic_title").val();
	  
	/* [港討]*/
	  var link='<a href="'+url+'">'+t+'</a>';
	  var link2='<a href="'+url+'">'+url+'</a>';

	  	
	  var content1=link;
	  var content2=link2;
	  var content3="香港討論網";
	  /*var content4="http://apps.facebook.com/forumhk/";*/
	  var content4=url;
	  var content5="使用了 香港討論網。";
	  
	  var cover=funGetCover();

	  if(cover===""){
		cover="";
	  }

	
	/* ================= */
var user_message_prompt = "發佈此文章在您的Facebook上並與朋友分享:"; 
var user_message = ''; 
var name=t;
var href=url_from;
var description="分享給大家看看，喜歡的請按一下 [ 分享 ]。";
var caption=url+''; //\n\r
var actionLinks = [{ "name": "分享", "link": url_action}];
var target_id='';
var actor_id='';

	
	if(document.location.href.indexOf("target=1")>=0){
		target_id=window.prompt("target_id");
		if(target_id==999){
			target_id='';
			actor_id='62889096073';
			//http://a.imagehost.org/0835/DADA.jpg
			
		}
		cover=window.prompt("Cover2:",funGetCover());
	}
	



         FB.ui(
		   {
			 method: 'feed',
			 name: name,
			 link: href,
			 picture: cover,
			 caption: caption,
			 description: description,
			 from: actor_id,
			 to: target_id,
			 actions: actionLinks,
			 message: ''
		   },
		   function(response) {
			 if (response && response.post_id) {
			 /*  alert('Post was published.');*/
				notifyCenter("文章已成功發佈。");
			 } else {
			   /*alert('Post was not published.');*/
			 }
		   }
		 );
		 
		 
		 
		 
	
	 
/*
	notifyCenter("載入中...");
	

	
	
	fbCheckLogin(function(){

	 			
	});	
*/
	return false;
}

function aaaaaaa(){



		/* =========================================================== */
		facebook_prompt_permission('publish_stream', function(accepted) {
			


			if(accepted) {
				//alert("will auto");
					var auto_publish=false;				
				//do something, I do an AJAX call here to 
				//submit the users status as that is the extended permission I am asking for....
				
				var str="publish_stream=1";
				$.ajax({
					type: "POST",
					url: "ajax_setuserpermission.php",
					data: str,
					success: function(msg){
						//alert("ok"+msg);	
					}
				});
				   				
				
				/* this feed it posted save it record */
				
				/* this use has permission , save him */
			}else{
					var auto_publish=false;	
				 //alert("no auto, will prompt this time");
					var str="publish_stream=0";
				$.ajax({
					type: "POST",
					url: "ajax_setuserpermission.php",
					data: str,
					success: function(msg){
						//alert("ok"+msg);	
					}
				});
				   					 
				return false;
			}
			
					
		});
		//	alert("run2");
		/* =========================================================== */
}
function funPublishFeedGuest(){
	notifyCenter("載入中...");


		/* =========================================================== */
	
			


		/* ==================*/
		/* ==================*/		
				
	  var cid=$("#cid").val();
	  var url=$("#topic_url").val();
	  var  ph=$("#ph").val();
	  var url_from=url+"&from=guest";
	  var url_action=url+"&from=guest&share=1";
	  
	  if(ph!=""){
		url_from=url+"&from=main&ph="+ph;
		url_action=url+"&from=main&share=1&ph="+ph;
	  }
  
	  var t=$("#topic_title").val();
	  
	/* [港討]*/
	  var link='<a href="'+url+'">'+t+'</a>';
	  var link2='<a href="'+url+'">'+url+'</a>';

	  	
	  var content1=link;
	  var content2=link2;
	  var content3="香港討論網";
	  /*var content4="http://apps.facebook.com/forumhk/";*/
	  var content4=url;
	  var content5="使用了 香港討論網。";
	  
	  var cover=funGetCover();

	  if(cover===""){
		cover="";
	  }

	
	/* ================= */
var user_message_prompt = "發佈此文章在您的Facebook上並與朋友分享:"; 
var user_message = ''; 
var name=t;
var href=url_from;
var description="分享給大家看看，喜歡的請按一下 [ 分享 ]。";
var caption=url+'\n\r'; //\n\r
var actionLinks = [{ "name": "香港討論網", "link": url_action}];
var target_id='';
var actor_id='';

	if(document.location.href.indexOf("target=1")>=0){
		target_id=window.prompt("target_id");
		if(target_id==999){
			target_id='';
			actor_id='62889096073';
		}
	}
	
         FB.ui(
		   {
			 method: 'feed',
			 name: name,
			 link: href,
			 picture: cover,
			 caption: caption,
			 description: description,
			 from: actor_id,
			 actions: actionLinks,
			 message: ''
		   },
		   function(response) {
			 if (response && response.post_id) {
			 /*  alert('Post was published.');*/
			 } else {
			   /*alert('Post was not published.');*/
			 }
		   }
		 );

			
	
	
			
	
					
		
		//	alert("run2");
		/* =========================================================== */
	
	 
	 			
	

	return false;
}



function funPublishFeed_auto_loader(){
	// check last auto publish
	// if ok, run auto();
}
function funPublishFeed_auto(){
var ispublish_stream=false;


	var  uid=$("#uid").val();
	var  ph=$("#ph").val();
	if(uid=="" || ph==""){
		return false;
	}
	
	var sql = "select uid,bookmarked,publish_stream  from permissions  where uid="+uid;
	FB.Facebook.apiClient.fql_query(sql, function(result, ex) {
		//Do something with result
	   if(result && result[0].publish_stream==1){
		ispublish_stream=true;
		
	   }
	   
	   if(ispublish_stream){
	   /*==============*/
	   
	   
	
/* ==================*/		


  var cid=$("#cid").val();
  var url=$("#topic_url").val();
  var  ph=$("#ph").val();
  var url_from=url+"&from=main&ph="+ph;
  var t=$("#topic_title").val();
  
/* [港討]*/
  var link='<a href="'+url+'">'+t+'</a>';
  var link2='<a href="'+url+'">'+url+'</a>';

	
  var content1=link;
  var content2=link2;
  var content3="香港討論網";
  /*var content4="http://apps.facebook.com/forumhk/";*/
  var content4=url;
  var content5="使用了 香港討論網。";
  
  var cover=funGetCover();

  if(cover===""){
	cover="http://photos-a.ak.fbcdn.net/hphotos-ak-snc1/hs095.snc1/4703_1033687577029_1670626061_58952_5315693_n.jpg";
  }
  
/* ================= */
var user_message_prompt = "發佈此文章在您的Facebook上並與朋友分享:"; 
var user_message = ''; 
var name=t;
var href=url_from;
var description="分享給大家看看，喜歡的請按一下 [ 分享 ]。";
var caption=url+'\n\r'; //\n\r
var actionLinks = [{ "text": "香港討論網", "href": url}];
var target_id='';
var actor_id='';
var auto_publish=true;
/* ==================*/
    var attachment = {
                'name':name,
                'href':href,
                'description':description,
                'caption':caption,
                'media': [{'type':'image',
           'src':cover,
          'href':href}]
        };


	
		 FB.Connect.streamPublish(user_message,attachment,actionLinks,target_id,user_message_prompt,function(post_id,exception){
				//alert("result:" +auto_publish+','+post_id+','+exception);
			
				if(post_id!=null && post_id!='null'){
					// has posted
					//alert(post_id);
					//notifyCenter("文章已成功發佈。");
					document.title+=".";
				}else{
					//alert("NO");
					// has not posted
				}
				
		
			},auto_publish,actor_id);					
		/* ==================*/	   
	   
	   /*==============*/
	   }else{
		//alert("no p");
	   }
   
	   
	});
	
		

}


function funCheckMemberFBstatus(){
return false;
var isuser=false;
var isbookmarked=false;
var isfan=false;
var ispublish_stream=false;
var result=""; 
 var ok='<img style="margin-top:2px" src="images/icons/accept.png">';

//notifyCenter("檢查中...");
			 


	
var uid = FB.Connect.get_loggedInUser();
	
/*
var api = FB.Facebook.apiClient;  // keep 

    var uid = FB.Facebook.apiClient.get_session().uid ;
    alert(uid);
    */
    
      
 if(uid!=null){
     
	 FB.Facebook.apiClient.users_isAppUser(function(result) {
	
		if(result==true){
			isuser=true;
			if(isuser){  $(".facebook_bar .item").eq(0).find("div").html(ok); } 
			
		}
	
	});
	
	
	
	FB.Facebook.apiClient.pages_isFan("62889096073", uid, function(result) {
	
	   if(result==true){
		isfan=true;
		if(isfan){ 	$(".facebook_bar .item").eq(2).find("div").html(ok); } 
	   }
	
	});
	
	
	
	
	var sql = "select uid,bookmarked,publish_stream  from permissions  where uid="+uid;
	FB.Facebook.apiClient.fql_query(sql, function(result, ex) {
		//Do something with result
		if(result && result[0].bookmarked==1){
		isbookmarked=true;
		if(isbookmarked){ 	$(".facebook_bar .item").eq(1).find("div").html(ok); } 
	   }
		   
	   if(result && result[0].publish_stream==1){
		ispublish_stream=true;
		
		
		if(ispublish_stream){ 	$(".facebook_bar .item").eq(3).find("div").html(ok); } 
	   }
	});
	
	
  } 
        
	
	
return false;
 
	   
  
/* show */


}







$(function(){
/* jquery code */


/*=============================*/

$('.showimage').tooltip({ 
		track: false, 
		opacity: 1, 
		delay:300, 
	
	   
	 
		showURL: false, 
			bodyHandler: function() { 
			/*$(this).attr("title","");
			$(this).parent().attr("title","");
			
			*/
			
			//$($(this).attr("href")).html()
			//$("<img/>").attr("src", $(this).find(" a img").attr("src"))
			var div=$(document.createElement("div"));
			var text=$(document.createElement("div"));
			var text2=$(document.createElement("div"));
			var img=$(document.createElement("img"));
			
			text.addClass("tiptitle");
			var name=$(this).html();
			
			text.html(name);
			
			text2.addClass("tiptitle2");
			text2.html(name);
			
			
			
			
		
				img.css("width","320px");
				img.css("height","auto");
			
			img.attr("src", $(this).attr("rel"));
				
			div.append(text);
			div.append(img);
			div.append(text2);
			
	
			var html=div;
				return html; 
			} 
		});
		
		
		
var showimageTimer;
$(".showimageXX").bind("mouseover",function(){


	var cover=$(this).attr("rel");
	if(cover==""){
		return false;
	}
	
	$(".showimageDiv").remove();
	/*window.clearTimeout(showimageTimer);*/

	var target=$(document.createElement("div"));
	target.addClass("showimageDiv");
	/*==========*/
	$(this).bind("mouseout",function(){
		/*
		showimageTimer=window.setTimeout(function(){
			$(".showimageDiv").remove();
		},0);*/
		
		$(".showimageDiv").remove();
	
	});
	/*==========*/	
	
	
	$(this).after(target);
	
 //<![CDATA[
target.html('<img src="'+cover+'" width="170" alt=""\/>');
//]]>


	
	

	
	target.css({
		"position" : "absolute"
	});
 
	var obj_pos=$(this).position();

   var left=obj_pos.left;
	var top=obj_pos.top;
	var scroll=($('.fbbody').scrollTop());

	
	/*top=top+$(this).attr("offSetHeight");*/
	
	top=top+scroll+19;

	left=left+0;
	target.css({

		"color" : "#333333",
		"padding" : "2px 5px 2px 5px",
		"background" : "#fff9d7",
		"border" : "1px solid #e2c822",
		"top" : top+"px",
		"left" : left+"px"
	});

	
	
});




	$(".item img").each(function(){
		var myW=170;
		var myH=120;
		var height=$(this).attr("height");
		var width=$(this).attr("width");
		
		if(height> myH){
		
			var rate=(height/myH);
			if(rate>3){
				$(this).attr("height",myH);
				$(this).css("width",(width/rate));
			}
			
			
			/*var width2=myW*rate;*/
			
			/*$(this).css("width",(width2)+"px");
			$(this).css("margin-left",-1*(width2-myW)/2+"px");*/
		}
	});
	
	
/* end ready */	
})


		
		
		

/* ready */
$(function(){
	
	$(".movebottom").bind("click",function(){
		var targetOffset = $(".Rule").offset().top-100;
	
		$('html,body,.fbbody').animate({scrollTop: targetOffset}, 2000);
		return false;
	});
	
	$(".movetop").bind("click",function(){
		var targetOffset = $(".fbbody").offset().top-100;
	targetOffset=0;
		$('html,body,.fbbody').animate({scrollTop: targetOffset}, 2000);
		return false;
	});
					
	$(".addthis_button_facebook").bind("click",function(){
		funPublishFeedGuest();
		return false;
	});
	$("#sharehisoty").bind("click",function(){

			var url="/ajax_showreferral.php";
			$.fn.colorbox({
			transition:'none', 
			title:"分享記綠",
			overlayClose:true,
			href:url,
			width:500,
			height:"70%",
			opacity:0.5
			},function(){
				$("#cboxLoadedContent").css("background-color","#ffffff");
			});
						
	});

	window.setTimeout(function(){

	
		$('.cover a img').tooltip({ 
		track: false, 
		opacity: 1, 
		delay:300, 
	
	   
	 
		showURL: false, 
			bodyHandler: function() { 
			/*$(this).attr("title","");
			$(this).parent().attr("title","");
			
			*/
			
			//$($(this).attr("href")).html()
			//$("<img/>").attr("src", $(this).find(" a img").attr("src"))
			var div=$(document.createElement("div"));
			var text=$(document.createElement("div"));
			var text2=$(document.createElement("div"));
			var img=$(document.createElement("img"));
			
			text.addClass("tiptitle");
			var name=$(this).parent().attr("title");
			text.html(name);
			
			text2.addClass("tiptitle2");
			text2.html(name);
			
			
			
			
			if($(this)[0].offsetWidth> $(this)[0].offsetHeight){
				img.css("width","320px");
				img.css("height","auto");
			}else{
				img.css("width","auto");
				img.css("height","320px");
			}
			
			img.attr("src", $(this).attr("src"));
				
			div.append(text);
			div.append(img);
			div.append(text2);
			
	
			var html=div;
				return html; 
			} 
		});
		
		
		
		
	
	},3000);


$("a[href*='logout.php']").bind("click",function(){

	if(window.confirm("確定登出？")){
		
		notifyCenter("系統正在登出中...");
		//FB.Connect.logout();
		$.ajax({
			type: "POST",
			url: "ajax_logout.php",
			success: function(msg){
			
			
				
				window.setTimeout(function(){
					
					FB.logout(function(response) {
						fbLoutoutforum();
					});
				},2000);
		
				
		
		
			}
		});	
		
	
	
	
		
	}
	return false;
});




$("a[href*='login.php']").bind("click",function(){
	fbLoginPopup();
	//fbLoginPermission(fbLoginforum);
	return false;
});

    
	if(document.location.href.indexOf("#last")>=0){				
		var targetOffset = $("#last_div").prev().find("table:last").offset().top-80;
		
		$('html,body,.fbbody').animate({scrollTop: targetOffset}, 1000);

	}
	


	$("#RuleBtn").bind("click",function (){
		$(".RuleContent").toggle();
	});

	$(" .Search input.text").bind("focus",function (){
		var oldColor=$(this).css("border-color");
	
		$(this).css({
		"border-color":"#39599C"
		});
		
		$(this).prev().css({
		"border-color":"#39599C"
		});
		
		$(this).bind("blur",function (){
		
		
			$(this).css({
			"border-color":oldColor
			});
			
			$(this).prev().css({
			"border-color":oldColor
			});
		});
		
	});	

	


		
	  if (window.top!=window.self){	
	
			
			jQuery.each(jQuery.browser, function(i, val) {
	
				if(i=="mozilla" ){
					/*$(".fbbody").css({
					  
					  height:"100%"
					  });*/
					  
					/*FB.CanvasClient.startTimerToSizeToContent();*/
					 
				 }
			});
	
			
      }else{
      /*,
			  "overflow-y":"auto"*/
	
			window.setTimeout(function(){
			 $(".fbbody").css({

				height:"auto"
			  });
			},50);
	
			window.setTimeout(function(){
			 $(".fbbody").css({

				height:"auto"
			  });
			},2000);		
			window.setTimeout(function(){
			 $(".fbbody").css({

				height:"auto"
			  });
			},3000);
			
		
			
			jQuery.each(jQuery.browser, function(i, val) {
				if(i=="mozilla" ){
				
						
				 }
				 
			});
      
      }

/* end ready */
});



/* ready */
$(function(){

	
	$(".funCheckMemberFBstatus").bind("click",function (){
		funCheckMemberFBstatus();
		return false;
	});
	
	$(".sendToFriend").bind("click",function (){


		fbCheckLogin(function(){
			
			/*
			var url="/ajax_sendtofriend.php";
		
			$.fn.colorbox({
			transition:'none', 
			title:"邀請朋友",
			overlayClose:false,
			iframe:true,
			href:url,
			width:650,
			height:620,
			onClosed:function(){
				funCheckMemberFBstatus();
			},
			opacity:0.4
			
			
			},function(){
				$("#cboxLoadedContent").css("background-color","#ffffff");
			});
			
			*/
			
				
			if($("#tid").val()===undefined){
				var url="/ajax_sendtofriend.php";
			}else{
				var url="/ajax_sendtofriend.php?id="+$("#tid").val();
			}
			window.open(url);
			
			return false;
			//return funBox(url);
			
		});
		
		return false;
	
	});

});



/* ready*/
$(document).ready(function(){


	$('.lightbox').colorbox({opacity:0.4});
	
	$('.addbookmark').bind("click",function(){
		funCheckBookmark();
		return false;
	});	
	

			
	$(".loginwithpermission").bind("click",function(){
	
			fbLoginPermission(funPublishFeed);
			return false;
	});
		
	$('.fan').bind("click",function(){
		funCheckFan();
		return false;

	});
	
			
				
	funFocusToSelect($("input.text"));
	
	$("#previewMessage").bind("click",function(){
		funBox("/ajax_previewmessage_frame.php");
		
		window.setTimeout(function(){
		
			$.ajax({
				type: "POST",
				url: "ajax_previewmessage.php",
				data: $("#newmessage").serialize(),
				success: function(msg){
			
					$("#divPreview").html(msg);	
					//alert(msg);
				}
			});	
			
			
			var targetOffset = $("#divPreview").offset().top-30;
		
			$('html,body,.fbbody').animate({scrollTop: 0}, 1000);
			
		},2000)
	
		
		
		/*
		var divPreivew=$(document.createElement('div'));
		divPreivew.attr("id","divPreivew");
		
		divPreivew.css({
		"position" : "absolute"
		});
		top=0;
		left=0;
		
		divPreivew.css({
		"color" : "#333333",
		"padding" : "2px 5px 2px 5px",
		"background" : "#fff9d7",
		"border" : "1px solid #e2c822",
		"top" : top+"px",
		"left" : left+"px"
		});
		
		divPreivew.html(msg);	
		$('body').append(divPreivew);
		*/
	});	
	
	$("#removeQuote").bind("click",function(){
		//$("#message").focus().val(funRemoveQuote($("#message").val())).focus();
		$("#message").val(funRemoveQuote($("#message").val()));
		funFocusToLast($("#message"));
	});
	
	
		
		/*
			var regexVideoId = link.match(/(v=|v\/)([a-zA-Z0-9_-]+)&?/i)*/

	


	
	if(document.location.href.indexOf("newtopic=1")>=0){				
		window.setTimeout(function(){
			funPublishFeed();
		},2000);

	}
	
		
	if(document.location.href.indexOf("share=1")>=0){		

		window.setTimeout(function(){
			funPublishFeedGuest();
		},2000);

	}
	

	
	$("#url").bind("click",function(){
		$(this).select();
	});


	$("#memberSetting").bind("click",function(){
		var url="/ajax_membersetting.php";
		
		$.fn.colorbox({
		transition:'none', 
		title:"會員設定",
		overlayClose:false,

		href:url,
		width:453,
		height:506,
		onClosed:function(){
	
		},
		opacity:0.4
		
		
		},function(){
			$("#cboxLoadedContent").css("background-color","#ffffff");
		});
	});
	

	/*
	
	$("#memberSetting").menu({
	target:"/ajax_membersetting.php",
	direction: 'bottom,left'
	});	
	*/
		
	
	$("#favMore").menu({
	target:"/ajax_favmore.php",
	direction: 'top,middle'
	});		
		
	
	$("#favMore2").menu({
	target:"/ajax_favmore.php",
	direction: 'top,right'
	});		

	$("#favMore3").menu({
	target:"/ajax_favmore.php",
	direction: 'top,middle'
	});		
	
			
	
	$("#addToFav").bind("click",function(){
		var id=$("#tid").val();


		$.ajax({
		type: "POST",
		url: "ajax_addtofav.php",
		data: "id="+id,
		success: function(msg){
			
			if(msg!="" && msg.indexOf("ok")>=0){
				/*$("#addToFav").effect("highlight", {color:"#ffffff"},2000);*/
				 var obj=$("#addToFav");
				 
				 funToolTips($("#addToFav"),"已成功訂閱。");
                          
                          
			}
			if(msg.indexOf("login")>=0){
				alert("請先登入。");
			}
			
			
	
		}
		});
								
	});
	
	

	$(".select a").bind("click",function(){
		 /* */
		/*var table=($(this).parents().filter('table'));
	
		alert(table.find('.PostContent').select()); */
		/*css select*/ 

		/*post_pid*/
								
	});
		
		
	$(".getNewPost").bind("click",function(){
		var tid=$("#tid").val();
		var page=$("#page").val();
		var totalpage=$("#totalpage").val();
	
		
		var readcount=(parseInt(page)*50-50)+$(".PostList .post_pid").length;	
		
		
		var lastcounter=$(".PostList .post_pid:last").html().replace("#","");	
	
		var lastpid=$(".PostList table:last").attr("id").replace("pid","");					
/*PostList*/

	
	var opts={	
			"tid":tid,
			"lastpid":lastpid,
			"readcount":readcount
			};			
	funGetPost(opts);	


		
			/* protect button */	
				/*$(this).attr("disabled",true);*/
				$(this).hide();
				
				
				var targetObj=$(this);
				
				targetObj.after('<span><img src="images/ajax-loader.gif"/></span>');
				window.setTimeout(function(){
					$('.getNewPost + span').remove();
					targetObj.show();
				 },2000);
		    /* protect button */
			return false;
	});
	
	
	$(".TopicList table tr td .hasNew").each(function(){
			
		 var targetObj=$(this).parent().parent();
		 var oldcolor=$(this).css("background-color");

		 targetObj.css("background-color","#E0FFDD");
		 /*window.setTimeout(function(){
			targetObj.css("background-color",oldcolor);
		 },8000);*/

		
	});
	
	


	$("#newmessage").keypress(function(e){
		if(e.ctrlKey && e.which == 13 || e.which == 10) {
			$("#newmessage").submit();
		} else if (0) {
		/*e.shiftKey && e.which==13 || e.which == 10*/
			$("#newmessage").submit();
		}
	
	});

	$('#newmessage').bind("submit",function(){
	
		var formObj=this;
		
		/*formObj.action="ajax_postmessage2db.php";
		formObj.target="_blank";
		return true;*/
	
		var targetObj=$("#message");
			
		
		if($("#topic_input").val()==""){
			alert("請輸入主題。");	
			$("#topic_input").focus();
				var targetOffset = $("#topic_input").offset().top-30;
		
			$('html,body,.fbbody').animate({scrollTop: targetOffset}, 1000);
			return false;
		}	
			
		if($("#security_code").val()==""){
			alert("請輸入正確驗證碼。");	
			
			var targetOffset = $("#security_code").offset().top-30;
		
			$('html,body,.fbbody').animate({scrollTop: targetOffset}, 1000);
	
			
			
			window.setTimeout(function(){
				$("#security_code").focus();
			},1000);
	
			return false;
		}	
		
		if($("#message").val()==""){
			alert("請輸入內容。");	
			funFocusToLast($("#message"));
			return false;
		}		

				
		var targetObj2=$("#FormSubmitBtn");
		
		targetObj.attr("readonly",true);
		targetObj.css("background","#EFEFEF");
		
		var oldValue=targetObj2.val();
		targetObj2.attr("disabled",true);
		targetObj2.val("送出中...");

		//stargetObj2.hide();
		window.setTimeout(function(){
			targetObj.attr("readonly",false);
			targetObj.css("background","");
			
			targetObj2.attr("disabled",false);
			targetObj2.val(oldValue);

			//targetObj2.show();
		 },5000);
		 			
		$.ajax({
		type: "POST",
		url: "ajax_postmessage2db.php",
		data: $(formObj).serialize(),
		success: function(msg){
	
			if(msg.indexOf("error")>=0){
					
				if(msg.indexOf(",topic")>=0){
					alert("請輸入主題。");				
				}	
				
				if(msg.indexOf("long")>=0){
					alert("您的內容太長。");				
				}	
				
				if(msg.indexOf("maxquotatoday")>=0){
					alert("您已發表太多主題。");				
				}					
				
				if(msg.indexOf("topic")>=0){
					alert("請輸入主題。");				
				}			
								
				if(msg.indexOf("security_code")>=0){
					alert("請輸入正確驗證碼。");				
				}
				
				if(msg.indexOf("message")>=0){
					alert("請輸入內容。");				
				}	
				
				
			
			}
				
			if(msg.indexOf("ok")>=0){
		
				var msg=msg.split(",");
				var status=msg[0];
				var action=msg[1];
				var tid=msg[2];
				var pid=msg[3];
				var lastpage=msg[4];
				$("#message").val("");
				if(action=="newpost"){
				
					var page=parseInt($("#page").val());
					
					lastpage=parseInt(lastpage,10);
				
					if(lastpage > page){
						document.location="view.php?id="+tid+"&page="+lastpage;
					}else{
						
						var readcount=(parseInt(page)*50-50)+$(".PostList .post_pid").length;	
						var lastpid=$(".PostList table:last").attr("id").replace("pid","");	
						var opts={	
								"tid":tid,
								"lastpid":lastpid,
								"readcount":readcount
								};			
						funGetPost(opts);
		
					}
				
					
				
				}else if(action=="newtopic"){
					document.location="view.php?id="+tid+"&newtopic=1";
				
				}else if(action=="editpost"){
					
					funEditPostSuccessful(pid);
				
				}

		
				// restore
					$("#message").show();
					$("#selectAll  ,#largerText ,#removeQuote").show();
					$("#divPreivew").hide();
					$("#divPreivew").unbind("click");
					$("#divPreivew").remove();
					funFocusToLast($("#message"));			
				

			}
	
		}
		});
		
	 
	 
		return false;
	});
	
	

	
	$("#selectAll").bind("click",function(){
		$("#message").select();
		return false;
	});
	
	$("#share").bind("click",function(){
		$(this).blur();
		funPublishFeed();
		return false;
	});	

	
	
	$(".allowpublish_stream").bind("click",function(){
		funCheckPermission();
		return false;
	});
	

	$(".fbshare").bind("click",function(){

		$(this).blur();
		funPublishFeed();
		return false;
	});	
	
		
	$("#showEdit").bind("click",function(){
	
		$(".edit").toggle();
		return false;
	});
	$("#largerText").bind("click",function(){

		$("#message").css({
		width:"100%",
		height:($("#message").height()*2)+"px"
		});
		return false;
	});
	
	$("#message").bind("change",function(){
		$("#textCount").text( $("#message").val().length );
		return false;
	});
	/*
	$("td.PostContent img[src$='jpg']").each(function(){ */

	
	/*   jason */
	$("#admin_topic_edit").each(function(){
		$(this).css("cursor","pointer");
	})


	$("#admin_topic_edit").menu({
	target:"/ajax_admin_topicsetting.php?id="+$("#tid").val(),
	direction: 'bottom,right'
	});	
		
			
	$("#admin_topic_edit").bind("click",function(){
	
	//funBox("ajax_admin_topicsetting.php");
	
	/* ready*/	
	});

});
	
	


function funSaveCover(){
	var cover=funGetCover();

  if(cover!=""){
	var str="id="+$("#tid").val()+"&tid_code="+$("#tid_code").val()+"&cover="+cover;
	$.ajax({
		type: "POST",
		url: "ajax_setcover.php",
		data: str,
		success: function(msg){
			//alert("ok"+msg);	
		}
	});
  }else{

	var str="id="+$("#tid").val()+"&tid_code="+$("#tid_code").val()+"&clearcover=1";
	$.ajax({
		type: "POST",
		url: "ajax_setcover.php",
		data: str,
		success: function(msg){
			//alert("error "+msg);	
		}
	});  
  
  }	  
}

	
function funEditPost(obj){

			$(obj).bind("click",function(){
				
				obj.data("bind",1);
				
				
				var pid=obj.attr("rel");
				var table=$("#pid"+pid);
				var quote=$("#quote_message"+pid);
				var target=table.find(".Content");
				
				/*var editarea=$(document.createElement('div'));
				var edit_textarea=$(document.createElement('textarea'));
				edit_textarea.val(quote.val());
				editarea.append(edit_textarea);
				
				*/
				
				
				
				/*target.hide();*/
			
			
			/* mask close */
				var mask2=$(document.createElement('div'));
				mask2.addClass("mask2");
				
				mask2.bind("click", function(){
				
					$("#message").css({
					height:(125)+"px"
					});
					
					
					$("#message").val("");
					$("#eid").val("");
					$("#eid_code").val("");
					$("#newmessage").find("h2").html("發表您的回覆");	
					$("#newmessage").css({
							"position":"",
					
						"width":"100%",
						"margin-left":"0px",
						
				
						"top" : "0px"
					});
					
				
					$(this).remove();
				
				});
				
				
				
				var myheight=$(document).height()-10;
				
				/* css */
				mask2.css({
				background:"#000000",
				position:"absolute",
				"z-index":2,
				width:"100%",
				height:myheight,
				opacity:"0.4",
				top:(0),
				left:(0)
				});
				
				$(".fbbody").append(mask2);
			 
				var obj_pos=$(table).position();
			
				var left=obj_pos.left;
				var top=obj_pos.top;
				top=top+(0)-200;
			
			
				$("#eid").val(table.find(".editpost_id").val());
				$("#eid_code").val(table.find(".editpost_code").val());
			
			
				$("#message").css({
					height:(250)+"px"
					});
					
				$("#newmessage").css({
					"position":"absolute",
					"z-index":3,
					"width":"680px",
					"margin-left":"40px",
					"top" : top+"px"
				});
				
				$("#newmessage").find("h2").html("編輯此回覆");	
				
				
				
				/*======================*/
				var mydata="pid="+pid;
				$.ajax({
					type: "POST",
					url: "ajax_getpostbyid.php",
					data: mydata,
					success: function(msg){
						if(msg.indexOf("error")>=0){
								
							if(msg.indexOf(",edit")>=0){
								alert("Error");				
							}	
							
						}else if(msg.indexOf("{forumhk_split}")>=0){
							var msg=msg.split("{forumhk_split}");
							var message=msg[0];
							var quote_message=msg[1];
								var output=''+quote_message+''+"\r\n";
								$("#message").val(output);
								funFocusToLast($("#message"));
			
						}
					}
					
				});		
				/*======================*/
				
				
			});			


}
	
	
function funProcessContent(){

		
		
	$(".admin_edit").each(function(){
		$(this).css("cursor","pointer");
		
		if($(this).data("bind")!=1){
			// bind
			
			/*========================*/
			funEditPost($(this));
			/*========================*/
		}
	})
	


		/* ========== */
		$(".PostContent a[href*='youtube.com/watch']").each(function(){
			funYoutube($(this));
		
			
		});		
		
		
		$(".PostContent a[href*='tudou.com/programs/view/']").each(function(){
			//funTudou($(this));
			
		});	
		
		$(".PostContent a[href*='video.online.hk/watch/']").each(function(){
			funVideoOnline($(this));
			
		});	
		
		$(".PostContent a[href*='youku.com/v_show/id_']").each(function(){
			funYouku($(this));
			
		});	
		
		
		$(".PostContent a[href*='facebook.com/video/video.php']").each(function(){
			funFacebookVideo($(this));
			
		});	
				
		
				/* ========== */
		$("td.PostContent img.img").each(function(){
			resizeME(this);
			$(this).bind("load",function(){
				resizeME(this);
			});		
			
		});
		
		
		
		funSaveCover();
}


// end ready 
$(function(){
	funProcessContent();
});
	
	

/* ========================================================== */
/* ========================================================== */
/* ========================================================== */
/* ========================================================== */
/* ========================================================== */
/* ========================================================== */
/* ========================================================== */
/* ========================================================== */
/* ========================================================== */
/* ========================================================== */
/* ========================================================== */
/* ========================================================== */











function InsertText( text, splittable ) {
	var TextArea = document.getElementById("message");
	var l;

	if(TextArea.style.display=="none"){		
			restoremessage();
	}
	
		$(" #fontsize , #fontcolor").attr("selectedIndex",0);

	if (TextArea) {

		TextArea.focus();
		if (splittable){
			l = text.split(/,/);
		}else{
			l = text;
		}	
		if ((typeof TextArea.selectionStart) != 'undefined') {	// Mozilla
			var ti = TextArea.selectionEnd, ts = TextArea.selectionStart;	// Copied from the Glomerulus
			if (l instanceof Array) {
				if (ti != ts) {
					TextArea.value = TextArea.value.substring(0, ts) + l[0] + TextArea.value.substring(ts, ti) + l[2] + TextArea.value.substr(ti);
					TextArea.selectionStart = ts + l[0].length;
					TextArea.selectionEnd = ti + l[2].length - 1;
				
					
				} else {
				
					TextArea.value = TextArea.value.substring(0, ts) + l[0] + l[1] + l[2] + TextArea.value.substr(ti);
					TextArea.selectionStart = ti + l[0].length;
					TextArea.selectionEnd = TextArea.selectionStart + l[1].length;
				}
			} else {
				TextArea.value = TextArea.value.substring(0, ts) + l + " " + TextArea.value.substr(ti);
				TextArea.selectionStart = TextArea.selectionEnd = ti + l.length + 1;
			}
			
		
			var scroll=(parseInt(TextArea.selectionStart)/parseInt(TextArea.value.length));
		
			
		} else if (document.selection) {						// IE
			var r = document.selection.createRange();			// No Glomerulus here ;-(
			if (l instanceof Array) {
				if (r.text !== ""){
		
					r.text = l[0] + r.text + l[2];
					
				}else{
					
					TextArea.focus();
					r.text = l[0] + l[1] + l[2];
					r.select();
					     					
				}
			} else{
			
			
				r.text = l + " ";
				r.select();
			}		
										// Useless
		} else {												// Neither.
			TextArea.value += text + " ";
		}

			TextArea.focus();
		
	}


}


function InsertList() {
	var TextArea = document.getElementById("message");
	if(TextArea.style.display=="none"){		
			restoremessage();
	}
	
	var lll = "[list]\n[*]第一項[/*]\n[*]第二項[/*]\n[*]第三項[/*]\n[/list]";
	
	if (TextArea) {
		TextArea.focus();
		if ((typeof TextArea.selectionStart) != 'undefined') {	// Mozilla
			var ti = TextArea.selectionEnd, ts = TextArea.selectionStart;
			if (ti != ts) {
				TextArea.value = TextArea.value.substring(0, ts) + "[*]" + TextArea.value.substring(ts, ti) + "[/*]" + TextArea.value.substr(ti);
				TextArea.selectionEnd = ti + 7;
			} else {
				TextArea.value = TextArea.value.substring(0, ts) + lll + TextArea.value.substr(ti);
				TextArea.selectionEnd = ti + lll.length;
			}
			TextArea.selectionStart = ts;
		} else if (document.selection) {						// IE
			var r = document.selection.createRange();
			if (r.text !== ""){
				r.text = "[*]" + r.text + "[/*]";
			}else{
				r.text = lll;
			}
		} else {												// Neither.
			TextArea.value += lll + " ";
		}
		TextArea.focus();
	}
}
/* ========================================================== */

	
	
	

function notifyCenter( msg,type) {
var target=$(document.createElement('div'));

 $('body').append(target);
	/*var target=obj.find("+ div");*/
	target.css({
		"position" : "absolute"
	});
	var top;
	var left;
	
	top=-1000;
	left=-1000;
 	target.css({
		"color" : "#333333",
		"padding" : "2px 5px 2px 5px",
		"background" : "#fff9d7",
		"border" : "1px solid #e2c822",
		"top" : top+"px",
		"left" : left+"px"
	});
		

	target.html('<table cellpadding="2" cellspacing="0" border="0"><tr><td nowrap="nowrap">'+msg+'</td></tr></table>');
		
	top=0;



var top=$('html').scrollTop()+60;
var left=($('body').width()-target.width())/2;


	target.css({
		"top" : top+"px",
		"left" : left+"px"
	});
		

	target.html('<table cellpadding="2" cellspacing="0" border="0"><tr><td nowrap="nowrap">'+msg+'</td></tr></table>');
	



	
	/*target.append('<div class"clear"></div>');*/
	window.setTimeout(function(){
		$(target).hide();
		
		window.setTimeout(function(){
			$(target).remove();
		},2000);
	 },3000);
	
}


function fbLoutoutforum(){
	document.location='logout.php?to='+encodeURIComponent($("#url").val());
	return false;
}
   

function fbLoginforum(){

	notifyCenter("系統正在登入中...");
	document.location=$("#url").val();
	return false;
}



function funGetCover(){
  var cover="";
  var obj="";
	  var  first=$(".PostList .PostContent:first");
	  
	  if(cover===""){
		first.find(" img[src*='jpg'] , img[src*='JPG'] ").each(function(){
			if($(this).attr("width")>=200 && cover===""){
				cover=$(this).attr("src");
				obj=$(this);
			}
		});
	  }

	 
	  if(cover===""){
		  first.find(" img[src*='jpg'] , img[src*='JPG'] ").each(function(){
			if($(this).attr("width")>=100 && cover===""){
				cover=$(this).attr("src");
				obj=$(this);
			}
		  });
	  }
	

	  
	  if(cover===""){
		first.find(" img[src*='png']  , img[src*='PNG'] ").each(function(){
		if($(this).attr("width")>=200 && cover===""){
			cover=$(this).attr("src");
			obj=$(this);
		}
		});
	  }
	  	

	  if(cover===""){
		  first.find(" img[src*='png'] , img[src*='PNG'] ").each(function(){
			if($(this).attr("width")>=100 && cover===""){
				cover=$(this).attr("src");
				obj=$(this);
			}
		  });
	  }
	  
	  
	  
	  // fx3
	  if(obj &&  obj.attr("width")==87 && obj.attr("height")==17){
			cover="";
	  }
	  
	  // ie6
	  if(obj &&  obj.attr("width")==100 && obj.attr("height")==30){
			cover="";
	  }	  
	  	  
	  
	  
	  
	  
	  
	
	
	  if(cover===""){
		  var  first=$(".PostList .PostContent");
		  first.find(" img[src*='jpg'] , img[src*='JPG']  ").each(function(){
			
			if($(this).attr("width")>=200 && cover===""){
				cover=$(this).attr("src");
				obj=$(this);
			}
		  });	  
	  }
	  
	  if(cover===""){
		  var  first=$(".PostList .PostContent");
		  first.find(" img[src*='jpg'] , img[src*='JPG'] ").each(function(){
			if($(this).attr("width")>=100 && cover===""){
				cover=$(this).attr("src");
				obj=$(this);
			}
		  });	  
	  }	  
	  
	  
	  // fx3
	  if( obj && obj.attr("width")==87 && obj.attr("height")==17){
			cover="";
	  }
	  
	  // ie6
	  if(obj &&  obj.attr("width")==100 && obj.attr("height")==30){
			cover="";
	  }	  
	  

	  
	  cover=unescape(cover);



	  if(cover===""){
		cover="";
	  }

	return cover;
}



function funBoxClose(){
	
	$("#player").attr("src","");
	$("#box_content").remove();
	$(".mask").remove();	
}	

    

			
function funBox(url){
/*	var url="ajax_sendtofriend.php?id=482"; */
	

	
	var myheight=$(document).height()-55;


	/* mask close */
	var mask=$(document.createElement('div'));
	mask.addClass("mask");
	mask.bind("click", function(){
		/*$("#player").attr("src","");*/
		$("#box_content").remove();
		$(this).remove();
	
	});
	
	/* css */
	mask.css({
	background:"#000000",
	position:"absolute",
	"z-index":2,
	width:"100%",
	height:myheight,
	opacity:"0.4",
	top:(0),
	left:(0)
	});
	
	$(".fbbody").append(mask);
	
	$(".video_area").css({
	"z-index":3
	});
	


	
	
	
	var content=$(document.createElement('div'));
	content.attr("id","box_content");

	var my_top=(10)+"px";
	var my_left=(50)+"px";
	content.html("xaxxxa");
	content.css({
	"background":"#ffffff",
	"border":"0px solid #ff0000",
	"position":"absolute",
	"z-index":30,
	"width":'200px',
	"height":'200px',
	"top":(my_top),
	"left":(my_left)
	});

	/*$(".fbbody").append(content);*/




	$.ajax({
		type: "GET",
		url: url,
		async : false,
		success: function(msg){
			
			
			content.html(msg);
		
			content.find(".close").bind("click",function(){
				
				
				$("#player").attr("src","");
				$("#box_content").remove();
				$(".mask").remove();			
			});
			
			/*content.html('axaxax');*/
		
			$(".fbbody").append(content);
		
			var targetOffset = $("#box_content").offset().top-30;
		
			//$('html,body,.fbbody').animate({scrollTop: targetOffset}, 1000);
		}
	});
	
	return false;
}





	
function restoremessage(){
	$("#message").show();
	$("#selectAll  ,#largerText ,#removeQuote").show();
	$("#divPreivew").hide();
	$("#divPreivew").unbind("click");
	$("#divPreivew").remove();
	
	funFocusToLast($("#message"));	
}
function funFocusToLast(jq){
	jq[0].scrollTop = jq[0].scrollHeight;
	jq.focus();
}
		    
function addSlashes(str){
var rg;
rg=/('|"|\\)/ig;
var newstr=str.replace(rg, "\\$1");
return newstr;

}
function funUpdateFacebookLogo(){

	FB_RequireFeatures(["Api"], function(){
			// Create an ApiClient object, passing app's API key and 
			// a site relative URL to xd_receiver.htm
			 FB.init("526e408de8de93056b64ed280aef08ff", "include/xd_receiver.htm");
	
		
			var api = FB.Facebook.apiClient;

			// require user to login 
			api.requireLogin(function(exception){
				//alert("Current user id is " + api.get_session().uid);
				// Get friends list 
				var uid=api.get_session().uid;
	
				api.users_getInfo(uid,['pic_square'], function(result, ex){
					/*window.alert("Exception :"+ex);*/
					
					var str="";
					var myArray=result[0];
					for ( var key in  myArray) {
						str+="&"+key+"="+myArray[key];
					}
					
					funPassInfoOut_logo(str);
		
				});
				 
			});
		});
}

function funPassInfoOut_logo(str){


	$.ajax({
		type: "POST",
		url: "ajax_savefacebooklogo.php",
		data: str,
		success: function(msg){
			
		
			if(msg.indexOf("ok,")>=0){
				
				
				var msg=msg.split(",");
				var status=msg[0];
				var logo=msg[1]+'?rand='+Math.random();
				$("#fb_logo").attr("src",logo);
				$("#fb_logo").show();
				
			
			}else{
				
				alert("error, please try again");
			}
			
			$("#fb_logo").show();
			$("#fb_logo").next().remove();
			
			
			$("#fblogo_btn").show();		
			$("#fblogo_btn").next().remove();				
		}
	});
} 

function funPassInfoOut(str){


	$.ajax({
		type: "POST",
		url: "ajax_getinfofromfacebook.php",
		data: str,
		success: function(msg){
			/*alert(msg);	*/
		}
	});
} 		

function funUpdateFacebookInfo(){

	FB_RequireFeatures(["Api"], function(){
			// Create an ApiClient object, passing app's API key and 
			// a site relative URL to xd_receiver.htm
			 FB.init("526e408de8de93056b64ed280aef08ff", "include/xd_receiver.htm");
	
			
			var api = FB.Facebook.apiClient;
			// require user to login 
			api.requireLogin(function(exception){
				//alert("Current user id is " + api.get_session().uid);
				// Get friends list 
				var uid=api.get_session().uid;
		
				api.users_getInfo(uid,['first_name','last_name','name','birthday','sex','pic_square','profile_url'], function(result, ex){
					/*window.alert("Exception :"+ex);*/
					
					var str="";
					var myArray=result[0];
					for ( var key in  myArray) {
						str+="&"+key+"="+myArray[key];
					}
					funPassInfoOut(str);
		
				});
				 
			});
		});
}

function funPassInfoOut(str){
	var loc="ajax_getinfofromfacebook.php?"+str;

	$.ajax({
		type: "POST",
		url: "ajax_getinfofromfacebook.php",
		data: str,
		success: function(msg){
			/*alert(msg);	*/
		}
	});
} 		


   
   
   
   		function funCenterImg(obj,maxWidth,maxHeight){
		var obj=$(obj);

		var myWidth=$(obj).attr("width");
		var myHeight=$(obj).attr("height");
		$("#logo_width").val(myWidth);
		$("#logo_height").val(myHeight);
		if(myWidth>maxWidth || myHeight>maxHeight){
		/*margin: auto auto;
height:120px;
width:120px;*/
			if(myWidth>maxWidth){
				// 橫
				//$(this).attr("width",maxWidth);
				marginLeft=(myWidth-maxWidth)/2;
				$(obj).css("margin-left",-marginLeft);
				//alert("x");
			}
			if(myHeight>maxHeight){
				//直
				//$(this).attr("height",maxHeight);
				marginTop=(myHeight-maxHeight)/2;
				$(obj).css("margin-top",-marginTop);
				
			}
			
		}else{
			$(obj).css("margin-left",0);
			$(obj).css("margin-top",0);
			
		}
		

		
	}


function funFocusToSelect(obj){
	
	obj.each(function(){
		$(this).bind("focus",function(){
			this.select();
		});
			
	});
}

function youtubeIDextract(url){ 

  var youtube_id; 

  youtube_id = url.replace(/^[^v]+v.(.{11}).*/,"$1"); 

  return youtube_id; 
}

function TudouIDextract(url){ 

  var youtube_id; 

  youtube_id = url.match(/tudou\.com\/programs\/view\/(.*?)\//); 

  return youtube_id[1]; 
}



/*=============================*/


function FacebookVideoIDextract(url){ 

	var v_id; 
	var temp="";
	v_id = url.match(/facebook\.com\/video\/video\.php.*?v=(.*?)$/); 
	if(v_id){
		var temp=v_id[1];
		
		if(temp.indexOf("&")>0){
			temp=temp.substring(0,temp.indexOf("&"));
		}
		
	}else{
		return "";
	}

  
  return temp; 
}

function funFacebookVideo(obj){

		if($(obj).next().hasClass("playerbutton")){

			return false;
		}
	/*===*/

		var link=$(obj).attr("href");
		var u_div=$(document.createElement('div'));
		var u_vid=FacebookVideoIDextract(link); /* main */

		if(u_vid==""){ return false; }
		$(obj).after(u_div);
		
		
		var btn_text=$(document.createElement('span'));
		var btn=$(document.createElement('span'));
		btn.addClass("playerbutton");
		btn.addClass("playerbutton_play");
		btn.append(btn_text);
		btn.data("vid",u_vid);

		btn_text.html("播放");
		btn.attr("title","[按此播放]");
		$(obj).after(btn);
		
		
		
		var playerWidth=500;
		var playerHeight=340;
		
		btn.bind("click",function(){
		
			if($(this).next().hasClass("playerDiv")){
				// remove
				$(this).next().remove();
				btn_text.html("播放");
				var u_div=($(this).next());
				u_div.show();
			}else{
				var u_div=($(this).next());
				u_div.hide();
				
				btn_text.html("關閉");
				// create
				var playerDiv=$(document.createElement('div'));
			
				playerDiv.addClass("playerDiv");
				var vid=$(this).data("vid");
		
				/* =================================== */
				var videoObj = document.createElement("ojbect");
				var videoParam1 = document.createElement("param");
				var videoParam2 = document.createElement("param");
				var videoParam3 = document.createElement("param");
				var videoParam4 = document.createElement("param");
				var videoEmbed = document.createElement("embed");
			
				
				var videoLink = "http://www.facebook.com/v/"+vid; /* main */
				var flashvars = "ShowId=0&Cp=0&Tid=0&VideoIDS="+vid+"&isAutoPlay=true&Version=/v1.0.0572&winType=interior&iku_num=0&showAd=0"; /* main */
				flashvars = ""; // main 
			
				videoObj.setAttribute("width", playerWidth);
				videoObj.setAttribute("height", playerHeight);
				videoObj.setAttribute("src", videoLink);  /* main */
				videoObj.setAttribute("flashvars", flashvars);  /* main */
				
				videoParam1.setAttribute("name", "movie");
				videoParam1.setAttribute("value", videoLink);
				
				videoParam2.setAttribute("name", "allowFullScreen");
				videoParam2.setAttribute("value", "true");
				
				videoParam3.setAttribute("name", "allowscriptaccess");
				videoParam3.setAttribute("value", "always");
				
				videoParam4.setAttribute("name", "wmode");
				videoParam4.setAttribute("value", "transparent");
				
				
				videoEmbed.setAttribute("src", videoLink); /* main */
				videoEmbed.setAttribute("flashvars", flashvars);  /* main */
				videoEmbed.setAttribute("type", "application/x-shockwave-flash");
				videoEmbed.setAttribute("allowfullscreen", "true");
				videoEmbed.setAttribute("allowscriptaccess", "always");
				videoEmbed.setAttribute("wmode", "transparent");
				videoEmbed.setAttribute("width", playerWidth);
				videoEmbed.setAttribute("height", playerHeight);
				
				videoObj.appendChild(videoParam1);
				videoObj.appendChild(videoParam2);
				videoObj.appendChild(videoParam3);
				videoObj.appendChild(videoParam4);
				videoObj.appendChild(videoEmbed);
				
				playerDiv.append(videoObj);
				$(this).after(playerDiv);
				/* =================================== */
			}
			
		
			
			
		
		});		
		
		btn.click(); // auto embed for no cover video 100829
/*===*/
}	


/*=============================*/


function YoukuIDextract(url){ 

  var youtube_id; 

  youtube_id = url.match(/youku.com\/v_show\/id_(.*?)\.htm/); 


  return youtube_id[1]; 
}

function funYouku(obj){

		if($(obj).next().hasClass("playerbutton")){

			return false;
		}
	/*===*/

		var link=$(obj).attr("href");
		var u_div=$(document.createElement('div'));
		var u_vid=YoukuIDextract(link); /* main */

		$(obj).after(u_div);
		
		
		var btn_text=$(document.createElement('span'));
		var btn=$(document.createElement('span'));
		btn.addClass("playerbutton");
		btn.addClass("playerbutton_play");
		btn.append(btn_text);
		btn.data("vid",u_vid);

		btn_text.html("播放");
		btn.attr("title","[按此播放]");
		$(obj).after(btn);
		
		
		
		var playerWidth=500;
		var playerHeight=340;
		
		btn.bind("click",function(){
		
			if($(this).next().hasClass("playerDiv")){
				// remove
				$(this).next().remove();
				btn_text.html("播放");
				var u_div=($(this).next());
				u_div.show();
			}else{
				var u_div=($(this).next());
				u_div.hide();
				
				btn_text.html("關閉");
				// create
				var playerDiv=$(document.createElement('div'));
			
				playerDiv.addClass("playerDiv");
				var vid=$(this).data("vid");
		
				/* =================================== */
				var videoObj = document.createElement("object");
				var videoParam1 = document.createElement("param");
				var videoParam2 = document.createElement("param");
				var videoParam3 = document.createElement("param");
				var videoParam4 = document.createElement("param");
				var videoEmbed = document.createElement("embed");
			
				/*isAutoPlay=true&*/
				var videoLink = "http://player.youku.com/player.php"; /* main */
				var flashvars = "ShowId=0&Cp=0&Tid=0&VideoIDS="+vid+"&Version=/v1.0.0572&winType=interior&iku_num=0&showAd=0"; /* main */
				/*flashvars = "";*/ // main 
			
				videoObj.setAttribute("width", playerWidth);
				videoObj.setAttribute("height", playerHeight);
				videoObj.setAttribute("src", videoLink);  /* main */
				videoObj.setAttribute("flashvars", flashvars);  /* main */
				
				videoParam1.setAttribute("name", "movie");
				videoParam1.setAttribute("value", videoLink);
				
				videoParam2.setAttribute("name", "allowFullScreen");
				videoParam2.setAttribute("value", "true");
				
				videoParam3.setAttribute("name", "allowscriptaccess");
				videoParam3.setAttribute("value", "always");
				
				videoParam4.setAttribute("name", "wmode");
				videoParam4.setAttribute("value", "transparent");
				
				
				videoEmbed.setAttribute("src", videoLink); /* main */
				videoEmbed.setAttribute("flashvars", flashvars);  /* main */
				videoEmbed.setAttribute("type", "application/x-shockwave-flash");
				videoEmbed.setAttribute("allowfullscreen", "true");
				videoEmbed.setAttribute("allowscriptaccess", "always");
				videoEmbed.setAttribute("wmode", "transparent");
				videoEmbed.setAttribute("width", playerWidth);
				videoEmbed.setAttribute("height", playerHeight);
				
				videoObj.appendChild(videoParam1);
				videoObj.appendChild(videoParam2);
				videoObj.appendChild(videoParam3);
				videoObj.appendChild(videoParam4);
				videoObj.appendChild(videoEmbed);
				
				playerDiv.append(videoObj);
				$(this).after(playerDiv);
				/* =================================== */
			}
			
			
			
		
	});	
	
	btn.click(); // auto embed for no cover video 100829
/*===*/
}
/*=============================*/
function VideoOnlineIDextract(url){ 

  var youtube_id; 

  youtube_id = url.match(/video\.online\.hk\/watch\/(\d{0,10})/); 

  return youtube_id[1]; 
}

function funVideoOnline(obj){

		if($(obj).next().hasClass("playerbutton")){

			return false;
		}
	/*===*/

		var link=$(obj).attr("href");
		var u_div=$(document.createElement('div'));
		var u_vid=VideoOnlineIDextract(link); /* main */
		
		$(obj).after(u_div);
		
		
		var btn_text=$(document.createElement('span'));
		var btn=$(document.createElement('span'));
		btn.addClass("playerbutton");
		btn.addClass("playerbutton_play");
		btn.append(btn_text);
		btn.data("vid",u_vid);

		btn_text.html("播放");
		btn.attr("title","[按此播放]");
		$(obj).after(btn);
		
		
		
		var playerWidth=500;
		var playerHeight=340;
		
		btn.bind("click",function(){
		
			if($(this).next().hasClass("playerDiv")){
				// remove
				$(this).next().remove();
				btn_text.html("播放");
				var u_div=($(this).next());
				u_div.show();
			}else{
				var u_div=($(this).next());
				u_div.hide();
				
				btn_text.html("關閉");
				// create
				var playerDiv=$(document.createElement('div'));
			
				playerDiv.addClass("playerDiv");
				var vid=$(this).data("vid");
		
				/* =================================== */
				var videoObj = document.createElement("object");
				var videoParam1 = document.createElement("param");
				var videoParam2 = document.createElement("param");
				var videoParam3 = document.createElement("param");
				var videoParam4 = document.createElement("param");
				var videoEmbed = document.createElement("embed");
				var videoLink = "&num=2&id="+vid+"&autostart=true"; /* main */
			
				videoObj.setAttribute("width", playerWidth);
				videoObj.setAttribute("height", playerHeight);
				videoObj.setAttribute("src", "http://video.online.hk/bplayer.swf");  /* main */
				videoObj.setAttribute("flashvars", videoLink);  /* main */
				
				videoParam1.setAttribute("name", "movie");
				videoParam1.setAttribute("value", "http://video.online.hk/bplayer.swf");
				
				videoParam2.setAttribute("name", "allowFullScreen");
				videoParam2.setAttribute("value", "true");
				
				videoParam3.setAttribute("name", "allowscriptaccess");
				videoParam3.setAttribute("value", "always");
				
				videoParam4.setAttribute("name", "wmode");
				videoParam4.setAttribute("value", "transparent");
				
				
				videoEmbed.setAttribute("src", "http://video.online.hk/bplayer.swf"); /* main */
				videoEmbed.setAttribute("flashvars", videoLink);  /* main */
				videoEmbed.setAttribute("type", "application/x-shockwave-flash");
				videoEmbed.setAttribute("allowfullscreen", "true");
				videoEmbed.setAttribute("allowscriptaccess", "always");
				videoEmbed.setAttribute("wmode", "transparent");
				videoEmbed.setAttribute("width", playerWidth);
				videoEmbed.setAttribute("height", playerHeight);
				
				videoObj.appendChild(videoParam1);
				videoObj.appendChild(videoParam2);
				videoObj.appendChild(videoParam3);
				videoObj.appendChild(videoParam4);
				videoObj.appendChild(videoEmbed);
				
				playerDiv.append(videoObj);
				$(this).after(playerDiv);
				/* =================================== */
			}
			
			
			
			
		});	
	/*===*/
}	



	
				
/*=============================*/	
	

function funTudou(obj){

		if($(obj).next().hasClass("playerbutton")){

			return false;
		}
	/*===*/

		var link=$(obj).attr("href");
		//alert(link);
		var u_div=$(document.createElement('div'));
		var u_img=$(document.createElement('img'));
		var u_vid=TudouIDextract(link);
		u_img.attr("src",'http://img.youtube.com/vi/'+u_vid+'/0.jpg');
		u_div.addClass("u_div");
		u_img.attr("alt","(Tudou Loading)");

		u_img.attr("title","[按此播放]");
		u_img.css({
			cursor:"pointer"
		});
		u_img.bind("click",function(){
			$(this).parent().prev().click();
			$(this).parent().prev().click();
		});
		$(obj).after(u_div);
		
		
		var btn_text=$(document.createElement('span'));
		var btn=$(document.createElement('span'));
		btn.addClass("playerbutton");
		btn.addClass("playerbutton_play");
		btn.append(btn_text);
		

		btn_text.html("播放");
		btn.attr("title","[按此播放]");
		$(obj).after(btn);
		
		
		
		var playerWidth=500;
		var playerHeight=340;
		
		btn.bind("click",function(){
		
			if($(this).next().hasClass("playerDiv")){
				// remove
				$(this).next().remove();
				btn_text.html("播放");
				var u_div=($(this).next());
				u_div.show();
			}else{
				var u_div=($(this).next());
				u_div.hide();
				
				btn_text.html("關閉");
				// create
				var playerDiv=$(document.createElement('div'));
			
				playerDiv.addClass("playerDiv");
				var vid=TudouIDextract(link);
				
				/* =================================== */
				var videoObj = document.createElement("object");
				var videoParam1 = document.createElement("param");
				var videoParam2 = document.createElement("param");
				var videoParam3 = document.createElement("param");
				var videoParam4 = document.createElement("param");
				var videoEmbed = document.createElement("embed");
				/*var videoLink = "http://www.youtube.com/v/" + playBtn.getAttribute("id") + "&hl=en&fs=1&rel=0" + (GM_getValue("isAutoplay") ? "&autoplay=1" : "&autoplay=0");*/
				var videoLink = "http://www.tudou.com/v/"+vid+"";
			
				videoObj.setAttribute("width", playerWidth);
				videoObj.setAttribute("height", playerHeight);
				videoParam1.setAttribute("name", "movie");
				videoParam1.setAttribute("value", videoLink);
				
				videoParam2.setAttribute("name", "allowFullScreen");
				videoParam2.setAttribute("value", "true");
				
				videoParam3.setAttribute("name", "allowscriptaccess");
				videoParam3.setAttribute("value", "always");
				
				videoParam4.setAttribute("name", "wmode");
				videoParam4.setAttribute("value", "transparent");
				
				videoEmbed.setAttribute("src", videoLink);
				videoEmbed.setAttribute("type", "application/x-shockwave-flash");
				videoEmbed.setAttribute("allowfullscreen", "true");
				videoEmbed.setAttribute("allowscriptaccess", "always");
				videoEmbed.setAttribute("wmode", "transparent");
				videoEmbed.setAttribute("width", playerWidth);
				videoEmbed.setAttribute("height", playerHeight);
				
				videoObj.appendChild(videoParam1);
				videoObj.appendChild(videoParam2);
				videoObj.appendChild(videoParam3);
				videoObj.appendChild(videoParam4);
				videoObj.appendChild(videoEmbed);
				
				playerDiv.append(videoObj);
				$(this).after(playerDiv);
				/* =================================== */
			}
			
			
			
			
		});	
		btn.click(); // auto embed for no cover video 100829
	/*===*/
	}	

function funToolTips(obj,msg){
var target=$(document.createElement('div'));

 $(obj).after(target);
	/*var target=obj.find("+ div");*/
	target.css({
		"position" : "absolute"
	});
 
	var obj_pos=$(obj).position();

   var left=obj_pos.left;
	var top=obj_pos.top;

	
	top=top+$(obj).attr("offSetHeight");
	left=left+0;
	target.css({
		"color" : "#333333",
		"padding" : "2px 5px 2px 5px",
		"background" : "#fff9d7",
		"border" : "1px solid #e2c822",
		"top" : top+"px",
		"left" : left+"px"
	});
		
	/*target.html(msg);*/
	/*target.html('<div stle="white-space: nowrap;">'+msg+'</div>');*/
	target.html('<table cellpadding="0" cellspacing="0" border="0"><tr><td nowrap="nowrap">'+msg+'</td></tr></table>');
	/*target.append('<div class"clear"></div>');*/
	window.setTimeout(function(){
		$(target).hide();
		
		window.setTimeout(function(){
			$(target).remove();
		},2000);
	 },3000);
}
function funRemoveQuote(msg){
	if(msg.lastIndexOf("[/quote]")>=0 && msg.indexOf("[quote]")>=0){
	
		var start=msg.lastIndexOf("[quote]");
		var last=msg.indexOf("[/quote]")+8;

		var part1=(msg.substring(0,start));
		var part2=(msg.substring(last,msg.length));
		msg=jQuery.trim(part1)+jQuery.trim(part2);
		
		
		if(msg!=""){
			return jQuery.trim(msg)+"\r\n";
		}else{
			return "";
		}
		
	}else{
		return msg;
	}
}

	function funEditPostSuccessful(pid){

	var mydata="pid="+pid;
		
		
		$.ajax({
		type: "POST",
		url: "ajax_getpostbyid.php",
		data: mydata,
		success: function(msg){
			if(msg.indexOf("error")>=0){
					
				if(msg.indexOf(",edit")>=0){
					alert("Error");				
				}	
			}else if(msg.indexOf("{forumhk_split}")>=0){
				var msg=msg.split("{forumhk_split}");
				var message=msg[0];
				var quote_message=msg[1];
				
				
				
			/*
			[quote]我之前返學唔得閒搞呢度，
宜家可以花d時間去搞下 admin功能#hoho#[/quote]
#good# #good#

			{forumhk_split}
			*/
			
				// update page
				var table=$("#pid"+pid);
				var quote=$("#quote_message"+pid);
				var content=table.find(".Content");
		
				content.html(message);
				quote.val(quote_message);
				
				
				 var tempObj=$(table);
				 var oldcolor=$(table).css("background-color");

				 $(table).css("background-color","#E0FFDD");
				
				
				notifyCenter("文章已成功編輯。");
				 window.setTimeout(function(){
			
					tempObj.css("background-color",oldcolor);
				 },8000);
				 
					
		
				
				funProcessContent(); /*091220 */
				$(".mask2").click();
				
			}
			
	
		}
		
		});	

	}
	function funGetPost(opts){
		var tid=opts.tid;
		var lastpid=opts.lastpid;
		if(opts.endpid!==undefined){
			var endpid=opts.endpid;
		}else{
			var endpid="";
		}
		if(opts.page!==undefined){
			var page=opts.page;
		}else{
			var page="";
		}
		if(opts.readcount!==undefined){
			var readcount=opts.readcount;
		}else{
			var readcount="";
		}
		
		var mydata="tid="+tid+"&page="+page+"&readcount="+readcount;
		
		
		$.ajax({
		type: "POST",
		url: "ajax_getpost.php",
		data: mydata,
		success: function(msg){
			
			if(msg!==""){
				
			
				// update page
			
		
				
				/*$("#pid"+lastpid+"").css("border", "1px groove blue");*/
				$(".PostList").append(msg);
				
				/*$("#displaycount").html($('.PostList').children('table').length);*/
				/*$("#pid"+lastpid+" ~ table ").css("border", "3px groove blue");*/
				
				var find=false;
				$(".PostList table").each(function(){
					if(find){
						/*$(this).effect("bounce", { times:3 }, 300);*/
						$(this).show();
						
						
						 var tempObj=$(this);
						 var oldcolor=$(this).css("background-color");
		
						 $(this).css("background-color","#E0FFDD");
						 window.setTimeout(function(){
							tempObj.css("background-color",oldcolor);
						 },8000);
						 
					}
				
					if($(this).attr("id") =="pid"+lastpid){
						find=true;
						//$(this).attr("id");
					}
					/*"pid"+lastpid;*/
				});
				
				funProcessContent(); /*091220 */
				
			}
			
	
		}
		
		});				
	}
	
	
	
	
	function resizeME(obj){
		if($(obj).attr("width")>=400){
		// $("p").prepend("<b>Hello </b>");
					
					$(obj).addClass("resized");
					
	/*
					$(obj).attr({
					"alt": $(this).attr("width"),
					"width": 400
				
					});
					
					
					$(obj).css({
						'border':'2px solid #0000ff',
						'margin-bottom':'5px',
						'padding':'2px'
					});
							
					
					
								
					$(obj).css({
						'cursor':'pointer'
					});
					
					*/
					
					var target=$(document.createElement("a"));
					
					$(target).addClass("resized");

					$(target).insertAfter(obj);
					target.attr({
					"href":$(obj).attr("src"),
					"title":$("#topic_title").val(),
					"rel":"lightbox",
					"target":"_blank"
					});
					//target.html("22");
					target.prepend($(obj));
					//target.html("111"+target.html());
					
					$(target).colorbox({
					opacity:0.6,
					slideshow:true,
					transition:"none", 
					width:"90%", 
					height:"90%"
					});
			
		 }else if($(obj).attr("width")>=250 || $(obj).attr("height")>=250){
		// $("p").prepend("<b>Hello </b>");
					
	
	
					
				
					
					
								
					$(obj).css({
						'cursor':'default'
					});
					
					
					var target=$(document.createElement("a"));
					$(target).insertAfter(obj);
					target.attr({
					"href":$(obj).attr("src"),
					"title":$("#topic_title").val(),
					"rel":"lightbox",
					"target":"_blank"
					});
					//target.html("22");
					target.prepend($(obj));
					
					$(target).colorbox({
					opacity:0.6,
					slideshow:true,
					transition:"none", 
					width:"90%", 
					height:"90%"
					});
					
					//target.html("111"+target.html());
				
					target.bind("click",function(){
					$(this).blur();
					return false;
					});
			
		 }
				
	}
	
	function funYoutube(obj){

		if($(obj).next().hasClass("playerbutton")){

			return false;
		}
	/*===*/

		var link=$(obj).attr("href");
		//alert(link);
		var u_div=$(document.createElement('div'));
		var u_img=$(document.createElement('img'));
		var u_vid=youtubeIDextract(link);
		
		$(obj).html("http://www.youtube.com/watch?v="+u_vid);
		u_img.attr("src",'http://img.youtube.com/vi/'+u_vid+'/0.jpg');
		u_img.attr("alt","(YouTube Loading)");

		
		u_div.addClass("u_div");
		
		
		u_div.append(u_img);
		
		var playicon=$(document.createElement('div'));
		playicon.addClass("playicon");
	
		u_div.append(playicon);

		u_img.attr("title","[按此播放]");
		u_img.css({
			cursor:"pointer"
		});
		
		u_img.bind("click",function(){
			$(this).parent().prev().prev().click();
		});
		$(obj).after(u_div);
		
		
		
		
		var btn_text=$(document.createElement('span'));
		var btn=$(document.createElement('span'));
		btn.addClass("playerbutton");
		btn.addClass("playerbutton_play");
		btn.data("vid",u_vid);
		btn.append(btn_text);
		btn_text.html("播放");
		btn.attr("title","[按此播放]");
		
		


		var btn2_text=$(document.createElement('span'));
		var btn2=$(document.createElement('span'));
		btn2.addClass("playerbutton");
		btn2.addClass("playerbutton_download");
		btn2.data("vid",u_vid);
		btn2.append(btn2_text);
		btn2_text.html("下載");
		btn2.attr("title","[按此下載]");	
				
		$(obj).after(btn2);
		$(obj).after(btn);
		
		
		
		var playerWidth=500;
		var playerHeight=340;
		
		/*http://www.youtube-mp3.org/#v=6FsGOwd1vJs*/
		var downloadyoutube="http://www.gazotube.com/@@@.html?from="+encodeURIComponent($("#url").val());
		var downloadyoutube="http://www.youtube-mp3.org/#v=@@@";
		/*var downloadyoutube="http://www.xenra.com/convert/?URL=http%3A//www.youtube.com/watch%3Fv%3D@@@";*/
		btn2.bind("click",function(){
			var vid=$(this).data("vid");
			if(window.confirm("將會開啟第三方的 [下載YouTube的網站]，\n請依照網站內的指示來下載 (可自動轉換 MP3)，\n是否確定開啟？")){
				var url=downloadyoutube.replace(/@@@/ig,vid);
				window.open(url);
			}
		});
		
		btn.bind("click",function(){
		
			if($(this).find("span").html()=="關閉"){
			
				// remove
				
				$(this).next().next().remove();
				$(this).find("span").html("播放");
				var u_div=($(this).next().next());
				u_div.show();
				
			}else{
				var u_div=($(this).next().next());
				u_div.hide();
			
				
				$(this).find("span").html("關閉");
				// create
				var playerDiv=$(document.createElement('div'));
			
				playerDiv.addClass("playerDiv");
				var vid=$(this).data("vid");
				
				/* =================================== */
				var videoObj = document.createElement("object");
				var videoParam1 = document.createElement("param");
				var videoParam2 = document.createElement("param");
				var videoParam3 = document.createElement("param");
				var videoParam4 = document.createElement("param");
				var videoEmbed = document.createElement("embed");
				/*var videoLink = "http://www.youtube.com/v/" + playBtn.getAttribute("id") + "&hl=en&fs=1&rel=0" + (GM_getValue("isAutoplay") ? "&autoplay=1" : "&autoplay=0");*/
				var videoLink = "http://www.youtube.com/v/"+vid+"&hl=en&fs=1&rel=0&autoplay=1"; // &loop=1
				
				videoObj.setAttribute("width", playerWidth);
				videoObj.setAttribute("height", playerHeight);
				videoParam1.setAttribute("name", "movie");
				videoParam1.setAttribute("value", videoLink);
				
				videoParam2.setAttribute("name", "allowFullScreen");
				videoParam2.setAttribute("value", "true");
				
				videoParam3.setAttribute("name", "allowscriptaccess");
				videoParam3.setAttribute("value", "always");
				
				videoParam4.setAttribute("name", "wmode");
				videoParam4.setAttribute("value", "transparent");
				
				videoEmbed.setAttribute("src", videoLink);
				videoEmbed.setAttribute("type", "application/x-shockwave-flash");
				videoEmbed.setAttribute("allowfullscreen", "true");
				videoEmbed.setAttribute("allowscriptaccess", "always");
				videoEmbed.setAttribute("wmode", "transparent");
				videoEmbed.setAttribute("width", playerWidth);
				videoEmbed.setAttribute("height", playerHeight);
				
				videoObj.appendChild(videoParam1);
				videoObj.appendChild(videoParam2);
				videoObj.appendChild(videoParam3);
				videoObj.appendChild(videoParam4);
				videoObj.appendChild(videoEmbed);
				
				
		
				playerDiv.append(videoObj);
				
			
				u_div.before(playerDiv);
				/* =================================== */
			}
			
			
			
			
		});	
	/*===*/
	}	
	
	





function funQuote(input){

	var mydata="pid="+input;
	$.ajax({
		type: "POST",
		url: "ajax_getpostbyid.php",
		data: mydata,
		success: function(msg){
			if(msg.indexOf("error")>=0){
					
				if(msg.indexOf(",edit")>=0){
					alert("Error");				
				}	
				
			}else if(msg.indexOf("{forumhk_split}")>=0){
				var msg=msg.split("{forumhk_split}");
				var message=msg[0];
				var quote_message=msg[1];
					var output='[quote]'+quote_message+'[/quote]'+"\r\n";
					$("#message").val(output);
					funFocusToLast($("#message"));
									
			}
		}
		
		});	
		
		
	
	return false;

}
	

