function selectDropDown(theDropDown,changeTo){
	document.getElementById(theDropDown).value = changeTo;
}
function selectRadio(theDropDown, theRadioButon){
	if(theDropDown.value != 2){
		document.getElementById(theRadioButon).checked = true;
	}
}

function updateFee(appFee){
	//get all the input fields
	tags = document.getElementsByTagName('input');	
	
	checkboxes	=	new Array();
	theChecked	=	new Array();
	
	//get all the checkboxes
	var inc = 0;
	for(i=0;i<tags.length;i++){
		if(tags[i].getAttribute('type') == 'checkbox' || tags[i].getAttribute('type') == 'radio'){
			checkboxes[inc++] = tags[i];			
		}
	}
	
	//see what checkboxes/radio buttons are actually selected
	//   yes, '.checked' works for radio buttons 
	inc = 0;
	for(i=0;i<checkboxes.length;i++){
		if(checkboxes[i].checked == true){
			theChecked[inc++] = checkboxes[i].value;			
		}
	}
	
	var fee = 0;
	for(i=0;i<theChecked.length;i++){
		fee += parseFloat(document.getElementById(theChecked[i]).value);
	}
	if (document.getElementById('discounts')){
	document.getElementById('discounts').value = parseFloat(fee);
	}
	if(document.getElementById('creditType')){
		values = document.getElementById('creditType').options[document.getElementById('creditType').selectedIndex].value.split(",");
		var convenienceFee = values[1];	
		if(convenienceFee){
			fee += parseFloat(convenienceFee);
		}
	}
	
	if(fee < 0){fee = 0;}
	if (document.getElementById("applicationFee")){
		document.getElementById("applicationFee").innerHTML = "<em>"+roundToPennies(document.getElementById('discounts').value)+"</em>"; //Application Fee with discounts if any.
		document.getElementById("charge2Card").innerHTML = "<em>"+roundToPennies(fee)+"</em>"; //Total charge to card.	
	}
	if(document.getElementById('appFee')){document.getElementById('appFee').innerHTML = fee;}
	if(document.getElementById('creditAmount')){document.getElementById('creditAmount').value = fee.toFixed(2);}
}
/** Convert an integer to a decimal **/
function roundToPennies(n)
{
 pennies = n * 100;

 pennies = Math.round(pennies);

 strPennies = "" + pennies;
 len = strPennies.length;

 return strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);
}

/** Open/Close with Effects **/
function openCloseExtra(divId,textId,openText,removeText) {			
	var delayLength = 0;
	if( $(divId).style.display == 'none'){
		new Effect.BlindDown($(divId),{duration:0.3,delay:delayLength});
		$(textId).innerHTML = removeText;
	}else{
		new Effect.BlindUp($(divId),{duration:0.3,delay:delayLength});
		$(textId).innerHTML = openText;
	}
}

/** Reservations - 
    Lease Payments uses updateFee() instead **/
function setConvenienceFee(feeAmount) {
	
	//check the length of the credit card type to make sure it is not 0 which is the first selection in the option box.
	var creditTypeLength = document.getElementById('creditType').options[document.getElementById('creditType').selectedIndex].value.length;
	if(document.getElementById('creditType') && creditTypeLength > 0){
		
		//Display the convenience notice
		document.getElementById("creditCardPaymentFee").style.display = "block";
		//the option's value is the type name and the fee separated by a comma, so split that up to use it
		values = document.getElementById('creditType').options[document.getElementById('creditType').selectedIndex].value.split(",");
		var convenienceFee = values[1];
		var cardname = values[0];
		if(convenienceFee){
			var fee = parseFloat(convenienceFee) + parseFloat(feeAmount);
		}else{
			var fee = parseFloat(feeAmount);
		}
		
		//Provide dollar formating
		var cardFee = fee;
		
		if (convenienceFee <= 0){
			convenienceFee = "00.00";
		}
		if (cardFee.toString().indexOf(".") == -1){
			cardFee += ".00";
		}
        
        //much easier than above.. but leaving it in just in case i missed something [cjm]
        convenienceFee = parseFloat(convenienceFee).toFixed(2);
        
		document.getElementById("conviFee").innerHTML = "<em>"+convenienceFee+"</em>"; //Charge for use of a credit card.
		document.getElementById("cardName").innerHTML = "<em>"+cardname+"</em>"; //Name of the card.
		if (document.getElementById("applicationFee")){
		document.getElementById("applicationFee").innerHTML = "<em>"+roundToPennies(feeAmount)+"</em>"; //Application Fee with discounts if any.
		}
		document.getElementById("charge2Card").innerHTML = "<em>"+parseFloat(cardFee).toFixed(2)+"</em>"; //Total charge to card.
		if(document.getElementById('creditAmount')){
			
		document.getElementById('creditAmount').value = parseFloat(fee).toFixed(2);} /* trac ticket 1232 */
	}
	else{ //Hide the convenience notice because the user selected the first item[0] "Credit Card"
		document.getElementById("creditCardPaymentFee").style.display = "none";
		if (feeAmount.toString().indexOf(".") == -1){
		document.getElementById('creditAmount').value =feeAmount+".00";
		}
	}
	return;	
}