function updateTotals() {
var subtotal = 0

if (document.golfreg.vipsponsor.checked) {
subtotal = subtotal+3000
                                }

if (document.golfreg.holeteamsponsor.checked) {
subtotal = subtotal+1800
                                }

if (document.golfreg.teamsponsor.checked) {
subtotal = subtotal+1500                                }

if (document.golfreg.lunchsponsor.checked) {
subtotal = subtotal+2000
                                }

if (document.golfreg.bevsponsor.checked) {
subtotal = subtotal+1000
                                }

if (document.golfreg.holesponsor.checked) {
subtotal = subtotal+300
                                }

document.golfreg.subtotal.value = currencyPad(subtotal,10)
        
if (subtotal < 0)
{subtotal == 0}
                        
return;
}

function ckFrm(FrmName){
	var f = false;
	f = checkForm(FrmName);
	if (f == true){
		FrmName.submit();
	}

	}
function checkForm(theForm) {
    var why = "";
    why += checkEmail(theForm.email.value);
    why += checkPhone(theForm.phone.value);
    why += checkBusiness(theForm.company.value);
    why += checkName(theForm.name.value);
    why += checkAddress(theForm.address.value);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}


function checkName (strng) {
 var error = "";
 if (strng == "") {
    error = "You didn't enter a name.\n";
	}
var illegalChars = /\W\s/;
  // allow only letters, numbers, and underscores
    if (illegalChars.test(strng)) {
       error = "The name contains illegal characters.\n";
    }
return error;
 }


function checkAddress (strng) {
 var error = "";
 if (strng == "") {
    error = "You didn't enter an address.\n";
	}
var illegalChars = /\W\s/;
  // allow only letters, numbers, and underscores
    if (illegalChars.test(strng)) {
       error = "The address contains illegal characters.\n";
    }
return error;
 }


function checkBusiness (strng) {
 var error = "";
 if (strng == "") {
    error = "You didn't enter a business.\n";
	}
var illegalChars = /\W\s/;
  // allow only letters, numbers, and underscores
    if (illegalChars.test(strng)) {
       error = "The business contains illegal characters.\n";
    }
return error;
 }


function checkEmail (strng) {
 var error = "";
 if (strng == "") {
    error = "You didn't enter an email address.\n";
	}
var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
if (strng.match(illegalChars)) {
   error = "The email address contains illegal characters.\n";

    }
return error;
}

function checkPhone (strng) {
 var error = "";
 if (strng == "") {
    error = "You didn't enter a phone number.\n";
	}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
   error = "The phone number contains illegal characters.\n";
    }
if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    }
return error;
}
                       



                        function currencyPad(anynum,width) {
                                //returns number as string in $xxx,xxx.xx format.
                                anynum = "" + eval(anynum)
                                //evaluate (in case an expression sent)
                                intnum=0
                                if (anynum >= 1) {
                                         intnum = parseInt(anynum)
                                }    
                                //isolate integer portion
                                intstr = ""+intnum
                                //add comma in thousands place.
                                if (intnum >= 1000) {
                                        intlen = intstr.length
                                        temp1=parseInt(""+(intnum/1000))
                                        temp2=intstr.substring(intlen-3,intlen)
                                        intstr = temp1+","+temp2
                                }
                                if (intnum >= 1000000) {
                                        intlen = intstr.length
                                        temp1=parseInt(""+(intnum/1000000))
                                        temp2=intstr.substring(intlen-7,intlen)
                                        intstr = temp1+","+temp2        
                                }
                                decnum = Math.abs(parseFloat(anynum)-intnum) //isolate decimal portion
                                decnum = decnum * 100 // multiply decimal portion by 100.
                                decstr = "" + Math.abs(Math.round(decnum))
                                while (decstr.length < 2) {
                                       
					decstr = "0"+decstr
                                }
                                retval = intstr + "." + decstr
                                if (intnum < 0) {
                                        retval=retval.substring(1,retval.length)
                                        retval="("+retval+")"        
                                }       
                                retval = "$"+retval
                                while (retval.length < width){
                                        retval=" "+retval
                                }
                                return retval
                        }

