
function initCountrySelect(_alpha2, _iso1) {
	debug("initCountrySelect alpha2:"+_alpha2+" iso1:"+_iso1);
	var
		readyFunction = function (_req) {
			if (_req.readyState == 4){
				var select = document.getElementById('user_alpha2');
				var items = _req.responseXML.getElementsByTagName('country');
				var selected = -1;
				var dcNumber;
				var selectedCountry;
				for (var i = 0; i < items.length; i++) {
					var itemAlpha2 = items[i].getAttribute('zn_alpha2');
					var name = items[i].getAttribute('zna_name');
				
			  		if(itemAlpha2==_alpha2){
			  			selected = i;
			  			selectedCountry = name;
			      		    dcNumber='+';
			      		
			      		if (items[i].getAttribute('dc_number'))
			      			dcNumber += items[i].getAttribute('dc_number');
			      	}
				    select.options[i]=new Option(name, itemAlpha2);
				}
			  
				if (selected != -1){
	      			setValueById('user_phone_idp', dcNumber);
	      			setValueById('user_fax_idp', dcNumber);
	      			select.selectedIndex = selected;
	      			setValueById('user_country', selectedCountry);
				}
			}
		};
	
	ajaxGet('/flash_all_countries_'+_iso1+'.xml', readyFunction);
}

function setMustField(_id, _trueFalse){
	setVisibilityById(_id+'_mf', _trueFalse);
}

function unCheckUserData(){
	checkElementByLength('user_name', 0);
	checkElementByLength('user_surname', 0);
	checkElementByLength('user_street', 0);
	checkElementByLength('user_street_number', 0);
	checkElementByLength('user_zipcode', 0);
	checkElementByLength('user_city', 0);
	checkElementByLength('user_phone', 0);
	checkElementByLength('user_phone_idp', 0);
	checkElementByLength('user_phone_ndp', 0);
	checkElementByLength('user_email', 0);
}

function checkUserData(){
	var
		success = true;
	
	success &= checkElementByLength('user_name', 3);
	success &= checkElementByLength('user_surname', 3);
	success &= checkElementByLength('user_street', 3);
	success &= checkElementByLength('user_street_number', 1);
	success &= checkElementByLength('user_zipcode', 1);
	success &= checkElementByLength('user_city', 3);
	success &= checkElementByLength('user_phone_idp', 2);
	success &= checkElementByLength('user_phone_ndp', 3);
	success &= checkElementByLength('user_phone', 3);
	success &= checkElementByLength('user_email', 6);
	debug('checking user data return:'+success);
	return success?1:0;
}

function checkEmailData(){
	var
		success = true;
	
	success &= checkElementByLength('user_name', 3);
	success &= checkElementByLength('user_surname', 3);
	success &= checkElementByLength('user_email', 6);
	debug('checking user data return:'+success);
	return success?1:0;
}

