
<!--
/************************* TableView Object ********************************/
function TableView( bool_lineItemsHaveDeletion )
{
	// table view properties
	this.bool_lineItemsHaveDeletion = bool_lineItemsHaveDeletion;
	this.str_tableDef;
	this.str_cellDef;
	this.str_columnSeperator;
	this.int_colSpan;
	this.str_spanId;
	this.str_dividerClass;
	this.int_numEntries = 0;
	this.str_tableHeaderDef;
	this.str_validateProductText;
	this.formName;	
	this.bool_allowNonValidProducts = false;
	
	// Array of LineItem objects
	this.OA_lineItems = new Array();
}
TableView.prototype.deleteFromList = deleteFromList;
TableView.prototype.addToList = addToList;
TableView.prototype.addSKUs = addSKUs;
TableView.prototype.addNonValidSKUs = addNonValidSKUs;
TableView.prototype.getCommonValuesList = getCommonValuesList;
TableView.prototype.getAlternateValuesList = getAlternateValuesList;
TableView.prototype.toggleProductEntry = toggleProductEntry;
TableView.prototype.nonValidProductUpdate = nonValidProductUpdate;


function addSKUs( sku, qty, reason)
{
    this.OA_lineItems[this.OA_lineItems.length] = new LineItem();
    this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[0] = encodeJS(sku);
    this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[1] = qty;
    this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[2] = reason;
    this.OA_lineItems[this.OA_lineItems.length-1].bool_hasDeletion = ( this.bool_lineItemsHaveDeletion ) ? true : false;
    this.OA_lineItems[this.OA_lineItems.length-1].verify_Product = true;
    this.int_numEntries++;
}

function addNonValidSKUs( sku, name, desc, qty, price, reason)
{
    this.OA_lineItems[this.OA_lineItems.length] = new LineItem();
    this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[0] = encodeJS(sku);
    this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[1] = qty;
    this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[2] = reason;
    this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[3] = encodeJS(name);
    this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[4] = encodeJS(desc);    
    this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[5] = price;    
    this.OA_lineItems[this.OA_lineItems.length-1].bool_hasDeletion = ( this.bool_lineItemsHaveDeletion ) ? true : false;
    this.OA_lineItems[this.OA_lineItems.length-1].verify_Product = false;
    this.int_numEntries++;
}

function encodeJS( text) 
{
    if (text == null)
        return null;
        
    var buffer = "";

    for (var i=0; i < text.length; i++)
    {
        var ch = text.charAt(i);
        switch(ch)
        {
            case '<':
                buffer += "&lt;";
                break;
            case '>':
                buffer += "&gt;";                
                break;
            default:
                buffer += ch;
                break;
        }    
    }
    return buffer;
}  

function decodeJS( text)
{
    text = text.replace( "&lt;", "<");
    text = text.replace( "&gt;", ">");
    return text;
}

function addToList( OA_frmElements )
{       
	this.OA_lineItems[this.OA_lineItems.length] = new LineItem();
	for( var i = 0; i < OA_frmElements.length; i++ )
	{
		this.OA_lineItems[this.OA_lineItems.length-1].AA_propertyArray[i] = encodeJS(OA_frmElements[i].value);
		this.OA_lineItems[this.OA_lineItems.length-1].bool_hasDeletion = ( this.bool_lineItemsHaveDeletion ) ? true : false;
		this.OA_lineItems[this.OA_lineItems.length-1].verify_Product = true;
	}	
	this.int_numEntries++;
}

// Function sets the specified index to null which will be ignored during 
// paint time and request assignment.
function deleteFromList( int_index )
{    
	this.OA_lineItems.setIndexToNull( int_index );
	this.int_numEntries--;	
}

function toggleProductEntry(int_index)
{    
    var verify = !this.OA_lineItems[int_index].verify_Product;
    this.OA_lineItems[int_index].verify_Product = verify;
    
    if(!this.OA_lineItems[int_index].verify_Product)
    {
        this.OA_lineItems[int_index].AA_propertyArray[3] = ("N/A");
        this.OA_lineItems[int_index].AA_propertyArray[4] = ("N/A");                
        this.OA_lineItems[int_index].AA_propertyArray[5] = ("0");                       
    }
    else
    {
        this.OA_lineItems[int_index].AA_propertyArray[3] = null;
        this.OA_lineItems[int_index].AA_propertyArray[4] = null;
        this.OA_lineItems[int_index].AA_propertyArray[5] = null;
    }
}

