/**
 * @author 252715 ??
 */
/*Principal container contient */
var data;

function RealTimeObject()
{
	data = new MyHashtable();
	this.add = function(productId, imgControlId, bidControlId, bidImgControlId, bidValue, askControlId, askImgControlId, askValue,  variationControlId, variationImgControlId, variationValue, dateControlId)
	{
		if (data.containsKey(productId))
		{
			data.get(productId).add(productId, imgControlId, bidControlId, bidImgControlId, bidValue, askControlId, askImgControlId, askValue, variationControlId, variationImgControlId, variationValue, dateControlId);
		}
		else
		{
		    data.put(productId, new ProductObject());
			data.get(productId).add(productId, imgControlId, bidControlId, bidImgControlId, bidValue, askControlId, askImgControlId, askValue,  variationControlId, variationImgControlId, variationValue, dateControlId);
		  }
	};
	
	
              
	
	this.update = function()
	{
	    try
	    {
           var TabKeys = data.keys();
           var  http_request = getObject();
            if (!http_request) 
            {
                return false;
             }

           http_request.onreadystatechange = function()
	        {
                try
                {
                  if(http_request.readyState == 4 && http_request.status == 200)
                   {
                       var resultTab = http_request.responseText.split('|');
                       for (i = 0; i < resultTab.length; i++)
                       {
                            var tempTab = resultTab[i].split(';');
                            if (self['data'])
                            {
                                data.get(tempTab[0]).update(tempTab[1], tempTab[2], tempTab[3], tempTab[4]);
                             }
                       }
                       http_request = null;
                   }
               }
               catch (err)
               {
                    
               }

                  };
           http_request.open('POST', SitePath + 'XmlHttpRequest.aspx?GetProductValues=1', true);
           http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

            var stringToSend = '';
            var i =0;
            for (i = 0; i < TabKeys.length - 1; i++)
           {
                stringToSend += TabKeys[i]+',';
           }
           stringToSend +=TabKeys[i];
           TabKeys = null;
           var tosend = "form="+stringToSend;
           if (tosend)
           {
            http_request.send(tosend); 
           }
           tosend = null;

           }
           catch(ex)
           {
           
           }
	};

}

function ProductObject()
{
	this.productId = -1;
	this.bidValue = -1;
	this.askValue = -1;
	this.variationValue = -1;
	this.timeGenerate = new Date();
	this.productsCollection = new Array();
	this.cnt = 0;

	this.add = function(productId, imgControlId, bidControlId, bidImgControlId, bidValue, askControlId, askImgControlId, askValue,  variationControlId, variationImgControlId, variationValue, dateControlId)
	{
		
		if (this.productsCollection.length === 0)
		{
		    if (this.productId < 0)
		    {
			    this.productId = productId;
		    }
			if (bidValue)
			{
				this.bidValue = bidValue;
			}
			if (askValue)
			{
				this.askValue = askValue;
			}
			if (variationValue && variationValue != -1)
			{
				this.variationValue = variationValue;
			}
			this.productsCollection.push(new Product());
			this.productsCollection[this.productsCollection.length - 1].SetAll(imgControlId, bidControlId, bidImgControlId, askControlId, askImgControlId, variationControlId, variationImgControlId, dateControlId);
		}
		else{
			for (this.cnt = 0; this.cnt < this.productsCollection.length; this.cnt++)
			{
				if (bidValue)
				{
					if (!this.productsCollection[this.cnt].bidControlId && !this.productsCollection[this.cnt].bidImgControlID)
					{
						this.bidValue = bidValue;
						this.productsCollection[this.cnt].SetBid(bidControlId, bidImgControlId);
						break;
					}
				}
				else if (askValue && !this.productsCollection[this.cnt].askControlId && !this.productsCollection[this.cnt].askImgControlID)
				{
					this.askValue = askValue;
					this.productsCollection[this.cnt].SetAsk(askControlId, askImgControlId);
					break;
				}
				else if (variationValue && !this.productsCollection[this.cnt].variationControlId && !this.productsCollection[this.cnt].variationImgControlID)
				{
					this.variationValue = variationValue;
					this.productsCollection[this.cnt].SetVariation(variationControlId, variationImgControlId);
					break;
				}
				else if (imgControlId && !this.productsCollection[this.cnt].imgControlID)
				{
					this.productsCollection[this.cnt].SetImg(imgControlId);
					break;
				}
			}
			if (this.cnt ==  this.productsCollection.length)
			{
				this.productsCollection.push(new Product());
				this.productsCollection[this.productsCollection.length - 1].SetAll(imgControlId, bidControlId, bidImgControlId, askControlId, askImgControlId, variationControlId, variationImgControlId, dateControlId);
		}
		}
		
	};
	this.update = function(bidValue, askValue, variationValue, dateValue)
	{
		for (this.cnt = 0; this.cnt < this.productsCollection.length; this.cnt++)
		{
		    var tendance = 0;
		    if (bidValue > this.bidValue || askValue > this.askValue)
		    {
			    //this.productsCollection[this.cnt].updateAll(1, bidValue, askValue, variationValue);
			    tendance = 1;
			}
			if ((this.bidValue != -1 && bidValue != this.bidValue) || (this.askValue != -1 && askValue != this.askValue))
			{
		        this.productsCollection[this.cnt].updateAll(tendance, bidValue, askValue, variationValue, dateValue);
		    }
		    
		}
		if (bidValue != -1)
		    this.bidValue = bidValue;
		if (askValue != -1)
	        this.askValue = askValue;
	    if (variationValue != -1)
	        this.variationValue = variationValue;    
	//this.variationValue;
	};
}


