var bmastatus = 0;
var bmatimer = null;

function bmview()
{
	id = ExtractCookie("BOOKMARK2");
	var pwd=null;
	if (id != null)
	{
		i = id.indexOf(':');
		if (i > 0)
		{
			pwd = id.substr(i+1);
			id = id.substr(0, i);
		}
		else
			id = null;
	}
	if (id == null)
	{
		document.write("<iframe id='bmframe' width='100%' height=1860 marginwidth=0 marginheight=0 frameborder='no' scrolling='no' src='http://66.90.73.205/bookmarks/view.php?u=new'></iframe>");
	}
	else
	{
		pg = ExtractCookie("BMPAGE");
		if (pg == null) pg = 1;
		document.write("<iframe id='bmframe' width='100%' height=1860 marginwidth=0 marginheight=0 frameborder='no' scrolling='no' src='http://66.90.73.205/bookmarks/view.php?u=" + id + "&p=" + pwd + "&x=" + pg + "'></iframe>");
	}
}

function ExtractCookie(c)
{
	ck = document.cookie + ";";
	i = ck.indexOf(c + "=");
	if (i < 0) return null;
	i += c.length + 1;
	j = ck.indexOf(";", i);
	return ck.substr(i, j-i);
}

function addbm(id,nm,th,rp)
{
	addbm2(id,nm,th,0)
}

function addbm2(id,nm,th,ht)
{
	user = ExtractCookie("BOOKMARK2");
	var pwd="";
	if (user != null)
	{
		i = user.indexOf(':');
		if (i > 0)
		{
			pwd = user.substr(i+1);
			user = user.substr(0, i);
		}
		else
			user = "";
	}
	else
		user = "";
	document.cookie = "BOOKMARKALERT=; expires=Sat, 19 Apr 2008 23:59:59 UTC; domain=sexydesktop.co.uk; path=/";
	if (ht == 0)
		fr = document.getElementById("bmframe");
	else
		fr = window.opener.document.getElementById("bmframe");
	fr.src = "http://66.90.73.205/bookmarks/add2.php?id=" + id + "&nm=" + nm + "&th=" + th + "&u=" + user + "&p=" + pwd + "&ht=" + ht;

	if (!bmatimer) 
	{
		createbmalert();
		bmatimer = window.setInterval('bmtimerproc()', 30);
	}
}

function addmyfaves()
{
	id = ExtractCookie("BOOKMARK2");
	var pwd=null;
	if (id != null)
	{
		i = id.indexOf(':');
		if (i > 0)
		{
			pwd = id.substr(i+1);
			id = id.substr(0, i);
		}
		else
			id = null;
	}
	if (id == null)
		parent.location.href="http://66.90.73.203/favourites/faves.php";
	else
		parent.location.href="http://66.90.73.203/favourites/faves.php?u=" + id + "&p=" + pwd;
}

function bmtimerproc()
{
	if (bmastatus == 0)
	{
		ck = ExtractCookie("BOOKMARKALERT");
		if (ck == null || ck.length < 2) return;
		
		document.cookie = "BOOKMARKALERT=; expires=Sat, 19 Apr 2008 23:59:59 UTC; domain=sexydesktop.co.uk; path=/";
	
		updatebmalert(ck);
		return;
	}
		
	var ea = document.getElementById("bmalert");
	if (ea == null) return;
	
	if (bmastatus == 1)
	{
		var e_b = document.getElementsByTagName("body")[0];
		e_b.removeChild(ea);
		window.clearInterval(bmatimer);
		bmatimer = null;
		bmastatus = 0;
		return;
	}
	
	if (bmastatus == 2)
	{
		ea.style.opacity = '0.25';
		ea.style.filter='alpha(opacity=25)';
	}
	
	if (bmastatus == 3)
	{
		ea.style.opacity = '0.5';
		ea.style.filter='alpha(opacity=50)';
	}
	
	if (bmastatus == 4)
	{
		ea.style.opacity = '0.7';
		ea.style.filter='alpha(opacity=70)';
	}
	
	bmastatus--;
}

function updatebmalert(ck)
{
	var e_r = document.getElementById("bmalertmsg");
	if (e_r != null)
	{
		for (i=0 ; i < 10 ; i++)
		{
			cn = e_r.firstChild;
			if (cn == null) break;
			e_r.removeChild(cn);
		}		
		
		if (ck.charAt(0) == '1')
			e_r.appendChild(document.createTextNode("You've bookmarked "));
		else
			e_r.appendChild(document.createTextNode("You've updated the bookmark of "));
		e_r.appendChild(document.createElement("br"));
		e_s = document.createElement("strong");
		e_s.appendChild(document.createTextNode(ck.substr(1)));
		e_r.appendChild(e_s);
		
		bmastatus = 70;
	}
}

function createbmalert()
{
	var e_b = document.getElementsByTagName("body")[0];
	var e_d = document.getElementById("bmalert");
	if (e_b != null && e_d == null)
	{
		w = document.body.clientWidth;
		if (w == null) w = 800;
		w = (w - 302) / 2;
		
		e_d = document.createElement("div");
		e_d.setAttribute("id", "bmalert");
		i = 0;
		if (document.documentElement.scrollTop)
			i = document.documentElement.scrollTop;
		else
		{
			if (document.body.scrollTop)
				i = document.body.scrollTop;
			else
			{
				if (window.pageYOffset) i = window.pageYOffset;
			}
		}
		i += 300;
		e_d.style.position="absolute";
		e_d.style.top = i + "px";
		e_d.style.left = w + "px";
		e_d.style.width = "299px";
		e_d.style.borderTop="1px solid #f60";
		e_d.style.borderLeft="1px solid #f60";
		e_d.style.borderRight="2px solid #C95000";
		e_d.style.borderBottom="2px solid #AB4400";
		e_d.style.fontFamily="verdana,sans-serif";
		e_d.style.backgroundColor="#c00";
		e_d.style.fontSize = "10pt";
		e_d.style.margin = "0";
		e_d.style.padding = "0";
		
		e_r = document.createElement("div");
		e_r.style.backgroundColor="#c00";
		e_r.style.color="#fff";
		e_r.style.margin = "0";
		e_r.style.padding = "1px 0 1px 5px";
		e_r.style.width = "295px";
		e_r.appendChild(document.createTextNode("Note:"));
		e_d.appendChild(e_r);

		e_r = document.createElement("div");
		e_r.setAttribute("id", "bmalertmsg");
		e_r.style.borderTop="1px solid #ff6300";
		e_r.style.borderBottom="1px solid #ff6300";
		e_r.style.width = "299px";
		e_r.style.margin = "0";
		e_r.style.padding = "32px 0";
		e_r.style.textAlign = "center";
		e_r.style.fontSize = "11pt";
		e_r.style.backgroundColor="#ffc";
		e_r.appendChild(document.createTextNode("Please wait..."));
		e_r.appendChild(document.createElement("br"));
		e_r.appendChild(document.createElement("br"));
		e_d.appendChild(e_r);
			
		e_r = document.createElement("div");
		e_r.style.backgroundColor="#c00";
		e_r.style.color="#f60";
		e_r.style.margin = "0";
		e_r.style.padding = "2px 5px 1px 0";
		e_r.style.width = "295px";
		e_r.style.textAlign = "right";
		e_r.appendChild(document.createTextNode("SexyDesktop"));
		e_d.appendChild(e_r);

		e_b.appendChild(e_d);
	}
}


