function progress()
{
	$('submit').innerHTML = '<img src="/i/progressSetup.gif" class="progressSetup" />';
}

function ajaxSendMessage()
{
	var errors = document.getElementsByClassName('error');
	errors = $A(errors);
	
	errors.each(function(span) {
		Element.hide(span);
	});
	
	new Ajax.Request(siteurl + 'wyslij_wiadomosc/' + $F('guid'),
	{
		asynchronous: true,
		method: 'post',
		postBody:
			'ajax=1' + '&send=' + encodeURIComponent($F('msgSend')) +
			'&title=' + encodeURIComponent($F('msgTitle')) +
			'&content=' + encodeURIComponent($F('msgContent')),
   		onComplete: function(obj) { 
   			$('submit').innerHTML = '<a href="#" onmousedown="ajaxSendMessage();" rel="insert" ><input class="button btn-send" type="button"  name="send" id="msgSend" value="Wyślij"/></a>';
   			response(obj); },
   		onLoading: progress()
   	});
	
   	return false;
}

function ajaxSendContactInvitationMessage()
{
	var errors = document.getElementsByClassName('error');
	errors = $A(errors);
	
	errors.each(function(span) {
		Element.hide(span);
	});
	
	new Ajax.Request(siteurl + 'zapros_do_kontaktow/' + $F('guid'),
	{
		asynchronous: true,
		method: 'post',
		postBody:
			'ajax=1' + '&send=' + encodeURIComponent($F('msgSend')) +
			'&content=' + encodeURIComponent($F('msgContent')),
   		onComplete: function(obj) { 
   			$('submit').innerHTML = '<a href="#" onmousedown="ajaxSendContactInvitationMessage();" rel="insert" ><input class="button btn-send" type="button"  name="send" id="msgSend" value="Wyślij"/></a>';
   			response(obj); },
   		onLoading: progress()
   	});
	
   	return false;
}

function ajaxSendMassPrivateMessage()
{
	var errors = document.getElementsByClassName('error');
	errors = $A(errors);
	
	errors.each(function(span) {
		Element.hide(span);
	});
	
	
	new Ajax.Request(siteurl + 'biuletyn_grupy/' + $F('guid'),
	{
		asynchronous: true,
		method: 'post',
		postBody:
			'ajax=1' + '&send=' + encodeURIComponent($F('msgSend')) +
			'&title=' + encodeURIComponent($F('msgTitle')) +
			'&content=' + encodeURIComponent($F('msgContent')),
   		onComplete: function(obj) { 
   			$('submit').innerHTML = '<a href="#" onmousedown="ajaxSendMassPrivateMessage();" rel="insert" ><input class="button btn-send" type="button"  name="send" id="msgSend" value="Wyślij"/></a>';
   			response(obj); },
   		onLoading: progress()
   	});
	
   	return false;
}

function ajaxSendGroupInvitationMessage()
{
	var errors = document.getElementsByClassName('error');
	errors = $A(errors);
		
	errors.each(function(span) {
		Element.hide(span);
	});
	
	new Ajax.Request(siteurl + 'zapros_do_grupy/' + $F('guid'),
	{
		asynchronous: true,
		method: 'post',
		postBody:
			'ajax=1' + '&send=' + encodeURIComponent($F('msgSend')) +
			'&groupID=' + encodeURIComponent($F('groupID')) +
			'&content=' + encodeURIComponent($F('msgContent')),
   		onComplete: function(obj) { 
   			$('submit').innerHTML = '<a href="#" onmousedown="ajaxSendGroupInvitationMessage();" rel="insert" ><input class="button btn-send" type="button"  name="send" id="msgSend" value="Wyślij"/></a>';
   			response(obj); },
   		onLoading: progress()
   	});

   	return false;
}


