var arrElement = new Array();
var blnAjaxDebug = false;

function ajaxform( nameID, submitvalue, ResponseId )
{	
	if ( document.getElementById(nameID).SUBMIT != "undefined" )			
	{
		document.getElementById(nameID).SUBMIT.value = submitvalue;
	}
	if( ResponseId == undefined )
	{	
		ResponseId = 'contentAJAX';	
	}
		
	if ( arrElement[nameID] != 1 )
	{			
		advAJAX.assign(document.getElementById(nameID), {
			  onLoading : function() {			  	 
			  	  contentHTML = document.getElementById( ResponseId ).innerHTML;
			  	  document.getElementById( ResponseId ).innerHTML = document.getElementById( 'loadtemplate2' ).innerHTML;
			  },	
		      onSuccess : function(obj) {	
		      	  document.getElementById( ResponseId ).innerHTML = obj.responseText;			      	  		      	    	  			      	  	
		      	  ajaxDebug( obj.responseText );
		      },
		      onError : function(obj) {
		      	  document.getElementById( ResponseId ).innerHTML = contentHTML;	
		      	  window.alert('Wystąpił nieoczekiwany błąd. Powtórz operację.');
		      }
		    });	    
	}	
	
	if (document.getElementById(nameID) != "null"  )
	{
		arrElement[nameID] = 1;
	}
	
	return false;	
}

function ajaxget( link, ResponseId )
{
	if( ResponseId == undefined )
	{	
		ResponseId = 'contentAJAX';	
	}
	link = "index.php5?"+link+'&ajax=1';
	advAJAX.get({
    url: link,
    onLoading : function() {		
			  	  contentHTML = document.getElementById( ResponseId ).innerHTML;
			  	  document.getElementById( ResponseId ).innerHTML = document.getElementById( 'loadtemplate2' ).innerHTML;			  	  
		},
    onSuccess : function(obj) { 
    	document.getElementById( ResponseId ).innerHTML = obj.responseText; 
    	ajaxDebug( obj.responseText );
    	},
    onError : function(obj) {
		      	  document.getElementById( ResponseId ).innerHTML = contentHTML;	
		      	  window.alert('Wystąpił nieoczekiwany błąd. Powtórz operację.');
		}	
	});
}

function ajaxDebug( HTMLtext )
{
	if ( blnAjaxDebug == true )
  	{  	  	
		okno = window.open("","ajaxDebug","width=800,height=600,top=10,left=20,resizable=no,scrollbars=no,menubar=no,toolbar=no,status=no,location=no,status=no");
		okno.document.write('<HTML>');
		okno.document.write('<TITLE>DEBUG AJAX</TITLE>');
		okno.document.write('<HEAD>');
		okno.document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
		okno.document.write('</HEAD>');
		okno.document.write('<BODY>');
		okno.document.write(HTMLtext);	
		okno.document.write('</BODY>');
		okno.document.write('</HTML>');
		okno.document.close();
	}
}
