ApplyOnline = {
	validate : function( frm ) {
		var fields = [ 'firstname', 'lastname', 'position', 'company', 'vat_id', 'cui', 'address', 'city', 'zip', 'country', 'phone' ];
		var message = 'Please fill in all the fields marked in red';
		var valid = true;
		var color = '#FFEFEF';
		var focused = null;
		
		fields.each(
			function( field ) {
				var value = frm[field].value.clean();
				frm[field].style.background = '';
				if( value == '' ||  value < 0 ) {
					valid = false;
					frm[field].style.background = color;
					if( !focused ) { focused = field; }
				}
			}
		);
		
		frm.email.style.background = '';
		
		if( frm.email.value.indexOf('@') < 1 || frm.email.value.indexOf('.') < 2 ) {
			frm.email.style.background = color;
			valid = false;
			if( !focused ) { focused = 'email'; }
		}

		if( !valid ) {
			$('msg').innerHTML = message;
			$('msg').style.display = 'block';
			if( frm[focused] ) { frm[focused].focus(); }
			
			var pos = $('msg').getPosition();
			window.scrollTo( pos.x, pos.y - 10 );
		}
		
		return valid;
	}
}

ReferralRegister = {
	validate : function( frm ) {
		var fields = [ 'firstname', 'lastname', 'address', 'city', 'zip', 'country', 'phone', 'captchacode' ];
		var message = 'Please fill in all the fields marked in red';
		var valid = true;
		var color = '#FFEFEF';
		var focused = null;
		
		fields.each(
			function( field ) {
				var value = frm[field].value.clean();
				frm[field].style.background = '';
				if( value == '' ||  value < 0 ) {
					valid = false;
					frm[field].style.background = color;
					if( !focused ) { focused = field; }
				}
			}
		);
		
		frm.email.style.background = '';
		
		if( frm.email.value.indexOf('@') < 1 || frm.email.value.indexOf('.') < 2 ) {
			frm.email.style.background = color;
			valid = false;
			if( !focused ) { focused = 'email'; }
		}

		if( !valid ) {
			$('msg').innerHTML = message;
			$('msg').style.display = 'block';
			if( frm[focused] ) { frm[focused].focus(); }
			
			var pos = $('msg').getPosition();
			window.scrollTo( pos.x, pos.y - 10 );
		}
		
		return valid;
	}
}

ReferralLead = {
	validate : function( frm ) {
		var fields = [ 'name', 'code', 'position', 'address', 'city', 'zip', 'country', 'phone' ];
		var message = 'Please fill in all the fields marked in red';
		var valid = true;
		var color = '#FFEFEF';
		var focused = null;
		
		fields.each(
			function( field ) {
				var value = frm[field].value.clean();
				frm[field].style.background = '';
				if( value == '' ||  value < 0 ) {
					valid = false;
					frm[field].style.background = color;
					if( !focused ) { focused = field; }
				}
			}
		);
		
		frm.email.style.background = '';
		
		if( frm.email.value.indexOf('@') < 1 || frm.email.value.indexOf('.') < 2 ) {
			frm.email.style.background = color;
			valid = false;
			if( !focused ) { focused = 'email'; }
		}
		
		frm.ref_email.style.background = '';
		
		if( frm.ref_email.value.indexOf('@') < 1 || frm.ref_email.value.indexOf('.') < 2 ) {
			frm.ref_email.style.background = color;
			valid = false;
			if( !focused ) { focused = 'email'; }
		}

		if( !valid ) {
			$('msg').innerHTML = message;
			$('msg').style.display = 'block';
			if( frm[focused] ) { frm[focused].focus(); }
			
			var pos = $('msg').getPosition();
			window.scrollTo( pos.x, pos.y - 10 );
		}
		
		return valid;
	}
}

