var translate = new Array();
translate['hu'] = new Array();
translate['en'] = new Array();

// fields:
translate['hu']['f_name'] = 'név/cégnév: ';
translate['hu']['f_email'] = 'email: ';
translate['hu']['f_message'] = 'üzenet: ';

translate['en']['f_name'] = 'name: ';
translate['en']['f_email'] = 'email: ';
translate['en']['f_message'] = 'message: ';

// messages:
translate['hu']['m_name'] = 'Kérjük adja meg a nevét!';
translate['hu']['m_message'] = 'Kérjük töltse ki az üzenet mezőt!';
translate['hu']['m_sending'] = 'Küldés...';
translate['hu']['m_sent'] = 'Üzenet elküldve.';
translate['hu']['m_error'] = 'Hiba történt az üzenet elküldése során.';

translate['en']['m_name'] = 'Please enter your name.';
translate['en']['m_message'] = 'Please fill out the message field.';
translate['en']['m_sending'] = 'Sending...';
translate['en']['m_sent'] = 'Message sent successfully.';
translate['en']['m_error'] = 'There was an error sending the message.';

Event.observe(window, 'load', function() {
	html_tag = $$('html')[0];
	var lang = html_tag.lang;
	
	$('frm_contact').onsubmit = function() { return false; }
	$('frm_name').onclick = function() { if (this.value == translate[lang]['f_name']) this.value = ''; }
	$('frm_name').onblur = function() { if (this.value == '') this.value = translate[lang]['f_name']; }
	$('frm_email').onclick = function() { if (this.value == translate[lang]['f_email']) this.value = ''; }
	$('frm_email').onblur = function() { if (this.value == '') this.value = translate[lang]['f_email']; }
	$('frm_message').onclick = function() { if (this.value == translate[lang]['f_message']) this.value = ''; }
	$('frm_message').onblur = function() { if (this.value == '') this.value = translate[lang]['f_message']; }
	
	Event.observe('frm_submit', 'click', function() {
		if ($F('frm_name') == '' || $F('frm_name') == translate[lang]['f_name']){
			alert(translate[lang]['m_name']);
			return false;
		}
		if ($F('frm_message') == '' || $F('frm_message') == translate[lang]['f_message']){
			alert(translate[lang]['m_message']);
			return false;
		}
		var opt = {
			method: 'post', 
			postBody: Form.serialize('frm_contact'),
			contentType: 'application/x-www-form-urlencoded',
			encoding: 'UTF-8',
			onLoading: function() {
				$('frm_submit').hide();
				$('frm_response').innerHTML = translate[lang]['m_sending'];
			},
			onSuccess: function(t) {
				if (t.responseText == 'OK') {
					$('frm_response').innerHTML = translate[lang]['m_sent'];
					$('frm_contact').reset();
				}
				else
					$('frm_response').innerHTML = translate[lang]['m_error'];
			}
		}
		new Ajax.Request('sendform_ajax.php', opt);
	});
});
