var sum_gb1 		= 0;
var sum_gb2		= 0;
var sum_gb3		= 0;
var sum_gb_opt 	= 0;
var sum_gb_full = 0;
var sum_gs 		= 0;
var sum_vs 		= 0;
var full_sum 	= 0;
var gb1amount   = 0;
var gb2amount	= 0;
var gb3amount	= 0;
// Static Prices for the different Options
// Geschenkbox standard
var price_gb1 = 41.9;
var price_gb2 = 17.9;
var price_gb3 = 13.9;
// Waldhonig
var price_gb_opt1 = 3.9;
// Schwarzbeerlikoer
var price_gb_opt2 = 7.2;
// Kaeferbohnen
var price_gb_opt3 = 2.8;
// Wanderkarte
var price_gb_opt4 = 4.9;
// Ortschronik
var price_gb_opt5 = 30;

var price_gs_dinner = 95;
var price_gs_genuss = 150;

/*var price_vs_gb_ausland = 15;
var price_vs_gs_ausland = 1.5;
var price_vs_gb_vor = 6.3;
var price_vs_gs_vor = .55;
var price_vs_gb_nach = 9.8;
var price_vs_gs_nach = 4.05;
*/
var price_vs_gb_ausland = 0;
var price_vs_gs_ausland = 0;
var price_vs_gb_vor = 0;
var price_vs_gs_vor = 0;
var price_vs_gb_nach = 0;
var price_vs_gs_nach = 0;

function calculate_gbprice(boxid)
{

	if(boxid==1) {

		gb1amount = document.getElementById('tx_pilmailform_pi1[text][gb1amount]').value;

		sum_gb1 = gb1amount * (price_gb1);

		// Set the gbpricefield
		document.getElementById('tx_pilmailform_pi1[text][gb1price]').value = roundvalue( sum_gb1, 2);
	} else 	if(boxid==2) {

		gba2mount = document.getElementById('tx_pilmailform_pi1[text][gb2amount]').value;

		sum_gb2 = gba2mount * (price_gb2);

		// Set the gbpricefield
		document.getElementById('tx_pilmailform_pi1[text][gb2price]').value = roundvalue( sum_gb2, 2);
	} else if(boxid==3) {

		gba3mount = document.getElementById('tx_pilmailform_pi1[text][gb3amount]').value;

		sum_gb3 = gba3mount * (price_gb3);

		// Set the gbpricefield
		document.getElementById('tx_pilmailform_pi1[text][gb3price]').value = roundvalue( sum_gb3, 2);
	} 
	//calculate_gboptions();
	calculate_fullgbprice();
}

function calculate_gboptions()
{
	// Reset
	opt1value = 0;
	opt2value = 0;
	opt3value = 0;
	opt4value = 0;
	opt5value = 0;
	opt6value = 0;
	opt7value = 0;
	opt8value = 0;
	opt9value = 0;

	gbamount = document.getElementById('tx_pilmailform_pi1[text][gbamount]').value;
	// First Optional Item
	/*if ( document.getElementById('tx_pilmailform_pi1[checkbox][opt1]').checked )
	{
		opt1value = gbamount * price_gb_opt1;

		document.getElementById('tx_pilmailform_pi1[text][opt1price]').value = roundvalue( opt1value, 2);
	} else {
		document.getElementById('tx_pilmailform_pi1[text][opt1price]').value = roundvalue( opt1value, 2);
	}
	// Second Optional Item
	if ( document.getElementById('tx_pilmailform_pi1[checkbox][opt2]').checked )
	{
		opt2value = gbamount * price_gb_opt2;

		document.getElementById('tx_pilmailform_pi1[text][opt2price]').value = roundvalue( opt2value, 2);
	}
	 else {
		document.getElementById('tx_pilmailform_pi1[text][opt2price]').value = roundvalue( opt2value, 2);
	}
	// Third Optional Item
	if ( document.getElementById('tx_pilmailform_pi1[checkbox][opt3]').checked )
	{
		opt3value = gbamount * price_gb_opt3;

		document.getElementById('tx_pilmailform_pi1[text][opt3price]').value = roundvalue( opt3value, 2);
	} else {
		document.getElementById('tx_pilmailform_pi1[text][opt3price]').value = roundvalue( opt3value, 2);
	}
	// Fourth Optional Item
	if ( document.getElementById('tx_pilmailform_pi1[checkbox][opt4]').checked )
	{
		opt4value = gbamount * price_gb_opt4;

		document.getElementById('tx_pilmailform_pi1[text][opt4price]').value = roundvalue( opt4value, 2);
	} else {
		document.getElementById('tx_pilmailform_pi1[text][opt4price]').value = roundvalue( opt4value, 2);
	}
	// Fifth Optional Item
	if ( document.getElementById('tx_pilmailform_pi1[checkbox][opt5]').checked )
	{
		opt5value = gbamount * price_gb_opt5;

		document.getElementById('tx_pilmailform_pi1[text][opt5price]').value = roundvalue( opt5value, 2);
	} else {
		document.getElementById('tx_pilmailform_pi1[text][opt5price]').value = roundvalue( opt5value, 2);
	}/*
	// Sixt Optional Item
	if ( document.getElementById('tx_pilmailform_pi1[checkbox][opt6]').checked )
	{
		opt6value = gbamount * price_gb_opt6;

		document.getElementById('tx_pilmailform_pi1[text][opt6price]').value = roundvalue( opt6value, 2);
	} else {
		document.getElementById('tx_pilmailform_pi1[text][opt6price]').value = roundvalue( opt6value, 2);
	}

	// Seventh Optional Item
	if ( document.getElementById('tx_pilmailform_pi1[checkbox][opt7]').checked )
	{
		opt7value = gbamount * price_gb_opt7;

		document.getElementById('tx_pilmailform_pi1[text][opt7price]').value = roundvalue( opt7value, 2);
	} else {
		document.getElementById('tx_pilmailform_pi1[text][opt7price]').value = roundvalue( opt7value, 2);
	}
	// eigth Optional Item
	if ( document.getElementById('tx_pilmailform_pi1[checkbox][opt8]').checked )
	{
		opt8value = gbamount * price_gb_opt8;

		document.getElementById('tx_pilmailform_pi1[text][opt8price]').value = roundvalue( opt8value, 2);
	} else {
		document.getElementById('tx_pilmailform_pi1[text][opt8price]').value = roundvalue( opt8value, 2);
	}
	// ninth Optional Item
	if ( document.getElementById('tx_pilmailform_pi1[checkbox][opt9]').checked )
	{
		opt9value = gbamount * price_gb_opt9;

		document.getElementById('tx_pilmailform_pi1[text][opt9price]').value = roundvalue( opt9value, 2);
	} else {
		document.getElementById('tx_pilmailform_pi1[text][opt9price]').value = roundvalue( opt9value, 2);
	}
*/
	sum_gb_opt = opt1value + opt2value + opt3value + opt4value + opt5value;// + opt6value + opt7value + opt8value + opt9value;

	//calculate_fullgbprice();
}

