
var arr= new Array();

arr['mincarat']=0.20;
arr['maxcarat']=10.00; 
arr['mincolour']='J';
arr['maxcolour']='D'; 
arr['minclarity']='I2';
arr['maxclarity']='IF'; 
arr['mincut']='Good'; 
arr['maxcut']='Ideal'; 
arr['minprice']=500; 
arr['maxprice']=150000; 
arr['shape']='round';

var colour_arr= new Array();
colour_arr[0]='D';
colour_arr[1]='E';
colour_arr[2]='F';
colour_arr[3]='G';
colour_arr[4]='H';
colour_arr[5]='I';
colour_arr[6]='J';
colour_arr[7]='K';

var clarity_arr= new Array();
clarity_arr[0]='IF';
clarity_arr[1]='VVS1';
clarity_arr[2]='VVS2';
clarity_arr[3]='VS1';
clarity_arr[4]='VS2';
clarity_arr[5]='SI1';
clarity_arr[6]='SI2';
clarity_arr[7]='I1';
clarity_arr[8]='I2';


var cut_arr= new Array();
cut_arr[0]='Ideal';
cut_arr[1]='Excellent';
cut_arr[2]='Very Good';
cut_arr[3]='Good';

var carat_arr= new Array();
carat_arr[0]=10.00;
carat_arr[1]=5.00;
carat_arr[2]=4.50;
carat_arr[3]=4.00;
carat_arr[4]=3.50;
carat_arr[5]=3.00;
carat_arr[6]=2.50;
carat_arr[7]=2.00;
carat_arr[8]=1.50;
carat_arr[9]=1.25;
carat_arr[10]=1.10;
carat_arr[11]=1.00;
carat_arr[12]=0.90;
carat_arr[13]=0.80;
carat_arr[14]=0.70;
carat_arr[15]=0.60;
carat_arr[16]=0.50;
carat_arr[17]=0.40;
carat_arr[18]=0.30;
carat_arr[19]=0.20;

var price_arr= new Array();
price_arr[0]=150000;
price_arr[1]=100000;
price_arr[2]=75000;
price_arr[3]=50000;
price_arr[4]=40000;
price_arr[5]=30000;
price_arr[6]=20000;
price_arr[7]=15000;
price_arr[8]=10000;
price_arr[9]=7500;
price_arr[10]=5000;
price_arr[11]=4500;
price_arr[12]=4000;
price_arr[13]=3500;
price_arr[14]=3000;
price_arr[15]=2500;
price_arr[16]=2000;
price_arr[17]=1500;
price_arr[18]=1000;
price_arr[19]=500;

function updatevaluebyuser()
{
	
	url=location.href.toLowerCase();
	// if in the build your own and set the cookie then....
	//alert("updatevlauebyuser "+url);
	if ((url.indexOf("m_engagement_ring_build.aspx") != -1) || (url.indexOf("m_Engagement_Ring_Build.aspx") != -1)){
		cookie_BYOShape=getCookieValue('BYOShape');
		if (cookie_BYOShape != null) {
			updatevaluesbyBYOcookies(cookie_BYOShape);
			return;
		}
		else
		{
			updatevaluesbyBYOcookies('round');
			return;
		}
	}
	//check if have done previouse diamond search (like back button)
	cookie_diamond_search=getCookie('diamondsearch');
	if (cookie_diamond_search!=null) {
		updatevaluesbycookies(cookie_diamond_search);
		return;
	}
	updatevaluesbyquerystr();
	
}

function updatevaluesbyBYOcookies(cookie_BYOShape)
{

	arr['shape']=cookie_BYOShape.toLowerCase();
	document.getElementById('rbtn_'+arr['shape']).checked=true;
	cookie_diamond_search=getCookie('diamondsearch');
	if (cookie_diamond_search!=null) {
		param=cookie_diamond_search.split(";");
	
			
		tmp_val=param[0].split("=");
		arr['mincarat']=tmp_val[1];
	
		tmp_val=param[1].split("=");
		arr['maxcarat']=tmp_val[1];
	
	
		tmp_val=param[2].split("=");
		arr['mincolour']=tmp_val[1];

		tmp_val=param[3].split("=");
		arr['maxcolour']=tmp_val[1];

		tmp_val=param[4].split("=");
		arr['minclarity']=tmp_val[1];
	
		tmp_val=param[5].split("=");
		arr['maxclarity']=tmp_val[1];

		tmp_val=param[6].split("=");
		arr['mincut']=tmp_val[1];


		tmp_val=param[7].split("=");
		arr['maxcut']=tmp_val[1];

		tmp_val=param[8].split("=");
		arr['minprice']=tmp_val[1];

		tmp_val=param[9].split("=");
		arr['maxprice']=tmp_val[1];

	}
}

