var Tr = new Object();
Tr.languages = new Array('pl', 'en');
Tr.languages['pl'] = new Array();
Tr.languages['en'] = new Array();
Tr.languages['pl']['freq'] = "To pole jest wymagane!";
Tr.languages['en']['freq'] = "This field is required!";


function alertObject (obj)
{
	var fieldContents;
	var details ="";
	for (var field in obj) {
		fieldContents = obj[field];
		if (typeof(fieldContents) == "function") {
			fieldContents = "(function)";
		}
		details += "  " + field + ": " + fieldContents + "\n";
	}
	alert(details);
};

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function showContactForm(top)
{
	top = top || 500;
	$('ContactDiv').style.top = top + 'px';
	$('ContactDiv').style.visibility = 'visible';
};


var send = true;

function sendContactForm()
{
	if(!send) { alert("Akcja juz wykonana"); return false; }
	send=false;
	var params = $('ContactForm').serialize(true);
	if(trim($('ContactForm').fullname.value) == '')
	{
		alert(Tr.languages[App.locale]['freq']);
		$('ContactForm').fullname.focus();
		send = true;
		return false;
	}
	if(trim($('ContactForm').phone.value) == '')
	{
		alert(Tr.languages[App.locale]['freq']);
		$('ContactForm').phone.focus();
		send = true;
		return false;
	}
	new Ajax.Request('/smallContact',
	{
		method: 'post',
		parameters: params,
		onSuccess: function(transport)
		{
			alert(transport.responseText);
			closeContactForm();
			send=true;
		},
		onFailure: function()
		{
			alert(':(');
			send=true;
		}
	});
};

function sendSmallContactForm()
{
	var params = $('ContactForm').serialize(true);
	$('ContactForm').disable();
	new Ajax.Request('/smallContact',
	{
		method: 'post',
		parameters: params,
		onSuccess: function(transport)
		{
			alert(transport.responseText);
			$('ContactForm').enable();
		},
		onFailure: function()
		{
			$('ContactForm').enable();
			alert(':(');
		}
	});
};

function closeContactForm()
{
	$('ContactDiv').style.visibility = 'hidden';
};