function KitchenRequest(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	
	this.init();
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		hideElementById('element_user_info');
		hideElementById('element_message');
		hideElementById('element_callback');
		hideElementById('element_consultation');
		hideElementById('element_contact_book');
		hideElementById('element_user_info_navi');
		hideElementById('element_success_r');
		hideElementById('element_success_l');
		initCountrySelect(alpha2, iso1);
		setValueById('form_subject', getAttributeById("headline_img","alt"));
			
		init = function(_stm){
			showElementById('element_contact_howto');
			/*setDisplayBlockOrNoneById('element_user_info_head', false);*/
			unCheckUserData();
		};
	
		exit = function(_stm){
			hideElementById('element_contact_howto');
		};
	
		this.addState('state_contact_howto', init, exit);
	
		check = function(_stm){
			return document.getElementById('inquiry_email').checked?this.target:null;
		}
		this.setTransition('state_contact_howto', 'inquiry_email', 'state_contact_email', check);
		
		check = function(_stm){
			return document.getElementById('inquiry_callback').checked?this.target:null;
		}
		this.setTransition('state_contact_howto', 'inquiry_callback', 'state_contact_call', check);
		
		check = function(_stm){
			return document.getElementById('inquiry_consulting').checked?this.target:null;
		}	
		this.setTransition('state_contact_howto', 'inquiry_consulting', 'state_contact_consultation', check);
		
		check = function(_stm){
			return document.getElementById('inquiry_material').checked?this.target:null;
		}	
		this.setTransition('state_contact_howto', 'inquiry_material', 'state_contact_book', check);
		
		// state_contact_email
		init = function(_stm){
			unCheckUserData();
			hideElementById('element_user_info_navi');
			hideElementById('element_callback');			
			setCSSClassById('element_user_info', 'box320_l');
			setCSSClassById('form_message', 'message_big');
			showElementById('element_user_info');
			showElementById('element_message');
			setDisplayBlockOrNoneById('element_user_info_head', true);
			setContent('element_user_info_head', this.attributes['title']);
			setMustField('user_email', true);
			hideElementById('element_message_error');
		};
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
			hideElementById('element_message_error');
			setDisplayBlockOrNoneById('element_user_info_head', false);
			setMustField('user_email', false);
		};
	
		this.addState('state_contact_email', init, exit);
	
		check = function(_stm){
			// check form
			var checked = checkUserData()+checkElementByLength('form_message', 5)/*+checkElementByLength('user_email', 6)*/;
			if (checked != 2){
				showElementById('element_message_error');
				return 'state_contact_email';
			}			
			
			var
				encoded = buildURLEncodedFormData(document.getElementById('kitchen_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return 'state_success_email';
		}
		this.setTransition('state_contact_email', 'next', 'state_success_email', check);

		// state_contact_call
		init = function(_stm){
			hideElementById('element_user_info_navi');
			setCSSClassById('element_user_info', 'box320_l');
			showElementById('element_user_info');
			setDisplayBlockOrNoneById('element_user_info_head', true);
			setContent('element_user_info_head', this.attributes['title']);
			showElementById('element_message');
			setCSSClassById('form_message', 'message_small');
			showElementById('element_callback');
			setMustField('user_email', true);
			hideElementById('element_message_error');
			document.getElementById('form_hour_to').selectedIndex = document.getElementById('form_hour_from').selectedIndex+1;
		};
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
			hideElementById('element_callback');
			hideElementById('element_message_error');
			setDisplayBlockOrNoneById('element_user_info_head', false);
			setMustField('user_email', false);			
		};
	
		this.addState('state_contact_call', init, exit);

		check = function(_stm){
			// check form
			var checked = checkUserData()+checkElementByLength('form_message', 5);
			if (checked != 2){
				showElementById('element_message_error');
				return 'state_contact_call';
			}			
			setValueById('form_desired_date_text', '');
			var
				encoded = buildURLEncodedFormData(document.getElementById('kitchen_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return 'state_success_call';
		}
		this.setTransition('state_contact_call', 'next', 'state_success_call', check);

		
		// state_contact_consultation
		init = function(_stm){
			setCSSClassById('element_user_info', 'box320_l');
			showElementById('element_user_info');
			showElementById('element_message');
			setDisplayBlockOrNoneById('element_consultation', true);
			setDisplayBlockOrNoneById('element_user_info_head', true);
			setContent('element_user_info_head', this.attributes['title']);
			setCSSClassById('form_message', 'message_small');
			setMustField('user_email', true);
			hideElementById('element_message_error');
		};
		exit = function(_stm){
			hideElementById('element_user_info');
			setDisplayBlockOrNoneById('element_consultation', false);
			hideElementById('element_message');
			hideElementById('element_user_info_navi');
			hideElementById('element_message_error');
			setDisplayBlockOrNoneById('element_user_info_head', false);
			setMustField('user_email', false);			
		};
	
		this.addState('state_contact_consultation', init, exit);
		check = function(_stm){
			// check form
			var checked = checkElementByLength('form_message', 5) + checkUserData() + checkElementByLength('form_desired_date_input', 10)+ checkElementByLength('form_desired_hour_input', 1);
			if (checked != 4){
				showElementById('element_message_error');
				return 'state_contact_consultation';
			}			
			
			var
				val = getValueById('form_desired_date_input')+' '+getValueById('form_desired_hour_input')+':00:00';
			setValueById('form_desired_date', val);	
			setValueById('form_desired_date_text', val);	
							
			var
				encoded = buildURLEncodedFormData(document.getElementById('kitchen_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return 'state_success_consultation';
		}
		this.setTransition('state_contact_consultation', 'next', 'state_success_consultation', check);
		
		// state_contact_book
		init = function(_stm){
			setCSSClassById('element_user_info', 'box320_r');
			showElementById('element_user_info');
			showElementById('element_contact_book');
			showElementById('element_user_info_navi');
			setContent('element_user_info_head', '&nbsp;');
			setDisplayBlockOrNoneById('element_user_info_head', false);
			hideElementById('element_contact_book_navi');
			setMustField('user_email', true);
			hideElementById('element_user_info_error');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_contact_book');
			hideElementById('element_user_info_navi');
			setMustField('user_email', false);
			hideElementById('element_user_info_error');
		};
		
		this.addState('state_contact_book', init, exit);

		// state_contact_book_1
		init = function(_stm){
			setCheckedById('inquiry_material', true);
			setCSSClassById('element_contact_book', 'box320_r');
			showElementById('element_contact_book');
			hideElementById('element_contact_book_navi_back');
			showElementById('element_contact_book_navi');
			setContent('element_contact_book_navi_next', this.attributes['next']);
			setMustField('user_email', true);
			setDisplayBlockOrNoneById('element_user_info_head', false);
			hideElementById('element_user_info_error');
		};
	
		exit = function(_stm){
			hideElementById('element_contact_book');
			setMustField('user_email', false);
			hideElementById('element_user_info_error');
		};
		
		this.addState('state_contact_book_1', init, exit);
		
		// state_contact_book_2
		init = function(_stm){
			setCSSClassById('element_contact_book', 'box320_l');
			showElementById('element_contact_book');
			hideElementById('element_contact_book_navi');
			setDisplayBlockOrNoneById('element_user_info_head', false);
			setCSSClassById('element_user_info', 'box320_r');
			showElementById('element_user_info');
			showElementById('element_user_info_navi');
			setMustField('user_email', true);
			hideElementById('element_user_info_error');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_contact_book');
			setMustField('user_email', false);
			hideElementById('element_user_info_error');
		};
		
		this.addState('state_contact_book_2', init, exit);
		this.setTransition('state_contact_book_1', 'next', 'state_contact_book_2', null);
		
		check = function(_stm){
			var checked = checkUserData()+checkElementByLength('user_email', 6);
			// check form
			if (checked != 2){
				setDisplayBlockOrNoneById('element_user_info_error', true);
				return this.src;
			}
		
			if (document.getElementById('form_order_coupon').checked){
				// init a form post
				var
					form = document.getElementById('kitchen_request');
					
				form.action = '/print_process.pdf';
				form.submit();
				return this.src;
			}else{
				var
					encoded = buildURLEncodedFormData(document.getElementById('kitchen_request'));
				ajaxPostURLEncoded('/process_forms.html', encoded, null);
			}
			if (document.getElementById('form_order_book').checked)
				return 'state_success_book';
			else
				return 'state_success_folder';
		}
		this.setTransition('state_contact_book_2', 'next', 'state_success_book', check);
		this.setTransition('state_contact_book', 'next', 'state_success_book', check);
		
		// state_success_email
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');
			setContent('element_success_head', this.attributes['title']);
			setContent('element_success_text', this.attributes['text']);		
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');
		};
		
		this.addState('state_success_email', init, exit);
		this.setTransition('state_success_email', 'next', 'state_contact_howto', null);

		// state_success_call
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');
			setContent('element_success_head', this.attributes['title']);
			setContent('element_success_text', this.attributes['text']);		
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');
		};

		this.addState('state_success_call', init, exit);
		this.setTransition('state_success_call', 'next', 'state_contact_howto', null);

		// state_success_book
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');
			setContent('element_success_head', this.attributes['title']);
			setContent('element_success_text', this.attributes['text']);			
		};

		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');
		};

		this.addState('state_success_book', init, exit);
		this.setTransition('state_success_book', 'next', 'state_contact_howto', null);
		// state_success_folder
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');
			setContent('element_success_head', this.attributes['title']);
			setContent('element_success_text', this.attributes['text']);
		};

		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');
		};

		this.addState('state_success_folder', init, exit);
		this.setTransition('state_success_folder', 'next', 'state_contact_howto', null);

		// state_success_consultation
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');
			setContent('element_success_head', this.attributes['title']);
			setContent('element_success_text', this.attributes['text']);
		};

		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');
		};
		
		this.addState('state_success_consultation', init, exit);
		this.setTransition('state_success_consultation', 'next', 'state_contact_howto', null);
	}
	function onChange(_element){
		var _id = _element.id;
		
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}else
		if (_id == 'form_order_coupon'){
			setCheckedById('form_order_book', false);
			setCheckedById('form_order_folder', false);
			setCheckedById(_id, true);
		}else
		if (_id == 'form_order_book' || _id == 'form_order_folder'){
			setCheckedById('form_order_coupon', false);
			if (!getValueById('form_order_book') && !getValueById('form_order_folder'))
				setCheckedById(_id, true);
		}else
		if (_id == 'form_hour_from'){			
			document.getElementById('form_hour_to').selectedIndex = _element.selectedIndex+1;
		}
	}	
}
KitchenRequest.prototype = new StateMachine();

