var xmlHttp;

function GetXmlHttpObject() {
	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");
	  }
	 }
	return xmlHttp;
} // end function

//######################################################
function addCPDinner(cp_id, d ) {
	document.getElementById("dinner").innerHTML="";

	if (d.length > 0) {		 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		} // end if 
		
		var url="/php/membership.php";
		url=url+"?cp_id="+cp_id;
		url=url+"&a=adddinner";
		url=url+"&d="+d;
		xmlHttp.onreadystatechange=stateChangedDinner;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} // end if

	if (d.length==0) { 	 
	 return;
	} // end if
} // end function

function stateChangedDinner() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  { 
		 document.getElementById("dinner").innerHTML="";
		 document.getElementById("dinner").innerHTML=xmlHttp.responseText;
	 } // end if
} // end function

//#############################################################
function addCPVisit(cp_id, d ) {
	if (d.length > 0) {		 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		} // end if 
		
		var url="/php/membership.php";
		url=url+"?cp_id="+cp_id;
		url=url+"&a=addcpvisit&";
		url=url+"&d="+d;
		url=url+"&type=3";
		xmlHttp.onreadystatechange=stateChangedVisits;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} // end if

	if (d.length==0) { 	 
	 return;
	} // end if
} // end function

function stateChangedVisits() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  { 
		 document.getElementById("visits").innerHTML="";
		 document.getElementById("visits").innerHTML=xmlHttp.responseText;
	 } // end if
} // end function

//#############################################################
function addPastorVisit(cp_id, d ) {
	if (d.length > 0) {		 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		} // end if 
		
		var url="/php/membership.php";
		url=url+"?cp_id="+cp_id;
		url=url+"&a=addcpvisit&";
		url=url+"&d="+d;
		url=url+"&type=1";
		xmlHttp.onreadystatechange=stateChangedPastorVisits;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} // end if

	if (d.length==0) { 	 
	 return;
	} // end if
} // end function

function stateChangedPastorVisits() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  { 
		 document.getElementById("pvisits").innerHTML="";
		 document.getElementById("pvisits").innerHTML=xmlHttp.responseText;
	 } // end if
} // end function

//#############################################################
function addStaffVisit(cp_id, d ) {
	if (d.length > 0) {		 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		} // end if 
		
		var url="/php/membership.php";
		url=url+"?cp_id="+cp_id;
		url=url+"&a=addcpvisit&";
		url=url+"&d="+d;
		url=url+"&type=2";
		xmlHttp.onreadystatechange=stateChangedStaffVisits;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} // end if

	if (d.length==0) { 	 
	 return;
	} // end if
} // end function

function stateChangedStaffVisits() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  { 
		 document.getElementById("svisits").innerHTML="";
		 document.getElementById("svisits").innerHTML=xmlHttp.responseText;
	 } // end if
} // end function

//#############################################################
function addCPNotes(cp_id, t ) {
	if (t.length > 0) {		 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		} // end if 
		
		var url="/php/notes.php";
		url=url+"?cp_id="+cp_id;
		url=url+"&a=addcpnote&";
		url=url+"&t="+t;
		xmlHttp.onreadystatechange=stateChangedAddNote;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} // end if

	if (t.length==0) { 	 
	 return;
	} // end if
} // end function

function stateChangedAddNote() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  { 
		 document.getElementById("cpnotes").innerHTML="";
		 document.getElementById("cpnotes").innerHTML=xmlHttp.responseText;
	 } // end if
} // end function
