var lstCustoms	= new Array();
var lstTables	= new Array();

		
function Extract ()
{
	lstCustoms = strCustoms.split(';');
	lstTables = strTables.split(';');
	
	for (indCustom=1; indCustom<=parseInt(lstCustoms[0]); indCustom++) {
		lstCustoms[indCustom] = lstCustoms[indCustom].split(':');
	}
	
	for (indTable=1; indTable<=parseInt( lstTables[0] ); indTable++)
	{
		lstTables[indTable] = lstTables[indTable].split(',');
		
		if (parseInt(lstTables[indTable][1] ) <= lstCustoms[0])// && parseInt( lstTables[indTable][2] ) > 1)
		{
			for (indX=0; indX<lstTables[indTable][2]; indX++) {
				lstTables[indTable][4 + indX] = lstTables[indTable][4 + indX].split(':');
			}
			if (parseInt(lstTables[indTable][1])) {
				for (indY=0; indY<lstTables[indTable][3]; indY++) {
					lstTables[indTable][4 + parseInt(lstTables[indTable][2])+indY] = lstTables[indTable][4+parseInt(lstTables[indTable][2])+indY].split(':');
				}
			}
		}
	}
}


function EvaluateTableField (form, field)
{
	var field = field==null ? '0.00' : field.toString();
	
	var results;
	
	if (results = field.match(/^C(\d)=T(\d)$/))
	{
		var selCustom = form['selCustom'+results[1]];
		var lstTable = lstTables[results[2]];
		var index = selCustom!=null ? selCustom.selectedIndex - 1 : -1;
		
		if (index < 0) {
			return '';
		}
		return EvaluateTableField(form, lstTable[4+parseInt(lstTable[2])+parseInt(lstTable[3])+index]);
	}
	else if (results = field.match(/^C(\d):C(\d)=T(\d)$/))
	{
		var selCustomX = form['selCustom'+results[1]];
		var selCustomY = form['selCustom'+results[2]];
		var lstTable = lstTables[results[3]];
		var indX = selCustomX!=null ? selCustomX.selectedIndex - 1 : -1;
		var indY = selCustomY!=null ? selCustomY.selectedIndex - 1 : -1;
		
		if (indX < 0 || indY < 0)
			return '';
		
		return EvaluateTableField(form, lstTable[4+parseInt(lstTable[2])+parseInt(lstTable[3])+indY*parseInt(lstTables[indTable][2])+indX]);
	}
	else if (field.substr(0,1)=='x') {
		return 'fltPermutation *= parseFloat('+field.substring(1,field.length)+');';
	}
	else {
		return 'fltTotal += parseFloat('+field+');';
	}
}

