﻿/*
	function openLBInvite2Bot(inviteCount,bRefresh)
	function openLBAuthentication(feedURL,blogURL,code,feed_id)
	function openLBRequestInvitation()
	function openLBDemo()
	function openLBDeletePage(iPageId, iSetId)
	function openLBHistory(iUserId,sUsername)
	function openLBDups(iSpreadId, iDescId, iGrazeId)
	function openLBDeleteSet(iSetId, sSetName)
	function openLBCopySet(iSetId, sSetName, iPageId)
	function openLBSendMessage(oCaller, sMessageId, sToUserId, sSubject)
	function openLBRegisterationStep2(userId, username, email)
	function openLBRegister(username, email)
	function openLBShareGraze(sGrazeId, SenderUsername)
	function openLBSharePage(sGrazeId, SenderUsername)
	function openLBLogin()
	function openLBAlertDeleteGraze(sGrazeId, sGrazeName)
	function openLBAlertDeletePage(sGrazeId, sSpreadId, sPageName, retURL)
	function openLBDeleteMessages()
	function createLightBox(sClassName, sLightBoxContent, sSubmitText, sCancelText, sSubmitFunction, iTop, iLeft, bCentered)
	function closeLightBox()
*/

// grazebot lightboxes - start -------------
function openLBInvite2Bot(inviteCount, bRefresh)
{
	var xmlHttp = new createXMLHttpRequest();
	xmlHttp.open("GET", "/server/s_grazebot_user_invites.asp?seed=" + Math.random(), true);
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			if (xmlHttp.status == 200)
			{
				var sHTML = '<h3 class="title">Invite your fellow bloggers to GRAZEbot</h3>' +
										'<div id="Invite2BotContent">';
										if(inviteCount)
										{
											sHTML += '<p>You can invite up to '+inviteCount+' more bloggers:</p>';
										}
										else
										{
											sHTML += '<p>Your previous invitations:</p>';
										}
										sHTML += '<table style="padding-top: 15px;">';

				var oXml = xmlHttp.responseXML;
				var inputTxt = "friend email address";
				var aInvites = oXml.getElementsByTagName("invite");
				for(var i=0; i<aInvites.length; i++)
				{
					sHTML += "<tr><td>"+(i+1)+". </td><td>"+aInvites[i].firstChild.nodeValue+" (invite sent "+aInvites[i].getAttribute("invite_sent_time")+")</td></tr>";
				}
				for(;i<4; i++)
				{
					sHTML += "<tr><td>"+(i+1)+". </td><td><input type=\"text\" id=\"inviteBotEmail"+i+"\" name=\"inviteBotEmail"+i+"\" size=\"30\" onfocus= \"hideSearchText(this,'"+inputTxt+"');\" value=\""+inputTxt+"\"/>";
				}

				if(inviteCount)
				{
					sHTML += '</table>' +
							'<br><p>Can\'t choose? <a href="http://twitter.com/home?status=Got+some+invites+to+grazebot+on+@GRAZEit.+Anyone+interested?" target="_blank">tweet it and let them race!</a></p>' +
						   '</div>';
				}
				closeLightBox();
				if(inviteCount)
				{
					createLightBox("Invite2Bot",sHTML, "Send", "Cancel", "GBinvite2Bot("+bRefresh+");", document.documentElement.scrollTop + 100, "", true);
					if(bRefresh)
					{
						$("LightBoxCancel").onclick = function(){ GBReload(); }; //only when opening lightbox from grazebot process!
					}

				}
				else
				{
					createLightBox("Invite2Bot",sHTML, "OK", "", "closeLightBox();", document.documentElement.scrollTop + 100, "", true);
					if(bRefresh)
					{
						$("LightBoxSubmit").onclick = function(){ GBReload();}; //only when opening lightbox from grazebot process!
					}
				}
			}
		}
	}
	xmlHttp.send("");

}

