var _get;
var q=true;
var o={
	"bt_discover":Array("1.20"),
	"ftp_bt":Array("1.08"),
	"img_ftp":Array("1.00","1.10"),
	"miesta":Array("1.00"),
	"minesweeper":Array("1.00","1.10"),
	"m_video":Array("1.00","1.10","1.20"),
	"real_jack":Array("1.01"),
	"rozvrh_2":Array("1.00")
};

window.onload=load;

function load(){
	get_load();
	var x=get("x");
	if (x=="download" || x=="upload"){
		if (get("y")!=""){
			document.getElementsByName("app")[0].value=get("y");
		}
		c(document.getElementsByName("app")[0].value);
	}
	if (x=="download"){
		//c(document.getElementsByName("app")[0].value);
		if (get("z")!="")
			document.getElementsByName("ver")[0].value=get("z");
		rel();
	}
}

function rel_(){
	document.location="?x=download&y="+document.getElementsByName("app")[0].value+"&z="+document.getElementsByName("ver")[0].value;
}

function get_load(){
	_get={};
	var tmp="";
	var pos=(""+document.location).indexOf("?");
	if (pos>-1){
		tmp=(""+document.location).substring(pos+1).split("&");
		for (var i=0;i<tmp.length;i++){
			tmp[i]=tmp[i].split("=");
			_get[tmp[i][0]]=tmp[i][1];
		}
	}
	return _get.length;
}

function get(a){
	if (!_get[a] || _get[a]==null)
		return "";
	return _get[a];
}
/*
function rx(){
	if (!window.XMLHttpRequest){
 		try{ return new ActiveXObject("MSXML3.XMLHTTP") }catch(e){}
    try{ return new ActiveXObject("MSXML2.XMLHTTP.3.0") }catch(e){}
    try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
    try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
    throw new Error("Could not find an XMLHttpRequest alternative.")
  }else{
  	return new XMLHttpRequest();
  }
}

function req(url,callbackFunction){
	var request=rx();
	if (request==null) return false;
	
  request.open("GET",url,true);
  request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
  request.onreadystatechange=function(){
  	
  	if (request.readyState==4 && request.status==200){
    	if (request.responseText){
      	callbackFunction(request.responseText);
     	}
   	}
  };
  request.send("");
  return true;
}
*/

//UPLOAD
function ch(){
	var a={
		"lang":"Enter language name",
		"file":"Select language file",
		"name[]":"Enter your name"
	};
	var b="";
	for (var c in a){
		if (document.getElementsByName(c)[0].value.length<2){
			if (b!="")
				b+="\n";
			b+=a[c];
		}
	}
	if (b!=""){
		alert(b);
		return;
	}
	document.abc.submit();
}

//DOWNLOAD, UPLOAD
function c(a){
	v=document.getElementsByName("ver")[0];
	v.options.length=0;
	y=o[a];
	try{
		for (var i=0;i<y.length;i++){
			v.options[i]=new Option("v"+y[i],y[i]);
		}
	}catch (E){
	}
	rel();
}
	
//DOWNLOAD
function t(){
	q=false;
}
	
function download(){
	app_name={
		"bt_discover":{"1.20":"BT_DISCOVER_2.jar"},
		"ftp_bt":{"1.08":"ftp_bt_108.jar"},
		"img_ftp":{"1.00":"img_ftp.jar","1.10":"img_ftp_110.jar"},
		"miesta":{"1.00":"miesto.jar"},
		"minesweeper":{"1.00":"miny.jar","1.10":"miny_110.jar"},
		"m_video":{"1.00":"mvideo.jar","1.10":"mvideo_1.jar"},
		"real_jack":{"1.01":"REAL_JACK_1.jar"},
		"rozvrh_2":{"1.00":"rozvrh_2.jar"}
	};
			
	l="";
	ch=document.getElementsByName("check_l[]");
	for (i=0;i<ch.length;i++){
		if (ch[i].checked){
			l+=ch[i].value+",";
		}
	}
	if (l==""){
		alert("Select languages first");
		return;
	}
	file_name="";
	file_name=app_name[document.getElementsByName("app")[0].value][document.getElementsByName("ver")[0].value];
	if (file_name=="")
		return;
	l=l.substring(0,l.length-1);
	document.location="http://java.xor.sk/down.php?wtf="+file_name+"&lang="+l;
}
	
function s(i){
	if (q){
		a=document.getElementsByName("check_l[]")[i];
		a.checked=!a.checked;
	}
	q=true;
}
/*
function r_ok(a){
	document.getElementById("down").innerHTML=a;
}
*/
	
function rel(){
	/*
	r_ok("");
	req("all.php?x="+document.getElementsByName("app")[0].value+"&y="+document.getElementsByName("ver")[0].value,r_ok);
	*/
}