function test_click() {
	alert('test click');
}


function checkAndSubmitForm(id_div,id_method,id_form,is_file) {
	f_gen = document.getElementById(id_div).getElementsByTagName('form')[0];
	ch = checkForm(f_gen);
	if(ch==true) {
		for(var i = 0;i<f_gen.elements.length;i++ ) {
			f_gen.elements[i].name = f_gen.elements[i].name.replace( /_required/, '' );
		}
		if(is_file == 0) {
			submitForm(id_div,id_method,id_form);
		}
		else {
			submitFormWfile(id_div,id_method,id_form);
		}
	}
}
function submitForm(id_div,id_method,id_form) {
	url_t = 'index.php?ajax=ajax&p=sendform&action='+ id_method +'&id_form=' + id_form;
	advAJAX.submit(document.getElementById(id_div).getElementsByTagName('form')[0], {
		url : url_t,
		onInitialization : function() {
			ajax_loader(true);
		},
		onSuccess : function(obj) {
			//document.getElementById(id_div).innerHTML = 'Formularz został wysłany';
			alert(obj.responseText);
			if (obj.responseText=='Formularz został wysłany. Dziękujemy!') {
  			advAJAX.get({
          url : 'index.php?ajax=ajax&p=getform&form_id='+id_form,
      		onInitialization : function() {

      		},
          onSuccess : function(obj) {
            setResponseTextToHtml(id_div, obj);
      			ajax_loader(false);
          },
          onError : function(obj) {
            alert("Form Error: " + obj.status); ajax_loader(false);
          }
        });
			}
			ajax_loader(false);
		}
	});
}
function submitFormWfile(id_div,id_method,id_form) {
	ajax_loader(true);
	url_t = 'index.php?ajax=ajax&p=sendform&action='+ id_method +'&id_form=' + id_form;
	document.getElementById(id_div).getElementsByTagName('form')[0].action = url_t;    // First target
    document.getElementById(id_div).getElementsByTagName('form')[0].target = "iframe1";
	document.getElementById(id_div).getElementsByTagName('form')[0].submit();
	alert('Formularz został wysłany. \n Dziękujemy!');
}

