/* 
DHTML version 3.3.19
Written by Gregory Wood
Copyright 2004(c) Gregory Wood. All Rights Reserved.
*/

back = "begin";


function FormatNumeric(oField)
{
    var sText = "";
    var iDecimalCount = 0;

    // Strip out non numerics
    for (var i = 0; i <= oField.value.length - 1; i++)
    {
        if (oField.value.charCodeAt(i) >= 48 &&
            oField.value.charCodeAt(i) <= 57)
        {
            sText = sText + oField.value.charAt(i);
        }
        else if (oField.value.charCodeAt(i) == 46)
        {
            // Make sure we only have one decimal point
            if (iDecimalCount == 0)
            {
                iDecimalCount = 1;
                sText = sText + oField.value.charAt(i);
            }
        }
    }

    // Set to 0 if no characters present
    if (sText.length == 0)
    {
        sText = "0";
    }

    // Add decimal point if missing
    if (iDecimalCount == 0)
    {
        sText = sText + ".";
    }
    // Add leading digit if missing
    else if (sText.indexOf(".") == 0)
    {
        sText = "0" + sText;
    }

    // Pad string for decimal values
    sText = sText + "00";

    //Strip off excess digits after the decimal point
    sText = sText.substr(0, sText.indexOf(".") + 3);

    // Set field value
    oField.value = sText;
}


function isIntegerVal(sVal)
{
    re_isIntegerVal = /^\d+$/;
    return re_isIntegerVal.test(sVal);
}


function isDecimalVal(sVal)
{
    re_isDecimalVal = /^\d+\.\d{2}$/;
    return re_isDecimalVal.test(sVal);
}


function submitnow()
{ 
    if(testfields())
    {
        document.form1.DESCRIPTION.value = "INVAILID";
        back = "reloadable";
        checkselection();
        document.form1.submit();
    }
    else
    {
        return;
    }
}


function testfields()
{
    propaddr = document.form1.PROPADDRESS.value;
    name = document.form1.NAME.value;
    street = document.form1.ADDRESS.value;
    city = document.form1.CITY.value;
    state = document.form1.STATE.value;
    zip = document.form1.ZIP.value;
    country = document.form1.COUNTRY.value;
    phone = document.form1.PHONE.value;
    email = document.form1.EMAIL.value;

    FormatNumeric(document.form1.tinvoice);
    tinvoice = document.form1.tinvoice.value;

    if((document.form1.fldLang.value == "INVOICED") && ((tinvoice == "") || (tinvoice == "0.00")))
    {
        alert("Please enter the Payment Amount for this invoice!");
        document.forms['form1'].elements['tinvoice'].focus();
        return false;
    }
    else if((document.form1.fldLang.value == "INVOICED") && (isIntegerVal(tinvoice) == false) && (isDecimalVal(tinvoice) == false))
    {
        alert("Please check the 'Invoice Payment Amount' field, numeric values ONLY!");
        document.forms['form1'].elements['tinvoice'].focus();
        return false;
    }
    else if((propaddr == ""))
    {
        alert("Please enter the Property Address for this payment!");
        document.forms['form1'].elements['PROPADDRESS'].focus();
        return false;
    }
    else if((name == ""))
    {
        alert("Please enter the name as it appears on the credit card!");
        document.forms['form1'].elements['NAME'].focus();
        return false;
    }
    else if((street == ""))
    {
        alert("Please enter your billing street address!");
        document.forms['form1'].elements['ADDRESS'].focus();
        return false;
    }
    else if((city == ""))
    {
        alert("Please enter your billing address's city!");
        document.forms['form1'].elements['CITY'].focus();
        return false;
    }
    else if((state == ""))
    {
        alert("Please enter your billing address's state!");
        document.forms['form1'].elements['STATE'].focus();
        return false;
    }
    else if((zip == ""))
    {
        alert("Please enter your billing address's zip code!");
        document.forms['form1'].elements['ZIP'].focus();
        return false;
    }
    else if((country == ""))
    {
        alert("Please enter your billing address's country!");
        document.forms['form1'].elements['COUNTRY'].focus();
        return false;
    }
    else if((phone == ""))
    {
        alert("Please enter your billing address's phone number!");
        document.forms['form1'].elements['PHONE'].focus();
        return false;
    }
    else if((email == ""))
    {
        alert("Please enter your E-mail address!");
        document.forms['form1'].elements['EMAIL'].focus();
        return false;
    }
    else
    {
        return true;
    }
}


