function getRequest(value, level){
    var xmlhttp = null;
    // Mozilla
    if (window.XMLHttpRequest) {
	xmlhttp = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    var	file = "fileadmin/templates/listing/structure.xml";

    xmlhttp.open("GET", file, true);
    xmlhttp.onreadystatechange = function() {
	if(xmlhttp.readyState!= 4) {
	//$("request").innerHTML = "...";
	}
	if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
	    refreshView(xmlhttp.responseXML, value, level);
	}
    }
    xmlhttp.send(null);
}

function refreshView(xml, cur, level){
    var items = xml.getElementsByTagName(cur)[0];
    var step2 = new Array;
    var down = new Array;
    var childs = new Array;

    var j=0;
    var k=0;
    var i=0;
    
    if(items.hasChildNodes){
	childs = items.childNodes;

	for(i=0;i<childs.length;i++){
	    if(childs[i].nodeType ==  1){
		if(childs[i].nodeName == 'file'){    
		    // attach to download section
		    down[j]=childs[i];
		    j++;
		} else {
		    // attach to step2
		    step2[k]=childs[i];
		    k++;
		}
	    }  
	}
    }

    var inner="";
    var cat="";
    var sub_category;
    
    switch(level){
	case 0:
	    sub_category = document.getElementById("sub_category1");
	    cat="second_cat";
	    break;
	case 1:
	    sub_category = document.getElementById("sub_category2");
	    cat="third_cat";
	    break;
	case 2:
	    sub_category = document.getElementById("sub_category3");
	    cat="first_cat";
	    break;
	default:
	    sub_category = document.getElementById("sub_category1");
	    cat="first_cat";
	    break;
    }

    if(step2.length>0){
	var main = document.getElementById("main_category");
	inner = '<option name="'+cat+'" value="'+main.options[main.selectedIndex].value+'">--- Please select ---</option>';
    }

    for(var i=0;i<step2.length;i++){
	inner += '<option name="'+cat+'" value="' + step2[i].nodeName + '">'+ step2[i].nodeName +'</option>\n';
    }

    if("" === inner && level !=2){
	inner='<option name="'+cat+'" value="no">No subcategories available</option>';
    }
  
    if(sub_category){
	// Bug in IE : IE removes first opening option tag, workaround would be working with the DOM tree
	//console.log(inner);
	sub_category.innerHTML=inner;
	//console.log(sub_category.innerHTML);
    }
    
    inner="";
    /*if(down.length>0){
	inner = '<option name="'+cat+'" value="no">--- Please select ---</option>';
    }*/
    var results = document.getElementById("results");
    for(i=0;i<down.length;i++){
	var name = down[i].getAttribute("name");
	var vis = down[i].getAttribute("visname");
	var hidden = down[i].getAttribute("hidden");
	var size= down[i].getAttribute("size");
	
	if(hidden == 0){
	    //inner += '<option name="results_entry" value="' + name + '">'+ vis +' ('+size+')</option>';
	    inner += '<a class="results_entry" title="Download file" target="_blank" href="http://spectran-developer.net/ftp/' + name + '">'+ vis +' ('+size+')</a><br>';
	}
    }

    if("" === inner){
	inner='<option name="'+cat+'" value="no">No files found</option>';
    }
    results.innerHTML = inner;
}

function getFileDownload(value){
    var main = document.getElementById("main_category");

    /*var path ="";
    if(main.options[main.selectedIndex].value != "no" && main.options[main.selectedIndex].value != "select"){
	path += main.options[main.selectedIndex].value + '/';
    }

    sub1 = document.getElementById("sub_category1");
    if(sub1.options[sub1.selectedIndex].value != "no" && sub1.options[sub1.selectedIndex].value != "select"){
	path += sub1.options[sub1.selectedIndex].value + '/';
    }

    sub2 = document.getElementById("sub_category2");
    if(sub2.options[sub2.selectedIndex].value != "no" && sub2.options[sub2.selectedIndex].value != "select"){
	path += sub2.options[sub2.selectedIndex].value + '/';
    }*/
    
    //path+=value;

    //var link = 'http://'+top.location.host+'/ftp/'+path;
    //var link = 'http://spectran-developer.net/ftp/'+path;
    var link = 'http://spectran-developer.net/ftp/'+value;

    window.location.href=link;
}