function nonValidProductUpdate(int_index)
{
    var name = eval(this.formName + ".productName" + int_index).value;
    if (trim(name) == "")
    {
        name="N/A"
        eval(this.formName + ".productName" + int_index).value = name
    }
    this.OA_lineItems[int_index].AA_propertyArray[3] = name;
    var desc = eval(this.formName + ".productDesc"+int_index).value;
    if (trim(desc) == "")
    {
        desc="N/A"
        eval(this.formName + ".productDesc"+int_index).value = desc;
    }
    this.OA_lineItems[int_index].AA_propertyArray[4] = desc;
    var price = eval(this.formName + ".productPrice"+int_index).value;
    this.OA_lineItems[int_index].AA_propertyArray[5] = price;
    floatValue=parseFloat(price) 
    if (isNaN(floatValue))
	{
	    alert("Please enter valid price.");	        
	    return;
	}
}

// Returns a string of the values in the TableView.OA_lineItems.AA_propertyArray.
// The arg 'int_index' specifies which index to grab the value from when traversing
// the OA_lineItems.AA_propertyArray.
// The delimeter specifies how the values are seperated in the string:
// val<char_delimeter>val<char_delimeter>val<char_delimeter>val
function getCommonValuesList( int_index, char_delimeter )
{
	var str_commonVals = "";
	for( var i = 0, j = 0; i < this.OA_lineItems.length; i++ )
	{
		if( this.OA_lineItems[i] != null )
		{
			str_commonVals += this.OA_lineItems[i].AA_propertyArray[int_index];
			str_commonVals += ( j < this.int_numEntries-1 ) ? char_delimeter : '';
			j++;
		}
	}
	return str_commonVals;
}


function getAlternateValuesList( A_keyStrings, char_delimeter )
{
	var str_commonVals = "";
	for( var i = 0; i < this.OA_lineItems.length; i++ )
	{
		if( this.OA_lineItems[i] != null )
		{
			for( var j = 0; j < this.OA_lineItems[i].AA_propertyArray.length; j++ )
			{
				str_commonVals += ( A_keyStrings[j] + this.OA_lineItems[i].AA_propertyArray[j] );
				str_commonVals += ( i < this.int_numEntries ) ? char_delimeter : '';
			}
		}
	}
	return str_commonVals;
}
/************************* TableView Object ********************************/

/************************* LineItem Object ********************************/
function LineItem( bool_hasDeletion )
{
	this.bool_hasDeletion = bool_hasDeletion;
	this.verify_Product = true;
	
	// Array of data properties representing the column data
	this.AA_propertyArray = new Array();  
}

/************************* LineItem Object ********************************/

/************************* Global functions ********************************/
function registerDataInputFields( OA_frmElements, R_eventFunction ) 
{
  for( var i = 0; i < OA_formElements.length; i++ )
  {
      	OA_frmElements[i].onkeydown = function(e) {
    	if( str_browser == "ie" )
    	{
    		e = window.event;    		
        	if( e.keyCode-0 == 13 )
        	{
				// updateUserList( OA_frmElements, O_tableView );			    
				eval( R_eventFunction );
			}
			e.cancelBubble = true;
    	}
   		else if( str_browser == "nn" )
    	{
      		if( ( e.which-0 ) == 13 )
        	{
				// Will launch a seperate window
				eval( R_eventFunction );
			} 
    	}
  	} // end function def
  }// end for loop
}

