appIT = Object.extend (new HPEItemApp, {

	opsSelect:"OtherOpsItem",
	getItem:hpe.getItem,
	postPrevEmails:"",

	InitApp : function() {
		var html = "<form id='AppItemTools' style='display:none' class='nomargin'><table width='100%' height='27' border='0' cellspacing='0' cellpadding='0'><tr>\
			<td align='left'>&nbsp;&nbsp;<input type='button' value='Return to List of Items' id='AppITClose' onClick='HPEBackApp()' />\
			</td></tr></table></form>";

		var elt = $("tabbarmiddle");
		if(!elt) { hpe.error("Failed to find tabbarmiddle"); return }
		new Insertion.Bottom(elt, html);

		this.body = "<div id='content' style='margin-left:0px'><div id='contentbreakprotect'>\
			<div id='ITHeaderContent' style='padding-top:5px'><p>Initializing...</p></div>\
			<div id='ITMainContent' style='padding-top:5px'></div>\
			</div></div>";
	},

	StartApp : function (id) {
		var elt = $("AppItemTools"); elt.show();
		elt = $("MainBody"); if(elt) elt.innerHTML = this.body;

		this.id = id;
		this.ResumeApp();
	},

	SuspendApp : function () {
		var elt = $("AppItemTools"); elt.hide();
	},

	ResumeApp : function () {
		var elt = $("AppItemTools"); elt.show();
		elt = $("MainBody"); if(elt) elt.innerHTML = this.body;

		var item = this.getItem(this.id);
		if(item) this.ShowItem(item);
			else this.LoadItemInfo();
	},

	ShowBackMessage : function() {
		var elt = $("ApplicationBackButton");
		if(!elt) return;
		elt.innerHTML = "<a class=\"OB\" href=\"#\" onClick=\"HPEBackApp()\">[back to item details]</a>";
		Element.show(elt);
	},

	Reload : function() {
		this.LoadItemInfo();
	},

	LoadItemInfo : function () {
		var url = siteHome + "ajaxAPI.php?api_call=Item::get&api_format=JSON&id=" + this.id;
		var myAjax = new Ajax.Request(url, { method:'get', onComplete:this.LoadItemInfoProcess.bind(this) });
		$("ITHeaderContent").innerHTML = "<p>Loading Item Info...</p>";
		$("ITMainContent").innerHTML = "";
		hpe.goToTop();
	},

	LoadItemInfoProcess : function (request) {
		var res = hpe.ProcessItemResponse(request);
		if(!res || res.response_code != 200) {
			$("ITHeaderContent").innerHTML = "<p>Failed to process data</p>"; return;
			$("ITMainContent").innerHTML = "";
		}

		var item = itemInfo[0];
		this.ShowItem(item);
	},

	ShowItem : function(item) {
		var topHtml = "<div class='ItemList'><div class='ItemZone'><div style='background-color:#E2E1C7;font-weight:bold;font-size:1.1em;padding-left:5px'>Item Details</div>";
		topHtml += "<div class='ItemBody' id='Body" + item.id + "'>";
		topHtml += hpe.RenderItemHeader(item);
		if(Delicious.BlogBadge)
			topHtml += "<div id='DeliciousDiv' style='padding-left:20px'></div>"
//		topHtml += "<iframe src='http://digg.com/api/diggthis.php?u="+escape(item.link)+"' height='80' width='52' frameborder='0' scrolling='no' align='right'></iframe>";
		topHtml += "<div id='akst_social'><ul>";
		topHtml += "<li><a id='akst_digg' href='http://digg.com/submit?phase=2&url=" + escape(item.link) + "' target='_blank'>Digg</a></li>";
		topHtml += "<li><a id='akst_furl' href='http://furl.net/storeIt.jsp?u=" + escape(item.link) + "' target='_blank'>Furl</a></li>";
		topHtml += "<li><a id='akst_netscape' href='http://www.netscape.com/submit/?U=" + escape(item.link) + "' target='_blank'>Netscape</a></li>";
		topHtml += "<li><a id='akst_yahoo_myweb' href='http://myweb2.search.yahoo.com/myresults/bookmarklet?u=" + escape(item.link) + "' target='_blank'>Yahoo! MyWeb</a></li>";
		topHtml += "<li><a id='akst_stumble' href='http://www.stumbleupon.com/submit?url=" + escape(item.link) + "' target='_blank'>StumbleUpon</a></li>";
		topHtml += "<li><a id='akst_google_bmarks' href='http://www.google.com/bookmarks/mark?op=edit&bkmk=" + escape(item.link) + "' target='_blank'>Google Bookmarks</a></li>";
		topHtml += "<li><a id='akst_technorati' href='http://www.technorati.com/faves?add=" + escape(item.link) + "' target='_blank'>Technorati</a></li>";
		topHtml += "<li><a id='akst_newsvine' href='http://www.newsvine.com/_wine/save?u=" + escape(item.link) + "' target='_blank'>Newsvine</a></li>";
		topHtml += "<li><a id='akst_reddit' href='http://reddit.com/submit?url=" + escape(item.link) + "' target='_blank'>Reddit</a></li>";
		topHtml += "<li><a id='akst_tailrank' href='http://tailrank.com/share/?link_href=" + escape(item.link) + "' target='_blank'>Tailrank</a></li>";
		topHtml += "<li><a id='akst_magnolia' href='http://ma.gnolia.com/bookmarklet/add?url=" + escape(item.link) + "' target='_blank'>ma.gnolias</a></li>";
		topHtml += "<li><a id='akst_blinklist' href='http://blinklist.com/index.php?Action=Blink/addblink.php&Url=" + escape(item.link) + "' target='_blank'>Blinklist</a></li>";
		topHtml += "</ul></div>";
		topHtml += "<div class=\"Post\" style='clear:both;border-top:1px dotted #E2E1C7;padding-top:10px'>";

		if(isPremiumPortal) {
			if(item.isClip)
				topHtml += ("<a onClick=\"return hpe.UnClipItem('" + item.id + "')\"><img width='38' id=\"Clip" + item.id + "\" src=\"/i/boclip-on.png\" /></a> ");
			else
				topHtml += ("<a onClick=\"return hpe.ClipItem('" + item.id + "')\"><img width='38' id=\"Clip" + item.id + "\" src=\"/i/boclip-off.png\" /></a> ");
			topHtml += ("<a onClick=\"return app.PostItemSms('" + item.id + "')\"><img width='38' src=\"/i/sms.png\" /></a> ");
		}
		topHtml += ("<a onClick=\"app.PostOneItemMail('" + item.id + "')\"><img width='35' src=\"/i/bomail.png\" /></a> ");
		if(blogList.length)
			topHtml += ("<a onClick=\"app.PostOneItemBlog('" + item.id + "')\"><img width='35' src=\"/i/boblog.png\" /></a> ");
		if(item.comments)
			topHtml += ("<a href=\"" + item.comments + "\" title=\"Post a Comment\" target=\"_blank\"><img width='62' src=\"/i/bocomment.png\" /></a> ");
		if(isPremiumPortal) {
			if (item.isClip && this.AnnotateClipShow)
				topHtml += "<a onClick=\"app.AnnotateClipShow('" + item.id + "')\" title=\"Add or edit annotation\"><img width='58' src=\"/i/boannotate.png\" /></a> ";
			if(srcInfo[item.sourcekey] && srcInfo[item.sourcekey].id)
				topHtml += ("<a onClick=\"app.FindSimilarItems('" + item.id + "')\"><img width='46' src=\"/i/bosimilar.png\" /></a> ");
			topHtml += "<a onClick=\"app.FindYQItems('" + item.id + "')\"><img width='88' src=\"/i/boyq.png\" /></a> ";
			topHtml += "<a onClick=\"app.ShowStikkit('" + item.id + "')\"><img width='48' src=\"/i/stikkit.png\" /></a> ";
		}
		topHtml += "</div>";
		topHtml += "<div class=\"Post\" id='ITLogMessage' style='border-top:1px dotted #E2E1C7;padding-top:10px;display:none;color:red;font-weight:bold'>";
		topHtml += "</div>";
		topHtml += "</div></div></div>";
		$("ITHeaderContent").innerHTML = topHtml;

		var bottomHtml = "<div class='ItemList'><div class='ItemZone'><div class='ItemBody'>";
		if(item.desc != '') {
			var desc = new String(item.desc);
			desc = desc.replace(/<[aA]/g, "<a onClick=\"return hpe.VisitItem('" + item.id + "', this)\" target=\"_blank\"");
			bottomHtml += "<table><tr><td class=\"Desc\" id=\"ItemDescZone" + item.id + "\">" + desc + "</td></tr></table>";
		}
		else bottomHtml += "<p><em>No Description</em></p>";
		bottomHtml += "</div></div></div>";
		$("ITMainContent").innerHTML = bottomHtml;

		if(Delicious.BlogBadge) {
			var url = siteHome + "ajaxAPI.php?api_call=Item::delicious_badge&api_format=PASSTHRU&seed=" + pageLoadSeed;
			pageLoadSeed++;
			var pars = "url=" + escape(item.link);
			var myAjax = new Ajax.Request(url, { method:'get', parameters: pars, onComplete:this.GetDelIcioUsBadgeProcess.bind(this) });
		}
	},
	
	ReLoadDesc : function(log) {
		var item = this.getItem(this.id);
		var bottomHtml = "<div class='ItemList'><div class='ItemZone'><div class='ItemBody'>";
		if(item.desc != '')
		{
			var desc = new String(item.desc);
			desc = desc.replace(/<[aA]/g, "<a onClick=\"return hpe.VisitItem('" + item.id + "', this)\" target=\"_blank\"");
			bottomHtml += "<table><tr><td class=\"Desc\" id=\"ItemDescZone" + item.id + "\">" + desc + "</td></tr></table>";
		}
		else bottomHtml += "<p><em>No Description</em></p>";
		bottomHtml += "</div></div></div>";
		$("ITMainContent").innerHTML = bottomHtml;
		if(log) {
			$("ITLogMessage").innerHTML = log;
			$("ITLogMessage").show();
		}
		else $("ITLogMessage").hide();
	},

	ShowBodyContent : function(title, body) {
		var bottomHtml = "<div class='ItemList'><div class='ItemZone'><div style='background-color:#E2E1C7;font-weight:bold;font-size:1.1em;padding-left:5px'>" + title + "</div>";
		bottomHtml += "<div class='ItemBody'>" + body + "</div></div></div>";
		$("ITMainContent").innerHTML = bottomHtml;
	},

	GetDelIcioUsBadgeProcess : function(request) {
		try { data = eval('('+request.responseText+')'); } 
		catch(e) { alert("Failed to process answer"); return hpe.error(e); }

		var item = this.getItem(this.id);
		var html = "<div class=\"delicious-blogbadge-line\">";

	    var total_posts = data.total_posts || 0;
	    var top_tags = []; 
	    for (t in data.top_tags) top_tags.push(t);
	    top_tags.sort(function(a,b) { return ( data.top_tags[b] - data.top_tags[a] ); });
	    var post_bookmark_url = 'http://del.icio.us/post'+
	        '?url='+encodeURIComponent(item.link)+
	        '&title='+encodeURIComponent(item.title || '')+
	        '&jump=no&partner=delbg';

		html += "<a class='save-to-link' href='" + post_bookmark_url + "' target='_blank'>bookmark this item on del.ico.us</a> ";
		html += "<span class='save-to-link-label'>bookmark this on del.icio.us</span> ";
		if(total_posts > 0) {
			html += "<a class='url-link' href='http://del.icio.us/url/" + data.hash + "' target='_blank'>";
			html += "<span class='post-count-label-before'>saved by </span>";
			html += "<span class='post-count'>" + total_posts + "</span>";
			html += "<span class='post-count-label-after'>" + (total_posts>1 ? " other people" : " other person") + "</span>";
			html += "</a>";
		} else {
			html += "<a href='" + post_bookmark_url + "' class='empty-save-to-link'><span class='empty-save-to-link-label'>save this</span></a>";
			html += "<span class='empty-message'>be the first to bookmark this page!</span>";
		}
		if(total_posts > 0 && top_tags.length > 0) {
			html += " <div class='top-tags-container'><span class='top-tags-title'>tags: </span><ul class='top-tags'>";
			top_tags.each(function(v){html += "<li><a href='http://del.icio.us/tag/"+v+"' title='"+v+"' target='_blank'>"+v+"</a></li> "});
			html += "</ul></div>";
		}

		html += "</div>";
		$("DeliciousDiv").innerHTML = html;
	},

	AnnotateClipShow : function(id) {
		var item = hpe.getItem(id);
		var html = '<textarea name="annotate_'+id+'_text" id="annotate_'+id+'_text" class="annotation">' + id;
		if (item.annotation) html += item.annotation;
		html += "</textarea>&nbsp;<input type='button' value='Save' onClick=\"appCL.AnnotateClipSave('"+id+"')\">";
		hpe.PostItemOps(id, 'annotate', html, true);
	},

	AnnotateClipSave : function(id) {
		var url = siteHome + "ajaxAPI.php?api_call=Clipping::annotate&api_format=JSON";
		var post = "id=" + id + "&annotation=" + $F('annotate_'+id+'_text');
		var myAjax = new Ajax.Request( url, {method: 'post', postBody: post, onSuccess: this.AnnotateClipSaveDone.bind(this, id) } );
	},

	AnnotateClipSaveDone : function(id, Request) {
		try { var res = eval('('+Request.responseText+')'); }
		catch(e) { return hpe.error(e); }
		if (res.response_code>=300)
			return false;
		var item = hpe.getItem(id);
		item.annotation = $F('annotate_'+id+'_text');
		hpe.PostItemOps(id, 'annotate');
		hpe.RenderItem(item, id);
	},

	GetItemPostBody : function(id) {
		var item = this.getItem(id);
		var bodyhtml = "<p>In <a href=\"" + item.sourcelink + "\">" + srcInfo[item.sourcekey].title + "</a>: ";
		bodyhtml += "<a href=\"" + item.link + "\">" + item.title + "</a>";
		if(item.desc != "") bodyhtml += ("\n<blockquote>" + item.desc + "</blockquote>");
		bodyhtml += "</p>\n\n";
		return bodyhtml;
	},

	PostOneItemMail : function(id) {
		var html  = "<form id=\"PostItemsForm\" name=\"PostItemsForm\" style=\"padding:10px 5px 10px 5px\" onSubmit=\"return app.PostItemsMailNow()\"><table align='center'>";
		html += "<tr><th align=\"right\" nowrap>Your Email:</th><td><input type=\"text\" size=\"30\" name=\"MailSender\"";
		if(!userIsGuest)
			html += " value=\"" + userName + "<" + userEmail + ">\"";
		html += " /></td></tr>\n";
		html += "<tr><th align=\"right\">To:</th><td><input type=\"text\" size=\"30\" id=\"MailToField\" name=\"MailTo\" value=\"" + this.postPrevEmails + "\" onKeyUp='getRecent(this);'/>" +
				"<span id='MailToField_error' class='errormsg hidden'>Need to enter a valid email address!</span></td></tr>\n";
		html +='<tr><td>&nbsp;</td><td><div id="recent" style=""></div></td></tr>';

		var item = this.getItem(id);
		html += "<tr><td colspan=\"2\">&nbsp;</td></tr><tr><th align=\"right\">Subject:</th><td><input type=\"text\" size=\"30\" name=\"MailSubject\" value=\"";
		html += EscapeQuotes(item.title);
		html += "\"></td></tr>\n";
		html += "<tr valign=\"top\"><th align=\"right\">Body:</th>";
		html += "<td id=\"DisplayBody" + id + "\">";
		html += "<textarea cols=\"60\" rows=\"9\" name=\"MailBody\" id=\"MailBody\" class='editzone'>" + this.GetItemPostBody(id) + "</textarea>";
		html += "</td></tr>\n";
		html += "</table>";
		html += "<p align='center'><input type='button' value='Cancel' onclick='app.ReLoadDesc()'/> <input type='button' value='Send' onclick='app.PostItemsMailNow()'/></p></form>";

		this.ShowBodyContent("Post Item to Mail", html);
		Field.focus("MailToField");
		tinyMCE.execCommand("mceAddControl", false, "MailBody");
		$("ITLogMessage").hide();
	},

	PostItemsMailNow : function (button) {
		var form = $("PostItemsForm");

		var post = new String;
		var to = "";
		if(form) {
			var ne = form.elements.length;
			for(ie=0; ie<ne; ie++) {
				if(form.elements[ie].name == "MailSender")
					post += form.elements[ie].name + "=" + escape(form.elements[ie].value) + "&";
				else if(form.elements[ie].name == "MailSubject" || form.elements[ie].name == "MailBody")
					post += form.elements[ie].name + "[]=" + escape(form.elements[ie].value) + "&";
				else if(form.elements[ie].name == "EditedBody" && form.elements[ie].value != "")
					post += "MailBody[]=" + escape(form.elements[ie].value) + "&";
				else if(form.elements[ie].name == "MailTo") {
					var regex = /.+@.+\..+/;
					if(regex.test(form.elements[ie].value)) {
						to = form.elements[ie].value;
						this.postPrevEmails = to;
						post += form.elements[ie].name + "=" + escape(form.elements[ie].value) + "&";
					}
				}
			}

			if(to == "") {
				// alert("Need to enter an email address!");
				Element.removeClassName('MailToField_error', 'hidden');
				Field.focus("MailToField");
				return false;
			}
			post += "-----------------------------7d325a200432--\n";
			var url = siteHome + "ajaxAPI.php?api_call=Item::postmail&api_format=JSON";
			var myAjax = new Ajax.Request( url, {method: 'post', postBody: post, onSuccess: this.PostItemsProcess.bind(this)} );
			lightWin.wait("Posting Items to Mail");
			return false;
		}
		else hpe.log("Failed to find mail form");
		return false;
	},

	PostOneItemBlog : function (id) {
		if (blogList.length<1) return;

		var html  = "<form id=\"PostItemsForm\" name=\"PostItemsForm\" style=\"padding:10px 5px 10px 5px\" onSubmit=\"return app.PostItemsBlogNow()\"><table align='center'>";
		var deschtml = "";
		var item = this.getItem(id);
		html += "<tr><tr><th align=\"right\">Title:</th><td><input type=\"text\" size=\"40\" name=\"BlogTitle\" id=\"BlogTitle" + id + "\" value=\"";
		html += EscapeQuotes(item.title);
		html += "\" /></td></tr>\n";
		html += "<tr><th align=\"right\">Link:</th><td><input type=\"text\" size=\"40\" name=\"BlogLink\" value=\"";
		html += EscapeQuotes(item.link);
		html += "\" /></td></tr>\n";

		html += "<tr valign=\"top\"><th align=\"right\">Body:</th><td id=\"DisplayBody" + id + "\">";
		html += "<textarea cols=\"60\" rows=\"9\" name=\"BlogBody\" id=\"BlogBody\">" + this.GetItemPostBody(id) + "</textarea>";
		html += "</td></tr>\n";
		html += "</table><table style=\"padding-left:20px\" align='center'>\n";
		html += "<tr><td colspan=\"4\"><small><em>Choose one or more blogs you want to post to.<br />If the password is not stored in your settings, you'll have to type it in now</em></small></td></tr>\n";
		for(var i in blogList) if(typeof blogList[i] != 'function') {
			html += "<tr><td><input type=\"checkbox\" name=\"BlogIndex" + i + "\" value=\"" + i + "\" /></td>\n";
			html += "<td style=\"padding-left:10px\" nowrap>\n";
			html += "<a href=\"/weblog/edit/" + i + "/\" target=\"_blank\" title=\"Edit This Blog Info\">" + blogList[i].title + "</a></td>\n";
			html += "<td style=\"padding-left:20px\">";
			if(blogList[i].hasPasswd)
				html += "</td><td><input type=\"hidden\" name=\"BlogPassword" + i + "\" />";
			else
				html += "<small><em>Password:&nbsp;</em></td><td width=\"100%\"><input type=\"password\" size=\"10\" name=\"BlogPassword" + i + "\" /></small>";
			html += "</td></tr>\n";
		}
		html += "</table>";
		html += "<p align='center'><input type='button' value='Cancel' onclick='app.ReLoadDesc()'/> <input type='button' value='Post' onclick='app.PostItemsBlogNow()'/></p></form>";

		this.ShowBodyContent("Post Item to Blog", html);
		Field.focus("BlogTitle" + id);
		tinyMCE.execCommand("mceAddControl", false, "BlogBody");
		$("ITLogMessage").hide();
	},

	PostItemsBlogNow : function (button) {
		var form = $("PostItemsForm");

		var post = new String;
		var blogs = new Array;
		if(form) {
			var ne = form.elements.length;
			var curBlog = -1;
			for(ie=0; ie<ne; ie++) {
				if(form.elements[ie].name == "BlogTitle" || form.elements[ie].name == "BlogLink" || form.elements[ie].name == "BlogBody")
					post += form.elements[ie].name + "[]=" + escape(form.elements[ie].value) + "&";
			}

			foundBlog = 0;
			for(ib=0; ib<blogList.length; ib++) {
				for(ie=0; ie<ne; ie++) {
					if(form.elements[ie].name == "BlogIndex" + ib && form.elements[ie].checked) {
						post += "blog[]=" + ib + "&";
						foundBlog++;

						ie++;
						if(ie < ne && form.elements[ie].name == "BlogPassword" + ib) {
							if(blogList[ib].hasPasswd)
								break;
							if(form.elements[ie].value != "") {
								post += "blogpasswd[" + ib + "]=" + escape(form.elements[ie].value) + "&";
								break;
							}
						}
						alert("Need to provide a password for blog '" + blogList[ib].title + "'");
						return false;
					}
				}
			}
			if(foundBlog == 0) {
				alert("Select a blog!");
				return false;
			}
			var url = siteHome + "ajaxAPI.php?api_call=Item::postblog&api_format=JSON";
			var myAjax = new Ajax.Request( url, {method: 'post', postBody: post, onSuccess: this.PostItemsProcess.bind(this)} );
			lightWin.wait("Post Items to Blog");
			return false;
		}
		else hpe.log("Failed to find form");
		return true;
	},
	
	PostItemsProcess : function (request) {
		lightWin.hide();

		try { var res = eval('('+request.responseText+')'); } 
		catch(e) { this.ReLoadDesc("Failed to process response"); return hpe.log(e); }

		if(res.response_code==200) {
			if(res.post_result) {
				lightWin.alert("Posted Item", res.post_result);
				this.ReLoadDesc();
			} else this.ReLoadDesc("Item was posted successfully");
			return
		}
		if(res.response_code>=500) {
			if(res.post_result) {
				lightWin.alert("Posted Item", res.post_result);
				this.ReLoadDesc();
			} else this.ReLoadDesc("Failed to post item");
			return
		}
		if(res.response_code>=300) { hpe.GotoLogin(); return }
	},

	FindSimilarItems : function(id) {
		var item = this.getItem(id);
		var post = "language=" + srcInfo[item.sourcekey].language + "&query=" + escape(item.title);

		var url = siteHome + "ajaxAPI.php?api_call=Item::similar&api_format=JSON&id=" +  id;
		var myAjax = new Ajax.Request( url, {method: 'post', postBody: post, onSuccess: this.FindSimilarItemsProcess.bind(this)} );

		lightWin.wait("Searching for similar items");
		$("ITLogMessage").hide();
	},
	
	FindSimilarItemsProcess : function(request) {
		lightWin.hide();

		try { var res = eval('('+request.responseText+')') } 
		catch(e) { this.ReLoadDesc("Failed to process data..."); return hpe.error(e); }

		if(isNull(res.similarItems) || res.similarItems.length == 0) {
			this.ReLoadDesc("Found no similar items...");
			return;
		}

		var shtml = "<table align=center cellspacing='0' cellpadding='1'>";
		for(var i=0; i < res.similarItems.length; i++) {
			if(res.similarItems[i].title == "")
				continue;
			shtml += "<div style=\"line-height:1.1;padding:3px 3px 3px 3px;background:#" + (i % 2 ? "eee" : "fff") + "\">" +
					 "<a href=\"" + res.similarItems[i].link + "\" target=\"_blank\"><b>" + res.similarItems[i].title + "</b></a><br />\n" +
					 "<div style=\"font-size:90%\"><em> in <a href=\"/sources/info/" + res.similarItems[i].sourceid + "/\" target=\"_blank\">" + res.similarItems[i].source + "</a></em></div></div>\n";
		}
		shtml += "</table>";

		this.ShowBodyContent("Similar Items", shtml);
	},

	FindYQItems : function(id) {
		var item = this.getItem(id);

		var url = siteHome + "ajaxAPI.php?api_call=Item::yq&api_format=JSON&id=" +  id + "&lang=" + srcInfo[item.sourcekey].language;
		var post = "context=" + escape(item.title);
		var desc = new String(item.desc);
		post += "+" + escape(desc.replace(/<[^>]+>/g, " "));

		var myAjax = new Ajax.Request( url, {method: 'post', postBody: post, onSuccess: this.FindYQItemsProcess.bind(this)} );

		lightWin.wait("Searching Y!Q for similar items");
		$("ITLogMessage").hide();
	},

	FindYQItemsProcess : function(request) {
		lightWin.hide();

		try { var res = eval('('+request.responseText+')'); } 
		catch(e) { this.ReLoadDesc("Failed to process data..."); return hpe.error(e); }

		if(isNull(res.yqItems) || res.yqItems.length == 0) {
			this.ReLoadDesc("Y!Q returned no items");
			return;
		}

		var shtml = "<table align=center><tr><td><div style=\"white-space:normal\">";

		for(var i in res.yqItems) if(typeof res.yqItems[i] != 'function') {
			shtml += "<div style=\"line-height:1.1;padding:3px 3px 3px 3px;background:#" + (i % 2 ? "eee" : "fff") + "\">" +
					 "<a href=\"" + res.yqItems[i].link + "\" target=\"_blank\"><b>" + res.yqItems[i].title + "</b></a><br />\n" +
					 "<div style=\"font-size:90%\">" + res.yqItems[i].desc + "</div></div>\n";
		}

		shtml += "</div><div style=\"text-align:right;font-size:80%;padding-top:5px\">powered by " +
			"<a href=http://yq.search.yahoo.com/splash/start.html target=_blank>Yahoo! Search</a></div></td></tr></table>";

		this.ShowBodyContent("<img src=http://us.i1.yimg.com/us.yimg.com/i/us/search/gr/yq_small.gif width=21 height=16 /> Similar Items provided by Y!Q", shtml);
	},

	PostItemSmsNow : function (button) {
		if (!userCanSendSms) {
			alert('Can not send sms: sms credit balance is too low');
			return;
		}
		var form = $("PostItemsForm");

		var post = new String;
		var to = "";
		if(form) {
			var ne = form.elements.length;
			for(ie=0; ie<ne; ie++) {
				if(form.elements[ie].name == "subject" || form.elements[ie].name == "text" || form.elements[ie].name == "link")
					post += form.elements[ie].name + "=" + escape(form.elements[ie].value) + "&";			
				else if(form.elements[ie].name == "SmsTo") {
					var regex = /^[0-9]+$/;
					if(regex.test(form.elements[ie].value)) {
						to = form.elements[ie].value;
						this.postPrevSms = to;
						post += form.elements[ie].name + "=" + escape(form.elements[ie].value) + "&";
					}
				}
			}

			if(to == "") {
				// alert("Need to enter an email address!");
				Element.removeClassName('SmsToField_error', 'hidden');
				Field.focus("SmsToField");
				return false;
			}
			post += "-----------------------------7d325a200432--\n";
			var url = siteHome + "ajaxAPI.php?api_call=Item::postsms&api_format=JSON";
			var myAjax = new Ajax.Request( url, {method: 'post', postBody: post, onSuccess: this.PostItemsProcess.bind(this)} );
			lightWin.wait("Posting item to mobile phone");
			return false;
		}
		else hpe.log("Failed to send sms");
		return false;
	},

	/*Send item over sms*/
	PostItemSms : function(id) {
		var item = this.getItem(id);

		var html  = "<form id=\"PostItemsForm\" name=\"PostItemsForm\" style=\"padding:10px 5px 10px 5px\" onSubmit=\"return hpe.PostItemSmsNow()\"><table width='600px' align=center>";	
		html += "<tr><th align=\"right\" nowrap>To mobile number:</th><td><input type=\"text\" size=\"30\" id=\"SmsToField\" name=\"SmsTo\" value=\"\" onKeyUp='getRecent(this);'/>" +
				"<span id='SmsToField_error' class='errormsg hidden'>Need to enter a valid mobile phone number!</span></td></tr>\n";
		html +='<tr><td>&nbsp;</td><td><div id="recent" style=""></div></td></tr>';

		var item = this.getItem(id);
		html += "<tr><td colspan=\"2\">&nbsp;</td></tr><tr><th align=\"right\">Subject:</th><td>";
		html += item.title;
		html += "<input type='hidden' name='subject' value=\""+EscapeQuotes(item.title.stripTags())+"\"></td></tr>\n";
		html += "<tr valign=\"top\"><th align=\"right\">Body:</th>";
		html += "<td id=\"DisplayBody" + id + "\"><input type=\"hidden\" name='text' value=\""+EscapeQuotes(item.shortdesc)+"\">";
		html += item.shortdesc;
		html += "</td></tr>\n";
		html +="<tr><td align='right'>Link:</td><td><input type='hidden' name='link' value=\""+EscapeQuotes(item.link)+"\">"+item.link+"</td></tr>";
		html += "</table>";
		html += "<p align='center'><input type='button' value='Cancel' onclick='app.ReLoadDesc()'/> <input type='button' value='Post' onclick='app.PostItemSmsNow()'/></p></form>";

		this.ShowBodyContent("Send Item by SMS", html);
		Field.focus("SmsToField");
	},

	ShowStikkit : function(id) {
		function ce(e){s=document.createElement(e);if (typeof s!='object')s=document.standardCreateElement(e);return s;}
		var item = this.getItem(id);

		var k='';
		if(item.tags.length)
			k="\ntag as "+item.tags.join(' ');
		var t="\n" + item.shortdesc;
		var s=ce('script');
		s.setAttribute('type','text/javascript');
		var url='http://stikkit.com/stikklet/new.js?raw_text='+
			encodeURIComponent((item.title?item.title+"\n":'')+item.link+t+k);
		s.setAttribute('src', url);
		document.getElementsByTagName('head').item(0).appendChild(s);

		var html = "<p align='center'><div id='stikkit-stikklet' \
			style='width:400px;background:#3e6aa1;border:1px solid #5d88bd; \
			font-size:24px;line-height:60px;text-align:center;font-family:verdana; \
			font-weight:bold;color:#fff;margin-bottom:10px'>Loading stikkit<blink>…</blink></div></p>";
		this.ShowBodyContent("Send Item to Stikkit", html);
	}


});

