
function CommandHistory() {
	this.ar=new Array();
	this.href="";
	
	this._spliter=";";
	
	this.save=function (command) {
		if (command.indexOf("#")>=0) {
			alert("'"+this._spliter+"' is special symbol and can not be used in command");
			throw new Exception("'"+this._spliter+"' is special symbol and can not be used in command");
			return;
		}
		this.ar.push(command);
		this._updateHref();
	}
	
	this.getCommands=function() {
		return this.ar;
	}				
	
	this.clear=function() {
		while(this.ar.length>0) this.ar.pop();
		this._updateHref();
	}
	
	this._updateHref= function() {
		var tmp=""
		for(var i=0; i<this.ar.length; i++) {
			tmp+=this.ar[i]+this._spliter;						
		}
		if (tmp.length>0) {
			tmp=tmp.substr(0, tmp.length-1);
			document.location.href=this.href+"#"+tmp;
		} else {
			document.location.href=this.href+"#none";
		}
		
	}
	
	this.parseHash=function(hash) {
		var ar=hash.split(this._spliter);
		var nar=new Array();
		for(var i=0; i<ar.length; i++) if (ar[i]!="none") nar.push(ar[i]);
		return nar;
	}
	
	
	var href=window.location.href;
	if (href.indexOf("#")>0) {
		var pos=href.indexOf("#");
		this.href=href.substr(0, pos);
		var hash=href.substr(pos+1);
		this.ar=this.parseHash(hash);
	}  else {
		this.href=href;
	}
}