function openLBGBaddBlog(code)
{
	var url = $("UserURL").value;
	if(url == "" || url == "http://" || url.indexOf("http://") != 0 )
	{
		alert("Please insert your blog's URL address or RSS feed in the textbox below, and click 'Add'");
		return;
	}

	createLightBox("AuthLightBox", '<h3 id="AuthTitle">Adding to GRAZEbot</h3>' +
							'<div id="AuthContent">' +
								'Please wait while we check your URL...<br>' +
								'<div style=\"margin:20px 0 0 130px;\"><object width=\"75\" height=\"75\">' +
									'<param name=\"movie\" value=\"/images/loading_animation.swf\" />' +
									'<embed src=\"/images/loading_animation.swf\" width=\"75\" height=\"75\" />' +
								'</object></div>',
			"Done", "Cancel", "", document.documentElement.scrollTop + 100, "", true);

	$("LightBoxSubmit").style.display= "none";
	GBProcessFeed(url,code);
}

function openLBAuthentication(feedURL,blogURL,code,feed_id)
{
	createLightBox("AuthLightBox", '<h3 id="AuthTitle">Authenticate your blog</h3>' +
							'<div id="AuthContent">' +
								'<p>Add the code below to: '+blogURL+'<br> Just copy & paste it anywhere in the blog\'s template, or to your latest post (don\'t worry - no one will see it).</p>' +
								'<div style="padding-top: 15px;">' +
									'<input type="text" id="code" name="code" size="50" value="<!-- '+code+' -->" readonly/>' +
								'</div>' +
								'<br><p>When you\'ve added it, click "Authenticate"</p>' +
								'<br><p>'+blogURL+' does not belog to the feed inserted? Need further help? contact us at support@grazeit.com</p>' +
							'</div>'
							,
			"Claim ownership", "Cancel", "GBauthenticateBlog('"+feedURL+"','"+blogURL+"','"+code+"',"+feed_id+");", document.documentElement.scrollTop + 100, "", true,100);
}

function openLBRequestInvitation()
{
	createLightBox("ReqInviteLightBox", '<h3>Request an invite to GRAZEbot</h3>' +
							'<div id="reqc" style="padding-top: 5px;">' +
								'<div style="padding-top: 15px;">' +
									'<label for="burl">Your blog\'s URL: </label>' +
									'<input type="text" id="burl" name="burl" />' +
								'</div>' +
							'</div>'
							,
			"Send", "Close", "GBreqInvitation();", document.documentElement.scrollTop + 100, "", true);
}

function openLBDeleteBlogFromBot(iFeedId, blogURL)
{
	createLightBox("DeleteBlogFromBot", '<h3>Remove this blog from GRAZEbot?</h3>' +
							'<p>Are you sure you want to remove ' +blogURL+ ' from GRAZEbot?</p>',
			"OK", "Cancel", "GBdeleteBlog('" + iFeedId + "'); closeLightBox();", document.documentElement.scrollTop + 200, "", true);
}

function openLBEditBlogFromBot(iFeedId, cat, lang)
{
	createLightBox("EditBlogFromBot", '<h3 id="LBEditTitle">Edit your blog in GRAZEbot</h3>' +
						    '<p id="LBEditTxt">Please select the following properites to your blog:</p>' + GBBlogPropertiesTable(lang,cat),
			"OK", "Cancel", "GBeditFeed2Grazebot('" + iFeedId + "');", document.documentElement.scrollTop + 200, "", true);
}

function openLBRunBot (iFeedId, feed_name)
{
	BGFeedRun(iFeedId);
	createLightBox("RunBot", '<h3>GRAZEbot is now processing your site...</h3>' +
							'<p>GRAZEbot is now crawling '+feed_name+' for new grazes.<br>It might take a few minutes.</p>' +
							'<p>You will receive a notification email when it\'s done (unless you have chosen not to receive GRAZEbot emails).</p>',
			"Close", "", "closeLightBox();", document.documentElement.scrollTop + 200, "", true);
}

// grazebot lightboxes - end -------------

