	var systempipe = null; //asuumed system pipe is NOT busy
	var q = 0;
	var r = -1; //folow q form 0. q starts the stuck.. here is missing 0 as the first request passes without queue
	var qArgs = new Array();

//	var jsAjaxReturned = new Array(); returnes value 
	
	function AJAX(args)//div, wait-mesages-div, msg, url, method, returncontent, display
	{
		if (systempipe == 1) //system is busy psh in q
		{
			qArgs.push(args);
			q++;
			return;
		}
		systempipe = 1;
		if (args[args.length-1] == 'debug')
			alert(args);
		
		
		cont = "";
		if (!args[5] || args[5] == 'undefined')
			args[5] = true; 
		if (!args[1] || args[1] == 'undefined')
			wait_div = args[0]; 
		else 
			wait_div = args[1];
		var method = args[4];
		
		WaitMessageDisplay(wait_div, args[2],args[5])
		var http = new HTTPObj();
			
		http.onreadystatechange = function()
		{		
				if (args[args.length-1] == 'debug')
					alert('Ready State: ' + http.readyState + ' HTTP Status ' + http.status);
				
				if (http.readyState == 4 && http.status == 200)
				{		
				
					///clear waiting msg 
						//window.clearTimeout(n); animated dots
						var wait_divx_ = getitem(wait_div); 
						wait_divx_.innerHTML = "";

					if (args[args.length-1] == 'debug')
						alert('Container: ' + args[0]);
					
					if (typeof(args[0]) != null)
						ChangeOpacity(20, args[0], 'down');
						
					var cont =  http.responseText;
					if (cont == '')
					{
							cont = ' &nbsp; ';
					}
					if (args[args.length-1] == 'debug')
						alert('Content: ' + http.responseText);
						
					
					if (cont)
					{
						if (args[0] != null && args[0] != '')
							Display(args[0], cont, args[4]);  ///ChangeOpacity(20, args[0], 'up'); this funciton is call in display
							systempipe = null;

						if (r < (q-1)) 
						{	
							AJAX(qArgs[++r]);
						}
						else 
						{
								qArgs.length = 0; 
								q = 0;
								r = -1;
						}
					}
					else 
					{
						if (args[0] != null && args[0] != '')
							Display(args[0], ' &nbsp; ', false, false); ///ChangeOpacity(20, args[0], 'up'); this funciton is call in display
					}
				}
			}

						if (!method && (args[3].split('?')))
							method = 'post';
						else if (!method && (!url.split('?')))
							method = 'get';
						else
							method = method.toLowerCase();

						if (method == 'post')
						{
							var urlstring = args[3].split('?');
							var urlfile = urlstring[0];
							var urlprm = urlstring[1];
								http.open("POST", urlfile, true);
								http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
								http.setRequestHeader("Content-length", urlprm.length);
								http.setRequestHeader("Connection", "Keep-Alive");
								http.send(urlprm);
						}
						if (method == 'get')
						{
								http.open("GET", args[3], true);
								http.send(null);
						}
	}
	
	var n = 0;
	function WaitMessageDisplay(container, msg, display)
	{
		//alert(container);	
		if (display)
		{
			if (container.constructor == Array)
			{
				for (i=0; i < container.length; i++)
				{	
					
					if (typeof msg == 'undefined') 
							currentmsg = '<em>Loading|||</em>';
					else if (typeof msg == 'string')
						currentmsg = msg;
					else if (msg.constructor == Array)
					{
						if (!msg[i])
							currentmsg = msg[0];
						else if (msg[i])
							currentmsg = msg[i];
						
					}
						div = getitem(container[i]);
						if (div.style.display == 'none')
							div.style.display = 'block';
							div.innerHTML = currentmsg;
							container[i].innerHTML = 'wwwstyles/default/ajax-loader.gif';
							//AnimatedDots(container[i], currentmsg);
				}
			}
			else 
			{
				
				//AnimatedDots(container, msg);
				container = getitem(container);
				
				if (typeof(container) == 'undefined' || typeof(container) == null || container == null || container == 'undefined' )
					return;
				
				if (container.style.display == 'none') 
						container.style.display = 'block';
				if(msg != "")
				{
					container.innerHTML = '<img src="ajax-loader.gif" align="absmiddle" /> ';
					container.innerHTML += ' '+ msg + '';
				}else
					container.innerHTML = '<img src="ajax-loader.gif" align="absmiddle" />';
				//alert(container.innerHTML);
			}
		}
	}
	
	function Display(container, content, display)
	{
		window.clearTimeout(n);
		if (container.constructor == Array)
		{
			var r = new Array();
			r = content.split("::::");
			if (display)
			{
				for (i=0; i < container.length; i++)
				{
						div = getitem(container[i]);
						if (div.style.display == 'none') //need check style.visibility as well
							div.style.dispalay = 'block';
						
						if (div.tagName == 'DIV')
							div.innerHTML = r[i];
						if (div.tagName == 'TEXTAREA')
						{
							r[i] = SpecialChar2Str(r[i]);
							r[i] = r[i].replace(/<br>/g, '\r\n');
							div.value = r[i];;
						}
				}
			} // don't display content 
		}
		else
		{
				if (display) 
				{
					var cc = container;
					container = getitem(container);
					if (container.style.display == 'none') 
						container.style.display = 'block';
					if (container.tagName == 'DIV' || container.tagName == 'SPAN')
						container.innerHTML = content;
					if (container.tagName == 'TEXTAREA')
					{
						content = SpecialChar2Str(content);
						content = content.replace(/<br>/g, '\r\n');
						container.value = content;
					}
					
				}
			ChangeOpacity(0, cc, 'up' );
		}
	}
	var zz = 0;
	
	
	var dotcounter = 0;
	function AnimatedDots(div, msg)
	{
		var x = getitem(div);
		x.innerHTML += ' <b>.</b> ';
		n = window.setTimeout("AnimatedDots('"+ div + "','"+ msg + "')", 250);
		dotcounter++;
		if (dotcounter==7)
		{
			x.innerHTML = msg;
			dotcounter = 0;
		}
	}
	
