function getAjaxXMLSimilar(band,div_id)
  {
  
 var xmlHttp;  
 

    toGet='gate.jsp?url=http://ws.audioscrobbler.com/1.0/artist/'+band+'/similar.xml';

    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("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        var xml =xmlHttp.responseXML;
        
          
          similars = xml.getElementsByTagName("name");
          
          var i;
          var similar="<div class=\"bbg\"><b>Similar Artists: </b></div><br>";
                    
          for (i=0;i<5;i++) {
          similar+=(similars[i].firstChild.nodeValue);
          similar+="<br>"
          }
          
          
          document.getElementById(div_id).innerHTML=similar;
		
        }
      }
 
    xmlHttp.open("GET", toGet ,true);    
    
    xmlHttp.send(null);
  }

function removeWhitespace(xml)
{
var loopIndex;
for (loopIndex = 0; loopIndex < xml.childNodes.length;
loopIndex++) {
var currentNode = xml.childNodes[loopIndex];
if (currentNode.nodeType == 1) {
removeWhitespace(currentNode);
}
if (((/^\s+$/.test(currentNode.nodeValue))) &&
(currentNode.nodeType == 3)) {
xml.removeChild(xml.childNodes[loopIndex--]);
}
}
}


function getAddAlbum(){
var band_id = document.getElementById("band_id").innerHTML;
var bandname = document.getElementById("t_b_n").innerHTML;
document.getElementById("main_window").innerHTML="<img src=\"img/ajax_anim.gif\"/>";
getAjax('addAlbum.jsp?band_id='+band_id+'&bandname='+bandname,'main_window');
disableForum();
}

function addAlbum(){
var band_id = document.getElementById("band_id").innerHTML;
var albumname = document.getElementById("albumnameField").value;
var year= document.getElementById("yearField").value;
var tracks = document.getElementById("tracksField").value;
var name = document.getElementById("bandname").innerHTML;

postAjax('addAlbum.jsp',band_id+"||"+albumname+"|||"+year+"||||"+tracks,'isPost');
timer=setTimeout('getBand(\''+name+'\')',1000);
enableForum();
}


function getAddTag(){
var band_id = document.getElementById("band_id").innerHTML;
var bandname = document.getElementById("t_b_n").innerHTML;
document.getElementById("main_window").innerHTML="<img src=\"img/ajax_anim.gif\"/>";
getAjax('addTag.jsp?band_id='+band_id+'&bandname='+bandname,'main_window');
disableForum();
}

function addTag(){
var band_id = document.getElementById("band_id").innerHTML;
var newtag = document.getElementById("newTagField").value;
var name = document.getElementById("bandname").innerHTML;
//name=escape(name);

postAjax('addTag.jsp',band_id+"||"+newtag,'isPost');
timer=setTimeout('getBand(\''+name+'\')',1000);
enableForum();
}

function getCloud(){
document.getElementById("main_window").innerHTML="<img src=\"img/ajax_anim.gif\"/>";
//alert(tagname);
getAjax('getCloud.jsp','main_window');
disableForum();
}

function getAddBand(){
document.getElementById("main_window").innerHTML="<img src=\"img/ajax_anim.gif\"/>";
//alert(tagname);
getAjax('addBand.jsp','main_window');
disableForum();
}

function addBand(){
var name = document.getElementById("bandnameField").value;
var picurl = document.getElementById("picField").value;
var desc = document.getElementById("descField").value;

name=escape(name);
picurl=escape(picurl);
desc =desc.replace(/–/g,"+"); 
desc=escape(desc);


postAjax('addBand.jsp',name+"||"+picurl+"|||"+desc,'isPost');
timer=setTimeout('getBand(\''+name+'\')',1000);
enableForum();
}

function getNews(){
document.getElementById("main_window").innerHTML="<img src=\"img/ajax_anim.gif\"/>";
//alert(tagname);
getAjax('getNews.jsp','main_window');
}


