function Subject () {
    this.value = "";
	this.observers = new Array();
	this.registerObserver = function(observer){
		this.observers.push(observer);
	}
	this.removeObserver = function(observer){
		for(var i=0; i < this.observers.length; i++){
			if(this.observers[i] === observer){
				this.observers.splice(i, 1);
			}
		}
	}
    this.setValue = function(value){
        this.value = value;
        this.notifyObservers();
    }
    this.notifyObservers  = function(){
		for(var i=0; i < this.observers.length; i++){
            this.observers[i].update(this.value);
    	}
    }
}
 
function Observer1 (subject){
    subject.registerObserver(this);
    this.update = function(value){
        document.write("I'm observer 1 and subject value is "+value+"<br>\n");
    }
} 
 
function Observer2 (subject){
    subject.registerObserver(this);
    this.update = function(value){
    	document.write("I'm observer 2 and subject value is "+value+"<br>\n");
    }
}
