
// --------------------------------------------------------
// Copyright © 1993-2010 12Ghosts Inc. All rights reserved.
// --------------------------------------------------------


// -----------------------------------------------
function InitPage()
{
    window.onerror = myErr;
}

// -----------------------------------------------
function myErr()
{
    return true;
}


// -----------------------------------------------

// globals
var fTotal = 0;

// -----------------------------------------------
function calcTotal()
{
	fTotal = 0;


    // individual
    if( undefined != myForm.quantityFtp )
    { 
        // new
        AddPrice(myForm.quantityFtp.value, 0);
        AddPrice(myForm.quantityTweak.value, 0);
        //AddPrice(myForm.quantityFil.value, 0);


	    AddPrice(myForm.quantity28.value, 0);    // Wash
	    AddPrice(myForm.quantity33.value, 0);    // Shredder
	    AddPrice(myForm.quantity10.value, 0);    // Backup
	    AddPrice(myForm.quantity14.value, 0);    // ShutDown
	    AddPrice(myForm.quantity09.value, 0);    // Timer

	    AddPrice(myForm.quantity20.value, 0);    // ShellX
	    AddPrice(myForm.quantity26.value, 0);    // Zip

	    AddPrice(myForm.quantity13.value, 0);    // Quick
	    AddPrice(myForm.quantity19.value, 0);    // ShowTime
	    AddPrice(myForm.quantity32.value, 0);    // Sync

	    AddPrice(myForm.quantity47.value, 0);    // Popup
	    AddPrice(myForm.quantityTlb.value, 0);   // IETools
	    AddPrice(myForm.quantity43.value, 0);    // Startup

	    AddPrice(myForm.quantity34.value, 0);    // Lookup
	    AddPrice(myForm.quantity18.value, 0);    // Profile
	    AddPrice(myForm.quantity24.value, 0);    // Replace
	    AddPrice(myForm.quantity25.value, 0);    // FileDate

	    AddPrice(myForm.quantity01.value, 0);    // SaveLayout
	    AddPrice(myForm.quantity23.value, 0);    // NotePad
	    AddPrice(myForm.quantity16.value, 0);    // SetColor

	    AddPrice(myForm.quantity12.value, 0);
	    AddPrice(myForm.quantity42.value, 0);
	    //AddPrice(myForm.quantity44.value, 0);  // JustAWindow
	    //AddPrice(myForm.quantityZip2.value, 0);  // Zip2
	    AddPrice(myForm.quantity35.value, 0);
	    AddPrice(myForm.quantity41.value, 0);
	    //AddPrice(myForm.quantity45.value, 0);  // 2ndFolder
	    AddPrice(myForm.quantity46.value, 0);
	    AddPrice(myForm.quantity11.value, 0);
	    AddPrice(myForm.quantity27.value, 0);
	    //AddPrice(myForm.quantity15.value, 0);  // JumpReg
	    AddPrice(myForm.quantity54.value, 0);

    }

    // packages -------------
    if( undefined != myForm.quantitySec )
        AddPrice(myForm.quantitySec.value, 1);
    if( undefined != myForm.quantitySys )
        AddPrice(myForm.quantitySys.value, 1);
    if( undefined != myForm.quantityAuto )
        AddPrice(myForm.quantityAuto.value, 1);
    if( undefined != myForm.quantityFiles )
        AddPrice(myForm.quantityFiles.value, 1);

    if( undefined != myForm.quantitySup )
    	AddPrice(myForm.quantitySup.value, 2);


	// round
	fTotal = Math.round(fTotal * 100) / 100;

	// 19% sales tax in the EU
	if( myForm.country.options[myForm.country.selectedIndex].value == 'Austria' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Belgium' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Denmark' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Finland' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'France' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Monaco' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Germany' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Greece' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Irland' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Italy' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Luxembourg' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Netherlands' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Portugal' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Spain' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'Sweden' ||
		myForm.country.options[myForm.country.selectedIndex].value == 'United Kingdom' ||
		
        myForm.country.options[myForm.country.selectedIndex].value == 'Cyprus' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Czech Republic' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Estonia' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Hungary' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Latvia' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Lithuania' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Malta' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Poland' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Slovakia' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Slovenia' ||
        
        myForm.country.options[myForm.country.selectedIndex].value == 'Romania' ||
        myForm.country.options[myForm.country.selectedIndex].value == 'Bulgaria' )
	{
 		fTotal *= 1.19;
		fTotal = Math.round(fTotal * 100) / 100;
	}


	// display with two decimals
	{
        var fRounded = myRound(fTotal);
    	window.document.getElementById("htmlTotal").innerHTML = "Total (USD): $" + fRounded;
	}
}