function enableForum(){
document.getElementById("isForum").className="vis";
document.getElementById("forum_window").className="mainright_fv";
document.getElementById("main_window").className="mainleft_fv";


}

function disableForum(){
document.getElementById("isForum").className="invis";
//document.getElementById("isForum").innerHTML="Hide Forum";
document.getElementById("main_window").className='mainleft_finv';
document.getElementById("forum_window").className="mainright_finv";


}

function moreTags(andor,tags){
//alert(andor);
tags = escape(tags);

if (andor=="null") {
 if (document.getElementById("combobox").selectedIndex==0) andor="and";
 if (document.getElementById("combobox").selectedIndex==1) andor="or";
 
 var like = document.getElementById('moretags_form').what.value;

 getAjax('moreTags.jsp?andor='+andor+"&tags="+tags+"&like="+like,'moretagssugg');
 }
 

 
else { 
 
 //alert (andor);
//alert ('moreTags.jsp?andor='+andor+"&tags="+tags);
var like = document.getElementById("what").value;

getAjax('moreTags.jsp?andor='+andor+"&tags="+tags+"&like="+like,'moretagssugg');

  }

}

function getTrack(trackname){
document.getElementById("main_window").innerHTML="<img src=\"img/ajax_anim.gif\"/>";
trackname = escape(trackname);
//alert(tagname);
getAjax('getBand.jsp?track='+trackname,'main_window');
}


function getAlbum(albumname){
document.getElementById("main_window").innerHTML="<img src=\"img/ajax_anim.gif\"/>";
albumname = escape(albumname);
//alert(tagname);
getAjax('getBand.jsp?album='+albumname,'main_window');
}

function getBandsFromTag(tagname){
document.getElementById("main_window").innerHTML="<img src=\"img/ajax_anim.gif\"/>";
tagname = escape(tagname);
//alert(tagname);
getAjax('getBandsFromTag.jsp?tag='+tagname,'main_window');
}

function getNoBand(){
var band = (document.getElementById("noband_form").value);
document.getElementById("main_window").innerHTML="<img src=\"img/ajax_anim.gif\"/>";
band=escape(band);
getAjax('players.jsp?band='+band,'main_window');

}

function hideDiv(div_id){
document.getElementById(div_id).innerHTML="";
document.getElementById(div_id).className = "invis";
}

/*
function changeDivVisib(div_id){
if (document.getElementById(div_id).className == 'invis')
document.getElementById(div_id).className = 'search_suggest';
else
document.getElementById(div_id).className = 'invis';
}
*/

function newPost(){
var name = document.getElementById("nameField").value;
var band = document.getElementById("band_id").innerHTML;
var post = document.getElementById("postfield").value;

//name=escape(name);
//alert(name);

postAjax('makePost.jsp',name+"||"+band+"|||"+post,'isPostForum');

}

function refreshForum(){
var band = document.getElementById("t_b_n").innerHTML; 
getAjax('getPosts.jsp?band='+band+'&nocache='+(Math.random()*1234567),'forum_window');
timer=setTimeout('refreshForum();',30000);
}


function resize() {

if(document.getElementById("forum_window").className == 'mainright_fv') {
document.getElementById("isForum").innerHTML="Show Forum";
document.getElementById("main_window").className='mainleft_finv';
document.getElementById("forum_window").className='mainright_finv';
}
else {
document.getElementById("isForum").innerHTML="Hide Forum";
document.getElementById("main_window").className='mainleft_fv';
document.getElementById("forum_window").className='mainright_fv';
}
}


function getBand(bname)
  {
  bname = bname.replace(/ /g,"+"); 
  getAjax('getBand.jsp?band='+bname,'main_window');
  
  getAjax('getPosts.jsp?band='+bname,'forum_window');
  
  getAjaxXMLSimilar(bname,'simil');
  
  getAjax('myspaceplayer.jsp?band='+bname,'player_place');
  
  getAjax('lastfmplayer.jsp?band='+bname,'player_place2');
  
  getAjax('hitVideo.jsp?band='+bname,'player_place3');
  
  timer=setTimeout('refreshForum();',30000);
  
}