function calculate_fullgbprice()
{
	//sum_gb_full = sum_gb_opt + sum_gb;

	sum_gb_full = sum_gb1 + sum_gb2 + sum_gb3;
	
	//document.getElementById('tx_pilmailform_pi1[text][gbsumprice]').value = roundvalue( sum_gb_full, 2);

	calculate_gs();
}

function calculate_gs()
{
	sum_gs = 0;
	gsamount = document.getElementById('tx_pilmailform_pi1[text][gamount]').value;

	for( var i = 0; i < document.getElementsByName('tx_pilmailform_pi1[radio][gs]').length; i++ )
	{
		if ( document.getElementsByName('tx_pilmailform_pi1[radio][gs]')[ i ].checked )
		{
			if ( document.getElementsByName('tx_pilmailform_pi1[radio][gs]')[ i ].value == 'Kerzerldinner' )
			{
				// Kerzerldinner
				sum_gs = gsamount * price_gs_dinner;
			} else if ( document.getElementsByName('tx_pilmailform_pi1[radio][gs]')[ i ].value == 'Genuss_und_Erlebnis' ) {
				// Genuss und Erlebnis
				sum_gs = gsamount * price_gs_genuss;
			} else if ( document.getElementsByName('tx_pilmailform_pi1[radio][gs]')[ i ].value == 'Individuell' ) {
				customprice = document.getElementById('tx_pilmailform_pi1[text][gscustom]').value;
				sum_gs = gsamount * customprice;
			}
		}
	}

	document.getElementById('tx_pilmailform_pi1[text][gssumprice]').value = roundvalue( sum_gs, 2);

	calculate_versand();
}

function calculate_versand()
{
	sum_vs = 0;

	gsamount = 0;//document.getElementById('tx_pilmailform_pi1[text][gamount]').value;
	gbamount = 0;//document.getElementById('tx_pilmailform_pi1[text][gbamount]').value;


	for( var i = 0; i < document.getElementsByName('tx_pilmailform_pi1[radio][versand]').length; i++ )
	{
		if ( document.getElementsByName('tx_pilmailform_pi1[radio][versand]')[ i ].checked )
		{
			if ( document.getElementsByName('tx_pilmailform_pi1[radio][versand]')[ i ].value == 'Abholung' )
			{
				// Abholung und Barzahlung
				sum_vs = 0;
				document.getElementById('versandoptionen').style.display = "none";
			} else if ( document.getElementsByName('tx_pilmailform_pi1[radio][versand]')[ i ].value == 'Versand' ) {
				// Versand
				document.getElementById('versandoptionen').style.display = "";

				// Check the Payment Options
				if ( document.getElementsByName('tx_pilmailform_pi1[radio][nachvor]')[ 0 ].checked )
				{
					// Nachnahme
					sum_vs = (gsamount * price_vs_gs_nach) + (gbamount * price_vs_gb_nach);
				} else {
					// Vorauskasse
					sum_vs = (gsamount * price_vs_gs_vor) + (gbamount * price_vs_gb_vor);
				}

			} else if ( document.getElementsByName('tx_pilmailform_pi1[radio][versand]')[ i ].value == 'Ausland' ) {
				document.getElementById('versandoptionen').style.display = "none";
				sum_vs = (gbamount * price_vs_gb_ausland) + (gsamount * price_vs_gs_ausland);
			}
		}
	}
	//document.getElementById('tx_pilmailform_pi1[text][vssumprice]').value = roundvalue( sum_vs, 2);
	
	calculate_summe();
}

function calculate_summe()
{
	fullsum = sum_gb_full + sum_gs + sum_vs;

	document.getElementById('tx_pilmailform_pi1[text][fullsum]').value = roundvalue( fullsum, 2);

}

function roundvalue(Num, Places)
{
	Number =  Num.toFixed( Places );

	Number = Number.toString();

	return Number.replace( /\./, "," );
}
