function newUser(){
	new Ajax.Updater('newUserActive','register.php',
	  {
		method:'post',
		parameters: $('newUserForm').serialize(true),
		evalScripts: true,
		onFailure: function(){ alert('Something went wrong...') }
	  });	
}

function userLogin(d){ 
	
	var updateDiv = d;
	
	new Ajax.Updater(updateDiv, 'login.php',
	  {
		method:'post',
		parameters:$('loginForm').serialize(true),
		onSuccess: function(transport){
			if (transport.responseText.match(/Va rugam asteptati/)){
				window.location = "index.php";
			}
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });	
}










var Navigate = {
	
	ajax : function(zone, file, _action, show_menu){
		new Ajax.Updater(zone, file + '.php',
		  {
			method:'post',
			parameters: {action: _action},
			evalScripts: true,
			onSuccess: function(transport){
			  $('head-menu-tabs').hide();
			},
			onFailure: function(){ alert('Something went wrong...') }
		  });	
	},
	
	menu_page_edit : function(_status){
		new Ajax.Updater('head-menu-top-pageEdit', 'do.php',
		  {
			method:'post',
			parameters: {action: 'menuPageEdit',status: _status},
			onFailure: function(){ alert('Something went wrong...') }
		  });	
	} 

}

// userLogin()

// loginRecover()
function loginRecover(){ 

	params = {action: 'doLoginRecover', e: $('uEmail').value};

	new Ajax.Updater('loginRecover', 'login.php',
	  {
		method:'post',
		parameters: params,
		onSuccess: function(transport){
			if (!transport.responseText.match(/Utilizator\/Parola gresite/)){
				//window.location = "index.php";
			}
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });	
}

// loginProblem()
function loginProblem(){ 
	params = {action: 'doLoginProblem', e: $('uEmail').value};

	new Ajax.Updater('loginProblem', 'login.php',
	  {
		method:'post',
		parameters: params,
		onSuccess: function(transport){
			if (!transport.responseText.match(/Utilizator\/Parola gresite/)){
				//window.location = "index.php";
			}
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });	
}


function formHintBox(e, text){
	var div = $('formHintBox');
	
	var _left = Event.pointerX(e) + 20;
	var _top = Event.pointerY(e) + 20;
	
	div.innerHTML = text;
	
	div.setStyle({
	  left: _left+'px',
	  top: _top+'px',
	  display: 'block'
	});	
}

function userAcc(_action){
	
	var params = function _params(){};
	
	params = (_action == undefined) ? $('userAccForm').serialize(true) : {action: _action};
	
	new Ajax.Updater('userAcc','user.php',
	  {
		method:'post',
		parameters: params,
		evalScripts: true,
		onFailure: function(){ alert('Something went wrong...') }
	  });	
}

function comPublish(){
	
	Loading('comPublishPreview');

	new Ajax.Updater('comPublishPreview','com.php',
	  {
		method:'post',
		parameters: $('comPublishForm').serialize(true),
		evalScripts: true,
		onSuccess: function(transport){
			if (!transport.responseText.match(/<input style=\"/)){
				//$('comPublish').innerHTML = transport.responseText;
			}
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });	
}

function userAcc(t,d, p){

//	var params = $('userAccForm').serialize(true)
	var _d = d != undefined ? d : 'userAccActive';
	var params = p != undefined ? p : '';

	Loading(_d);

	new Ajax.Updater(_d,'user.php',
	  {
		method:'post',
		parameters: {action: 'userAcc_' + t, post: params},
		evalScripts: true,

		onFailure: function(){ alert('Something went wrong...') }
	  });	
}

function Loading(div, t){

	Element.insert($(div),{top: '<span class="loading">Se incarca...</span>'});

}

/**
*
* AJAX IFRAME METHOD (AIM)
* http://www.webtoolkit.info/
*
**/

AIM = {

    frame : function(c) {

        var n = 'f' + Math.floor(Math.random() * 99999);
        var d = document.createElement('DIV');
        d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
        document.body.appendChild(d);

        var i = document.getElementById(n);
        if (c && typeof(c.onComplete) == 'function') {
            i.onComplete = c.onComplete;
        }

        return n;
    },

    form : function(f, name) {
        f.setAttribute('target', name);
    },

    submit : function(f, c) {
        AIM.form(f, AIM.frame(c));
        if (c && typeof(c.onStart) == 'function') {
            return c.onStart();
        } else {
            return true;
        }
    },

    loaded : function(id) {
        var i = document.getElementById(id);
        if (i.contentDocument) {
            var d = i.contentDocument;
        } else if (i.contentWindow) {
            var d = i.contentWindow.document;
        } else {
            var d = window.frames[id].document;
        }
        if (d.location.href == "about:blank") {
            return;
        }

        if (typeof(i.onComplete) == 'function') {
            i.onComplete(d.body.innerHTML);
        }
    }

}

        function startCallback() {
            Loading('userAccActive');
            
            
        }

        function completeCallback(response) {
            $('userAccActive').innerHTML = response;
        }
		
		
		function mobilpay(f, t, s, d){
			new Ajax.Request('user.php', {
				parameters: { action: 'mobilpay', t: t, s: s, d: d},
				onComplete: function(transport){
					if (!transport.responseText.match(/ok/)) alert('Va rugam mai incercati o data!');
					else f.submit();
				},
				method: 'post'
			});
			
			return false;
		}