function postAjax(link,data,div_id)
  {
  
 var xmlHttp;  
 
    
    //var toGet= link.concat("&nocache=")
    //link = link.concat(Math.random()*1234567);
    toGet=link;
    
    
    //document.getElementById(div_id).innerHTML='<img src="img/ajax_anim.gif"/>'
    //document.getElementById(div_id).innerHTML='LÓFASZ';
    //alert (document.getElementById(div_id).innerHTML);
    
    //document.getElementById("errorbar").innerHTML=toGet;
    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("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        var str =xmlHttp.responseText;
        
    //    alert (div_id);
     //   alert (document.getElementById(div_id));
        document.getElementById(div_id).innerHTML=str;
        
        
        if (div_id==='isPostForum')
		    refreshForum();
		    
		    
        }
      }

    
    xmlHttp.open("POST", link ,true);  
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");  
    xmlHttp.setRequestHeader("Content-length", data.length);    
    // xmlHttp.setRequestHeader("Content-Type", "text/plain; charset=ISO-8859-2");
    xmlHttp.send("data="+data);
  }


function getAjax(link,div_id)
  {
  
 var xmlHttp;  
 
   // alert(link);
    //var toGet= link.concat("&nocache=")
    //link = link.concat(Math.random()*1234567);
    toGet=link;
//  alert (link);
 //   alert(div_id);
    
    //document.getElementById(div_id).innerHTML='<img src="img/ajax_anim.gif"/>'
    //document.getElementById(div_id).innerHTML='LÓFASZ';
    //alert (document.getElementById(div_id).innerHTML);
    
    //document.getElementById("errorbar").innerHTML=toGet;
    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("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        var str =xmlHttp.responseText;
        
          //alert (div_id);
          //alert (document.getElementById(div_id));
          //alert(str);
          //alert(document.getElementById(div_id));
          if (document.getElementById(div_id)==null) ;
          else document.getElementById(div_id).innerHTML=str;
		
        }
      }

    
    xmlHttp.open("GET", toGet ,true);    
    
    xmlHttp.send(null);
  }


function getSugg(table)
  {
 // alert (document.getElementById(table).className);
 var xmlHttp;  
    var patt=  "sugg.jsp?like=";
    var form = (table+"_form");
    var toGet= patt.concat(document.getElementById(form).what.value);
    
    toGet = toGet.concat("&search=");
    toGet = toGet.concat(table);
    toGet = toGet.concat("&nocache=");
    toGet = toGet.concat(Math.random()*1234567);
    //alert(toGet)
    
    //document.getElementById("errorbar").innerHTML=toGet;
    //alert(toGet);
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
   // alert (e);
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
     // alert (e);
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        //alert (e);
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        /*
        var str =xmlHttp.responseText.split("<br>");        
        
        var toadd='';
        for(i=0; i < str.length - 1; i++) {
        var elem ='';
        elem +='<div class="suggest_link">';
        elem += str[i];
        elem +='</div>';
        toadd+=elem;
        }
        */
        //alert (toadd);
        document.getElementById(table).innerHTML=xmlHttp.responseText;
        if (document.getElementById(form).what.value =="") hideDiv(table); 
        else document.getElementById(table).className = 'search_suggest'; 
        }
      }

    
    xmlHttp.open("GET", toGet ,true);
    //xmlHttp.open("GET", "time.php" ,true);
    
    xmlHttp.send(null);
  }
  
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}  
 
function cloudOver(div_value) {
	div_value.className = 'cloud_link_over';
}
//Mouse out function
function cloudOut(div_value) {
	div_value.className = 'cloud_link';
}   