function openLBDemo(sFFVersion, sIEVersion)
{
	var sBrowser = "";
	var sBrowserName = "";
	if (Browser.Engine.trident)
	{
		sBrowser = "ie";
		sBrowserName = "Internet Explorer";
	}
	else
		if (Browser.Engine.gecko)
		{
			sBrowser = "ff";
			sBrowserName = "Firefox";
		}
		else
		{
			sBrowser = "other";
			sBrowserName = "Other";
		}

		var sDemoHTML = '<h3>What is GRAZEit?</h3>' +
							'<div style="background: #000;">' +
								'<object width="591" height="298">' +
									'<param name="movie" value="/images/home/grazeit_intro.swf?autoplay=1" />' +
									'<param name="quality" value="high" />' +
									'<param name="wmode" value="transparent" />' +
									'<param name="autoPlay" value="true" />' +
									'<embed src="/images/home/grazeit_intro.swf?autoplay=1" wmode="transparent" width="591" height="298" autoPlay="true"></embed>' +
								'</object>' +
							'</div>' +
							'<div class="dbutton ' + sBrowser + '">';
		if (sBrowser == "ff")
			sDemoHTML += '<a href="#" onclick="downloadFF(\''+sFFVersion+'\',\'demo\');"'
		else
		{
			if (sBrowser == "ie")
				sDemoHTML += '<a href="/install/GRAZEit.IE.Plugin.'+sIEVersion+'.exe" onclick="downloadIE(\'demo\');"'
			else
				sDemoHTML += '<a href="/download/"';
		}

		sDemoHTML += ' class="get">Get GRAZEit <span>Free • No spyware • No registration</span></a>' +
							'<p>(' + sBrowserName + ') <a href="/download/">Other versions</a></p>' +
						'</div>'
	createLightBox("DemoLightBox", sDemoHTML,	"Close", "", "closeLightBox();", document.documentElement.scrollTop + 100, "", true);
}

function openLBAddPage(iPageId)
{
}

function openLBDeletePage(iPageId, iSetId)
{
	createLightBox("AlertLightBox", '<h3>Delete this page?</h3>' +
							'<p>Are you sure you want to remove this page from your set?</p>',
			"OK", "Cancel", "deleteSetPage(" + iPageId + "," + iSetId + "); closeLightBox();", document.documentElement.scrollTop + 200, "", true);
}

function openLBHistory(iUserId,sUsername)
{
	closeLightBox();

	var xmlHttp = new createXMLHttpRequest();
	xmlHttp.open("GET", "/server/s_user_score_get.asp?u="+iUserId+"&un="+sUsername+"&seed=" + Math.random(), true);
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			if (xmlHttp.status == 200)
			{
				var oXml = xmlHttp.responseXML;
				var aDays = oXml.getElementsByTagName("day");
				var sHTML = ''+ '<h3>Recently Gained and Lost Score</h3>';
				for(var i=0; i<aDays.length; i++)
				{
					var oE = aDays[i];
					sHTML += '<h4>' + oE.getAttribute("date") + '</h4><ul>';
					var aEvents = oE.getElementsByTagName("score_event");

					for(var j=0; j<aEvents.length; j++)
					{
						var oEv = aEvents[j];
						if(oEv.getAttribute("sign") == "minus")
						{
							sHTML += '<li><b class="lose">-';
						}
						else
						{
							sHTML += '<li><b class="gain">+';
						}

						sHTML += oEv.getAttribute("score");
						sHTML += '</b>' + oEv.firstChild.nodeValue + '</li>';
					}
					sHTML += '</ul>';
				}
				createLightBox("ScoreHistoryLightBox", sHTML, "Close", "", "closeLightBox()", document.documentElement.scrollTop + 200, "", true);
			}
		}
	}
	xmlHttp.send("");
}