function Refresh (form)
{
	fltTotal = parseFloat(0.00);
	fltPermutation = parseFloat(1.00);	
	var price_error = false;
	
	for (indTable=1; indTable<=parseInt(lstTables[0]); indTable++)
	{
		indNamesX = 4;
		indNamesY = indNamesX + parseInt(lstTables[indTable][2]);
		indData = indNamesY + parseInt(lstTables[indTable][3]);
		
		if (!parseInt(lstTables[indTable][0]) && !parseInt(lstTables[indTable][1])) {
			continue;
		}
		if (parseInt(lstTables[indTable][1]) > parseInt(lstCustoms[0]))
		{
			if (lstTables[indTable][4].length) {
				indX = parseInt(form['selCustom'+lstTables[indTable][4]].selectedIndex)-1;
			}
			else {
				indX = 0;
			}
			
			if (parseInt( lstTables[indTable][3] ) > 1) {
				indY = parseInt(form['selCustom'+lstTables[indTable][4+parseInt(lstTables[indTable][2])]].selectedIndex)-1;
			}
			else {
				indY = 0;
			}
			
			// ISO : THIS IS UGLY //
			if (lstCustoms[parseInt(lstTables[indTable][0])][0]=='Custom Range') {
				;
			}
			else
			{
				txtCustom = form['txtCustom'+lstTables[indTable][0]];
				txtCustomView = form['txtCustomView'+lstTables[indTable][0]];
				
				var value = parseFloat(txtCustom.value);
				var min = form['hidCustomMin'+lstTables[indTable][0]].value;
				var max = form['hidCustomMax'+lstTables[indTable][0]].value;
				min = min==null ? 0 : min;
				max = max==null ? 0 : max;
				
				if ((txtCustom != null) && txtCustom.value.length && $('li[id=liCustomization'+lstTables[indTable][0]+']').css('display')!='none')
				{
					if (!isNaN(txtCustom.value) && (value >= min && value <= max))
					{
						if (txtCustomView != null) {
							var format = form['hidCustomFormat'+lstTables[indTable][0]].value;
							if (format=='tenth') {
								value = parseInt(value * 10).toString();
								while (value.length < 3) {
									value = '0'+value;
								}
							}
							else if (format=='nenth') {
								value = parseInt(value * 10).toString();
								while (value.length < 2) {
									value = '0'+value;
								}
								value = 'N'+value;
							}
							else if (format=='length') {
								value = parseInt(value).toString();
								while (value.length < 3) {
									value = '0'+value;
								}
							}
							txtCustomView.value = value;
						}
						EvaluateTableField(form, lstTables[indTable][indY*parseInt(lstTables[indTable][2])+indX+indData]);
						
						var field = lstTables[indTable][indY*parseInt(lstTables[indTable][2])+indX+indData];
						field = field==null ? '0.00' : field.toString();
						
						if (field.substr(0,1)=='x') {
							fltTotal += (indX < 0) || (indY < 0) ? 0.00 : parseFloat(txtCustom.value) * parseFloat(field.substring(1,field.length));
						}
						else {
							fltTotal += (indX < 0) || (indY < 0) ? 0.00 : parseFloat(txtCustom.value) * parseFloat(field);
						}
						//fltTotal += (indX < 0) || (indY < 0) ? 0.00 : parseFloat(txtCustom.value) * parseFloat(lstTables[indTable][indY*parseInt(lstTables[indTable][2])+indX+indData]);
						
						if (txtCustomView != null) {
							txtCustomView.style.color = '#333333';
						}
					}
					else {
						price_error = true;
						if (txtCustomView != null) {
							txtCustomView.value = 'E';
							txtCustomView.style.color = '#ff0000';
						}
					}
				}
				else if (txtCustomView != null) {
					txtCustomView.value = '---';
				}
			}
		}
		else
		{
			if (0) { /*parseInt(lstTables[indTable][2]) <= 1) {
				
				eval(EvaluateTableField(form,lstTables[indTable][indData]));
				
				/*var field = lstTables[indTable][indData].toString();
				
				if (field.substr(0,1) == 'x')
					fltPermutation *= parseFloat(field.substring(1,field.length));
				else
					fltTotal += parseFloat(field);*/
					
				//fltTotal += parseFloat(lstTables[indTable][indData]);	
			}
			else
			{
				selCustomX = form['selCustom'+lstTables[indTable][0]];
				txtCustomViewX = form['txtCustomView'+lstTables[indTable][0]];
				
				if (selCustomX != null) {
					indX = selCustomX.selectedIndex - 1;
				}
				else {
					indX = -1;
				}
				
				// ISO : THIS IS UGLY //
				if ((parseInt(lstTables[indTable][0]) < lstCustoms[0]) && (lstCustoms[parseInt(lstTables[indTable][0])+1][0]=='Custom Range'))
				{
					var objLiCustomization, objSpanC, objSpanF, objSpanNA, objSpanView, objSpanViewNA;
					var strUnits = '';
					
					if (document.all) {
						objLiCustomization = document.all['liCustomization'+(parseInt(lstTables[indTable][0])+1)];
						objSpanC = document.all['spanCustomC'+(parseInt(lstTables[indTable][0])+1)];
						objSpanF = document.all['spanCustomF'+(parseInt(lstTables[indTable][0])+1)];
						objSpanNA = document.all['spanCustomNA'+(parseInt(lstTables[indTable][0])+1)];
					}
					else if(document.getElementById) {
						objLiCustomization = document.getElementById('liCustomization'+(parseInt(lstTables[indTable][0])+1));
						objSpanC = document.getElementById('spanCustomC'+(parseInt(lstTables[indTable][0])+1));
						objSpanF = document.getElementById('spanCustomF'+(parseInt(lstTables[indTable][0])+1));
						objSpanNA = document.getElementById('spanCustomNA'+(parseInt(lstTables[indTable][0])+1));
					}
					
					txtCustomView = form['txtCustomView'+(parseInt(lstTables[indTable][0])+1)];
					
					if (indX >= 0)
					{
						if (lstTables[indTable][4+indX][0]=='YC') {
							strUnits = 'C';
							objLiCustomization.style.display = 'block';
							objSpanC.style.display = 'inline';
							objSpanF.style.display = 'none';
							objSpanNA.style.display = 'none';
							txtCustomView.style.display = 'inline';
							txtCustomViewX.style.display = 'none';
						}
						else if (lstTables[indTable][4+indX][0] == 'YF') {
							strUnits = 'F';
							objLiCustomization.style.display = 'block';
							objSpanC.style.display = 'none';
							objSpanF.style.display = 'inline';
							objSpanNA.style.display = 'none';
							txtCustomView.style.display = 'inline';
							txtCustomViewX.style.display = 'none';
						}
						else {
							strUnits = '';
							objLiCustomization.style.display = 'none';
							objSpanC.style.display = 'none';
							objSpanF.style.display = 'none';
							objSpanNA.style.display = 'none';
							txtCustomView.style.display = 'none';
							txtCustomViewX.style.display = 'inline';
						}
					}
					else {
						strUnits = '';
						objLiCustomization.style.display = 'none';
						objSpanC.style.display = 'none';
						objSpanF.style.display = 'none';
						objSpanNA.style.display = 'none';
						txtCustomView.style.display = 'none';
						txtCustomViewX.style.display = 'inline';
					}
					
					if (strUnits.length) {
						txtCustomFrom = form['txtCustomFrom'+strUnits+(parseInt(lstTables[indTable][0])+1)];
						txtCustomTo = form['txtCustomTo'+strUnits+(parseInt(lstTables[indTable][0])+1)];
						txtCustomFromC = form['txtCustomFromC'+(parseInt(lstTables[indTable][0])+1)];
						txtCustomToC = form['txtCustomToC'+(parseInt(lstTables[indTable][0])+1)];
						txtCustomFromF = form['txtCustomFromF'+(parseInt(lstTables[indTable][0])+1)];
						txtCustomToF = form['txtCustomToF'+(parseInt(lstTables[indTable][0])+1)];
						
						hidCustomMin = form['hidCustomMin'+strUnits+(parseInt(lstTables[indTable][0])+1)];
						hidCustomMax = form['hidCustomMax'+strUnits+(parseInt(lstTables[indTable][0])+1)];
						intMin = hidCustomMin==null ? -200 : hidCustomMin.value;
						intMax = hidCustomMax==null ?  600 : hidCustomMax.value;
						
						if ((txtCustomFromC != null) && (txtCustomToC != null) && (txtCustomFromF != null) && (txtCustomToF != null))
						{
							if (strUnits=='C') {
								txtCustomFromF.value = Math.round(CelsiusToFahrenheit(txtCustomFromC.value));
								txtCustomToF.value = Math.round(CelsiusToFahrenheit(txtCustomToC.value ));
							}
							else if (strUnits=='F') {
								txtCustomFromC.value = Math.round(FahrenheitToCelsius(txtCustomFromF.value ));
								txtCustomToC.value = Math.round(FahrenheitToCelsius(txtCustomToF.value ));
							}
						}
						
						if ((txtCustomView != null) && (txtCustomFrom != null) && (txtCustomTo != null)) {
							txtCustomView.value  = '[' + (((txtCustomFrom != null) && txtCustomFrom.value.length && !isNaN( txtCustomFrom.value )) ? txtCustomFrom.value : '---') + '/';
							txtCustomView.value += (((txtCustomTo != null) && txtCustomTo.value.length && !isNaN( txtCustomTo.value )) ? txtCustomTo.value : '---') + '°' + strUnits + ']';
						}
						
						if (txtCustomFrom != null) {
							if (!txtCustomFrom.value.length || isNaN(txtCustomFrom.value) || (parseInt(txtCustomFrom.value) < intMin) || (parseInt(txtCustomFrom.value) > intMax) || (parseInt(txtCustomFrom.value) > parseInt(txtCustomTo.value))) {
								price_error = true;
								if (txtCustomView != null) {
									txtCustomView.value = 'E';
									txtCustomView.style.color = '#ff0000';
								}
							}
						}
						
						if (txtCustomTo != null) {
							if (!txtCustomTo.value.length || isNaN(txtCustomTo.value) || (parseInt(txtCustomTo.value) > intMax) || (parseInt(txtCustomTo.value) < intMin) || (parseInt(txtCustomTo.value) < parseInt(txtCustomFrom.value))) {
								price_error = true;
								if (txtCustomView != null) {
									txtCustomView.value = 'E';
									txtCustomView.style.color = '#ff0000';
								}
							}
						}
						
						if (txtCustomView != null) {
							if (txtCustomView.value != 'E') {
								if (strUnits=='C') {
									if ((txtCustomFrom != null && (parseInt(txtCustomFrom.value) < -50)) || (txtCustomTo != null && (parseInt(txtCustomTo.value) > 200))) {
										fltTotal += 60.00;
									}
								}
								else if (strUnits=='F') {
									if ((txtCustomFrom != null && (parseInt(txtCustomFrom.value) < -58)) || (txtCustomTo != null && (parseInt(txtCustomTo.value) > 392))) {
										fltTotal += 60.00;
									}
								}
								txtCustomView.style.color = '#333333';
							}
						}
					}
					else {
						if (txtCustomView != null) {
							txtCustomView.value = '-----------';
						}
					}
				}
				
				var showcustom = null;
				
				if (indX >= 0)
				{
					var cst = null;
					
					if (txtCustomViewX != null) {
						txtCustomViewX.value = selCustomX.options[selCustomX.selectedIndex].text.split(' : ')[0];
					}
					if (parseInt(lstTables[indTable][1])) {
						
						selCustomY = form['selCustom'+lstTables[indTable][1]];
						txtCustomViewY = form['txtCustomView'+lstTables[indTable][1]];
						
						if (selCustomY != null) {
							indY = selCustomY.selectedIndex-1;
						}
						else {
							indY = -1;
						}
						
						if (indY >=0) {
							
							if (txtCustomViewY != null) {
								txtCustomViewY.value = selCustomY.options[selCustomY.selectedIndex].text.split(' : ')[0];
							}
							
							cst = lstTables[indTable][indY*parseInt(lstTables[indTable][2])+indX+indNamesY];
							
							if ($('li[id=liCustomization'+lstTables[indTable][1]+']').css('display')!='none') {
								eval(EvaluateTableField(form, lstTables[indTable][indY*parseInt(lstTables[indTable][2])+indX+indData]));
							}
							
							/*var field = lstTables[indTable][indY*parseInt(lstTables[indTable][2])+indX+indData].toString();
							
							if (field.substr(0,1) == 'x') {
								fltPermutation *= parseFloat(field.substring(1,field.length));
							}
							else {
								fltTotal += parseFloat(field);
							}*/
							//fltTotal += parseFloat(lstTables[indTable][indY*parseInt(lstTables[indTable][2])+indX+indData]);
						}
						else if (txtCustomViewY != null) {
							txtCustomViewY.value = '---';
						}
					}
					else {
						cst = lstTables[indTable][indX+indNamesX][2];
						
						if ($('li[id=liCustomization'+lstTables[indTable][0]+']').css('display')!='none') {
							eval(EvaluateTableField(form,lstTables[indTable][indX+indData]));
						}
						
						/*var field = lstTables[indTable][indX+indData].toString();
						
						if (field.substr(0,1) == 'x') {
							fltPermutation *= parseFloat(field.substring(1,field.length));
						}
						else {
							fltTotal += parseFloat(field);
						}*/
						
						//fltTotal += parseFloat(lstTables[indTable][indX+indData]);
					}
				}
				else if (txtCustomViewX != null) {
					txtCustomViewX.value = '---';
				}
				
				if (cst) {
					showcustom = cst;
				}
				else {
					var c = lstCustoms[parseInt(lstTables[indTable][0])];
					if (c != null) {
						var def = parseInt(c[1]);
						if (def != null && !isNaN(def)) {
							showcustom = def;
						}
					}
				}
				
				if (showcustom) {
					
					var grp = parseInt($('#liCustomization'+showcustom+' div.number').text());
					
					$('#custom_builder li[id^=liCustomization]').each(function(){
						var nb = this.id.substring(15);
						var num = parseInt($(this).children('.number').text());
						if (num == grp) {
							if (nb != showcustom) {
								$(this).hide();
								$('input[name=txtCustomView'+nb+']').hide();
							}
						}
					});
					
					$('#liCustomization'+showcustom).show();
					$('input[name=txtCustomView'+showcustom+']').show();
				}
				
			}
		}
	}
		
	var fltTotal_ita = ((fltTotal*g_fltCurrency_ita)+fltPrice_ita)*fltPermutation;
	var fltTotal_usa = ((fltTotal*g_fltCurrency_usa)+fltPrice_usa)*fltPermutation;
	var fltTotal_can = ((fltTotal*g_fltCurrency_can)+fltPrice_can)*fltPermutation;
		fltTotal = ((fltTotal*g_fltCurrency)+fltPrice)*fltPermutation;
	
	if (g_blnRefresh)
	{
		if (price_error) {
			if (form.hidTotal_ita != null) {
				form.hidTotal_ita.value = RoundPrice(0);
			}
			if (form.hidTotal_usa != null) {
				form.hidTotal_usa.value = RoundPrice(0);
			}
			if (form.hidTotal_can != null) {
				form.hidTotal_can.value = RoundPrice(0);
			}
			if (form.txtTotal != null) {
				form.txtTotal.value = 'ERROR';
				form.txtTotal.style.color = '#ff0000';
			}
		}
		else {
			if (form.hidTotal_ita != null) {
				form.hidTotal_ita.value = RoundPrice(fltTotal_ita);
			}
			if (form.hidTotal_usa != null) {
				form.hidTotal_usa.value = RoundPrice(fltTotal_usa);
			}
			if (form.hidTotal_can != null) {
				form.hidTotal_can.value = RoundPrice(fltTotal_can);
			}
			if (form.txtTotal != null) {
				form.txtTotal.value = g_strCurrencySign + RoundPrice(fltTotal);
				form.txtTotal.style.color = '#333333';
			}
		}
		var txtQuantity = form.txtQuantity;
		
		if (form.hidNetTotal != null &&
			form.txtNetTotal != null) {
			if (price_error) {
				form.hidNetTotal.value	= RoundPrice( 0 );
				form.txtNetTotal.value	= 'ERROR';
				form.txtNetTotal.style.color = '#ff0000';
			}
			else if (txtQuantity.value.length && !isNaN(txtQuantity.value) && (parseInt(txtQuantity.value) > 0)) {
				form.hidNetTotal.value	= RoundPrice(fltTotal*parseFloat(txtQuantity.value));
				form.txtNetTotal.value	= RoundPrice(fltTotal*parseFloat(txtQuantity.value));
				form.txtNetTotal.style.color = '#333333';
			}
			else {
				form.hidNetTotal.value	= RoundPrice( 0 );
				form.txtNetTotal.value	= '-----';
				form.txtNetTotal.style.color = '#cccccc';
			}
		}
	}
	return true;
}

