var req;

function handle_send_form( formId ){
	
	if ( !check_ChkFormular() ){
		return false;
	}
	$('noJs').value = 0;
	req	=	get_ajax_form_obj(req, $(formId).action, formId );	
	req.send();
	
	return true;
}

function get_ajax_form_obj( ajaxObj, actionUrl, formId ){

	//if ( !$defined(ajaxObj) ){
		
		var loaderId	=	'ajaxLoader'+formId.substr(0, 1).toUpperCase() + formId.substr(1);
				
		ajaxObj = new Request({
							method: 'post',
							url: 	actionUrl,
							data: 	$(formId),
							onRequest: function(){
													$('statusDiv').set('text', '');
													
													if ( $('statusDiv').getStyle('display') == "none" ){
														$('statusDiv').setStyle ('display', 'block');
														//$('statusDiv').setAttribute('style', 'display:block');
													}
													if ( !$defined($(loaderId)) ){
														var loader	=	new Element( 'img', {
																								'id':	loaderId,
																								'alt': 	'loader',
																								'src':	'/img/ico/loader.gif'										
																							} );
														$('statusDiv').adopt(loader, loaderId);
														
													}														
													
													showLoader( true, loaderId);
													/*$('Submit').disabled = true;*/														
										},
							onComplete: function(){
													/*$('Submit').disabled = false;*/
													showLoader( false, loaderId );
										},
							onSuccess: 	function( response ){
									 				$('statusDiv').setAttribute('style', 'color:#FFFFFF');
													$('statusDiv').set('html',response);
													$('statusDiv').morph('.successfull');
										},
							onFailure: 	function(){
									 				$('statusDiv').setAttribute('style', 'color:#FFFFFF');
													$('statusDiv').set('text', 'An error occured!');
													$('statusDiv').morph('.error');	
										}
		});
	//}
	
	return ajaxObj;
}
function get_ajax_post_obj( url, objData, resultDiv ){
	
	if ( !$defined(resultDiv) ){
		resultDiv	=	'statusDiv';
	}
	

	var req = new Request({
							method: 'post',
							url: url,
							data: 	objData,
							onRequest: function(){
											$(resultDiv).set('text', '');
											if ( !$defined($('sendMailLoader')) ){
										
													var loader	=	new Element( 'img', {
																								'id':	'sendMailLoader',
																								'alt': 	'loader',
																								'src':	'/img/ico/loader.gif'										
																							} );
													$(resultDiv).adopt(loader);
											}
												
											showLoader(true, 'sendMailLoader');												
									   },
							
							onComplete: function(text){
													showLoader(false, 'sendMailLoader');
							 						$(resultDiv).setStyle('color', '#FFFFFF');
													$(resultDiv).set('text', text);
													$(resultDiv).morph('.successfull');														
												  }
						});
	return req;
}

function get_ajax_post_obj_html( url, objData, resultDiv ){
	
	if ( !$defined(resultDiv) ){
		resultDiv	=	'statusDiv';
	}
	
	var req = new Request.HTML({
							method: 'post',
							url: url,
							data: 	objData,
							onRequest: function(){
											$(resultDiv).set('text', '');
											if ( !$defined($('sendMailLoader')) ){
										
													var loader	=	new Element( 'img', {
																								'id':	'sendMailLoader',
																								'alt': 	'loader',
																								'src':	'/img/ico/loader.gif'										
																							} );
													$(resultDiv).adopt(loader);
											}
												
											showLoader(true, 'sendMailLoader');												
									   },
							
							onComplete: function(html){
													showLoader(false, 'sendMailLoader');
							 						$(resultDiv).setStyle('color', '#FFFFFF');
													$(resultDiv).adopt('text', html);
													$(resultDiv).morph('.successfull');
												  }
						});
	return req;
}

//function that switches visibility of loadingImg
function showLoader(show, id){
	if ( typeof(id) == "undefined" ){
		id	=	"ajaxLoader";
	}
	
	if(show){
		$(id).style.display = 'block';
	}else{
		$(id).style.display = 'none';
	}
};