function getCookieValue(name) 
{	
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));

}
function updatevaluesbyquerystr()
{
	if(getQueryStringVar('CaratMaximum')!=null)	
		arr['maxcarat']=getQueryStringVar('CaratMaximum');
	if(getQueryStringVar('CaratMinimum')!=null)
		arr['mincarat']=getQueryStringVar('CaratMinimum');
	if(getQueryStringVar('PriceMaximum')!=null)
		arr['maxprice']=getQueryStringVar('PriceMaximum');
	if(getQueryStringVar('PriceMinimum')!=null)
		arr['minprice']=getQueryStringVar('PriceMinimum');
	//if(getQueryStringVar('ClarityMaximum')!=null)	
	//	arr['maxclarity']=getQueryStringVar('ClarityMaximum');
	//if(getQueryStringVar('ClarityMinimum')!=null)
	//	arr['minclarity']=getQueryStringVar('ClarityMinimum');
	if(getQueryStringVar('Shape')!=null)
		arr['shape']=getQueryStringVar('Shape').toLowerCase();;
	document.getElementById('rbtn_'+arr['shape']).checked=true;
	//if(getQueryStringVar('Shape')==null)
	//	showHideItems('diamond_shape', 'img_diamond_shape');
	
}

function updatevaluesbycookies(cookie_diamond_search)
{
	param=cookie_diamond_search.split(";");
	
	
	tmp_val=param[0].split("=");
	arr['mincarat']=tmp_val[1];
	
	tmp_val=param[1].split("=");
	arr['maxcarat']=tmp_val[1];
	

	tmp_val=param[2].split("=");
	arr['mincolour']=tmp_val[1];

	tmp_val=param[3].split("=");
	arr['maxcolour']=tmp_val[1];

	tmp_val=param[4].split("=");
	arr['minclarity']=tmp_val[1];
	
	tmp_val=param[5].split("=");
	arr['maxclarity']=tmp_val[1];

	tmp_val=param[6].split("=");
	arr['mincut']=tmp_val[1];


	tmp_val=param[7].split("=");
	arr['maxcut']=tmp_val[1];

	tmp_val=param[8].split("=");
	arr['minprice']=tmp_val[1];

	tmp_val=param[9].split("=");
	arr['maxprice']=tmp_val[1];

	tmp_val=param[10].split("=");
	arr['shape']=tmp_val[1];
	document.getElementById('rbtn_'+arr['shape']).checked=true;

		
}



function updatesliders()
{
	getDiamondAjax(arr);
}

function getpositionbyval(tmparr, value)
{
	for(var i=0; i < tmparr.length; ++i)
	{
		if(tmparr[i] == value)
			return i;
		
	}
	for(var i=0; i < tmparr.length -1; ++i)
	{
		if((tmparr[i] > value) && (tmparr[i+1] < value))
			return i+1;
	}
	return 0;
}

function init_slider(name)
{
  mySlider2 = new Bs_Slider();
  
  mySlider2.attachOnChange(bsSliderChange);
  mySlider2.attachOnSlideEnd(bsSliderRelease);
  mySlider2.direction     = 1;
  mySlider2.width         = 50;
  mySlider2.height        = 150;
  mySlider2.imgDir   = '/javascript/images/';
 
  
  mySlider2.fieldName     = 'slider2_start';
  //FOR EACH ON OF THE SLIDER	 
  getvaluesbyname(name,mySlider2);
 

  mySlider2.setSliderIcon('down-arrow.gif', 50, 11);
  mySlider2.useInputField = 3;
  mySlider2.styleValueFieldClass = 'sliderInput';
  mySlider2.colorbar = new Object({ color:'#E7E1CB', width:20, widthDifference:30, offsetLeft:0, offsetTop:0 });
	
  mySlider2.useSecondKnob        = true;
  mySlider2.preventValueCrossing = true;
  mySlider2.wheelAmount        = 0; //disable mouse wheeling cause we have 2 knobs.
	
  mySlider2.fieldName2     = 'slider2_end';
  

  mySlider2.setSliderIcon2('up-arrow.gif', 50, 11);

  mySlider2.useInputField2 = 3;
  mySlider2.styleValueFieldClass2 = 'sliderInput';

  mySlider2.colorbar2 = new Object({ color:'#E7E1CB', width:20, widthDifference:-21, offsetLeft:0, offsetTop:0 });
	
  mySlider2.drawInto(name);		


}
function getDiamond(key,value)
{
   	arr[key]=value;
	getDiamondAjax(arr);
	setCookie();

}


