
function AjaxCall () {

    return {
	main_url: '/rpc.php',
	ok_hdl: null,
	err_hdl: null,

	getLoginWin: function() {
	    return this.callMethod('login',null);
	},

	getSignupForm: function() {
	    return this.callMethod('signupform',null);
	},


	signin: function(login,password){
	    return this.callMethod('signin',{login: login, password: password});
	},

	signinnopw: function(login,remember_me){
	    return this.callMethod('signinnopw',{login: login,remember_me: remember_me});
	},


	signupok: function(){
	    return this.callMethod('signupok',null);
	},

	signup: function(email,password,firstName,lastName,company,country,city,state,street,address2,zip,phone,bUpdateNotify,bThriveSubscribe,key_number){
	    return this.callMethod('signup',{email: email,password: password,firstName: firstName,lastName: lastName,
					company: company,country: country,city: city,state: state,street: street,address2: address2,
					zip: zip,phone: phone,bUpdateNotify: bUpdateNotify,bThriveSubscribe: bThriveSubscribe, 
					bAutoLogin: 1,key_number: key_number});
	},

	signupnopw: function(email,firstName,lastName,company,country,city,state,street,address2,zip,phone,bUpdateNotify,bThriveSubscribe,key_number){
	    return this.callMethod('signupnopw',{email: email,firstName: firstName,lastName: lastName,
					company: company,country: country,city: city,state: state,street: street,address2: address2,
					zip: zip,phone: phone,bUpdateNotify: bUpdateNotify,bThriveSubscribe: bThriveSubscribe, 
					bAutoLogin: 1,key_number: key_number});
	},


	setOkHdl: function(hdl){
	    this.ok_hdl = hdl;
	    return this;
	},

	setErrHdl: function(hdl){
	    this.err_hdl = hdl;
	    return this;
	},

	getContent: function(method,el,el_err,data,loading){

	    if(!el_err) el_err = el;

	    if(el)
    		this.setOkHdl(function(content){
		    dom = $(content);
		    if(loading){
			dom.appendTo(el);
			loading.remove();
		    }else{
			el.html("");
			dom.appendTo(el);
		    }
    		});

	    if(el_err)
    		this.setErrHdl(function(content){
        	    el_err.html(content);
    		});

	    this.callMethod(method,data);
	},

	callMethod: function(method,data){
	    var url = this.main_url + '?method=' + method;
	    var ok_hdl = this.ok_hdl;
	    var err_hdl = this.err_hdl;

	    $.ajax({
		type: "GET",
		url: url,
		dataType: "json", 
		data: data,
		cache: false,
		success: function (data, textStatus) {
		    if(ok_hdl && data.status == "ok"){
			ok_hdl(data.msg);
		    }
		    else if(err_hdl && data.status == "error"){
			err_hdl(data.msg);
		    }else if(err_hdl){
			err_hdl('Unknow answer type');
		    }
		},

		error: function(request, textStatus, errorThrown){
		    err_hdl(request.responseText);
		}

	    });
	}

    }
}