function MakeItWhite()
{
    //var elementsTab = document.getElementsByName("Up");
    var elementsTab = getElementsById("Up");
    for (var i = 0; i< elementsTab.length; i++)
    {
        elementsTab[i].style.backgroundColor = "#FFFFFF";
        elementsTab[i].id = "blank";
    }
    elementsTab = null;
   // elementsTab = document.getElementsByName("Up");
    elementsTab = getElementsById("Down");
    for (var i = 0; i< elementsTab.length; i++)
    {
        elementsTab[i].style.backgroundColor = "#FFFFFF";
        elementsTab[i].id = "blank";
    }
   // node.style.backgroundColor = "#000000";
}

function Product()
{
    this.bidControlID;
	this.bidControl;
    this.askControlID;
	this.askControl;
	this.bidImgControlID;
	this.bidImgControl;
	this.askImgControlID;
	this.askImgControl;
	this.imgControlID;
	this.imgControl;
	this.variationControl;
	this.variationConrolID;
	this.variationImgControlID;
	this.variationImgControl;
	this.dateControl;
	this.dateControlId;
	this.refImgUp = PortalPath + "images/fleche_verte.gif";
	this.refImgDown = PortalPath + "images/fleche_rouge.gif";
	

	this.SetAll = function(imgControlId, bidControlId, bidImgControlId, askControlId, askImgControlId, variationControlId, variationImgControlId, dateControlId)
	{
		this.SetBid(bidControlId, bidImgControlId);
		this.SetAsk(askControlId, askImgControlId);
		this.SetImgControl(imgControlId);
		this.SetVariation(variationControlId, variationImgControlId);
		this.SetUpdateDate(dateControlId);
	};

	this.SetBid = function(bidControlId, bidImgControlId)
	{
		if (bidControlId)
		{
			this.bidControlID = bidControlId;
			this.bidControl = window.document.getElementById(bidControlId);
			
		}
		if (bidImgControlId)
		{
			this.bidImgControlID = bidImgControlId;
			this.bidImgControl = window.document.getElementById(bidImgControlId);
		}
	};

	this.SetAsk = function(askControlId, askImgControlId)
	{
		if (askControlId)
		{
			this.askControlID = askControlId;
			this.askControl = window.document.getElementById(askControlId);
		}
		if (askImgControlId)
		{
			this.askImgControlID = askImgControlId;
			this.askImgControl = window.document.getElementById(askImgControlId);
		}
	};
	
	this.SetVariation = function(variationControlId, variationImgControlId)
	{
		if(variationControlId)
		{
			this.variationConrolID = variationControlId;
			this.variationControl = window.document.getElementById(variationControlId);
		}
		if(variationImgControlId)
		{
			this.variationImgControl = variationImgControlId;
			this.variationImgControlID = window.document.getElementById(variationImgControlId);
		}
		
	};
	
	this.SetUpdateDate = function(dateControlId)
	{
		if(dateControlId)
		{
			this.dateControlId = dateControlId;
			this.dateControl = window.document.getElementById(dateControlId);
		}
	};

	this.SetImgControl = function(imgControlId)
	{
		if (imgControlId)
		{
			this.imgControlID = imgControlId;
			this.imgControl = window.document.getElementById(imgControlId);
		}
	};

	this.updateControlValue = function (tendance, bidValue, askValue, variationValue,dateValue) 
	{
		if (this.bidControl && bidValue)
		{
			this.bidControl.innerHTML = bidValue;
			if (tendance == 1)
			{ 
			    SetBackground(this.bidControl.parentNode.id, 'RealTimeContainerUp');
			     
			}
			else
			{
			    SetBackground(this.bidControl.parentNode.id, 'RealTimeContainerDown');
			 
			}
			window.setTimeout("SetBackground('"+ this.bidControl.parentNode.id+"', 'RealTimeContainer')", highlightTimer);
			
		}
		if (this.askControl && askValue)
		{
			this.askControl.innerHTML = askValue;
			if (tendance == 1)
			{
			    SetBackground(this.askControl.parentNode.id, 'RealTimeContainerUp');
			   
			}
			else
			{
			    SetBackground(this.askControl.parentNode.id, 'RealTimeContainerDown');
			}
			window.setTimeout("SetBackground('"+ this.askControl.parentNode.id+"', 'RealTimeContainer')", highlightTimer);
		}
		if (this.variationControl && variationValue != -1)
		{
			this.variationControl.innerHTML = variationValue;
			if (tendance == 1)
			{
			    SetBackground(this.variationControl.parentNode.id, 'RealTimeContainerUp');
			}
			else
			{
			    SetBackground(this.variationControl.parentNode.id, 'RealTimeContainerDown');
			 }
			 
			if (parseFloat(variationValue) > 0)
			    SetBackground(this.variationControl.id, 'RealVariation Pos');
            else if (parseFloat(variationValue) < 0)
			    SetBackground(this.variationControl.id, 'RealVariation Neg');
			else
			    SetBackground(this.variationControl.id, 'RealVariation');
			
			window.setTimeout("SetBackground('"+ this.variationControl.parentNode.id+"', 'RealTimeContainer')", highlightTimer);
		}
		if (this.dateControl)
		{
		    this.dateControl.innerHTML = dateValue;
			if (tendance == 1)
			{
			    SetBackground(this.dateControl.parentNode.id, 'RealTimeContainerUp');
			}
			else
			{
			    SetBackground(this.dateControl.parentNode.id, 'RealTimeContainerDown');
			 }
			window.setTimeout("SetBackground('"+ this.dateControl.parentNode.id+"', 'RealTimeContainer')", highlightTimer);
		}
	};
	
	this.updateImgControl = function (tendance)
	{
		if (this.imgControl)
		{
			if (tendance == 1)
			{
				this.imgControl.src = this.refImgUp;
			}
			else
			{
				this.imgControl.src = this.refImgDown;
			}
		}
		if (this.askImgControl)
		{
			if (tendance == 1)
			{
				this.askImgControl.src = this.refImgUp;
			}
			else
			{
				this.askImgControl.src = this.refImgDown;
			}
		}
		if (this.bidImgControl)
		{
			if (tendance == 1)
			{
				this.bidImgControl.src = this.refImgUp;
			}
			else
			{
				this.bidImgControl.src = this.refImgDown;
			}
		}
		if (this.variationImgControl)
		{
			if (tendance == 1)
			{
				this.variationImgControl.src = this.refImgUp;
			}
			else
			{
				this.variationImgControl.src = this.refImgDown;
			}
		}
	};
	
	this.updateAll = function(tendance, bidValue, askValue, variationValue, dateValue)
	{
		this.updateControlValue(tendance, bidValue, askValue, variationValue, dateValue);
		this.updateImgControl(tendance);
	};
}