function bsSliderRelease(obj) {
	getslidervaluebyname(obj.divname ,obj);
	setCookie();
}
function bsSliderChange(obj) {
	
	switch (obj.divname) {
		case 'sliderDivCarat':
			calcCarat(obj);
			break;
		case 'sliderDivPrice':
			calcPrice(obj);
			break;
	}
	
}
function getslidervaluebyname(name,obj)
{
	switch (name) {
		case 'sliderDivCarat':
			//alert('carat change');
			calcCarat(obj);
			break;
		case 'sliderDivPrice':
			calcPrice(obj);
			break;
		case 'sliderDivColour':
			calcColour(obj);
			break;
		case 'sliderDivCut':
			calcCut(obj);
			break;
		case 'sliderDivClarity':
			calcClarity(obj);
			break;
	}
	getDiamondAjax(arr);
}
function calcCut(obj)
{
	arr['maxcut']= cut_arr[obj.getValue()];
	arr['mincut']= cut_arr[obj.getValue2()-1];
	
}
function calcColour(obj)
{
	arr['maxcolour']= colour_arr[obj.getValue()];
	arr['mincolour']= colour_arr[obj.getValue2()-1]; 
}
function calcClarity(obj)
{

	arr['maxclarity']= clarity_arr[obj.getValue()];
	arr['minclarity']= clarity_arr[obj.getValue2()-1];
}
function calcCarat(obj)
{
	tmpmax_c=carat_arr[obj.getValue()];
	tmpmin_c=carat_arr[obj.getValue2()-1];
	if (tmpmax_c == tmpmin_c)
		tmpmax_c=tmpmax_c + 0.01;
	arr['mincarat']= tmpmin_c;
	arr['maxcarat']= tmpmax_c;
	if (tmpmax_c.toFixed)
	{
		document.getElementById('carat_max_out').innerHTML =tmpmax_c.toFixed(2);
		document.getElementById('carat_min_out').innerHTML =tmpmin_c.toFixed(2);
	}else
	{
		document.getElementById('carat_max_out').innerHTML =tmpmax_c;
		document.getElementById('carat_min_out').innerHTML =tmpmin_c ;
	}
	
	
}
function calcPrice(obj)
{
	tmpmax_p= price_arr[obj.getValue()];
	tmpmin_p= price_arr[obj.getValue2()-1];
	if (tmpmax_p == tmpmin_p)
		tmpmax_p=tmpmax_p + 250;
	
	arr['minprice']= tmpmin_p;
	arr['maxprice']= tmpmax_p ;
	
	tmp_max = new NumberFormat(tmpmax_p);
	tmp_min = new NumberFormat(tmpmin_p);

	
	tmp_max.setPlaces(0);
	tmp_min.setPlaces(0);
	tmp_max.setCommas(true);
	tmp_min.setCommas(true);

	document.getElementById('price_max_out').innerHTML ="$" + tmp_max.toFormatted(); 
	document.getElementById('price_min_out').innerHTML ="$" + tmp_min.toFormatted(); 
	

}
function getvaluesbyname(name,myslider2) {
	
	switch (name) {
		case 'sliderDivCarat':
			mySlider2.setBackgroundImage('bg-carat.jpg', 'no-repeat');
			mySlider2.minVal        = 0;
 			mySlider2.maxVal        = 20;
 			mySlider2.valueInterval = 1;
 			mySlider2.valueDefault  = getpositionbyval(carat_arr,arr['maxcarat']);
			mySlider2.minVal2        = 0;
  			mySlider2.maxVal2        = 20;
		  	mySlider2.valueInterval2 = 1;
	  		mySlider2.valueDefault2  = getpositionbyval(carat_arr,arr['mincarat'])+1;

			document.getElementById('carat_max_out').innerHTML =carat_arr[getpositionbyval(carat_arr,arr['maxcarat'])].toFixed(2);
			document.getElementById('carat_min_out').innerHTML =carat_arr[getpositionbyval(carat_arr,arr['mincarat'])].toFixed(2);
			break;
		case 'sliderDivPrice':
			mySlider2.setBackgroundImage('bg-price.jpg', 'no-repeat');
			mySlider2.minVal        = 0;
 			mySlider2.maxVal        = 20;
 			mySlider2.valueInterval = 1;
 			mySlider2.valueDefault  = getpositionbyval(price_arr,arr['maxprice']);
			mySlider2.minVal2        = 0;
  			mySlider2.maxVal2        = 20;
		  	mySlider2.valueInterval2 = 1;
	  		mySlider2.valueDefault2  = getpositionbyval(price_arr,arr['minprice'])+1;
			
			
			tmpmax_p= price_arr[getpositionbyval(price_arr,arr['maxprice'])];
			tmpmin_p= price_arr[getpositionbyval(price_arr,arr['minprice'])];

			tmp_max = new NumberFormat(tmpmax_p);
			tmp_min = new NumberFormat(tmpmin_p);
			tmp_max.setPlaces(0);
			tmp_min.setPlaces(0);
			tmp_max.setCommas(true);
			tmp_min.setCommas(true);

			document.getElementById('price_max_out').innerHTML ="$" + tmp_max.toFormatted(); 
			document.getElementById('price_min_out').innerHTML ="$" + tmp_min.toFormatted(); 
			break;
		case 'sliderDivColour':
		      mySlider2.setBackgroundImage('bg-colour.jpg', 'no-repeat');
			mySlider2.minVal        = 0;
 			mySlider2.maxVal        = 7;
 			mySlider2.valueInterval = 1;
 			mySlider2.valueDefault  = getpositionbyval(colour_arr,arr['maxcolour']);
			mySlider2.minVal2        = 0;
  			mySlider2.maxVal2        = 7;
		  	mySlider2.valueInterval2 = 1;
	  		mySlider2.valueDefault2  = getpositionbyval(colour_arr,arr['mincolour'])+1;
			break;
		case 'sliderDivCut':
			mySlider2.setBackgroundImage('bg-cut.jpg', 'no-repeat');
			mySlider2.minVal        = 0;
 			mySlider2.maxVal        = 4;
 			mySlider2.valueInterval = 1;
 			mySlider2.valueDefault  = getpositionbyval(cut_arr,arr['maxcut']);
			mySlider2.minVal2        = 0;
  			mySlider2.maxVal2        = 4;
		  	mySlider2.valueInterval2 = 1;
	  		mySlider2.valueDefault2  = getpositionbyval(cut_arr,arr['mincut'])+1;
			break;
		case 'sliderDivClarity':
			mySlider2.setBackgroundImage('bg-clarity.jpg', 'no-repeat');
			mySlider2.minVal        = 0;
 			mySlider2.maxVal        = 9;
 			mySlider2.valueInterval = 1;
 			mySlider2.valueDefault  = getpositionbyval(clarity_arr,arr['maxclarity']);
			mySlider2.minVal2        = 0;
  			mySlider2.maxVal2        = 9;
		  	mySlider2.valueInterval2 = 1;
	  		mySlider2.valueDefault2  = getpositionbyval(clarity_arr,arr['minclarity'])+1;
			break;
	}
}


