<!--

/////////////////////////////////////////////////////////////////////////////
// <a href="newlink.php" onclick="javascript: return function();"> blah </a>
// <input type="submit" name="submit" value="Step #2: Credit Card &gt;" class="vistabuttonbig" onclick="javascript: ProcessOrder();">
// <input type="submit" name="submit" value="Step #2: Credit Card &gt;" class="vistabuttonbig" onclick="if(order.item_number.value.length<24) { alert('Please enter a valid Previous Key'); order.item_number.focus(); } else { document.order.onsubmit(); }">
// 

/////////////////////////////////////////////////////////////////////////////
function poptastic(iItem, iWidth, iHeight)
{
    var attribs = "toolbar=0,menubar=1,location=0,status=1,resizable=1,scrollbars=0,left=" + ((screen.width/2)-(iWidth/2)) + ",top=" + (((screen.height/2)-(iHeight/2))-40) + ",width=" + iWidth + ",height=" + iHeight;
    var generator=window.open('','Upgrades',attribs);

    generator.document.write("<html><head><title>vTask Studio</title>");
    generator.document.write("<style type='text/css'>BODY { font-size:13px; color:#404040; font-family:Tahoma,Verdana,Arial; margin:0px; background: #ffffff; }</style>");
    generator.document.write("</head><body><table width='100%' cellpadding='8' cellspacing='0' border='0'>");
    generator.document.write("<tr><td bgcolor='#85B7DC' width='50'><img border='0' src='http://www.vtaskstudio.com/images/vistacircle.gif'></td>");
    if(iItem==1)
    {
        generator.document.write("<td bgcolor='#85B7DC'><font color='#ffffff' style='font-size: 20px' face='Arial,Tahoma,Verdana,Helvetica'>vTask Studio Upgrade Policy</font></td></tr></table>");
        generator.document.write("<br><br>&nbsp; &nbsp; <u>vTask Studio Upgrade Policy:</u><br><br>");
        generator.document.write("<ul><li> A one-year maintenance agreement is included with each purchase.  All improvements to the product are provided at no cost during the first 12 months.<br><br>");
        generator.document.write("<li> Returning customers receive a 50% discount off the current pricing.  This discount applies for any previous version of vTask.  The discount must be used the same number of licenses (or fewer) as the original purchase.<br><br>");
        generator.document.write("<li> To receive the upgrade discount, click the 'Upgrade' button on the purchase page.</ul><br>");
    }
    else if(iItem==2)
    {
        generator.document.write("<td bgcolor='#85B7DC'><font color='#ffffff' style='font-size: 20px' face='Arial,Tahoma,Verdana,Helvetica'>Vista Software, Inc. Privacy Statement</font></td></tr></table>");
        generator.document.write("<br><br>&nbsp; &nbsp; <u>Your Personal and Corporate Information</u><br><br>");
        generator.document.write("<ul><li> Under no circumstances do we sell, rent, or lease our customer lists or any customer information to third parties.<br><br>");
        generator.document.write("<li> All purchase and customer information is stored in an offline computer, and is not accessible externally via the internet.<br><br>");
        generator.document.write("<li> Vista Software will never send 'spam'.  Upon request or purchase, we notify users of available upgrades.  Any email notification from Vista Software will also include a link that allows withdrawal from the automatic notification process.<br><br>");
        generator.document.write("<li> Vista Software websites do not use any 'cookies', or other tracking information.<br><br>");
        generator.document.write("<li> Any questions or requests concerning privacy can be sent to <a href='mailto:support@vtaskstudio.com'><u>support@vtaskstudio.com</u></a>.<br><br>");
        generator.document.write("</ul><br><br>");
    }
    else if(iItem==3)
    {
        generator.document.write("<td bgcolor='#85B7DC'><font color='#ffffff' style='font-size: 20px' face='Arial,Tahoma,Verdana,Helvetica'>License Agreement</font></td></tr></table>");
        generator.document.write("<br><br>&nbsp; &nbsp; <u>By downloading, installing, copying, using, or taking possession of this Software, you are agreeing to be bound by the terms of this Agreement:</u><br><br>");
        generator.document.write("<ul><li> 1. You may not reverse engineer, decompile, or disassemble the Software.  You may not remove any proprietary notices, labels or marks on the program and accompanying documentation.  This Software may not be used in commercial applications, resold, or leased without the prior written consent of Vista Software.<br><br>");
        generator.document.write("<li> 2. All title and copyrights in and to the Software (including but not limited to any images, photographs, animations, video, audio, music, and text incorporated into the Software), the accompanying printed materials, and any copies of the Software are owned by Vista Software. The Software is protected by copyright laws and international treaty provisions.<br><br>");
        generator.document.write("<li> 3. The Software is provided AS IS and with all faults. Vista Software makes no representations or warranties of any kind concerning the quality, safety or suitability of the Software, either express or implied, including without limitation any implied warranties of merchantability, fitness for a particular purpose, or non-infringement. In no event will Vista Software be liable for any indirect, punitive, special, incidental or consequential damages however they may arise and even if Vista Software has been previously advised of the possibility of such damages.<br></ul><br>");
    }
    generator.document.write("<center><a href='javascript:self.close()'>Close</a></center></body></html>");
    generator.document.close();

    if(window.focus)
    {
        generator.focus();
    }
}

