// JavaScript Document
function showPermissionDialog(){
	//FB.Connect.showPermissionDialog("email", onPermission, false, null);
	//FB.Connect.showPermissionDialog("publish_stream,email", onPermission, false, null);
	FB.Facebook.apiClient.users_hasAppPermission("photo_upload",function(has){
		if (has == 0) {
			document.getElementById("msg").style.display = "block";
			document.getElementById("msg").innerHTML = '<iframe src="msg.html" width="755" height="650" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"></iframe>';
			FB.Connect.showPermissionDialog("publish_stream,email,photo_upload", onPermission, false, null);
			document.getElementById("flashContent").style.visibility="hidden";
		}else{
			onPermission();
		}
	  }
	);
	
}

function onPermission() { 
	hideMsg();
	//alert("onPermission");
	//document.getElementById("flashContent").onPermission();
}




function publish(user_name,act_url,uid){
	document.getElementById("flashcontent").style.width="1px";
	//document.getElementById("flashcontent").style.visibility="hidden";
	var user_message="";
	var imgsrc="http://cell.webgene.com.tw/carantion/event/100420_event/images/130x130_2.jpg";
	var action_text = "康乃馨 輕柔美學";
	var action_href = act_url;
	var actionLinks = [{"text": action_text, "href": action_href}];
	var user_message_prompt="告訴你/妳的朋友";
	var attachment={};

	attachment={"name":"快來幫 "+user_name+" 投票 讓 "+user_name+" 飛高高拿COACH包!",
	"href":act_url ,
	"description":"快來幫 "+user_name+" 的「輕柔系女孩告白」投票，讓 "+user_name+" 飛得高高，就可以抽COACH包！來投票還有機會獲得GEORG JENSEN ENDLESS 鑰匙圈！",
	"caption":"",
	"media":[{"type": "image", "src":imgsrc, "href":action_href, "width":130,"height":130}]};
	FB.Connect.streamPublish(user_message, attachment, actionLinks, uid, user_message_prompt, onPublished, false);
}

function onPublished(post_id, exception){
	document.getElementById("flashcontent").style.width="100%";
	//document.getElementById("flashcontent").style.visibility="visible";
	swfobject.getObjectById("flashcontent").fbPublished(post_id);
}	

function sendEmail(uidAry,subject,text,fbml){
	var target_id_Ary=uidAry.split(",");
	FB.Facebook.apiClient.notifications_sendEmail(target_id_Ary, subject, null, fbml, onSendEmail) ;
	//FB.Facebook.apiClient.notifications_sendEmail(target_id_Ary, "subject11", "", "fbml", onSendEmail) ;
}

function onSendEmail(){
	alert("onSendEmail");
}

function showInvite(uid) {
	document.getElementById("invite").style.display = "block";
	document.getElementById("invite").innerHTML = '<iframe src="invite.php?uid='+uid+'" width="755" height="650" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"></iframe>';
	document.getElementById("flashContent").style.visibility="hidden";
}

function hideInvite() {
	document.getElementById("invite").style.display = "none";
	document.getElementById("invite").innerHTML = '';
}

function showMsg() {
	document.getElementById("msg").style.display = "block";
	document.getElementById("msg").innerHTML = '<iframe src="msg.html" width="755" height="650" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"></iframe>';
	FB.Connect.showPermissionDialog("offline_access", onPermission, false, null);
	document.getElementById("flashContent").style.visibility="hidden";
}

function hideMsg() {
	document.getElementById("flashContent").style.visibility = "visible";
	document.getElementById("msg").style.display = "none";
	document.getElementById("msg").innerHTML = '';
}

function hideFlash(){
	document.getElementById("msg").style.display = "block";
	document.getElementById("msg").innerHTML = '<iframe src="msg.html" width="755" height="650" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"></iframe>';
	document.getElementById("flashContent").style.visibility="hidden";
}

function bookmark(){
	document.getElementById("msg").style.display = "block";
	document.getElementById("msg").innerHTML = '<iframe src="msg.html" width="755" height="650" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"></iframe>';
	FB.Connect.showBookmarkDialog(bookmarkOK);
	document.getElementById("flashContent").style.visibility="hidden";
}

function bookmarkOK(){
	document.getElementById("flashContent").style.visibility = "visible";
	document.getElementById("msg").style.display = "none";
	document.getElementById("msg").innerHTML = '';
}