// -----------------------------------------------
function myRound(fNum)
{
var iInt = 0;
var iDec = 0;

	iInt = Math.round(fNum);

	// rounded up?
	if( iInt > fNum + 0.00001 )
		iInt--; 

	iDec = Math.round(fNum * 100);
	iDec -= iInt * 100;

	if( iDec >= 100 )
	{
		iInt++;
		iDec = 0;
	}

	if( iDec >= 10 )
	{
		return iInt + '.' + iDec;
	}
	else if( iDec > 0 )
	{
		return iInt + '.0' + iDec;
	}
	else
	{
		return iInt + '.00';
	}
}

// -----------------------------------------------
function AddPrice(fQuantity, fCategory)
{
var fNum1 = new Array(19.95, 34.95, 49.95);
var fNum5 = new Array(17.99, 34.95, 49.95);  // x 5 = 89.95
var fNum25 = new Array(13.18, 34.95, 49.95);  // x 5 = 329.50
var fNumUp = new Array(14.95, 29.95, 39.95);

var fSub = 0;

	fQuantity = Math.round(fQuantity);
	if( fQuantity < 1 )
	{
		return;
	}

	// update?
	if( myForm.ordertype.value == 'Update Version' )
	{
	    fSub = fQuantity * fNumUp[fCategory];
	}
	else
	{
	    if( fQuantity >= 25 )
	    {
		    fSub = fQuantity * fNum25[fCategory];
	    }
	    else if( fQuantity >= 5 )
	    {
		    fSub = fQuantity * fNum5[fCategory];
	    }
	    else
	    {
		    fSub = fQuantity * fNum1[fCategory];
	    }
    }

	fTotal += fSub;
}


// --------------------------------------------------------
// Copyright © 1993-2010 12Ghosts Inc. All rights reserved.
// --------------------------------------------------------


// -----------------------------------------------
function PayPalAdd(szProgName, bUpdate)
{
    if( null != document.paypalform.display )
        document.paypalform.display.removeChild();

    if( 1 == PayPalSetPrice(szProgName, bUpdate) )
    {
	    document.paypalform.submit();
	} 
}

// -----------------------------------------------
function PayPalDisplay()
{
    if( null == document.paypalform.display )
    {
        var NewInput = document.createElement("input");
        NewInput.name = "display";
        NewInput.type = "hidden";
        NewInput.value = "1";
        document.paypalform.appendChild(NewInput);
    } 

	document.paypalform.submit();
}

// -----------------------------------------------
function PayPalSetPrice(szProgName, bUpdate)
{
var fNet = 0;

    if( null != document.getElementById("idName") )
        document.getElementById("idName").innerHTML = szProgName;


    if( 99 == bUpdate )
    {
        // donate
        document.paypalform.cmd.value = "_xclick";
        document.paypalform.item_name.value = "Support Free Software";
        document.paypalform.amount.value = 0;
        return 1;
    }

    if( 88 == bUpdate )
    {
        // site license
        document.paypalform.cmd.value = "_xclick";
        document.paypalform.item_name.value = "Special Offer";
        document.paypalform.amount.value = 0;
        return 1;
    }

    if( 25 == bUpdate )
    {
        fNet = "329.50";  // 17.99
        document.paypalform.item_name.value = szProgName + " 9.0 (25 User)";
    }
    else if( 5 == bUpdate )
    {
        fNet = "89.95";  // 13.18
        document.paypalform.item_name.value = szProgName + " 9.0 (5 User)";
    }
    else if( 1 == bUpdate )
    {
        if( "12G-Complete" == szProgName )
        {
	        fNet = "39.95";
        }
        else if( "12G-Security" == szProgName ||
                  "12G-SysTools" == szProgName ||
                  "12G-Automation" == szProgName ||
                  "12G-FilesMore" == szProgName )
        {
	        fNet = "29.95";
        }
        else
        {
            fNet = "14.95";
        }

        // set the name
        document.paypalform.item_name.value = szProgName + " 9.0 (Update)";
    }
    else 
    {
        if( "12G-Complete" == szProgName )
        {
	        fNet = "49.95";
        }
        else if( "12G-Security" == szProgName ||
                  "12G-SysTools" == szProgName ||
                  "12G-Automation" == szProgName ||
                  "12G-FilesMore" == szProgName )
        {
	        fNet = "34.95";
        }
        else
        {
            fNet = "19.95";
        }

        // set the name
        document.paypalform.item_name.value = szProgName + " 9.0";
    }


    // change price in form
    document.paypalform.amount.value = fNet;
    //document.paypalform.currency_code.value = "USD";
    //document.paypalform.lc.value = "US";
    if( null != document.getElementById("idPrice") )
        document.getElementById("idPrice").innerHTML = "$" + fNet;

    // OK, submit
    return 1;
}