function HTTPObj()
	{
		 var xmlhttp = null;
		 if (!window.XMLHttpRequest)
		 {
				try
				 {
						xmlhttp = new ActiveXObject('Msxml2.XMLHTTP.6.0');
						return xmlhttp;
				 }catch(e)
				 {
					try
					 {
							xmlhttp = new ActiveXObject('Msxml2.XMLHTTP.5.0');
							return xmlhttp;
					 }catch(e)
					 {
						try
						 {
								xmlhttp = new ActiveXObject('Msxml2.XMLHTTP.4.0');
								return xmlhttp;
						 }catch(e)
						 {
							try
							 {
									xmlhttp = new ActiveXObject('Msxml2.XMLHTTP.3.0');
									return xmlhttp;
							 }catch(e)
							 {
								try
								 {
										xmlhttp = new ActiveXObject('Msxml2.XMLHTTP.4.0');
										return xmlhttp;
								 }catch(e)
							 	{
									try
									 {
											xmlhttp = new ActiveXObject('Msxml2.XMLHTTP.3.0');
											return xmlhttp;
									 }catch(e)
									 {
										try
										 {
												xmlhttp = new ActiveXObject('Msxml2.XMLHTTP.2.0');
												return xmlhttp;
										 }catch(e)
										 {
											try
											{
												  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
												  return xmlhttp;		
											  }	catch(e)
											  {
											    try
												 {
													xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");	
													return xmlhttp;
												 }catch(e)
												 {
													xmlhttp = false; 
												 }
											 }
										 }
									 }
								}
							 }
						 }
					 }
				 }
		}
		else //if (window.XMLHttpRequest)
		{
				try
				{
					xmlhttp = new XMLHttpRequest();	
				}
				catch (e)
				{
					xmlhttp = false;
				}
		  }
			return xmlhttp;
	}
//////////////// ajax ends here ////////////////////////////

	function getitem(id)
	{
		
			var britem = false; //browser item
	
			if (document.getElementById){
				britem = document.getElementById(id);
	
			}else if (document.all){
				britem = document.all[id];
				
			}else if (document.layers){
				britem = document.layers[id];
				
			}		
			return britem;
		}




