function getXmlHttp ()
{
	var getXmlHttp=false;

	try 
	{
		getXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");		
	} 
	catch (e) 
	{
		try 
		{
			getXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			getXmlHttp = false;
		}
	}
	
	if (!getXmlHttp && typeof XMLHttpRequest!='undefined') 
	{
		try 
		{
			getXmlHttp = new XMLHttpRequest();
		} 
		catch (e) 
		{
			getXmlHttp=false;
		}
	}
	if (!getXmlHttp && window.createRequest) 
	{
		try 
		{
			getXmlHttp = window.createRequest();
		} 
		catch (e) 
		{
			getXmlHttp=false;
		}
	}
	return getXmlHttp;
}

function gajax(type,url,request,objectId,getConfirm,returnWhat,hideProcessAfter)
{
	if ( getConfirm && ! confirm('Bu işlemi yapmak istediğinize emin misiniz?'))
	{
		return false;
	}

	var xmlHttp = getXmlHttp ();
	if (xmlHttp)
	{
		xmlHttp.open (type,url,true);
		
		var oProcess = null;
		var o = null;
		var oOks = null;
		var stringToEval = null;

		if (type == "POST")
		{
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=iso-8859-9");
		}
		
		if ( typeof ( objectId ) == "object" )
		{
			oProcess = document.getElementById(objectId[0]);
			oProcess.style.display = "block";
			
			o = document.getElementById(objectId[1]);
			o.style.display = "none";
		}
		
		xmlHttp.onreadystatechange = function ()
		{
			if (xmlHttp.readyState==4 && xmlHttp.status == 200) 
			{
				var responseText = String(xmlHttp.responseText);
				var parsedText = '';
				//alert(responseText);
				
				// array yapisina örnek: Array('divProcess','divError',Array('divOk1','divOk2')) ve ya Array('divProcess','divError','divOk')
				// ilk arg process objesi id'si.
				// ikinci arg error objesi id'si.
				// ücüncü arg Array ise diger taraftan OK0 ve ya OK1 seklinde deger döner, 3. char bize kacinci indexteki id'yi kullanacagimizi söyler.
				// ücüncü arg string ise, OK donen herhangi bir degerde direkt bu id kullanilir.
                if ( typeof ( objectId ) == "object" )
				{
					switch ( responseText.substr(0,2) )
					{
						case "ER":
							o = document.getElementById(objectId[1]);
							parsedText = responseText.substr(3);
							break;
							
						case "OK":
							if ( typeof ( objectId[2] ) == "object" )
							{
								var oindex = responseText.substr(2,1)
								//alert(oindex);
								o = document.getElementById(objectId[2][oindex]);
								parsedText = responseText.substr(4);
								
								for ( i = 0; i < objectId[2].length; i++ )
								{
									if ( oindex != i )
									{
										oOks = document.getElementById(objectId[2][i]);
										oOks.style.display = "none";
									}
								}
								
							}
							else
							{
								o = document.getElementById(objectId[2]);
								parsedText = responseText.substr(3);
							}
							
							var startEvalLocation = parsedText.indexOf("[EVAL]");
							
							if ( startEvalLocation > -1 )
							{
								var endEvalLocation = parsedText.indexOf("[/EVAL]");
								stringToEval = parsedText.substr(startEvalLocation + 6, endEvalLocation - ( startEvalLocation + 6 ) );
								var finalParsedText = parsedText.substr(0, startEvalLocation);
								finalParsedText = finalParsedText + parsedText.substr(endEvalLocation + 7);
								
								//alert(stringToEval);
								
								parsedText = finalParsedText;
								//alert(parsedText);
							}

	
							break;
					}
				}
				else
				{
					o = document.getElementById(objectId);
					parsedText = xmlHttp.responseText;
				}
						

				o.innerHTML = parsedText;
			
				if ( stringToEval != null )
				{
					eval(stringToEval);
				}
				
				//alert(parsedText);
				
				if ( hideProcessAfter && oProcess != null )
					oProcess.style.display = "none";					
				
				o.style.display = "block";
			}
			else
			{
				if ( oProcess != null )
					oProcess.style.display = "block";
			}
		};

		if ( typeof ( request ) == "object" ) // gönderilen request yine Array'lerden olusan bir Array'se..... Alt Array: [ formelement(object), formelementType ]..... formelementtype: radio, text, check, vs......
		{
			var sRequest = "";
			for ( i = 0; i < request.length; i++ )
			{
				if (request[i][1] == "hidden" || request[i][1] == "text" || request[i][1] == "textarea")
				{
					if ( request[i][0].getAttribute("ajaxid") != null )
						sRequest += escape(request[i][0].getAttribute("ajaxid")) + "=" + escape(request[i][0].value) + "&";
					else
						sRequest += escape(request[i][0].name) + "=" + escape(request[i][0].value) + "&";
				}
				else if (request[i][1] == "radio")
				{
					for ( j = 0 ; j <  request[i][0].length ; j++ )
					{
						if (request[i][0][j].checked)
						{
							sRequest += escape(request[i][0][j].name) + "=" + escape(request[i][0][j].value) + "&";
							break;
						}
					}
				}
				else if (request[i][1] == "select")
				{
					sRequest += escape(request[i][0].name) + "=" + escape(request[i][0].options[request[i][0].selectedIndex].value) + "&";
				}
				else if (request[i][1] == "editor")
				{
					tinyMCE.triggerSave();

					sRequest += escape(request[i][0].name) + "=" + escape(request[i][0].value) + "&";
				}
				else if (request[i][1] == "checkbox")
				{
					if ( request[i][0].checked )
						sRequest += escape(request[i][0].name) + "=" + escape(request[i][0].value) + "&";
					else
						sRequest += escape(request[i][0].name) + "=&";
				}
				
			}

			request = sRequest;
		}
		
		xmlHttp.send (request);	
		if ( oProcess != null )
			oProcess.style.display = "block";
	}
	else
	{
		return false;
	}

	if (returnWhat != null)
	{
		return returnWhat;
	}

}
