var nPINs = 0;

function checkForm()
{
    var sErr = "";
    var Form = document.theForm, lOk = true;

    recalc2();

    if(nPINs < 30){
        if(Form.total.value == "" || isNaN(parseFloat(Form.total.value)) || parseFloat(Form.total.value) < 20){
            alert("Total must be $20 or more");
            Form.amount[0].focus();
            return false;
        }
    }

    Form.ccname.value = Trim(Form.ccname.value);
    if(Form.ccname.value.length < 4){
        alert("Name is incorrect");
        Form.ccname.focus();
        return false;
    }

    Form.ccnum.value = Trim(Form.ccnum.value);
    if(Form.ccnum.value == "" || Form.ccnum.value.length < 15){
        alert("Credit Card Number is incorrect");
        Form.ccnum.focus();
        return false;
    }

        Form.address.value = Trim(Form.address.value);
        if(Form.address.value == ""){
            alert("Street address is incorrect");
            Form.address.focus();
            return false;
        }
      
    Form.zip.value = Trim(Form.zip.value);
    if(Form.zip.value == "" || Form.zip.value.length < 5){
        alert("Zip Code is incorrect");
        Form.zip.focus();
        return false;
    }

    return true;
}
function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}
function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}
function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}
function Replace(Expression, Find, Replace)
{
	var temp = Expression;
	var a = 0;

	for (var i = 0; i < Expression.length; i++)
	{
		a = temp.indexOf(Find);
		if (a == -1)
			break
		else
			temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}

	return temp;
}
function recalc2()
{
    var i, s = 0, Form = document.theForm, El; 
    var am = new String('amount');

    if(nPINs < 30){
        for(i = 0; i < Form.elements.length; i++){
            El = Form.elements[i];

            if(El.name.substring(0,6) == "amount"){
                El.value = Replace(El.value, ",", ".");
                if(El.value == "0")
                    El.value = "";

                if(!isNaN(parseFloat(El.value))){
                    //alert(parseFloat(El.value));
                    El.value = Math.round(parseFloat(El.value) * 100) / 100
                    s = Math.round((parseFloat(s) + parseFloat(El.value)) * 100) / 100;
                }
                else{
                    El.value = "";
                }
            }
        }

        Form.total0.value = s;
        Form.total.value = s;
    }
}