/**
    Created by: Michael Synovic
    on: 01/12/2003
   
    This is a Javascript implementation of the Java Hashtable object.
   
    Contructor(s):
     Hashtable()
              Creates a new, empty hashtable
   
    Method(s):
     void clear()
              Clears this hashtable so that it contains no keys.
     boolean containsKey(String key)
              Tests if the specified object is a key in this hashtable.
     boolean containsValue(Object value)
              Returns true if this Hashtable maps one or more keys to this value.
     Object get(String key)
              Returns the value to which the specified key is mapped in this hashtable.
     boolean isEmpty()
              Tests if this hashtable maps no keys to values.
     Array keys()
              Returns an array of the keys in this hashtable.
     void put(String key, Object value)
              Maps the specified key to the specified value in this hashtable. A NullPointerException is thrown is the key or value is null.
     Object remove(String key)
              Removes the key (and its corresponding value) from this hashtable. Returns the value of the key that was removed
     int size()
              Returns the number of keys in this hashtable.
     String toString()
              Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters ", " (comma and space).
     Array values()
              Returns a array view of the values contained in this Hashtable.
           
*/

function MyHashtable(){
    this.clear = hashtable_clear;
    this.containsKey = hashtable_containsKey;
    this.containsValue = hashtable_containsValue;
    this.get = hashtable_get;
    this.isEmpty = hashtable_isEmpty;
    this.keys = hashtable_keys;
    this.put = hashtable_put;
    this.remove = hashtable_remove;
    this.size = hashtable_size;
    this.toString = hashtable_toString;
    this.values = hashtable_values;
    this.hashtable = new Array();
}