function ajaxSendSiteInvitationMessage()
{
	var errors = document.getElementsByClassName('error');
	errors = $A(errors);
		
	errors.each(function(span) {
		Element.hide(span);
	});
	
	new Ajax.Request($('frm-recommend').action,
	{
		asynchronous: true,
		method: 'post',
		postBody:
			'ajax=1' + '&send=' + encodeURIComponent($F('msgSend')) +
			'&emails=' + encodeURIComponent($F('emails')) +
			'&content=' + encodeURIComponent($F('msgContent')),
   		onComplete: function(obj) {
   			$('submit').innerHTML = '<a href="#" onmousedown="ajaxSendSiteInvitationMessage();" rel="insert" ><input class="button btn-send" type="button"  name="send" id="msgSend" value="Wyślij"/></a>';
   			response(obj);
   		},
   		onLoading: progress()
   	});

   	return false;
}

function ajaxSendModeratorMessage()
{
	var errors = document.getElementsByClassName('error');
	errors = $A(errors);
	
	errors.each(function(span) {
		Element.hide(span);
	});
	
	new Ajax.Request($('frm-recommend').action,
	{
		asynchronous: true,
		method: 'post',
		postBody:
			'ajax=1' + '&send=' + encodeURIComponent($F('msgSend')) +
			'&reason=' + encodeURIComponent($F('msgReason')) +
			'&description=' + encodeURIComponent($F('msgDescription')),
   		onComplete: function(obj) { 
   			$('submit').innerHTML = '<a href="#" onmousedown="ajaxSendModeratorMessage();" rel="insert" ><input class="button btn-send" type="button"  name="send" id="msgSend" value="Wyślij"/></a>';
   			response(obj); },
   		onLoading: progress()
   	});
	
   	return false;
}

function ajaxSendTicketReplyMessage()
{
	var errors = document.getElementsByClassName('error');
	errors = $A(errors);
	
	errors.each(function(span) {
		Element.hide(span);
	});
	
	new Ajax.Request($('frm-recommend').action,
	{
		asynchronous: true,
		method: 'post',
		postBody:
			'ajax=1' + '&send=' + encodeURIComponent($F('msgSend')) +
			'&content=' + encodeURIComponent($F('msgContent')),
   		onComplete: function(obj) { 
   			$('submit').innerHTML = '<a href="#" onmousedown="ajaxSendTicketReplyMessage();" rel="insert" ><input class="button btn-send" type="button"  name="send" id="msgSend" value="Wyślij"/></a>';
   			response(obj); },
   		onLoading: progress()
   	});
	
   	return false;
}


function ajaxContestApply()
{
	var errors = document.getElementsByClassName('error');
	errors = $A(errors);
	
	errors.each(function(span) {
		Element.hide(span);
	});

	new Ajax.Request(siteurl + 'konkurs/' + $F('guid') + '/zglos',
	{
		asynchronous: true,
		method: 'post',
		postBody:
			'ajax=1' + '&send=' + encodeURIComponent($F('msgSend')) +
			'&description=' + encodeURIComponent($F('msgDescription')),
   		onComplete: function(obj) { 
   			$('submit').innerHTML = '<a href="#" onmousedown="ajaxContestApply();" rel="insert" ><input class="button btn-send" type="button"  name="send" id="msgSend" value="Wyślij"/></a>';
   			response(obj); },
   		onLoading: progress()
   	});
	
   	return false;
}


function response(obj)
{
	var response = obj.responseText;
	
	text = response.split('^');
	if (text[0] == 'ERROR')
	{
		for(i=1; i<text.length; i++)
		{
			error = text[i].split('|');
			$(error[0]+'Error').innerHTML = error[1];
			Element.show(error[0]+'Error');
		}
	}
	else if (text[0] == 'MESSAGE')
	{
		Element.hide('formBox');
		$('msgMonit').className = 'message green';
		$('msgMonit').innerHTML = text[1];
		Element.show('monitBox');
	}
	else
	{
		Element.hide('formBox');
		$('msgMonit').className = 'message red';
		$('msgMonit').innerHTML = 'Błąd! ' + response;
		Element.show('monitBox');
	}
}