function tag1(text1)
   {
       var obj = document.form_comment.txt;
       if ((document.selection))
         {
             obj.focus();
             document.selection.createRange().text += text1;
         } else if ((obj.selectionStart) || (obj.selectionStart==0))
		 {  
		    var selEnd = obj.selectionEnd;
			var selStart = obj.selectionStart;
			var selSet;
			if (selStart<selEnd) selSet = 1;
		    obj.value = obj.value.substr(0, selEnd) + text1 + obj.value.substr(selEnd);
			obj.focus();
			if (selSet) obj.selectionStart = selStart;
			obj.selectionEnd = selEnd + text1.length;
		 } else
		 {
		   obj.value += text1;
		 }
   }
																
function tag(text1, text2)
   {
       var obj = document.form_comment.txt;
       if ((document.selection))
         {
             document.form_comment.txt.focus();
             document.form_comment.document.selection.createRange().text = text1+document.form_comment.document.selection.createRange().text+text2;
         } else if ((obj.selectionStart) || (obj.selectionStart==0))
		 {
		    var selEnd = obj.selectionEnd;
			var selStart = obj.selectionStart;
			if (selStart<selEnd) selSet = 1;
		    obj.value = obj.value.substr(0, selStart) + text1 + obj.value.substr(selStart, selEnd) + text2 + obj.value.substr(selEnd);
			obj.focus();
			obj.selectionStart = selStart;
			obj.selectionEnd = selEnd + text2.length + text1.length;		 
		 } else document.form_comment.txt.value += text1+text2;
   }
   
function delete_data(message_alert, go_link) 
  {
      if (confirm(message_alert))
 	     parent.location = go_link;
  }
  
function doAct(t)
  {
      document.getElementById('form_messages').submit();
  }
		         
function clear_cb(num, num2)
  {
    for(i=0;i<num;i++)
      for(j=0;j<=num2;j++)
        { 
		      var e = document.getElementById(j+'msg'+i);
			    if (e) e.checked = 0;
	      }
  }		         

function select_cb(num, r, ch)
  {
	  for(i=0;i<num;i++)
	    { 
		    var e = document.getElementById(r+'msg'+i);
			  if (e) e.checked = ch;
	    }
  }
  
function out_pleer(path, flashcontent)
  {
      //var so = new SWFObject('pleer/uppod.swf?st=pleer/style_pleer.txt&file='+path, 'flash', '470', '33', '7');
			// so.addParam('wmode', 'transparent');
			// so.addParam('allowFullScreen', 'true');
			// so.addParam('allowScriptAccess', 'always');
			// so.write(flashcontent);
      var flashvars = {'uid': flashcontent,'st':'pleer/style_pleer.txt','file': path};
      var params = {wmode:'transparent', allowScriptAccess:'always'}; 
			new swfobject.embedSWF('pleer/pleer4.swf', flashcontent, '470', '33', '9.0.0', false, flashvars, params);
  }
 
function out_vpleer(path, flashcontent)
  {    
    var flashvars = {'uid':flashcontent,'st':'pleer/style_vpleer.txt','file':path};         
    var params = {wmode:'transparent',  allowFullScreen:'true', allowScriptAccess:'always'};          
    new swfobject.embedSWF('pleer/uppod.swf', flashcontent, '500', '400', '9.0.115.0', false, flashvars, params);
  } 
  
function listen_song(path, title)
  {
     str = "top=100, left=100, width=500, height=120, location=no, menubar=no, status=no, toolbar=no, channelmode=no, fullscreen=no";
	 window.open(path, title, str);
  }
 
function makeRequest(url, element_id) {
   http_request = false;
   if (window.XMLHttpRequest) 
     { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) 
         {
          http_request.overrideMimeType('text/xml');
         }
     } else if (window.ActiveXObject) { // IE
       try {
             http_request = new ActiveXObject("Msxml2.XMLHTTP");
           } catch (e) {
       try {
             http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
           }
           }

    if (!http_request) 
       {
         //alert('Giving up :( Cannot create an XMLHTTP instance');
         return false;
       }
      
   http_request.onreadystatechange = function() { alertFContents(http_request, element_id); }  
   http_request.open('GET', url, true);
   http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=windows-1251');
   http_request.send(null);

}

