function rebuildContainerRegister()
{
    $("#center_container").empty();
    var ajax_load = "<center><img src='images/ajax-loader.gif' alt='loading...' /></center>";
    var loadUrl = 'categorii.ajax.php';
    var data = {
        op:'rebuild_container'
    };
    var callbackFunction = function(){
        showRegistryForm();
    };
    $("#center_container").html(ajax_load).load(loadUrl,data,callbackFunction);
}
function showRegistryForm()
{
    $.ajax({
      url: "utilizatori.ajax.php?op=show",
      cache: false,
      success: function(html){
        $("#Searchresult").html(html);
      },
      complete: function(){
        $("#Pagination").hide();
        $("#child_categories").hide();
        $("#cat_title").empty().html('Înregistrare');
        reloadDatepicker();
        $.post(
        		"populare_orase.ajax.php",
        		{what:$('#judet').val(),cluj:1},
        		function(data){
        			$("#orase").html(data);
        			if ($('#judet').val() == JUD_CLUJ_ID){
        				$("#orase").val(ORAS_CLUJ_ID);
        			}
        		}
        );
      }
    });
}

function saveRegFrm()
{
	var username = $('#username').val();
	var parola = $('#password').val();
    var check_parola = $('#verify_password').val();
	var nume = $('#nume').val();
	var prenume = $('#prenume').val();
	var email = $('#email').val();
	var data_nasterii = $('#data_nasterii').val();
    var judet = $('#judet').val();
	var oras = $('#orase').val();
    var adresa = $('#adresa').val();
    var cartier = $('#cartier').val();
    var tel = $('#tel').val();
    var ocupatia = $('#ocupatia').val();
	if(username.length == 0)
	{
		show_error('Introduceti numele de utilizator.','error_profilulmeu');
		return false;
	} else if(parola.length == 0) {
		show_error('Introduceti parola.', 'error_profilulmeu');
		return false;
	}else if(parola != check_parola) {
		show_error('Parola de verificare nu corespundă cu parola.', 'error_profilulmeu');
		return false;            
        }else if(nume.length == 0) {
		show_error('Introduceti numele.', 'error_profilulmeu');
		return false;
	} else if (prenume.length == 0) {
		show_error('Introduceti prenumele', 'error_profilulmeu');
		return false;
	} else if (email.length == 0) {
		show_error('Introduceti e-mail-ul', 'error_profilulmeu');
		return false;
	} else if (!validEmail(email)) {
		show_error('Adresa de e-mail este invalida', 'error_profilulmeu');
		return false;
	} else if (data_nasterii.length == 0) {
		show_error('Introduceti data nasterii', 'error_profilulmeu');
		return false;
	} else if (!$('#fem').attr('checked') && !$('#masc').attr('checked')){
            show_error('Nu aţi selectat sexul.', 'error_profilulmeu');
            return false;
    } 
	if ($('#fem').attr('checked')){
            var sex = $('#fem').val();

    } else if($('#masc').attr('checked')){
            var sex = $('#masc').val();
    } 
	
	if (judet == 0) {
            show_error('Nu aţi selectat judetul.', 'error_profilulmeu');
            return false;
    } else if (oras == 0) {
            show_error('Nu aţi selectat orasul.', 'error_profilulmeu');
            return false;
    }
        $.ajax({

        url: "utilizatori.ajax.php",
        method: 'post',
        data: ({
            op: 'save',
            username: username,
            parola: parola,
            nume: nume,
            prenume: prenume,
            email: email,
            sex: sex,
            judet: judet,
            oras: oras,
            adresa: adresa,
            cartier: cartier,
            tel: tel,
            ocupatia: ocupatia,
            txt_data_nastere: data_nasterii,
            subscribe: 0,
            PHPSESSID: '<?=session_id() ?>'

        }),
        complete: function(msg)
        {
            var r = msg.responseText;
            if(r.substr(0,2) == "ok")
            {
                fadeout('.error_profilulmeu');
                $("#registrationForm").empty();
                show_message('Contul a fost creat cu succes.','success_profilulmeu');
                window.setTimeout('document.location = "index.php"', 2000);
            } else if (r.substr(0, 5) == "error") {
                // numele nu este unic
                show_error('Exista deja un utilizator cu acest nume de utilizator', 'error_profilulmeu');
                $('#username').focus();
                $('#username').keypress(function(){
                    if($('.error_profilulmeu').css('display') != 'none') fadeout('.error_profilulmeu');
                    $('#username').keypress(function(){ });
                });
            }  else {
                show_error(r, 'error_profilulmeu');
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown)
        {
            show_error('Am intalnit o eroare. Incercati mai tarziu.', 'error_profilulmeu');
            return false;
        }
    });

    return false;

	    
}

function validEmail(email)
{
    invalidChars = " /:,;"

    if (email == "") {						// camp obligatoriu de completat
        return false
    }
    for (i=0; i<invalidChars.length; i++) {	// contine caractere invalide
        badChar = invalidChars.charAt(i)
        if (email.indexOf(badChar,0) > -1) {
            return false
        }
    }
    atPos = email.indexOf("@",1)			// tb sa existe simbolul "@"
    if (atPos == -1) {
        return false
    }
    if (email.indexOf("@",atPos+1) != -1) {	// un singur simbol "@"
        return false
    }
    periodPos = email.indexOf(".",atPos)
    if (periodPos == -1) {					// si cel putin un "." dupa "@"
        return false
    }
    if (periodPos+3 > email.length)	{		// cel putin 2 caractere dupa "."
        return false
    }
    return true
}