function MKBRequest(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	this.initCountrySelectBox = initCountrySelectBox;

	this.init();
	
	function initCountrySelectBox(){
		initCountrySelect(alpha2, iso1);
	}
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		
		// show state
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info');
			showElementById('element_message');
			hideElementById('element_message_error');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
			hideElementById('element_message_error');
		};
	
		this.addState('state_show_request', init, exit);
		
		// hide state
		init = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
			hideElementById('element_success_r');
			hideElementById('element_success_l');
		};
	
		this.setTransition('state_show_request', 'close', 'state_hide_request', null);
		this.addState('state_hide_request', init, null);

		init = function(_stm){
			showElementById('element_success_r');
			showElementById('element_success_l');
		};
	
		exit = function(_stm){
			hideElementById('element_success_r');
			hideElementById('element_success_l');
		};
	
		this.addState('state_success', init, exit);
		this.setTransition('state_success', 'close', 'state_hide_request', null);

		check = function(_stm){
			// check form
			var checked = checkUserData()+checkElementByLength('user_email', 6);
			if (checked!=2){
				showElementById('element_message_error');
				return 'state_show_request';
			}			
			
			var
				encoded = buildURLEncodedFormData(document.getElementById('kitchen_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return 'state_success';
		}
		this.setTransition('state_show_request', 'next', 'state_success', check);
	}

	function onChange(_element){
		var _id = _element.id;
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}
	}	
}
MKBRequest.prototype = new StateMachine();

