//
//	InteractiveIT 	Javascript Library
//
//	Functions for product page
//
//	RichP - 28/10/2008
//	richard_palmer@blueyonder.co.uk
// 
 
function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e); 
}  

	// dhtmlLoadScript("dhtml_way.js");
 
var fdata; 
var prices_loaded = false;
 
function split_prices(){
	//	Split and load the Perms.
  fdata = new Array(total_perms); 
	var i=0;
	var perm_split;
	var data_split;
	for (i=0;i<total_perms;i++){
	//for (i=0;i<1;i++){
		fdata[i]=new Array(11);		
		perm_split = perms[i].split("|");	
		for (d=0;d<11;d++){
			data_split=perm_split[d].split(":");
			fdata[i][d]=data_split[1];
	//	alert(data_split[0]+":"+data_split[1]);
		}		
	}
	
	
} 
 
function getCheckedValue(radioObj) {
	//alert(radioObj.name);
	var rvalue="";
	if(!radioObj){
		rvalue="";
	} else {		
		var radioLength = radioObj.length;


		
		if(radioLength == undefined){
				//alert("Not radio - check box Value:"+radioObj.value);
				if(radioObj.checked)
					rvalue="1";
				else
					rvalue="2";
				
					rvalue = radioObj.value;
			} else {
				
				//alert("Radio:"+radioLength);
				
				for(var i = 0; i < radioLength; i++) {
					//alert("Pos:"+i+":"+radioObj[i].value);
					if(radioObj[i].selected) {
						rvalue=radioObj[i].value;
					}					
					if(radioObj[i].checked) {
						rvalue=radioObj[i].value;
					}
				}
			}
	}
	
	//alert("Selected Value:"+rvalue);
	return rvalue;
	
	
}
 
function get_extra(){		
		
	//1 Try At Home
	//2 Vision Type 
	//3 Colour
	//4 Bridge
	//5 Lens Thickness
	//6 Lens Type
	//7 Anti-Reflective
	//8 Scratch Resistance
	//9 UV 400 Protection
	//10 Lens Tint
	//11 Tint Colour		
				
	//perms[0]='1:-1|2:1|3:-1|4:-1|5:1|6:1|7:1|8:-1|9:1|10:1|11:-1|';
		
	//2		lens_type_obj = returnObjById(lens_type);	
	//5		lens_thickness_obj = returnObjById(lens_thickness);	
	//6		lens_coating_obj = returnObjById(lens_coating);	
	//7		lens_tint_obj = returnObjById(lens_tint);		
	//9		tint_colour_obj = returnObjById(tint_colour);	
	//10 
	
	//	Find the permutation that fits this combination selected.		
	//alert(product_id);
	var a=getCheckedValue(returnObjById ('v_'+product_id+'_2'));	
	var b=getCheckedValue(document.forms['shopping_cart'].elements['v_'+product_id+'_5']);		
	var c=getCheckedValue(document.forms['shopping_cart'].elements['v_'+product_id+'_6']);	
	var d=getCheckedValue(returnObjById ('v_'+product_id+'_7'));	
	var e=getCheckedValue(returnObjById ('v_'+product_id+'_9'));	
	var f=getCheckedValue(document.forms['shopping_cart'].elements['v_'+product_id+'_10']);	
	var g=getCheckedValue(document.forms['shopping_cart'].elements['v_'+product_id+'_1']);	
	
	//alert("a="+a+"b="+b+"c="+c+"d="+d+"e="+e+"f="+f+"g="+g);	
 
	//  Match these values
	
	var pmatch_value = new Array(6);
	var pmatch_loc = new Array(6);
	var pmatch_default = new Array(6);	
	var pmatch_total = 7;
	
	pmatch_loc[0] = 0;
	pmatch_value[0] = g;
	pmatch_default[0] = 2;
	
	pmatch_loc[1] = 1;
	pmatch_value[1] = a;
	pmatch_default[1] = 1;	
	
	pmatch_loc[2] = 4;
	pmatch_value[2] = b;
	pmatch_default[2] = 1;	
	
	pmatch_loc[3] = 5;
	pmatch_value[3] = c;
	pmatch_default[3] = 1;	
	
	pmatch_loc[4] = 6;
	pmatch_value[4] = d;
	pmatch_default[4] = 1;	
	
	pmatch_loc[5] = 8;
	pmatch_value[5] = e;	
	pmatch_default[5] = 1;				
	
	pmatch_loc[6] = 9;
	pmatch_value[6] = f;	
	pmatch_default[6] = 1;					
	
	//	Got chosen values, find the perm
	var lprice=0;
	var pfind=0;
	var found=false;
	var local_found = true;
	var temp;
	
	for (i=0;i<total_perms;i++){
	//for (i=0;i<1;i++){		 
		//	Check to see if *all* selected vals match
		local_found=true;
		for (d=0;d<pmatch_total;d++){
			
			pfind = pmatch_loc[d];

			temp = fdata[i][pfind];
									
			// Fix for items that have only 1 selection - Will always be the first.
			// Unless it is try at home, in which case it will be 2 :)
			if (temp==-1){
				temp=pmatch_default[d];
			}

			if (i==129){
				//alert(temp+":"+pmatch_value[d]);			
			}
			if (temp!=pmatch_value[d]){				
				local_found=false;
				//alert('Different');
			}
			
		}
		
		if (local_found){
			//alert("Found:"+i);
			lprice = price[i];			
			i=total_perms+1;
		}
		
		
	}			
	
	return lprice;
	
}
 