// --------------------------------------------------------
// Copyright © 1993-2010 12Ghosts Inc. All rights reserved.
// --------------------------------------------------------


// globals
var g_fKeep = 0;
var g_LastPackage = "";

// -----------------------------------------------
function ToggelTabs(idPackage, bKeep)
{
    bUseDisplay = 0;
    if( navigator.userAgent.indexOf("Firefox") < 0 )
    {
        bUseDisplay = 1;  // collapse is not supported
    }

    // show sub if in that package
    if( g_fKeep > 0 )
    {
        if( g_LastPackage == idPackage )
        {
            return; 
        }
    }

    // last toggle
    if( bKeep > 0 )
    {
        g_fKeep = 1;
        g_LastPackage = idPackage;
    }
   
    // keep if that package
    if( g_LastPackage.length > 0 )
    {
        if( idPackage == "none" )
        {
            idPackage = g_LastPackage;
        }
    }


    // hide all
    if( 1 == bUseDisplay )
    {
        document.getElementById('idSubSec1').style.display = 'none';
        document.getElementById('idSubSec2').style.display = 'none';
        document.getElementById('idSubSys1').style.display = 'none';
        document.getElementById('idSubSys2').style.display = 'none';
        document.getElementById('idSubAuto1').style.display = 'none';
        document.getElementById('idSubAuto2').style.display = 'none';
        document.getElementById('idSubFiles1').style.display = 'none';
        document.getElementById('idSubFiles2').style.display = 'none';
        document.getElementById('idSubDev1').style.display = 'none';
        document.getElementById('idSubDev2').style.display = 'none';
    }
    else
    {
        document.getElementById('idSubSec1').style.visibility = 'collapse';
        document.getElementById('idSubSec2').style.visibility = 'collapse';
        document.getElementById('idSubSys1').style.visibility = 'collapse';
        document.getElementById('idSubSys2').style.visibility = 'collapse';
        document.getElementById('idSubAuto1').style.visibility = 'collapse';
        document.getElementById('idSubAuto2').style.visibility = 'collapse';
        document.getElementById('idSubFiles1').style.visibility = 'collapse';
        document.getElementById('idSubFiles2').style.visibility = 'collapse';
        document.getElementById('idSubDev1').style.visibility = 'collapse';
        document.getElementById('idSubDev2').style.visibility = 'collapse';
    }

    document.getElementById('idTopSec').style.fontWeight = 'normal';
    document.getElementById('idTopSys').style.fontWeight = 'normal';
    document.getElementById('idTopAuto').style.fontWeight = 'normal';
    document.getElementById('idTopFiles').style.fontWeight = 'normal';


    // show contents of highlighted package
    if( 'idTopSec' == idPackage )
    {
        if( 1 == bUseDisplay )
        {
            document.getElementById('idSubSec1').style.display = 'block';
            document.getElementById('idSubSec2').style.display = 'block';
        }
        else
        {
            document.getElementById('idSubSec1').style.visibility = 'visible';
            document.getElementById('idSubSec2').style.visibility = 'visible';
        }
        document.getElementById('idTopSec').style.fontWeight = 'bold';
    }
    else if( 'idTopAuto' == idPackage )
    {
        if( 1 == bUseDisplay )
        {
            document.getElementById('idSubAuto1').style.display = 'block';
            document.getElementById('idSubAuto2').style.display = 'block';
        }
        else
        {
            document.getElementById('idSubAuto1').style.visibility = 'visible';
            document.getElementById('idSubAuto2').style.visibility = 'visible';
        }
        document.getElementById('idTopAuto').style.fontWeight = 'bold';
    }
    else if( 'idTopSys' == idPackage )
    {
        if( 1 == bUseDisplay )
        {
            document.getElementById('idSubSys1').style.display = 'block';
            document.getElementById('idSubSys2').style.display = 'block';
        }
        else
        {
            document.getElementById('idSubSys1').style.visibility = 'visible';
            document.getElementById('idSubSys2').style.visibility = 'visible';
        }
        document.getElementById('idTopSys').style.fontWeight = 'bold';
    }
    else if( 'idTopFiles' == idPackage )
    {
        if( 1 == bUseDisplay )
        {
            document.getElementById('idSubFiles1').style.display = 'block';
            document.getElementById('idSubFiles2').style.display = 'block';
        }
        else
        {
            document.getElementById('idSubFiles1').style.visibility = 'visible';
            document.getElementById('idSubFiles2').style.visibility = 'visible';
        }
        document.getElementById('idTopFiles').style.fontWeight = 'bold';
    }
    else if( 'idTopDev' == idPackage )
    {
        if( 1 == bUseDisplay )
        {
            document.getElementById('idSubDev1').style.display = 'block';
            document.getElementById('idSubDev2').style.display = 'block';
        }
        else
        {
            document.getElementById('idSubDev1').style.visibility = 'visible';
            document.getElementById('idSubDev2').style.visibility = 'visible';
        }
    }
}