function checkselection()
{
    var charge = 5.00;

    if (document.form1.fldLang.value == "INVOICED")
    {//Checks if INVOICE radio button is checked
        var tiInum = document.form1.tinvoicenum.value;
        var tinval = document.form1.tinvoice.value;
        //alert(parseFloat(tinval) + charge + " " + tiInum + "-: " + document.form1.PROPADDRESS.value);
        document.form1.DESCRIPTION.value = "I-" + tiInum + "-: " + document.form1.PROPADDRESS.value;
        document.form1.AMOUNT.value = parseFloat(tinval.replace(/,/g, "")) + charge;
    }

    else if (document.form1.fldLang.value == "ESTOPPEL")
    {//Checks if ESTOPPEL radio button is checked
        var estval = document.form1.est.value;
        if (document.form1.rushpay.checked == true)
        {
            //alert(parseInt(estval) * 2 + charge + " " + estval.substr(5) + "-: " + document.form1.PROPADDRESS.value);
            document.form1.DESCRIPTION.value = "<RUSH>Eestoppel-" + estval.substr(5) + "-: " + document.form1.PROPADDRESS.value;
            document.form1.AMOUNT.value = parseInt(estval.replace(/,/g, "")) * 2 + charge;
        }
        else
        {
            //alert(parseInt(estval) + charge + " " + estval.substr(5) + "-: " + document.form1.PROPADDRESS.value);
            document.form1.DESCRIPTION.value = "Eestoppel-" + estval.substr(5) + "-: " + document.form1.PROPADDRESS.value;
            document.form1.AMOUNT.value = parseInt(estval.replace(/,/g, "")) + charge;
        }
    }

    else if (document.form1.fldLang.value == "RESALE")
    {//Checks if RESALE radio button is checked
        var resval = document.form1.res.value;
        if (document.form1.rushpay.checked == true)
        {
            //alert(parseInt(resval) * 2 + charge + " " + resval.substr(5) + "-: " + document.form1.PROPADDRESS.value);
            document.form1.DESCRIPTION.value = "<RUSH>Resale-" + resval.substr(5) + "-: " + document.form1.PROPADDRESS.value;
            document.form1.AMOUNT.value = parseInt(resval.replace(/,/g, "")) * 2 + charge;
        }
        else
        {
            //alert(parseInt(resval) + charge + " " + resval.substr(5) + "-: " + document.form1.PROPADDRESS.value);
            document.form1.DESCRIPTION.value = "Resale-" + resval.substr(5) + "-: " + document.form1.PROPADDRESS.value;
            document.form1.AMOUNT.value = parseInt(resval.replace(/,/g, "")) + charge;
        }
    }
    
    else if (document.form1.fldLang.value == "PLANREVIEW")
    {//Checks if PLAN REVIEW radio button is checked
        var preval = document.form1.pre.value;
        //alert(parseInt(preval) + charge + " " + preval.substr(5) + "-: " + document.form1.PROPADDRESS.value);
        document.form1.DESCRIPTION.value = "Plan Review-" + preval.substr(5) + "-: " + document.form1.PROPADDRESS.value;
        document.form1.AMOUNT.value = parseInt(preval.replace(/,/g, "")) + charge;
    }
    
    else
    {
        return false;
    }

    //r = tinval.replace(/,/g, "");
    //alert(parseInt(tinval.replace(/,/g, "")) * 2 + charge);
    //alert(parseInt(tinval) + charge);
}