function update_price(){				

	if (prices_loaded){
	} else {
		split_prices();
		prices_loaded = true;
	}
	var extra;
	
	extra = (get_extra()/100);

	//alert(base_price);
	//alert(extra);

	var new_price = base_price + extra;
	
	
	
	var nf = new NumberFormat(new_price);
	nf.setPlaces(2);
	nf.setSeparators(false);
	new_price = nf.toFormatted();

	var price_display_ele = returnObjById('price_display');
	
	price_display_ele.innerText = "£"+new_price+" ";
	
}


function interactive_onchange(obj_name){
	
	obj_value = returnObjById(obj_name).value;
	
	process_choice(obj_name,obj_value);
	
	update_price();
	
}

function set_checked(element_name){
		
	var element = returnObjById(element_name);
	var element_box = returnObjById('check_'+element_name);

	if (element_box.checked == true){
		element.value="1";
	}
	else {
		element.value="2";
	}
	
	update_price();

}

function interactive_onclick(obj_name,obj_value){
	
	//  alert('Change:'+obj_name+' Value:'+obj_value);
	
	process_choice(obj_name,obj_value);
	if (calculate_price){
		update_price();
	}
	
}

function interactive_enable_all(){
	
	set_objects();
	
	element_check(lens_thickness,0);
	element_check(lens_coating,0);
	element_check(lens_tint,0);
	element_check(tint_colour,0);

}

function isdefined( variable)
{
    return (typeof(variable) == "undefined")?  false: true;
}

function set_label(pobj,poffset,pdata){
	
	var ele;
	ele = 'label_'+pobj+"_"+poffset;
	ele = returnObjById(ele);
	ele.innerHTML = pdata;
	
}

function set_objects(){
	
	form_obj=document.forms['shopping_cart'];	

	if (isdefined(product_id)){
		
		lens_type='v_'+product_id+'_2';
		lens_thickness='v_'+product_id+'_5';
		lens_coating='v_'+product_id+'_6';
		lens_tint='v_'+product_id+'_10';		
		tint_colour='v_'+product_id+'_11';	
		
		lens_type_obj = returnObjById(lens_type);	
		lens_thickness_obj = returnObjById(lens_thickness);	
		lens_coating_obj = returnObjById(lens_coating);	
		lens_tint_obj = returnObjById(lens_tint);		
		tint_colour_obj = returnObjById(tint_colour);	
	}
}

	var lens_type;
	var lens_type_obj;
	var lens_thickness;
	var lens_thickness_obj;	
	var lens_coating;
	var lens_coating_obj;	
	var lens_tint;
	var lens_tint_obj;		
	var tint_colour;	
	var tint_colour_obj;		
	var form_obj;

function process_choice(obj_name,obj_value){
	
	set_objects();
	
	switch (obj_name)
  {
    case lens_type: { select_lens_type(obj_value); break }
    case lens_thickness: { ; break }
    case lens_coating: {select_lens_coating(obj_value) ; break }
    case lens_tint: { select_lens_tint(obj_value) ; break }
    case tint_colour: { ; break }        
  }
  
}

function default_settings(){

		set_objects();
		
		// Disable all colours
  		element_disable(tint_colour,-1,0);	
  		
}

