var xmlHttp;



function GetXmlHttpObject() {

	var xmlHttp=null;

	try {

		// Firefox, Opera 8.0+, Safari

		xmlHttp=new XMLHttpRequest();

	}

	catch (e) {

		// Internet Explorer

		try {

			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

		}

		catch (e) {

			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

		}

	}

	return xmlHttp;

}



/*

function loginAndDownload(fileName) {

	//alert("loginAndDownload: "+fileName);

	var url="insight/CheckValidSession.php";

	url=url+"?pdfFile="+fileName;

	xmlHttp=GetXmlHttpObject();

	xmlHttp.onreadystatechange=checkLoggedIn;

	xmlHttp.open("POST",url,true);

	xmlHttp.send(null);

}



function checkLoggedIn() { 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 

		alert("xmlHttp.responseText: "+xmlHttp.responseText);

		if(xmlHttp.responseText == "NOT_LOGGED_IN" || xmlHttp.responseText == "" || xmlHttp.responseText == null ) {

			window.location = "insight/Login.html";

		} else {

			window.location = "insight/DownloadPDF.php?pdfFile="+xmlHttp.responseText;

		}

	} 

}

*/


var loginWindow = null;
function loginAndDownload(fileName) {

	//alert("loginAndDownload: "+fileName);

	var url="insight/CheckValidSession.php";

	// NOTE: You need to have the insightForm and pdfFile on the pages that have the links 

	// of PDF to be downloaded.

	//alert("Opening Window");

	loginWindow = window.open(url+"?pdfFile="+fileName,"Login_Window","width=900,height=500,scrollbars=yes");

	//window.document.insightForm.pdfFile.value=fileName;

	//window.document.insightForm.method = "get";

	//window.document.insightForm.action = url;

	//window.document.insightForm.submit();

}

function closeAndDownload(fileName) {
	//alert("loginWindow: "+loginWindow);
	if (loginWindow == null || loginWindow == "undefined") {
		alert("No Child Window");
		return;
	}

	var url="DownloadPDF.php?pdfFile="+fileName;
	//loginWindow.open(url,"Download_Window","width=900,height=500,scrollbars=yes,toolbar=yes");
	loginWindow.location.target="_blank";
	loginWindow.location.href = url;
	
	//loginWindow.close();
}