function Validate_getCustomizationIndex (offsets, customization)
{
	var grp = parseInt($('#liCustomization'+customization+' div.number').text());
	if (!isNaN(grp)) {
		index = grp;
	}
	else {
		var index = customization;
		for (var i=0; i<offsets.length; i++) {
			if (customization > offsets[i]) {
				index--;
			}
		}
	}
	return index;
}
function Validate (form)
{
	var offsets = [1];
	
	for (indTable=1; indTable<=parseInt(lstTables[0]); indTable++)
	{
		indData =  4 + parseInt(lstTables[indTable][2]) + parseInt(lstTables[indTable][3]);
		
		if (parseInt(lstTables[indTable][1]) > parseInt(lstCustoms[0]))
		{
			txtCustom = form['txtCustom'+lstTables[indTable][0]];
			hidCustomMin = form['hidCustomMin'+parseInt(lstTables[indTable][0])];
			hidCustomMax = form['hidCustomMax'+parseInt(lstTables[indTable][0])];
			
			intMin = (hidCustomMin == null) ? -99999 : hidCustomMin.value;
			intMax = (hidCustomMax == null) ?  99999 : hidCustomMax.value;
			
			if (txtCustom != null && $('li[id=liCustomization'+lstTables[indTable][0]+']').css('display')!='none') {
				if (!txtCustom.value.length || isNaN(txtCustom.value) || (parseInt(txtCustom.value) < intMin) || (parseInt(txtCustom.value) > intMax)) {
					alert('Customization #'+Validate_getCustomizationIndex(offsets,parseInt(lstTables[indTable][0]))+' value is invalid');
					txtCustom.focus();
					return false;
				}
			}
		}
		else
		{
			//if (parseInt( lstTables[indTable][2] ) > 1)
			{
				selCustomX = form['selCustom'+lstTables[indTable][0]];
				selCustomY = form['selCustom'+lstTables[indTable][1]];
				
				if (selCustomX != null && $('li[id=liCustomization'+lstTables[indTable][0]+']').css('display')!='none') {
					if (selCustomX.selectedIndex < 1) {
						alert('Customization #'+Validate_getCustomizationIndex(offsets,parseInt(lstTables[indTable][0]))+' has no selection');
						selCustomX.focus();
						return( false );
					}
					
					indX = selCustomX.selectedIndex - 1;
				}
				else {
					indX = -1;
				}
				
				if (selCustomY != null && $('li[id=liCustomization'+lstTables[indTable][1]+']').css('display')!='none') {
					if (selCustomY.selectedIndex < 1) {
						alert('Customization #'+Validate_getCustomizationIndex(offsets,parseInt(lstTables[indTable][1]))+' has no selection');
						selCustomY.focus();
						return( false );
					}
				}
				
				// ISO : THIS IS UGLY //
				if ((parseInt(lstTables[indTable][0]) < lstCustoms[0]) && (lstCustoms[parseInt(lstTables[indTable][0]) + 1][0]=='Custom Range') && (indX >= 0))
				{
					offsets[offsets.length] = parseInt(lstTables[indTable][0]);
					
					var strUnits = '';
					
					if (lstTables[indTable][4+indX][0]=='YC') {
						strUnits = 'C';
					}
					else if (lstTables[indTable][4+indX][0]=='YF') {
						strUnits = 'F';
					}
					if (strUnits.length) {
						txtCustomFrom = form['txtCustomFrom'+strUnits+(parseInt(lstTables[indTable][0])+1)];
						txtCustomTo = form['txtCustomTo'+strUnits+(parseInt(lstTables[indTable][0])+1)];
						hidCustomMin = form['hidCustomMin'+strUnits+(parseInt(lstTables[indTable][0])+1)];
						hidCustomMax = form['hidCustomMax'+strUnits+(parseInt(lstTables[indTable][0])+1)];
						
						intMin = hidCustomMin==null ? -200 : hidCustomMin.value;
						intMax = hidCustomMax==null ?  600 : hidCustomMax.value;
						
						if (txtCustomFrom != null) {
							if (!txtCustomFrom.value.length || isNaN(txtCustomFrom.value) || (parseInt(txtCustomFrom.value) < intMin) || (parseInt(txtCustomFrom.value) > intMax) || (parseInt(txtCustomFrom.value) > parseInt(txtCustomTo.value))) {
								alert('Customization #'+Validate_getCustomizationIndex(offsets,parseInt(lstTables[indTable][0]))+' minimum value is invalid');
								txtCustomFrom.focus();
								return( false );
							}
						}
						
						if (txtCustomTo != null) {
							if (!txtCustomTo.value.length || isNaN(txtCustomTo.value) || (parseInt(txtCustomTo.value) > intMax) || (parseInt(txtCustomTo.value) < intMin) || (parseInt(txtCustomTo.value) < parseInt(txtCustomFrom.value))) {
								alert('Customization #'+Validate_getCustomizationIndex(offsets,parseInt(lstTables[indTable][0]))+' maximum value is invalid');
								txtCustomTo.focus();
								return( false );
							}
						}
					}
				}
			}
		}
	}
	
	var txtQuantity = form.txtQuantity;
	
	if ((txtQuantity != null) && (!txtQuantity.value.length || isNaN(txtQuantity.value) || (parseInt(txtQuantity.value) < 1))) {
		alert('Quantity is invalid');
		txtQuantity.focus();
		return false;
	}
	return true;
}

