CurrentObject = null;
CurrentObjectAction = null;

// =====================================================================================================
// Отбелязваме кои е текущият видим обект
function SetCurrentObject(sObjectName){
	SetEmptyException(sObjectName, "sObjectName е задължителен аргумент на SetCurrentObject", 1003);
	CurrentObject = GetObjectInformation(sObjectName);
	SetEmptyException(CurrentObject, "Няма обект с име '"+sObjectName+"'", 1004);
}

// =====================================================================================================
// Отбелязваме кои е текущият видим action
function SetCurrentObjectAction(sObjectActionName){
	SetEmptyException(sObjectActionName, "sObjectActionName е задължителен аргумент на SetCurrentObjectAction", 1005);
	CurrentObjectAction = GetObjectAction(sObjectActionName);
}

// =====================================================================================================
// Взимаме текущият видим обект
function GetCurrentObject(){
	return CurrentObject;
}

// =====================================================================================================
// Взимаме кода на текущият видим обект
function GetCurrentObjectCode(){
	var CurrentObject = GetCurrentObject();
	if(CurrentObject)
		return CurrentObject.Code;
	return null;
}

// =====================================================================================================
// Взимаме текущият видим action
function GetCurrentObjectAction(){
	return CurrentObjectAction;
}

// =====================================================================================================
// Взима информация за action по ObjectActionCode
function GetObjectAction(sObjectActionCode){
	if(SetEmptyException(sObjectActionCode, "sObjectActionCode трябва да е от вида Order.List", 1006))
		return false;
	var ObjectInformation = GetObjectInformation(GetObjectCode(sObjectActionCode));
	var ObjectAction = ObjectInformation.Actions.Get(sObjectActionCode);
	if(SetEmptyException(ObjectAction, GetObjectCode(sObjectActionCode)+" няма метод "+sObjectActionCode, 1007))
		return false;
	return ObjectAction;
}

// =====================================================================================================
function GetCurrentUserID(){
	return top.CurrentUserID;
}

// =====================================================================================================
function RefreshContent(ContentWindow, bRefreshAll, arAttributes){
	if(typeof(bRefreshAll) == "undefined")
		bRefreshAll = false;
	if(IsListAction(ContentWindow) && !bRefreshAll){
		var ListView = ContentWindow.GetListView3();
		if(ListView)
			ListView.RefreshPage();
	}else{
		if(ContentWindow == self){
			var oLink = document.createElement("A");
			document.body.appendChild(oLink);
			window.name = "_target";
			oLink.target = "_target";
			oLink.display = "none";
			oLink.href = window.location;
			var sUrl = "";
			if(typeof(arAttributes) != "undefined"){
				for(var i in arAttributes)
					sUrl += "&"+i+"="+arAttributes[i];
				oLink.href += sUrl;
			}
			oLink.click();
		}else{
			ContentWindow.frameElement.ContentHolder.Reload(arAttributes);
		}
	}
}

// =====================================================================================================
function CheckGotoLogin(){
	var CurrentWindow = window;
	while(true){
		if(CurrentWindow.dialogArguments && CurrentWindow.dialogArguments.ParentWindow){
			CurrentWindow.close();
			CurrentWindow = CurrentWindow.dialogArguments.ParentWindow;
		}else{
			break;
		}
	}
	if(CurrentWindow != top){
		alert("Your session has expired. Please login again! / Сесията ви е изтекла. Моля влезте в системата отново!");
		CurrentWindow.open("?nAction=800", "_top");
	}
}
// =====================================================================================================
function SetPopupLocation(sLocation){
	var oLink = document.createElement("A");
	document.body.appendChild(oLink);
	window.name = "__SecretWindowName";
	oLink.target = window.name;
	oLink.display = "none";
	oLink.href = sLocation;
	oLink.click();
}
