var $j = jQuery.noConflict();
$j(document).ready(function() {
							
	$j('#frmReg').submit(function() {
        var path = '/api/Registration.svc/UsrFormReg?apikey=0566e181-5b76-44e7-a41d-e556635d5dee';
        if ($j.query.toString().length > 0) { path = path + $j.query.toString().replace('?','&'); }
        $j(this).ajaxSubmit({ url: path, dataType: "json", success: reg_showResponse });
        return false;
    });

    $j('.error').hide();
    $j('#errorWrapper').hide();
    $j('#dialog').jqm();
});

function reg_showResponse(responseText, statusText) {
    if (responseText.PageRedirect != null && responseText.Success == 1)
        window.location.href = responseText.PageRedirect;

    $j('#errorWrapper').hide();
    $j('.error').hide();
    $j.each(responseText.Messages, function(i, msg) {
        $j('#errorWrapper').show();
        //See if error has already been added
        var err = $j('#error_' + msg.Id);
        if (err.length == 0) {$j('#errorWrapper').append(login_ErrorTemplate, msg);}
        else err.show();
    });

}