function Compile (form)
{
	var lstTweak = [form.txtTotal==null?'':form.txtTotal.value];
	
	for (indCustom=1; indCustom<=parseInt( lstCustoms[0] ); indCustom++)
	{
		for (indTable=1; indTable<=parseInt( lstTables[0] ); indTable++)
		{
			if (parseInt(lstTables[indTable][0]) == indCustom) {
				indAxis = 0;
				indNames = 4;
				break;
			}
			else if (parseInt(lstTables[indTable][1]) == indCustom) {
				indAxis = 1;
				indNames = 4 + parseInt(lstTables[indTable][2]);
				break;
			}
		}
		
		if (indTable > parseInt(lstTables[0])) {
			lstTweak[lstTweak.length] = '';
		}
		else
		{
			if (parseInt(lstTables[indTable][1]) > parseInt(lstCustoms[0]))
			{
				// ISO : THIS IS UGLY //
				if (lstCustoms[parseInt(lstTables[indTable][0])][0]=='Custom Range')
				{
					objSelect = form['selCustom'+(parseInt(lstTables[indTable][0])-1)];
					
					if (objSelect.selectedIndex > 0) {
						strValue = objSelect.options[objSelect.selectedIndex].text.substring( 0, 2 );
					}
					else {
						strValue = '';
					}
					if (strValue=='YC') {
						lstTweak[lstTweak.length] = form['txtCustomFromC'+lstTables[indTable][0]].value + ';' + form['txtCustomToC'+lstTables[indTable][0]].value + ';C';
					}
					else if (strValue=='YF') {
						lstTweak[lstTweak.length] = form['txtCustomFromF'+lstTables[indTable][0]].value + ';' + form['txtCustomToF'+lstTables[indTable][0]].value + ';F';
					}
					else {
						lstTweak[lstTweak.length] = '';
					}
				}
				else {
					lstTweak[lstTweak.length] = form['txtCustom'+indCustom].value;
				}
			}
			else
			{
				if (parseInt( lstTables[indTable][2 + indAxis] ) <= 1) {
					lstTweak[lstTweak.length] = '';
				}
				else {
					lstTweak[lstTweak.length] = form['selCustom'+indCustom].selectedIndex - 1;
				}
			}
		}
	}
	
	return lstTweak.join('@');
}