/////////////////////////////////////////////////////////////////////////////
// Use this function with "onclick" not "onsubmit", since we have 2 SUBMIT buttons on the form (each for different database action)
function ValidateEmailAndPost(formname, iCommand)
{
    var str = formname.email.value;

    if(str.length < 5 || str.indexOf(".") < 2 || str.indexOf("@") < 1 || str.indexOf(" ") > 0 || str.indexOf(",") > 0 || str.indexOf("!") > 0 || str.indexOf("#") > 0 || str=="name@email.com")
    {
        alert("Please enter a valid email address");
        formname.email.focus();
        return false;
    }

    var attribs = "toolbar=0,menubar=0,left=" + ((screen.width/2)-150) + ",top=" + ((screen.height/2)-125) + ",width=300,height=250,resizable=yes,scrollbars=no";

    var poststring = "";
    if(iCommand==2)
    {
        poststring = "http://www.vtaskstudio.com/vista.pl?action=remove&email=" + formname.email.value;
    }
    else if(iCommand==3)
    {
        poststring = "http://www.vtaskstudio.com/vista.pl?action=notify&email=" + formname.email.value;
    }
    else if(iCommand==4)
    {
        poststring = "http://www.vtaskstudio.com/vista.pl?action=remove&email=" + formname.email.value;
    }
    else
    {
        poststring = "http://www.vtaskstudio.com/vista.pl?action=notify&email=" + formname.email.value;
    }

    //alert(poststring);
    newwindow = window.open(poststring, "_blank", attribs);
    return true;
}

/////////////////////////////////////////////////////////////////////////////
function UpdateOrder(bDiscountAlreadyApplied, szWhichProduct)
{
    var iMediaQty;
    var iMaint;
    var fMediaTotal;
    var fLicenseTotal;
    var szLicenseTotal;
    var szGrandTotal;
    var szMediaTotal;
    var szGrandTotalFormatted;
    var szPriceEach;
    var szAmount;
    var fPrice;

    //alert(document.getElementById('price').innerHTML);

    // Yes, hardcoded, so what
    iQty = atoix(document.getElementById('qty').value);
    if(iQty<0)
    {
        iQty = 0;
    }

    // ----------------------------------------------------
    // MEDIA
    fMediaTotal = 0;
    // put/remove shipping cost
    // FOR HARD-CODED SINGLE, this is all you need:  SetItemText('media_qty', '1', 2);
    // FOR HARD-CODED SINGLE, this is all you need:  SetItemText('media_cost', '19.00', 2);    
    iMediaQty = atoix(document.getElementById('media_qty').value);
    if(iMediaQty<1 || iMediaQty.toString()=='NaN')
    {
        iMediaQty = 0;
        SetItemText('media_qty', '0', 1);
    }
    // DEBUG  alert(iQty.toString() + ", " + iMediaQty.toString());
    // sorry, can't order more CD's than licenses
    if(iQty < iMediaQty)
    {
        alert("The CD-ROM media quantity cannot be greater than the License quantity");
        SetItemText('media_qty', iQty.toString(), 1);
        iMediaQty = iQty;
    }    
    fMediaTotal = (iMediaQty*19.00);
    szMediaTotal = fMediaTotal.toString() + ".00";
    SetItemText('media_ext', szMediaTotal, 2);
    // required shipping details in PayPal
    // NO: WE ALREADY HAVE THIS CALC'D FROM ABOVE:  iMediaTotal = atoix(document.getElementById('media_cost').innerHTML);
    
    // ----------------------------------------------------
    // QUANTITY
    // They may have picked the upgrade package which sets the price+qty; don't redo discount
    if(bDiscountAlreadyApplied==true)
    {
        fPrice = atoix(document.getElementById('price').innerHTML);
        // no, it's already done, duh  SetItemText('price', fPrice.toString() + ".00", 2);
    }
    
    // Auto-update their discount level
    fPrice = 99.00;
    if(iQty>=10)
    {
        fPrice = 79.00;
    }
    
    if(document.getElementById('discount').value.length > 24)
    {
        fPrice = (fPrice / 2);
    }
    else if(document.getElementById('discount').value == "CROSSGRADE" || document.getElementById('discount').value == "Crossgrade" || document.getElementById('discount').value == "crossgrade")
    {
        fPrice = (fPrice * 0.85);
    }
    else if(document.getElementById('discount').value == "RESELLER" || document.getElementById('discount').value == "Reseller" || document.getElementById('discount').value == "reseller")
    {
        fPrice = (fPrice * 0.80);
    }

    fPrice = fPrice.toFixed();

    szPriceEach = fPrice.toString() + ".00";
    SetItemText('price', szPriceEach, 2);

    // ----------------------------------------------------
    // UPDATE THE PAGE'S DATA
    fLicenseTotal = (fPrice*iQty);

    var fGrandTotal = new Number(fLicenseTotal + fMediaTotal);
    fGrandTotal = fGrandTotal.toFixed(0);
    if(fGrandTotal>0)
    {
        szLicenseTotal = fLicenseTotal.toString() + ".00";
        szGrandTotal = "$" + fGrandTotal.toString() + ".00";
        szAmount = fGrandTotal.toString() + ".00";
    }
    else
    {
        szLicenseTotal = "0.00";
        szGrandTotal = "$0.00";
        szAmount = "0.00";
    }

    szGrandTotalFormatted = "<font style='font-size: 14px'>" + szGrandTotal + "</font>";
    SetItemText('price_ext', szLicenseTotal, 2);
    SetItemText('grandtotal', szGrandTotalFormatted, 2);
    // this is a PayPal field
    SetItemText('amount', szAmount, 1);

    if(iQty==1)
    {
        szItem = "vTask 1 License";
    }
    else
    {
        szItem = "vTask " + iQty.toString() + " License Pack";
    }
    
    if(iMediaQty>0)
    {
        szItem = szItem + " + " + iMediaQty.toString() + " CD-ROM";
    }
    
    if(document.getElementById('discount').value.length > 0)
    {
        szItem = szItem + " Discount: " + document.getElementById('discount').value;
    }
    
    // this is a PayPal field
    SetItemText('item_name', szItem, 1);
}

