/*
    Filename: download.js
    
    Date: 28 Jan 2007
    
    URL: http://bandwidthcontroller.com/download.js
    
    Description: Javascript functions for downloading and purchasing.
*/

function addPersonalDownloadForm(insertTagName)
{
    // create form
    var downloadForm=document.createElement("form");
    downloadForm.name="downloadPersonalForm";

    // create select
    var downloadSelect=document.createElement("select");
    downloadSelect.name="downloadSelect";
    downloadSelect.id="downloadPersonalSelect";

    // fill select

    // exe
    var option=document.createElement("option");
    option.text="Traffic Shaper XP v1.21 (4.26 MB executable)";
    option.id="executable";
    try
    {
	    // standards compliant
	    downloadSelect.add(option, null);
    }
    catch(exception)
    {
	    // ie
	    downloadSelect.add(option);
    }

    // zip
    var option=document.createElement("option");
    option.text="Traffic Shaper XP v1.21 (2.78 MB compressed)";
    option.id="compressed";
    try
    {
	    // standards compliant
	    downloadSelect.add(option, null);
    }
    catch(exception)
    {
	    // ie
	    downloadSelect.add(option);
    }

    // add select to form
    downloadForm.appendChild(downloadSelect);

    // create download button
    var downloadButton=document.createElement("input");
    downloadButton.type="button";
    downloadButton.name="downloadButton";
    downloadButton.value="Download";

	// register click event
    downloadButton.onclick=downloadPersonalButtonClicked;
	if (downloadButton.captureEvents)
		element.captureEvents(Event.CLICK);

    // add button to form
    downloadForm.appendChild(downloadButton);

    // insert into document
    var insertPoint=document.getElementById(insertTagName);
    insertPoint.appendChild(downloadForm);
}

function addStandardDownloadForm(insertTagName)
{
    // create form
    var downloadForm=document.createElement("form");
    downloadForm.name="downloadStandardForm";

    // create select
    var downloadSelect=document.createElement("select");
    downloadSelect.name="downloadSelect";
    downloadSelect.id="downloadStandardSelect";

    // fill select

    // exe
    var option=document.createElement("option");
    option.text="Standard Edition v1.21 (5.17 MB executable)";
    option.id="executable";
    try
    {
	    // standards compliant
	    downloadSelect.add(option, null);
    }
    catch(exception)
    {
	    // ie
	    downloadSelect.add(option);
    }

    // zip
    var option=document.createElement("option");
    option.text="Standard Edition v1.21 (3.32 MB compressed)";
    option.id="compressed";
    try
    {
	    // standards compliant
	    downloadSelect.add(option, null);
    }
    catch(exception)
    {
	    // ie
	    downloadSelect.add(option);
    }

    // add select to form
    downloadForm.appendChild(downloadSelect);

    // create download button
    var downloadButton=document.createElement("input");
    downloadButton.type="button";
    downloadButton.name="downloadButton";
    downloadButton.value="Download";

	// register click event
    downloadButton.onclick=downloadStandardButtonClicked;
	if (downloadButton.captureEvents)
		element.captureEvents(Event.CLICK);

    // add button to form
    downloadForm.appendChild(downloadButton);

    // insert into document
    var insertPoint=document.getElementById(insertTagName);
    insertPoint.appendChild(downloadForm);
}

