var req;
function loadXMLDoc(url)
{
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
        
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange(){
	if (req.readyState == 4){
		if (req.status == 200){
			var a=req.responseXML;			
			//alert(req.responseText);
			var root = a.documentElement;
			var type=root.getElementsByTagName("type");
			var cs=type[0].getAttribute("t");
			if(cs=='showtown'){
				var town=a.getElementsByTagName("town");
				var obj=document.getElementById('seltown');
				var contt=document.getElementById('conttown');
				obj.style.display='block';
				contt.innerHTML='';
				for(var i=0;i<town.length;i++){
					var title=town[i].getAttribute('title');
					var div = document.createElement('div');
					div.className='item';
					div.onclick = new Function('selTown(this)');
					div.onmouseout = new Function('outdiv(this)');
					div.onmouseover = new Function('odiv(this)');
					div.innerHTML=title;
					contt.appendChild(div);
				}
			}
			else if(cs='showmp3'){
				var items=a.getElementsByTagName("item");
				var cont=document.getElementById('searchmp3');
				var h=document.getElementById('searchmp3h');
				var mp3scanc=document.getElementById('mp3scanc');
				if(items.length>0 && document.getElementById('q2').value!=''){

					cont.style.display='block';
					mp3scanc.style.display='block';
					h.style.display='block';
					
					h.lastChild.nodeValue='Результат поиска:';
					cont.innerHTML='';
					for(var i=0;i<items.length;i++){
						
						var singer_name=items[i].getAttribute('singer_name');
						var song_name=items[i].getAttribute('song_name');
						var mp3id=items[i].getAttribute('mp3id');
						var size=items[i].getAttribute('size');
						var nick=items[i].getAttribute('nick');
						var div = document.createElement('div');
						div.className='mp3';
						if(items[i].getAttribute('img')){
							div.style.background="url(/res/mp3/img_small/"+mp3id+".jpg) 0 0 no-repeat";
						}
						
						var h4 = document.createElement('h4');
						var h4_div = document.createElement('div');
						var h4_div_text = document.createTextNode(singer_name);
						h4_div.appendChild(h4_div_text);
						var h4_a = document.createElement("a");
						var h4_a_text = document.createTextNode(song_name);
						h4_a.appendChild(h4_a_text);
						h4_a.setAttribute("href","/community/mp3/"+mp3id+".html");
						h4.appendChild(h4_div);
						h4.appendChild(h4_a);
						div.appendChild(h4);
						var h5 = document.createElement('h5');
						var h5_text = document.createTextNode(size+"//закачал");
						h5.appendChild(h5_text);
						var h5_a = document.createElement("a");
						var h5_a_text = document.createTextNode(nick);
						h5_a.appendChild(h5_a_text);
						h5_a.setAttribute("href","/community/users/"+nick);
						h5.appendChild(h5_a);
						div.appendChild(h5);
						cont.appendChild(div);
					}
					
				}
				else if(cs='mp3Best'){
					
				}
				else{
					hidmp3s(1);
				}
			}
		} 
		else {
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}