function checkSupplierDataPage1(){
	var
		success = true;
	
	success &= checkElementByLength('user_firm', 3);
	success &= checkElementByLength('user_street', 3);
	success &= checkElementByLength('user_street_number', 1);
	success &= checkElementByLength('user_zipcode', 1);
	success &= checkElementByLength('user_city', 3);
	//success &= checkElementByLength('form_homepage', 1);
	success &= checkElementByLength('form_legalform', 1);
	success &= checkElementByLength('form_established_in', 1);
	//success &= checkElementByLength('form_concern', 1);
	//success &= checkElementByLength('form_subsidiary', 1);
	success &= checkElementByLength('form_employees', 1);
	success &= checkElementByLength('form_turnover', 1);
	success &= checkElementByLength('form_certification', 1);
	success &= checkElementByLength('form_products', 1);
	debug('checkSupplierDataPage1 return:'+success);
	return success;
}

function checkSupplierDataPage2(){
	var
		success = true;
	
	success &= checkElementByLength('user_name', 3);
	success &= checkElementByLength('user_surname', 3);
	success &= checkElementByLength('user_position', 3);
	//success &= checkElementByLength('user_department', 3);
	success &= checkElementByLength('user_phone', 3);
	success &= checkElementByLength('user_phone_idp', 2);
	success &= checkElementByLength('user_phone_ndp', 3);
	//success &= checkElementByLength('user_fax', 3);
	//success &= checkElementByLength('user_fax_idp', 2);
	//success &= checkElementByLength('user_fax_ndp', 3);
	//success &= checkElementByLength('user_email', 6);
	success &= checkElementByLength('form_message', 3);
	debug('checkSupplierDataPage2 return:'+success);
	return success;
}

