﻿/*****************************************************************************/
function openWindow(url, name, w, h)
{
	return openWindow(url, name, w, h, false);
}
function openWindow(url, name, w, h, scrollable)
{
	return window.open(url, name, "toolbar=0,scrollbars="+(scrollable?"1":"0")+",status=0,width="+w+",height="+h);
}
/*****************************************************************************/
function openBidLiveWindow(url, id)
{
	var win = openWindow(url, 'BidLive_'+id, 812, 608);
	if (win.focus) win.focus();

	return false;
}
/*****************************************************************************/
function clearTextBox(txt, onlyfirsttime)
{
	if(!txt._clearedonce)
	{
		txt.value = "";
		txt._clearedonce = true;
	}
}
/*****************************************************************************/
function goSearch(query)
{
	if(query.length > 0)
	{
		document.location.href = "search.aspx?q=" + query;
	}
}
/*****************************************************************************/
function trackOutgoing(url)
{
	$.ajax({type:"GET",url:url});
}
/*****************************************************************************/
function includeJS(jspath)
{
	var ele = document.createElement("script");
	ele.setAttribute("type", "text/javascript");
	ele.setAttribute("src", jspath);
	document.getElementsByTagName("head")[0].appendChild(ele);
}
/*****************************************************************************/
function out2D(num) { return (num < 10) ? ("0" + num) : num; }
/*****************************************************************************/
function reloadPage() { document.location.href = document.location.href; }
/*****************************************************************************/
function showhide(show, ele)
{
	ele.style.display = show ? "none" : "";
}
/*****************************************************************************/
// Item Bookmark Javascript
// HTML Element Link Struct ({bset:element, brem:element}), ItemID (int), Bookmark (bool - off/on)
function BookmarkItem(linkelements, itemid, bookmark)
{
	var path = relpath + "handlers/registrant.ashx";
	var varData = {
		command: "bookmarkitem",
		i: itemid,
		bm: bookmark
	};

	$.ajax({
		type:"GET",
		url:path,
		data:varData,
		success:function(responseText){BookmarkItem_Success(responseText, linkelements);},
		error:function(responseText){BookmarkItem_Failure(responseText);}
	});
}

function BookmarkItem_Success(xml_response, linkelements)
{
	var response = $(xml_response).find("response");

	switch(response.attr("type"))
	{
		case "success":
			var state = response[0].getElementsByTagName("fieldstate")[0].firstChild.nodeValue;
			var itemid = response[0].getElementsByTagName("fielditemid")[0].firstChild.nodeValue;

			if (state == 1) // bookmark on
			{
				linkelements.bset.hide();
				linkelements.brem.show();
			}
			else // bookmark off
			{
				linkelements.bset.show();
				linkelements.brem.hide();
			}
			
			return;
		case "failure":
			alert("An error occurred while trying to bookmark this item, please try again!");
			return;
		default:
			break;
	}
}

function BookmarkItem_Failure(xml_response)
{
	alert("A communication error occurred while trying to bookmark this item, please try again!");
}
/*****************************************************************************/