var xmlhttp = null; function friend (iFriendUserId, sAction) { var sURL = "friend.php"; var sQueryString = "f=" + iFriendUserId + "&a=" + sAction; if (window.XMLHttpRequest) {// code for Mozilla, Safari, etc xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = handleFriendResult; xmlhttp.open("POST",sURL,true); xmlhttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); xmlhttp.send(sQueryString); } else if (window.ActiveXObject) {//IE xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); if (xmlhttp) { xmlhttp.onreadystatechange = handleFriendResult; xmlhttp.open("POST",sURL,true); xmlhttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); xmlhttp.send(sQueryString); } } } function handleFriendResult () { if (xmlhttp.readyState == 4) { if (xmlhttp.status == 200) { var oXML = xmlhttp.responseXML; var oRedirect = oXML.getElementsByTagName("redirect").item(0); if (oRedirect) { self.location = oRedirect.getAttribute("url"); } else { var oError = oXML.getElementsByTagName("e").item(0); if (oError) { alert (oError.getAttribute("m")); } else { updateFriend (xmlhttp.responseText); } } xmlhttp = null; } } } function updateFriend (sLink) { var oFriend = document.getElementById ('friend'); oFriend.innerHTML = sLink; } CsFriendList = function() { this.getResponse = function( id, status ) { if( DrAjax.statuses[ status ] == 'Complete' ) { var xml = DrAjax.getResponse( id ); var redirect = xml.getElementsByTagName("redirect").item(0); if ( redirect ) { self.location = redirect.getAttribute("url"); } else { var error = xml.getElementsByTagName("e").item(0); if ( error ) { alert ( error.getAttribute("m") ); } else { parseResponse( xml ); } } } } var parseResponse = function( xml ) { var friendList = xml.getElementsByTagName( 'friendList' ).item(0); var befriendList = xml.getElementsByTagName( 'befriendList' ).item(0); $( 'FriendList' ).innerHTML = friendList.getAttribute( 'c' ); $( 'BefriendList' ).innerHTML = befriendList.getAttribute( 'c' ); } this.add = function( id ) { DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=User.addFriend&id=' + id ); } this.remove = function( id ) { DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=User.removeFriend&id=' + id ); } } FriendList = new CsFriendList();