var g_OldBody;                              // Old body of html page
var old;                                    // page innerHTML with buttons

//
// Purpose: Restore old body of html page
//****************************************************************************
function RestoreOldBody()
{
    if ( iBrowser < 5 && iBrowser > 0)
    {
        document.body.innerHTML = g_OldBody;
    }
    else
    {
        document.getElementById("all_form").style.display = "";
        document.getElementById("all_fax").innerHTML = "";
    }
}
//
// Purpose: Save body of html page
//****************************************************************************
function SaveBody()
{
    if ( iBrowser < 5 && iBrowser > 0)
    {
        g_OldBody = document.body.innerHTML;
    }
    else
    {
        document.getElementById("all_form").style.display = "none";
    }
}
//
// Purpose: Hide buttons
//****************************************************************************
function beforeprint()
{
    if (iBrowser < 1)
    {
        objToHide = document.getElementById("tohide");
        objToShow = document.getElementById("toshow");
    }
    else
    {
        objToHide = document.all.tohide;
        objToShow = document.all.toshow;
    }

    old = objToHide.innerHTML ;
    objToHide.innerHTML = '';
    objToShow.style.display = '';
}
//
// Purpose: Show buttons
//****************************************************************************
function afterprint()
{
    objToHide.innerHTML = old;
    objToShow.style.display = 'none';
}
//
// Purpose: If user entered that he has no state/province in address - clear it
//****************************************************************************
function ClearState(sEnteredState)
{

    if (sEnteredState.toUpperCase() == 'N/A'      ||
        sEnteredState.toUpperCase() == 'NON US'   ||
        sEnteredState.toUpperCase() == 'NON USA'  ||
        sEnteredState.toUpperCase() == 'NA'       ||
        sEnteredState.toUpperCase() == 'NONE'     ||
        sEnteredState == '-'        )
    {
        var GetState = '';
    }
    else
    {
        var GetState = sEnteredState;
    }
    return (GetState);
}
//
// Purpose: Switch to print version of page
//****************************************************************************
function PrintVersion()
{
    SaveBody();

    var CurDate          = new Date();
    var sDate            = GetMonthName(CurDate.getMonth()) + " " +
                           CurDate.getDate() + ", " + CurDate.getFullYear();
    var sShipment;

    if (fDownloadOnly == true)
    {
        sShipment = "<br>Download only";
    }
    else
    {
        sShipment = "<br>Physical shipment";
    }

    var sSecondYear = "";
    if (fSecondYear)
    {
        sSecondYear = "<br>With the second year of free upgrades";
    }

    var sProduct         = objProduct.options[objProduct.selectedIndex].text +
                           sShipment + sSecondYear;
    if (fUpgrade == true)
    {
        sProduct = 'Upgrade of ' + sProduct;
    }
    var nNumberCopies    = objNumberOfCopies.value;

    var sNetPrice        = objNetPrice.innerHTML;
    var sSernum          = objSerNum.value;
    var sName            = objTitle.value  + " " + objFirstName.value  + " " + sLastName;
    var sName2           = objTitle2.value + " " + objFirstName2.value + " " + sLastName2;

    var sCountry1        = objCountry.options[objCountry.selectedIndex].text;
    var sCountry2        = objCountry2.options[objCountry2.selectedIndex].text;

    var sCardType        = objCardType.options[objCardType.selectedIndex].text;
    var sCardValid       = sExpDateMonth + " / " + iExpDateYear;

    var sCardID          = objCC_ID.value;
    var sCardNumber      = objCC_Number0.value + " " +
                           objCC_Number1.value + " " +
                           objCC_Number2.value + " " +
                           objCC_Number3.value + " ";

    var s                = "" +
'<table width="100%">' +
'<tr><td><IMG src="../images/logo.jpg" width=174></td>' +
'<td align="right" valign="top">' +
'<table><tr><td class="blue" width="160" align="center"><b>Order</b></td></tr>' +
'</table></td></tr></table>'

if (sRef.length > 0)
{
    s = s +
    '<table width="100%">' +
    '<tr><td align=right class="tnr12">Customer Ref./PO No.:' + sRef + '</td>' +
    '</tr></table>'
}

    s = s +
'<table width="100%">' +
'<tr><td rowspan=2 width="100">&nbsp;</td>' +
'<td colspan=2 class="tnr16" width="500"><b>APSoft / Sales Department</b></td>' +
'</tr>' +
'<tr>' +
'<td class="tnr12" width="130">Am Wald 6, 84437 Reichertsheim, Germany</td>' +
'<td class="tnr12" align="right"><b>' + sDate + '</b></td></tr>' +
'</table><br>' +
'<table width="100%">' +
'<tr><td class="tnr12">By this letter we would like to order following APSoft product:</td></tr></table>' +
'<table width="100%"><tr><td width="10%">&nbsp;</td><td class="cn10"><b>' + sProduct + '</b></td></tr>' +
'<tr><td width="10%">&nbsp;</td><td class="cn10">Copy(ies): <b>' + nNumberCopies + '</b> '
if ( sNetPrice != "" )
{
    s = s + '&nbsp;&nbsp;&nbsp;&nbsp;Net Price: <b>Euros ' + sNetPrice + '</b>';
}
    s = s + '</td></tr>'

    if (sSernum.length > 0)
    {
        s = s +
        '<tr><td width="10%">&nbsp;</td>' +
        '<td class="cn10">Existing serial number: ' +
        '<b>' + sSernum + '</br></td></tr>';
    }

    s = s + '</table>'

    if (fPayByCard)
    {
        s = s +
'<br><table width="100%"><tr><td class="tnr12">Please charge following Credit Card:</td></tr></table>' +
'<table width="100%">' +
'<tr><td width="10%">&nbsp;</td><td class="tnr12" width="25%">Name on the card:</td><td class="cn10"><b>' + sNameOnTheCard + '</b></td></tr>' +
'<tr><td width="10%">&nbsp;</td><td class="tnr12" width="25%">Credit Card Type:</td>' +
'<td class="cn10"><b>' + sCardType + '</b></td></tr>' +
'<tr><td width="10%">&nbsp;</td><td class="tnr12" width="25%">Credit Card Number:</td>' +
'<td class="cn10"><b>' + sCardNumber + '</b></td></tr></table><table width="100%">' +
'<tr><td width="10%">&nbsp;</td><td class="tnr12" width="25%">Valid:</td>' +
'<td class="cn10" width="23%"><b>' + sCardValid + '</b></td>' +
'<td class="tnr12" width="15%">Card ID:</td><td class="cn10"><b>' + sCardID + '</b></td></tr></table>';
    }

    s = s +
'<br><table width="100%">' +
'<tr><td class="tnr12" width="46%"><u>Billing Address:</u></td>';

    if (fUseShippingAddr)
    {
        s = s +
        '<td width="8%">&nbsp;</td><td class="tnr12"><u>Shipping Address:</u></td>';
    }

    s = s + '</tr><tr><td class="cn12" width="46%"><table>';

    if (sName != "")
        s = s +
        '<tr><td width="14%">&nbsp;</td><td class="cn10"><b>' + sName + '</b></td></tr>';

    if (sCompany != "")
        s = s +
        '<tr><td width="14%">&nbsp;</td><td class="cn10"><b>' + sCompany + '</b></td></tr>';

    s = s + '<tr><td width="14%">&nbsp;</td><td class="cn10"><b>' + sStreet + '</b></td></tr>';

    if (sZip != "" || sCity != "")
        s = s +
        '<tr><td width="14%">&nbsp;</td><td class="cn10"><b>' + sZip + ' ' +
        sCity + '</b></td></tr>';

    if (sState != "")
        s = s + '<tr><td width="14%">&nbsp;</td><td class="cn10"><b>' + sState + '</b></td></tr>';

    if (sCountry1 != "")
        s = s +
        '<tr><td width="14%">&nbsp;</td><td class="cn10"><b>' + sCountry1 + '</b></td></tr>';

    s = s + '</table>';

    if (fUseShippingAddr)
    {
        s = s + '<td>&nbsp;</td><td><table>';

        if (sName2 != "")
            s = s + '<tr><td class="cn10"><b>' + sName2 + '</b></td></tr>';

        if (sCompany2 != "")
            s = s + '<tr><td class="cn10"><b>' + sCompany2 + '</b></td></tr>';

        if (sStreet2 != "")
            s = s + '<tr><td class="cn10"><b>' + sStreet2 + '</b></td></tr>';

        if (sZip2 != "" || sCity2 != "")
            s = s + '<tr><td class="cn10"><b>' + sZip2 + ' ' + sCity2 + '</b></td></tr>';

        if (sState2 != "")
            s = s + '<tr><td class="cn10"><b>' + sState2 + '</b></td></tr>';

        if (sCountry2 != "")
            s = s + '<tr><td class="cn10"><b>' + sCountry2 + '</b></td></tr>';


        s = s + '</table>';
    }

    s = s +
    '</tr></table><br></tr></table><br><table width="100%">' +
    '<tr><td class="cn12" nowrap width="20%">EMail:</td><td class="cn10"><b>' +
    sEmail + '</b></td></tr></table>';

    if (sPhone != "")
    {
        s = s +
        '<table width="100%"><tr><td class="cn12" nowrap width="20%">Phone #:</td>' +
        '<td class="cn10"><b>' + sPhone + '</b></td></tr></table>';
    }

    if (sFax != "")
    {
        s = s +
        '<table width="100%"><tr><td class="cn12" width="20%">FAX #:</td>' +
        '<td class="cn10"><b>' + sFax + '</b></td></tr></table>';
    }

    if (sVat != "")
    {
    s = s +
    '<br><table width="100%"><tr><td class="cn12" nowrap width="20%">VAT:</td>' +
    '<td class="cn10"><b>' + sVat + '</b></td></tr></table>';
    }

    s = s +
    '<br><p align="center"><table width="70%">' +
    '<tr><td class="tnr12" nowrap>Please sign here:</td><td nowrap class="cn10"><u>';

    for (j = 0; j < 40; j++)
        s += '&nbsp;';

    s = s +
    '</u></td><td>&nbsp;</td></tr>' +
    '<tr><td>&nbsp;</td>';

    if (fPayByCard)
    {
        s = s +
        '<td align="center"><i><p class="tnr10">(Credit Card holder)</p></i></td>'
    }
    s = s +
    '</tr><tr><td class="tnr12" nowrap>Printed Name:</td><td nowrap class="cn10"><u><b>';

    var sTmp, i;

    if (fPayByCard)
        sTmp = sNameOnTheCard;
    else if (sName != "")
        sTmp = sName;
    else if (sName2 != "")
        sTmp = sName2;
    else
        sTmp = "";

    for (i = 0; i < 40; i++)
    {
        var cTemp = sTmp.charAt(i);
        if (cTemp != "")
            s += cTemp;
        else
            s += '&nbsp;';
    }


    s = s + '</b></u></td><td>&nbsp;</td></tr></table></p>' +
    '<p id="toshow" style="display: none;" class="tnr10" align="center">' +
    '<i>Please fax signed form to +49 8073 9275.</i></p>' +
    '<div id="tohide"><hr color="FF6600"><ol class="tip">'

    if ( iBrowser == -2 || iBrowser == 0 )  // opera and unknown browsers
    {
        s = s +
        '<li>APSoft recommends usage of Microsoft Internet Explorer Version 5.x ' +
        'or later for view this site. Our WEB could be not compatible with your ' +
        'version of Internet Browser. We are sorry for your inconvenience.' +
        '<br>Please feel free <a href="mailto:sales@tssc.de">contact us by ' +
        'e-mail</a> if you have any question.</li>'
    }

    s = s +
    '<li>Please review your order. If you want to correct entered information, ' +
    'please click <a href="" onclick="' + sCancelEvent + 'RestoreOldBody();">' +
    '<img align=absmiddle border=0 alt="Review" src="images/review.gif"></a> ' +
    'button, otherwise please press <a href="" onclick="' + sCancelEvent + 'print();">' +
    '<img align=absmiddle border=0 alt="Print" src="images/print.gif"></a> ' +
    'button for print your order.</li><li>Please hand-sign your order.</li>' +
    '<li>Please fax signed form to +49 8073 9275. Alternatively you can ' +
    'send signed form via regular mail or scan and e-mail it.</li>' +
    '</ol></div>';
    if (iBrowser > 0 && iBrowser < 5)
    {
        document.body.innerHTML = s;
    }
    else
    {
        document.getElementById("all_fax").innerHTML = s;
    }
}

