/* functie setFocus(focusField) zorgt dat de focus op het met naam genoemde veld komt te staan.
Er wordt  uitgegaan van één formulier per pagina
authors: Robin Bakker & Joke Homan */
function setFocus(focusField)
{
	//document.forms[0][focusField].focus();
	fo[focusField].focus();
}

/* functie formatValue formatteert een getal zodat na elk
duidendtal een punt komt te staan. Voor een nagatief getal staat
een '-' 
authors: Robin Bakker & Joke Homan */
function formatValue(amount)
{
	var negative = "";
	if (amount < 0)
	{
		amount = Math.abs(amount);
		negative = "-";
	}

	var units = Math.floor(amount);
	amountstr=units.toString();   

	var temp="";
	iArray = new Array();
	var j=0;
	for(i=amountstr.length-3;i>-3;i=i-3)
	{
	  iArray[j] = amountstr.substring(i,i+3);
	  j++;
	  temp = "." + iArray[j-1]+ temp;
	}
	units = negative + temp.substring(1,temp.length);

	return units;
}

function onlineAfsluiten(url, product, isAutomaticSavingSelected, initialDepositAmount, periodicDepositAmount)
{
	var targetUrl = url;
	targetUrl += "?";
	targetUrl += "form_automaticSavingSelected=" + isAutomaticSavingSelected;
	targetUrl += "&form_initialDepositAmount=" + initialDepositAmount;
	targetUrl += "&form_periodicDepositAmount=" + periodicDepositAmount;

	from_popup(targetUrl);
	self.close();   
}

function onlineAanvragen(url, isAutomaticSavingSelected, initialDepositAmount, periodicDepositAmount)
{
	onlineAfsluiten(url, "", isAutomaticSavingSelected, initialDepositAmount, periodicDepositAmount);
}

/* functie activateSubmit() controleert of <enter> is gedrukt en zo ja, roept dan
de checkForm functie aan
authors: Robin Bakker & Joke Homan */
function activateSubmit(objForm) 
{
	if (document.all)
	{
		if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
		{
			if (checkForm(objForm))  // de checkform functie moet altijd bestaan in de JSP van het betreffende form
			{
				if (objForm != null) 
				{
					objForm.submit();
				}
				else
				{
					fo.submit();
				}
				return false;
			}
			return false;
		}
	}
	return true;
}

/* functie setForm() 'initialiseert' het form object
authors: Robin Bakker & Joke Homan */
var fo;
var fo2;
function setFO(formname, formname2)
{
	if (document.all || document.layers)
	{
		fo = document.forms[0];
		if (formname2 != "")
		{
			fo2 = document.forms[1];
		}
	}
	else
	{
		fo = document.getElementById(formname);
		if (formname2 != "")
		{
			fo2 = document.getElementById(formname2);
		}
	}
}

/* function stripPeriodsFromAmount() 
This function strips periods from a given value, normally an amount value.
author: John Hessing */
function stripPeriodsFromAmount(fieldobj)
{
	var newValue = "";
	var oneChar  = "";
	var amount   = fieldobj.value;

	for (i = 0; i < amount.length; i++)
	{
		oneChar = amount.substring(i,i+1);
		if (oneChar!='.')
			newValue = newValue + oneChar;
	}
	return newValue;	
}

/*
     remove illegal characters     
 */
var splChar = [ '<' , '>', ':' , '^','{','}','(',')'];
var charFound = false;
var tempQueryString = unescape(location.search.replace(/\+/g,  " "));
for ( var i=0 ;  i<splChar.length; i++)  {
	var regex = new RegExp("\\"+splChar[i],"gi");		
	if (tempQueryString.search(regex)!=-1)
	{
		charFound = true;
		tempQueryString = tempQueryString.replace(regex,"");
	}
}

if(charFound)	{
	location.search = tempQueryString;
}
