var web_host = "/"
var url = ""+document.location;
var addType,showType,xshowType;
var id,re;
if(url.indexOf('movie') != -1) 
{
	addType = "addmovie";	//movie
	showType = "movies"
	xshowType = 1;
	re=/(\S.*)(movie)\/(?:\S.*)-(\d{1,})\/(\S*)/g;
	id = url.replace(re,"$3");
}
if(url.indexOf('celebrity') != -1) 
{
	addType = "addperson";	//person
	showType = "persons"
	xshowType = 2
	re=/(\S.*)(celebrity)\/(?:\S.*)-(\d{1,})\/(\S*)/g;
	id = url.replace(re,"$3");
}

//replace ' to \'
re = /\'/g;
var fa_title = '' + document.title;
fa_title = fa_title.replace(re,"\\\'");

//dynamic load js
function AddFavHandler(s){
	
}
function AddFav(){
	if (__UserInfo == "")
	{
		alert('Sorry, You are not login!');
		return;
	}
	if(showType=="persons")
		window.open('http://blog.bitcomet.com/cmd.aspx?cmd=js_addfavs&t='+xshowType+'&mid='+id);
	else
		CreateFavContainer();
	
}
function loadJs(file,charset){
	var scriptTag = document.getElementById('loadScript');
	var head = document.getElementsByTagName('head').item(0)
	if(scriptTag) head.removeChild(scriptTag);
	script = document.createElement('script');
	script.src = file;
	script.type = 'text/javascript';
	script.id = 'loadScript';
	script.charset = charset;
	head.appendChild(script)

	alert('add favor successfully!');
}

if (showType == "movies"){
	if (typeof movie_viewstate!='undefined')
	{
		id = movie_viewstate[0];
	}
	document.write("<a href=\"javascript:void(0);\" class=\"favorite\" onclick=\"AddFav()\" >Favorite</a>");
	document.write("<a class=\"quote\" href='/cmd.asp?cmd=addplace&typeno=3&infoid=" + id + "&tn=mdbbtn'\" target=\"_blank\">Quote</a>");
	document.write("<a class=\"blog\" href='http:\/\/blog.bitcomet.com\/PostAdd.aspx?mid=" + id + "'\" target=\"_blank\">Blog</a>");
	
}else{
	if (typeof person_viewstate!='undefined')
	{
		id = person_viewstate[0];
	}
	document.write("<a href=\"javascript:void(0);\" style=\"margin-left:15px;\" class=\"favorite\" onclick=\"AddFav()\" >Favorite</a>");
	document.write("<a class=\"quote\" href='/cmd.asp?cmd=addplace&typeno=4&infoid=" + id + "&tn=mdbbtn'\" target=\"_blank\">Quote</a>");
	//document.write("<a class=\"blog\" href='http:\/\/blog.bitcomet.com\/PostAdd.aspx?mid=" + id + "'&t=1\" target=\"_blank\">Blog</a>");
}
//common
document.writeln('<script language="javascript" src="/script/starvote.js"></script>');
document.writeln('<SCRIPT src="/script/xmllib.js" type=text/javascript></SCRIPT>');

function CreateFavContainer(){
	var e=getEvent();
	var target = null;
	var defVal = 'Loading...';
	if (window.event) { window.event.cancelBubble = true; target = e.srcElement}
    else {if (e.stopPropagation) e.stopPropagation(); target = e.target}
	if(document.getElementById("favdiv") && document.getElementById("favdiv").innerHTML != defVal){
		document.getElementById("favdiv").style.display = '';
		return;
	}
	if(document.getElementById("favdiv")) target.parentNode.removeChild(document.getElementById("favdiv"));
	var odiv = document.createElement("DIV");
	odiv.className = "site_search_menu";
	odiv.id = "favdiv";
	odiv.innerHTML = defVal;
	odiv.style.display = "none";
	odiv.style.top = "25px";
	odiv.style.left = "10px";
	odiv.style.width = "auto";
	target.parentNode.appendChild(odiv);
	shMrhMenu(odiv.id);
	BuildAddFavList(odiv);
}

function BuildAddFavList(odiv){

	if(document.getElementById("alicn")) {var a = document.getElementById("alicn"); a.parentNode.removeChild(a);}
	AsyncScript.script("http://blog.bitcomet.com/movie-list/ajax.aspx?act=getmylist&value=1&json=FavListParser",function(){
		
	},window);

	
}

function FavListParser(json){
	container = document.getElementById("favdiv");
	container.innerHTML = "";
	var ofrag = document.createDocumentFragment();
	var newNode = BuildNewListNode(json);

	if(typeof json == 'undefined'){		
		ofrag.appendChild(newNode);
	}else{
		var o = eval(json);
		
		for(var i = 0;i<o.length;i++){
			var odiv = document.createElement("DIV");
			var oa = document.createElement("A");
			oa.href = "http://blog.bitcomet.com/movie-list/ajax.aspx?act=myfavor&mid="+id+"&mlid="+o[i].MovieListID+"&value=1";
			oa.target = "_blank";
			oa.appendChild(document.createTextNode(decodeURIComponent(o[i].MovieListName)));
			oa.className = 'srTab';
			odiv.appendChild(oa);
			ofrag.appendChild(odiv);
		}
		ofrag.appendChild(newNode);
	}

	container.appendChild(ofrag);
}

function BuildNewListNode(json){
	var odiv = document.createElement("DIV");
	var oa = document.createElement("A");
	oa.href = "http://blog.bitcomet.com/movie-list/custom-list/create/?mid="+id;
	oa.target = "_blank";
	oa.appendChild(document.createTextNode("Create New List"));
	oa.className = 'srTab';

	if(__UserInfo != '' && typeof json == 'undefined'){
		var oa1 = document.createElement("A");
		oa1.href = "http://blog.bitcomet.com/movie-list/ajax.aspx?act=myfavordefault&value=post&mid="+id;
		oa1.target = "_blank";
		oa1.appendChild(document.createTextNode(__UserInfo.split('|')[1]+"'s new list"));
		oa1.className = 'srTab';

		odiv.appendChild(oa1);
	}

	odiv.appendChild(oa);

	return odiv;
}