function openLBDups(iSpreadId, iDescId, iGrazeId)
{
	var xmlHttp = new createXMLHttpRequest();
	xmlHttp.open("GET", "/server/s_spread_dups.asp?spread_id=" + iSpreadId + "&graze_desc_id=" + iDescId + "&seed=" + Math.random(), true);
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			if (xmlHttp.status == 200)
			{
				var oXml = xmlHttp.responseXML;
				var aSpreads = oXml.getElements("spread");
				var sTitle = $("title" + iSpreadId).innerHTML;
				var sUrl = $("url" + iSpreadId).innerHTML;

				closeLightBox();

				var sHTML = '<div class="top">' +
							'<strong>' + aSpreads.length + ' additional grazers spread</strong>' +
							'<p>' + $("graze_" + iGrazeId+ "_title").innerHTML + '</p>' +
							'<strong>to page</strong>' +
							'<p>' + $("url" + iSpreadId).innerHTML + '</p>' +
						'</div>' +
						'<ul class="dups">';

				var iUserId, sUserLink, sUserName, sUserPhoto, sSpreadTime, sDesc;
				aSpreads.each(function(oE)
				{
					iUserId	= oE.getAttribute("user_id");
					sUserName	= oE.getAttribute("username");
					sUserPhoto	= oE.getAttribute("photo");
					sUserLink	= oE.getAttribute("user_link");
					sSpreadTime	= oE.getAttribute("spread_time");
					sDesc		= (oE.firstChild) ? oE.firstChild.nodeValue : "&#160;";

					sHTML += '<li>' +
							'<div class="user">' +
								'<a href="' + sUserLink + '">' +
									'<img src="' + sUserPhoto + '" alt="' + sUserName + '" height = "52px" width = "52px"/>' +
								'</a>' +
							'</div>' +
							'<div class="username">' +
								'<h4><a href="' + sUserLink + '">' + sUserName + '</a> [' + sSpreadTime + ']</h4>' +
								'<p>' + sDesc + '</p>' +
							'</div>' +
							'<div class="clear">&#160;</div>' +
						   '</li>';
				});

				sHTML += '</ul>';

				createLightBox("DuplicatesLightBox", sHTML, "Close", "", "closeLightBox();", document.documentElement.scrollTop + 200, "", true);
			}
		}
	}
	xmlHttp.send("");
}

function openLBDeleteSet(iSetId, sSetName)
{
	closeLightBox();

	createLightBox("AlertLightBox", '<h3>Delete selected set?</h3>' +
							'<p>Are you sure you want to delete the set <b>' + sSetName + '</b>?</p>',
			"OK", "Cancel", "setDelete(" + iSetId + "); closeLightBox();", document.documentElement.scrollTop + 200, "", true);
}

function openLBCopySet(iSetId, sSetName, iPageId)
{
	closeLightBox();
	var xmlHttp = new createXMLHttpRequest();
	xmlHttp.open("GET", "/server/s_user_sets_get.asp?seed=" + Math.random(), true);
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			if (xmlHttp.status == 200)
			{
				var sWhatAreSets = "A set is a group of pages used for quick spreading"
				var sTitle = (iPageId)? "Add page to set" : "Copy pages to set";

				var oXml = xmlHttp.responseXML;
				var aSets = oXml.getElementsByTagName("set");
				var sHTML = '<div id="acont">' +
						'<h3>' + sTitle + '</h3>' +
						'<div class="t">' +
							'<input id="chkToSet" type="radio" name="ct" checked="true" onclick="checkNewSetStatus(false);" />' +
							'<label for="chkToSet">Add pages to my existing set</label>' +
						'</div>' +
						'<div class="f">' +
							'<select id="slctSet">' +
								'<option value="-1">Select a set...</option>';
								for(var i=0; i<aSets.length; i++)
								{
									var oSet = aSets[i];
									sHTML += '<option value="' + oSet.getAttribute("set_id") +'">' + oSet.getAttribute("set_name")+ '</option>';
								}

						sHTML += '</select>' +
						'</div>' +
						'<div class="t">' +
							'<input id="chkNewSet" type="radio" name="ct" value="' + sSetName + '" onclick="checkNewSetStatus(true);" />' +
							'<label for="chkNewSet">Add pages to a new set with this name</label>' +
						'</div>' +
						'<div class="f">' +
							'<input type="text" id="iSetName" value="" disabled="true" />' +
						'</div>';

						if (!iPageId)
						{
							sHTML += '<div class="spt" onclick="toggleSetPages();"><img src="/images/plus-expand.gif" id="xpp" alt="Expand" /> Select pages to copy (<span id="nop"></span>)</div>' +
								   '<ul id="spages"></ul>';
						}
						sHTML += '<p class="war"><span class="link" id="whatares" title="' + sWhatAreSets + '">What are sets?</span></p>' +
							'</div>';

				createLightBox("CopySet", sHTML, "OK", "Cancel", "setCopy('" + iSetId + "', '" + ((iPageId)? iPageId : -1) + "')", document.documentElement.scrollTop + 200, "", true);

				var myTips = new Tips("#whatares", {className: "tooltip", offsets:{'x': 0, 'y': -123} });

				if (!iPageId)
					populateSetPages(iSetId);
			}
		}
	}
	xmlHttp.send("");
}

