﻿// JScript File
var globalLotId;
function AddToWatchList(exist, lotId) {
	if (!exist) {
		set_display('login', 'block');
		AdditionalParams.push("&addLotIdToWatchList=" + lotId);
		return;
	}
	globalLotId = lotId;
	WebService.CheckWatchList(lotId, OnComplete, onTimeOut, onError);
}

function AddToWatchListWithCallback(isLoggedIn, lotId, callback) {
	if (!isLoggedIn) {
		set_display('login', 'block');
		if (typeof (focusLogin) != "undefined") {
			focusLogin();
		}
		AdditionalParams.push("&addLotIdToWatchList=" + lotId);
		return;
	}
	globalLotId = lotId;
	WebService.AddToWatchList(globalLotId, function(obj) {
		if (typeof (callback) != "undefined") {
			callback(obj);
		}
		if (obj.isAdded) {
			// display notification
			if (typeof (notifyAddLot) != "undefined") {
				notifyAddLot(globalLotId);
			}
		}
	});
}

function AddToWatchListWithCallback1(isLoggedIn, lotId, callback) {
	if (!isLoggedIn) {
		set_display('login', 'block');
		if (typeof (focusLogin) != "undefined") {
			focusLogin();
		}
		AdditionalParams.push("&addLotIdToWatchList=" + lotId);
		return;
	}
	globalLotId = lotId;
	WebService.AddToWatchList(globalLotId, function(obj) {
		if (typeof (callback) != "undefined") {
			callback(obj);
		}
	});
}

function RemoveFromWatchListWithCallback(lotId, callback) {
	globalLotId = lotId;
	WebService.DelFromWatchList(lotId, function(arg) {
		if (typeof (callback) != "undefined") {
			callback(true);
		}
	});
}

function RemoveFromWatchList(lotId) {
	globalLotId = lotId;
	WebService.DelFromWatchList(lotId, OnCompleteDel, onTimeOutDel, onErrorDel);
}


function OnComplete(arg) {
	if (arg == 0) {
		WebService.AddToWatchList(globalLotId, OnCompleteIns, onTimeOutIns, onErrorIns);
	}
}

function OnCompleteIns(arg) {
	var addToWatchList = document.getElementById('btnAddToWatch' + globalLotId);
	var delFromWatchList = document.getElementById('btnRemoveFromWatch' + globalLotId);
	addToWatchList.style.display = "none";
	delFromWatchList.style.display = "block";
	if (typeof (notifyAddLot) != "undefined") {
		notifyAddLot(globalLotId);
	}
}

function onTimeOutIns(arg) {
    WebService.RedirectToLoginPage(onRedirectComplete);
}

function onTimeOut(arg) {
    WebService.RedirectToLoginPage(onRedirectComplete);
}

function onRedirectComplete(arg) {
    window.location = arg;
}

function onErrorIns(arg) {
	alert("Error " + arg);
}

function onError(arg) {
	alert("Error " + arg);
}

function OnCompleteDel(arg) {
	var addToWatchList = document.getElementById('btnAddToWatch' + globalLotId);
	var delFromWatchList = document.getElementById('btnRemoveFromWatch' + globalLotId);
	addToWatchList.style.display = "block";
	delFromWatchList.style.display = "none";
}

function onTimeOutDel(arg) {
    WebService.RedirectToLoginPage(onRedirectComplete);
}

function onErrorDel(arg) {

}

