if (!rootpath) var rootpath = "";

function SubmitReq(_process, _this) {

			switch (_process){
			
			/*		
				case "XXXXXXXXXXXXXX": 
					_params = getFormData(_this);
					ajaxReq('POST', rootpath+'php/user_forgotpassword_json.php', _params, _process, true)
					break;
			*/
				
				case "REQUESTFRIEND":
					_params = "status=1&friend=" + _this;
					ajaxReq('POST', rootpath+'php/user_friend.php', _params, _process, true)
					break;
					
				case "APPROVEFRIEND":
					_params = "status=3&friend=" + _this;
					ajaxReq('POST', rootpath+'php/user_friend.php', _params, _process, true)
					break;
					
				case "DECLINEFRIEND":
					_params = "status=4&friend=" + _this;
					ajaxReq('POST', rootpath+'php/user_friend.php', _params, _process, true)
					break;		
					
				case "BLOCKFRIEND":
					_params = "status=6&friend=" + _this;
					ajaxReq('POST', rootpath+'php/user_friend.php', _params, _process, true)
					break;		
					
				case "REMOVEFRIEND":
					_params = "status=0&friend=" + _this;
					ajaxReq('POST', rootpath+'php/user_friend.php', _params, _process, true)
					break;
					
					
					
					
				default : alert( _process + " Not Recognized");
			} // end switch
}

var uPass;


///////////////////////////////////////////////////////
// Ajax set up
var http;

function createRequestObject() {
    var ro;
    if (window.ActiveXObject) {
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

// Ajax Request
function ajaxReq(_action, _url, _params, _process, _asych) {
	http = createRequestObject();
    http.open(_action, _url, _asych);
	http.onreadystatechange = new Function("handleAjaxReq('"+_process+"')");
	switch (_action) {
		case "POST":
			http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			http.send(_params);
			break;
		case "GET":
    		http.send(null);
			break
	}
}

// Ajax Result
function handleAjaxReq(_process) {

    if (http.readyState == 4) {
		if (http.status == 200) {
			
			switch (_process){
				case "foo": 
					fooAjax(http)
					break;
				case "boo": 
					fooXmlReq(http)
					break;
					
				case "REQUESTFRIEND": 
					REQUESTFRIEND(http)
					break;
					
				case "APPROVEFRIEND":
					GENERICRESPONSEFRIEND(http, "3")
					break;
					
				case "DECLINEFRIEND":
					GENERICRESPONSEFRIEND(http, "4")
					break;
					
				case "BLOCKFRIEND":
					GENERICRESPONSEFRIEND(http, "6")
					break;
					
				case "REMOVEFRIEND": // default back to approved status
					GENERICRESPONSEFRIEND(http, "0")
					break;
					
				default : alert( _process + " Not Recognized");
			} // end switch
		} else {
			// status not ok
			alert("Ajax Error: " + http.status);
		}
    } // end ready state
} // end HandleAjaxReq



//////////////////////////////////////////////////////////////////////////////
// Ajax Application Functions
function fooAjax(_http) {
	var response = _http.responseText;
	alert(response)
	document.getElementById("ajat").innerHTML = response;
}

function booXmlReq(_http) {
	var xmldoc = _http.responseXML;
	//var root_node = xmldoc.getElementsByTagName('root').item(0);
	//alert(root_node.firstChild.data);
	
	var my_node = xmldoc.getElementsByTagName('answer');
	for (i=0; i < my_node.length; i++) {
		alert(my_node[i].firstChild.nodeValue);
		document.getElementById("ajax").innerHTML = xmldoc;
	}
}
function gooJsonReq(_http) {
    var local=new Function("return "+_http.responseText)();
    alert(local[0].message);
}


function REQUESTFRIEND(_http) {
	var response = _http.responseText;
	response = response.replace(/^\s+|\s+$/g,'');
    var local=new Function("return "+response)();
    if (local[0].message > "") 
		document.getElementById("div_addfriendlink").innerHTML = "<img src='"+rootpath+"img/spacer.gif' height='4' width='1' /><br><span class='cLink_addfriend >"+local[0].message+"</span>";
}

function GENERICRESPONSEFRIEND(_http, _status) {
	var response = _http.responseText;
	response = response.replace(/^\s+|\s+$/g,'');
	 var local=new Function("return "+response)();
	 if (local[0].message > "") {
		document.getElementById("friend_status").value = _status;
		formSubmit('Form1',''+returnpage+'');
	}
}