function alertFContents(http_request, element_id) 
 {
   var PickText, prevDiv;
   if (http_request.readyState == 4) {
    if (http_request.status == 200) {
     PickText = http_request.responseText;
      } else {
         PickText = 'Проблема с запросом';
        }
		  prevDiv = document.getElementById(element_id); 
		  if (prevDiv !=null) prevDiv.innerHTML = PickText;
   }
 }

var window_play_list;
function OpenWindowPlayList()
  {
    window_play_list = window.open('playlist/','playlist_win',
            'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
            'scrollbars=yes,resizable=yes,' +
            'width=550,height=400');
  }
  
function MenuItemOn(menu_id,flag) {
     if (document.getElementById(menu_id)!=null) {
		    if (flag==1) document.getElementById(menu_id).style.display="block";
		   else document.getElementById(menu_id).style.display="none";
	   }
	}
	
function AddToPlayList(data_id, bookmark_id, type_music, link_music, link_user)
{ 
  var update_pl = 0;
  if ((!window_play_list) || (window_play_list.closed))
    {
      window_play_list = window.open('', 'playlist_win',
            'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
            'scrollbars=yes,resizable=yes,' +
            'width=550,height=400');
      
      if (window_play_list.document.title=='')
        OpenWindowPlayList(); else
          {
            if (window_play_list.playlist_create==0)
              OpenWindowPlayList(); else
                {
                  update_pl = 1;
                  
                }
          }
        
    }
  if ((window_play_list) && (update_pl==1))
    {
      var num = window_play_list.ArrayID.length;
      var def_gr = "background-image: url('../img/ground/ground1.gif')";
      var def_txt = "padding-left : 5px; padding-right : 5px;";
      window_play_list.parent.ArrayID[num] = data_id;
      window_play_list.parent.ArrayType[num] = type_music;
      window_play_list.parent.ArrayBM[num] = bookmark_id; 
        
      var table_pl = window_play_list.document.getElementById('table_play_list');
      var new_row = table_pl.insertRow(num+1);
    
      var new_cell= new_row.insertCell(-1);
      new_cell.innerHTML = "<input id=1msg"+ num + " name='msg" + 
                            bookmark_id + "' type='checkbox' value='"+ bookmark_id +"'>";
      //<input id=$id_cb name='msg$f[bookmark_id]' type='checkbox' value='$f[bookmark_id]'>
      //alert(new_cell.innerHTML);
      new_cell.align = "center"; 
      var new_cell= new_row.insertCell(-1); 
      
      new_cell.style.cssText= def_gr;
      
      var new_cell= new_row.insertCell(-1); 
      new_cell.innerHTML = "<a href='#' onClick='play_to_num(" + num + "); return false;'><img src='../img/button/play.gif'></a>";
      //alert(new_cell.innerHTML);
      new_cell.align = "center";
      var new_cell= new_row.insertCell(-1);
      new_cell.style.cssText= def_gr; 
      
      var new_cell= new_row.insertCell(-1); 
      new_cell.innerHTML = num+1;
      new_cell.id = 'num' + num;
      new_cell.align = "center"; 
      
      var new_cell= new_row.insertCell(-1); 
      new_cell.style.cssText= def_gr; 
      
      var new_cell= new_row.insertCell(-1); 
      new_cell.style.cssText = def_txt;
      
      new_cell.innerHTML = '<a id=name' + num + link_music;
      //alert(new_cell.innerHTML);
      //window_play_list.document.getElementById('new_song').id = 'name' + num;
      //alert(window_play_list.document.getElementById('new_song').id);
      //new_cell.id= 'name' + num; 
      
      
      var new_cell= new_row.insertCell(-1); 
      new_cell.style.cssText= def_gr; 
      
      var new_cell= new_row.insertCell(-1); 
      new_cell.style.cssText = def_txt;
      new_cell.innerHTML = '<a id=user' + num + link_user;
      
      var new_cell= new_row.insertCell(-1); 
      new_cell.style.background = "url(../img/ground/ground5.gif)";
      num++;
    }
}

function set_vote(id, value, t)
  {
    makeRequest('ajax/set_vote.php?id=' + id + '&v=' + value + '&t=' + t, 'v' + id);
  }
  
function delete_msg(id) 
  {
    if (confirm('Удалить сообщение?'))
 	    makeRequest('ajax/delete_msg.php?id=' + id, 'm' + id);
  }    