// Image preload

pic1= new Image(24,24); 
pic1.src="images/load.gif"; 
pic2= new Image(43,11); 
pic2.src="images/load2.gif"; 
pic2= new Image(24,24); 
pic2.src="images/close.png"; 

// AJAX for all browsers
function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch(e) {
        //Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

// AJAX POST FUNCTION
function AjaxPost(url, param, success_function) {
	xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Your browser doesn't support AJAX. You should upgrade it!")
        return
    }
    xmlHttp.onreadystatechange = success_function;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(param);
}

function $(d) {
    return document.getElementById(d);
}

function FriendSubmitLink(uid,fid) {

	$('sendrequest' + fid).innerHTML = '<span class="UIButton_Text">Sending...</span>';
	param = "uid=" + uid + "&fid=" + fid;

	AjaxPost(myURL+"/includes/modules/friendlist/add.php", param, 
			 function () {
				if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
					$('friendrequest').innerHTML = '<span class="UIButton_Text">Friendship Pending</span>';
    				$('sendrequest' + fid).innerHTML = '<span class="UIButton_Text">Send Request</span>';
					showhide('FBstyleAdd');
        		}
    		}
	)
}

function FriendDeleteAsk(uid,fid) {
	$('frienddelete' + fid).style.height = '30px';
    $('frienddelete' + fid).innerHTML = '<div style="color:#000;text-align:center;margin-top:60px;">Are you sure you want to remove this friend connection? &nbsp;<a href="#" onclick="FriendDeletelink(' + fid + ','+ uid +');return false">Yes</a>&nbsp;&nbsp;&nbsp;<a href="#" onclick="FriendCloseDelete(' + fid + ');return false">No</a></div>';
}

function FriendCloseDelete(fid) {
	$('frienddelete' + fid).style.height = '0px';
    $('frienddelete' + fid).innerHTML = '';
}

function FrienddoMove(fid, height, opacity) {
    if (height > 0) {
        height = (height - 100)
        opacity = opacity - 0.08
        $('friend' + fid).style.height = height + 'px';
        $('friend' + fid).style.opacity = opacity;

        setTimeout('FrienddoMove(' + fid + ', ' + height + ', ' + opacity + ')', 10); // call doMove() in 20 msec
    }
    else {
        $('friend' + fid).style.display = 'none';
		$('frienddelete' + fid).innerHTML = '';
    }

}

function FriendDeletelink(fid,uid) {
	AjaxPost(myURL+"/includes/modules/friendlist/remove.php", "fid=" + fid + "&uid=" + uid,
			 function () {
			 
			 	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
						FrienddoMove(fid, 80, 1);
        		}
    		}
	)
}

var state = 'none';
function showhide(layer) {

	if (state == 'block') {
		state = 'none';
	}
	else {
		state = 'block';
	}
	if (document.all) { 
		eval( "document.all." + layer + ".style.display = state");
	}
	if (document.layers) { 
		document.layers[layer].display = state;
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer);
		hza.style.display = state;
	}
} 
