/* 
######################################################################
# earthspace 
# Version: 1.0
# Date         : 05-Feb-2007 
# Modification : 10-Feb-2007 
# =========================
# Coded by: Muhamad Thaha S
# Company : Netlife Solutions Pvt Ltd
######################################################################
######################################################################
# In this page contains all common ajax functions
#######################################################################

  1)createXmlHttp()													:	this function is used to create a new xmlHttp object.
  2)ued_encode(arr,current_index)						:   Function used to endcode the array for the passing the data to server for ajax
*/


//this function is used to create a new xmlHttp object.


function createXmlHttp()
{  
	var xmlHttp;
  	try
    {    
	// Firefox, Opera 8.0+, Safari    
	xmlHttp=new XMLHttpRequest();    
	}
  	catch (e)
    {    
		// Internet Explorer    
		try
      	{      
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
    	catch (e)
      	{     
			try
        	{        
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
      		catch (e)
        		{        
				alert("Your browser does not support AJAX!");        
				return false;        
				}      
		
		}    
	}
return xmlHttp;

}

//######################################################################################################################################
//Function used to endcode the array for the passing the data to server for ajax
//######################################################################################################################################

function ued_encode(arr,current_index) {
	var query = ""
	if(typeof current_index=='undefined') current_index = '';

	if(typeof(arr) == 'object') {
		var params = new Array();
		for(key in arr) {
			var data = arr[key];
			var key_value = key;
			if(current_index) {
				key_value = current_index+"["+key+"]"
			}

			if(typeof(data) == 'object') {
				if(data.length) { //List
					for(var i=0;i<data.length; i++) {
						params.push(key_value+"[]="+ued_encode(data[i],key_value)); //:RECURSION:
					}
				} else { //Associative array
					params.push(ued_encode(data,key_value)); //:RECURSION:
				}
			} else { //String or Number
				params.push(key_value+"="+encodeURIComponent(data));
			}
		}
		query = params.join("&");
	} else {
		query = encodeURIComponent(arr);
	}

	return query;
}
//###########################################################################################