// -----------------------------------------------
function ShowMoreSec()
{
    ToggelRow('idTabSec2', 1);
    ToggelRow('idTabSecMore', 0);
}

// -----------------------------------------------
function ShowMoreSys()
{
    ToggelRow('idTabSys2', 1);
    ToggelRow('idTabSys3', 1);
    ToggelRow('idTabSys4', 1);
    ToggelRow('idTabSys5', 1);
    ToggelRow('idTabSys6', 1);
    ToggelRow('idTabSysMore', 0);
}

// -----------------------------------------------
function ShowMoreAuto()
{
    ToggelRow('idTabAuto2', 1);
    ToggelRow('idTabAutoMore', 0);
}

// -----------------------------------------------
function ShowMoreFiles()
{
    ToggelRow('idTabFiles2', 1);
    ToggelRow('idTabFilesMore', 0);
}

// -----------------------------------------------
function ShowMoreOff()
{
    ToggelRow('idTabSec2', 0);
    ToggelRow('idTabSys2', 0);
    ToggelRow('idTabSys3', 0);
    ToggelRow('idTabSys4', 0);
    ToggelRow('idTabSys5', 0);
    ToggelRow('idTabSys6', 0);
    ToggelRow('idTabAuto2', 0);
    ToggelRow('idTabFiles2', 0);
}

// -----------------------------------------------
function ToggelRow(idRow, bShow)
{
    bUseDisplay = 0;
    if( navigator.userAgent.indexOf("Firefox") < 0 )
    {
        bUseDisplay = 1;  // collapse is not supported
    }

    if( 1 == bShow )
    {
        // show 
        if( 1 == bUseDisplay )
        {
            document.getElementById(idRow).style.display = 'block';
        }
        else
        {
            document.getElementById(idRow).style.visibility = 'visible';
        }
    }
    else 
    { 
        // hide
        if( 1 == bUseDisplay )
        {
            document.getElementById(idRow).style.display = 'none';
        }
        else
        {
            document.getElementById(idRow).style.visibility = 'collapse';
        }
    } 
}

// --------------------------------------------------------
// Copyright © 1993-2010 12Ghosts Inc. All rights reserved.
// --------------------------------------------------------


// -----------------------------------------------
function createXHR() 
{
    var request = false;
    try
    {
        request = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (err2)
    {
        try
        {
            request = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (err3)
        {
	        try
	        {
		        request = new XMLHttpRequest();
	        }
	        catch (err1) 
	        {
		        request = false;
	        }
        }
    }
    return request;
}


// --------------------------------------------------------
// Copyright © 1993-2010 12Ghosts Inc. All rights reserved.
// --------------------------------------------------------