function SupplierRequest(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	this.initCountrySelectBox = initCountrySelectBox;

	this.init();
	
	function initCountrySelectBox(){
		initCountrySelect(alpha2, iso1);
	}
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		
		// state_company_info
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_supplier_info_1');
			showElementById('element_supplier_info_2');
			hideElementById('element_supplier_info_2_error');		
		};
	
		exit = function(_stm){
			hideElementById('element_supplier_info_1');
			hideElementById('element_supplier_info_2');
			hideElementById('element_supplier_info_2_error');
		};
	
		this.addState('state_company_info', init, exit);
		
		// state_user_info
		init = function(_stm){
			showElementById('element_user_info');
			showElementById('element_message');
			hideElementById('element_message_error');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
			hideElementById('element_message_error');
		};
	
		this.addState('state_user_info', init, exit);
		
		// next transition
		check = function(_stm){
			if (!checkSupplierDataPage1()){
				showElementById('element_supplier_info_2_error');
				
				return this.src;
			}
			return this.target;
		}
		this.setTransition('state_company_info', 'next', 'state_user_info', check);
		
		// send transition
		check = function(_stm){
			if (!checkSupplierDataPage2()){
				showElementById('element_message_error');
				return this.src;
			}
			
			var
				encoded = buildURLEncodedFormData(document.getElementById('supplier_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return this.target;
		}
		this.setTransition('state_user_info', 'next', 'state_success', check);

		// state_success
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
		};
	
		this.addState('state_success', init, exit);
		this.setTransition('state_success', 'next', 'state_company_info', check);
	}

	function onChange(_element){
		var _id = _element.id;
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}
	}	
}
SupplierRequest.prototype = new StateMachine();

function ContactRequest(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	this.initCountrySelectBox = initCountrySelectBox;

	this.init();
	
	function initCountrySelectBox(){
		initCountrySelect(alpha2, iso1);
	}
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		
		// state_deutschland_contact
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info');
			showElementById('element_message');
			hideElementById('element_message_error');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
			hideElementById('element_message_error');
		};
	
		this.addState('state_deutschland_contact', init, exit);
		
		// send transition
		check = function(_stm){
			var checked = checkUserData()+checkElementByLength('form_message', 5)+checkElementByLength('user_email', 6);
			if (checked != 3){
				showElementById('element_message_error');
				return this.src;
			}
			setValueById('form_type', 'contact_deutschland');
			
			var
				encoded = buildURLEncodedFormData(document.getElementById('contact_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return this.target;
		}
		this.setTransition('state_deutschland_contact', 'next', 'state_deutschland_success', check);

		// state_deutschland_success
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
		};
	
		this.addState('state_deutschland_success', init, exit);
		this.setTransition('state_deutschland_success', 'next', 'state_deutschland_contact', null);
		
		
		// state_international_contact
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info');
			showElementById('element_message');
			hideElementById('element_message_error');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
			hideElementById('element_message_error');
		};
	
		this.addState('state_international_contact', init, exit);
		// send transition
		check = function(_stm){
			var checked = checkUserData()+checkElementByLength('form_message', 5)+checkElementByLength('user_email', 6);
			if (checked != 3){
				showElementById('element_message_error');
				return this.src;
			}
			setValueById('form_type', 'contact_international');
			
			var
				encoded = buildURLEncodedFormData(document.getElementById('contact_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return this.target;
		}
		this.setTransition('state_international_contact', 'next', 'state_international_success', check);
		// state_international_success
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');			
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
		};
	
		this.addState('state_international_success', init, exit);
		this.setTransition('state_international_success', 'next', 'state_international_contact', null);
	}

	function onChange(_element){
		var _id = _element.id;
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}
	}
}
ContactRequest.prototype = new StateMachine();
function VisitRequest(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	this.initCountrySelectBox = initCountrySelectBox;

	this.init();
	
	function initCountrySelectBox(){
		initCountrySelect(alpha2, iso1);
	}
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		
		// state_deutschland_anmeldung
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info');
			showElementById('element_message');
			hideElementById('element_message_error');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
			hideElementById('element_message_error');
		};
	
		this.addState('state_deutschland_anmeldung', init, exit);
		
		// send transition
		check = function(_stm){
			var checked = checkElementByLength('user_name', 2)+checkElementByLength('user_surname', 2)+checkElementByLength('user_phone', 3)+checkElementByLength('user_phone_ndp', 1);
			if (checked != 4){
				showElementById('element_message_error');
				return this.src;
			}
			setValueById('form_type', 'visit_exhibition');
			var
				val = getValueById('form_desired_date_input')+' '+getValueById('form_desired_hour_input')+':00:00';
				setValueById('form_desired_date', val);	
				setValueById('form_desired_date_text', val);				
			var
				encoded = buildURLEncodedFormData(document.getElementById('contact_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return this.target;
		}
		this.setTransition('state_deutschland_anmeldung', 'next', 'state_deutschland_anmeldung_success', check);

		// state_deutschland_anmeldung_success
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
		};
	
		this.addState('state_deutschland_anmeldung_success', init, exit);
		this.setTransition('state_deutschland_anmeldung_success', 'next', 'state_deutschland_anmeldung', null);
		
		
		// state_international_contact
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info');
			showElementById('element_message');
			hideElementById('element_message_error');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
			hideElementById('element_message_error');
		};
	
	}

	function onChange(_element){
		var _id = _element.id;
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}
	}
}
VisitRequest.prototype = new StateMachine();