function Serialize (form)
{
	var lstSerial = new Array();
	
	for (indCustom=1; indCustom<=parseInt(lstCustoms[0]); indCustom++)
	{
		for (indTable=1; indTable<=parseInt(lstTables[0]); indTable++)
		{
			if (parseInt(lstTables[indTable][0]) == indCustom) {
				var indAxis = 0;
				var indNames = 4;
				break;
			}
			else if (parseInt(lstTables[indTable][1]) == indCustom) {
				var indAxis = 1;
				var indNames = 4 + parseInt(lstTables[indTable][2]);
				break;
			}
		}
		
		if (indTable > parseInt(lstTables[0])) {
			;//lstSerial[lstSerial.length] = '';
		}
		else
		{	
			if (parseInt( lstTables[indTable][1] ) > parseInt(lstCustoms[0] ))
			{
				// ISO : THIS IS UGLY //
				if (lstCustoms[parseInt( lstTables[indTable][0] )][0] == 'Custom Range')
				{
					objSelect = form['selCustom'+(parseInt(lstTables[indTable][0])-1)];
					
					if (objSelect.selectedIndex > 0) {
						strValue = objSelect.options[objSelect.selectedIndex].text.substring( 0, 2 );
					}
					else {
						strValue = '';
					}
					if (strValue == 'YC') {
						lstSerial[lstSerial.length] = '['+form['txtCustomFromC'+lstTables[indTable][0]].value + '/' + form['txtCustomToC'+lstTables[indTable][0]].value + 'C]';
					}
					else if (strValue == 'YF') {
						lstSerial[lstSerial.length] = '['+form['txtCustomFromF'+lstTables[indTable][0]].value + '/' + form['txtCustomToF'+lstTables[indTable][0]].value + 'F]';
					}
				}
				else
				{
					if ($('li[id=liCustomization'+indCustom+']').css('display')!='none') {
						
					var value = form['txtCustom'+indCustom].value;
					var format = form['hidCustomFormat'+indCustom].value;
					if (format == 'tenth') {
						value = parseInt(parseFloat(value)*10).toString();
						while (value.length < 3) {
							value = '0'+value;
						}
					}
					lstSerial[lstSerial.length] = value;
					
					}
				}
			}
			else
			{
				if (parseInt( lstTables[indTable][2 + indAxis] ) <= 1) {
					lstSerial[lstSerial.length] = lstTables[indTable][indNames][0];
				}
				else
				{
					if ($('li[id=liCustomization'+indCustom+']').css('display')!='none') {
						
					var indSelected = form['selCustom'+indCustom].selectedIndex - 1;
					var strSelectedValue = indSelected < 0 ? 'n/a' : lstTables[indTable][indNames + indSelected][0];
					
					if ((parseInt( lstTables[indTable][0] ) < lstCustoms[0]) && (lstCustoms[parseInt(lstTables[indTable][0])+1][0] == 'Custom Range') && ((strSelectedValue=='YC') || (strSelectedValue=='YF'))) {
						;
					}
					else {
						lstSerial[lstSerial.length] = strSelectedValue
					}
					
					}
				}
			}
		}
	}
	
	return lstSerial.join('@');
}

