function cleanname(arg){
	while(arg.value.match(/^\s/)){	//remove leading spaces
		arg.value = arg.value.substr(1);
	}
	while(arg.value.charAt(arg.value.length-1) == " "){	//remove trailing spaces
		arg.value = arg.value.substr(0,arg.value.length-1);
	}
	arg.value = arg.value.toProperCase();	//fix the word case
}

String.prototype.toProperCase = function()
{
  return this.replace(/^(.)|\s(.)/g, function($1) { return $1.toUpperCase(); });
}

function testnames(arg1, arg2){
	if(document.getElementById(arg1).value == "" || document.getElementById(arg2).value == "" ){
	alert("Please enter First and Last Name.");
	}
}

function check()
{
var letters = document.jogform.night_phone_a.value.length +1;
if (letters <= 3)
{document.jogform.night_phone_a.focus()}
else
{document.jogform.night_phone_b.focus()}
}

function check2()
{
var letters = document.jogform.night_phone_b.value.length +1;
if (letters <= 3)
{document.jogform.night_phone_b.focus()}
else
{document.jogform.night_phone_c.focus()}
}

function check3()
{
var letters = document.jogform.night_phone_c.value.length +1;
if (letters <= 4)
{document.jogform.night_phone_c.focus()}
else
{
document.jogform.email.focus()}
}