function InfoRequest(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	this.initCountrySelectBox = initCountrySelectBox;

	this.init();
	
	function initCountrySelectBox(){
		initCountrySelect(alpha2, iso1);
	}
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		
		// state_deutschland_contact
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info');
			showElementById('element_message');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
		};
	
		this.addState('show_info_request', init, exit);
		init = function(_stm){
			_stm.initCountrySelectBox();
			hideElementById('element_user_info');
			hideElementById('element_message');
		};
	
		this.addState('hide_info_request', init, null);

		// info_request_success
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');			
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
		};
	
		this.addState('info_request_success', init, exit);
		
		// send transition
		check = function(_stm){
			if (!checkUserData()){
				return this.src;
			}
			var
				encoded = buildURLEncodedFormData(document.getElementById('contact_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return this.target;
		}		
		
		this.setTransition('show_info_request', 'next', 'info_request_success', check);
		this.setTransition('info_request_success', 'next', 'show_info_request', null);
	}

	function onChange(_element){
		var _id = _element.id;
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}
	}
}
InfoRequest.prototype = new StateMachine();

function JobRequest(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	this.initCountrySelectBox = initCountrySelectBox;

	this.init();
	
	function initCountrySelectBox(){
		initCountrySelect(alpha2, iso1);
	}
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		
		// show_job_request
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info_1');
			showElementById('element_user_info_2');
			hideElementById('element_user_info_2_error');		
		};
	
		exit = function(_stm){
			hideElementById('element_user_info_1');
			hideElementById('element_user_info_2');
			hideElementById('element_user_info_2_error');		
		};
	
		this.addState('show_job_request', init, exit);
		
		// hide_job_request
		init = function(_stm){
			_stm.initCountrySelectBox();
			hideElementById('element_user_info_1');
			hideElementById('element_user_info_2');
			hideElementById('element_user_info_2_error');
			hideElementById('element_job_info');
			hideElementById('element_message');
			hideElementById('element_message_error');
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
			hideElementById('formulare');						
		};
	
		this.addState('hide_job_request', init, null);
			
		// show_job_request2
		init = function(_stm){
			showElementById('element_job_info');
			showElementById('element_message');
			hideElementById('element_message_error');
		};
	
		exit = function(_stm){
			hideElementById('element_job_info');
			hideElementById('element_message');
			hideElementById('element_message_error');
		};
	
		this.addState('show_job_request2', init, exit);
		
		// next transition
		check = function(_stm){
			var
				success = true;
			
			success &= checkElementByLength('user_name', 3);
			success &= checkElementByLength('user_surname', 3);
			success &= checkElementByLength('user_street', 3);
			success &= checkElementByLength('user_zipcode', 1);
			success &= checkElementByLength('user_city', 3);
			success &= checkElementByLength('user_phone', 3);
			success &= checkElementByLength('user_phone_idp', 2);
			success &= checkElementByLength('user_phone_ndp', 3);
			success &= checkElementByLength('user_email', 6);			

			if (!success){
				showElementById('element_user_info_2_error');
				return this.src;
			}
			return this.target;
		}
		this.setTransition('show_job_request', 'next', 'show_job_request2', check);
		
		// send transition
			check = function(_stm){
			var
				success = true;
			
			success &= checkElementByLength('form_message', 3);
			if (!success){
				showElementById('element_message_error');
				return this.src;
			}
			
			var
				encoded = buildURLEncodedFormData(document.getElementById('job_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return this.target;
		}
		this.setTransition('show_job_request2', 'next', 'state_success', check);

		// state_success
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
		};
	
		this.addState('state_success', init, exit);
		this.setTransition('state_success', 'next', 'hide_job_request', check);
	}

	function onChange(_element){
		var _id = _element.id;
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}
	}	
}
JobRequest.prototype = new StateMachine();

