/* ********* DataList Fonctionnalities ************ */
/* ***************** Global *********************** */
var gstrMasterIdTag = "mstId" ;
var gstrRowLinkExtTag = "RowLinkExt" ;
var gstrSortLinkExtTag = "SortLinkExt" ;
var gstrOvOtColorTag = "OvOtColor" ;
var gstrPkysTag = "PKYS" ;
var gstrDataListSep = ";";
var gstrExtActionView = "_VIEW";
var gstrExtActionNav  = "_NAVI";

var gstrNavMvtNext = "NEXT";
var gstrNavMvtPrevious = "PREVIOUS";
var gstrNavMvtFirst = "FIRST";
var gstrNavMvtLast = "LAST"; 

var gDATALIST_TARGET 	= "__DT_TARGET";
var gDATALIST_ARGS 		= "__DT_ARGS";

/* ***************** Class ************************ */

function WebList(sender, uniqueID, overColor, extLink, cssOverColor, submitButton)
{
		
	this._uniqueID  = uniqueID	;
	this._overColor = overColor	;
	this._extLink   = extLink	;
	this._submitId  = submitButton ;
	
	if ( cssOverColor == null || cssOverColor == '')
	{
	}
	else
	{
		this._overCss = cssOverColor;
		this._overColor = '';
	}
		
	this._eventTarget   = null;
	this._eventArgument = null;
	this._form			= null;
	this._submitButton  = null;
	
	this._eventObjFinded = false;
	
	// Method mappings	
	this.OverOut		= WebList_OvOt		;
	this.Click			= WebList_Click		;
	this.Sort			= WebList_Sort		;
	this.View			= WebList_View		;
	
	this.Nav			= WebList_Nav			;
	this.Next			= WebList_NavNext		;
	this.Previous		= WebList_NavPrevious	;
	this.First			= WebList_NavFirst		;
	this.Last			= WebList_NavLast		;

	this.GetEventElements = WebList_GetEventElements;
	this.Request        = WebList_Request	;
	

}

function WebList_GetEventElements (sender, allElements)
{
	if ( ! this._eventObjFinded)
	{
		this._eventTarget 	= getDocument(sender).getElementById (gDATALIST_TARGET) ;
		this._eventArgument = getDocument(sender).getElementById (gDATALIST_ARGS) ;

		if ( this._eventTarget == null )
		{
			this._eventTarget 	= getDocument(sender).getElementById (EVENTTARGET) ;
		}
		if ( this._eventArgument == null )
		{
			this._eventArgument = getDocument(sender).getElementById (EVENTARGUMENT) ;
		}

		this._eventObjFinded    = !(this._eventTarget == null || this._eventArgument == null) ;
	}

	if ( allElements )
	{
		this._submitButton = null;
		if ( this._submitButton == null )
		{
			this._submitButton = getDocument(sender).getElementById (this._submitId);	
		}

		this._form 			= getDocument(sender).getElementById ("aspnetForm");
		if ( this._form == null )
		{
			this._form   	= getDocument(sender).getElementById ("Form1");	
		}
		
		this._eventObjFinded    = this._eventObjFinded && (this._submitButton != null || this._form != null);
	}
}

function WebList_Request ()
{
	if ( this._submitButton != null )
	{
		this._eventObjFinded = false;
		this._submitButton.click ();
	}
	else
	{
		this._eventObjFinded = false;
		this._form.submit();
	}	
}

function WebList_OvOt(sender, mode)
{
	
	if ( this._overColor == '' )
	{
		if ( mode == 1 )
		{
			// -> MouseOver
			sender.setAttribute ('dClass', sender.className) ;
			sender.className = this._overCss;
			
		}
		else
		{
			// -> MouseOut	
			sender.className = sender.getAttribute ('dClass') ; ;
		}
	}
	else
	{
		if ( mode == 1 )
		{
			// -> MouseOver
			sender.setAttribute ('dClr', sender.style.backgroundColor) ;
			sender.style.backgroundColor = this._overColor ;
		}
		else
		{
			// -> MouseOut	
			sender.style.backgroundColor = sender.getAttribute ('dClr') ; ;
		}
	}
}
function WebList_Click (sender, line)
{
	this.GetEventElements (sender, true);

	this._eventTarget.value 	= this._uniqueID + this._extLink ;
	
	if ( sender.getAttribute(gstrPkysTag) != null )
	{
		this._eventArgument.value 	= line + gstrDataListSep + sender.getAttribute(gstrPkysTag) ;
	}
	else
	{
		this._eventArgument.value 	= line + gstrDataListSep + sender.parentNode.getAttribute(gstrPkysTag);
	}
	
	this.Request ();
}

function WebList_Sort (sender, id)
{
	this.GetEventElements (sender, true);
	this._eventTarget.value = id ;
	
	this.Request ();
}
function WebList_View (sender, pk)
{
	this.GetEventElements (sender, true);
	this._eventTarget.value 	= this._uniqueID + gstrExtActionView ;
	this._eventArgument.value 	= pk ;
	
	this.Request ();
}
function WebList_Nav (sender, mvt)
{
	this.GetEventElements (sender, true);
	this._eventTarget.value 	= this._uniqueID + gstrExtActionNav ;
	this._eventArgument.value 	= mvt ;
	
	this.Request ();
}

function WebList_NavNext (sender, mvt)
{
	this.Nav(sender, gstrNavMvtNext);
}
function WebList_NavPrevious (sender, mvt)
{
	this.Nav(sender, gstrNavMvtPrevious);
}
function WebList_NavFirst (sender, mvt)
{
	this.Nav(sender, gstrNavMvtFirst);
}
function WebList_NavLast (sender, mvt)
{
	this.Nav(sender, gstrNavMvtLast);
}