function select_lens_tint(obj_value){

	switch (obj_value)
  {
  	case '1': {
  		// None

  		// Disable all colours
  		element_disable(tint_colour,-1,0);	
  		
  		break;
  	}  	
  	case '2': {
  		// None
  		
  		// Enable all colours, disable clear
  		element_enable(tint_colour,-1,0);	
  		element_disable(tint_colour,0,1);
			element_disable(tint_colour,2,1);  	
			element_disable(tint_colour,3,1);		
			element_disable(tint_colour,6,1);						
  		element_select(lens_coating,0);	
  		
  		break;
  	}
  	case '3': {
  		// None
  		
  		// Enable all colours, disable clear
  		element_enable(tint_colour,-1,0);	
  		element_disable(tint_colour,0,1);
			element_disable(tint_colour,2,1);  	
			element_disable(tint_colour,3,1);		
			element_disable(tint_colour,6,1);	
  		element_select(lens_coating,0);	
  		
  		break;
  	}  	
	}
}

function select_lens_coating(obj_value){

	switch (obj_value)
  {
  	case '1': {
  		// None
  		
  		// Disable all colours
  		element_disable(tint_colour,-1,0);	
  		//	Enable the lens Tint	  		
  		element_enable(lens_tint,-1);	

  		
  		break;
  	}
  	case '2': {
  		//	Polarised  		
  		
  		//	Diasble the lens Tint	  		
  		//element_disable(lens_tint,-1,0);	
  		element_select(lens_tint,0);	
 			//	Enable only Brown and Grey
 			element_disable(tint_colour,0,4);
 			element_disable(tint_colour,1,4);	
 			element_disable(tint_colour,2,4);	
 			element_disable(tint_colour,3,4);	
 			element_disable(tint_colour,6,4);	
			element_disable(tint_colour,7,4);	 			 
 			element_enable(tint_colour,4,0);	 
 			element_enable(tint_colour,5,0);	  			 			
 						 			 			 					
 					
  		break;
  	}
  	case '3': {
  		//	Transition			
  		
  		//	Diasble the lens Tint	  		
  		//element_disable(lens_tint,-1,0);		
  		element_select(lens_tint,0);
 			//	Enable only Brown and Grey
 			element_disable(tint_colour,0,4);
 			element_disable(tint_colour,1,4);	
 			element_disable(tint_colour,2,4);	
 			element_disable(tint_colour,3,4);	
 			element_disable(tint_colour,6,4);	 
 			element_disable(tint_colour,7,4);	
 			element_enable(tint_colour,4,0);	 
 			element_enable(tint_colour,5,0);	 
 			  		
  						
  		break;
  	}
  	case '4': {
  		//	Dark Sunglasses Tint  	
  		
  		//	Diasble the lens Tint	
  		//element_disable(lens_tint,-1,0);		
  	  element_select(lens_tint,0);
  	  //	Enable all colours
  		element_enable(tint_colour,-1,0);
   		element_disable(tint_colour,0,1);
   		element_disable(tint_colour,7,1);   		
  			  		
  		break;
  	}  	  	
  }

}


function select_lens_type(obj_value){
	
	switch (obj_value)
  {
  	case '1': {
  		
  		//	Single Vision
			
			element_enable(lens_thickness,-1);	
			element_enable(lens_coating,-1);	
			
			//	Set prices
			
			set_label(lens_coating,2,'Polarised (£60)');
			set_label(lens_coating,3,'Transition (£50)');			
			
			
  		break;
  	}
  	case '2': {	
			
  		//	Bifocal
  	
  		element_enable(lens_thickness,0);
  		element_disable(lens_thickness,1,0);		
  		element_disable(lens_thickness,2,0);
  		
			element_enable(lens_coating,-1);
  					
			//	Set prices
  					
  		set_label(lens_coating,2,'Polarised (£90)');
			set_label(lens_coating,3,'Transition (£80)');	  		
			
  		break;
  	}
  	case '3': {
  		//	Varifocal
  		
  		element_enable(lens_thickness,0);  		
  		element_disable(lens_thickness,1,0);		
  		element_disable(lens_thickness,2,0);
  		
  		element_disable(lens_coating,1,0);
  		
			//	Set prices
			
			set_label(lens_coating,2,'Polarised (Not available)'); 
			set_label(lens_coating,3,'Transition (£80)');			 		
  		
  		break;
  	}  	  	
  }
	
}

