

var allUserContacts=new Object();

function pcngGetContact(contactId){
	return allUserContacts[contactId];
}

function pcngContact(contactId, preferredName, phone, email){
	this.contactId=contactId;
	this.preferredName=preferredName;
	this.email=email;
	this.phone=phone;
	this.nameListeners=new Array();
	
	allUserContacts[contactId]=this;
	
	this.getName=function(){
		return this.preferredName;
	}
	this.setName=function(name){
		this.preferredName=name;
		
		for(i=0;i<this.nameListeners.length;i++){
			if(this.nameListeners[i].onNameChange)
				this.nameListeners[i].onNameChange(this);
			else
				this.nameListeners[i].innerHTML=this.getName();
		}
	};
	
	this.setEmail=function(email){
		this.email=email;
	}
	
	this.registerNameListener=function(lis){
		this.nameListeners.push(lis);
	}
}


function saveQuickEditContact(node){
	if(!node.dirty)
		return;
	pcngContact=node.pcngContact;
	var url='/PC-NG-AA/phonebook/editContact.do?action=changeName&contactTrackingId='+pcngContact.contactId;
	url+='&'+node.name+'='+node.value;
	node.dirty=false;

	var ajaxHelper=new SimpleAjaxHelper(url);
	var callBackFunc=new function(){
		this.onSuccess=function(){
			displayGeneralMessage('Your contact has been saved');
			this.node.afterSave(this.origVal);
		};
	};
	callBackFunc.origVal=node.value;
	callBackFunc.node=node;
	ajaxHelper.get('', true, callBackFunc);
}
function setCurrentEditingContact(pcngContact){
	currentDisplayingContact=pcngContact;
}
