﻿		// JScript File
		var bid_history_hide_elements;
		var bid_history_agens = "agents";
		var bid_history_bids = "bids";
		var bid_history_mode = bid_history_bids;
		function isBidHistoryActivated(){
			return bid_history_mode == bid_history_bids;
		}
		function activateBidHistory(){
			bid_history_mode = bid_history_bids;
		}
		function activateBidAgentsHistory(){
			bid_history_mode = bid_history_agens;
		}
		
		// ----------------------------- Bid Agents History -----------------------------------------
		function show_bid_agent_history_with_params(lotId, isPositionChange, isPositionChangeId)
		{
			bh_setLotId(lotId);
			activateBidAgentsHistory(); 
			changePosition = isPositionChange;
			changePositionId = isPositionChangeId;
			show_bid_agent_history();
		}
		function show_bid_agent_history()
		{		
			lotId = bh_getLotId();
			bidTypeCodes = document.getElementById('hBidTypeCodes').value;
			bidStateCodes = document.getElementById('hBidStateCodes').value;
			
			pageIndex = document.getElementById('hPageIndex').value;
			pageSize = document.getElementById('hPageSize').value;
			
			lotId = bh_getLotId();
			bidTypeCodes = document.getElementById('hBidTypeCodes').value;
			bidStateCodes = document.getElementById('hBidStateCodes').value;
			extendedView = document.getElementById('hExtendedView').value;

			WebService.ReachBidAgentHistory(lotId, pageIndex, pageSize, true, onReachBidAgentsHistoryCompleted);
		}
		
		function onReachBidAgentsHistoryCompleted(arg)
		{
			hideBeforeBiddingHistory();
			set_display('biddingHistory','block');
			obj = document.getElementById('spanContent');
			if(obj)
			{
				obj.innerHTML = arg.Data;
			}
			document.getElementById('biddingHistoryCloseLink').style.display = 'inline';
			document.getElementById('biddingHistoryCloseText').style.display = 'none';
			
			RefreshPaging(arg.RowsCount);
		}
		// ------------------------------------------------------------------------------------------
		
		
		function showHistory(){
			if (isBidHistoryActivated()) {
				show_bidding_history();
			}
			else
				show_bid_agent_history();
		}
		
		
		function show_bidding_history_with_params(lotId, isPositionChange, isPositionChangeId)
		{
			bh_setLotId(lotId);
			activateBidHistory();
			changePosition = isPositionChange;
			changePositionId = isPositionChangeId;
			
			
			showHistory();			
		}
		
		function show_bidding_history()
		{
			lotId = bh_getLotId();
			bidTypeCodes = document.getElementById('hBidTypeCodes').value;
			bidStateCodes = document.getElementById('hBidStateCodes').value;
			
			pageIndex = document.getElementById('hPageIndex').value;
			pageSize = document.getElementById('hPageSize').value;
			
			lotId = bh_getLotId();
			bidTypeCodes = document.getElementById('hBidTypeCodes').value;
			bidStateCodes = document.getElementById('hBidStateCodes').value;
			extendedView = document.getElementById('hExtendedView').value;
			WebService.ReachBiddingHistory(lotId, bidTypeCodes, bidStateCodes, pageIndex, pageSize, extendedView == 1, onReachHistoryComplite);
		}

		function onReachHistoryComplite(arg)
		{
			hideBeforeBiddingHistory();
			set_display('biddingHistory','block');
			obj = document.getElementById('spanContent');
			if(obj)
			{
				obj.innerHTML = arg.Data;
			}
			document.getElementById('biddingHistoryCloseLink').style.display = 'inline';
			document.getElementById('biddingHistoryCloseText').style.display = 'none';
			
			RefreshPaging(arg.RowsCount);
		}

		function RefreshPaging(rowsCount)
		{
			pageIndex = document.getElementById('hPageIndex').value;
			pageSize = document.getElementById('hPageSize').value;
			pagesCount = Math.ceil(rowsCount / pageSize);
			
			if(pageIndex == 1)
			{
				hide_div('imgPreviousPage');
				set_display('imgPreviousPageDisabled','block');
			}
			else
			{
				set_display('imgPreviousPage','block');
				hide_div('imgPreviousPageDisabled');
			}
			
			if(pageIndex == pagesCount)
			{
				hide_div('imgNextPage');
				set_display('imgNextPageDisabled','block');
			}
			else
			{
				set_display('imgNextPage','block');
				hide_div('imgNextPageDisabled');
			}
		}
		
		function NextPage(direction)
		{
			document.getElementById('biddingHistoryCloseLink').style.display = 'none';
			document.getElementById('biddingHistoryCloseText').style.display = 'inline';
			
			pageIndex = document.getElementById('hPageIndex').value;

			if(direction == -1)
			{
				pageIndex++;
			}
			else
			{
				pageIndex--;
			}
			
			document.getElementById('hPageIndex').value = pageIndex;
			
			showHistory();
		}
		
		function RefreshHistory()
		{
			document.getElementById('biddingHistoryCloseLink').style.display = 'none';
			document.getElementById('biddingHistoryCloseText').style.display = 'inline';
			
			$("#spanContent").hide("slow");
			showHistory();
			$("#spanContent").show("slow");
		}
		
		function CloseBiddingHistory()
		{
			document.getElementById('hPageIndex').value = 1;
			set_display('biddingHistory','none');

			NeedRefresh = document.getElementById('hNeedRefresh').value;
			onCloseEventHandler = document.getElementById('hOnDialogClosed').value;
			if(onCloseEventHandler && NeedRefresh == 1)
			{
				eval(onCloseEventHandler);
			}
			showAfterBiddingHistory();
		}
		
		function RetractBid(bidId)
		{
			WebService.RetractBid(bidId, RetractBidCompleted);
		}
		function RetractBidAgent(agentId)
		{
			WebService.RetractBidAgent(agentId, RetractBidCompleted);
		}
		
		function RetractBidCompleted()
		{
			RefreshHistory();
			
			document.getElementById('hNeedRefresh').value = 1;
		}

