
function MyAuth() {
	this.data = {id:null,authType:null,name:""};
	this.getData();
}

MyAuth.prototype.logout = function (){
	deleteCookie ("auth");
	this.data = {id:null,authType:null,name:""};
}

MyAuth.prototype.getData=function(){
	try {
		var cookie = decodeURIComponent(getCookie ("auth"));
		var data = JSON.parse(cookie);
		this.data = data;	
	}catch(e){
	    this.logout();
	}
}

MyAuth.prototype.vkwLogin = function ( vkData, callback ) { //  got authData from the widget
	try {	
		this.data = { id:vkData.uid, authType:"vkw", name: vkData.first_name+" "+vkData.last_name, hash:vkData.hash, remember:vkData.remember };
		var param = JSON.stringify(this.data);
		var pass = encodeURIComponent(param);
//		setCookie("auth", param );	
		fb.ajax( {source:'/_php/vk_auth.php?auth='+ pass,cacheable:false, finish:callback });
	}catch(e){
	    this.logout();
	}
}


var myAuth = new MyAuth();