function SetEvents(form)
{
	for (indCustom=1; indCustom<=parseInt(lstCustoms[0]); indCustom++)
	{
		var selCustom = form['selCustom'+indCustom];
		var txtCustom = form['txtCustom'+indCustom];
		var txtCustomSingle = form['txtCustomSingle'+indCustom];
		var txtCustomFromC = form['txtCustomFromC'+indCustom];
		var txtCustomToC = form['txtCustomToC'+indCustom];
		var txtCustomFromF = form['txtCustomFromF'+indCustom];
		var txtCustomToF = form['txtCustomToF'+indCustom];
		var txtCustomView = form['txtCustomView'+indCustom];
		
		if (selCustom != null) {
			selCustom.onchange = function() { Refresh(form); }
		}
		if (txtCustom != null) {
			txtCustom.onkeydown = function() { Refresh(form);  }
			txtCustom.onkeypress = function() { Refresh(form); }
			txtCustom.onkeyup = function() { Refresh(form); }
		}
		if (txtCustomSingle != null) {
			txtCustomSingle.onkeydown = function() { return false; }
			txtCustomSingle.onkeypress = function() { return false; }
			txtCustomSingle.onkeyup = function() { return false; }
		}
		if (txtCustomFromC != null) {
			txtCustomFromC.onkeydown = function() { Refresh(form); }
			txtCustomFromC.onkeypress = function() { Refresh(form); }
			txtCustomFromC.onkeyup = function() { Refresh(form); }
		}
		if (txtCustomToC != null) {
			txtCustomToC.onkeydown = function() { Refresh(form); }
			txtCustomToC.onkeypress = function() { Refresh(form); }
			txtCustomToC.onkeyup = function() { Refresh(form); }
		}
		if (txtCustomFromF != null) {
			txtCustomFromF.onkeydown = function() { Refresh(form); }
			txtCustomFromF.onkeypress = function() { Refresh(form); }
			txtCustomFromF.onkeyup = function() { Refresh(form); }
		}
		if (txtCustomToF != null) {
			txtCustomToF.onkeydown = function() { Refresh(form); }
			txtCustomToF.onkeypress = function() { Refresh(form); }
			txtCustomToF.onkeyup = function() { Refresh(form); }
		}
		if (txtCustomView != null) {
			txtCustomView.onkeydown = function() { return false; }
			txtCustomView.onkeypress = function() { return false; }
			txtCustomView.onkeyup = function() { return false; }
		}
	}
	if (form.txtTotal != null) {
		form.txtTotal.onchange = function() { return false; }
		form.txtTotal.onkeydown = function() { return false; }
		form.txtTotal.onkeypress = function() { return false; }
		form.txtTotal.onkeyup = function() { return false; }
	}
	if (form.txtNetTotal != null) {
		form.txtNetTotal.onchange = function() { return false; }
		form.txtNetTotal.onkeydown = function() { return false; }
		form.txtNetTotal.onkeypress = function() { return false; }
		form.txtNetTotal.onkeyup = function() { return false; }
	}
	if (form.txtQuantity != null) {
		form.txtQuantity.onchange = function() { Refresh(form); }
		form.txtQuantity.onkeydown = function() { window.setTimeout('document.forms.'+form.name+'.txtQuantity.onchange()',1); }
		form.txtQuantity.onkeypress = function() { window.setTimeout('document.forms.'+form.name+'.txtQuantity.onchange()',1); }
		form.txtQuantity.onkeyup = function() { window.setTimeout('document.forms.'+form.name+'.txtQuantity.onchange()',1); }
	}
}

