// JavaScript Document
//alert("including ajax_funcs_ee");
  var resultType='xml';
  var doc="";
  var reqUrl="";
  var userCBfunc="";
  var http_request = false;
  var queryString = null;
  var method = 'GET';

 function AJAX_getXml(url, userCallbackFunc)
 {
	   //alert("AJAX_getxml");
       userCBfunc= function (doc) {  userCallbackFunc(doc);};
       //alert(userCBfunc);
	   reqUrl = url;
	   resultType= 'xml';
	   AJAX_createHttpRequest();
 }

 function AJAX_getText(url, userCallbackFunc)
 {
       
	   userCBfunc= function (doc) { userCallbackFunc(doc);};
	   reqUrl = url;
	   resultType= 'text';
	   AJAX_createHttpRequest();
 }
//function doNothing();
 function AJAX_submitForm(url, qs, sendMethod, userCallbackFunc)
 {
//		alert("processing your request");
       userCBfunc= function (doc) {  userCallbackFunc(doc);};
      // alert(userCBfunc);
	   reqUrl = url;
	  // alert(reqUrl);
	   resultType= 'text';
	  // alert(resultType);
//	  document.write(url + '?' + qs);
	   queryString=qs;
	  //alert(queryString);
//		alert("in submitForm");
	   method=sendMethod;
	 //  alert(method);
	   AJAX_createHttpRequest();
 }
 
function ajaxCallbackFunc()
{
   // alert('ajaxCallbackFunc');

   if (http_request.readyState == 4) 
	{
 //       alert('readyState = 4');
	try 
	{
		  if (http_request.status == 200)
		   {
					// perfect!
				 //   alert('status = 200');
					if (resultType=='xml')
					{
				//        alert('resultType = xml');
						doc = http_request.responseXML; 
					}
					else
					{
						doc = http_request.responseText; 
					}
					
					userCBfunc(doc);
	
		   } 
		   else 
		   {
			   
		// there was a problem with the request,
		// for example the response may be a 404 (Not Found)
		// or 500 (Internal Server Error) response codes
		 //  alert('There was a problem with the request.');
	
		   }
	}
	catch (e) {
		//alert('Problem ');
		}

		// everything is good, the response is received
	} 
	else
	{
       // alert('still not ready');
		// still not ready
	}
	

}

function AJAX_createHttpRequest ()
{
    //alert('AJAX_createHttpRequest');

	 
	 if(window.ActiveXObject)
	 {
          //alert('IE browser');

           try 
			{
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } 
			catch (e) 
			{
               //alert('failed to create Msxml2.XMLHTTP');
               try 
				{
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                }
				catch (e) {alert('Problem creating Microsoft.XMLHTTP');}
			}
		    //alert(http_request);

     }
	 else if (window.XMLHttpRequest)
	 { // Mozilla, Safari, ...
   		 //alert(' Mozilla, Safari, ...');
		try{
		http_request = new XMLHttpRequest();}
		catch(e) {
			http_request = false;
        }

        //alert('new XMLHttpRequest()');
		http_request.overrideMimeType('text/xml');
         //alert('overrideMimeType');
	 }
	 else
	 {
		 alert('unknown browser...');
	 }
	 
	 
	 if (!http_request)
	 {
            alert('Giving up :Cannot create an XMLHTTP instance');
            return false;
     }
	
    //alert('about to define callback function');
	http_request.onreadystatechange = function(){ajaxCallbackFunc()};
	
    try
    {
		var thisPage = String(document.location);
		if (thisPage.toLowerCase().indexOf("http://www.aish.com")!=-1)
		{	
			reqUrl = reqUrl.replace(/http:\/\/aish.com/i,"http://www.aish.com");
            //alert(reqUrl);
		}
		else if (thisPage.toLowerCase().indexOf("http://aish.com")!=-1)
		{
			reqUrl = reqUrl.replace(/http:\/\/www.aish.com/i,"http://aish.com");
            //alert(reqUrl);
		}
		
        //alert(reqUrl);
		http_request.open(method, reqUrl, true);
	}
	catch (e) {alert('Problem open Microsoft.XMLHTTP');}
    //alert('open');


	if (method=='POST')
	{
	    try
	    {   
	        http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	        //alert('method is POST')
	    }
	    catch (e) {alert('Problem with setRequestHeader');}
	    //alert('request header');
	} 	
	
	//alert('method: '+method+', reqUrl: <br><br>'+reqUrl);
	//document.write(reqUrl+'?'+queryString);
	try
	{
	    http_request.send(queryString);
	}
	catch (e) {alert('Problem sending Microsoft.XMLHTTP');}
    //alert('send');
}

 


