function showCCForm(){
	document.getElementById("creditCardInfo").style.display = "block";
	document.getElementById("subForContent").style.display = "none";
	document.getElementById("cardNum").focus();
}

function showSubForContent(){
	document.getElementById("creditCardInfo").style.display = "none";
	document.getElementById("subForContent").style.display = "block";
	sendPageNameAndChannelToOmniture("Sub For Content", "Subscription");
}

function setPPIndex(){
	var pricePoints = document.getElementsByName("pricePoint");
	for (i=0; i<pricePoints.length; i++){
		if (pricePoints[i].type == 'hidden' || pricePoints[i].checked){
			document.getElementById("paypalLink").href += "&ppIndex=" + pricePoints[i].value;
		}
	}
}

//add onChange functions to pricePoint options and
//display the correct form section (to counteract browser using its cached page if a user hits 'back')
function initPaymentOptions(){
	//alert("initPaymentOptions, num options = "+numPaymentOptions);
	var pricePoints = document.getElementsByName("pricePoint");
	var checkedPP = -1;
	
	for (var i = 0; i < pricePoints.length; i++){
		pricePoints[i].onclick = selectPlan;
		
		if (pricePoints[i].checked){
			checkedPP = i;
		}
	}
	
	if (pricePoints && pricePoints.length > 1 && checkedPP >=0) {
		//pricePoints[checkedPP].onclick();
		selectPlan();
	}

}

function selectPlan() {
	//alert("selectPlan()");
		//	paymentOptions = document.getElementsByName("paymentOption");
		
		var pricePoints = document.getElementsByName("pricePoint");
		var checkedPP = -1;
		for (var i = 0; i < pricePoints.length; i++){
			if (pricePoints[i].checked){checkedPP = i;}
		}
		
		var checkedPP_radio = pricePoints[checkedPP];
		
		for (var i = 0; i < numPaymentOptions; i++){
			var option = document.getElementById("paymentOption"+i);
			option.className = "paymentOption";
		}
	
		var optionTD = "paymentOption";
		
		if (checkedPP_radio.id == "freePricePoint"){
			//showSubForContent();
			optionTD += numPaymentOptions-1;
		}else{
			//showCCForm();
			optionTD += checkedPP_radio.value;
		}
		//alert(optionTD);
		document.getElementById(optionTD).className = "checkedPaymentOption";
	//alert("highlighted selected plan");
		
	if (!hideForms){
		//alert("showing a form");
		document.getElementById("continueButton").style.display = "none";
		if (checkedPP_radio.id == "freePricePoint"){
			showSubForContent();
		}else{
			showCCForm();
		}
	}
}

function submitForm(form){

	properClickThrough=true;
		
	// Disabling submit buttons  must come after form.submit(). 
	// Don't know why! Form won't submit otherwise.
	
	var fName = form.name;
    document.forms[fName].submit();
   
	document.getElementById("submitCCForm").disabled = true;
	var submitSubForContForm = document.getElementById("submitSubForContForm");
	if (submitSubForContForm) {
		submitSubForContForm.disabled = true;
	}
}

function addInputSubmitEvent(form, input) {
    input.onkeydown = function(e) {
        e = e || window.event;
        if (e.keyCode == 13) { 
        	submitForm(form);
        }
    };
}

function trapEnterKey() {
    var forms = new Array();
    var numForms=0;
    
    if(document.getElementById('freeOptionForm')){
	    forms[numForms] = document.getElementById('freeOptionForm');
	    numForms++;
    }
    if(document.getElementById('subscriptionCreditCardForm')){
	    forms[numForms] = document.getElementById('subscriptionCreditCardForm');
    }
	
	//if(forms[0] && forms[1]) {
	    for (var i=0;i < forms.length;i++) {
	        var inputs = forms[i].getElementsByTagName('input');
	
	        for (var j=0;j < inputs.length;j++){
	            addInputSubmitEvent(forms[i], inputs[j]);
	        }
	    }
   // }
}

addEvent(window, 'load', trapEnterKey);
//addEvent(window, 'DOMContentLoaded', initPaymentOptions);