function element_check(obj,ele){
	
	//	Check all radio elements
	//	If all disabled, then enable the element sent in parameter.
	
	var all_disabled = true;
	var item_disabled;
	var items;
	
	eval('items = form_obj.'+obj+'.length;');
	
	for (var i=0;i<items;i++){
			eval('item_disabled = form_obj.'+obj+'['+i+'].disabled;');
			if (item_disabled==false){
				all_disabled = false;
			}							
	}
	if (all_disabled){
		element_select(obj,ele);
	}
}

function element_select(obj,ele){
	
	element_enable(obj,ele);
	eval('form_obj.'+obj+'['+ele+'].checked=true;');
	
}

function element_enable(obj,ele){
	
	var items;
	eval('items = form_obj.'+obj+'.length;');
	
	if (ele==-1){
		//	Enable All
		for (var i=0;i<items;i++){
			eval('form_obj.'+obj+'['+i+'].disabled=false;');
		}
	} else {
		//	Enable Ele.
		eval('form_obj.'+obj+'['+ele+'].disabled=false;');		
	}
}
function element_disable(obj,ele,zeroset){
	
	var items;
	var item_selected;
	
	eval('items = form_obj.'+obj+'.length;');
	

	if (ele==-1){
		//	Disable All
		for (var i=0;i<items;i++){
			eval('form_obj.'+obj+'['+zeroset+'].checked=true;');	
			eval('form_obj.'+obj+'['+i+'].disabled=true;');
		}
	} else {
		//	If element is selected, then select the zero set
		var item_checked;
		eval('item_checked = form_obj.'+obj+'['+ele+'].checked;');
		if (item_checked){
				//	Item was checked, so select the zero item.
				eval('form_obj.'+obj+'['+zeroset+'].checked=true;');	
		} 
		//	Disable Ele.		
		eval('form_obj.'+obj+'['+ele+'].disabled=true;');		
	}
}

function returnObjById( id ) 
{ 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar; 
}


