var lastPopupWindow = null;

function popup(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, width, height, top, left, replace) {
	lastPopupWindow = window.open(url, windowName, "status="+(status==true?"yes":"no")+", toolbar="+(toolbar==true?"yes":"no")+", status="+(status==true?"yes":"no")+", scrollbars="+(scrollbars==true?"yes":"no")+", menubar="+(menubar==true?"yes":"no")+", location="+(location==true?"yes":"no")+", resizable="+(resizable==true?"yes":"no")+", width="+width.toString()+",height="+height.toString()+",left="+left.toString()+",top="+top.toString(), replace);
	checkPopupBlock(lastPopupWindow);
	return lastPopupWindow;
}

function popupFullScreen(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, replace) {
	lastPopupWindow = popup(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, window.screen.availWidth-10, window.screen.availHeight-40, 0, 0, replace);
	return lastPopupWindow;
}

function popupSingle(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, width, height, top, left, replace) {
	closeLastPopupWindow();
	return popup(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, width, height, top, left, replace);
}

function popupFullScreenSingle(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, replace) {
	closeLastPopupWindow();
	return popupFullScreen(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, replace);
}


function popupScalar(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, width, height, top, left, replace) {
	return popup(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, width, height, top, left, replace);
}

function popupFullScreenScalar(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, replace) {
	return popupFullScreen(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, replace);
}

function popupSingleScalar(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, width, height, top, left, replace) {
	return popupSingle(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, width, height, top, left, replace);
}

function popupFullScreenSingleScalar(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, replace) {
	return popupFullScreenSingle(url, windowName, status, toolbar, scrollbars, menubar, location, resizable, replace);
}



function closeLastPopupWindow() {
	if(lastPopupWindow != null) lastPopupWindow.close();
}

function refreshOpener() {
	var win = window.opener;
	if(win != null) win.location.reload(true);
}

function refreshOpenerAndClose() {
	refreshOpener();
	window.close();
}


function checkPopupBlock(newWindow) {
	if(newWindow == null) alert("Popups are blocked. Allow popups for this application to run properly.\n\nPopups worden tegengehouden. Sta popups toe om deze applicatie normaal te laten werken.\n\nPopups sont bloques. Autorisez popups pour que cette application marcherait normalment.");
	return newWindow;
}


var openNextWindowAfterLastPopupWindowIntervalID = null;

function openNextWindowAfterLastPopupWindow(nextWindowScript) {
   //debugger;

   if(lastPopupWindow.closed) {
	   window.eval(nextWindowScript);
	   return;
   }
   
   openNextWindowAfterLastPopupWindowIntervalID = window.setInterval("openNextWindow(\"" + nextWindowScript + "\");", 5000);
}

function openNextWindow(nextWindowScript) {
   //debugger;
   
   if(!lastPopupWindow.closed) return;
   window.clearInterval(openNextWindowAfterLastPopupWindowIntervalID);
   window.eval(nextWindowScript);
}

//--------------------------------------------------------------------------------------------------------------------------------------------

function openInformation(pageTitleKey, infoTextKey) {
	popupSingle("../Portal/InformationPopup.aspx?PageTitleKey=" + pageTitleKey + "&TextKey=" + infoTextKey, "InformationPopup", false, false, true, false, false, true, 800, 600, 50, 50, true);
}

function openStandardLabels() {
	popupSingle("../Portal/StandardLabelsPopup.aspx", "StandardLabelsPopup", false, false, true, false, false, true, 800, 600, 50, 50, true);
}

function openStandardBanners(languageCode) {
	popupSingle("../Documents/" + languageCode + "/StandardBanners.pdf", "StandardBannersPopup", false, false, true, false, false, true, 800, 600, 50, 50, true);
}

function openDeliveryNote(deliveryId, deliveryShipperId, deliveryNoteLanguage, allowFromCache) {
	return popupSingle("../ProductionMonitor/DeliveryNote.aspx?DeliveryId="+deliveryId+"&DeliveryNoteLanguage="+deliveryNoteLanguage+"&DeliveryShipperId="+deliveryShipperId+"&AllowFromCache="+allowFromCache, "DeliveryNote", true, true, true, true, true, true, 800, 600, 50, 50, true);
}

function openLabelExpress3DeliveryNote(deliveryId, deliveryShipperId, deliveryNoteLanguage, allowFromCache) {
	popupSingle("../LabelExpress3/DeliveryNote.aspx?DeliveryId="+deliveryId+"&DeliveryNoteLanguage="+deliveryNoteLanguage+"&DeliveryShipperId="+deliveryShipperId+"&AllowFromCache="+allowFromCache, "DeliveryNote", true, true, true, true, true, true, 800, 600, 50, 50, true);
}

