// Module version: 1.03.07

function RoundTo2dp(x) {
  var k = (Math.round(x * 100) / 100).toString();
  k += (k.indexOf('.') == -1)? '.00' : '00';
  var p = k.indexOf('.'), m = k.indexOf('-.');
  var f = (p == 0 || m == 0)? '0.' : '.';
  return k.substring(0, p) + f + k.substring(p+1, p+3);
}




function getValueFromDelimStr( FullRow, FieldReqd, Delim ) {

 var S, T, U = null;
 var j, k, c, L, FieldNo = 0;


S = new String( null );
T = new String( null );
U = new String( null );


 if ( FullRow != '' ) {

   S = FullRow;

   j   = S.indexOf( Delim ) + 1;


  if ( j != 0 ) {


				for ( CurrField=0; CurrField<=FieldReqd;CurrField++ )
				{
			
					j = 0;
					k = 0;
					c = 0;
		
					j  = S.indexOf( Delim );
			
					if ( CurrField == FieldReqd )
					{
						 U = S.substring( 0, j );
					}
					 else { U = ''; }

					c = j;
					c++;

					T = S.substring( c, FullRow.length );
					S = T;
	
				}


	} // j != 0


     return U;
				
 }
  else {
	// FullRow blank!
   return '';
  }


}





function reCalcAllSelectedRadios(lDelim)
{
																				
					var theform      = document.frmProdDetails;					
					var totalValue   = 0.00;
				    
					for(i=0; i<theform.elements.length; i++)
					{

						var field = theform.elements[i];

						if ( field.type=="radio" ) 
						{

							var startingIndex = i;
							var Checked       = 0;
							var rLength       = 1;
					    
							while ( field.type == theform.elements[i+1].type && field.name == theform.elements[i+1].name )
							{
							    								
								//	alert( field.name );
								//  alert( theform.elements[i].value );
								
								rLength++;
								i++; 

							}
					    
							for ( g = startingIndex; g < rLength+startingIndex; g++ ) 
							{
							
								// alert( field.name );
								// alert( theform.elements[g].value );
							
								if ( theform.elements[g].checked && theform.elements[g].value != 'None|0.00|' )
								{
									Checked++;

									// N.B: Zero-Indexed (3rd option is therefore the price of the product in this case)
									totalValue = totalValue + parseFloat( getValueFromDelimStr( theform.elements[g].value, 2, lDelim ) );

								   // break;
								}
								
							}          
											       

						} //end if (fieldtype = radio)
					    

					}//end for     



					return RoundTo2dp( totalValue );
				  				       
}




function reCalcAllSelectedCheckboxes(lDelim)
{
																				
					var theform      = document.frmProdDetails;					
					var totalValue   = 0.00;
				    
					for(i=0; i<theform.elements.length; i++)
					{

						var field = theform.elements[i];

						if ( field.type=="checkbox" ) 
						{

							var startingIndex = i;
							var Checked       = 0;
							var rLength       = 1;
					    
							while ( field.type == theform.elements[i+1].type && field.name == theform.elements[i+1].name )
							{
							    								
								//	alert( field.name );
								//  alert( theform.elements[i].value );
								
								rLength++;
								i++; 

							}
					    
							for ( g = startingIndex; g < rLength+startingIndex; g++ ) 
							{
							
								// alert( field.name );
								// alert( theform.elements[g].value );
							
								if ( theform.elements[g].checked && theform.elements[g].value != 'None|0.00|' )
								{
									Checked++;

									// N.B: Zero-Indexed (3rd option is therefore the price of the product in this case)
									totalValue = totalValue + parseFloat( getValueFromDelimStr( theform.elements[g].value, 2, lDelim ) );

								   // break;
								}
								
							}          
											       

						} //end if (fieldtype = radio)
					    

					}//end for     



					return RoundTo2dp( totalValue );
				  				       
}