function openLBSendMessage(oCaller, sMessageId, sToUserId, sSubject)
{
	closeLightBox();

	var sSubject = sSubject || "";
	var sUserHTML = "";

	var oMessage = $("message" + sMessageId + "user");
	if(oMessage)
	{
		sUserHTML = oMessage.innerHTML;
	}
	else
	{
		var sUserName = sMessageId.split(";")[0];
		var sImage = sMessageId.split(";")[1];
		sUserHTML = '<img src="' + sImage + '" alt="' + sUserName + '" class="avatar" />' + sUserName;
	}

	var sHTML = '' +
	'<h3>Send a Message</h3>' +
	'<form action="" method="get" id="SendMessageForm" onsubmit="return false;">' +
		'<div>' +
			'<label for="lb_to">To</label>' +
			'<span>' + sUserHTML + '</span>' +
		'</div>' +
		'<div>' +
			'<label for="lb_subject">Subject</label>' +
			'<input type="text" value="' + sSubject.replace(/&apos;/g,"'") + '" name="lb_subject" id="lb_subject" class="txt" />' +
		'</div>' +
		'<div>' +
			'<label for="lb_content">Content</label>' +
			'<textarea name="lb_content" id="lb_content" class="txt" rows="6"></textarea>' +
		'</div>' +
	'</form>';

	createLightBox("SendMessageLightBox", sHTML, "Send", "Cancel", "validateNewMessage(" + sToUserId + ");", document.documentElement.scrollTop + 100);
}

function openLBRegisterationStep2(userId, username, email)
{
	$("RegisterForm").innerHTML = '<p>An email containing 6-digit verification code was sent to ' +
						'<b>'+email+'</b>.</p>' +
						'<div class="verify">' +
							'<label for="lb_code">Please paste the code:</label>' +
							'<input type="text" value="" name="lb_code" id="lb_code" class="txt" maxlength="6" />' +
						'</div>';

	var oFaqList = document.createElement("ul");
		oFaqList.className = "problems";
		oFaqList.innerHTML =	'<li>Problems?</li>' +
						'<li><span class="link" onclick="openLBRegister(\'\',\'\'); removeToolTips();" title="No problem. Just sign-up all over again.">This is not my email address</span></li>' +
						'<li><span class="link" title="<ul><li>1. Be patient, sometimes it takes a while for the email to arrive.</li><li>2. Check your junk or bulk mailbox, the message might have been filtered as junk.</li><li>3. Still didn\'t get it? Sign-up again with a different email address.">I\'m still waiting for the code</li></ul></span></li>' +
						'<li><span class="link" onclick="openLBRegister(\''+username+'\',\''+email+'\'); removeToolTips();" title="Just sign-up again with the same email.">I deleted my code by mistake...</span></li>';

	$$("#LightBox .buttons")[0].appendChild(oFaqList);
	var myTips = new Tips("#LightBox .buttons li span", {className: "tooltip", offsets:{'x': 0, 'y': -123} });

	$("LightBox").addClass("VerificationLightBox");
	setLightBoxShadowSize();

	$("lb_code").focus();
	$("LightBoxSubmit").value = "Confirm";
	$("LightBoxSubmit").onclick = function(){ checkConfirmationCode($('RegisterForm'), userId); }
}