function openDeliveryReceipt(deliveryId, deliveryShipperId, deliveryReceiptLanguage, allowFromCache) {
	return popup("../ProductionMonitor/DeliveryReceipt.aspx?DeliveryId="+deliveryId+"&DeliveryReceiptLanguage="+deliveryReceiptLanguage+"&DeliveryShipperId="+deliveryShipperId+"&AllowFromCache="+allowFromCache, "DeliveryReceipt", true, true, true, true, false, true, 800, 600, 75, 75, true);
}

function openPrintHeavyPurchaseBinLines() {
	popupSingle("../LabelExpress3/PrintHeavyPurchaseBinLines.aspx", "PrintHeavyPurchaseBinLines", true, true, true, true, false, true, 800, 600, 50, 50, true);
}

function openPrintOrderLines(orderId) {
	popupSingle("../ProductionMonitor/PrintOrderLines.aspx?OrderId=" + orderId, "PrintOrderLines", true, true, true, true, false, true, 800, 600, 50, 50, true);
}

function openPrintInvoiceCheck() {
	popupSingle("../ProductionMonitor/PrintInvoiceCheck.aspx", "PrintInvoiceCheck", true, true, true, true, false, true, 800, 600, 50, 50, true);
}

function openPrintActiveOrderTracking() {
	popupSingle("../ProductionMonitor/PrintOrders.aspx", "PrintActiveOrderTracking", true, true, true, true, false, true, 800, 600, 50, 50, true);
}

function openPDF(pdfUrl) {
	popupSingle(pdfUrl, "PDF", false, false, false, false, false, true, 800, 600, 50, 50, true);
}

function openPDFPreview(title, pdfPreviewId) {
	popupSingle("../LabelExpress3/GeneratePDF.aspx?Title=" + title + "&PDFPreviewId=" + pdfPreviewId, "PDFPreview", false, false, false, false, false, true, 800, 600, 50, 50, true);
}

function openTemplatePreviewPDF(title, templateId) {
	popupSingle("../LabelExpress3/GeneratePDF.aspx?Title=" + title + "&TemplateId=" + templateId, "TemplatePreviewPDF", false, false, false, false, false, true, 800, 600, 50, 50, true);
}

function openOrderLinePDF(title, orderLineId) {
	return popupSingle("../ProductionMonitor/GeneratePDF.aspx?Title=" + title + "&orderLineId=" + orderLineId, "OrderLinePDF", false, false, false, false, false, true, 800, 600, 50, 50, true);
}

function openAddToBasket(/*optional*/ combinationIdString) 
{
	popupSingle("AddToBasket.aspx" + (combinationIdString ? "?CombinationIdString="+combinationIdString : ""), "AddToBasket", true, false, true, false, false, true, 800, 600, 50, 50, true);
}

function openAddPDFPreview(/*optional*/ combinationIdString) 
{
	popupSingle("AddPDFPReview.aspx" + (combinationIdString ? "?CombinationIdString="+combinationIdString : ""), "AddPDFPreview", true, false, true, false, false, true, 800, 600, 50, 50, true);
}

function openHeavyTaskLoader(popupHeavyTaskLoaderUrl) 
{
	popupSingle(popupHeavyTaskLoaderUrl, "PopupHeavyTaskLoader", true, false, true, false, false, true, 800, 600, 50, 50, true);
}

function openTranslateFreeText() {
	popupSingle("FreeTextEdit.aspx", "TranslateFreeText", true, false, true, false, false, true, 800, 600, 50, 50, true);
}

function openTranslateSubsetPlantCommonName() {
	popupSingle("CommonNameEdit.aspx", "TranslateSubsetPlantCommonName", true, false, true, false, false, true, 800, 360, 50, 50, true);
}

function openGenerateFilePage(pageTitle, path, contentType) {
	popupSingle("GenerateFilePage.aspx?PageTitle=" + pageTitle + "&Path=" + path + "&ContentType=" + contentType, "GenerateFilePage", false, false, false, false, false, true, 800, 600, 50, 50, true);
}

function openViewPicture(pictureId) {
	popupSingle("ViewPicture.aspx?PictureId=" + pictureId, "ViewPicture", true, true, true, true, false, false, 550, 600, 50, 50, true);
}