function getpricebypos(position)
{
	max =150000;//_global.maxprice;
	min = 500;//_global.minprice;
	
	maxposval = (200*200*200);
	xtogettomax = (max-min)/maxposval;
	tmp = 200  - position;
	valByPos = ((tmp * tmp * tmp ) * xtogettomax) + min;
	rlength = 0; // The number of decimal places to round to
	
	
	return Math.round(valByPos*Math.pow(10,rlength))/Math.pow(10,rlength);
	
	 
}

function getcaratbypos(position)
{
	max = 10;
	min = 0.30;
	
	maxposval = (1000*1000*1000);
	xtogettomax = (max-min)/maxposval;

	tmp = 1000  - position;
	valByPos = ((tmp * tmp * tmp) * xtogettomax) + min;
	rlength = 2; // The number of decimal places to round to
	

	return Math.round(valByPos*Math.pow(10,rlength))/Math.pow(10,rlength);
	
}

// Query String javascript ------------------------------------------------------------------------------------------------
function getQueryStringVar(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return null;
}


// COOKIE CODE --------------------------------------------------------------------------------------------------------------


function getCookie(NameOfCookie)
{

	if(document.cookie != "")
	{
		var my_cookie = unescape(document.cookie);
		//alert(document.cookie);
		if((my_cookie.indexOf(NameOfCookie))== -1)
			return null;
		//alert("after index of name");
 		var clipped_cookie = my_cookie.substring(my_cookie.indexOf(NameOfCookie), my_cookie.length);
		var parameter_array = clipped_cookie.split("//");
		return parameter_array[1];			
	}
	return null;
}

function setCookie()
{
	var expiredays = 2;
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

	var str_cookie_value = "Name=diamondsearch//";
	str_cookie_value+="mincarat="+arr['mincarat']+";";
	str_cookie_value+="maxcarat="+arr['maxcarat']+";";
	str_cookie_value+="mincolour="+arr['mincolour']+";";
	str_cookie_value+="maxcolour="+arr['maxcolour']+";";
	str_cookie_value+="minclarity="+arr['minclarity']+";";
	str_cookie_value+="maxclarity="+arr['maxclarity']+";";
	str_cookie_value+="mincut="+arr['mincut']+";";
	str_cookie_value+="maxcut="+arr['maxcut']+";";
	str_cookie_value+="minprice="+arr['minprice']+";";
	str_cookie_value+="maxprice="+arr['maxprice']+";";
	str_cookie_value+="shape="+arr['shape']+";";
	str_cookie_value+="expires=" + ExpireDate.toGMTString();
		
	
	document.cookie = escape(str_cookie_value);
}


/// NUMBER/PRICE HENDLING ---------------------------------------------------------------------------------------------------


// 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;
}

