//AJAX FUNCTIONS!

var xmlHttpPage = 'includes/xmlHttp.php';
var xmlImagesDir = 'images/';

function GetXmlHttpObject(){ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest();
	}else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}	
	return objXMLHttp;
} 



function setToDownLevelDirectory(){
	xmlHttpPage = '../' + xmlHttpPage;
	xmlImagesDir = '../' + xmlImagesDir;
}







var xmlHttp_loadActiveUserIdByEmail;
function loadActiveUserIdByEmail(emailDiv, idDiv, acceptDiv){
	
	if(emailDiv == null || emailDiv == ''){
		return;	
	}	
	
	email = document.getElementById(emailDiv).value;
	
	xmlHttp_loadActiveUserIdByEmail=GetXmlHttpObject();
	if (xmlHttp_loadActiveUserIdByEmail==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById(idDiv).innerHTML = "Loading.....";
	
	var url = xmlHttpPage + "?action=get_active_user_id_by_email&email="+email;
	
	//xmlHttp_loadActiveUserIdByEmail.onreadystatechange=stateChanged_loadActiveUserIdByEmail;
	xmlHttp_loadActiveUserIdByEmail.onreadystatechange=function(){
		if (xmlHttp_loadActiveUserIdByEmail.readyState==4 || xmlHttp_loadActiveUserIdByEmail.readyState=="complete"){
			res = xmlHttp_loadActiveUserIdByEmail.responseText.split(";");
			if(res[0] == 1){
				showDiv(acceptDiv);
			}else{
				hideDiv(acceptDiv);
			}
			document.getElementById(idDiv).innerHTML = res[1];
		}
	}
	xmlHttp_loadActiveUserIdByEmail.open("GET",url,true);
	xmlHttp_loadActiveUserIdByEmail.send(null);	
	
}




var xmlHttp_loadBusinessSubCategories;
function loadBusinessSubCategories(cat_id, theDiv){
	
	if(cat_id == null || cat_id == ''){
		return;	
	}	
	
	xmlHttp_loadBusinessSubCategories=GetXmlHttpObject();
	if (xmlHttp_loadBusinessSubCategories==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById(theDiv).innerHTML = "Loading....";
	
	var url = xmlHttpPage + "?action=get_business_category_child_select&c_id="+cat_id;
	
	//xmlHttp_loadBusinessSubCategories.onreadystatechange=stateChanged_loadBusinessSubCategories;
	xmlHttp_loadBusinessSubCategories.onreadystatechange=function(){
		if (xmlHttp_loadBusinessSubCategories.readyState==4 || xmlHttp_loadBusinessSubCategories.readyState=="complete"){
			//alert(xmlHttp_loadBusinessSubCategories.responseText);
			theDiv = document.getElementById(theDiv);
			theDiv.innerHTML = xmlHttp_loadBusinessSubCategories.responseText;
			theDiv.refresh;
		}
	}
	xmlHttp_loadBusinessSubCategories.open("GET",url,true);
	xmlHttp_loadBusinessSubCategories.send(null);	
	
}



var xmlHttp_addNewUserRelationship;
function addNewUserRelationship(user_id_1, user_id_2, linkDiv){
	
	if(user_id_1 == null || user_id_1 == ''){
		alert("Sorry, but we are unable to your identification!");
		return;	
	}
	
	if(user_id_2 == null || user_id_2 == ''){
		alert("Sorry, but we are unable to determine your new relationship's identification!");
		return;	
	}
	
		
	xmlHttp_addNewUserRelationship=GetXmlHttpObject();
	if (xmlHttp_addNewUserRelationship==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	
	var url = xmlHttpPage + "?action=add_new_user_relationship";
	url += "&user_id_1="+user_id_1;
	url += "&user_id_2="+user_id_2;
	
	//xmlHttp_addNewUserRelationship.onreadystatechange=stateChanged_addNewUserRelationship;
	xmlHttp_addNewUserRelationship.onreadystatechange=function(){
		if (xmlHttp_addNewUserRelationship.readyState==4 || xmlHttp_addNewUserRelationship.readyState=="complete"){ 
			if(xmlHttp_addNewUserRelationship.responseText.replace(/ /gi,'')==1){
				alert("Your relationship has been added successfully!");
				if(linkDiv != null){
					document.getElementById(linkDiv).style.display = 'none';
				}	
			}else{
				alert(xmlHttp_addNewUserRelationship.responseText);
			}
			
		}
	}
	xmlHttp_addNewUserRelationship.open("GET",url,true);
	xmlHttp_addNewUserRelationship.send(null);	
	
}



var xmlHttp_updateUserRelationshipLevel;
function updateUserRelationshipLevel(relationship_id, type_id, type_name, trDiv){
	
	if(!confirm("Are you sure you wish to update this relationship to: " + type_name + "?")){
		return false;	
	}
	
	if(relationship_id == null || relationship_id == ''){
		alert("Sorry, but we are unable to determine your relationship to update!");
		return false;	
	}
	if(type_id == null || type_id == ''){
		alert("Sorry, but we are unable to determine the relationship type to update!");
		return false;	
	}
	
	if(type_id == 0){
		if(!confirm('Are you sure you want to remove this relationship?'))
			return false;
	}
	
	xmlHttp_updateUserRelationshipLevel=GetXmlHttpObject();
	if (xmlHttp_updateUserRelationshipLevel==null){
		alert ("Browser does not support HTTP Request")
		return false;
	} 
	
	
	var url = xmlHttpPage + "?action=update_user_relationship_level";
	url += "&relationship_id="+relationship_id;
	url += "&type_id="+type_id;
	
	//xmlHttp_updateUserRelationshipLevel.onreadystatechange=stateChanged_updateUserRelationshipLevel;
	xmlHttp_updateUserRelationshipLevel.onreadystatechange=function(){
		if (xmlHttp_updateUserRelationshipLevel.readyState==4 || xmlHttp_updateUserRelationshipLevel.readyState=="complete"){ 
			if(xmlHttp_updateUserRelationshipLevel.responseText.replace(/ /gi,'')==1){
				newClass = type_name.replace(/ /gi, "_");
				var cols = document.getElementById(trDiv).getElementsByTagName('td');
				for ( var i = 0; i < cols.length; i++ ) {	
					cols[i].className = newClass.toLowerCase();
					cols[i].refresh;
				}
			}else{
				alert("Sorry, but there was an error while updating your relationship!");	
			}
		}
	}
	xmlHttp_updateUserRelationshipLevel.open("GET",url,true);
	xmlHttp_updateUserRelationshipLevel.send(null);	
	return true;
}





var xmlHttp_deleteUser;
function deleteUser(user_id, row_id){
	
	if(user_id == null || user_id == ''){
		alert("Sorry, but we are unable to the user to delete!");
		return;	
	}
	
	if(!confirm('Are you sure you wish to delete this member from the ProGrowth system?')){
		return;	
	}
		
	xmlHttp_deleteUser=GetXmlHttpObject();
	if (xmlHttp_deleteUser==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	
	var url="../includes/xmlHttp.php?action=delete_user";
	url += "&user_id="+user_id;
	
	//xmlHttp_deleteUser.onreadystatechange=stateChanged_deleteUser;
	xmlHttp_deleteUser.onreadystatechange=function(){
		if (xmlHttp_deleteUser.readyState==4 || xmlHttp_deleteUser.readyState=="complete"){ 
			
			alert(xmlHttp_deleteUser.responseText);	
			hideTr(row_id);
			
		}
	}
	xmlHttp_deleteUser.open("GET",url,true);
	xmlHttp_deleteUser.send(null);	
	
}






var xmlHttp_deleteUserRelationshipShare;
function deleteUserRelationshipShare(share_id, row_id){
	
	if(share_id == null || share_id == ''){
		alert("Sorry, but we are unable to the user to delete!");
		return;	
	}
	
	if(!confirm('Are you sure you wish to delete this share?')){
		return;	
	}
		
	xmlHttp_deleteUserRelationshipShare=GetXmlHttpObject();
	if (xmlHttp_deleteUserRelationshipShare==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	
	var url = xmlHttpPage + "?action=delete_user_relationship_share";
	url += "&user_relationship_share_id="+share_id;
	
	//xmlHttp_deleteUserRelationshipShare.onreadystatechange=stateChanged_deleteUserRelationshipShare;
	xmlHttp_deleteUserRelationshipShare.onreadystatechange=function(){
		if (xmlHttp_deleteUserRelationshipShare.readyState==4 || xmlHttp_deleteUserRelationshipShare.readyState=="complete"){ 
			
			alert(xmlHttp_deleteUserRelationshipShare.responseText);	
			hideTr(row_id);
			
		}
	}
	xmlHttp_deleteUserRelationshipShare.open("GET",url,true);
	xmlHttp_deleteUserRelationshipShare.send(null);	
	
}







var xmlHttp_sendUserMessage;
//sends a message to the 'user_id'
function sendUserMessage(){
	xmlHttp_sendUserMessage=GetXmlHttpObject();
	if (xmlHttp_sendUserMessage==null){
		alert ("Browser does not support HTTP Request")
		return false;
	} 
	
	var user_id_to = document.getElementById('user_id_to').value;
	var user_id_from = document.getElementById('user_id_from').value;
	var theSubject = document.getElementById('message_subject').value;
	var theMessage = document.getElementById('message_message').value;
	var copyEmails = document.getElementById('message_emails').value;
	
	
	if(user_id_to == null || user_id_to == ''){
		alert("Sorry, a user was not selected to send the message to!");
		return false;	
	}
	if(user_id_from == null || user_id_from == ''){
		alert("Sorry, we were unable to determine who to send the message from!");
		return false;	
	}
	if(theSubject == ''){
		alert("Sorry, you did not enter a subject!");	
		return false;
	}
	if(theMessage == ''){
		alert("Sorry, you did not enter a message!");	
		return false;
	}
	
	//alert(theSubject + " : "+ theMessage);
	var url = xmlHttpPage + "?action=send_user_message";
	params = "user_id_to="+user_id_to;
	params += "&user_id_from="+user_id_from;
	params += "&subject="+theSubject;
	params += "&message="+theMessage;
	params += "&emails="+copyEmails;
	
	//xmlHttp_sendUserMessage.onreadystatechange=stateChanged_sendUserMessage;
	xmlHttp_sendUserMessage.onreadystatechange=function(){
		if (xmlHttp_sendUserMessage.readyState==4 || xmlHttp_sendUserMessage.readyState=="complete"){ 
			alert(xmlHttp_sendUserMessage.responseText);
			document.getElementById('message_subject').value = '';
			document.getElementById('message_message').value = '';
			document.getElementById('message_emails').value = '';
			return true;
		}
	}
	
	xmlHttp_sendUserMessage.open("POST",url,true);
	xmlHttp_sendUserMessage.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp_sendUserMessage.setRequestHeader("Content-length", params.length);
    xmlHttp_sendUserMessage.setRequestHeader("Connection", "close");
	xmlHttp_sendUserMessage.send(params);
	return true;
	
}





var xmlHttp_sendTeamMessage;
//sends a message to the 'user_id'
function sendTeamMessage(team_id, user_id){
	xmlHttp_sendTeamMessage=GetXmlHttpObject();
	if (xmlHttp_sendTeamMessage==null){
		alert ("Browser does not support HTTP Request")
		return false;
	} 
	
	var theSubject = document.getElementById('message_subject').value;
	var theMessage = document.getElementById('message_message').value;
	
	
	if(team_id == null || team_id == ''){
		alert("Sorry, a team was not selected to send the message to!");
		return false;	
	}
	if(user_id == null || user_id == ''){
		alert("Sorry, we were unable to determine who to send the message from!");
		return false;	
	}
	if(theSubject == ''){
		alert("Sorry, you did not enter a subject!");	
		return false;
	}
	if(theMessage == ''){
		alert("Sorry, you did not enter a message!");	
		return false;
	}
	
	//alert(theSubject + " : "+ theMessage);
	var url = xmlHttpPage + "?action=send_team_message";
	params = "team_id="+team_id;
	params += "&user_id_from="+user_id;
	params += "&subject="+theSubject;
	params += "&message="+theMessage;
	
	//xmlHttp_sendTeamMessage.onreadystatechange=stateChanged_sendTeamMessage;
	xmlHttp_sendTeamMessage.onreadystatechange=function(){
		if (xmlHttp_sendTeamMessage.readyState==4 || xmlHttp_sendTeamMessage.readyState=="complete"){ 
			if(xmlHttp_sendTeamMessage.responseText.replace(/ /gi,'')==1){
				alert('Your message has been sent successfully!');
				document.getElementById('message_subject').value = '';
				document.getElementById('message_message').value = '';
				return true;
			}else{				
				alert(xmlHttp_sendTeamMessage.responseText);	
				return false;
			}
		}
	}
	
	xmlHttp_sendTeamMessage.open("POST",url,true);
	xmlHttp_sendTeamMessage.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp_sendTeamMessage.setRequestHeader("Content-length", params.length);
    xmlHttp_sendTeamMessage.setRequestHeader("Connection", "close");
	xmlHttp_sendTeamMessage.send(params);
	return true;
	
}





var xmlHttp_loadTouchHistoryByUser;
function loadTouchHistoryByUser(relationship_id, user_id, historyDiv, theOverlay){
	
	if(relationship_id == null || relationship_id == ''){
		alert("Sorry, but we are unable to determine your relationship!");
		return;	
	}
		
	xmlHttp_loadTouchHistoryByUser=GetXmlHttpObject();
	if (xmlHttp_loadTouchHistoryByUser==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById(historyDiv).innerHTML = "<div align='center'><img src='"+ xmlImagesDir + "loading.gif'></div>";
	overlayDiv(this, theOverlay);
	
	var url = xmlHttpPage + "?action=load_touch_history_by_user";
	url += "&relationship_id="+relationship_id;
	url += "&user_id="+user_id;
	
	//xmlHttp_loadTouchHistoryByUser.onreadystatechange=stateChanged_loadTouchHistoryByUser;
	xmlHttp_loadTouchHistoryByUser.onreadystatechange=function(){
		if (xmlHttp_loadTouchHistoryByUser.readyState==4 || xmlHttp_loadTouchHistoryByUser.readyState=="complete"){ 
			document.getElementById(historyDiv).innerHTML = xmlHttp_loadTouchHistoryByUser.responseText;
			centerDiv(theOverlay);
		}
	}
	xmlHttp_loadTouchHistoryByUser.open("GET",url,true);
	xmlHttp_loadTouchHistoryByUser.send(null);	
	
}




var xmlHttp_loadAddTouchForm;
function loadAddTouchForm(relationship_id, touchDiv){
	
	if(relationship_id == null || relationship_id == ''){
		alert("Sorry, but we are unable to determine your relationship!");
		return false;	
	}
		
	xmlHttp_loadAddTouchForm=GetXmlHttpObject();
	if (xmlHttp_loadAddTouchForm==null){
		alert ("Browser does not support HTTP Request")
		return false;
	} 
	
	document.getElementById(touchDiv).innerHTML = "<div align='center'><img src='"+ xmlImagesDir + "loading.gif'></div>";
	
	var url = xmlHttpPage + "?action=get_add_touch_form";
	url += "&relationship_id="+relationship_id;
	
	//xmlHttp_loadAddTouchForm.onreadystatechange=stateChanged_loadAddTouchForm;
	xmlHttp_loadAddTouchForm.onreadystatechange=function(){
		if (xmlHttp_loadAddTouchForm.readyState==4 || xmlHttp_loadAddTouchForm.readyState=="complete"){ 
			document.getElementById(touchDiv).innerHTML = xmlHttp_loadAddTouchForm.responseText;
			return true;
		}else{
			document.getElementById(touchDiv).innerHTML += ".";
		}
	}
	xmlHttp_loadAddTouchForm.open("GET",url,true);
	xmlHttp_loadAddTouchForm.send(null);
	
}



var xmlHttp_addTouch;
//sends a message to the 'user_id'
function addTouch(){
	xmlHttp_addTouch=GetXmlHttpObject();
	if (xmlHttp_addTouch==null){
		alert ("Browser does not support HTTP Request")
		return false;
	} 
	
	theRelationship = document.getElementById('touch_relationship_id').value;
	theDate = document.getElementById('touch_hidden_date').value;
	theContactMethod = document.getElementById('touch_contact_method').value;
	theReminder = document.getElementById('touch_hidden_reminder_date').value;
	theComments = document.getElementById('touch_comments').value;
	commentsPrivate = document.getElementById('touch_comments_private');
	commentsPublic = document.getElementById('touch_comments_public');
	
	
	if(commentsPublic.checked == true){
		theCommentsPublic = 1;	
	}else{
		theCommentsPublic = 0;
	}
	
	if(theRelationship < 1){
		alert("Sorry, you did not select a relationship!");
		return false;	
	}
	if(theDate == ''){
		alert("Sorry, you did not select a date for the touch!");
		return false;	
	}
	if(theContactMethod == ''){
		alert("Sorry, your did not select a contact method!");	
		return false;
	}
	if(theReminder == ''){
		alert("Sorry, you did not select a reminder date!");	
		return false;
	}
	
	var url = xmlHttpPage + "?action=add_touch";
	params = "relationship_id="+theRelationship;
	params += "&date="+theDate;
	params += "&contact_method="+theContactMethod;
	params += "&reminder_date="+theReminder;
	params += "&comments="+theComments;
	params += "&comments_public="+theCommentsPublic;
	
	//xmlHttp_addTouch.onreadystatechange=stateChanged_addTouch;
	xmlHttp_addTouch.onreadystatechange=function(){
		if (xmlHttp_addTouch.readyState==4 || xmlHttp_addTouch.readyState=="complete"){ 
			if(xmlHttp_addTouch.responseText.replace(/ /gi,'')==1){
				document.getElementById('touch_comments').value = '';
				document.getElementById('touch_comments_private').checked = 'checked';
				document.getElementById('touch_comments_public').checked = '';
				alert("Your touch has been added successfully!");
				return true;
			}else{
				alert(xmlHttp_addTouch.responseText);	
				return false;
			}			
		}
	}
	
	xmlHttp_addTouch.open("POST",url,true);
	xmlHttp_addTouch.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp_addTouch.setRequestHeader("Content-length", params.length);
    xmlHttp_addTouch.setRequestHeader("Connection", "close");
	xmlHttp_addTouch.send(params);
	return true;
	
}





var xmlHttp_loadUserSelectByRegion;
function loadUserSelectByRegion(region_id, theDiv){
	
	if(region_id == null || region_id < 1){
		return;	
	}	
	
	xmlHttp_loadUserSelectByRegion=GetXmlHttpObject();
	if (xmlHttp_loadUserSelectByRegion==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById(theDiv).innerHTML = "Loading....";
	
	var url = xmlHttpPage + "?action=load_user_select_by_region&region_id="+region_id;
	
	//xmlHttp_loadUserSelectByRegion.onreadystatechange=stateChanged_loadUserSelectByRegion;
	xmlHttp_loadUserSelectByRegion.onreadystatechange=function(){
		if (xmlHttp_loadUserSelectByRegion.readyState==4 || xmlHttp_loadUserSelectByRegion.readyState=="complete"){ 
			document.getElementById(theDiv).innerHTML = xmlHttp_loadUserSelectByRegion.responseText;
		}
	}
	xmlHttp_loadUserSelectByRegion.open("GET",url,true);
	xmlHttp_loadUserSelectByRegion.send(null);	
	
}




var xmlHttp_loadTeamSelectByRegion;
function loadTeamSelectByRegion(region_id, theDiv, select_a_team, is_rising_star){
	
	if(region_id == null || region_id < 1){
		return;	
	}	
	
	xmlHttp_loadTeamSelectByRegion=GetXmlHttpObject();
	if (xmlHttp_loadTeamSelectByRegion==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById(theDiv).innerHTML = "Loading....";
		
	var url = xmlHttpPage + "?action=load_team_select_by_region&region_id="+region_id+"&select_a_team="+select_a_team+"&is_rising_star="+is_rising_star;
	
	//xmlHttp_loadTeamSelectByRegion.onreadystatechange=stateChanged_loadTeamSelectByRegion;
	xmlHttp_loadTeamSelectByRegion.onreadystatechange=function(){
		if (xmlHttp_loadTeamSelectByRegion.readyState==4 || xmlHttp_loadTeamSelectByRegion.readyState=="complete"){ 
			document.getElementById(theDiv).innerHTML = xmlHttp_loadTeamSelectByRegion.responseText;
		}
	}
	xmlHttp_loadTeamSelectByRegion.open("GET",url,true);
	xmlHttp_loadTeamSelectByRegion.send(null);	
	
}





var xmlHttp_loadTeamMembers;
function loadTeamMembers(team_id, theDiv){
	
	if(team_id == null || team_id < 1){
		return;	
	}	
	
	xmlHttp_loadTeamMembers=GetXmlHttpObject();
	if (xmlHttp_loadTeamMembers==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById(theDiv).innerHTML = "Loading....";
	
	var url = xmlHttpPage + "?action=load_team_members_select&team_id="+team_id;
	
	//xmlHttp_loadTeamMembers.onreadystatechange=stateChanged_loadTeamMembers;
	xmlHttp_loadTeamMembers.onreadystatechange=function(){
		if (xmlHttp_loadTeamMembers.readyState==4 || xmlHttp_loadTeamMembers.readyState=="complete"){ 
			document.getElementById(theDiv).innerHTML = xmlHttp_loadTeamMembers.responseText;
		}
	}
	xmlHttp_loadTeamMembers.open("GET",url,true);
	xmlHttp_loadTeamMembers.send(null);	
	
}



var xmlHttp_changeUserTeamRole;
function changeUserTeamRole(user_id, role_id){
	
	if(user_id == null || user_id == ''){
		alert("Sorry, but we are unable to determine the member to update!");
		return false;	
	}
	if(role_id == null || role_id == ''){
		alert("Sorry, but we are unable to determine the role to update!");
		return false;	
	}
	
	xmlHttp_changeUserTeamRole=GetXmlHttpObject();
	if (xmlHttp_changeUserTeamRole==null){
		alert ("Browser does not support HTTP Request")
		return false;
	} 
	
	
	var url = xmlHttpPage + "?action=update_user_team_role";
	url += "&user_id="+user_id;
	url += "&team_role_id="+role_id;
	
	//xmlHttp_changeUserTeamRole.onreadystatechange=stateChanged_changeUserTeamRole;
	xmlHttp_changeUserTeamRole.onreadystatechange=function(){
		if (xmlHttp_changeUserTeamRole.readyState==4 || xmlHttp_changeUserTeamRole.readyState=="complete"){ 
			alert(xmlHttp_changeUserTeamRole.responseText);
		}
	}
	xmlHttp_changeUserTeamRole.open("GET",url,true);
	xmlHttp_changeUserTeamRole.send(null);	
	return true;
}



var xmlHttp_loadUserSearchDropDown;
function loadUserSearchDropDown(query, theDiv, instanceNum, multipleSelect, showInactive){
	
	if(query == null || query == ''){
		div = document.getElementById(theDiv)
		div.innerHTML = "";
		div.style.display = 'none';
		return;	
	}	
	
	if(instanceNum == null || instanceNum == ''){
		instanceNum = 1;	
	}
	
	xmlHttp_loadUserSearchDropDown=GetXmlHttpObject();
	if (xmlHttp_loadUserSearchDropDown==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById(theDiv).innerHTML = "Loading....";
	
	var url = xmlHttpPage + "?action=get_user_search_drop_down";
	var params = "query="+query;
	params += "&instance="+instanceNum;
	params += "&multiple_select="+multipleSelect;
	params += "&show_inactive="+showInactive;
	
	//xmlHttp_loadUserSearchDropDown.onreadystatechange=stateChanged_loadUserSearchDropDown;
	xmlHttp_loadUserSearchDropDown.onreadystatechange=function(){
		if (xmlHttp_loadUserSearchDropDown.readyState==4 || xmlHttp_loadUserSearchDropDown.readyState=="complete"){
			//alert(xmlHttp_loadUserSearchDropDown.responseText);
			document.getElementById(theDiv).innerHTML = xmlHttp_loadUserSearchDropDown.responseText;
		}
	}
	
	xmlHttp_loadUserSearchDropDown.open("POST",url,true);
	xmlHttp_loadUserSearchDropDown.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp_loadUserSearchDropDown.setRequestHeader("Content-length", params.length);
    xmlHttp_loadUserSearchDropDown.setRequestHeader("Connection", "close");
	xmlHttp_loadUserSearchDropDown.send(params);
	
}





var xmlHttp_updateUserEventInvitationStatus;
function updateUserEventInvitationStatus(event_id, email, name, status, attendees, txtStatus, theOverlay){
	
	if(event_id == null || event_id == ''){
		alert("Sorry, but we are unable to determine the event!");
		return;	
	}
	
	if(status == null){
		alert("Sorry, but we are unable to determine the invitation status!");
		return;	
	}
		
	xmlHttp_updateUserEventInvitationStatus=GetXmlHttpObject();
	if (xmlHttp_updateUserEventInvitationStatus==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
		
	var url = xmlHttpPage + "?action=update_user_event_invitation_status";
	url += "&event_id="+event_id;
	url += "&email="+email;
	url += "&name="+name;
	url += "&status="+status;
	url += "&attendees="+attendees;
	
	//xmlHttp_updateUserEventInvitationStatus.onreadystatechange=stateChanged_updateUserEventInvitationStatus;
	xmlHttp_updateUserEventInvitationStatus.onreadystatechange=function(){
		if (xmlHttp_updateUserEventInvitationStatus.readyState==4 || xmlHttp_updateUserEventInvitationStatus.readyState=="complete"){ 
			theResponse = xmlHttp_updateUserEventInvitationStatus.responseText;
			if(txtStatus != null && txtStatus != ''){
				document.getElementById(txtStatus).innerHTML = theResponse;
			}
			
			alert('Your RSVP Has Been Saved As: ' + theResponse);
			if(theOverlay != null && theOverlay != ''){
				overlayclose(theOverlay);
			}
		}
	}
	xmlHttp_updateUserEventInvitationStatus.open("GET",url,true);
	xmlHttp_updateUserEventInvitationStatus.send(null);	
	
}






var xmlHttp_loadUserEventInvitationsByStatus;
function loadUserEventInvitationsByStatus(event_id, status, invitationDiv, theOverlay){
	
	if(event_id == null || event_id == ''){
		alert("Sorry, but we are unable to determine the event!");
		return;	
	}
	
	if(status == null){
		alert("Sorry, but we are unable to determine the invitation status!");
		return;	
	}
		
	xmlHttp_loadUserEventInvitationsByStatus=GetXmlHttpObject();
	if (xmlHttp_loadUserEventInvitationsByStatus==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	
	document.getElementById(invitationDiv).innerHTML = "<div align='center'><img src='"+ xmlImagesDir + "loading.gif'></div>";
	overlayDiv(this, theOverlay);
	
	var url = xmlHttpPage + "?action=load_user_event_invitations_by_status";
	url += "&event_id="+event_id;
	url += "&status="+status;
	
	//xmlHttp_loadUserEventInvitationsByStatus.onreadystatechange=stateChanged_loadUserEventInvitationsByStatus;
	xmlHttp_loadUserEventInvitationsByStatus.onreadystatechange=function(){
		if (xmlHttp_loadUserEventInvitationsByStatus.readyState==4 || xmlHttp_loadUserEventInvitationsByStatus.readyState=="complete"){ 
			document.getElementById(invitationDiv).innerHTML = xmlHttp_loadUserEventInvitationsByStatus.responseText;
			centerDiv(theOverlay);
		}else{
			document.getElementById(invitationDiv).innerHTML += ".";
		}
	}
	xmlHttp_loadUserEventInvitationsByStatus.open("GET",url,true);
	xmlHttp_loadUserEventInvitationsByStatus.send(null);	
	
}







var xmlHttp_loadSwf;
function loadSwf(name, theDiv, oDiv){
	
	if(name == null || name == ''){
		return;
	}
	
	xmlHttp_loadSwf=GetXmlHttpObject();
	if (xmlHttp_loadSwf==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById(theDiv).innerHTML = "<div align='center'><img src='"+ xmlImagesDir + "loading.gif'></div>";
	
	var url = xmlHttpPage + "?action=get_swf";
	var params = "name="+name;
	
	//xmlHttp_loadSwf.onreadystatechange=stateChanged_loadSwf;
	xmlHttp_loadSwf.onreadystatechange=function(){
		if (xmlHttp_loadSwf.readyState==4 || xmlHttp_loadSwf.readyState=="complete"){
			//alert(xmlHttp_loadSwf.responseText);
			document.getElementById(theDiv).innerHTML = xmlHttp_loadSwf.responseText;
			overlayDiv(this, oDiv);
		}
	}
	
	xmlHttp_loadSwf.open("POST",url,true);
	xmlHttp_loadSwf.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp_loadSwf.setRequestHeader("Content-length", params.length);
    xmlHttp_loadSwf.setRequestHeader("Connection", "close");
	xmlHttp_loadSwf.send(params);
	
}





var xmlHttp_loadUserCompactProfile;
function loadUserCompactProfile(user_id, theDiv){
	
	if(user_id == null || user_id < 1){
		return;	
	}	
	
	xmlHttp_loadUserCompactProfile=GetXmlHttpObject();
	if (xmlHttp_loadUserCompactProfile==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById(theDiv).innerHTML = "Loading....";
		
	var url = xmlHttpPage + "?action=load_user_compact_profile&user_id="+user_id;
	
	//xmlHttp_loadUserCompactProfile.onreadystatechange=stateChanged_loadUserCompactProfile;
	xmlHttp_loadUserCompactProfile.onreadystatechange=function(){
		if (xmlHttp_loadUserCompactProfile.readyState==4 || xmlHttp_loadUserCompactProfile.readyState=="complete"){ 
			document.getElementById(theDiv).innerHTML = xmlHttp_loadUserCompactProfile.responseText;
		}
	}
	xmlHttp_loadUserCompactProfile.open("GET",url,true);
	xmlHttp_loadUserCompactProfile.send(null);	
	
}
