var d = document;

function fInit(){
	var i,_id ,  a = d.getElementById('content').getElementsByTagName('a');
	var  sp = d.getElementById('content').getElementsByTagName('span');
	
	for(i=0;i<a.length;i++){
		_id = a[i].id;
		if(_id.substring(0,2) == 'JS'){
			a[i].onclick=function(){return eval('fAjaxAddFriend(this,' + parseInt(this.id.replace('JS','')) + ')')};
			a[i].style.display =  'inline';
		}
	}
	for(i=0;i<sp.length;i++){
		if(sp[i].className == 'JSHide'){
			sp[i].style.display =  'inline';
		}
	}
	
	var l = document.getElementById('AdvancedLink');
	l.href = l.href + '&js=on';
}

function fAjaxAddFriend(obj,_id){
	if(xmlHttp&&xmlHttp.readyState!=0){
		xmlHttp.abort();
	}
	var xmlHttp = XmlHttp.create();
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			var _responseText = xmlHttp.responseText;
			if(_responseText == 'UPDATED'){
				obj.href='profile.friends.asp';
				obj.innerHTML ='Saved in friends';
				obj.onclick=function(){return true};
			}else if(_responseText == 'SessionEnded'){
				xmlHttp.abort();
				location.reload();
			}else{
				obj.innerHTML ='ERROR. Retry...';
			}
		}else{
			obj.innerHTML ='Please Wait...';
		}
	}
	_url = 'Scripts/addfriends.asp';
	_data = 'member=' + _id + '&ajax=True';
	
	xmlHttp.open("POST",_url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.send(_data)
	return false;
}

_onloadFunctions = 'fInit()';