function goToBank(bank) {
	document.getElementById('pankki').value = bank;
	document.customerForm.submit();
}

function submitAge(age, type){
	document.ageForm.elements['age'].value = age;
	document.ageForm.elements['type'].value = type;
	document.ageForm.submit();
}	

function submitType(type){
	document.ageForm.elements['type'].value = type;
	document.ageForm.submit();	
}	

function inviteFriend(status){
	if (status != true) {
		var nimi = document.customerForm.elements['etunimi'].value + " " + document.customerForm.elements['sukunimi'].value;
		var osoite = document.customerForm.elements['email'].value;
	}

	if ((nimi != '' && osoite != '') || status == true) {
		var inviteWindow = window.open("invite.php?t="+(status == true ? 1 : ''), "invite", "status=1, width=400, height=450, resizable=0");
	}
	else {
		alert("Täytä yhteystietosi.\nNimi ja sähköpostiosoite ovat pakollisia tietoja ystävälle kerrottaessa.");
	}
}

function inviteFriendsFromFacebook(){
	var inviteWindow = window.open("/inviteFacebookFriends.php", "inviteWin", "status=1, width=800, height=700, resizable=0, scrollbars=0");
}

function fetchInfo(){
	var nimi = opener.document.customerForm.elements['etunimi'].value+" "+opener.document.customerForm.elements['sukunimi'].value;
	var email = opener.document.customerForm.elements['email'].value;

	// set values to form
	document.inviteForm.elements['displayName'].value = nimi+" <"+email+">";
	document.inviteForm.elements['senderName'].value = nimi;
	document.inviteForm.elements['senderEmail'].value = email;
	
	// set senders' name and email to page
	$("#invite_sender").text(nimi+" <"+email+">");
}

function checkDonateValue(){
	// get form
	var form = document.mainpageDonationForm;
	// get input element
	var inputElement = form.elements['amount'];
	// "convert" value to integer
	var contertedValue = parseInt(inputElement.value);

	// value is correct
	if(contertedValue == inputElement.value){
		// submit form
		form.submit();
	}
	else{
		// give user information about value
		alert("Summan pitää olla kokonaisluku.");
	}
}

function submitGift(giftCount, giftValue, documentName){
	if(documentName == 'moneyForm'){
		var newValue = parseInt(document.moneyForm.elements['money'].value);

		if (document.moneyForm.elements['money'].value == newValue) {
			document.moneyForm.elements['packetCount'].value = giftCount;
			document.moneyForm.elements['totalValue'].value = giftValue;
			
			document.moneyForm.submit();
		}
		else {
			alert("Summan pitää olla kokonaisluku.");
		}
	}

	if(documentName == 'giftForm'){
		document.giftForm.elements['packetCount'].value = giftCount;
		document.giftForm.elements['totalValue'].value = giftValue;

		document.giftForm.submit();	
	}	
	
}