function openLBRegister(username, email)
{
	var username = username || "";
	var email = email || "";
	closeLightBox();

	var sHTML = '' +
	'<h3>Sign-up</h3>' +
	'<form action="" method="get" id="RegisterForm" onsubmit="return false;">' +
		'<div>' +
			'<label for="lb_username">Username</label>' +
			'<input type="text" value="'+username+'" name="lb_username" id="lb_username" class="txt" maxlength="15"/>' +
		'</div>' +
		'<div>' +
			'<label for="lb_email">Email</label>' +
			'<input type="text" value="'+email+'" name="lb_email" id="lb_email" class="txt" />' +
		'</div>' +
		'<div>' +
			'<label for="lb_website">Website</label>' +
			'<input type="text" value="" name="lb_website" id="lb_website" class="txt" />' +
		'</div>' +
		'<div>' +
			'<label for="lb_password">Password</label>' +
			'<input type="password" value="" name="lb_password" id="lb_password" class="txt" />' +
		'</div>' +
		'<div>' +
			'<label for="lb_confirmpassword">Confirm</label>' +
			'<input type="password" value="" name="lb_confirmpassword" id="lb_confirmpassword" class="txt" />' +
		'</div>' +
		'<div>' +
			'<label for="lb_coupon">Coupon</label>' +
			'<input type="text" value="" name="lb_coupon" id="lb_coupon" class="txt" />' +
		'</div>' +
		'<div>' +
			'<label>&#160;</label>' +
			'<input type="checkbox" value="yes" id="lb_newsletter" name="lb_newsletter" class="chk" checked/><label for="lb_newsletter" class="chklbl">Update me about new stuff</label>' +
		'</div>' +
		'<div>' +
			'<label>&#160;</label>' +
			'<input type="checkbox" value="yes" id="lb_tosagree" name="lb_tosagree" class="chk" /><label for="lb_tosagree" class="chklbl">I agree to the <a href="/disclaimer/terms/">Terms of Use</a></label>' +
		'</div>' +
	'</form>';

	createLightBox("RegisterLightBox", sHTML, "Signup", "Cancel", "signup_validity_check($('RegisterForm'));");

	$("LightBox").style.left = $("SpreadButton").getLeft() - 50 + "px";
	$("lb_username").focus();

	$("RegisterForm").onkeydown = function(e){ checkForFormSubmission((e || event), "signup_validity_check($('RegisterForm'));"); }
}

function openLBShareGraze(sGrazeId,SenderUsername)
{
	closeLightBox();

	var oGraze = $(sGrazeId);
	var iGrazeId = sGrazeId.replace("graze_", "");
	var sHTML = '' +
			'<h3>Share a graze</h3>' +
			'<form action="" method="post" id="ShareGrazeForm" onsubmit="return false;">' +
				'<input type="hidden" value="' + iGrazeId + '" id="lb_share_gid" name="lb_share_gid" />' +
				'<div class="formfield">' +
					'<label for="lb_share_emails">To <em class="de">E-mail Addresses</em></label>' +
					'<input type="text" value="" name="lb_share_emails" id="lb_share_emails" class="txt" />' +
					'<span class="de">[ seperate by comma ]</span>' +
				'</div>' +
				'<div class="formfield subject">' +
					'<label for="lb_share_subject">Subject</label>' +
					'<span id="lb_share_to">' + SenderUsername +' shared this graze with you' +
				'</div>' +
				'<div class="formfield">' +
					'<label for="lb_share_message">Message</label>' +
					'<textarea id="lb_share_message" name="lb_share_message" rows="4">Thought you might want to check this out</textarea>' +
					'<span class="de">[ optional ]</span>' +
				'</div>' +
				'<div class="formfield preview">' +
					'<label for="lb_share_preview">Graze preview</label>' +
					'<div class="clear">&#160;</div>' +
				'</div>' +
				'<div class="formfield SharePreview">' +
					'<div class="ShareLeft">' +
						oGraze.getElements(".left")[0].innerHTML +
					'</div>' +
					'<div class="ShareRight">' +
						oGraze.getElements(".right")[0].innerHTML +
					'</div>' +
					'<div class="ShareContent">' +
						oGraze.getElements(".content")[0].innerHTML +
						'<div class="tags">' + oGraze.getElements(".tags")[0].innerHTML + '</div>' +
					'</div>' +
				'</div>' +
			'</form>';

	createLightBox("ShareGrazeLightBox", sHTML, "Send", "Cancel", "share_validity_check($('ShareGrazeForm'),'"+SenderUsername+"');", document.documentElement.scrollTop + 70, oGraze.getLeft() + 100);
}

