// JavaScript Document
if ( typeof(AFR) == 'undefined' ) AFR = function() {};
if ( typeof(AFR.config) == 'undefined' ) AFR.config = function() {};
AFR.poweredby ='AFRMEDIA';
AFR.get_path = function(x){return this.config.siyt_path + x;}
AFR.loadingIMG1 = new Image();
AFR.loadingIMG1.src = AFR.get_path('images/loading_1.gif');
AFR.loadingIMG2 = new Image();
AFR.loadingIMG2.src = AFR.get_path('images/loading_2.gif');
AFR.loadingIMG3 = new Image();
AFR.loadingIMG3.src = AFR.get_path('images/loading_3.gif');
var blankSrc = AFR.get_path('images/blank.gif');

AFR.loading = function(oId)
{
	h=document.getElementById(oId).offsetHeight;
	var html='';
	html += '		<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	html += '            <tr>';
	html += '              <td height="'+ h +'" align="center" style="font-family:Tahoma;font-size:11px;"><img src="'+ this.loadingIMG.src +'"><br>Yüklenir...</td>';
	html += '            </tr>';
	html += '          </table>';
	
	return html;
}

function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

//RTrim(string) : Returns a copy of a string without trailing spaces.
function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Returns a copy of a string without leading or trailing spaces
function str_rep_arr(str,str_search,str_rpl)
{
	for(i=0;i<str_search.length;i++)
	{
		while(str.indexOf(str_search[i])!=-1)
		{
	 		str=str.replace(str_search[i],str_rpl[i]);
		}
	}
	return str;
}
function str_rep(str,str_search,str_rpl)
{
	while(str.indexOf(str_search)!=-1)
	{
		str=str.replace(str_search,str_rpl);
	}
    return str;
}
function trim(str)
{
   str=ltrim(str);
   str=rtrim(str);
   while(str.indexOf("  ")!=-1)
	{
	 str=str.replace("  "," ");
	}
   return str;
}
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
function GetElementByName(xml, start, end) 
{
   	startpos = xml.indexOf(start);
   	if (startpos == -1) return false;
   	startpos = startpos + start.length;
   	endpos =  xml.indexOf(end);
   	tag = xml.substring(startpos, endpos);
  	return trim(tag);
}
function XPathValue(XPath,node)
{
   	list = XPath.split('/');
    for (i=0;i < list.length;i++) 
   	{
    	node = GetElementByName(node, '<'+ list[i] +'>', '</'+ list[i] +'>'); 
   	}
    return node;
}
var http = createRequestObject();
function getHtml(url,id,inner_html,fnct) 
{
	
	http.open('get', url);
    http.onreadystatechange = function()
	{
		if(http.readyState == 4)
		{
        	var response = http.responseText;
			insertHtml(id,response,1);
            if(fnct!=null && fnct!="")eval(fnct);
       	}
		else 
		{
			if(inner_html=="" || inner_html==null)inner_html=AFR.loading(id);
			else
			{
				inner_html = inner_html.replace('%2','<img align="left" src="'+ AFR.loadingIMG2.src +'">');
				inner_html = inner_html.replace('%1','<img align="left" src="'+ AFR.loadingIMG1.src +'">');
				inner_html = inner_html.replace('%3','<img align="left" src="'+ AFR.loadingIMG3.src +'">');
			}
			insertHtml(id,inner_html,1);
		}
	}
    http.send(null);
}
function insertHtml(oDiv,html,display) 
{
    if(document.getElementById(oDiv))
	{
		document.getElementById(oDiv).innerHTML = html;
		if(display==1)document.getElementById(oDiv).style.display="";
		else document.getElementById(oDiv).style.display="none";
	}
}
function Online() 
{
    	
	setTimeout("Online()",60000);
	var ajax = createRequestObject();
	ajax.open('get', 'http://radio.azeri.net/sayac.php');
    ajax.onreadystatechange = function()
	{
		if(ajax.readyState == 4)
		{
        	var response = ajax.responseText;
			insertHtml('gosterDiv',response,1);
        }
	}
    ajax.send(null);
}
Online();
function $(elem)
{
	return document.getElementById(elem);	
}
function select_all(oId,where)
{
	var rows = document.getElementById(where).getElementsByTagName('tr');
	if(oId.checked)
	{
		for(i=0;i<rows.length;i++)
		{
			if(rows[i].getElementsByTagName( 'input' )[0].checked==false)
			{
				rows[i].getElementsByTagName( 'input' )[0].checked=true;
				rows[i].className = 'marked';
			}
		}
	}
	else
	{
		for(i=0;i<rows.length;i++)
		{
			rows[i].getElementsByTagName( 'input' )[0].checked=false;
			rows[i].className = 'odd';
		}
	} 
}
function markRowsInit(where)
{
 	
	if(document.getElementById(where))
	{
		var rows = document.getElementById(where).getElementsByTagName('tr');
		for ( var i = 0; i < rows.length; i++ ) 
		{
			if ( 'odd' != rows[i].className) 
			{
				continue;
			}
		   
			
			rows[i].onmouseover = function() 
			{
				this.className = 'hover';
			}
			rows[i].onmouseout = function() 
			{
				if(this.getElementsByTagName( 'input' )[0].checked)this.className = 'marked';
				else this.className = 'odd'
			}
		   
			rows[i].onmousedown = function() 
			{
				var checkbox;
	
				checkbox = this.getElementsByTagName( 'input' )[0];
				if ( checkbox && checkbox.type == 'checkbox' ) 
				{
					checkbox.checked;
					checkbox.checked = ! checkbox.checked;
					
					if(checkbox.checked==true) this.className = 'marked';
					else 
					{
						this.className = 'odd';
						$('sellectAll').checked=false;
					}
				} 
				else 
				{
					return;
				}
			}
	
			var checkbox = rows[i].getElementsByTagName('input')[0];
			if ( checkbox ) 
			{
				checkbox.onclick = function() 
				{
					// opera does not recognize return false;
					this.checked = ! this.checked;
				}
			}
		}
	}
}
AFR.playList = new Array();
function createRadioPlayList()
{
	var m = AFR.playList.length;
	var xml = new JKL.ParseXML( "http://radio.azeri.net/cookiePlayList.php");
	var data = xml.parse();
	var list = data.playlists.playlist;
	if(list.track != 'undefined')
	{
		for(var i=0;i<list.track.length;i++)
		{
			AFR.playList[m] = new Array();
			AFR.playList[m]['id'] = list.track[i]["trackMod"];
			AFR.playList[m]['title'] = list.track[i]["title"];
			m++;
		}
	}
}
createRadioPlayList();
function addPlayList(where)
{
	var addStatus;
	var rows = document.getElementById(where).getElementsByTagName('tr');
	for(i=0;i<rows.length;i++)
	{
		var cBox = rows[i].getElementsByTagName( 'input' )[0];
		if(cBox.checked==true)
		{
			var m = AFR.playList.length;
			addStatus = true;
			for(j=0;j<m;j++)if(AFR.playList[j]['id'] == cBox.value){addStatus = false;break;}
			if(addStatus == true)
			{
				AFR.playList[m] = new Array();
				AFR.playList[m]['id'] = cBox.value;
				AFR.playList[m]['title'] = cBox.title;
				
			}
		}
	}
	cookiePlayList();
}
function removePlayList(where)
{
	var rows = document.getElementById(where).getElementsByTagName('tr');
	for(i=0;i<rows.length;i++)
	{
		var cBox = rows[i].getElementsByTagName( 'input' )[0];
		if(cBox.checked==true)
		{
			var playList =  new Array();
			var z = 0;
			for(j=0;j<AFR.playList.length;j++)if(AFR.playList[j]['id'] != cBox.value){playList[z] = AFR.playList[j];z++;}
			AFR.playList = playList;
		}
	}
	cookiePlayList();
	writePlayList();
}
function writePlayList()
{
	
	var content = '';
	content += '<div style="width:390;height:230px;display:block;overflow:auto;border:1px solid #CCCCCC;">';
    content += '  <table width="100%" border="0" cellspacing="0" cellpadding="0" id="playList_table">';
    content += '  <form name="playList_form" id="playList_form">';
	for(j=0;j<AFR.playList.length;j++)
	{
		content += '<tr class="odd">';
        content += '  <td width="6%" height="22" style="border-top:1px solid #E9F6FF;border-right:1px solid #ffffff;"><input type="checkbox" name="linkId" id="linkId" value="'+ AFR.playList[j]['id'] +'" title="'+ AFR.playList[j]['title'] +'"></td>';
        content += '  <td width="94%" style="border-top:1px solid #E9F6FF;">'+ AFR.playList[j]['title'] +'</td>';
        content += '</tr>';
		
	}
	content += '  </form>';
    content += '  </table>';
    content += '  </div>';
    content += '  <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    content += '   <tr>';
    content += '      <td height="25"><input type="checkbox" name="sellectAll" id="sellectAll" onClick="select_all(this,\'playList_table\');"> <input type="submit" name="button2" id="button2" value="Seçilileri Siyahıdan Sil" class="btn_01" onClick="removePlayList(\'playList_table\');"> <input type="submit" name="button2" id="button2" value="Radioda Dinle" class="btn_01" onClick="rRadioPlayList();"></td>';
    content += '    </tr>';
    content += '  </table>';
	$('inner_ajax').innerHTML = content;
	markRowsInit("playList_table");
}
function cookiePlayList()
{
	var cookie_value = '';
	for(j=0;j<AFR.playList.length;j++)
	{
		cookie_value += AFR.playList[j]['id'] + ',';
	}
	cookie_value = cookie_value.substring(0,cookie_value.length-1);
	writeCookie('RadioPlayList', cookie_value, 24);
}
function rRadioPlayList()
{
	$("Layermsg").innerHTML = '';
	var content = '<embed type="application/x-shockwave-flash" '
        +' src="http://radio.azeri.net/player/player.swf" allowScriptAccess="always"'
        +' width="200px" height="300px" '
        +' bgcolor="#ECECEC" '
        +' id="radioblog_player_0" '
		+' wmode="transparent" '
        +' FlashVars="'
        +'id=0'
        +'&playlistPath=http://radio.azeri.net/cookiePlayList.php'
        +'&colors=body:#ECECEC;border:#BBBBBB;button:#999999;player_text:#666666;playlist_text:#666666;'
		+'&tracknum=1'
        +'"'
        +'></embed>';
		$("Layermsg").innerHTML = content;
}

function writeCookie(name, value, hours)

{

  var expire = "";

  if(hours != null)

  {

    expire = new Date((new Date()).getTime() + hours * 3600000);

    expire = "; expires=" + expire.toGMTString();

  }

  document.cookie = name + "=" + escape(value) + expire;

}

function readCookie(name)

{

  var cookieValue = "";

  var search = name + "=";

  if(document.cookie.length > 0)

  { 

    offset = document.cookie.indexOf(search);

    if (offset != -1)

    { 

      offset += search.length;

      end = document.cookie.indexOf(";", offset);

      if (end == -1) end = document.cookie.length;

      cookieValue = unescape(document.cookie.substring(offset, end))

    }

  }

  return cookieValue;

}

