function ajexconnect()
	{
	
		var ajex;
		var browser=navigator.appName;
		
		if(browser == "Microsoft Internet Explorer")
		{
			ajex = new ActiveXObject("microsoft.XMLHTTP");
		}
		else
		{
			ajex = new XMLHttpRequest();
		}
		return ajex;
		
	}
	
	var http = ajexconnect();

function Ajax_autofill(txt)
{
	http.open('get', HTTP_URL+'autoFill.php?txt='+txt+'&LANG='+LANG);
	http.onreadystatechange = Ajax_autofill_res;
    http.send(null);
}
function Ajax_autofill_res()
{
		var response = http.responseText;
		var SatateId = new Array();
		SatateId = response.split('|!|');
		document.getElementById('city').value=SatateId[0];
		document.getElementById('state').value=SatateId[1];
		document.getElementById('edit-locations-0-postal-code').value=SatateId[2];
		initialize();
		var loc=document.getElementById('location').value+', '+document.getElementById('city').value+', '+document.getElementById('state').value;
		var txt='<b>'+document.getElementById('location').value+'</b>, <br> '+document.getElementById('city').value+' , <br> <b>'+document.getElementById('state').value+'</b>';
		if(SatateId[0]!='')
		{
			findLocation(loc,txt);
		}
		
}
function count_page(id)
	{
		http.open('get', HTTP_URL+'/count_page.php?nid='+id);
		http.onreadystatechange = count_page_res;
	    http.send(null);
	}
	
	function count_page_res()
	{	
		if(http.readyState == 4)
		{	
    	    var response = http.responseText;
		}

	}

	
		
	function ChangeGallegryImage(id)
	{
		http.open('get', HTTP_URL+'/imagegallery.php?nid='+id);
		http.onreadystatechange = Get_State_Gallery;
	    http.send(null);
	}
	
	function Get_State_Gallery()
	{	
		if(http.readyState == 4)
		{	
    	    var response = http.responseText;
		
			document.getElementById('edit-charities-wrapper').innerHTML=response;
		}

	}

function fill_other_field(field,value)
	{ 
		if(value=="")
		{
			return false;
		}
		http.open('get', HTTP_URL+'/fill_other_field.php?field='+field+'&value='+value);
		http.onreadystatechange = Get_fill_opher_field;
	    http.send(null);
return false;
	}
	function Get_fill_opher_field()
	{	
		if(http.readyState == 4)
		{	
    	    var response = http.responseText;
			var SatateId = new Array();
		//alert(response);
			SatateId = response.split('|');
		
		
		if(SatateId[0]=='4')
			{ 
				
					document.getElementById('postalcod').value=SatateId[1];
						 if(SatateId[2]!='')
						 {
							 	
							document.getElementById('city').value=SatateId[2];
						    document.getElementById('state').value=SatateId[3];
							document.getElementById('country').value=SatateId[4];
							if(document.getElementById('country').value!='')
		 					{    document.getElementById('country').focus();
							}
						 }
						  if(SatateId[3]=='')
						 {
							  document.getElementById('state').focus();
						 }
			  
			   
					var val = document.getElementById('country').value;
				
				if(SatateId[2]!='' && SatateId[3]!='' && SatateId[4]!='')
				{
					Show_location(val);
				}
									
			}
			if(SatateId[0]=='3')
			{ 
				if(SatateId[1]!='')
				{
					document.getElementById('city').value=SatateId[1];
						 if(SatateId[2]!='')
						 {
						    document.getElementById('state').value=SatateId[2];
							document.getElementById('country').value=SatateId[3];
	 					    if(document.getElementById('country').value!='')
		 					{    document.getElementById('country').focus();
							}
						 }					
			   }
			   else
			   {
				   document.getElementById('city').focus();
			   }
			   
					var val = document.getElementById('country').value;
				
				if(SatateId[1]!='' && SatateId[2]!='' && SatateId[3]!='')
				{
					Show_location(val);
				}
									
			}
			
			if(SatateId[0]=='2')
			{
					 if(SatateId[1]!='')
					 {
						document.getElementById('state').value=SatateId[1];
						document.getElementById('country').value=SatateId[2];
						document.getElementById('country').focus();
					 }
					 else
					 {
						 document.getElementById('state').focus();
					 }
					 if(SatateId[1]!='' && SatateId[2]!='')
					{
						var val = document.getElementById('country').value;
						Show_location(val);
					}
									
			}
			
			if(SatateId[0]=='1')
			{ 
					 if(SatateId[1]!='')
					 {
						document.getElementById('country').value=SatateId[1];
						var val = document.getElementById('country').value;
						Show_location(val);
					 }
					 else
					 {
						document.getElementById('country').focus();
					 }
					
					return false;
			}
		
			
			//document.getElementById('edit-charities-wrapper').innerHTML=response;
		}

	}
	
function blog_map(field,value)
	{ 
		if(value=="")
		{
			return false;
		}
		http.open('get', HTTP_URL+'/fill_other_field.php?mode=blog&field='+field+'&value='+value);
		http.onreadystatechange = Get_fill_blog_field;
	    http.send(null);
		return false;
	}

function Get_fill_blog_field()
	{	
		if(http.readyState == 4)
		{	
    	    var response = http.responseText;
			var SatateId = new Array();
		
			SatateId = response.split('|');
		
		
		if(SatateId[0]=='2')
			{
					 if(SatateId[1]!='')
					 {
						document.getElementById('blogstate').value=SatateId[1];
						document.getElementById('blogcountry').value=SatateId[2];
						if(SatateId[2]==''){
							document.getElementById('blogcountry').focus();
						}
					 }
					 else
					 {
						 document.getElementById('blogstate').focus();
					 }
					 if(SatateId[1]!='' && SatateId[2]!='')
					{
						var val = document.getElementById('blogcountry').value;
						Show_blog_location(val);
					}
									
			}
			
			if(SatateId[0]=='1')
			{ 
					 if(SatateId[1]!='')
					 {
						document.getElementById('blogcountry').value=SatateId[1];
						var val = document.getElementById('blogcountry').value;
						Show_blog_location(val);
					 }
					 else
					 {
						document.getElementById('blogcountry').focus();
					 }
					
					return false;
			}
			
			
			
			
			//document.getElementById('edit-charities-wrapper').innerHTML=response;
		}

	}
	
	function fillstate(mode,val)
	{ 
		/*if(val=="")
		{
			return false;
		}*/
		http.open('get', HTTP_URL+'/countrystate.php?mode='+mode+'&value='+val);
		http.onreadystatechange = Get_fillstate;
	    http.send(null);
		return false;
	}
	function Get_fillstate()
	{	
		if(http.readyState == 4)
		{	
    	    var response = http.responseText;
			var SatateId = new Array();
			SatateId = response.split('|');
		//alert(response);
		document.getElementById('state').innerHTML=response;
	
		}
	}