function confirm_registration(jsonData){
    $('url_code').update(jsonData['shortly']);
    Modalbox.show($('modal_reg_thx'), {title: 'Thanks for Registering!', width: 600}); 
    aObj.removeScriptTag();
}

function sendBalloon(form_name){
    f = document.getElementById(form_name);
    e = f.getInputs('text');
    reg = "http://www.redballoonrace.com/d/submit?" + e.serialize();
    
    // Create a new request object                                                                                                                                                                                                   
    aObj = new JSONscriptRequest(reg);
    // Build the dynamic script tag                                                                                                                                                                                                  
    aObj.buildScriptTag();
    // Add the script tag to the page                                                                                                                                                                                                
    aObj.addScriptTag();
}

function giveThanks(){
    alert("Thanks for your submission!");
    aObj.removeScriptTag();    
}

function doSubmit(){
    f = document.getElementById("submit_form");
    e = f.getInputs('text');
    b_submit = false;
	
	// Check that fields aren't empty and clear out empty ones.
	e.each(function(item){
		if(!(item.hasClassName('active_input'))){
		    item.value = ''}
		if(item.value){
		    b_submit = true;}
	    })
	
	// If no fields open, raise the error.
	if(!(b_submit)){
	    document.getElementById('submit_error').style.display = 'inline';}

    // Check that all fields have been validated.
    e.each(function(item){
	    if(item.hasClassName('errored_input')){
		b_submit = false;
	    }})

	// If so, submit!
	if(b_submit){
	    var reg = "http://www.redballoonrace.com/d/register?" + f.serialize();

	    // Create a new request object
	    aObj = new JSONscriptRequest(reg); 
	    // Build the dynamic script tag
	    aObj.buildScriptTag(); 
	    // Add the script tag to the page
	    aObj.addScriptTag();
	    document.getElementById('submit_error').style.display = 'none';	    
	}}

function clearInput(input_id){
    var e = document.getElementById(input_id);
    if(!(e.hasClassName('active_input'))){
	e.addClassName('active_input')
	    e.style.color = 'black'
	    e.value = ''
	    }
}

function regCheck(input_id, error_id, regex){
    var filter = new RegExp(regex);
    var val= document.getElementById(input_id).value
	if(filter.test(val)){
	    document.getElementById(error_id).style.display = 'inline';
	    document.getElementById(input_id).addClassName('errored_input');}
	else{
	    document.getElementById(error_id).style.display = 'none';
	    document.getElementById(input_id).removeClassName('errored_input');}
}

function emailCheck(input_id, error_id, regex){
    var filter = new RegExp(regex);
    var val = document.getElementById(input_id).value;
    if(!(filter.test(val)) && (val.length > 0)){
	document.getElementById(error_id).style.display = 'inline';
	document.getElementById(input_id).addClassName('errored_input');}
    else{
	document.getElementById(error_id).style.display = 'none';
	document.getElementById(input_id).removeClassName('errored_input');}
}

