function ChEvent(){
	var id;
	var picture;
	var title;
	var entryType;
	var category;	
	var desc;
	var hour;
	var datetv;
}

function parseTag(id, tag, text){
	var t = "<" + tag + " id=\"" + id + "\">"
	var start = text.indexOf(t, 0)
	if(start<0){ 
		result = ""
	}else{
		var stop = text.indexOf("</" + tag + ">", start)
		var result = text.substring(start +t.length, stop)
		if(start>=stop || stop <= 0) result = ""
	}
	return result;
}

function parseImgTag(id, tag, text){
	var t = "<" + tag + " id=\"" + id + "\" src=\""
	var start = text.indexOf(t, 0)
	if(start<0){ 
		result = ""
	}else{		
		start = start + + t.length
		var stop = text.indexOf("\"", start )
		var result = text.substring(start, stop)
		if(start>=stop || stop <= 0) result = ""
	}
	return result;
}

function createXMLHttp() {

   if (typeof XMLHttpRequest != "undefined") {
       return new XMLHttpRequest();
   } else if (window.ActiveXObject) {
     var aVersions = [ "MSXML2.XMLHttp.5.0",
       "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
       "MSXML2.XMLHttp","Microsoft.XMLHttp"
     ];

     for (var i = 0; i < aVersions.length; i++) {
       try {
           var oXmlHttp = new ActiveXObject(aVersions[i]);
           return oXmlHttp;
       } catch (oError) {
           //Do nothing
       }
     }
   }
   throw new Error("XMLHttp object could be created.");
}

function ChEventMap(){
	var chEvent = [];
	var url = "/data/entryDescr?eid=";

	this.push = function( chE ){
		if( this.getById(chE.id) != null )
			this.pop( chE.id );
		chEvnet.push( cheE );
	}

	this.getById = function(id){
		//search local bufor
		for ( i = 0 ; i < chEvent.length ; i++ ){
			if ( chEvent[i].id == id ){
				return chEvent[i];
			}
		}
		var cur = this.getFromServer( id );
		chEvent.push( cur );
		
		return cur;
	}
	
	this.getFromServer = function(id){
		var chE = new ChEvent();
				
		var xmlHttp = createXMLHttp();
		xmlHttp.open("get", url + id, false);
		xmlHttp.send(null);

		
		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			
			chE.id = parseTag("id","div", response);
			chE.picture = parseImgTag("image","img", response);
			chE.title = parseTag("name","div", response);
			chE.entryType = parseTag("entry-type","div", response);
			chE.category = parseTag("category","div", response);
			chE.desc = parseTag("description","div", response);
			chE.hour = parseTag("hour","div", response);
			chE.datetv = parseTag("datetv","div", response);		
			
		}
		return chE;
	}
	
	this.pop = function( id ){
		for ( i = 0 ; i < chEvent.length ; i++ ){
			if ( chEvent[i].id == id )
				return chEvent.pop( chEvent[i] );
		}
	}
	
}

function BufChEventTooltip(  ){	
	var tooltips = new ChEventMap();

	this.getValue = function( id ){
		var tt = tooltips.getById( id );	
		return tt;
	}
}
