/**
 * @author sksizer
 */
function makeAjaxRequest(formData, jqForm, options) {
	formData.push( { name: 'format' , value: 'ajax' } )
	var form_id = options['form_id']
	formData.push( { name: 'form_id' , value: form_id })
	if (LiveValidation.massValidate(options['validations']))
	{
		var len = options['validations'].length
		for (var i = 0;i<len;i++) {
			options['validations'][i].destroy();
		}
		return(true)
	} else {
		return( false )
	}
}

function createRemoteForm( form_id , validations ) {
	var options = {
		target: 'testy',
		beforeSubmit: makeAjaxRequest,
		dataType: 'script',
		form_id: form_id,
		validations: validations
    }; 
	jQuery('#'+form_id).ajaxForm(options);
}

function navigateTo(tabID) {
	var flash = jQuery('#flash:visible');
	if (flash.length > 0)
	{
		jQuery('#flash').fadeOut(500,function() {
			emptyFlash();
			showPage(tabID);
		});	
	}
	else
	{
		showPage(tabID);
	}
}

function showPage( tabID )
{
	var callbackrun = false
	jQuery(tabID).hide(0);
	jQuery('.tab:not('+tabID+')').fadeOut(500 , function() {
		if (callbackrun) {
			jQuery(tabID).fadeIn(500);
		} else {
			callbackrun = true;
		}
	})
	return( false );
}

function emptyFlash() {
	jQuery('#flash').empty();
}
