var myselect;
function getXMLHTTP() { 
	var xmlhttp=false;
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e) {
		try{
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}
	
	return xmlhttp;
}// end function getXMLHTTP()

function Display(dtarget,file){

	var req = getXMLHTTP();
	document.getElementById(dtarget).innerHTML="<center><img src='images/ajax_loader.gif'></center>";

	if(req){
	
		req.onreadystatechange = function() {
		
		if (req.readyState == 4) {
		
			if (req.status == 200) {
			
				var result=req.responseText;
				document.getElementById(dtarget).innerHTML=result;
			
			}// end if (req.status == 200)
		
		}// end if (req.readyState == 4)
		
		}// end if(req)
	
	var rstr=Math.random();
	var strURL=file+"&rstr="+rstr;
	req.open("GET", strURL, true);
	req.send(null);
	
	}
	
}//end function display()


function DisplayPic(dtarget1,dtarget2,file){

	var req = getXMLHTTP();
	document.getElementById(dtarget1).innerHTML="<center><img src='images/ajax_loader.gif'></center>";

	if(req){
	
		req.onreadystatechange = function() {
		
		if (req.readyState == 4) {
		
			if (req.status == 200) {
			
				var result=req.responseText;
				document.getElementById(dtarget1).innerHTML="";
				document.getElementById(dtarget2).innerHTML=result;
			
			}// end if (req.status == 200)
		
		}// end if (req.readyState == 4)
		
		}// end if(req)
	
	var rstr=Math.random();
	var strURL=file+"&rstr="+rstr;
	req.open("GET", strURL, true);
	req.send(null);
	
	}
	
}//end function display()

function load_xml(url){

	xmlReq = getXMLHTTP();
	var rstr =Math.random();
	xmlReq.onreadystatechange=callBack;
	xmlReq.open("GET",url,true);
	xmlReq.send(null);
}

function callBack(){
	
	myselect=createSelect("myselect");
	if(xmlReq.readyState==4){
		if(xmlReq.status==200){
			
			if(xmlReq.responseText != "EMPTY"){
		
				var xmlResult=xmlReq.responseXML;
				var dataNodes=xmlResult.getElementsByTagName("data");
				var Url;
				var Name;
				for(var i=0;i<dataNodes.length;i++){

					Url=dataNodes[i].getElementsByTagName("Url")[0].firstChild.nodeValue;
					Name=dataNodes[i].getElementsByTagName("Name")[0].firstChild.nodeValue;
					myselect.appendChild(createOption(Url,Name));

					
				}
				
				displayMySelect(myselect);
			
				
			}
		}
	}

}

function createSelect(nameSelect){

	var newSelect=document.createElement("select");
	newSelect.setAttribute("id",nameSelect);
	newSelect.setAttribute("name",nameSelect);
	var theOption=document.createElement("OPTION");
	theOption.setAttribute("value","#");
	theOption.appendChild(document.createTextNode("ระบุ"));
	newSelect.appendChild(theOption);
	return newSelect;
}

function createOption(addId,addText){

	var theOption=document.createElement("OPTION");
	theOption.setAttribute("value","http://"+addId);
	var myOnChange = new Function("e", "window.open(this.options[this.selectedIndex].value,'_blank')");
	myselect.onchange=myOnChange;
	theOption.appendChild(document.createTextNode(addText));
	return theOption;
	
}

function displayMySelect(myselect){

	var web_ring=document.getElementById("web_ring");
	web_ring.appendChild(myselect);
}
