var http;// = getHTTPObject();
function handleHttpResponse() 
{ 
	if (http.readyState == 4) 
	{	
		//alert(http.responsetext);
      	isWorking = false;
    	if (http.responseText.indexOf('invalid') == -1) 
		{
			var xmlDocument = http.responseXML; 
			var no = xmlDocument.getElementsByTagName('id').length;
			
			//alert(document.getElementById("allCommunities"));
			
			var allCommunities=document.getElementById("allCommunities");
			allCommunities.length=no;
			
			/*var no_new = document.getElementById('Communities').length;
			for(j=0,i=0;j<parseInt(no_new);j++)
			{
			 	Communities[j].value = "";
				Communities[j].text = "";											
			}
			document.getElementById('Communities').length = 0;*/
			
			
			//alert(state_name);
			if(parseInt(no)>0)
			{			
				for(j=0;j<parseInt(no);j++)
				{
					
					var idd = xmlDocument.getElementsByTagName('id').item(j).firstChild.data;
		   			var area = xmlDocument.getElementsByTagName('area').item(j).firstChild.data;
					
					allCommunities[j].value	= area;
	   				allCommunities[j].text 	= area;
   					isWorking = false;
					
					
				}
				isWorking = false;
			}else{
					
				isWorking = false;
			}	
			
				//document.getElementById("product_area").innerHTML = html;

    	}else{
			isWorking = false;
		}
	}
}

function getArea()
{
	var city = document.getElementById('City_value').value;
	if(!city)
		return false;
	var url = AJAX_URL + "getArea.php?code=";
	var isWorking = false;
	if (!isWorking)
	{
		isWorking = true;
		url += city;
		//alert(url);
		//return false;
		if (window.XMLHttpRequest)
	  	{
	  		http=new XMLHttpRequest()
	  		http.open("GET",url, true)
		  	http.onreadystatechange=handleHttpResponse
		  	http.send(null)
	  	}
		// code for IE
		else if (window.ActiveXObject)
	  	{
	  		http=new ActiveXObject("Microsoft.XMLHTTP")
	    	if (http)
	    	{
	    		http.open("GET",url, true);
	    		http.onreadystatechange=handleHttpResponse
	    		http.send()
	    	}
	  	}
  	}
}

function additem()
{
		//alert(document.getElementById('allCommunities').length);
		var no = document.getElementById('allCommunities').length;
		//alert(no);
		var no_new = document.getElementById('Communities').length;
		//alert(no_new);
		var allCommunities=document.getElementById('allCommunities');
		//alert(allCommunities);
		var Communities=document.getElementById('Communities');
		//alert(Communities);
		for(j=0;j<parseInt(no);j++)
		{
			if(allCommunities[j].selected)
			{
				var flag = 0;
				if(parseInt(no_new))
				{
					for(t=0;t<parseInt(no_new);t++)
					{
						
						if(Communities[t].value == allCommunities[j].value)
							flag = 1;
					}		
					//alert(flag);	
					if(flag == 0)
					{
						document.getElementById('Communities').length = document.getElementById('Communities').length + 1;
						var k = document.getElementById('Communities').length -1;
						Communities[k].value = allCommunities[j].value;
						Communities[k].text = allCommunities[j].value;
					}
				}
				else
				{
						document.getElementById('Communities').length = document.getElementById('Communities').length + 1;
						var k = document.getElementById('Communities').length -1;
						Communities[k].value = allCommunities[j].value;
						Communities[k].text = allCommunities[j].value;
				}
			}
				
		}
		//allCommunities.length = allCommunities.length + 
}
function removeitem()
{
	var no = document.getElementById('Communities').length;
	var no_new = document.getElementById('Communities').length;
	var arr_comm =  new Array;
	
	var Communities=document.getElementById('Communities');
	for(j=0,i=0;j<parseInt(no);j++)
	{
		if(!Communities[j].selected)
		{   
		 	arr_comm[i] = Communities[j].value;
			i++;												
		}
	}
	
	document.getElementById('Communities').length = arr_comm.length;
	var no_new = document.getElementById('Communities').length;
	for(j=0,i=0;j<parseInt(no_new);j++)
	{
		 	Communities[j].value = arr_comm[j];
			Communities[j].text = arr_comm[j];											
	}
	
}