function reset()
{
    document.form1.rushpay.checked = false;

    document.forms['form1'].fldLang.options[0].selected = true;

    //for (i = 0; i < document.form1.fldLang.length; i++)
    //{
    //    if (document.form1.fldLang[i].checked == true)
    //    {
    //        document.form1.fldLang[i].checked = false;
    //    }
    //}

    document.forms['form1'].elements['tinvoice'].value = "";
    document.forms['form1'].elements['tinvoicenum'].value = "";
    document.forms['form1'].elements['PROPADDRESS'].value = "";
    document.forms['form1'].est.options[0].selected = true;
    document.forms['form1'].res.options[0].selected = true;
    document.forms['form1'].pre.options[0].selected = true;
    document.forms['form1'].elements['NAME'].value = "";
    document.forms['form1'].elements['ADDRESS'].value = "";
    document.forms['form1'].elements['CITY'].value = "";
    document.forms['form1'].elements['STATE'].value = "";
    document.forms['form1'].elements['ZIP'].value = "";
    document.forms['form1'].elements['PHONE'].value = "";
    document.forms['form1'].elements['EMAIL'].value = "";
}


function loadup()
{
    //stopErrors();

    //for (t = 0; t < document.form1.fldLang.length; t++)
    //{
    //    if (document.form1.fldLang[t].checked == true)
    //    {
    //        showNext(t + 1);
    //        if (t == 0)
    //        {
    //            showProp(2);
    //            testdropbox();
    //            showPay();
    //            return;
    //        }
    //        else
    //        {
    //            showProp(1);
    //            showPay();
    //            return;
    //        }
    //    }
    //}
}


function showProp(x)
{
    switch(x)
    {
        case 1:
            if(testdropbox())
            {
                window.document.getElementById('propaddrDiv').style.display = "block";
                document.forms['form1'].elements['PROPADDRESS'].focus();
                return true;
            }
            else
            {
                return false;
            }

        case 2:
            field1 = document.form1.tinvoice.value;
            field2 = document.form1.tinvoicenum.value;
            if ((field1 != "") && field2 != "")
            {
                window.document.getElementById('propaddrDiv').style.display = "block";
            }
            else
            {
                return false;
            }
            return false;

        default:
            document.forms['form1'].elements['PROPADDRESS'].value = "";
            document.forms['form1'].elements['tinvoice'].value = "";
            document.forms['form1'].elements['tinvoicenum'].value = "";
            return false;
    }
}


function showPay()
{
    propfield = document.form1.PROPADDRESS.value;

    if (propfield.length > 7)
    {
        window.document.getElementById('addressDiv').style.display = "block";
    }
    else
    {
        window.document.getElementById('addressDiv').style.display = "none";
    }
    return;
}


