//XMLhttp variable will hold the XMLHttpRequest object
var xmlhttp=null;
try  {
  // Firefox, Opera 8.0+, Safari
  xmlhttp=new XMLHttpRequest();
} catch (e)  {
  // Internet Explorer
  try	{
	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  }  catch (e)	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
// Ajax Implementation
function populateData(pid,type,id) {
	

	document.getElementById(id).className = 'links-act';
	//document.getElementById('search_spinner').style.display   = 'block';
	document.getElementById('propertyshow').style.display   = 'none';
	document.getElementById('loader').style.display   = 'block';
	var url = 'getPropertyNotes.php?pid='+pid+'&type='+type;
	
	//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
	xmlhttp.open('GET', url, true);
	//Check that the PHP script has finished sending us the result
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var responsetext =  xmlhttp.responseText;
			
			response		=	responsetext.split('#');
			if(response[0] == 1){
				alert("This property is already added to your list");	
				document.getElementById('property').innerHTML = response[1];
			}else{
				document.getElementById('property').innerHTML = response[0];
			}
			//document.getElementById('property').innerHTML = responsetext;
			//document.getElementById('search_spinner').style.display   = 'none';
			
		}
	}

	xmlhttp.send(null); 
}

function populateDelete(deleteid,id) {
	/*alert(document.getElementById(id).className);
	document.getElementById(id).className = 'links1';*/
	document.getElementById('propertyshow').style.display   = 'none';
	document.getElementById('loader').style.display   = 'block';
	
 	var url = 'getPropertyNotes.php?action=delete&DelId='+deleteid;
	//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
	xmlhttp.open('GET', url, true);
	//Check that the PHP script has finished sending us the result
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var responsetext =  xmlhttp.responseText;
			document.getElementById('property').innerHTML = responsetext;
			//document.getElementById('search_spinner').style.display   = 'none';

			
		}
	}

	xmlhttp.send(null); 
}

function populateDeletePD(deleteid,serviceid) {
	document.getElementById('search_spinner').style.display   = 'block';
	document.getElementById('propertyshow').style.display   = 'none';
	document.getElementById('loader').style.display   = 'block';
 	var url = 'getPropertyNotes.php?action=deletePD&DelId='+deleteid+'&ServiceId='+serviceid;

	//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
	xmlhttp.open('GET', url, true);
	//Check that the PHP script has finished sending us the result
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var responsetext =  xmlhttp.responseText;
			document.getElementById('party').innerHTML = responsetext;
			document.getElementById('search_spinner').style.display   = 'none';
		}
	}
	
	xmlhttp.send(null); 
}


function populateSave(sid,id) {
	document.getElementById(sid).className = 'links2-act';
	document.getElementById(sid).innerHTML = '<a >Save</a>';
	//document.getElementById(id).className = 'links1';
 	var url = 'getPropertyNotes.php?sid='+sid+'&uid='+id;
	//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
	xmlhttp.open('GET', url, true);
	//Check that the PHP script has finished sending us the result
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var responsetext =  xmlhttp.responseText;
			//document.getElementById('property').innerHTML = responsetext;
			//document.getElementById('search_spinner').style.display   = 'none';

			
		}
	}

	xmlhttp.send(null); 
}
function populateSaveOnload(sid,id) {
	document.getElementById(sid).className = 'links2-act';
	//document.getElementById(id).className = 'links1';
 	var url = 'getPropertyNotes.php?sid='+sid+'&uid='+id;
	//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
	xmlhttp.open('GET', url, true);
	//Check that the PHP script has finished sending us the result
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var responsetext =  xmlhttp.responseText;
			document.getElementById('property').innerHTML = responsetext;
			//document.getElementById('search_spinner').style.display   = 'none';

			
		}
	}

	xmlhttp.send(null); 
}