function openLBSharePage(iPageId, SenderUsername)
{
	closeLightBox();

	var sHTML = '' +
			'<h3>Share a page</h3>' +
			'<form action="" method="post" id="ShareGrazeForm" onsubmit="return false;">' +
				'<input type="hidden" value="' + iPageId + '" id="lb_share_pid" name="lb_share_pid" />' +
				'<div class="formfield">' +
					'<label for="lb_share_emails">To <em class="de">E-mail Addresses</em></label>' +
					'<input type="text" value="" name="lb_share_emails" id="lb_share_emails" class="txt" />' +
					'<span class="de">[ seperate by comma ]</span>' +
				'</div>' +
				'<div class="formfield subject">' +
					'<label for="lb_share_subject">Subject</label>' +
					'<span id="lb_share_to">' + SenderUsername +' shared this page with you' +
				'</div>' +
				'<div class="formfield">' +
					'<label for="lb_share_message">Message</label>' +
					'<textarea id="lb_share_message" name="lb_share_message" rows="4">Thought you might want to check this out</textarea>' +
					'<span class="de">[ optional ]</span>' +
				'</div>' +
				'<div class="formfield preview">' +
					'<label for="lb_share_preview">Preview</label>' +
					'<div class="clear">&#160;</div>' +
				'</div>' +
				'<div class="formfield SharePreview TopPage">' +
					$("pTopPage").innerHTML.replace("<!--[GOOGLEAD-->", "<!--").replace("<!--GOOGLEAD]-->", "-->") +
				'</div>' +
			'</form>';

	createLightBox("SharePageLightBox", sHTML, "Send", "Cancel", "share_validity_check($('ShareGrazeForm'),'"+SenderUsername+"');", document.documentElement.scrollTop + 70, 0, true);

	$$("#LightBox .actions span").each(function(el){ el.onclick = null; });
}

function openLBLogin()
{
	closeLightBox();

	var sHTML = '' +
	'<form action="/server/s_login.asp" method="post" id="LoginForm" onsubmit="return login_validity_check(this);">' +
		'<h3>Log in</h3>' +
		'<div>' +
			'<label for="username">Username</label>' +
			'<input type="text" value="" name="username" id="username" class="txt" />' +
		'</div>' +
		'<div>' +
			'<label for="password">Password</label>' +
			'<input type="password" value="" name="password" id="password" class="txt" /><a href="/forgot/" class="forgot">Forgot?</a>' +
		'</div>' +
		'<div>' +
			'<input type="checkbox" value="yes" id="RememberMe" name="RememberMe" class="chk" />' +
			'<label for="RememberMe" class="chklbl">Remember me on this computer</label>' +
		'</div>' +
	'</form>';

	createLightBox("LoginLightBox", sHTML, "Login", "Cancel", "login_validity_check($('LoginForm'));", document.documentElement.scrollTop + 80, $("SpreadButton").getLeft() - 50);

	var oGetFree = new Element("div", {
		"class" : "signupnow",
		"html" : 'or <span class="link" onclick="openLBRegister(\'\',\'\');">get a free account</span>'});

	$$("#LightBox .buttons")[0].appendChild(oGetFree);

	$("username").focus();
	$("LoginForm").onkeydown = function(e){ checkForFormSubmission((e || event), "login_validity_check($('LoginForm'));"); }
}

function openLBAlertDeleteGraze(sGrazeId, sGrazeName)
{
	closeLightBox();

	var iTop = document.documentElement.scrollTop + 200;

	if (canDelete(sGrazeId))
	{
		createLightBox("AlertLightBox", '<h3>Delete this GRAZE?</h3>' +
								'<p>Are you sure you want to delete the graze:<br>' +
								'<em>' + sGrazeName + '</em>?</p>',
				"OK", "Cancel", "deleteGraze(" + sGrazeId + ", true); closeLightBox();", iTop, "", true);
	}
	else
	{
		createLightBox("AlertLightBox", '<h3>Delete this GRAZE?</h3>' +
								'<p>You cannot delete this graze, you can only remove it from your spread urls.<br>Are you sure you want to unpsread the graze:<br>' +
								'<em>' + sGrazeName + '</em>?</p>',
				"OK", "Cancel", "deleteGraze(" + sGrazeId + ", false); closeLightBox();", iTop, "", true);

	}
}


function openLBAlertDeletePage(sGrazeId, sSpreadId, sPageName, retURL)
{
	closeLightBox();
	createLightBox("AlertLightBox", '<h3>Remove graze from this page?</h3>' +
							'<p>Are you sure you want to remove this graze from<br />' +
							'<em>' + sPageName + '</em>?</p>',
			"OK", "Cancel", "unspreadGraze(" + sGrazeId + "," + sSpreadId + ",'" + retURL + "'); closeLightBox();", document.documentElement.scrollTop + 200, "", true);
}

function openLBDeleteMessages()
{
	closeLightBox();

	createLightBox("AlertLightBox", '<h3>Delete selected messages?</h3>' +
							'<p>Are you sure you want to delete the selected messages?</p>',
			"OK", "Cancel", "deleteMessages(); closeLightBox();", document.documentElement.scrollTop + 200, "", true);
}

