var tell_friend = {};

tell_friend.expand = function(obj){
	if(!document.getElementById("tell_friend_form")){
		ajax = new Ajax();
		ajax.CallBack = "tell_friend.expand_response";
		ajax.FilePath = "templates/tell_friend.php";
		ajax.ClassName = "tell_friend";
		ajax.MethodName = "x_render";
		ajax.Attributes = obj;
		ajax.Send();
	} else {
		$('#tell_friend_form, #tell_friend_form_bkgr').remove();
	}
}

tell_friend.expand_response = function(request, obj){
	//var obj = document.getElementById(attr);
	var form = document.createElement("div");
	form.id = "tell_friend_form";
	form.className = "tell_friend_form";
	form.style.background = "none";
	form.innerHTML = request.responseText;

	bckgr = document.createElement("div");
	bckgr.id = "tell_friend_form_bkgr";
	bckgr.className = "tell_friend_form";

	DocumentDOM.SetOpacity(bckgr, 60);

	obj.parentNode.insertBefore(bckgr, obj);
	obj.parentNode.insertBefore(form, obj);
}

tell_friend.close = function(){
	$(document).ready(function(){
		$('#tell_friend_form, #tell_friend_form_bkgr').remove();
	});
}

tell_friend.send = function(){
	var form = document.getElementById("tell_friend_form");
	var inp = form.getElementsByTagName("input");
	var txt = form.getElementsByTagName("textarea");
	var arg = new Array();
	for(var z = 0; z < inp.length; z++){
		if(inp[z].name != ""){
			arg[inp[z].name] = inp[z].value;
		}
	}
	for(var z = 0; z < txt.length; z++){
		if(txt[z].name != ""){
			arg[txt[z].name] = txt[z].value;
		}
	}

	ajax = new Ajax();
	ajax.CallBack = "";
	ajax.FilePath = "templates/tell_friend.php";
	ajax.ClassName = "tell_friend";
	ajax.MethodName = "x_send";
	for(var name in arg){
		ajax.RegisterArgument(name, arg[name]);
	}
	ajax.Send();
	document.getElementById("tell_friend_form_bkgr").parentNode.removeChild(document.getElementById("tell_friend_form_bkgr"));
	document.getElementById("tell_friend_form").parentNode.removeChild(document.getElementById("tell_friend_form"));
}