function showFields(addressType,clearFieldsFl)
{
	
	var confirmFl = true;
	if(clearFieldsFl)
	{
		confirmFl = confirm("Changing address type will clear out any fields you may have already filled in. Are you sure you want to change your address type?");
	}
	
	if(confirmFl)
	{
		if(addressType=='P')
		{
			setVisibility('poboxFields','show');
			setVisibility('houseFields','hide');
			setVisibility('rrFields','hide');
			
			if(clearFieldsFl)
			{
				clearStreetFields();
				clearRRFields();
			}
		}
	
		if(addressType=='S')
		{
			setVisibility('poboxFields','hide');
			setVisibility('houseFields','show');
			setVisibility('rrFields','hide');
			
			if(clearFieldsFl)
			{
				clearPOBoxFields();
				clearRRFields();
			}
		}
	
		if(addressType=='B')
		{
			setVisibility('poboxFields','hide');
			setVisibility('houseFields','hide');
			setVisibility('rrFields','show');
			
			if(clearFieldsFl)
			{
				clearStreetFields();
				clearPOBoxFields();
			}
		}
	}
	
	
}

function showSelectedFields()
{
	var myForm;
	
	
	if(document.getElementById)
	{
		myForm = document.getElementById('stopForm');
		
	}
	
	else if (document.all)
	{
		myForm = document.all.stopForm;
		
	
	}
	
	if(!myForm)
	{
		if(document.getElementById)
		{
			myForm = document.getElementById('startForm');
		
		}
	
		else if (document.all)
		{
			myForm = document.all.startForm;
		}
	}
	
	if(myForm)
	{
		
		for (i=0; i<myForm.length; i++)
		{

			if(myForm[i].name == 'mailingAddress.streetNumberType')
			{
				
				if(myForm[i].checked)
				{
					
					showFields(myForm[i].value,false);
				
				}
			}
		
		}
	
	}

}


function setVisibility(divName,visType)
{
	var displayTxt; 
	var visibilityTxt;
	if(visType == 'show')
	{
			displayTxt = 'block';
			visibilityTxt = 'visible';
	}	
	
	if(visType == 'hide')
	{
			displayTxt = 'none';
			visibilityTxt = 'hidden';
	
	}
    if (document.getElementById)
	{
		document.getElementById(divName).style.display = displayTxt;
		document.getElementById(divName).style.visibility = visibilityTxt;
	}
	else if (document.all)
	{
		
		document.all.divName.style.display = displayTxt;
		document.all.divName.style.visibility = visibilityTxt;
	}
	

}

function clearStreetFields()
{
	
	if(document.getElementById)
	{
	document.getElementById('mailingAddress.streetPreDirectionCode').value="";
	
	document.getElementById('mailingAddress.streetPostDirectionCode').value="";
	document.getElementById('mailingAddress.apartmentNumber').value="";
	document.getElementById('mailingAddress.streetName').value="";
	document.getElementById('mailingAddress.streetSuffix').value="";
	document.getElementById('mailingAddress.houseNumber').value="";
	}
	
	else if(document.all)
	{
		document.all.mailingAddress.streetPreDirectionCode.value="";
		document.all.mailingAddress.streetPostDirectionCode.value="";
		document.all.mailingAddress.apartmentNumber.value="";
		document.all.mailingAddress.streetName.value="";
		document.all.mailingAddress.streetSuffix.value="";
		document.all.mailingAddress.houseNumber.value="";
	
	}
}

function clearRRFields()
{
	if(document.getElementById)
	{
		document.getElementById('mailingAddress.rrBoxNumber').value="";
		document.getElementById('mailingAddress.rrNumber').value="";
	}
	
	else if (document.all)
	{
		document.all.mailingAddress.rrBoxNumber.value="";
		document.all.mailingAddress.rrNumber.value="";

	}

}


function clearPOBoxFields()
{

	if(document.getElementById)
	{
		document.getElementById('mailingAddress.poBoxNumber').value="";
	}

	else if(document.all)
	{
		document.all.mailingAddress.poBoxNumber.value="";
	}

}


function addEvent(obj, evType, fn)
{ 
	 if (obj.addEventListener)
	 { 
   		obj.addEventListener(evType, fn, false); 
   		return true; 
 	} else if (obj.attachEvent){ 
   		var r = obj.attachEvent("on"+evType, fn); 
   		return r; 
 	} else { 
   		return false; 
 	} 
}