function PressRequest(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	this.initCountrySelectBox = initCountrySelectBox;

	this.init();
	
	function initCountrySelectBox(){
		initCountrySelect(alpha2, iso1);
	}
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info');
			showElementById('element_message');
			document.getElementById('press_request').className="active";
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
		};
	
		this.addState('show_press_request', init, exit);
		init = function(_stm){
			_stm.initCountrySelectBox();
			hideElementById('element_user_info');
			hideElementById('element_message');
		};
	
		this.addState('hide_press_request', init, null);

		// info_request_success
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');			
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
		};
	
		this.addState('press_request_success', init, exit);
		
		// send transition
		check = function(_stm){
			if (!checkUserData()){
				return this.src;
			}
			var
				encoded = buildURLEncodedFormData(document.getElementById('contact_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			
			return this.target;
		}		
		
		this.setTransition('show_press_request', 'next', 'press_request_success', check);
		this.setTransition('press_request_success', 'next', 'show_press_request', null);
	}

	function onChange(_element){
		var _id = _element.id;
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}
	}
}
PressRequest.prototype = new StateMachine();

function ImagepartnerRequest(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	this.initCountrySelectBox = initCountrySelectBox;

	this.init();
	
	function initCountrySelectBox(){
		initCountrySelect(alpha2, iso1);
	}
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		
		// state_deutschland_contact
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info');
			showElementById('element_message');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
		};
	
		this.addState('show_imagepartner_request', init, exit);
		init = function(_stm){
			_stm.initCountrySelectBox();
			hideElementById('element_user_info');
			hideElementById('element_message');
		};
	
		this.addState('hide_imagepartner_request', init, null);

		// info_request_success
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');			
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
		};
	
		this.addState('imagepartner_request_success', init, exit);
		
		// send transition
		check = function(_stm){
			if (!checkUserData()){
				return this.src;
			}
			var
				encoded = buildURLEncodedFormData(document.getElementById('contact_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			return this.target;
		}		
		
		this.setTransition('show_imagepartner_request', 'next', 'imagepartner_request_success', check);
		this.setTransition('imagepartner_request_success', 'next', 'show_imagepartner_request', null);
	}

	function onChange(_element){
		var _id = _element.id;
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}
	}
}
ImagepartnerRequest.prototype = new StateMachine();

function ImagepartnerRequest2(_alpha2, _iso1){
	var
		alpha2 = _alpha2;
	var
		iso1 = _iso1;
	
	this.onChange = onChange;
	this.init = init;
	this.initCountrySelectBox = initCountrySelectBox;

	this.init();
	
	function initCountrySelectBox(){
		initCountrySelect(alpha2, iso1);
	}
	
	function init(){
		var
			init;
		var
			check;
		var
			exit;
		
		// state_deutschland_contact
		init = function(_stm){
			_stm.initCountrySelectBox();
			showElementById('element_user_info');
			showElementById('element_message');
		};
	
		exit = function(_stm){
			hideElementById('element_user_info');
			hideElementById('element_message');
		};
	
		this.addState('show_imagepartner_request', init, exit);
		init = function(_stm){
			_stm.initCountrySelectBox();
			hideElementById('element_user_info');
			hideElementById('element_message');
		};
	
		this.addState('hide_imagepartner_request', init, null);

		// info_request_success
		init = function(_stm){
			showElementById('element_success_l');
			showElementById('element_success_r');			
		};
	
		exit = function(_stm){
			hideElementById('element_success_l');
			hideElementById('element_success_r');			
		};
	
		this.addState('imagepartner_request_success', init, exit);
		
		// send transition
		check = function(_stm){
			if (!checkEmailData()){
				return this.src;
			}
			var
				encoded = buildURLEncodedFormData(document.getElementById('contact_request'));
			ajaxPostURLEncoded('/process_forms.html', encoded, null);
			return this.target;
		}		
		
		this.setTransition('show_imagepartner_request', 'next', 'imagepartner_request_success', check);
		this.setTransition('imagepartner_request_success', 'next', 'show_imagepartner_request', null);
	}

	function onChange(_element){
		var _id = _element.id;
		if (_id =='user_alpha2'){
			initCountrySelect(_element.value, iso1);
		}
	}
}
ImagepartnerRequest2.prototype = new StateMachine();
