/**
 *
 *
 *
 */

/*
var iPredefInputs = 1;
var iMinInputs    = 1;
var iMaxInputs    = 5;
*/
 
// function to send donations
function SendDonations()
{
	var oInForm   = this.document.donationForm;
	var bSendForm = false;
	var iErrorMsg = 0;
	
	// check if currency is selected ...
	var iCurrency    = 0;
	var bCurrencySel = false;
	
	for(i=0; i<oInForm.fDonorCurrency.length; i++)
	{
		if(oInForm.fDonorCurrency[i].checked)
		{
			iCurrency    = oInForm.fDonorCurrency[i].value;
			bCurrencySel = true;
			bSendForm    = true;
			iErrorMsg    = 0;
			break;
		}
	}
	
		// check if amount is selected ...
	if(bSendForm)
	{
		var iAmount = 0;
		var bAmountSel = false;
		
		for(i=0; i<oInForm.fDonorAmount.length; i++)
		{
			if(oInForm.fDonorAmount[i].checked)
			{
				iAmount    = oInForm.fDonorAmount[i].value;
				bAmountSel = true;
				bSendForm  = true;
				iErrorMsg  = 0;
				break;
			}
		}
	}
	
	// ... or inserted
	if(!bAmountSel)
	{
		if(isNumber(oInForm.fDonorOtherAmount.value))
		{
			bSendForm = true;
			iErrorMsg = 0;
		}
		else
		{
			bSendForm = false;
			iErrorMsg = 1;
		}
	}
	else
	{
		bSendForm = true;
		iErrorMsg = 0;
	}
	
	// check first name
	if(bSendForm)
	{
		if(isString(oInForm.fDonorFirstname.value) && isName(oInForm.fDonorFirstname.value))
		{
			bSendForm = true;
			iErrorMsg = 0;
		}
		else
		{
			bSendForm = false;
			iErrorMsg = 3;
		}
	}
	
	// check last name
	if(bSendForm)
	{
		if(isString(oInForm.fDonorLastname.value) && isName(oInForm.fDonorLastname.value))
		{
			bSendForm = true;
			iErrorMsg = 0;
		}
		else
		{
			bSendForm = false;
			iErrorMsg = 4;
		}
	}
	
	// check address
	if(bSendForm)
	{
		if(oInForm.fDonorAddress.value != "")
		{
			bSendForm = true;
			iErrorMsg = 0;
		}
		else
		{
			bSendForm = false;
			iErrorMsg = 5;
		}
	}
	
	// check ZIP
	if(bSendForm)
	{
		if(oInForm.fDonorZIP.value != "")
		{
			bSendForm = true;
			iErrorMsg = 0;
		}
		else
		{
			bSendForm = false;
			iErrorMsg = 6;
		}
	}
	
	// check country
	if(bSendForm)
	{
		if(oInForm.fDonorCountry.options[oInForm.fDonorCountry.selectedIndex].value.length == 2)
		{
			bSendForm = true;
			iErrorMsg = 0;
		}
		else
		{
			bSendForm = false;
			iErrorMsg = 7;
		}
	}
	
	// check email address
	if(bSendForm)
	{
		if(isString(oInForm.fDonorEmail.value) && isEMail(oInForm.fDonorEmail.value))
		{
			bSendForm = true;
			iErrorMsg = 0;
		}
		else
		{
			bSendForm = false;
			iErrorMsg = 8;
		}
	}

	// execute action depending on check result
	if(bSendForm)
	{
		oInForm.submit();
		return true;
	}
	else
	{
		alert(aErrorMsg[iErrorMsg]);
		return false;
	}
	
}

// use this function only when donation is selectable by radio buttons
function CheckAmount(sName)
{
	var oInForm = this.document.donationForm;
	if(sName == "fDonorAmount" && oInForm.fDonorOtherAmount.value != "")
	{
		oInForm.fDonorOtherAmount.value = "";
	}
	if(sName == "fDonorOtherAmount" && oInForm.fDonorOtherAmount.value != "")
	{
		if(isNumber(oInForm.fDonorOtherAmount.value))
		{
			for(i=0; i<oInForm.fDonorAmount.length; i++)
			{
				if(oInForm.fDonorAmount[i].checked)
				{
					oInForm.fDonorAmount[i].checked = false;
				}
			}
		}
		else
		{
			oInForm.fDonorOtherAmount.value = "";
		}
	}
}

// use this function only when just "other" amount is possible - no selection through radio buttons
/*
function CheckAmount(sName)
{
	var oInForm = this.document.donationForm;
	if(sName == "fDonorOtherAmount" && oInForm.fDonorOtherAmount.value != "")
	{
		if(!isNumber(oInForm.fDonorOtherAmount.value))
		{
			oInForm.fDonorOtherAmount.value = "";
		}
	}
}
*/

function SelectLanguage()
{
	var oInForm      = this.document.donationForm;
	var sISOLangCode = oInForm.fDonorLanguage.options[oInForm.fDonorLanguage.selectedIndex].value;
	this.document.location.href = "../" + sISOLangCode;
}

function SelectAmount(iAmountId)
{
	this.document.donationForm.fDonorAmount[iAmountId].checked = true;
}

function SelectCurrency(iCurrencyId)
{
	this.document.donationForm.fDonorCurrency[iCurrencyId].checked = true;
}

function ChangeCurrency(sCurrencyId)
{
	if(sCurrencyId == "EUR")
	{
		var oCurrency1 = this.document.createTextNode("39");
		var oCurrency2 = this.document.createTextNode("78");
		var oCurrency3 = this.document.createTextNode("214");
		var oCurrency4 = this.document.createTextNode("389");
	}
	if(sCurrencyId == "GBP")
	{
		var oCurrency1 = this.document.createTextNode("27");
		var oCurrency2 = this.document.createTextNode("53");
		var oCurrency3 = this.document.createTextNode("147");
		var oCurrency4 = this.document.createTextNode("267");
	}
	if(sCurrencyId == "USD")
	{
		var oCurrency1 = this.document.createTextNode("50");
		var oCurrency2 = this.document.createTextNode("100");
		var oCurrency3 = this.document.createTextNode("275");
		var oCurrency4 = this.document.createTextNode("500");
	}
	document.getElementById("fDonorAmount1").replaceChild(oCurrency1, document.getElementById("fDonorAmount1").firstChild);
	document.getElementById("fDonorAmount2").replaceChild(oCurrency2, document.getElementById("fDonorAmount2").firstChild);
	document.getElementById("fDonorAmount3").replaceChild(oCurrency3, document.getElementById("fDonorAmount3").firstChild);
	document.getElementById("fDonorAmount4").replaceChild(oCurrency4, document.getElementById("fDonorAmount4").firstChild);		
}

