﻿/*  Config options: (comma delimited)
resizable=yes or no
scrollbars=yes or no
toolbar=yes or no
location=yes or no
directories=yes or no
status=yes or no
menubar=yes or no
copyhistory=yes or no
*/

//Site-Specific Code:
/* Examples:
function NewWindow_AddZone()											{	NewWindow('zonemaintenance_zoneaddedit.aspx',																														350,    200);	}
function NewWindow_EditZone(zoneId)										{	NewWindow('zonemaintenance_zoneaddedit.aspx?zoneId=' + zoneId,																										350,    200);	}
*/

function NewWindow_AddBranchUnavailabilityException(BranchId, date)      { NewWindow('../Appointments/BranchException_AddEdit.aspx?BranchId=' + BranchId + '&Date=' + date,	480,    550);	}
function NewWindow_EditBranchUnavailabilityException(ExceptionID)   { NewWindow('../Appointments/BranchException_AddEdit.aspx?ExceptionID=' + ExceptionID,	485,    550);	}
function NewWindow_AddEditAppointment()                             { NewWindow('Appointnment_AddEdit.aspx?',	570,    400);	}
function NewWindow_CancelAppointment()                              { NewWindow('CancelAppointmentPopup.aspx',	420,    250);	}
function NewWindow_AddUserUnavailabilityException(BranchId, UserName, date) { NewWindow('../Appointments/UserException_AddEdit.aspx?BranchId=' + BranchId + '&UserName=' + UserName + '&Date=' + date, 450, 550); }
function NewWindow_EditUserUnavailabilityException(ExceptionID)     { NewWindow('../Appointments/UserException_AddEdit.aspx?ExceptionID=' + ExceptionID,	450,    550);	}
function NewWindow_EditUserUnavailabilityException(ExceptionID, BranchId)     { NewWindow('../Appointments/UserException_AddEdit.aspx?ExceptionID=' + ExceptionID,	450,    550);	}
function NewWindow_EditLookup(LookupId, CategoryCode)               { NewWindow('Lookup_AddEdit.aspx?LookupId=' + LookupId + '&CategoryCode=' + CategoryCode,	500,    520);	}
function NewWindow_AddLookup(CategoryCode)                          { NewWindow('Lookup_AddEdit.aspx?CategoryCode=' + CategoryCode,	500,    520);	}
function NewWindow_EditUserDetails(UserName)                        { NewWindow('UserDetails.aspx?UserName=' + UserName,	844,    568);	}
function NewWindow_AddNewUser() { NewWindow('UserDetails.aspx', 844, 568); }
function NewWindow_EditUser(UserName) { NewWindow('../Administration/UserDetails.aspx?UserName=' + UserName, 844, 568); }
function NewWindow_AppointmentHistory(appointmentID)                { NewWindow('../Appointments/AppointmentHistory.aspx?AppointmentTUID=' + appointmentID,	900,    550, 'scrollbars=yes');	}
function NewWindow_SendText()                                       { NewWindow('../SendText.aspx',	580,    450);	}
function NewWindow_SendTextFromCustomPage()                         { NewWindow('../../../../Pages/SendText.aspx',	580,    450);	}

function NewWindow_Help(helpPage)                                   { NewWindow(helpPage,	1000,    900, 'resizable=yes, scrollbars=yes, toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, copyhistory=yes');	}

function NewWindow_HtmlEditor()                                     { NewWindow('../System/HtmlEditorPopup.aspx',	300,    570);}

function NewWindow_CustomerSearch(customerCode)                     { NewWindow('CustomerSearchPopup.aspx?CustomerCode=' + customerCode,	580,    450);	}
function NewWindow_CustomerSearchFromPopup(customerCode)            { NewWindow('CustomerSearchPopup.aspx?CustomerCode=' + customerCode,	580,    450, '', true);	}
function NewWindow_BillingCustomerSearch(customerCode)              { NewWindow('BillingCustomerSearchPopup.aspx?CustomerCode=' + customerCode,	580,    450);	}
function NewWindow_BillingCustomerSearchFromPopup(customerCode)     { NewWindow('BillingCustomerSearchPopup.aspx?CustomerCode=' + customerCode,	580,    450, '', true);	}


