/*

REQUIRES:
/_js/var/path.js
/_js/data/numberdirectory.js (for write photo url, gtau())


CONSTRUCTOR ARGUMENTS
u = userId
m = memberId

VARS:
this.ack = anti-cach key

FUNCTIONS:
this.cfpj() = create project
this.rfav(t) = refresh avatar (type to re-show [t|s|m])
this.deav(t) = delete avatar (type to re-show after delete [t|s|m])
this.gtau(t,ac) = get avatar url(type [t|s|m|pht|phs|phm] ('ph*' for place holder), anti-cache[boolean])
this.depj() = delete project by checked items.  post to the confirm page
this.dewt() = delete watch list by checked items
this.cdpj() = commit project deletion
*/

function Member(u,m) {
var _PB = photoRootUrl;
this.ack = Math.random();
this.crpj = function() { window.location = '/'+u+'/projects/0/save/new'; }
this.rfav = function(t) {
	this.ack = Math.random();
	var img = new Image();
	img.src = this.gtau(t, true);
	ge('avatar').innerHTML = '';
	ge('avatar').appendChild(img);
}
this.deav = function(t) {
	if (!confirm('sure to DELETE your photo?')) { return; }
	deavgf = new GF('deavgf');
	deavgf.url = '/'+u+'/save/deleteavatar';
	deavgf.c();
	this.rfav('ph'+t);
}

this.gtau = function(t, ac) {
	var t = (t==null)?'s':t;
	var mstr = NumberDirectory.prototype.write(m);
	if (t.match(/^ph/)) { var u = _PB+'/ph/a'+t.substr(2,1)+'.gif'; }
	else { var u = _PB+'/u/'+mstr+'/a/'+t+'.jpg'; }
	return (ac)?u+='?'+this.ack:u;
}

this.depj = function() {
	var ai = gt(ge('pjls'), 'input');
	var ac = [] // array of checked projectid
	for (var ii=0;ii<ai.length;ii++){
		if(ai[ii].checked) {
			ac[ac.length]=ai[ii].value;
		}
	}
	if (ac.length>0) {
		var fm = ge('depj');
		fm.action = '/members/save/confirmdeleteproject/-/userId='+u;
		fm.method = 'post';
		fm.pjid.value = ac.join(',');
		fm.submit();
	}
}

this.dewt = function() {
	var ai = gt(ge('wtls'), 'input');
	var ac = [] // array of checked projectid
	for (var ii=0;ii<ai.length;ii++){
		if(ai[ii].checked) {
			ac[ac.length]=ai[ii].value;
			he('trw'+ai[ii].value);
		}
	}
	if (ac.length>0) {
		wtgf = new GF('wtgf');
		wtgf.url = '/members/save/unwatch/-/userId='+u+'&id='+ac.join(',');
		wtgf.c();
	}
}

this.poiv = function (num) {
	var winInv = window.open('/members/invoice/-/number='+num, 'winInv', 'width=800,height=550,status=yes,menubar=yes,toolbar=no,scrollbars=yes,resizable=yes');
	winInv.focus();
}

}