function showNext()
{
    var x = 0;
    
    if(document.form1.fldLang.value == "INVOICED")
    {
        x = 1;
    }
    if(document.form1.fldLang.value == "ESTOPPEL")
    {
        x = 2;
    }
    if(document.form1.fldLang.value == "RESALE")
    {
        x = 3;
    }
    if(document.form1.fldLang.value == "PLANREVIEW")
    {
        x = 4;
    }

    switch(x)
    {
        case 1:
            if (back == "")
            {
                document.forms['form1'].elements['PROPADDRESS'].value = "";
            }
            else
            {
            
            }

            window.document.getElementById('invoiceDiv').style.display = "block";
            window.document.getElementById('estoppleDiv').style.display = "none";
            window.document.getElementById('resaleDiv').style.display = "none";
            window.document.getElementById('previewDiv').style.display = "none";
            window.document.getElementById('propaddrDiv').style.display = "none";
            window.document.getElementById('addressDiv').style.display = "none";
            window.document.getElementById('rushDiv').style.display = "none"; 
            document.form1.rushpay.checked = false;
            document.forms['form1'].est.options[0].selected = true;
            document.forms['form1'].res.options[0].selected = true;
            document.forms['form1'].pre.options[0].selected = true;
            document.forms['form1'].elements['tinvoicenum'].focus();
            back = "";
            return;

        case 2:
            if (back == "")
            {
                document.forms['form1'].elements['PROPADDRESS'].value = "";
                document.form1.rushpay.checked = false;
            }
            else
            {
            
            }

            window.document.getElementById('estoppleDiv').style.display = "block";
            window.document.getElementById('invoiceDiv').style.display = "none";
            window.document.getElementById('resaleDiv').style.display = "none";
            window.document.getElementById('previewDiv').style.display = "none";
            window.document.getElementById('rushDiv').style.display = "none";//was visible//
            window.document.getElementById('addressDiv').style.display = "none";
            window.document.getElementById('propaddrDiv').style.display = "none";
            document.forms['form1'].res.options[0].selected = true;
            document.forms['form1'].pre.options[0].selected = true;
            document.forms['form1'].elements['tinvoice'].value = "";
            document.forms['form1'].elements['tinvoicenum'].value = "";
            back = "";
            return;

        case 3:
            if (back == "")
            {
                document.forms['form1'].elements['PROPADDRESS'].value = "";
                document.form1.rushpay.checked = false;
            }
            else
            {
            
            }

            window.document.getElementById('resaleDiv').style.display = "block";
            window.document.getElementById('estoppleDiv').style.display = "none";
            window.document.getElementById('invoiceDiv').style.display = "none";
            window.document.getElementById('previewDiv').style.display = "none";
            window.document.getElementById('addressDiv').style.display = "none";
            window.document.getElementById('propaddrDiv').style.display = "none";
            window.document.getElementById('rushDiv').style.display = "none";//was visible//
            document.forms['form1'].est.options[0].selected = true;
            document.forms['form1'].pre.options[0].selected = true;
            document.forms['form1'].elements['tinvoice'].value = "";
            document.forms['form1'].elements['tinvoicenum'].value = "";
            back = "";
            return;

        case 4:
            if (back == "")
            {
                document.forms['form1'].elements['PROPADDRESS'].value = "";
            }
            else
            {
            
            }

            window.document.getElementById('previewDiv').style.display = "block";
            window.document.getElementById('estoppleDiv').style.display = "none";
            window.document.getElementById('resaleDiv').style.display = "none";
            window.document.getElementById('invoiceDiv').style.display = "none";
            window.document.getElementById('rushDiv').style.display = "none";
            window.document.getElementById('addressDiv').style.display = "none";
            window.document.getElementById('propaddrDiv').style.display = "none";
            document.forms['form1'].est.options[0].selected = true;
            document.forms['form1'].res.options[0].selected = true;
            document.forms['form1'].elements['tinvoice'].value = "";
            document.forms['form1'].elements['tinvoicenum'].value = "";
            document.form1.rushpay.checked = false;
            back = "";
            return;

        default:
            window.document.getElementById('previewDiv').style.display = "none";
            window.document.getElementById('estoppleDiv').style.display = "none";
            window.document.getElementById('resaleDiv').style.display = "none";
            window.document.getElementById('invoiceDiv').style.display = "none";
            window.document.getElementById('addressDiv').style.display = "none";
            window.document.getElementById('rushDiv').style.display = "none";
            window.document.getElementById('propaddrDiv').style.display = "none";
            document.forms['form1'].est.options[0].selected = true;
            document.forms['form1'].res.options[0].selected = true;
            document.forms['form1'].pre.options[0].selected = true;
            document.forms['form1'].elements['tinvoice'].value = "";
            document.forms['form1'].elements['tinvoicenum'].value = "";
            document.form1.rushpay.checked = false;
            return;
    }
}


function testdropbox()
{
    estoppel = document.form1.est.value;
    resale = document.form1.res.value;
    plan = document.form1.pre.value;

    if(document.form1.fldLang.value == "ESTOPPEL" && estoppel == "")
    {
        showNext(2);
        alert("Please select estoppel type for this payment!");
        document.forms['form1'].elements['PROPADDRESS'].value = "";
        window.document.getElementById('propaddrDiv').style.display = "none";
        window.document.getElementById('addressDiv').style.display = "none";
        return false;
    }
    else if(document.form1.fldLang.value == "RESALE" && resale == "")
    {
        showNext(3);
        alert("Please select resale type for this payment!");
        document.forms['form1'].elements['PROPADDRESS'].value = "";
        window.document.getElementById('propaddrDiv').style.display = "none";
        window.document.getElementById('addressDiv').style.display = "none";
        return false;
    }
    else if(document.form1.fldLang.value == "PLANREVIEW" && plan == "")
    {
        showNext(4);
        alert("Please select plan review type for this payment!");
        document.forms['form1'].elements['PROPADDRESS'].value = "";
        window.document.getElementById('propaddrDiv').style.display = "none";
        window.document.getElementById('addressDiv').style.display = "none";
        return false;
    }
    else
    {
        return true;
    }
}


function stopErrors()
{
    return true;
    window.onerror = stopErrors;
}