function NewWindow_LostQuote()                                      { NewWindow('LostQuotePopup.aspx',	420,    200);	}
function NewWindow_LostQuoteSingle(quoteTuid)                       { NewWindow('LostQuotePopup.aspx?QuoteTUID=' + quoteTuid,	420,    200);	}

function NewWindow_QuoteHistory(quoteID)                            { NewWindow('QuoteHistory.aspx?QuoteTUID=' + quoteID,	900,    550, 'scrollbars=yes');	}
function NewWindow_QuoteLineDetails(quoteLineItemID)                { NewWindow('QuoteLineDetails.aspx?QuoteLineItemTUID=' + quoteLineItemID,	350,    450);	}


function NewWindow_QuotePrintOptions(appointmentNo)                { NewWindow('QuotePrintOptions.aspx?AppointmentTUID=' + appointmentNo,	700,    700);	}

function NewWindow_NewAppointmentPopupFromDiary(branchID, userName, apptDateTime) { NewWindow('NewAppointmentPopup.aspx?BranchID=' + branchID + '&UserId=' + userName + '&AppointmentDateTime=' + apptDateTime, 970, 670, 'resizable=yes, scrollbars=yes'); }
function NewWindow_NewAppointmentPopup(branchID, groupID, gridStartTime, row, column) { NewWindow('NewAppointmentPopup.aspx?BranchID=' + branchID +  '&GroupID=' + groupID + '&GridStartDateTime=' + gridStartTime + '&Row='+ row + '&Column='+ column,	970,    670, 'resizable=yes, scrollbars=yes');	}

function NewWindow_NewPhotoPopup(photoUrl)                         { NewWindow(photoUrl,	700,    520, 'resizable=yes, scrollbars=yes');	}


function NewWindow_EditCampaignStatuse(CampaignStatuseID)          { NewWindow('CampaignStatuses_AddEdit.aspx?CampaignStatusID=' + CampaignStatuseID,	400,    420);	}
function NewWindow_AddCampaignStatuse()                            { NewWindow('CampaignStatuses_AddEdit.aspx',	400,    420);	}

function NewWindow_AddProductMaster(branchID)                      { NewWindow('ProductMaster_AddEdit.aspx?BranchID=' + branchID,	520,    570);	}
function NewWindow_EditProductMaster(branchID, productID)          { NewWindow('ProductMaster_AddEdit.aspx?BranchID=' + branchID + '&ProductID=' + productID,	520,    570);	}

function NewWindow_SurveyItemEdit(appointmentID, RoomPosition, ItemPosition, LastUpdateTime) { NewWindow('../../Pages/Surveys/ItemDetailsPopup.aspx?AppointmentTuid=' + appointmentID + '&RoomPosition=' + RoomPosition + '&ItemPosition=' + ItemPosition + '&LastUpdateTime=' + LastUpdateTime , 600, 625);	}

function NewWindow_FreeTimeSearch(date, branchID, groupID) { NewWindow('FreetimeSearch.aspx?Date=' + date + '&BranchID=' + branchID + '&GroupID=' + groupID, 800, 570); }
function NewWindow_DailyTeamPlanner(date) { NewWindow('DailyTeamPlanner.aspx?Date=' + date, 800, 570, 'scrollbars=yes'); }
function NewWindow_JobScheduling(jobTuid) { NewWindow('JobScheduling.aspx?JobTuid=' + jobTuid, 924, 668); }
function NewWindow_JobMaterials(jobTuid) { NewWindow('JobMaterials_AddEdit.aspx?JobTuid=' + jobTuid, 1024, 600); }
function NewWindow_JobHistory(jobTuid) { NewWindow('../Administration/History.aspx?Table=Job&Key=' + jobTuid, 900, 550, 'scrollbars=yes'); }
function NewWindow_JobQuickSchedule(date, assignTo) { NewWindow('QuickSchedule.aspx?Date=' + date + '&AssignTo=' + assignTo, 400, 400); }