function cleanup() {

document.jogform.first_name.value=document.jogform.sponsorfirst.value
document.jogform.last_name.value=document.jogform.sponsorlast.value
document.jogform.address1.value=document.jogform.street.value
var onePhone = document.jogform.night_phone_a.value + "-" + document.jogform.night_phone_b.value + "-" + document.jogform.night_phone_c.value;
document.jogform.address2.value = onePhone;
document.jogform.phone.value = onePhone;

document.jogform.amount.value=document.jogform.amount.value.replace(",", "");   //remove a comma
document.jogform.amount.value=document.jogform.amount.value.replace(",", "");   //remove a commas 2x
// document.jogform.amount.value=parseFloat(document.jogform.amount.value.replace(",", ""));   //remove a commas 2x
document.jogform.total.value=document.jogform.total.value.replace(",", "");   //remove a comma
document.jogform.total.value=document.jogform.total.value.replace(",", "");   //remove a commas 2x

   var params = "?" + "first_name=" + document.jogform.sponsorfirst.value + "&last_name=" + document.jogform.sponsorlast.value;
   var params2 = "&address1=" + document.jogform.street.value + "&city=" + document.jogform.city.value + "&state=" + document.jogform.state.value;
   var params3 = "&zip=" + document.jogform.zip.value + "&email=" + document.jogform.email.value + "&item_number=" + document.jogform.item_number.value;
   var params4 = "&night_phone_a=" + document.jogform.night_phone_a.value + "&night_phone_b=" + document.jogform.night_phone_b.value + "&night_phone_c=" + document.jogform.night_phone_c.value + "&total=" + document.jogform.total.value

//paramhdr  endr and 6 through 10 are added to allow pledge and pay simultaneously by passing the pledge params through PayPal. 
//unfortunately, PayPal limits comment length so only truncated pledge info is provided. All info is in confirming email but not auto insertable.

   var paramhdr = document.jogform.salute.value + ";" + document.jogform.sponsorfirst.value + ";" + document.jogform.middle.value + ";" + document.jogform.sponsorlast.value + ";" + document.jogform.street.value + ";" + document.jogform.city.value + ";" + document.jogform.state.value + ";" + document.jogform.zip.value + ";" + document.jogform.phone.value + ";" + document.jogform.email.value + ";" ;

   var runner1 = ""; var runner2 = ""; var runner3 = ""; var runner4 = ""; var runner5 = ""; 

   var paramhdr = ";repeat;;;;;;;;;" ;

   var paramendr = document.jogform.textarea.value ;

//ignore above hdr and endr and keep it short to skirt PayPal comment limit

   var paramhdr = "" ;

   var paramendr = "" ;

if(document.jogform.runnerfirst.value != ""){
   var params6 = "\n" + paramhdr + document.jogform.runnerfirst.value + ";" + document.jogform.runnerlast.value + ";" + document.jogform.pledge1.value + ";;;" + document.jogform.amount.value + ";" + paramendr ;
   runner1 = "&runner1=" + document.jogform.runnerfirst.value + "_" + document.jogform.runnerlast.value;
} else {var params6 = "";}

if(document.jogform.runnerfirst2.value != ""){
   var params7 = "\n" + paramhdr + document.jogform.runnerfirst2.value + ";" + document.jogform.runnerlast2.value + ";" + document.jogform.pledge2.value + ";;;" + document.jogform.amount2.value + ";" + paramendr ;
   runner2 = "&runner2=" + document.jogform.runnerfirst2.value + "_" + document.jogform.runnerlast2.value;
} else {var params7 = "";}

if(document.jogform.runnerfirst3.value != ""){
   var params8 = "\n" + paramhdr + document.jogform.runnerfirst3.value + ";" + document.jogform.runnerlast3.value + ";" + document.jogform.pledge3.value + ";;;" + document.jogform.amount3.value + ";" + paramendr ;
   runner3 = "&runner3=" + document.jogform.runnerfirst3.value + "_" + document.jogform.runnerlast3.value;
} else {var params8 = "";}

if(document.jogform.runnerfirst4.value != ""){
   var params9 = "\n" + paramhdr + document.jogform.runnerfirst4.value + ";" + document.jogform.runnerlast4.value + ";" + document.jogform.pledge4.value + ";;;" + document.jogform.amount4.value + ";" + paramendr ;
   runner4 = "&runner4=" + document.jogform.runnerfirst4.value + "_" + document.jogform.runnerlast4.value;
} else {var params9 = "";}

if(document.jogform.runnerfirst5.value != ""){
   var params10 = "\n" + paramhdr + document.jogform.runnerfirst5.value + ";" + document.jogform.runnerlast5.value + ";" + document.jogform.pledge5.value + ";;;" + document.jogform.amount5.value + ";" + paramendr ;
   runner5 = "&runner5=" + document.jogform.runnerfirst5.value + "_" + document.jogform.runnerlast5.value;
} else {var params10 = "";}

   document.jogform.custom.value=document.jogform.textarea.value;
//change custom.value to pass through PayPal comment
   document.jogform.custom.value = document.jogform.custom.value + "  " + params6 + params7 + params8 + params9 + params10;
   var params5 = "&custom=" + document.jogform.custom.value;

if (document.jogform.hop.value == 1) {
    //if (document.jogform.textarea.value != ""){
        //document.jogform.method="get";
        //document.jogform.action="donate.html" + params + params2 + params3 + params4 + params5;
       //} else {document.jogform.method="get"; //document.jogform.action="donate.html" + params + params2 + params3 + params4;
        //newURL="donate.html" + params + params2 + params3 + params4 + params5;
        newURL="donate.html" + params + params2 + params3 + params4 + runner1 + runner2 + runner3 + runner4 + runner5 + params5;
	 //}
newwindow = window.open(newURL, "donateWindow");

   } else { 
//dp document.jogform.method="post"; 
//dp document.jogform.action="http://www.csarlington.org/formmail_1d92-JM.pl";
}
//      document.jogform.action="http://www.csarlington.org/Cov-OnlinePayThanks-PP.pl"; //for test only
//      document.jogform.action="mailto:webmaster@covmin.org"; //for test only

}



function paynow(ccrd) {
   
   if (document.jogform.laps.checked ) { document.jogform.hop.value=1; document.jogform.total.focus();
//   if ( ccrd == "creditcard" ) { document.jogform.hop.value=1;
   } else {document.jogform.hop.value=0; document.jogform.total.value="";}
}


function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
nameVal[0] = nameVal[0].replace("amp;", "");      // dp added to strip amp; from name
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}


function Mail(box) {
   domain="csarlington.org";
   document.write("<a href=\"mailto:"+box+"@"+domain+"?subject=Jog-a-thon Inquiry"+"\">"+box+"@"+domain+"</a>"); }


