var wSave = null;
var wHelp = null;
var wOpen = null;
var wDataElements = null;
var wSelectContact = null;
var wBeforeYouBegin = null;
var wRptPreview = null;
var wizPreview= null;
var wPrivacy = null;
var wPrint = null;
var wReportPreview = null;
var wRange = null;

/*	This function is to get NumRange	*/
function GetRange(fromtext,fromvalue,dtype){
	if (wRange && !wRange.closed) wRange.close()
	wRange = openWindow("Range1.aspx?Desc="+escape(fromtext)+"&val="+escape(fromvalue)+"&dtype="+escape(dtype), "RangeWindow", 260, 200, "noresize")	
}

function privacy_Click()
{
	wPrivacy = openWindow("http://www.thirdwaveresearch.com/aha_wizard/PrivacyStatement.aspx","PrivacyStatement",700,600,"dependent,scrollbars=yes,resizable=no");
}

function toolBar_Click(helpText)
{
	wHelp = openWindow("FieldHelp.aspx?HelpCode=" + helpText,"Help",300,250,"dependent,scrollbars=no,resizable=yes");
}
function help_Click(helpText,rptType)
{
	wHelp = openWindow("FieldHelp.aspx?RptType=" + rptType + "&HelpCode=" + helpText,"Help",400,300,"dependent,scrollbars=yes,resizable=yes");
}

function reportPreview_Click(myRptType)
{
	wReportPreview = openWindow("ReportPreview.aspx?RptType=" + myRptType,"ReportPreview",700,450,"dependent,scrollbars=yes,resizable=yes");
}


function pdfPreview_Click(url)
{
	wReportPreview = openWindow(url,"Preview",700,450,"dependent,scrollbars=yes,resizable=yes");
}

function toolBarSave_Click(myRptType)
{
	wSave = openWindow("SaveDetails.aspx?RptType=" + myRptType,"Save",300,250,"dependent,scrollbars=no,resizable=no");
}

function openSaveForPurchase(myRptType,srcPage)
{
	wSave = openWindow("SaveDetails.aspx?RptType=" + myRptType + "&srcPage=" + srcPage,"Save",300,250,"dependent,scrollbars=no,resizable=no");
}

function toolBarOpen_Click(myRptType)
{
	wOpen = openWindow("OpenQuery.aspx?RptType=" + myRptType,"Open",400,300,"dependent,scrollbars=no,resizable=no");
}

function dataElementSearch_Click(searchText)
{
	wDataElements = openWindow("DataElementSearch.aspx?Search=" + searchText,"Search",400,300,"dependent,scrollbars=yes,resizable=no");
}

function selectContactsSearch_Click(searchText)
{
	wSelectContact = openWindow("SelectContactSearch.aspx?Search=" + searchText,"SelectContactSearch",400,300,"dependent,scrollbars=yes,resizable=no");
}
function PopWindow(url)
{
	
	wBeforeYouBegin = openWindow(url,"BeforeYouBegin",600,600,"dependent,scrollbars=no,resizable=yes");
	//var w = window.open(url,"BeforeYouBegin");
}

