// JavaScript subroutines for DEALER_REG.PHP

// copies mailing address to billing address if checked, otherwise clears billing address entries
function handleSameAddrClick(theFormID) {
	var formObj=findObjId(theFormID);
	if (formObj) {
		if (formObj.cbaddrsame.checked) {
			copyAddr(theFormID);
		} else {
			formObj.cbaddr1.value = "";
			formObj.cbaddr2.value  = "";
			formObj.cbcity.value = "";
			formObj.cbstate.value = "";
			formObj.cbzip.value = "";
			formObj.cbcountry.value = "";
		}
	}
}


// copies the mailing address form values to the billing address values
function copyAddr(theFormID) {
	var formObj=findObjId(theFormID);
	if (formObj) {
		if (formObj.cbaddrsame.checked) {
			formObj.cbaddr1.value=formObj.cmaddr1.value;
			formObj.cbaddr2.value=formObj.cmaddr2.value;
			formObj.cbcity.value=formObj.cmcity.value;
			formObj.cbstate.value=formObj.cmstate.value;
			formObj.cbzip.value=formObj.cmzip.value;
			formObj.cbcountry.value=formObj.cmcountry.value;
		}
	}
}


// resets the billing-same-as-mailing checkbox if billing address field is changec to something different
function handleBillAddr(theFormID) {
	var formObj=findObjId(theFormID);
	if (formObj) {
		if (formObj.cbaddr1.value!=formObj.cmaddr1.value) formObj.cbaddrsame.checked=false;
		if (formObj.cbaddr2.value!=formObj.cmaddr2.value) formObj.cbaddrsame.checked=false;
		if (formObj.cbcity.value!=formObj.cmcity.value) formObj.cbaddrsame.checked=false;
		if (formObj.cbstate.value!=formObj.cmstate.value) formObj.cbaddrsame.checked=false;
		if (formObj.cbzip.value!=formObj.cmzip.value) formObj.cbaddrsame.checked=false;
		if (formObj.cbcountry.value!=formObj.cmcountry.value) formObj.cbaddrsame.checked=false;
	}
}


// requires the I-Agree checkbox on terms and conditions
function checkAgreement(theForm,errBlkID) {
	if (theForm.agree.checked) {
		theForm.submit();
		return true;
	}
	theForm.agree.focus();
	var theErr=findObjId(errBlkID);
	if (theErr) theErr.style.display='block';
	return false;
}


// makes magazine title drop down visible if magazine info source is selected
// Parms:	thisElem = the element from which this procedure is called
//			whichVal = the value of thisElem that is considered true, causing the drop down div to be visible
//			theDiv = the ID of the division tag within which the target drop down exists
//			theSelection = the ID of the targeted drop down. (resets to 0 if the div is made hidden)
//			theNewMag = the ID of the new magazine title (resets to 'add to list' if the div is made hidden)
function checkInfoSrc(thisElem,whichVal,theDiv,theSelection,theNewMag) {
	var theObj=findObjId(theDiv);
	if (theObj) {
		if (thisElem.value==whichVal) {
			theObj.style.visibility='visible';
		}
		if (thisElem.value!=whichVal) {
			theObj.style.visibility='hidden';
			theObj=findObjId(theSelection);
			if (theObj) theObj.value=0;
//			theObj=findObjId(theNewMag);
//			if (theObj) {
//				theObj.value="";
//				theObj.style.color="#666666";
//				theObj.style.fontStyle="italic";
//				theObj.value="add to list";
//			}
		}
	}
}


// handles the onfocus event for new magazine titles
//function prepNewMag(thisElem) {
//	if (thisElem.value=='add to list') thisElem.value='';
//	thisElem.style.color='#000000';
//	thisElem.style.fontStyle='normal';
//}


// inspects changes to the new magazine title field.
// if a new title is entered zero the magazine selection (in the drop down list)
// if the value is changed to null, reset the field to the default: 'add to list'
//function checkNewMag(thisElem,theSelection) {
//	if (thisElem.value=='') {
//		thisElem.value="";
//		thisElem.style.color="#666666";
//		thisElem.style.fontStyle="italic";
//		thisElem.value="add to list";
//	} else {
//		var theObj=findObjId(theSelection);
//		if (theObj) theObj.value=0;
//	}
//}