/***** scrolling popup *****/
function initWScroll()
{
	var _p = document.getElementById('biddingHistory');
	if(_p)
	{
		var _offset = getCurrentYPos();
		var _top = _offset;
		_p.style.marginTop = _top + "px";
	}
	window.onscroll = function()
	{
		var _p1 = document.getElementById('biddingHistory');
		if(_p1)
		{
			var _offset = getCurrentYPos();
			var _top = _offset;
			_p1.style.marginTop = _top+ "px";
		}
	}
}
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
function getCurrentYPos()
{
	var _offset = 0;
    if (document.body && document.body.scrollTop)
      _offset =  document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      _offset = document.documentElement.scrollTop;
    if (window.pageYOffset)
      _offset =  window.pageYOffset;
    return _offset;
 }


	if (window.addEventListener){
		window.addEventListener("load", initWScroll, false);
		window.addEventListener("resize", initWScroll, false);
	}
	else if (window.attachEvent){
		window.attachEvent("onload", initWScroll);
		window.attachEvent("onresize", initWScroll);
	}
	
function trim(arg){
    return arg.replace(/^\s*/, "").replace(/\s*$/, "");
}	
	
function getIdsFromString(arg){
	var result = new Array();
	var splitted = arg.toString().split(",");
	if (splitted)
		for(var i = 0; i < splitted.length; i++)
			if (trim(splitted[i]) != "")
				result.push(trim(splitted[i]));
	return result;
}

function showElements(arg){
	if (arg)
		for(var i = 0; i < arg.length; i++){
			var obj = document.getElementById(arg[i]);
			if (obj) {
				obj.style.display = obj.getAttribute("_attr_switch_disp");
			}
		}
}

function hideElements(arg){
	if (arg)
		for(var i = 0; i < arg.length; i++){
			var obj = document.getElementById(arg[i]);
			if (obj) {
				obj.setAttribute("_attr_switch_disp", obj.style.display);
				obj.style.display = "none";
			}
		}
}
function hideBeforeBiddingHistory(){
	if (bid_history_hide_elements)
		hideElements(getIdsFromString(bid_history_hide_elements));
}
function showAfterBiddingHistory(){
	if (bid_history_hide_elements)
		showElements(getIdsFromString(bid_history_hide_elements));
}
function bh_setLotId(lotId){
	var obj = document.getElementById("hBiddingHistoryLotId");
	if (obj)
		obj.value = lotId;
}

function bh_getLotId(){
	
	var obj = document.getElementById("hBiddingHistoryLotId");
	if (obj)
		return obj.value;
	return 0;
}