$(document).ready(function(){

// prepare Options Object
var options = {
    target:     '#addcredit_error',
    url:        'https://www.bigmoneytrivia.com/includes/ajax/checkoutCredits.php',
    beforeSubmit: validate,
    success:    function(html) {
  //  alert(html);
    $("#TB_load").remove();
    $("#TB_overlay").remove();
    delayer(html);
        }
};
// pass options to ajaxForm
$('#addcredits').ajaxForm(options);
 });

     function validate(formData, jqForm, options) {
   //  alert('here');
     $("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
    $("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
    $("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
    $("#TB_load").show();
    $('#addcredit_error').empty();
    var answer = $("#addcredit_error");
         if (answer.is(':hidden')) {
         $('#addcredit_error').fadeIn();
         }
 //alert('hi'+content);
    // formData is an array of objects representing the name and value of each field
    // that will be sent to the server;  it takes the following form:
    //
    // [
    //     { name:  username, value: valueOfUsernameInput },
    //     { name:  password, value: valueOfPasswordInput }
    // ]
    //
    // To validate, we can examine the contents of this array to see if the
    // username and password fields have values.  If either value evaluates
    // to false then we return false from this method.
    for (var i=0; i < formData.length; i++) {
        if (!formData[i].value) {
            alert('Please enter a value for all fields');
            $("#TB_load").remove();
            $("#TB_overlay").remove();
            return false;
       }
    }
  }
function delayer(html){
var suc;
suc = html;
//alert(suc);
if( suc.indexOf("Success") > -1) {
//alert('hi going');
window.location = "https://www.bigmoneytrivia.com/cashier.php";
}
//else {
//alert('hi');
//$('#addcredit_error').fadeOut('slow');
//}
}