/*	Keep popup window always on top	*/
function bodyFocus() {
  //the delay is to allow the window time to close, if that is the case   
  	setTimeout("if (wOpen && !wOpen.closed) wOpen.focus()", 100)
  	setTimeout("if (wRange && !wRange.closed) wRange.focus()", 100)
  	setTimeout("if (wPrivacy && !wPrivacy.closed) wPrivacy.focus()", 100)
  	setTimeout("if (wSave && !wSave.closed) wSave.focus()", 100)
	setTimeout("if (wDataElements && !wDataElements.closed) wDataElements.focus()", 100)
	setTimeout("if (wSelectContact && !wSelectContact.closed) wSelectContact.focus()", 100)
	setTimeout("if (wHelp && !wHelp.closed) wHelp.focus()", 100)
	setTimeout("if (wRptPreview && !wRptPreview.closed) wRptPreview.focus()", 100)
	setTimeout("if (wBeforeYouBegin && !wBeforeYouBegin.closed) wBeforeYouBegin.focus()", 100)
	setTimeout("if (wizPreview && !wizPreview.closed) wizPreview.focus()", 100)
	setTimeout("if (wPrint && !wPrint.closed) wPrint.focus()", 100)
	setTimeout("if (wReportPreview && !wReportPreview.closed) wReportPreview.focus();", 100)
}
/*	Body Unload events	*/
function bodyUnload() {
	if (wOpen && !wOpen.closed) wOpen.close();
	if (wRange && !wRange.closed) wRange.close();
	if (wPrivacy && !wPrivacy.closed) wPrivacy.close();
	if (wSave && !wSave.closed) wSave.close();
	if (wDataElements && !wDataElements.closed) wDataElements.close();
	if (wSelectContact && !wSelectContact.closed) wSelectContact.close();
	if (wHelp && !wHelp.closed) wHelp.close();
	if (wRptPreview && !wRptPreview.closed) wRptPreview.close();
	if (wBeforeYouBegin && !wBeforeYouBegin.closed) wBeforeYouBegin.close();
	if (wizPreview && !wizPreview.closed) wizPreview.close();
	if (wPrint && !wPrint.closed) wPrint.close();
	if (wReportPreview && !wReportPreview.closed) wReportPreview.close();
}

function openBeforeYouBegin(){
	var rptType = "<%=ourRptType%>";
	var returnUrl = "<%=Request.RawUrl%>";
	PopWindow("BeforeYouBegin.aspx?RptType=" + rptType + "&ReturnUrl=" + returnUrl);
}
		
function openWindow(url, wName, wWidth, wHeight, otherFeatures) 
{
	//opens a window of size (wWidth,wHeight) at the center of the screen
	var xVar, yVar, features
	if (navigator.appName == "Netscape") {
		xVar = "screenX"
		yVar = "screenY"
	}else {
		xVar = "left"
		yVar = "top"
	}
	features = xVar + "=" + (screen.width-wWidth)/2 +
		"," + yVar + "=" + (screen.height-wHeight)/2 +
		",width=" + wWidth + ",height=" + wHeight
	if (otherFeatures != "") features += "," + otherFeatures
	var w = window.open(url,wName,features)
	if(!w){
		setTimeout("alert('popup is blocked in your server')", 100)
		//alert("popup is blocked in your server");
	}
	return w
}

function ToolBarPreviewWithPage_Click(myRptType,srcPage){
//	alert(srcPage);
	wizPreview = openWindow("WizardPreview.aspx?RptType=" + myRptType + "&Src=" + srcPage,"Preview",600,500,"dependent,scrollbars=yes,resizable=no");
}

function ToolBarPreview_Click(myRptType)
{
	wizPreview = openWindow("WizardPreview.aspx?RptType=" + myRptType,"Preview",600,500,"dependent,scrollbars=yes,resizable=no");
}

function btnPrint_Click(myRptType){
	//alert("WizardPreview.aspx?RptType=" + myRptType + "&mode=print")
	var wPrint = openWindow("WizardPreview.aspx?RptType=" + myRptType + "&mode=print","PrintWindow",600,500,"scrollbars=yes,resizable=no");
}
function btnCancel_Click(){
	top.close()
}

function showSample(imageFileName){
    wRptPreview = openWindow("","MessageWindow",600,600,"dependent,scrollbars=yes")
   with (wRptPreview.document){
      writeln("<html><head><title>Report Preview</title><LINK href='Styles.css' type='text/css' rel='stylesheet'>" + "<" + "script>self.focus()")
	  writeln("var opener1 = opener")
	  writeln("setInterval('if (!opener1 || opener1.closed) self.close()',500)")
	  writeln("<" + "/script>")
	  writeln("</head><body bgcolor='#FFFFFF'>")
	  writeln("<table><tr><td>")
	  writeln("<img src='"+imageFileName+"'>")
	  writeln("</td></tr>")
	  writeln("<tr><td align='center'>")
	  writeln("<input type='button' id='btnClose' name='btnClose' class='MainButton' value='Close' onclick='top.close()'")
	  writeln("</td></tr></table>")
	  writeln("</body></html>");
	  close();
   }
}
 
