var chekin = {
	
	element: null,
	lang: null,
	
	messages: {
		fr: {
			email: 'format Email Incorrect !',
			resa: 'Vous devez entrer le numero de reservation !',
			name: 'Vous devez entrer votre nom',
			tel: 'Vous devez entrer votre numéro de Téléphone'

		},
		de: {
			email: 'Mandatory fields or invalid format',
			resa: 'Please fill all the compulsory fields',
			name: 'Please fill all the compulsory fields Name'
		},
		it: {
			email: 'Questo campo e vuoto o l\'indirizzo di posta elettronica non e valido',
			resa: 'Questo campo è obbligatorio',
			name: 'Questo campo è obbligatorio',
			tel: 'Vi preghiamo di inserire il vostro numero di telefono'

		},
		en: {
			email: 'Mandatory fields or invalid format',
			resa: 'Please fill all the compulsory fields',
			name: 'Please fill all the compulsory fields Name',
			tel: 'Please enter your telephone number'

		}
	},
	
	init: function () {
		
		
		
		this.lang = 'en';
		
		if ( document.location.pathname.match(/^\/fr\//) )
			this.lang = 'fr';
		
		else if ( document.location.pathname.match(/^\/de\//) )
			this.lang = 'de';
		
		else if ( document.location.pathname.match(/^\/it\//) )
			this.lang = 'it';
			
		
		if ( !$('#chekin') )
			return ; 
		
		this.element = $('#chekin select');
		
		
		this.element.change(function () {
			
			var idx = $('#chekin select').attr('selectedIndex');
			className = document.getElementById('chekin').getElementsByTagName('select')[0].options[idx].className;
			
			if ( className == 'gatean' )
				url = 'https://www2.klm.com/gs/ici/checkin/Main/Checkin?LANG=' + chekin.lang + '&DPS=f7&homeurl=http://www.flybaboo.com/';
			
				else if ( className == 'swissport' )
				url = 'https://selfservice.sita.aero/internetSWP/identificationEdit.do?locale=' + chekin.lang + '&al=carrier_F7';
			
						
			
			//window.open(url, 'Webcheckin','resizable=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=no,width=800,height=600,status');
			//document.location = url;
			$('#chekinform').attr('action', url);
			
		});
		
		
		$('#chekin form.resa').submit(function (event) {
			
			if ( $('#chekin form.resa input[name="recordlocator"]').val().length < 1 ) {
				
				alert(chekin.messages[chekin.lang]['resa']);
				event.preventDefault();
				
			} else if ( !$('#chekin form.resa input[name="lastname"]').val() ) {
				
				alert(chekin.messages[chekin.lang]['name']);
				event.preventDefault();
				
			}
			
		});
		
		
		
		if ( document.getElementById('SMS') ) {
			
			$('#SMS').submit(function (event) {
				
				var val = $('#SMS input[name="tel"]').val();
				if ( !val || !/^[-]?\d*\.?\d*$/.test(val) ) {
					
					event.preventDefault();
					alert(chekin.messages[chekin.lang]['tel']);
					
				}
				
			});
		
			
		}
		
		if ( document.getElementById('news') ) {
			
			$('#news').submit(function (event) {
				
				var val = $('#news input[name="email"]').val();
				if ( !val || !/.*@.*\...*/.test(val) ) {
					
					event.preventDefault();
					alert(chekin.messages[chekin.lang]['email']);
					
				}
				
			});
		
			
		}
		
		
	}
	
};
