function RECORD_createHeader (showMeasurement, showVAT, additional, additionalSize)
{
	var output = "";
	
	output += "<table border=0 width=98% class=RECORD_TABLE cellpadding=1 cellspacing=1 id='recordList'>";
	output += "<tr>";
	output += "<th colspan=4 width='1%'>";
	// fake input to make row look same size as data rows
	output += "<input id='header' type=text style='visibility:hidden; width:1px' NAME='header'/>";
	output += "</th>";
	
	output += RECORD_createHeaderColumn ("header_code", "CODE");
	output += RECORD_createHeaderColumn ("header_name", "NAME");
	
	if (showVAT)
	{
		output += RECORD_createHeaderColumn ("header_price_without_vat", "PRICE");
		output += RECORD_createHeaderColumn ("header_price_with_vat", "PRICE_WITH_VAT");		
	}
	else
		output += RECORD_createHeaderColumn ("header_price", "PRICE");
	
	if (showMeasurement == "True")
	{
		output += "<th class=RECORD_TABLE_HEADER>";
		output += TRANSLATION_getValue ("header_measurement");
		output += "</th>";
	}
	
	if (additionalSize > 0)
	{
		var size =  additionalSize*10;
		output += "<th style='width:" + size + "px' class=RECORD_TABLE_HEADER >";
		output += additional;
		output += "</th>";		
	}
	
	output += "<th class=RECORD_TABLE_HEADER colspan=2 width='10%'>";
	output += TRANSLATION_getValue ("header_order");
	output += "</th></tr>";
	
	return output;
}

function RECORD_generateHeader (showMeasurement, showVAT, additional, additionalSize)
{
	document.write (RECORD_createHeader (showMeasurement, showVAT, additional, additionalSize));	
}

function RECORD_list (offset, currency, i, showMeasurement, showVAT, additionalSize)
{
	document.write (RECORD_createList (offset, currency, i, showMeasurement, showVAT, additionalSize));
}

function RECORD_getSortIndex ()
{
    switch (group_sort)
	{
	    case "NAME": return 5; 
	    case "CODE": return 4; 
	    case "PRICE": 
	    case "PRICE_WITH_VAT":
	        return 6; 
	}
}

function RECORD_createList (offset, i, additionalSize)
{
	var recordListNode = document.getElementById("recordList");			
	var currencySuffix = ",- " + currency;

	if (offset < RECORD_count)
	{
		var selected = RECORD(offset);				
		var insertAt = RECORD_getListIndexAt(selected, currencySuffix);		
		
		var moveToRecord = getCookie("moveToRecord");		
		if (moveToRecord == null) moveToRecord = -1;
		
		var trNode = recordListNode.insertRow(insertAt);
		trNode.id = "recordLine";

		code_class = "RECORD_Code";
		noalt_class = "RECORD_NoAlt";
		other_class = "RECORD_OtherAlt";
		desc_class = "RECORD_Description";

		if (moveToRecord == selected.ID) 
		{
		    code_class+= "_Selected";
		    other_class+= "_Selected";
		    noalt_class+= "_Selected";
		}

		code_class+="TD";
		other_class+="TD";
		desc_class+="TD";

		// Picture icon		
		var pictureTd = CreateCell(trNode, "right", noalt_class);
		var pictureText = "<a name='aRecord" + selected.ID + "'>";
		
		if (selected.Picture.length > 0) 
		{			
			pictureText += "<img style='cursor: pointer' border=0 src='./images/camera.gif' alt='" + PictureAlt + "' ";			
			pictureText += "onClick='window.open (\"./images/" + selected.Picture + "\", \"\", \"" + selected.Picture_Args + "\");'>";						
		}
		else pictureText += "&nbsp";
		
		pictureTd.innerHTML = pictureText + "</a>";
		
		// Description icon
		var descrTd = CreateCell(trNode, "right", noalt_class);	
		if (selected.Description.length > 0) 
		{						
			descrTd.innerHTML = "<img id='desc_img_down_" + selected.ID + "' border=0 src='./images/down.gif' style='cursor: pointer' alt='" + DescriptionShowAlt + "' onClick='RECORD_DESCRIPTION_SWITCH (" + selected.ID + ", true)'>";
			descrTd.innerHTML += "<img id='desc_img_up_" + selected.ID + "' border=0 src='./images/up.gif' alt='" + DescriptionHideAlt + "' style='cursor: pointer; display: none' onClick='RECORD_DESCRIPTION_SWITCH (" + selected.ID + ", false)'></a>";
		}
		else descrTd.innerHTML = "&nbsp";
		
		// Check for flags ...
		flags = Number (selected.Flags);
		
		CreateCell(trNode, "right", noalt_class).innerHTML = (flags & RECORD_FLAG_Action) == RECORD_FLAG_Action ?
				"<img border=0 src='./images/action_flag.gif' alt='" + ActionAlt + "'></img>" : "&nbsp";
				
		CreateCell(trNode, "right", noalt_class).innerHTML = (flags & RECORD_FLAG_NewItem) == RECORD_FLAG_NewItem ?
				"<img border=0 src='./images/newitem_flag.gif' alt='" + NewItemAlt + "'></img>" : "&nbsp";		

		// Data
		
		//CreateEmptyCell(trNode, "10%", "right", code_class).innerHTML = "<a name='aRecord" + selected.ID + "'>&nbsp;" + selected.Code + "</a>";		
		CreateEmptyCell(trNode, "10%", "right", code_class).innerHTML = "<a name='aRecord" + selected.ID + "'>&nbsp;</a>" + selected.Code;		
		CreateCell(trNode, "left", other_class).innerHTML = selected.Name + "&nbsp";
		CreateEmptyCell(trNode, "15%", "right", other_class).innerHTML = format_Money (selected.Price) + currencySuffix;
		
		if (showVAT)
			CreateEmptyCell(trNode, "15%", "right", other_class).innerHTML = format_Money (selected.PriceWithVAT) + currencySuffix;
		
		if (showMeasurement == "True")
			CreateEmptyCell(trNode, "4%", "center", other_class).innerHTML = selected.Measurement;			
			
		// Additional data
		if (additionalSize != -1)
		{			
			var additionalData = "<input style='width:90%' maxlength=" + additionalSize + " id='input_data_" + selected.ID + "' type=text class=Input />";
			CreateCell(trNode, "center", other_class).innerHTML = additionalData;
		}
				
		// Order input & icon 
		CreateEmptyCell(trNode, "8%", "center", other_class).innerHTML = "<input id='input_" + selected.ID + "' type=text class=Input style='width: 80%' name=eCount value=1>";
		onClick_name = "onClick_bAdd (" + offset + "," + selected.ID + ");";

		CreateCell(trNode, "", other_class).innerHTML = "<img style='cursor: pointer' border=0 src='./images/prop.gif' alt='" + AddItemsAlt + "' onClick='" + onClick_name +"'></a>"

		// Description text
		if (selected.Description.length > 0)
		{
			var descriptionTr = recordListNode.insertRow(insertAt+1);
			descriptionTr.id = "desc_tr_" + selected.ID;
			descriptionTr.style.display = "none";
			
			CreateCell(descriptionTr).colSpan = 4;
			var description = CreateCell(descriptionTr, "", desc_class);
			description.colSpan = 6;
			description.id = "desc_td_" + selected.ID;
			description.setAttribute("valign", "top");
			description.style.visibility = "hidden";
			//description.setAttribute("style", "visibility: hidden");
			description.innerHTML = selected.Description;
		}		
	}
}

function RECORD_initHook()
{
	
}
