var player;
var stat_set = false;

function playerReady(obj) {
	var id = obj['id'];
//	play_area
	
	var objx = swfobject.getObjectById("play_area");
	if (objx) {
  		objx.addModelListener('STATE', 'stateMonitor');
	}	
};

function stateMonitor(obj)
{
	if(obj.newstate == 'PLAYING')
	if (stat_set==false)
	{
		var objx = swfobject.getObjectById("play_area");
		
		if (objx) 
		{
	  		fn_writetostats(objx.getPlaylist()[0].title);
	  		stat_set = true;
		}					
	}	
};


function fn_writetostats(sval)
{
		var url = '/files/statistics.php';
		var params = 'id='+sval;
	
		new Ajax.Request(
				url,
				{
					method: 'post',
					parameters: params,
					onLoading: function(){},
					onComplete : function(transport)
					{
					}
				}
				);		
}

function zobrazit(id) {
	this.document.getElementById(id).style.display = 'block';
}
function prepnout(id) {
	if (document.getElementById(id).style.display == 'block')
		document.getElementById(id).style.display = 'none';
	else
		document.getElementById(id).style.display = 'block';
}
function check(elem) {
	elem.checked = true;
}

// http://www.alexking.org - LGPL
function insertAtCursor(myField, prefix, postfix) {
	var re = new RegExp("^(.*\\S)(\\s*)$");
  myField.focus();
  //IE support
  if (document.selection) {
    sel = document.selection.createRange();
		var selection = sel.text;
		var wasEmpty = (selection == "");
		var space = "";
		if (!wasEmpty) {
			var matches = selection.match(re);
			if (matches) {
				selection = RegExp.$1;
				space = RegExp.$2;
			}
		}
    sel.text = prefix+selection+postfix+space;
		sel.collapse(false);
		if (wasEmpty) {
			sel.moveEnd('character',-(prefix.length+1))
		}
		sel.select();
  }
  //MOZILLA/NETSCAPE support
  else {
		if (myField.selectionStart || myField.selectionStart == '0') {
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			var selection = myField.value.substring(startPos, endPos);
			var wasEmpty = (startPos == endPos);
			var space = "";
			if (!wasEmpty) {
				var matches = selection.match(re);
				if (matches) {
					selection = RegExp.$1;
					space = RegExp.$2;
				}
			}
			myField.value = myField.value.substring(0, startPos)
										+ prefix+selection+postfix+space
										+ myField.value.substring(endPos, myField.value.length);

			var newPosition;
			if (wasEmpty) {
				newPosition = startPos+prefix.length;
			} else {
				newPosition = startPos+prefix.length+selection.length+postfix.length+space.length;
			}
			myField.setSelectionRange(newPosition, newPosition);
		} else {
			myField.value += prefix+postfix;
			myField.setSelectionRange(startPos+prefix.length, startPos+prefix.length);
		}
	}
}

function blockIp(ip,url,id){
 
        if (window.XMLHttpRequest) {
         req = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
         try {
          req = new ActiveXObject('Msxml2.XMLHTTP');
         } catch (eror) {
          req = new ActiveXObject('Microsoft.XMLHTTP');
         }
        }

        req.open('POST',url,false);
        req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        req.send('block_ip='+ip);
        
        if(req.readyState == 4){
		     if (req.status == 200){
		      document.getElementById(id).style.textDecoration='line-through';
		      document.getElementById(id).style.color='#555555';
		     }
        }
}