function SetLayerStyle (id, style, value)
{
	var element = null;
	if (document.all) {
		element = document.all[id];
	}
	else if (document.getElementById) {
		element = document.getElementById(id);
	}
	if (element) {
		element.style[style] = isNaN(value)?'\''+value+'\'':value;
	}
}

function CelsiusToFahrenheit (degrees) {
	return (parseFloat(degrees) * 1.8) + 32.0;
}
function FahrenheitToCelsius (degrees) {
	return (parseFloat(degrees) - 32.0) / 1.8;
}

function SetCustomization (form)
{
	for (var i=0; i<parseInt(lstCustoms[0]); i++)
	{
		var indCustom = i + 1;
		var selCustom = form['selCustom'+indCustom];
		var txtCustom = form['txtCustom'+indCustom];
		var txtCustomFromC = form['txtCustomFromC'+indCustom];
		var txtCustomToF = form['txtCustomToC'+indCustom];
		var txtCustomFromF = form['txtCustomFromF'+indCustom];
		var txtCustomToF = form['txtCustomToF'+indCustom];
		
		if (arguments[i] == null) {
			continue;
		}
		if (selCustom) {
			selCustom.selectedIndex = parseInt(arguments[i]);
		}
		else if (txtCustom) {
			txtCustom.value = arguments[i].toString();
		}
		else if (txtCustomFromC && txtCustomToC && txtCustomFromF && txtCustomToF) {
			var argument = arguments[i].toString().split(',');
			txtCustomFromC.value = argument[0];
			txtCustomToC.value = argument[1];
			txtCustomFromF.value = argument[2];
			txtCustomToF.value = argument[3];
		}
	}
	Refresh(form);
}

function LockCustomization (form)
{
	for (var i=0; i<parseInt(lstCustoms[0]); i++)
	{
		var indCustom = i + 1;
		var selCustom = form['selCustom'+indCustom];
		var txtCustom = form['txtCustom'+indCustom];
		var txtCustomFromC = form['txtCustomFromC'+indCustom];
		var txtCustomToF = form['txtCustomToC'+indCustom];
		var txtCustomFromF = form['txtCustomFromF'+indCustom];
		var txtCustomToF = form['txtCustomToF'+indCustom];
		
		if (selCustom) {
			selCustom.disabled = arguments[i] ? true : false;
		}
		else if (txtCustom) {
			txtCustom.disabled = arguments[i] ? true : false;
		}
		else if (txtCustomFromC && txtCustomToC && txtCustomFromF && txtCustomToF) {
			var disable = arguments[i] ? true : false;
			txtCustomFromC.disabled = disable;
			txtCustomToC.disabled = disable;
			txtCustomFromF.disabled = disable;
			txtCustomToF.disabled = disable;
		}
	}
}

function InitializeCustomizations(form)
{
	//	virtual function -AKA- dummy callback function to be re-declared during execution //
}