var page = {
		baseUrl : '',
		PHPSESSID: '',
		
		initialize : function(baseUrl,PHPSESSID){
				page.baseUrl = baseUrl;
				page.PHPSESSID = PHPSESSID;
				$('#btn_check').click(page.btn_check_clicked);
				$('#btn_continue').click(page.btn_continue_clicked);
				$('#form_check_code').submit(page.form_check_code_submit);
				$('#form_check_code input').keypress(page.code_keypress);
				$("#informationBoxform").dialog({
						autoOpen: false,
						bgiframe: true,
						width: 454,
						minWidth : 454,
						minHeight: 170,
						modal: true,
						closeOnEscape: true
				});
				$("#informationBox").dialog({
						autoOpen: false,
						bgiframe: true,
						width: 454,
						minWidth : 454,
						minHeight: 170,
						modal: true,
						closeOnEscape: true
				});
				$("#informationBox_price1, #informationBox_price2").dialog({
						autoOpen: false,
						bgiframe: true,
						width: 654,
						minWidth : 654,
						minHeight: 370,
						modal: true,
						closeOnEscape: true
				});
				$("#informationBoxform	a.close, #informationBox	a.close, #informationBox_price1	 a.close, #informationBox_price2 a.close").click(page.closeBox);
				$('#btn_readmore_price1').click(page.infoPrice1);
				$('#btn_readmore_price2').click(page.infoPrice2);
				
				$('#imgswitch').cycle({
					fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
					pause:  1,
					speed:  700,
					timeout: 10000
				});
		},


		infoPrice1:function(){
			$('#informationBox_price1').dialog('open');
		},

		infoPrice2:function(){
			$('#informationBox_price2').dialog('open');
		},

		closeBox:function(){
			$("#informationBox, #informationBox_price1, #informationBox_price2").dialog('close');
		},

		code_keypress:function(e){
			if(e.keyCode == 13){
				page.btn_check_clicked();
			}
		},
		
		form_check_code_submit:function(){
			return false;
		},

		btn_check_clicked:function(){
			$('#form_check_code input').removeClass('error');
			$('#form_check_code input').parent().removeClass('error');
			$('#informationBox').html('Bezig met controleren!');
			$('#informationBox a.close').hide();
			$("#informationBox").dialog('open');
			$.post(
				page.baseUrl + '/index/checkcode/PHPSESSID/'+page.PHPSESSID,
				$('#form_check_code').serialize(),
				page.checkRecieved,
				'json'
			);
			main.boxCenterText('#informationBox');
			return false;
		},


		checkRecieved:function(data){
			if(data.result != 'code_ok'){
				$('#informationBox').html('De opgegeven code <b>'+$('#code_1').val()+'</b> is niet geldig!<br /><br /><a class="button close">Sluiten</a>');
				$("#informationBox").dialog('open');
				$("#informationBox a.close").click(page.closeBox);
				$('#informationBox a.close').show();
				main.boxCenterText('#informationBox');
				if(data.errorFields.length > 0){
					for(var i = 0; i < data.errorFields.length; i++){
						$('#'+data.errorFields[i]).addClass('error');
						$('#'+data.errorFields[i]).parent().addClass('error');
					}
				}
			}else{
				$("#informationBoxform").dialog('open');
				$("#formcode").val($("#code_1").val());
			}
		},


		btn_continue_clicked:function(){
			$.post(
				page.baseUrl + '/index/checkcodepersonal/PHPSESSID/'+page.PHPSESSID,
				$('#form_check_userdata').serialize(),
				page.checkRecievedTwo,
				'json'
			);
			return false;
		},


		checkRecievedTwo:function(data){
			window.location = data.url;
		}

}
