

function init_cms_controls(e){
	$$(".block").each(function(el){
		if(el.down('.edit_controls')){
			el.observe("mouseover", show_edit)
			el.observe("mouseout", hide_edit)			
		}
	})
}
function show_edit(e){
	if(e.down(".edit_controls")){
		e.down(".edit_controls").show()
	}
}
function hide_edit(e){
	if(e.down(".edit_controls")){
		e.down(".edit_controls").hide()
	}
}




function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function update_total_credit(el){

    amount = el.value;
    value = amount.replace("$","");
    value = value.replace(",","");

    if(value)
    {
       service_charge = .03 * parseFloat(value)
	   pt = parseFloat(value) + service_charge;
	   pt = pt.toFixed(2);
	}
	else
	{
	   pt=0;
	}
	
	pt = addCommas(pt);

	Element.update("payment_total","$"+pt);
	Element.update("charge_total","$"+pt);
	
	new Effect.Highlight("charge_total_row",{startcolor:"#768463",endcolor:"#ffffff",duration:2,restorecolor:"#ffffff"});
}

function update_total_echeck(el){

    amount = el.value;
    value = amount.replace("$","");
    value = value.replace(",","");

    if(value)
    {
       service_charge = .03 * parseFloat(value)
	   pt = parseFloat(value) +service_charge;
	   pt = pt.toFixed(2);
	}
	else
	{
	   pt=0;
	}
	
	pt = addCommas(pt);

	Element.update("payment_total_e","$"+pt);
	Element.update("charge_total_e","$"+pt);
	
	new Effect.Highlight("charge_total_row_e",{startcolor:"#768463",endcolor:"#ffffff",duration:2,restorecolor:"#ffffff"});
}

function monitor_form_input(id,type){
    if(type == 'echeck')
       new Form.Element.Observer(id, '0.25', update_total_echeck); 
    else if(type == 'recurring')
       new Form.Element.Observer(id, '0.25', update_total_recurring);  
    else
        new Form.Element.Observer(id, '0.25', update_total_credit);
}

function change_form(el){
    hide_all()
    Element.toggle(el.value)
}

function hide_all(){
    Element.hide('credit')
    Element.hide('echeck')
}

function show_help(payment_type){
    new Effect.toggle('check_div_'+payment_type)
}
function remove_help(payment_type){
    new Effect.DropOut('check_div_'+payment_type)
}



(function(){
	function show_nav_content(e){ 
		this.down('div').show();
	}
	function hide_nav_content(e){
		this.down('div').hide();
	}

	function setup_rollers(){
		$$('.rollcontrol').invoke('observe','mouseover', show_nav_content)
		$$('.rollcontrol').invoke('observe','mouseout', hide_nav_content, false)
	}
	
	//load everything once the dom is finished loading
	document.observe("dom:loaded", setup_rollers)
	
})()

