function UniqueID()
{
	ldDate = new Date();
	return ldDate.getTime();
}
function CenterWindow(toWin, tnWidth, tnHeight)
{
	lnX = screen.width / 2	- tnWidth / 2;
	lnY = screen.height / 2	- tnHeight / 2;
	toWin.moveTo(lnX, lnY);
}


function GetCenterWindow_Left(tnWidth)
{
	return screen.width / 2	- tnWidth / 2;
}
function GetCenterWindow_Top(tnHeight)
{
	return screen.height / 2	- tnHeight / 2;
}
function openPopup(tcUrl, tnWidth, tnHeight, tcWindowName, tlScrolled, tnPosX, tnPosY)
{
	if(("" + tcWindowName) == "undefined")
	{
		tcWindowName = UniqueID();
	}
	var lcScrolled = tlScrolled == null ? 'no' : 'yes';
	
	var lnLeft	= tnPosX != null ? tnPosX : GetCenterWindow_Left(tnWidth);
	var lnTop	= tnPosY != null ? tnPosY : GetCenterWindow_Top(tnHeight);
	var lcSettings = 
		"left="			+lnLeft		+
		",top="			+lnTop		+
		",scrollbars="	+lcScrolled	+
		",resizable="	+'no'		+
		",width="		+tnWidth	+
		",height="		+tnHeight;
		
	loWin = open(tcUrl, "popup_"+tcWindowName, lcSettings);
	loWin.focus();
}


function openPopupScrolled(tcUrl, tnWidth, tnHeight)
{
	loWin = open(tcUrl, "popup"+UniqueID(), "scrollbars=yes,resizable=no,width="+tnWidth+",height="+tnHeight+"");
	loWin.focus();
}

function editSimpleText(tcTask, tnChapterID, tcLangID, tcFieldName, tcLogicID)
{
	if(tcTask == 'edit' || tcTask == 'add')
	{
		$lcUrl = "editSimpleText.php?task=" +tcTask
			+ "&chapterID="		+ tnChapterID
			+ "&textLangID="	+ tcLangID
			+ "&field_name="	+ tcFieldName
			+ "&logic_id=" 		+ tcLogicID;
		//alert();
		openPopup($lcUrl, 650, 550);
	}
	if(tcTask == 'view')
	{
		window.location = "?text_lang_id="+tcLangID;
	}
	if(tcTask == 'drop' && AreYouSure())
	{
		window.location = "?delete_text_id="+tnChapterID;
	}
	
}

// ============== GALLERY CHAPTER
function editGalleryChapter(tnID)
{
	manageGalleryChapter("edit", tnID);
}
function deleteGalleryChapter(tnID)
{
	manageGalleryChapter("drop", tnID);
}
function addGalleryChapter(tnParentID)
{
	manageGalleryChapter("add", 0, tnParentID);
}

function manageGalleryChapter(tcTask, tnID, tnParentID)
{
	if(tcTask == "add" || tcTask == "edit" || tcTask == "drop")
	{
		lcUrl = "popup/editGalleryChapter.php?task=" + tcTask;
		if(tcTask == "add")
			lcUrl += "&parent_id=" + tnParentID;
		else
			lcUrl += "&id=" + tnID;
		openPopup(lcUrl, 500, 450);
	}
	else
	{
		window.location.href = "?task=" + tcTask + "&id=" + tnID;
	}
}
// ============== GALLERY FOLDER
function editGalleryFolder(tnID)
{
	manageGalleryFolder("edit", tnID);
}
function deleteGalleryFolder(tnID)
{
	manageGalleryFolder("drop", tnID);
}
function addGalleryFolder(tnParentID)
{
	manageGalleryFolder("add", 0, tnParentID);
}

function manageGalleryFolder(tcTask, tnID, tnParentID)
{
	if(tcTask == "add" || tcTask == "edit" || tcTask == "drop")
	{
		lcUrl = "popup/editGalleryFolder.php?task=" + tcTask;
		if(tcTask == "add")
			lcUrl += "&parent_id=" + tnParentID;
		else
			lcUrl += "&id=" + tnID;
		openPopup(lcUrl, 500, 450);
	}
	else
	{
		window.location.href = "?task=" + tcTask + "&id=" + tnID;
	}
}
