/***************************************************************************
*
* IMPORTANT: This is a commercial product made by AntonLV and cannot be modified for other than personal usage. 
* This product cannot be redistributed for free or a fee without written permission from AntonLV. 
* This notice may not be removed from the source code.
*
***************************************************************************/

function frd_executeRequest(sAction, sParams) {
	var rRequest = false;		

	if (window.XMLHttpRequest) 
		rRequest = new XMLHttpRequest();
	else if (window.ActiveXObject)
		rRequest = new ActiveXObject("Microsoft.XMLHTTP");

	if(rRequest) {		
		rRequest.open("POST", sFrdUrl +'actions/'+ sAction + ".php", true);
		rRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		rRequest.onreadystatechange = function() {
			if(rRequest.readyState == 4 && rRequest.status == 200) {
				frd_parseXML(sAction, rRequest.responseXML);				
			}
		}
		var date = new Date();
		rRequest.send(sParams + "&_s=" + date.getTime());
	}	
}

function frd_parseXML(sAction, oXML) {
	var oNode = null;
	switch(sAction) {
		case 'move':
			var sListName = "";
			var sImageName = "";

			var iFrdId = 0;
			var iTop = 0;
			var sResult = "";

			oNode = oXML.getElementsByTagName('friend')[0];
			sResult = oNode.getAttribute('result');
			if(sResult == 'false') 
				alert(sError_LimitReached);
			else if(sResult = 'true') {
				iFrdId = oNode.getAttribute('id');
				if( oNode.getAttribute('top') == 1) {
					sListName = 'frd_topList';					
					sImageName = 'toNonTop';
					iTop = 0;
				}
				else {
					sListName = 'frd_nonTopList';
					sImageName = 'toTop';				 
					iTop = 1;
				}
				
				//--- Change friend location ---//
				document.getElementById(sListName).appendChild(document.getElementById('frd_' + iFrdId));

				//--- Change move button ---//
				var oButton = document.getElementById('frd_' + iFrdId + '_move');
				oButton.className = 'frd_move';
				oButton.style.backgroundImage = 'url(' + sFrdUrl + 'images/' + sImageName + '.gif)';
				oButton.onclick = function() {
					frd_executeRequest('move', 'oId=' + iOwnId + '&fId=' + iFrdId + '&top=' + iTop);
				}			
			}	
			break;
	}
}