/*
Kullanımı
var getResponse = AjaxHTTP( "POST", mStatusControl, mHostAddress, query );
*/

var IsDebug = false;
var IsAlert = false;
var ErrorMsg = "<font color=red>! İşlem Sırasında Hata Oluştu.Lütfen Tekrar Deneyiniz..</font>";
var NotFound = "İşlem Sayfası Bulunamadı.";

function AjaxHTTP( SubmitType, objStatus,objResponseText, HostAddress, Query )
{
     	/*
		AjaxHTTP Settings
		*/
		var oAjaxHTTP = null;
		var LoadingImage = '<img src="images/kitapseti/ajax-loader.gif" border="0" width="16" height="16" align="left" />';

		AjaxDebug(objStatus);

       try
       {
              if( window.XMLHttpRequest )
              {
                     oAjaxHTTP = new XMLHttpRequest();
              }
              else if( window.ActiveXObject )
              {
                     oAjaxHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
              }
              else
              {
                     alert( "XMLHTTP Desteği Yok - The AJAX Not Supported" );
              }

              if( oAjaxHTTP != null )
              { 
					 AjaxDebug("XMLHttpRequest Nesnesi Oluşturuldu.");
                     oAjaxHTTP.open( SubmitType, HostAddress, true );
					 oAjaxHTTP.onreadystatechange = function (){ HTTPStateContents( oAjaxHTTP,objStatus,objResponseText,HostAddress,LoadingImage ); }
                     oAjaxHTTP.setRequestHeader( 'Content-Type','application/x-www-form-urlencoded; charset=UTF-8' );
					 oAjaxHTTP.setRequestHeader("Connection", "close")
                     oAjaxHTTP.send( Query );
					 AjaxDebug("Query Gönderildi.."+HostAddress+Query);
              }
              else
              {
                     alert( "The AJAX Not Supported" );
              }
       }
       catch( e )
       {
			  AjaxDebug("Catch İçerisinde..");
              alert( "Error.." + e.message );
       }
}

//  ---------------------------------------

function HTTPStateContents( oAjaxHTTP,objStatus,objResponseText,HostAddress,LoadingImage )
{
       if( oAjaxHTTP.readyState == 1){ //// 2 ve 3 ü göz ardı ettik.
		   AjaxLoading( objStatus, LoadingImage );
       }
       else{
              if( oAjaxHTTP.readyState == 4 )
              {
				     if( oAjaxHTTP.status == 200){
						document.getElementById(objResponseText).innerHTML = oAjaxHTTP.responseText;
					 }
					 else if( oAjaxHTTP.status == 404 ){
							if(IsDebug){
							AjaxLoading( objStatus, NotFound + " -> " + oAjaxHTTP.statusText + " ->Host Address ;" + HostAddress );
							}
							else{
							AjaxLoading( objStatus, NotFound);
							}
                     }
                     else{
						 if(IsDebug){
                            AjaxLoading( objStatus, ErrorMsg + " -> " + oAjaxHTTP.statusText + " ->Host Address ;" + HostAddress );
						 }
						 else{
							AjaxLoading( objStatus, ErrorMsg);
						 }
                     }
              }
       }
}

//  ---------------------------------------

function AjaxLoading( objStatus, sMessage )
{
       if( objStatus != null )
       {
              document.getElementById(objStatus).innerHTML = sMessage;
       }
}


function AjaxDebug(sMessage){
	if(IsDebug){
		if(IsAlert){
		alert(sMessage);
		}
	}
}
