window.addEvent('load', function() {

	/**
	*	Information box setups
	*/
	// group all infoboxes
	informationBox.hideAll("infoBox");

	infoBoxArray[0][1].start(1);

	// setup slide actions
	$('idName').addEvent('focus', function(){informationBox.showInfoBox(0);});
	$('idLastName').addEvent('focus', function(){informationBox.showInfoBox(1);});
	$('idMail').addEvent('focus', function(){informationBox.showInfoBox(2);});
	$('idPass').addEvent('focus', function(){informationBox.showInfoBox(3);});
	$('idConfPw').addEvent('focus', function(){informationBox.showInfoBox(4);});
	$('idPhone').addEvent('focus', function(){informationBox.showInfoBox(5);});
	$('idMobile').addEvent('focus', function(){informationBox.showInfoBox(6);});
	$('idCompany').addEvent('focus', function(){informationBox.showInfoBox(7);});
	$('idOrg').addEvent('focus', function(){informationBox.showInfoBox(8);});
	$('idAddress').addEvent('focus', function(){informationBox.showInfoBox(9);});
	$('idPostal').addEvent('focus', function(){informationBox.showInfoBox(10);});
	$('idCity').addEvent('focus', function(){informationBox.showInfoBox(11);});
	$('idCountry').addEvent('focus', function(){informationBox.showInfoBox(12);});


	/**
	*	END: Information box setups
	*
	*	Save profile checkform
	*/
	if($type($('saveUser'))) {
		$('saveUser').addEvent('click',function(e){
			new Event(e).stop();
			//var idFName = $('idName').getProperty('value');
			var idName = $('idName').getProperty('value');
			var idLastName = $('idLastName').getProperty('value');
			var idMail = $('idMail').getProperty('value');
			var idPwd1 = $('idPass').getProperty('value');
			var idPwd2 = $('idConfPw').getProperty('value');
			var idPhone = $('idPhone').getProperty('value');
			var idMobile = $('idMobile').getProperty('value');
			var idCompany = $('idCompany').getProperty('value');
			var idOrg = $('idOrg').getProperty('value');
			var idAddress = $('idAddress').getProperty('value');
			var idZipcode = $('idPostal').getProperty('value');
			var idCity = $('idCity').getProperty('value');
			var idCountry =  '';
			$('idCountry').getChildren().each(function(e){if(e.getProperty('selected')){idCountry = e.getProperty('value')}});
			var idBox1 = $('idBox1').getProperty('checked');

			var errorMsg = Array();

			var i = 0;
			if(idName == '') {
				errorMsg[i]=langArray['save.error.field.firstname'];
				i+=1;
			};
			if(idLastName == '') {
				errorMsg[i]=langArray['save.error.field.lastname'];
				i+=1;
			};
			if(idMail == '') {
				errorMsg[i]=langArray['save.error.field.email'];
				i+=1;
			};
			if(idPhone == '') {
				errorMsg[i]=langArray['save.error.field.phone'];
				i+=1;
			};
			if(idMobile == '') {
				errorMsg[i]=langArray['save.error.field.mobile'];
				i+=1;
			};
			if(idPwd1 != idPwd2) {
				errorMsg[i]=langArray['save.error.field.password.missmatch'];
				i+=1;
			};
			if(idPwd1 == '' || idPwd1.length < 6) {
				errorMsg[i]=langArray['save.error.field.password'];
				i+=1;
			};
			if(idCompany == '') {
				errorMsg[i]=langArray['save.error.field.name'];
				i+=1;
			};
			if(idOrg == '') {
				errorMsg[i]=langArray['save.error.field.idno'];
				i+=1;
			};
			if(idAddress == '') {
				errorMsg[i]=langArray['save.error.field.address'];
				i+=1;
			};
			if(idZipcode == '') {
				errorMsg[i]=langArray['save.error.field.zipcode'];
				i+=1;
			};
			if(idCity == '') {
				errorMsg[i]=langArray['save.error.field.city'];
				i+=1;
			};
			if(idCountry == '') {
				errorMsg[i]=langArray['save.error.field.country'];
				i+=1;
			};
			if(!idBox1) {
				errorMsg[i]=langArray['save.error.user.agreement'];
				i+=1;
			} 

			if(errorMsg.length > 0) {
				globalActions.err(errorMsg);
			} else {
				if (!this.hasClass('btnSaving')) {
					this.addClass('btnSaving');
					/*var data = {
						'firstname':idFName
					};
					globalActions.saveRequest("/register/save",data,this);*/
					$('saveUserForm').submit();
				} else {
					// wait.
				};
			};
		});
	}

   /**
	* Add event to Copy number button
	*
	* @author henhus
	**/	
	$('copyMobile').addEvent('click', function(e) {
		new Event(e).stop();
		$('idMobile').setProperty('value',$('idPhone').getProperty('value'));
	});
});