function CMqWebPart(){

	function GetHTML_ListContainer(strListTitle, strListBulletImagePath, arrListInfo)
	{
		var strHTML="";
		var HEADER_HEIGHT="27";
		var objContentLinks=new CMqContentLinks();
		var strLinksList = objContentLinks.GetLinksList(arrListInfo, strListBulletImagePath);
		
		if(strLinksList.length>0){
			strHTML+="<div class='ListContainer'>";
			strHTML+="<div class='ContainerHeader'>";
			strHTML+="<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%'>";
			strHTML+="<tr>";
			strHTML+="<td colspan='3'>&#160;<\/td>";
			strHTML+="<\/tr>";
			strHTML+="<tr height='27'>";
			strHTML+="<td width='11'><div class='ListTitleLeft'><\/div><\/td>";
			strHTML+="<td class='ListTitleCenter' valign='middle' width='100%'>" + strListTitle + "<\/td>";
			strHTML+="<td width='11'><div class='ListTitleRight'><\/div><\/td>";
			strHTML+="<\/tr>";
			strHTML+="<\/table>";
			strHTML+="<\/div>";
			strHTML+="<div class='ListItemsContainer'>";		
			strHTML+=strLinksList;
			strHTML+="<\/div>";
			strHTML+="<\/div>";
		}		
		return strHTML;
	}
	this.GetHTML_ListContainer=GetHTML_ListContainer;


	function CMqContentLinks(){

		function GetLinksList(arrListInfo, strListBulletImagePath){

			var lngCount;										
			
			var strList="";
			
			if(arrListInfo){
				for (lngCount=0; lngCount<arrListInfo.length; lngCount++){
				
					strList+=GetRowInList(arrListInfo[lngCount], strListBulletImagePath);
				}
			}

			if (strList.length>0){
				strList="<table class='ListItems' height='100%' width='100%'>" + strList + "<\/table>";
			}
			return strList;
		}
		this.GetLinksList=GetLinksList;

		//private	
		function GetRowInList(arrListItem, strListBulletImagePath)
		{
			var LIST_ITEM_ONCLICK=0;
			var LIST_ITEM_NAME=1;
			var LIST_ITEM_TOOLTIP=2;
			var LIST_ITEM_CODE_AFTER=3;
			
			var strHTML="";
			var strCodeAfter="";
			
			if(arrListItem){
				if(arrListItem[LIST_ITEM_NAME]){
					if(arrListItem[LIST_ITEM_NAME].length>0){
						strHTML+= "<tr><td align='right' valign='middle'><a href='#' onclick='";
						strHTML+= arrListItem[LIST_ITEM_ONCLICK];
						strHTML+= "'><img src='" + strListBulletImagePath + "' alt='";
						strHTML+= arrListItem[LIST_ITEM_TOOLTIP];
						strHTML+= "' border='0'><\/a><\/td><td valign='middle'><a href='#' onclick='";
						strHTML+= arrListItem[LIST_ITEM_ONCLICK] + "' class='ListItems-Link'>";
						strHTML+= arrListItem[LIST_ITEM_NAME] + "<\/a><\/td><\/tr>";
						
						if(arrListItem[LIST_ITEM_CODE_AFTER]){
							strCodeAfter=arrListItem[LIST_ITEM_CODE_AFTER];
							if(strCodeAfter.length>0){
								strHTML+= "<tr><td colspan='2'>" + strCodeAfter + "<\/td><\/tr>";
							}
						}
					}
				}
			}				
			return strHTML;
												
		}
	}
}  

function NumberRanges(  ) 
{
	var _me=this;
	
	// Array of number ranges, each one with lower and higher limits
	var _arrRanges=[];
	var PREFIX_CTL_NUM_RANGE_FROM ="NumRangeFrom_";
	
	function OnChange( currentFieldID)
	{
		// Value needs to be integer
		if (currentFieldID)
		{
			var intCurrentRange = _arrRanges.indexOf(currentFieldID);
		
			if (intCurrentRange>-1)
			{
				var valFromNextRange= g_VWS.RecordMgr().CurrentRecord().FldVals(currentFieldID).GetValue();
				
				if (!valFromNextRange)
				{
					valFromNextRange=0;
				}
				// Get the ID of the field for the next range
				var idFrom_NextRange = _arrRanges[intCurrentRange + 1];
				
				if (idFrom_NextRange)
				{
					// Set the lower limit of the next range
					var sNextRangeFromElement= PREFIX_CTL_NUM_RANGE_FROM + idFrom_NextRange;
				
					$('#' + sNextRangeFromElement).html( valFromNextRange);
				}
				
			}
		}
	}
	
	function AddRange( sRange, sFieldID)
	{
		if (sRange)
		{
			var iRange=parseInt(sRange);
		
			_arrRanges[ iRange]=sFieldID;
		}
	}
	
	function AddNextRange( sFieldID)
	{
		if (sFieldID)
		{
			_arrRanges.push(sFieldID);
		}
	}
	
	function OnAfterLoadRec() 
	{
		var l = _arrRanges.length;
		for (var i = 0; i < l; i++) 
		{
			// Call OnChange
			_me.OnChange( _arrRanges[i] );
			
		}		
	}
	
	this.AddRange =AddRange;
	this.AddNextRange =AddNextRange;
	this.OnChange = OnChange;
	this.OnAfterLoadRec = OnAfterLoadRec;
	this.Name="Number Ranges";
}