/*=======Private methods for internal use only========*/

function hashtable_clear(){
    this.hashtable = new Array();
}

function hashtable_containsKey(key){
    var exists = false;
    for (var i in this.hashtable) {
        if (i == key && this.hashtable[i] != null) {
            exists = true;
            break;
        }
    }
    return exists;
}

function hashtable_containsValue(value){
    var contains = false;
    if (value != null) {
        for (var i in this.hashtable) {
            if (this.hashtable[i] == value) {
                contains = true;
                break;
            }
        }
    }
    return contains;
}

function hashtable_get(key){
    return this.hashtable[key];
}

function hashtable_isEmpty(){
    return (parseInt(this.size()) == 0) ? true : false;
}

function hashtable_keys(){
    var keys = new Array();
    for (var i in this.hashtable) {
        if (typeof this.hashtable[i] == "function") 
		    continue;
        if (this.hashtable[i] != null)
            keys.push(i);
    }
    return keys;
}

function hashtable_put(key, value){
    if (key == null || value == null) {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }else{
        this.hashtable[key] = value;
    }
}

function hashtable_remove(key){
    var rtn = this.hashtable[key];
    this.hashtable[key] = null;
    return rtn;
}

function hashtable_size(){
    var size = 0;
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
            size ++;
    }
    return size;
}

function hashtable_toString(){
    var result = "";
    for (var i in this.hashtable)
    {     
        if (this.hashtable[i] != null)
            result += "{" + i + "},{" + this.hashtable[i] + "}\n";  
    }
    return result;
}

function hashtable_values(){
    var values = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null)
            values.push(this.hashtable[i]);
    }
    return values;
}




function getObject()//creates the XMLHttpRequest Object
{
   
    if (window.XMLHttpRequest)  // for Gecko Browsers
    { 
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) 
       {
            http_request.overrideMimeType('text/xml');
        }
     } 
    else if (window.ActiveXObject) 
     { // IE
       try 
       {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } 
        catch (e) 
          {
            try 
                    {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
                    }
            catch (e) 
            {
                    alert("could not create an XMLHttpRequest Object!");
            }
            }
        }
    return http_request;
    }
    
    
function getElementsById(sId)
 {
 var outArray = new Array();
 if(typeof(sId)!='string' || !sId)
 {
 return outArray;
 };

 if(document.evaluate)
 {
 var xpathString = "//*[@id='" + sId.toString() + "']"
 var xpathResult = document.evaluate(xpathString, document, null, 0, null);
 while ((outArray[outArray.length] = xpathResult.iterateNext())) { }
 outArray.pop();
 }
 else if(document.all)
 {
    var l;
    eval("l = document.all." + sId + ".length");
    for(var i=0,j=l;i<j;i+=1) {
        eval("outArray[i] = document.all." + sId + "[i]");
    }
 }
 else if(document.getElementsByTagName)
 {

 var aEl = document.getElementsByTagName( '*' );
 for(var i=0,j=aEl.length;i<j;i+=1){

 if(aEl[i].id == sId )
 {
 outArray.push(aEl[i]);
 };
 };

 };

 return outArray;
 }
 
 
 function SetBackground(objSpanId, className)
 {
    document.getElementById(objSpanId).className = className;
 }