
   //var http_request = false;
   
  
   
	//*******************************************************************************************   
   
   function makePOSTRequest(url, parameters, bpost, majax_div_panel, majax_add_info_to_panel, majax_wait_picture) {
   	
     var http_request = false;
	 	 //var majax_div_panel = '';
	   //var majax_wait_picture = '';
	   //var majax_add_info_to_panel = '';
   
      if (window.XMLHttpRequest) { // Mozilla, Safari,...

		//alert("Mozila");
		
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
         
         
         
      } else if (window.ActiveXObject) { // IE
      	
      	//alert("IE");
      	
         try {
         	http_request = new ActiveXObject("Microsoft.XMLHTTP");
            
         } catch (e) {
            try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");   
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      http_request.onreadystatechange = function () {
   
      if (http_request.readyState == 4) {
      
         //alert("Received 4");
      
         if (http_request.status == 200) 
         {
                       
			//alert(http_request.responseText);
			
			//alert("Received 200");
			
			var descNode = document.createElement("div"); 
			descNode.innerHTML = http_request.responseText;
			
			var jsScript = "";
			
			var divList = descNode.getElementsByTagName("div");
			
			
			for ( i = 0; i < divList.length; i++ )
			{
				
			  	if (majax_div_panel && majax_div_panel != '' && divList[i].id != '' && majax_div_panel.indexOf(divList[i].id) != -1)
			  	{
			  		
			  		var panel = document.getElementById(divList[i].id);
			  		
			  		if (panel != null && panel.innerHTML != divList[i].innerHTML) 
			  		{
			  			if (majax_add_info_to_panel || majax_div_panel.indexOf(divList[i].id+'+') != -1)
			  			{
			  				
			  				//alert('add');
			  				if (divList[i].innerHTML != '')
			  				{
				  				// add info to panel
						  		panel.innerHTML += divList[i].innerHTML;
						  	}
					  	}
					  	else
					  	{
					  		//alert('replace');
					  		// replace panel info
					  		panel.innerHTML = divList[i].innerHTML;
					  	}
						//alert(panel.innerHTML);
				  	}
			  	}
			  	
				else if ( majax_div_panel == '' && divList[i].id.substr(0,9) == "majax_div")
			  	{
			  		var panel = document.getElementById(divList[i].id);
			  		if (panel != null && panel.innerHTML != divList[i].innerHTML) 
			  		{
				  		panel.innerHTML = divList[i].innerHTML;
				  	}
			  	}
				else if ( divList[i].id.substr(0,8) == "majax_js")
				{
					
					//alert(divList[i].);
					 var re = new RegExp("<[script|\/script](.*?)>", "gi");
					 jsScript = divList[i].innerHTML.replace(re, '');
					 jsScript = jsScript.replace('&amp;','&');
					// alert(jsScript);
				}
				
			}
			
			if (jsScript!="")
			{
			  addscript(jsScript);
			}
			
			
			if (majax_wait_picture != '')
			{
			  var wp = document.getElementById(majax_wait_picture);
			  if (wp != null)
			  {
			  	wp.style.display = 'none';
			  }
			  
			}
            
         } 
         else 
         {
            //alert('There was a problem with the request.');
         }
         
      }
   };
    //-----------------------------------------------------------  
      if (bpost)
      {
	      http_request.open('POST', url, true);
	      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	      http_request.setRequestHeader("Content-length", parameters.length);
	  }
	  else
	  {
	  	  http_request.open('GET', url, true);
	      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	      http_request.setRequestHeader("Content-length", 0);
	  }
	    
      //http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
      //alert(parameters);
      //alert("Parameters sent");
   }
   
   //*******************************************************************************************

	function appendChild(node, text) { 
	  if (null == node.canHaveChildren || node.canHaveChildren) { 
	    node.appendChild(document.createTextNode(text)); 
	  } else { 
	    node.text = text; 
	  } 
	} 
	/*...*/ 
	function addscript(newScript) { 
		
		var old = document.getElementById('lastLoadedCommand');
		if (old) document.body.removeChild(old);
		
		var script = document.createElement("script"); 
		script.setAttribute('type','text/javascript'); 
		script.id = 'lastLoadedCommand';
		
		appendChild(script, newScript); 
		
		document.body.appendChild(script);
	}
	
	
	
   //*******************************************************************************************
   
   
   //*******************************************************************************************
   
   
   
   function majax_submit(scriptName, DivName, UpdatePanel, wait_picture, add_info_to_panel) 
   {
   	 
   	
   	  if (wait_picture)
   	  {
	   	  //majax_wait_picture = wait_picture;
	   	  document.getElementById(wait_picture).style.display = 'block';
	  	}
   	
   	  var params = "";
   	  
   	  if (DivName != '')
   	  {
		  var panel = document.getElementById(DivName);
		  
		  var list = panel.getElementsByTagName("input");
		  
		  for ( i = 0; i < list.length; i++ )
		  {
		  	if (list[i].type == 'checkbox' || list[i].type == 'radio')
		  	{
		  		if (list[i].checked)
		  		{
				  	params += "&"+list[i].name+"="+encodeURIComponent(list[i].value);
				  	
				}
			}
			else
			{
				params += "&"+list[i].name+"="+encodeURIComponent(list[i].value);
			}
		  }
		  
		   list = panel.getElementsByTagName("select");
		  
		  for ( i = 0; i < list.length; i++ )
		  {
		  	params += "&"+list[i].name+"="+encodeURIComponent(list[i].value);
		  }
		  
		  list = panel.getElementsByTagName("textarea");
		  
		  for ( i = 0; i < list.length; i++ )
		  {
		  	params += "&"+list[i].name+"="+encodeURIComponent(list[i].value);
		  }
		  
		}
	
	  //majax_add_info_to_panel = add_info_to_panel;
		
	  //alert(window.location.pathname);
      //majax_div_panel = UpdatePanel;
      //makePOSTRequest(window.location.pathname, params, true);
      makePOSTRequest(scriptName, params, true, UpdatePanel, add_info_to_panel, wait_picture);
      
      
      return false;
   }
   
   //*******************************************************************************************
   
   // add_info_to_panel - default is replace
   
   function majax_get(url, majax_panel, wait_picture, add_info_to_panel) 
   {
   
   	  if (wait_picture)
   	  {
	   	  //majax_wait_picture = wait_picture;
	   	  document.getElementById(wait_picture).style.display = 'block';
	  }
   	  	
   	  //majax_div_panel = majax_panel;
	  
	  	//majax_add_info_to_panel = add_info_to_panel;
	  
      makePOSTRequest(url, '', false, majax_panel, add_info_to_panel, wait_picture);
      	
      return false;
   }
   

