function ValidateRegisterForm(theForm) {
	if(!ValidateVisaDate4Char(theForm.cardExp)) return (false);
	return (true);
}


function ValidateVisaDate4Char(theDate) {
	var tmpyear, d, m, y;
	var kMaxYearInFuture = 6;

	var kLongErrMsg = "Please enter a valid month and year in the \"Visa Exp (MMYY)\" field.  This MUST be 4 numbers. Preceed the month and year with zeros if necessary."
	d = "" + theDate.value; 
	m = d.substring(0, 2);
	y = d.substring(2, 4);


	if (d.length != 4){ /* make sure proper length */
		alert(kLongErrMsg);
		theDate.focus();
		return (false);
	}
			
	if (parseInt("1" + theDate.value).toString() != "1" + theDate.value) { /* make sure that all are numbers */
		alert(kLongErrMsg);
		theDate.focus();
		return (false);
	}
	
	
	
	var today, maxYear;
	today = new Date();
	/* maxYearTime = today.getTime(); */
	/* maxYearTime = ((60 * 1000 * 60 * 24) * 365) * kMaxYearInFuture; */
	/* maxYear.setTime(maxYearTime); */
	maxYear = new Date();
	maxYear.setFullYear(maxYear.getFullYear() + kMaxYearInFuture);
	
	tmpyear = 2000 + parseInt(y);
	/* alert("tmpyear: " + tmpyear + " " + maxYear.getYear() + "  " + today.getYear() + " " + today.getFullYear()); */
	if (tmpyear >= maxYear.getFullYear()) {
		alert("The Expiration Time is > 8 years in the future.");
		theDate.focus();
		return (false);
	}
	
	if ((m > 12) || (m == 0)) {
		alert("The Expiration Month is not valid.");
		theDate.focus();
		return (false);
	}
	
	var expireDate, expireTime;
	expireDate = new Date(tmpyear, m); // will show 1st day of NEXT month after
	expireTime = expireDate.getTime();
	expireTime -= (60 * 1000 * 60 * 24); // pub back 1 day
	expireDate.setTime(expireTime);
	if (today.getTime() > expireDate.getTime()) {
		alert("The Expiration Date has already passed.");
		theDate.focus();
		return false;
	}

	return(true);	
}


function FindControl(searchString) {
    var theForm = document.forms['aspnetForm'];
    if (!theForm) {
        theForm = document.aspnetForm;
    }

	var formElements = theForm.elements;
	for(var i=0;i<formElements.length;i++) {
		if(formElements[i].id.indexOf(searchString) > -1) {
			return formElements[i];
		}
	}
}

function copyShip() {
   var theForm = document.forms['aspnetForm'];
    if (!theForm) {
        theForm = document.aspnetForm;
    }

    if (theForm.shipSameAsOrgChk.checked) {
        FindControl("shipContact").value = FindControl("orgContact").value;
        FindControl("shipStreet").value = FindControl("orgStreet").value;
        FindControl("shipCity").value = FindControl("orgCity").value;
        FindControl("shipState").value = FindControl("orgState").value;
        FindControl("shipZip").value = FindControl("orgZip").value;
       }
}



function copyPay() {
    var theForm = document.forms['aspnetForm'];
    if (!theForm) {
        theForm = document.aspnetForm;
    }

    if (theForm.paySameAsShipChk.checked ) {
        FindControl("payStreet").value = FindControl("shipStreet").value;
        FindControl("payCity").value = FindControl("shipCity").value;
        FindControl("payState").value = FindControl("shipState").value;
        FindControl("payZip").value = FindControl("shipZip").value;
        }
}



function copyfirst() {
    var this_doc;
    this_doc = document.aspnetForm;

	this_doc.frm_first_name.value = this_doc.bill_to_first_name.value;
}
function copylast() {
    var this_doc;
    this_doc = document.regform;

	this_doc.frm_last_name.value = this_doc.bill_to_last_name.value;
}