function addEnterpriseDownloadForm(insertTagName)
{
    // create form
    var downloadForm=document.createElement("form");
    downloadForm.name="downloadEnterpriseForm";

    // create select
    var downloadSelect=document.createElement("select");
    downloadSelect.name="downloadSelect";
    downloadSelect.id="downloadEnterpriseSelect";

    // fill select

    // exe
    var option=document.createElement("option");
    option.text="Enterprise Edition v1.21 (6.32 MB executable)";
    option.id="executable";
    try
    {
	    // standards compliant
	    downloadSelect.add(option, null);
    }
    catch(exception)
    {
	    // ie
	    downloadSelect.add(option);
    }

    // zip
    var option=document.createElement("option");
    option.text="Enterprise Edition v1.21 (3.78 MB compressed)";
    option.id="compressed";
    try
    {
	    // standards compliant
	    downloadSelect.add(option, null);
    }
    catch(exception)
    {
	    // ie
	    downloadSelect.add(option);
    }

    // add select to form
    downloadForm.appendChild(downloadSelect);

    // create download button
    var downloadButton=document.createElement("input");
    downloadButton.type="button";
    downloadButton.name="downloadButton";
    downloadButton.value="Download";

	// register click event
    downloadButton.onclick=downloadEnterpriseButtonClicked;

	if (downloadButton.captureEvents)
		element.captureEvents(Event.CLICK);

    // add button to form
    downloadForm.appendChild(downloadButton);

    // insert into document
    var insertPoint=document.getElementById(insertTagName);
    insertPoint.appendChild(downloadForm);
}

// download personal button clicked
function downloadPersonalButtonClicked(eventInformation)
{
    var select=document.getElementById("downloadPersonalSelect");

	switch(select.selectedIndex)
	{
		case 0:
		default:
		{
		    // exe
		    document.location.href="files/TrafficShaperXpSetup.exe";
		    break;
		}

		case 1:
		{
		    // zip
		    document.location.href="files/TrafficShaperXpSetup.zip";
		    break;
		}
	}
}

// download standard button clicked
function downloadStandardButtonClicked(eventInformation)
{
    var select=document.getElementById("downloadStandardSelect");

	switch(select.selectedIndex)
	{
		case 0:
		default:
		{
		    // exe
		    document.location.href="files/BandwidthControllerStandardSetup.exe";
		    break;
		}

		case 1:
		{
		    // zip
		    document.location.href="files/BandwidthControllerStandardSetup.zip";
		    break;
		}
	}
}

// download enterprise button clicked
function downloadEnterpriseButtonClicked(eventInformation)
{
    var select=document.getElementById("downloadEnterpriseSelect");
    
	switch(select.selectedIndex)
	{
		case 0:
		default:
		{
		    // exe
		    document.location.href="files/BandwidthControllerEnterpriseSetup.exe";
		    break;
		}

		case 1:
		{
		    // zip
		    document.location.href="files/BandwidthControllerEnterpriseSetup.zip";
		    break;
		}
	}
}

function addStandardPurchaseButton(insertTagName)
{
    // create button
    var purchaseButton=document.createElement("input");
    purchaseButton.type="button";
    purchaseButton.name="purchaseStandardButton";
    purchaseButton.id="purchaseStandardButton";
    purchaseButton.value="Buy Now >";

	// register click event
    purchaseButton.onclick=purchaseStandardButtonClicked;
	if (purchaseButton.captureEvents)
		element.captureEvents(Event.CLICK);

    // add button to document
    var insertPoint=document.getElementById(insertTagName);
    insertPoint.appendChild(purchaseButton);
}

function addEnterprisePurchaseButton(insertTagName)
{
    // create button
    var purchaseButton=document.createElement("input");
    purchaseButton.type="button";
    purchaseButton.name="purchaseEnterpriseButton";
    purchaseButton.id="purchaseEnterpriseButton";
    purchaseButton.value="Buy Now >";

	// register click event
    purchaseButton.onclick=purchaseEnterpriseButtonClicked;
	if (purchaseButton.captureEvents)
		element.captureEvents(Event.CLICK);

    // add button to document
    var insertPoint=document.getElementById(insertTagName);
    insertPoint.appendChild(purchaseButton);
}

function purchaseStandardButtonClicked(eventInformation)
{
    document.location.href="purchaseStandard.html";
}

function purchaseEnterpriseButtonClicked(eventInformation)
{
    document.location.href="purchaseEnterprise.html";
}