var AjaxObj = false; // make global variables
var objHTML = false
//

function PageTracker(PathOffset, pFilename) {
	sReferrer = GetReferringURL();
	sURL  = PathOffset + 'Admin/UpdatePageViews.php';
	sURL += '?page=' + pFilename;
	sURL += '&referrer=' + sReferrer;
//alert(sURL );
	AjaxObj = GetAjaxObj();
	if(AjaxObj)	{
		AjaxObj.onreadystatechange = function()
			{
				if (AjaxObj.readyState == 4 && AjaxObj.status == 200) {
//alert(AjaxObj.responseText);
				}
			}
		AjaxObj.open("GET", sURL, true);
		AjaxObj.send(null);
	}

}
//End PageTracker


function GetReferringURL(){
	sStr = document.referrer.replace('http://','');
	if (sStr.indexOf('/')) {
		nOffset = sStr.indexOf('/');
		sStr = sStr.substring(0,nOffset);
	}
	return sStr;
}
// End GetReferringURL

function GetAjaxObj (){
	var AjaxObj = false;
	if (window.XMLHttpRequest)
	{
		AjaxObj = new XMLHttpRequest();
	}
		else if (window.ActiveXObject)
		{
		AjaxObj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	return AjaxObj;
}
// End GetAjaxObj

function DownloadInstructions(sPlanName) {

	sMsg  = '<p style="font-style: italic; color:red; font-weight:bold">';
	sMsg += 'Please Note: <br /><p>';
	sMsg += '<p style="font-style: italic;  color:red; margin: -15 0 0 0">';
	sMsg += 'These plans are provided as downloadable PDF files. ';
	sMsg += 'After your order has been completed by Paypal, you will receive instructions ';
	sMsg += 'for downloading your ' + sPlanName + ' plans';
	sMsg += '</p>';

document.getElementById('download_instructions').innerHTML = sMsg ;
}
// End DownloadInstructions

function LargeImage(imgFile) {
	document.getElementById('Div-LargeImage').style.display = 'inline';
	if (imgFile=='Hide') {
		document.getElementById('Div-LargeImage').style.display = 'none';
		return;
	}
}

// End LargeImage

function DownloadButton(PathOffset, PlanName, PdfFile){
// This function displays a download button for the PDF file
	sDownloadURL = PathOffset + 'FreeDownloads/' + PdfFile;
	sEvent = 'onclick=\'DownLoadPDF("'+PathOffset + '","' + sDownloadURL + '", "' + PdfFile + '")\' ';
	sStr  = '<div class="download">'
	sStr += '<p class="color_bold_center_italic">';
	sStr += 'Click the Download button for your free '+ PlanName +' plans.</p>';
	sStr += '<input type="button" name="download" value="Download"';
	sStr += sEvent  + '><br /><br />';
	sStr += 'When the plans open in your PDF viewer, be sure to save the file to your hard drive. ';
	sStr += '</div>	';
	document.write(sStr);
//	alert(sDownloadURL);
}
//End DownloadButton

function DownloadPreview(PathOffset, PlanName, PdfFile){
// This function displays a download button for the PDF file
	sDownloadURL = PathOffset + 'FreeDownloads/' + PdfFile;
	sEvent = 'onclick=\'DownLoadPDF("'+PathOffset + '","' + sDownloadURL + '", "' + PdfFile + '")\' ';
	sStr  = '<div class="download">'
	sStr += '<p class="color_bold_center_italic">';
	sStr += 'Click the Download button for your free Preview.</p>';
	sStr += '<input type="button" name="download" value="Download"';
	sStr += sEvent  + '><br /><br />';
	sStr += 'When the plans open in your PDF viewer, be sure to save the file to your hard drive. ';
	sStr += '</div>	';
	document.write(sStr);
//	alert(sDownloadURL);
}
//End DownloadButton


function DownLoadPDF(PathOffset, DownloadURL, PdfFile) {
	// This function updates the PdfViews table, then implements downloading of the pdf file.
	sTrackingURL  = PathOffset + 'Admin/UpdatePageViews.php?PdfFile=' + PdfFile;
//	alert(sTrackingURL);
	// The following code sends the above URL to the php script which updates the PdfViews table.
	AjaxObj = GetAjaxObj();
	if(AjaxObj)	{
		AjaxObj.onreadystatechange = function()
			{
				if (AjaxObj.readyState == 4 && AjaxObj.status == 200) {
//		alert(AjaxObj.responseText);
				}
			}
		AjaxObj.open("GET", sTrackingURL, true);
		AjaxObj.send(null);
	}
	// The following line implements the download using the URL passed to the function the
	window.open(DownloadURL,"Download");
}
//End DownLoadPDF
