var queue = null;

function ajax_set_location(geo_field_id)
{	
	var webroot = $('#geowebroot').val();
	var location = $.trim($('#'+geo_field_id).val());
	
	if(queue!==null)
			queue.abort(); 

//@author:mansari
//@ondate:22/11/2011
//ticket: 10 Progress bar not accept with alphabets specail character(http://www.jillslist.com/) 
//@desc: Adding validation for special character
var success_call = true;            
var iChars = '~!@#$%^*()_+={}[]|":;/?.><';

var geoLength = location.length;
if (geoLength > 0)
    {
        for (var i = 0; i < geoLength; i++)
        {
            if (iChars.indexOf(location.charAt(i)) != -1) 
            {
                success_call = false;
                alert('Your location has special characters. \n Please remove them and try again.');
                break;
            }
        }
    }
        
	if(location!='' && success_call)
	{
		queue = $.ajax({
			type: "POST",
			url: webroot+'locations/ajax_set_location',
			data: "ajax=true&location="+location,
			beforeSend: function() {
				$('.bubbleInfo').html('<img src="'+webroot+'img/ajax/wheel_throbber.gif" alt=""/>');
			},
			success: function(msg)
			{
				if(msg!='Not a valid location.')
				{
					//$('#geolocation_display').html(msg);
					window.location.reload();
				}
				else
					alert(msg);
			}
		});
	}
}