function writeUserList( O_tableObj )
{     
	var str_mainMenuId = O_tableObj.str_spanId;
	var str_listContents = O_tableObj.str_tableDef;
	
	if (O_tableObj.bool_allowNonValidProducts)
	{
	    for(var i=0; i<O_tableObj.OA_lineItems.length; i++)
	    {
		    if(O_tableObj.OA_lineItems[i] != null && O_tableObj.OA_lineItems[i].verify_Product == false)
		    {
	            str_listContents += O_tableObj.str_tableHeaderDef;
		        break;		
		    }
	    }
	}
	for( var i = 0; i < O_tableObj.OA_lineItems.length; i++ )
	{
		if( O_tableObj.OA_lineItems[i] != null )
		{ 
			var OR_lineItems = O_tableObj.OA_lineItems[i];
			str_listContents += '<tr>';
			
			if (OR_lineItems.verify_Product)
			{
			    //Print the first 2 properties - then the X  - and then the status 
			    for( var j = 0; j < 2; j++ )
			    {	   
				    str_listContents += ( O_tableObj.str_cellDef + OR_lineItems.AA_propertyArray[j] + '</td>' );
				    str_listContents += ( O_tableObj.str_columnSeperator + '&nbsp;</td>' );								
			    }
			}
			else
			{
				str_listContents += ( O_tableObj.str_cellDef + OR_lineItems.AA_propertyArray[0] + '</td>');
				str_listContents += ( O_tableObj.str_columnSeperator + '&nbsp;</td>' );
				str_listContents += ( O_tableObj.str_cellDef + OR_lineItems.AA_propertyArray[1] + '</td>');
				str_listContents += ( O_tableObj.str_columnSeperator + '&nbsp;</td>' );
                str_listContents += ('<td class="textFieldSmall"><input type="text" maxlength=60 name="productName' + i + '" value=') + OR_lineItems.AA_propertyArray[3] + (' size="15" onchange="O_tableView.nonValidProductUpdate(' + i + ');"></td>');
                str_listContents += ( O_tableObj.str_columnSeperator + '&nbsp;&nbsp;</td>' );
                str_listContents += ('<td class="textFieldSmall"><input type="text" maxlength=240 name="productDesc' + i + '" value=') + OR_lineItems.AA_propertyArray[4] + (' size="20" onchange="O_tableView.nonValidProductUpdate(' + i + ');"></td>');
                str_listContents += ( O_tableObj.str_columnSeperator + '&nbsp;&nbsp;</td>' );
                str_listContents += ('<td class="textFieldSmall"><input type="text" name="productPrice' + i + '" value=') + OR_lineItems.AA_propertyArray[5] + (' size="3" onchange="O_tableView.nonValidProductUpdate(' + i + ');"></td>');
				str_listContents += ( O_tableObj.str_columnSeperator + '&nbsp;&nbsp;</td>' );			    
			}
			
			//The delete cell--> last cell; maybe set to an empty cell if the TableView object was declared without the deletion property set.
			str_listContents += ( OR_lineItems.bool_hasDeletion ) ? ( '<td class="font8pt" align="left"><a href="javascript:O_tableView.deleteFromList(' + i + ');writeUserList(O_tableView);forceFormElementFocus(' + O_tableObj.formName + '.domProductId )" name="test"><img src="../images/btn_xblue.gif" width="16" height="15" name="x" border="0"></a>&nbsp;' ) : '<td>&nbsp;';
					    
		    if (O_tableObj.bool_allowNonValidProducts)
		    {
		        if (OR_lineItems.verify_Product)
		            str_listContents += ( '<input name=nonValidCheckBox type="checkbox" checked onclick="O_tableView.toggleProductEntry(' + i + ');writeUserList(O_tableView);">&nbsp;' + O_tableObj.str_validateProductText + '</td></tr>' );
		        else
		            str_listContents += ( '<input name=nonValidCheckBox type="checkbox" onclick="O_tableView.toggleProductEntry(' + i + ');writeUserList(O_tableView);">&nbsp;' + O_tableObj.str_validateProductText + '</td></tr>' );
		    }
		    else
		    {
		        str_listContents += '</td></tr>';
		    }

			//The rest of the properties
		    if (OR_lineItems.verify_Product)
			{
			    for( var j = 2; j < OR_lineItems.AA_propertyArray.length; j++ )
			    {
			        if (OR_lineItems.AA_propertyArray[j] != null)
				        str_listContents += ( '<td class="font8ptRed">' + OR_lineItems.AA_propertyArray[j] + '</td>' + O_tableObj.str_columnSeperator + '&nbsp;</td>' );
				}
			}
			else
			{
			    if (OR_lineItems.AA_propertyArray[2] != null)
				    str_listContents += ( '<td class="font8ptRed">' + OR_lineItems.AA_propertyArray[2] + '</td>' + O_tableObj.str_columnSeperator + '&nbsp;</td>' );
			}
			// Row divider
			str_listContents += ('<tr><td class="' + O_tableObj.str_dividerClass + '" colspan="' + O_tableObj.int_colSpan + '"><img src="../images/spacer.gif" width="1" height="1" border="0"></td></tr>' );
		} // end if
	} // end for loop
	str_listContents += ( '</table>' );
	if( str_browser == "ie" )
	{	    
        eval( str_DOMDocument + "." + str_mainMenuId + ".innerHTML='" + str_listContents + "'");
	}
	else 
	{	    
	    if ( str_browser == "nn" && int_version == "5")
	    {	        
	        eval( str_DOMDocument + "(\"" + str_mainMenuId + "\"\).innerHTML='" + str_listContents + "'");		
	    }
	    else
	    {
		    eval( str_DOMDocument + "." + str_mainMenuId + ".document.write('" + str_listContents + "')" );
		    eval( str_DOMDocument + "." + str_mainMenuId + ".document.close()" );
		}
	}
}



