function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == 'Microsoft Internet Explorer'){
        ro = new ActiveXObject('Microsoft.XMLHTTP');
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
var http = createRequestObject();

function sndReq(id_foto) {
    http.open('get', 'index.php?action=ajax&foto='+id_foto);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
            document.getElementById(update[2]).innerHTML = update[3];
			
        }
    }
}


function sndReqEfir() {
    http.open('get', '/ajax/playsong/');
    http.onreadystatechange = handleResponseEfir;
    http.send(null);
}


function handleResponseEfir() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
			countDownInterval=update[1]-minusInterval;
			if (update[3].length<=25)
				document.getElementById(update[2]).style.fontSize='11px';
			else if (update[3].length<35)
				document.getElementById(update[2]).style.fontSize='10px';
			else if (update[3].length<50)
				document.getElementById(update[2]).style.fontSize='9px';
			else if (update[3].length>60)
				document.getElementById(update[2]).style.fontSize='8px';
            document.getElementById(update[2]).innerHTML = update[3];
            document.getElementById(update[4]).innerHTML = update[5];
            document.getElementById(update[6]).innerHTML = update[7];
        }
    }
}


function countDown()
{
	countDownTime--;
	if (countDownTime == 1)
	{
		sndReqEfir();
	}
	if (document.all)
	{
		document.all.secund.innerText = secsToMins(countDownTime);
	}
	else if (document.getElementById)
	{
		document.getElementById("secund").innerHTML = secsToMins(countDownTime);
	}
	if (countDownTime == 0)
	{
		countDownTime = countDownInterval;
	}
	if (countDownTime < -1)
	{
		countDownTime =5;
	}
	counter = setTimeout("countDown()", 1000);
}

function secsToMins(theValue) 
{
	var theMin = Math.floor(theValue / 60);
	var theSec = (theValue % 60);
	if (theSec < 10)
	{
		theSec = "0" + theSec;
	}
	return(theMin + ":" + theSec);
}




function get_code_WMP(pl) 
{
	f=document.getElementById(pl);
	channel=f.channel.value;
	width=f.width.value;
	height=f.height.value;
	autostart=f.autostart.value;
	volume=f.volume.value;
	if (pl=='wmp')
	{
		f.code.value="<script type=\"text/javascript\">\nif(-1 != navigator.userAgent.indexOf(\"MSIE\"))\n{\ndocument.write('<OBJECT id=\"Player\"');\ndocument.write(' classid=\"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6\"');\ndocument.write(' width="+width+" height="+height+">');\n}\nelse if(-1 != navigator.userAgent.indexOf(\"Firefox\"))\n{\ndocument.write('<OBJECT id=\"Player\"'); \ndocument.write(' type=\"application/x-ms-wmp\"'); \ndocument.write(' width="+width+" height="+height+">');\n}      \ndocument.write('<PARAM NAME=\"URL\" VALUE=\"http://"+channel+".radiowm.net:8001/"+channel+"kbps\">'); \ndocument.write('<PARAM NAME=\"AutoStart\" VALUE=\""+autostart+"\">'); \ndocument.write('<PARAM NAME=\"Volume\" VALUE=\""+volume+"\">'); \ndocument.write('</OBJECT>'); \n</script>";
		document.getElementById("wmp_pl").style.display="block";
		document.getElementById("afp_pl").style.display="none";
	}
	else if (pl=='afp')
	{
		f.code.value="<script type=\"text/javascript\" src=\"http://www.radiowm.net/object/swfobject.js\"></script>\n<div id=\"player\"></div>\n<script type=\"text/javascript\">\nvar so = new SWFObject('http://www.radiowm.net/object/mediaplayer.swf', 'stream', '"+width+"', '"+height+"', '7');\nso.addVariable('height','"+height+"');\nso.addVariable('width','"+width+"');\nso.addVariable('type', 'mp3');\nso.addVariable('file','http://"+channel+".radiowm.net:8001/"+channel+"kbps');\nso.addVariable('searchbar','false');\nso.addVariable('showicons','false');\nso.addVariable('usefullscreen','false');\nso.addVariable('autostart','"+autostart+"');\nso.addVariable('volume','"+volume+"');\nso.write('player');\n</script>";
		document.getElementById("afp_pl").style.display="block";
		document.getElementById("wmp_pl").style.display="none";
	}
	f.code.select();
	return false;
}

function get_code_selected (pl)
{
	f=document.getElementById(pl);
	f.code.select();

}