function createLightBox(sClassName, sLightBoxContent, sSubmitText, sCancelText, sSubmitFunction, iTop, iLeft, bCentered, iSubmitWidth)
{
	if($("LightBox"))
	{
		return;
	}

	var oLightBox = new Element("div", {
		"id" : "LightBox",
		"class" : "LightBox " + sClassName});

	var oContent = new Element("div", {
		"class" : "content",
		"html" : sLightBoxContent });

	var oButtons = new Element("div");
		oButtons.innerHTML = '' +
		'<div class="buttons">' +
			((sSubmitText != "")?'<span class="button submit" onclick="' + sSubmitFunction + '" id="LightBoxSubmit" ' + ((iSubmitWidth)? 'style="width: ' + iSubmitWidth + 'px;"' : '') + '><span class="right">&#160;</span>' + sSubmitText + '</span>' : '') +
			((sCancelText != "")?'<input type="button" value="' + sCancelText + '" class="button cancel" onclick="closeLightBox();" id="LightBoxCancel" />' : '') +
		'</div>' +
		'<span class="close" onclick="closeLightBox();">&#160;</span>';


	var oHandle = new Element("div", {
		"class" : "handle",
		"html" : "&#160;",
		"mouseover" : function(){ this.addClass("hover"); },
		"mouseout" : function(){ this.removeClass("hover"); } });

	var oShadows = getLightBoxShadow();

	oContent.appendChild(oButtons);
	oContent.appendChild(oHandle);

	oContent.onkeydown = function(e){ var e = e || event; if (e.keyCode == 27){ closeLightBox(); } }

	oLightBox.appendChild(oContent);
	oLightBox.appendChild(oShadows);

	document.body.appendChild(oLightBox);

	if (iTop)
		oLightBox.style.top = iTop + "px";
	if (iLeft)
		oLightBox.style.left = iLeft + "px";

	setLightBoxShadowSize();

	if (bCentered)
		oLightBox.style.left = (document.body.offsetWidth  - oLightBox.offsetWidth)/2 + "px";

	// Has to be in a try-catch block, cause sometimes the created lightbox isn't visible
	try
	{
		oContent.focus();
	}
	catch(e) {}

	var oDrag = new Drag(oLightBox, {handle: $$(".handle")});
}

function setLightboxSubmitText(str)
{
	$("LightBoxSubmit").innerHTML = '<span class="right">&#160;</span>' + str;
}

function resizeLightBoxHeight(iNewHeight)
{
	var oLightBoxContent = $$("#LightBox .content")[0];
	oLightBoxContent.style.height = iNewHeight + "px";
	setLightBoxShadowSize();
}

function closeLightBox()
{
	if($("LightBox"))
		$("LightBox").destroy();
}

function setLightBoxShadowSize()
{
	var oLightBoxContent = $$("#LightBox .content")[0];
	var iLightBoxWidth = oLightBoxContent.offsetWidth + 110;
	var iLightBoxHeight = oLightBoxContent.offsetHeight + 110;

	$("LightBoxShadow").style.width = iLightBoxWidth + "px";
	$("LightBoxShadow").style.height = iLightBoxHeight + "px";
}

function getLightBoxShadow()
{
	var oTable = new Element("table",{
				"id" : "LightBoxShadow"});
	var oTbody = new Element("tbody");
	var oTopRow = new Element("tr",{
				"class" : "top"});
	var oBottomRow = new Element("tr",{
				"class" : "bottom"});

	for(var i=0; i<2; i++)
	{
		var oTd = new Element("td", {
				"class" : ((i == 0)? "left" : "right"),
				"html" : "&#160;"});

		oTopRow.appendChild(oTd);
		oBottomRow.appendChild(oTd.cloneNode(true));
	}

	oTbody.appendChild(oTopRow);
	oTbody.appendChild(oBottomRow);

	oTable.appendChild(oTbody);

	return oTable;
}

function displayLBButtons(bdisplay)
{
	for(var i = 0; i < $$("#LightBox .buttons").length; i++)
	{
		if(bdisplay)
			$$("#LightBox .buttons")[i].style.display = "block";
		else
			$$("#LightBox .buttons")[i].style.display = "none";
	}

}