<!--
/**
 * common.js Common js functions
 */
/*
-------------------------------------------------------------------------------------------------
	Title:		Number to Words Converter
	Copyright:	Copyright � Demetrius Francis, 1998-1999.  All rights reserved.
	Author:		Demetrius Francis
	Contact:	dem_@hotmail.com	http://www.angelfire.com/de/draf/index.html

	License:	Freeware

	Obligation:	PLEASE READ CAREFULLY BEFORE COPYING OR DOWNLOADING.
				You are hereby granted a free user license to copy and use this script, provided you
				maintain the copyright notice and this license agreement at the begining of the script.
   ---------------------------------------------------------------------------------------------------*/
	popup=null
	setTimeout("if (popup != null && popup.name === 'Ad') popup.close()",3000)

	//aUnits=["","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"]
	//aTeens=["","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"]
	//aTens =["","Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"]

	aUnits=["","een","twee","drie","vier","vijf","zes","zeven","acht","negen"]
	aTeens=["","elf","twaalf","dertien","veertien","vijftien","zestien","zeventien","achtien","negentien"]
	aTens =["","tien","twintig","dertig","veertig","vijftig","zestig","zeventig","tachtig","negentig"]


	//these function perform the actual array manipulation.
	function getunits(xValue){return (aUnits[xValue])}
	function gethund(xValue){return (aUnits[xValue] != '') ? (aUnits[xValue]+' honderd') : (aUnits[xValue])}
	function teens(xValue){return (aTeens[xValue])}
	function tens(xValue){return (aTens[xValue])}

	//	--------------------------------------------------------------------
	//	stramt	= amount entered converted to a string
	//	sMax	= 12 (999 million max) minus the converted string length.
	//	cStringAmount	= actual dollars amount without decimal places.
	//	str1..str4	= break down of actual string
	//	--------------------------------------------------------------------

	function ConvertNumberToWords(nAmount){
		var sAmount=nAmount.toString();
		if (sAmount.indexOf(".") == -1) sAmount+='.00'		//if a decimal place is not given, then add it.
		var sMax = (12 - sAmount.length)					//Maximum of 12-length of the number given with decimals.

		var cStringAmount='';								//the string to be manipulated.
		var sNumberInWords	='';									//actual string of words being created [return value].

		for (c=1; c <=sMax; c++){ cStringAmount += '0'}		// pad the string with zero up to 12 characters (999 Million)
		sAmount=cStringAmount+sAmount;

		cStringAmount=sAmount.substring(0,9);				//9 digit value without the decimal places.
		var str1= sAmount.substring(0,3);
		var str2= sAmount.substring(3,6);
		var str3= sAmount.substring(6,9);
		var str4= sAmount.substring(10,12)

		//
		// --- Process Millions:- then reduce [cStringAmount] length.
		//
 		if (cStringAmount.length >= 7){
			sWords = NumberInWords(str1);
			if (sWords.length >= 3) sNumberInWords += sWords +" miljoen ";
			cStringAmount=cStringAmount.substring(3,9)
		}

		//
		// --- Process Thousands:- then reduce [cStringAmount] length.
		//
		if (cStringAmount.length >= 4){
			sWords = NumberInWords(str2)
			if (sWords.length >= 3) sNumberInWords += sWords +" duizend ";
	        cStringAmount = cStringAmount.substring(6,9)
        }


		//
		// --- Process Hundreds or Tens:- then reduce [cStringAmount] length.
		//
		if (cStringAmount.length <= 3){
			sWords = NumberInWords(str3);
			sNumberInWords += sWords+' '
		}

		//
		// --- Process Units:- then reduce [cStringAmount] length.
		//
		var sTens=gettens(str4);
		sTens=((sTens == " ") ? 'nul' : sTens)
		//sNumberInWords += ((sTens <= 0) ? '' : 'en '+sTens+' cent');		// optional if cents to be words.
 	  //sNumberInWords+='and '+str4+'/100'// optional if cents n/100.

    	return (sNumberInWords)
	}


	function NumberInWords(cString){
		// this function does the actual processing of getting the words.
 		xhund =gethund(cString.substring(0,1))
		xtens =gettens(cString.substring(1,3))
		xwords=xhund
		xwords+= ((xtens.length >= 3) ? ' ' : '')+xtens
		return (xwords);
	}

	function gettens(xValue){
		// -----------------------------------------------------------------------------
		//	This function accepts a two string parameter i.e.  "90", "12", "32" etc...
		//	xval_ = the first character.
		//	_xval = the second character.
		// -----------------------------------------------------------------------------

		xval_ =xValue.substring(0,1);
		_xval =xValue.substring(1,2);

		if (xval_ == '1' && _xval != '0') {xnum= teens(_xval)}

		if (xval_ == '1' && _xval == '0') xnum="Ten"

		if (xval_ != '1' && (_xval != '0' || _xval == '0')){
			xnum= tens(xval_)+" "+getunits(_xval);
		}

		return (xnum)
	}

//-->