function writeUserListInv( O_tableObj)
{
	var str_mainMenuId = O_tableObj.str_spanId;
	var str_listContents = O_tableObj.str_tableDef;
	
	for( var i = 0; i < O_tableObj.OA_lineItems.length; i++ )
	{
		if( O_tableObj.OA_lineItems[i] != null )
		{ 
			var OR_lineItems = O_tableObj.OA_lineItems[i];
			str_listContents += '<tr>';
						
			//Print the first 'numEntriesOnOneLine' properties - then the X  - and then the status 
			for( var j = 0; j < 4; j++ )
			{	   
				str_listContents += ( O_tableObj.str_cellDef + OR_lineItems.AA_propertyArray[j] + '</td>' + O_tableObj.str_columnSeperator + '&nbsp;</td>' );								
			}
			
			//The delete cell--> last cell; maybe set to an empty cell if the TableView object was declared without the deletion property set.
			str_listContents += ( OR_lineItems.bool_hasDeletion ) ? ( '<td class="textFieldSmall" align="center"><a href="javascript:O_tableView.deleteFromList(' + i + ');writeUserListInv(O_tableView);forceFormElementFocus( document.addInvoiceLinesForm.domItemName)" name="test"><img src="../images/btn_xblue.gif" width="16" height="15" name="x" border="0"></a></td></tr>' ) : '<tr><td>&nbsp;</td></tr>';

			//The rest of the properties
			for( var j = 4; j < OR_lineItems.AA_propertyArray.length; j++ )
				str_listContents += ( '<td class="font8ptRed">' + OR_lineItems.AA_propertyArray[j] + '</td>' + O_tableObj.str_columnSeperator + '&nbsp;</td>' );
			// Row divider
			str_listContents += ('<tr><td class="' + O_tableObj.str_dividerClass + '" colspan="' + O_tableObj.int_colSpan + '"><img src="../images/spacer.gif" width="1" height="1" border="0"></td></tr>' );
		} // end if
	} // end for loop
	str_listContents += ( '</table>' );		
	if( str_browser == "ie" )
	{	    
        eval( str_DOMDocument + "." + str_mainMenuId + ".innerHTML='" + str_listContents + "'");
	}
	else 
	{	    
	    if ( str_browser == "nn" && int_version == "5")
	    {	        
	        eval( str_DOMDocument + "(\"" + str_mainMenuId + "\"\).innerHTML='" + str_listContents + "'");		
	    }
	    else
	    {
		    eval( str_DOMDocument + "." + str_mainMenuId + ".document.write('" + str_listContents + "')" );
		    eval( str_DOMDocument + "." + str_mainMenuId + ".document.close()" );
		}
	}
}

/************************* Global functions ********************************/
//-->