// mredkj.com
function NumberFormat(num, inputDecimal)
{
this.VERSION = 'Number Format v1.5.4';
this.COMMA = ',';
this.PERIOD = '.';
this.DASH = '-'; 
this.LEFT_PAREN = '('; 
this.RIGHT_PAREN = ')'; 
this.LEFT_OUTSIDE = 0; 
this.LEFT_INSIDE = 1;  
this.RIGHT_INSIDE = 2;  
this.RIGHT_OUTSIDE = 3;  
this.LEFT_DASH = 0; 
this.RIGHT_DASH = 1; 
this.PARENTHESIS = 2; 
this.NO_ROUNDING = -1 
this.num;
this.numOriginal;
this.hasSeparators = false;  
this.separatorValue;  
this.inputDecimalValue; 
this.decimalValue;  
this.negativeFormat; 
this.negativeRed; 
this.hasCurrency;  
this.currencyPosition;  
this.currencyValue;  
this.places;
this.roundToPlaces; 
this.truncate; 
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF; 
this.setSeparators = setSeparatorsNF; 
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF; 
this.setNegativeRed = setNegativeRedNF; 
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF; 
this.setCurrencyPosition = setCurrencyPositionNF; 
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.moveDecimalRight = moveDecimalRightNF;
this.moveDecimalLeft = moveDecimalLeftNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.expandExponential = expandExponentialNF;
this.getZeros = getZerosNF;
this.moveDecimalAsString = moveDecimalAsStringNF;
this.moveDecimal = moveDecimalNF;
this.addSeparators = addSeparatorsNF;
if (inputDecimal == null) {
this.setNumber(num, this.PERIOD);
} else {
this.setNumber(num, inputDecimal); 
}
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH); 
this.setNegativeRed(false); 
this.setCurrency(false); 
this.setCurrencyPrefix('$');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num, inputDecimal)
{
if (inputDecimal != null) {
this.setInputDecimal(inputDecimal); 
}
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.COMMA;
if (decimal == null) decimal = this.PERIOD;
if (separator == decimal) {
this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
} else {
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.COMMA, this.PERIOD);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp
}
function setPlacesNF(p, tr)
{
this.roundToPlaces = !(p == this.NO_ROUNDING); 
this.truncate = (tr != null && tr); 
this.places = (p < 0) ? 0 : p; 
}
function addSeparatorsNF(nStr, inD, outD, sep)
{
nStr += '';
var dpos = nStr.indexOf(inD);
var nStrEnd = '';
if (dpos != -1) {
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
nStr = nStr.substring(0, dpos);
}
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + sep + '$2');
}
return nStr + nStrEnd;
}
function toFormattedNF()
{	
var pos;
var nNum = this.num; 
var nStr;            
var splitString = new Array(2);   
if (this.roundToPlaces) {
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum)); 
} else {
nStr = this.expandExponential(Math.abs(nNum)); 
}
if (this.hasSeparators) {
nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue);
} else {
nStr = nStr.replace(new RegExp('\\' + this.PERIOD), this.decimalValue); 
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
} else if (this.currencyPosition == this.LEFT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0) {
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getZerosNF(places)
{
var extraZ = '';
var i;
for (i=0; i<places; i++) {
extraZ += '0';
}
return extraZ;
}
function expandExponentialNF(origVal)
{
if (isNaN(origVal)) return origVal;
var newVal = parseFloat(origVal) + ''; 
var eLoc = newVal.toLowerCase().indexOf('e');
if (eLoc != -1) {
var plusLoc = newVal.toLowerCase().indexOf('+');
var negLoc = newVal.toLowerCase().indexOf('-', eLoc); 
var justNumber = newVal.substring(0, eLoc);
if (negLoc != -1) {
var places = newVal.substring(negLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
} else {
if (plusLoc == -1) plusLoc = eLoc;
var places = newVal.substring(plusLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
}
newVal = justNumber;
}
return newVal;
} 
function moveDecimalRightNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, false);
} else {
newVal = this.moveDecimal(val, false, places);
}
return newVal;
}
function moveDecimalLeftNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, true);
} else {
newVal = this.moveDecimal(val, true, places);
}
return newVal;
}
function moveDecimalAsStringNF(val, left, places)
{
var spaces = (arguments.length < 3) ? this.places : places;
if (spaces <= 0) return val; 
var newVal = val + '';
var extraZ = this.getZeros(spaces);
var re1 = new RegExp('([0-9.]+)');
if (left) {
newVal = newVal.replace(re1, extraZ + '$1');
var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');		
newVal = newVal.replace(re2, '$1$2.$3');
} else {
var reArray = re1.exec(newVal); 
if (reArray != null) {
newVal = newVal.substring(0,reArray.index) + reArray[1] + extraZ + newVal.substring(reArray.index + reArray[0].length); 
}
var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
newVal = newVal.replace(re2, '$1$2$4.');
}
newVal = newVal.replace(/\.$/, ''); 
return newVal;
}
function moveDecimalNF(val, left, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimalAsString(val, left);
} else {
newVal = this.moveDecimalAsString(val, left, places);
}
return parseFloat(newVal);
}
function getRoundedNF(val)
{
val = this.moveDecimalRight(val);
if (this.truncate) {
val = val >= 0 ? Math.floor(val) : Math.ceil(val); 
} else {
val = Math.round(val);
}
val = this.moveDecimalLeft(val);
return val;
}
function preserveZerosNF(val)
{
var i;
val = this.expandExponential(val);
if (this.places <= 0) return val; 
var decimalPos = val.indexOf('.');
if (decimalPos == -1) {
val += '.';
for (i=0; i<this.places; i++) {
val += '0';
}
} else {
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++) {
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
newVal = val + '';
var isPercentage = false;
if (newVal.indexOf('%') != -1) {
newVal = newVal.replace(/\%/g, '');
isPercentage = true; 
}
var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)eE]', 'g');	
newVal = newVal.replace(re, '');
var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
var treArray = tempRe.exec(newVal); 
if (treArray != null) {
var tempRight = newVal.substring(treArray.index + treArray[0].length); 
newVal = newVal.substring(0,treArray.index) + this.PERIOD + tempRight.replace(tempRe, ''); 
}
if (newVal.charAt(newVal.length - 1) == this.DASH ) {
newVal = newVal.substring(0, newVal.length - 1);
newVal = '-' + newVal;
}
else if (newVal.charAt(0) == this.LEFT_PAREN
&& newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN) {
newVal = newVal.substring(1, newVal.length - 1);
newVal = '-' + newVal;
}
newVal = parseFloat(newVal);
if (!isFinite(newVal)) {
newVal = 0;
}
if (isPercentage) {
newVal = this.moveDecimalLeft(newVal, 2);
}
return newVal;
}