/////////////////////////////////////////////////////////////////////////////
// bUseValueOrInner:  1==edit field and hidden input; 2==table data
function SetItemText(id, newval, bUseValueOrInner)
{
    if(document.getElementById)
    {
        t = document.getElementById(id);
    }
    else
    {
        t = document.all(id);
    }
    if(t == null)
        return;

    //alert(document.order.qty.value);
    //alert(document.order['qty'].value);

    // document.forms[0].select.selectedIndex = 2;

    //if (document.forms[0].checkbox.checked)
    //      user_input = document.forms[0].checkbox.name
    // document.forms[0].checkbox.checked = true

    // var x=document.getElementById('myTable').rows[0].cells
    // x[0].innerHTML="NEW CONTENT"
    // document.getElementById('myTable').deleteRow(i)  http://www.w3schools.com/js/tryit.asp?filename=try_dom_table_deleterow

    //Unfortunately it's not possible to see at once which radio button in a group the user has checked. You need to go through all radio's and see which one's checked property is true.
    //for (i=0;i<document.forms[0].radios.length;i++)
    //{
    //    if (document.forms[0].radios[i].checked)
    //    {
    //        user_input = document.forms[0].radios[i].value;
    //    }
    //}
    //
    //var i = document.form.selectname.selectedIndex;
    //var val = document.form.selectname[i].value;
    //var txt = document.form.selectname[i].text;
    //or
    //var o = document.form.selectname.options;
    //var val = o[o.selectedIndex].value;
    //var txt = o[o.selectedIndex].text;

    // http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=11
    // REFERENCING Example:
    //p = document.getElementById("pid");
    //p.style.color = "blue"
    //p.style.fontSize = "18pt"

    // For example, if a radio button has the name 'mybutton', it can be referenced using:  document.nameOfForm.mybutton
    // but if two radio buttons share the name 'mybutton',
    //      the second button (for example) can be referenced using:  document.nameOfForm.mybutton[1]
    // For select boxes, each individual option can be referenced using:  input_name.options[number_of_option]

    //To fully reference an image, use
    //document['imagename'].src
    //or
    //document.images['imagename'].src
    //or
    //document.images[number_of_image].src

    // One or the other will work
    if(bUseValueOrInner==1)
    {
        t.value = newval;
    }
    else
    {
        t.innerHTML = newval;
        //t.innerText = newval;
    }
}

/////////////////////////////////////////////////////////////////////////////
function atoix(sometext)
{
    var newstring;
    newstring = "";
    for(iLoop=0; iLoop<10; iLoop++)
    {
        if((sometext.substring(iLoop, iLoop+1) >= '0' && sometext.substring(iLoop, iLoop+1) <= '9') || sometext.substring(iLoop, iLoop+1) == '.')
        {
            newstring = newstring + sometext.substring(iLoop, iLoop+1);
        }
    }
    return parseFloat(newstring);
}

// comment end: stop hiding -->
