function FocusWindowAndCheckBlocker( windowObject )
{
	if (windowObject == null)
	{ 
		alert('Your popup blocker has blocked one of our popup windows. In order to be able to use the full functionality of this site, please configure your popup blocker to allow popups for this site.');
	}
	else 
	{
		windowObject.focus();
	}

//  if( windowObject != null )
//  {
//    windowObject.focus();
//  }
}

function CloseDialogWindow( bRefreshOpener )
{
  if( bRefreshOpener == true )
  {
    RefreshOpener();
  }
  window.close();
}

var dlgWindow;
var dlgEscrowWindow; 
var dlgCreditCardPayment; 
var dlgCcVerificationNumberHelpWindow;
var dlgServiceTask;

function SearchPerson(inputContact, personTypeID, companyID)
{
	document.Form1.hiddenTargetObject.value = inputContact;
	ShowSearchPersonWindow("../DialogPages/SearchPersonsDlg.aspx?pti=" + personTypeID + "&sid=" + companyID);
}

function ShowSendReportToActorWindow(docLoc)
{
	CloseDlgWindow(dlgWindow);
	var w = 340;
	var h = 200;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable=no';
	
	dlgWindow = window.open(docLoc,"_blank",winprops);
	FocusWindowAndCheckBlocker( dlgWindow )
}

function ShowSearchPersonWindow(docLoc)
{
	CloseDlgWindow(dlgWindow);
	var w = 780;
	var h = 400;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	
	dlgWindow = window.open(docLoc,"_blank",winprops);
	FocusWindowAndCheckBlocker( dlgWindow )
}

function ShowUploadCCKeyWindow(docLoc)
{
	CloseDlgWindow(dlgWindow);
	var w = 820;
	var h = 450;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	dlgWindow = window.open(docLoc,"Window",winprops);
	FocusWindowAndCheckBlocker( dlgWindow )
}

function ShowServiceAgreement(docLoc)
{
	CloseDlgWindow(dlgWindow);
	
	var w = 800;
	var h = 570;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes,menubar=yes';
	dlgWindow = window.open(docLoc,"Window",winprops);
	FocusWindowAndCheckBlocker( dlgWindow )
}

function showAgreement(appointmentID)
{
//	showAgreement(appointmentID, false);
  ShowServiceAgreement("../DialogPages/ServiceAgreementDlg.aspx?apptId=" + appointmentID);
}

function showAgreement(appointmentID, refreshOpener)
{
  var strRefreshOpener;
  if( refreshOpener == true )
  {
    strRefreshOpener = "&ro=true";
  }
  else
  {
    strRefreshOpener = "&ro=false";
  }
	ShowServiceAgreement("../DialogPages/ServiceAgreementDlg.aspx?apptId=" + appointmentID + strRefreshOpener);
}

function CloseDlgWindow(windowName) 
{
	if (windowName != null)
	{
		windowName.close();
	}
}

function CancelAppointment(appointmentID) {
	CloseDlgWindow(dlgWindow);
	
	var w = 780;
	var h = 600;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	//dlgWindow = window.open("../Company/AppointmentDetail.aspx?cApID=" + appointmentID,"Window",winprops);
	dlgWindow = window.open("../Company/EditAppointment.aspx?id=" + appointmentID + "&cancel=true&ro=true","Window",winprops);
	FocusWindowAndCheckBlocker( dlgWindow )
}

function ShowAppointment(strPath, appointmentID, refreshOpener) {
	CloseDlgWindow(dlgWindow);
	
	var w = 1000;
	var h = 750;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	var strOpen = strPath + "?id=" + appointmentID;
	if( refreshOpener == true )
	{
	  strOpen = strOpen + "&ro=true";
	}
	dlgWindow = window.open(strOpen,"Window",winprops);
	FocusWindowAndCheckBlocker( dlgWindow )
}

function EditAppointment(strPath, appointmentID, refreshOpener, strAname) {
	CloseDlgWindow(dlgWindow);
	
	var w = 1000;
	var h = 700;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	var strOpen = strPath + "?id=" + appointmentID;
	if( refreshOpener == true )
	{
	  strOpen = strOpen + "&ro=true";
	}
	if( strAname != null )
	{
	  strOpen = strOpen + strAname;
	}
	dlgWindow = window.open(strOpen,"Window",winprops);
	FocusWindowAndCheckBlocker( dlgWindow )
}

function CreateAppointment(strPath)
{
	//CloseDlgWindow(dlgWindow);
	
	window.open(strPath);
	
//	var w = 1000;
//	var h = 700;
//	var winl = (screen.width - w) / 2;
//	var wint = (screen.height - h) / 2;
//	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
//	if( refreshOpener == true )
//	{
//	  strOpen = strOpen + "&ro=true";
//	}
//	if( strAname != null )
//	{
//	  strOpen = strOpen + strAname;
//	}
//	dlgWindow = window.open(strPath,"Window",winprops);
//	FocusWindowAndCheckBlocker( dlgWindow )
}

function ShowEscrowForm(appointmentID)
{
	CloseDlgWindow(dlgEscrowWindow);
	
	var w = 780;
	var h = 600;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	dlgEscrowWindow = window.open("../Company/ViewEscrowForm.aspx?ApID=" + appointmentID,"Window",winprops);
	FocusWindowAndCheckBlocker( dlgEscrowWindow )
}

function ShowServiceCreditCardPaymentDlg(appointmentID)
{
	CloseDlgWindow(dlgCreditCardPayment);
	
	var w = 780;
	var h = 650;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	dlgCreditCardPayment = window.open("../DialogPages/ServiceCreditCardPaymentDlg.aspx?ApID=" + appointmentID,"Window",winprops);
	FocusWindowAndCheckBlocker( dlgCreditCardPayment )
}


function ShowCcVerificationNumberHelp()
{
	CloseDlgWindow(dlgCcVerificationNumberHelpWindow);
	
	var w = 400;
	var h = 400;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	dlgCcVerificationNumberHelpWindow = window.open("../CcVerificationHelp.aspx","Window",winprops);
	FocusWindowAndCheckBlocker( dlgCcVerificationNumberHelpWindow )
}


function ShowServiceTaskDlg(appointmentID, taskItemId)
{
	CloseDlgWindow(dlgServiceTask);
	
	var w = 700;
	var h = 600;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	dlgServiceTask = window.open("../Company/ServiceTaskEditDlg.aspx?ApID=" + appointmentID + "&ItemID=" + taskItemId,"Window",winprops);
	FocusWindowAndCheckBlocker( dlgServiceTask )
}