// JavaScript Document



var cBuchung = Class.create();



cBuchung.prototype = {

	

	initialize: function() {

		Element.hide ('btnSubmit');

	},

	

	updateCamp: function() {

		var selectBox = $('camp');

// 		if ( preselect != 0 ) 

// 			selectBox.selectedIndex = preselect;

		

		var selectIdx = selectBox.selectedIndex;

        var element = selectBox.options [selectIdx];

		  

		if ( element.value <= 0 )

			return;

		

		if ( Element.visible ( 'btnSubmit' ) )

			Element.hide('btnSubmit');

		if ( Element.visible ( 'timeSelection' ) )

			Element.hide('timeSelection');

		if ( Element.visible ( 'travelSelection' ) )

			Element.hide('travelSelection');

		if ( Element.visible ( 'insuranceSelection' ) )

			Element.hide('insuranceSelection');

			

        var camp = element.value;

            

		new Ajax.Request( '/phpincs/we_buchung.inc.php', {

			method: 'post',

			postBody: 'ajax=1&camp=' + camp,

			onSuccess: function (t) {

				Effect.toggle('timeSelection', 'appear' );

				$('time').innerHTML = t.responseText;

			},

			onFailure: function(t) {

				Element.hide ( 'timeSelection' );

				alert('Error ' + t.status + ' -- ' + t.statusText);

			}

		});

	},

	

	updateTimeSelection: function() {

    return;   

		new Ajax.Request( '/phpincs/we_buchung.inc.php', {

			method: 'post',

			postBody: 'ajax=1&run=showCampTime',

			onSuccess: function (t) {

				if ( ! Element.visible ( 'timeSelection' ) )

					Effect.toggle('timeSelection', 'appear' );

				$('time').innerHTML = t.responseText;

			},

			onFailure: function(t) {

				Element.hide ( 'timeSelection' );

				alert('Error ' + t.status + ' -- ' + t.statusText);

			}

		});

	},



    selectTime: function(idx, ids) {

//         alert ( idx );

		if ( idx.indexOf ( '_' ) <= 0 )

			return;

			

//         try {         

//             var myids = ids.split(',');  

//             var idClicked = idx.split('_'); idClicked = idClicked [1];

//             for ( i = 0; i < myids.length; i++ ) {

//                 var idName = 'name_' + myids [ i ];

//                 var idPreis = 'price_' + myids [ i ];

//                 var idAction = 'action_' + myids [ i ];

//                 //alert ( idName + ' = ' + $(idName ) );

//                 if ( myids [ i ] != idClicked ) {

//                     $(idName).innerHTML = 'not_clk';

//                     Element.setStyle ( $(idName), {fontWeight:'normal'} );

//                     Element.setStyle ( $(idPreis), { fontWeight: 'normal' } );

//                     Element.setStyle ( $(idAction), { fontWeight: 'normal' } );

//                 } else {

//                     $(idName).innerHTML = 'clk';

//                     Element.setStyle ( $(idName), { fontWeight: 'bold' } );

//                     Element.setStyle ( $(idPreis), { fontWeight: 'bold' } );

//                     Element.setStyle ( $(idAction), { fontWeight: 'bold' } );

//                 }

//             }

//         } catch (exception) {}

        

		$a_ids = ids.split(",");

		

		for ($x = 1; $x <= $a_ids.length; $x++)	{

			$element = document.getElementById("timesel_" + $x);

			if (isNaN($element)) $element.style.visibility = "hidden";

		}

		

		$a_idx = idx.split("_");

		$idx = $a_idx[1];

		

		$element = document.getElementById("timesel_" + $idx);

		if (isNaN($element)) $element.style.visibility = "";

			

		if ( Element.visible ( 'btnSubmit' ) )

			Element.hide('btnSubmit');

		if ( Element.visible ( 'travelSelection' ) )

			Element.hide('travelSelection');

		if ( Element.visible ( 'insuranceSelection' ) )

			Element.hide('insuranceSelection');

			

        var camp = idx.substring ( 0, idx.indexOf ( '_' ) );

        var time = idx.substring ( idx.indexOf ( '_' ) + 1 );


		new Ajax.Request( '/phpincs/we_buchung.inc.php', {

			method: 'post',

			postBody: 'ajax=1&time=' + time,

			onSuccess: function (t) {

				Effect.toggle('travelSelection', 'appear' );

				$('travel').innerHTML = t.responseText;

				Buchung.updateTimeSelection();

			},

			onFailure: function(t) {

				Element.hide ( 'travelSelection' );

				alert('Error ' + t.status + ' -- ' + t.statusText);

			}

		});

	},

	

	selectTravel: function(idx, change, city) {

		if ( idx.indexOf ( '_' ) <= 0 )

			return;

		if ( ! change || typeof(change) == 'undefined' )

			change = false;

			

		var type = idx.substring ( 0, idx.indexOf ( '_' ) );

		var idx = idx.substring ( idx.indexOf ( '_' ) + 1 );

		

		if ( Element.visible ( 'btnSubmit' ) )

			Element.hide('btnSubmit');

		if ( Element.visible ( 'travelSelection' ) )

			Element.hide('travelSelection');

		if ( Element.visible ( 'insuranceSelection' ) )

			Element.hide('insuranceSelection');



        var url = '/phpincs/we_buchung.inc.php';

        var params = 'ajax=1';

        params += change ? '&' + type + '=0' : '&' + type + '=' + idx;



        try {

            if ( city && city.length > 0 ) {

                params += '&abcity=' + encodeURI ( $F(city) );

            }

        } catch (exception) {}

//alert(url + params);

		new Ajax.Request( url, {

			method: 'post',

			postBody: params,

			onSuccess: function (t) {

				Effect.toggle('travelSelection', 'appear' );

				$('travel').innerHTML = t.responseText;

				// if ( type == 'ab' && ! change )
				if ( type == 'an' && ! change )

                    Buchung.showInsurance();

            },

			onFailure: function(t) {

				Element.hide ( 'travelSelection' );

				alert('Error ' + t.status + ' -- ' + t.statusText);

			}

		});

	},

	

	showInsurance: function() {

        var params = 'ajax=1&insurance=1';   

		new Ajax.Request( '/phpincs/we_buchung.inc.php', {

			method: 'post',

			postBody: params,

			onSuccess: function (t) {

				Effect.toggle('insuranceSelection', 'appear' );

				

				$('insurance').innerHTML = t.responseText;

				if ( ! Element.visible ( 'btnSubmit' ) )

					Effect.toggle('btnSubmit', 'appear' );

				

			},

			onFailure: function(t) {

				Element.hide ( 'insuranceSelection' );

				alert('Error ' + t.status + ' -- ' + t.statusText);

			}

		});

	},

	

	gotoCustomer: function () {

		

		var params = 'ajax=1';

		

		var insWelcome = $('insurance_welcome');

		if ( insWelcome && typeof(insWelcome) != 'undefined' )

			params += '&insWelcome=' + ( insWelcome.checked == true ? "1" : "0" );

		var insWelcome21 = $('insurance_welcome21');

		if ( insWelcome21 && typeof(insWelcome21) != 'undefined' )

			params += '&insWelcome21=' + ( insWelcome21.checked == true ? "1" : "0" );
		

		var insTravel = $('insurance_travel');

		if ( insTravel && typeof(insTravel) != 'undefined' )

			params += '&insTravel=' + ( insTravel.checked == true ? "1" : "0" );

		

		var insStorno = $('insurance_storno');

		if ( insStorno && typeof(insStorno) != 'undefined' )

			params += '&insStorno=' + ( insStorno.checked == true ? "1" : "0" );

	    //alert ( insStorno  + " :: " + insStorno.checked );

		new Ajax.Request( '/phpincs/we_buchung.inc.php', {

			method: 'post',

			postBody: params,

			onSuccess: function (t) {

				$('buchung').innerHTML = t.responseText;

			},

			onFailure: function(t) {

				alert('Error ' + t.status + ' -- ' + t.statusText);

			}

		});

	},

	

	sendCustomer: function () {

		

		var params = 'ajax=1&submit=1';

		

		var keys = [ 'firstname', 'lastname', 'email', 'street', 'schule', 'city', 'postal', 'country', 'parent', 

              'telefon_arbeit', 'telefon_privat', 'fax', 'email', 'partnercode', 'sibling', 'ersatztermin', 'schulstufe' ];

		for ( var i = 0; i < keys.length; i++ )

			params += '&' + keys [ i ] + '=' + $F( keys [ i ] );

            

        if ( $('sex_m').checked ) params += '&sex=m';

        else if ( $('sex_w').checked ) params += '&sex=w';
        	
                 

        try {

            params += '&birthday_day=' + $F('birthday_day') + '&birthday_month=';

            var birthdayMonth = $('birthday_month');

            params += birthdayMonth.options [ birthdayMonth.selectedIndex ].value;

            params += '&birthday_year=' + $F('birthday_year');

        } 

        catch ( exception ) {}



		new Ajax.Request( '/phpincs/we_buchung.inc.php', {

			method: 'post',

			postBody: params,

			onSuccess: function (t) {

				$('buchung').innerHTML = t.responseText;

			},

			onFailure: function(t) {

				alert('Error ' + t.status + ' -- ' + t.statusText);

			}

		});

	},

    

    sendBasket: function () {

        

        var params = 'ajax=1&basket=1';

        

        try {

            if ( $('agb').checked ) params += '&agb=1';

            else params += '&agb=0';

        } catch (exception) {}

        

        var insWelcome = $('insurance_welcome');

        if ( insWelcome && typeof(insWelcome) != 'undefined' )

            params += '&insWelcome=' + ( insWelcome.checked == true ? "1" : "0" );

        var insStorno = $('insurance_storno');

        if ( insStorno && typeof(insStorno) != 'undefined' )

            params += '&insStorno=' + ( insStorno.checked == true ? "1" : "0" );

        

        new Ajax.Request( '/phpincs/we_buchung.inc.php', {

            method: 'post',

            postBody: params,

            onSuccess: function (t) {

                if ( t.responseText == 'StartBuchung' ) {

					if (window.location.href == "http://www.camps.at/en/travel/online_booking.php#") {

						window.document.location.href = '/en/travel/online_booking.php?p=1';

					}

					else {

                    	window.document.location.href = '/de/reise/buchung.php?p=1';

					}

				} else

                    $('buchung').innerHTML = t.responseText;

            },

            onFailure: function(t) {

                alert('Error ' + t.status + ' -- ' + t.statusText);

            }

        });

    }

}