function NewWindow_AuditQuestionDesign(questionIndex) { NewWindow('AuditQuestionDesign.aspx?QuestionIndex=' + questionIndex, 500, 520); }
function NewWindow_AuditQuestionAnswer(appointmentTuid, questionIndex) { NewWindow('AuditQuestionAnswer.aspx?AppointmentTuid=' + appointmentTuid + '&QuestionIndex=' + questionIndex, 500, 520); }
function NewWindow_AuditTask(appointmentTuid, taskIndex) { NewWindow('Tasks_Edit.aspx?AppointmentTuid=' + appointmentTuid + '&TaskIndex=' + taskIndex, 500, 470); }

function NewWindow_AddEditProgram(programCode) { NewWindow('Program_AddEdit.aspx?ProgramCode=' + programCode, 500, 470); }
function NewWindow_AddEditProduct(productId) { NewWindow('Product_AddEdit.aspx?ProductId=' + productId, 580, 500); }
function NewWindow_AddEditPrice(productId, programCode) { NewWindow('Price_AddEdit.aspx?ProductId=' + productId + "&ProgramCode=" + programCode, 500, 470); }
function NewWindow_AddEditProgramSubsidy(programSubsidyId) { NewWindow('Subsidy_AddEdit.aspx?ProgramSubsidyId=' + programSubsidyId, 500, 520); }

function NewWindow_AppointmentQuickEdit(appointmentTuid) { NewWindow('Appointment_Quick_Edit.aspx?AppointmentTuid=' + appointmentTuid, 400, 500); }

function NewWindow_AddProduct() { NewWindow('JobProduct_Add.aspx', 700, 450); }
function NewWindow_QuoteDetails(quoteTuid) { NewWindow('../Quotes/QuoteDetails.aspx?QuoteTuid=' + quoteTuid, 824, 500); }

function NewWindow_AddEditRecurringJob(recurringJobId) { NewWindow('../Appointments/RecurringJobs_AddEdit.aspx?RecurringJobId=' + recurringJobId, 500, 500); }

function NewWindow_InstalledQuantities(quoteTuid) { NewWindow('InstalledQuantities.aspx?QuoteTuid=' + quoteTuid, 824, 500); }

//General Code
var newWindowHandle = null;
function NewWindow(page,width,height,config, isThirdLevelPopup)
{
	//Provide default dimensions
	if (width  == null)	{ width  = 440;	}
	if (height == null)	{ height = 90;	}

	//Center the window
	var left = Math.floor((window.screen.availWidth  - width )/2);
	var top  = Math.floor((window.screen.availHeight - height)/2);

	//Build config string
	var conf = "width="+width+",height="+height+",top="+top+",left="+left+",resizable=yes,";
	if (config != null)	
	{	conf += config;	}
	
	//Sneak in an extra querystring parameter, so the server can differentiate (eg. session lost)
	var extraParam = 'newWindow=true';
	if (-1 != page.indexOf('?'))
	{  page += '&' + extraParam;  }
	else
	{  page += '?' + extraParam;  }
	
	//Add new parameter to prevent caching
	page += '&time='+ new Date().getTime();
	
	//Close the window (if open)
	if (null != newWindowHandle)	{	newWindowHandle.close();	}
	
	if(isThirdLevelPopup == null || isThirdLevelPopup == false)
	  newWindowHandle = window.open(page, 'newWindow', conf);
	else
	  newWindowHandle = window.open(page, 'newWindow2', conf);

    if (null != newWindowHandle)
	{

	    // Resize the window, required as if there is an existing window with the same name('newWindow'),
	    // then the window.open method will just use this existing window without applying the new size
	    newWindowHandle.resizeTo(width, height + 30);  
		newWindowHandle.focus();	
		return;
	}
	alert('ERROR: Your browser does not allow popups!\n\nYou need to either:\n\t1. Hold down the CTRL key while clicking, OR\n\t2. Click the red/yellow button on your toolbar to enable popups for this site');
}


