function request(url, oncomplete, param1, param2, postBody)
{
	var xmlHttp;
	try
	{
	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Vaš preglednik ne podržava AJAX!");
				return false;
			}
		}
    }
    
	xmlHttp.onreadystatechange = function()
    {
		if(xmlHttp.readyState==4)
			oncomplete(xmlHttp.responseText, param1, param2);
	}

	if(postBody == 'undefined')
	{
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
	else
	{
		xmlHttp.open("POST", url, true);
		xmlHttp.send(postBody);	
	}
}

function isSet(varname)
{
	if(typeof(window[varname]) != "undefined")
		return true;
	else
		return false;
}

function isNumeric(value)
{
	return typeof value != "boolean" && value !== null && !isNaN(+ value);
}

function getEl(id)
{
	return document.getElementById(id);
}

function setPercentBox(id, yes, no)
{
	font_yes = 10;
	font_no = 10;
	if(yes > 50)
		font_yes = 14;
	if(no > 50)
		font_no = 14;
	getEl(id).innerHTML =	"<span style='font-size: " + font_yes + "px;' class='true'>" + yes + "%</span>" +
 							" | " +
							"<span style='font-size: " + font_no + "px;' class='false'>" + no + "%</span>";
}

function VoteHandler(_url, _msg_id, _html0, _html1, _html2, _logged, _msg_not_logged)
{	
	this.url = _url;
	this.id_prefix = 'votebox_';
	this.msg_id = _msg_id;
	this.html0 = _html0;
	this.html1 = _html1;
	this.html2 = _html2;
	this.logged = _logged;
	this.msg_not_logged = _msg_not_logged;

	this.sendVote = function(id, answer)
	{
		if(!this.logged)
		{
			alert(this.msg_not_logged);
			return false;
		}
		old_html = getEl('votebox_'+id).innerHTML;
		if(answer == '1')
			getEl('votebox_'+id).innerHTML = this.html1;
		else if(answer == '2')
			getEl('votebox_'+id).innerHTML = this.html2;

		request_url = this.url + id + '' + '?answer='+answer;
		request(request_url, this.handleVote, id, old_html);
	}

	this.handleVote = function(response, id, old_html)
	{
		response = response.split('|');

		if(isNumeric(response[0]) && isNumeric(response[1]))
		{
			getEl(this.msg_id).innerHTML = '<span style="font-weight:bold; color: #008800">' + response[2] + '</span>';
			setPercentBox('votebox_' + id + '_percent', response[0], response[1]);
		}
		else
		{
			//alert(response[0]);
			getEl('votebox_'+id).innerHTML = old_html;
		}
	}
}

function switchIcon(id)
{
	src
	getEl('send_icon_'+id).src = 'adminmax/images/send_open.gif';
}

function send(id, url)
{
	getEl('send_'+id).style.display="none";
	getEl('send_icon_'+id).src = 'adminmax/images/send_open.gif';
	to = getEl('send_to_'+id).value;
	subject = getEl('send_subject_'+id).value;
	body = getEl('send_body_'+id).value;
	
	postValues = 'data[to]='+to+'&data[subject]='+subject+'&data[body]='+body;
	
	idval = "send_msg_"+id;
	
	new	ajax(url,
		{
			method: 'post',
			postBody: postValues,
			onComplete:function(response)
			{
				status = response.responseText[0];
				msg = response.responseText.substring(1);
				if(status == '0')
					getEl(idval).innerHTML = '<span class="error">'+msg+'</span>';
				else
					getEl(idval).innerHTML = '<span class="success">'+msg+'</span>';
			}
		}
	);
}

function sender(id, options){
		this.id = id;
		this.url = options.url || 'http://www.rekaosamti.com/send';
		this.idDiv = options.idDiv || 'send_';
		this.idIcon = options.idIcon || 'send_icon_';
		this.idTo = options.idTo || 'send_to_';
		this.idSubject = options.idSubject || 'send_subject_';
		this.idMail = options.idMail || 'send_body_';
		this.idMsg = options.idMsg || 'send_msg_';
		this.postTo = options.postTo || 'data[to]';
		this.postSubject = options.postSubject || 'data[subject]';
		this.postMail = options.postMail || 'data[body]';
		this.iconDir = options.iconDir || 'adminmax/images/';
		this.iconClosed = options.iconClosed || 'send.gif'; 
		this.iconOpened = options.iconOpened || 'send_open.gif'; 
		this.iconSuccess = options.iconSuccess || 'send_success.gif';
		this.iconError = options.iconError || 'send_error.gif';
	
		this.slide = new Fx.Slide(this.idDiv+id);
		this.slide.hide();
		$(this.idDiv+id).style.display = 'block';
		this.hidden = true;
		$(this.idMsg+id).style.display = 'none';

	
	this.isHidden = function()
	{
		if(getEl(this.idDiv+id).style.display == "none")
			return true;
		else
			return false;
	}
	
	this.showDiv = function()
	{
		this.hidden = false;
		res=this.slide.slideIn();
		getEl(this.idIcon+this.id).src = this.iconDir + this.iconOpened;
	}
	
	this.hideDiv = function()
	{
		this.hidden = true;
 		this.slide.slideOut();
		getEl(this.idIcon+this.id).src = this.iconDir + this.iconClosed;
	}
	
	this.showHideDiv = function()
	{
		$(this.idMsg+id).style.display = 'none';
		if (!this.slide.open)
			this.showDiv();
		else
			this.hideDiv();
	}
	
	this.getPostBody = function()
	{
		to = getEl(this.idTo+this.id).value;
		subject = getEl(this.idSubject+this.id).value;
		mail = getEl(this.idMail+this.id).value;
		return this.postTo+'='+to+'&'+this.postSubject+'='+escape(subject)+'&'+this.postMail+'='+escape(mail)+'&data[id]='+this.id;
	}
	
	this.showMessage = function(msg, status)
	{
		$(this.idMsg+this.id).style.display = 'block';
		if(status == '0')
		{
			getEl(this.idIcon+this.id).src = this.iconDir + this.iconError;
			getEl(this.idMsg+this.id).innerHTML = '<span class="error">'+msg+'</span>';
		}
		else
		{
			getEl(this.idIcon+this.id).src = this.iconDir + this.iconSuccess;
			getEl(this.idMsg+this.id).innerHTML = '<span class="success">'+msg+'</span>';
		}
	}
	
	this.send = function()
	{
		post = this.getPostBody();
		thisObj = this;
		
		url = this.url;
		
		new	Ajax(this.url,
			{
				method: 'post',
				data: post,
				onComplete:function(response)
				{
					status = this.response.text.charAt(0);
					thisObj.showMessage(this.response.text.substring(1), status);
					thisObj.hideDiv();
				}
			}
		).request();
		this.hideDiv();
	}
}