function binder(url,trg,shw){
	hide('winbase');
	var job = new Object();
	
	if (url.indexOf('?')>0){
		url=url+'&';
	}else{
		url=url+'?';
	}
	
	url=url+'MLid='+getVal('ML_id')+'&BEVid='+getVal('BEV_id');
	
	if (shw==null){
		job.func=function(){
			jx.bind({ 'url':url,'update':trg,'onSuccess':function() {document.getElementById('menu').className='off';} });
		}
	}else{
		job.func=function(){
			jx.bind({ 'url':url,'update':trg,'onSuccess':function() {document.getElementById('menu').className='off';show(shw)} });
		}
	}
	
	if (trg!='win'){
		if (document.getElementById('ML_id')!=null){
			if (confirm('Mentsem a munkalap változásait?')){
				clone(jx).bind({
					'url':'src/worker/save_ml.php?MLid='+getVal('ML_id'),
					'update':'worker',
					'onSuccess': function() {
						job.func();
					}
				});
			}else{
				job.func();
			}
		}else{
			job.func();
		}
	}else{
		job.func();
	}
}

function clone(myObj){
	if(typeof(myObj) != 'object') return myObj;
	if(myObj == null) return myObj;
	var myNewObj = new Object();
	for(var i in myObj) myNewObj[i] = clone(myObj[i]);
	return myNewObj;
}

function encode_utf8(s){
  return unescape(encodeURIComponent(s));
}

function decode_utf8(s){
	//news=escape(s);
	alert (s);
	news=decodeURIComponent(s);
	alert (news);
	return news;
}

//V3.01.A - http://www.openjs.com/scripts/jx/
jx = {
	//Create a xmlHttpRequest object - this is the constructor. 
	getHTTPObject : function() {
		var http = false;
		//Use IE's ActiveX items to load the file.
		if(typeof ActiveXObject != 'undefined') {
			try {http = new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e) {
				try {http = new ActiveXObject("Microsoft.XMLHTTP");}
				catch (E) {http = false;}
			}
		//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
		} else if (window.XMLHttpRequest) {
			try {http = new XMLHttpRequest();}
			catch (e) {http = false;}
		}
		return http;
	},
	
	// This function is called from the user's script. 
	//Arguments - 
	//	url	- The url of the serverside script that is to be called. Append all the arguments to 
	//			this url - eg. 'get_data.php?id=5&car=benz'
	//	callback - Function that must be called once the data is ready.
	//	format - The return type for this function. Could be 'xml','json' or 'text'. If it is json, 
	//			the string will be 'eval'ed before returning it. Default:'text'
	//	method - GET or POST. Default 'GET'
	
	load : function (url,callback,format,method, opt) {
		var http = this.init(); //The XMLHttpRequest object is recreated at every call - to defeat Cache problem in IE
		if(!http||!url) return;
		//XML Format need this for some Mozilla Browsers
		if (http.overrideMimeType) http.overrideMimeType('text/xml');

		if(!method) method = "GET";//Default method is GET
		if(!format) format = "text";//Default return type is 'text'
		if(!opt) opt = {};
		format = format.toLowerCase();
		method = method.toUpperCase();
		
		//Kill the Cache problem in IE.
		var now = "uid=" + new Date().getTime();
		url += (url.indexOf("?")+1) ? "&" : "?";
		url += now;

		var parameters = null;

		/*if(method=="POST") {
			actform=document.getElementById(opt.formname);
			var parts = url.split("\?");
			url = parts[0];
			//parameters = parts[1];
			if (opt.formname) {
				var parameters='';
				for (i=0; i<actform.length; i++) {
					//alert (document[opt.formname][i].value);
					if (actform[i].name != ''){
						if (parameters!='') { parameters+="&"; }
						parameters = parameters +actform[i].name+"="+encodeURI(actform[i].value);
					}	
				}
				//alert (temp);
			}
			//alert (parameters);
		}*/
		if(method=="POST") {
			//var parts = url.split("\?");
			//url = parts[0];
			parameters=opt.parameters;
			
		}
		http.open(method, url, true);

		if(method=="POST") {
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-type", "text/xml; charset=iso-8859-2");
			http.setRequestHeader("Content-length", parameters.length);
			http.setRequestHeader("Connection", "close");
		}

		var ths = this;// Closure
		if(opt.handler) { //If a custom handler is defined, use it
			http.onreadystatechange = function() { opt.handler(http); };
		} else {
			http.onreadystatechange = function () {//Call a function when the state changes.
				if (http.readyState == 4) {//Ready State will be 4 when the document is loaded.
					if(http.status == 200) {
						var result = "";
						if(http.responseText) result = http.responseText;
						//alert (result);
						//If the return is in JSON format, eval the result before returning it.
						if(format.charAt(0) == "j") {
							//\n's in JSON string, when evaluated will create errors in IE
							result = result.replace(/[\n\r]/g,"");
							result = eval('('+result+')');

						} else if(format.charAt(0) == "x") { //XML Return
							result = http.responseXML;
							//alert (result);
						}

						//Give the data to the callback function.
						if(callback) callback(result);
					} else {
						if(opt.loadingIndicator) document.getElementsByTagName("body")[0].removeChild(opt.loadingIndicator); //Remove the loading indicator
						if(opt.loading) document.getElementById(opt.loading).style.display="none"; //Hide the given loading indicator.
						
						if(error) error(http.status);
					}
				}
			}
		}
		http.send(parameters);
	},
	bind : function(user_options) {
		var opt = {
			'url':'', 			//URL to be loaded
			'onSuccess':false,	//Function that should be called at success
			'onError':function(){alert('Hiba történt a letöltéskor!')},	//Function that should be called at error
			'format':"text",	//Return type - could be 'xml','json' or 'text'
			'method':"GET",		//GET or POST
			'formname':"form",	//default formname to retrieve data from
			'update':"",		//The id of the element where the resulting data should be shown. 
			'loading':"loading_holder",		//The id of the loading indicator. This will be set to display:block when the url is loading and to display:none when the data has finished loading.
			//'loadingIndicator':"...", //HTML that would be inserted into the document once the url starts loading and removed when the data has finished loading. This will be inserted into a div with class name 'loading-indicator' and will be placed at 'top:0px;left:0px;'
			'loadingIndicator':"<img src='img/loading.gif' />", //HTML that would be inserted into the document once the url starts loading and removed when the data has finished loading. This will be inserted into a div with class name 'loading-indicator' and will be placed at 'top:0px;left:0px;'
			'parameters':''		//for the POST
		}
		for(var key in opt) { 
			if(user_options[key]) {//If the user given options contain any valid option, ...
				opt[key] = user_options[key];// ..that option will be put in the opt array.
			}
		}
		
		//alert (opt.url);
		
		if(!opt.url) return; //Return if a url is not provided
		
		if(opt.method=="POST") {
			actform=document.getElementById(opt.formname);
			//parameters = parts[1];
			if (opt.formname) {
				opt.parameters='';
				for (i=0; i<actform.length; i++) {
					//alert (document[opt.formname][i].value);
					if (actform[i].id != ''){
						if (actform[i].type=='radio' && actform[i].checked==''){
							//
						}else{
							if (opt.parameters!='') { opt.parameters+="&"; }
							opt.parameters = opt.parameters +actform[i].id+"="+encodeURI(actform[i].value);
						}
					}
				}
			}
		}

		var div = false;
		if(opt.loadingIndicator) { //Show a loading indicator from the given HTML
			//div = opt.update //document.createElement("div");
			//div.setAttribute("style","position:absolute;top:0px;left:0px;");
			//div.setAttribute("class","loading-indicator");
			//div.innerHTML = opt.loadingIndicator;
			document.getElementById(opt.update).innerHTML = opt.loadingIndicator;
			//document.getElementsByTagName("body")[0].appendChild(div);
			//this.opt.loadingIndicator=div;
		}
		if(opt.loading) document.getElementById(opt.loading).style.display="block"; //Show the given loading indicator.
		
		this.load(opt.url,function(data){
			if(opt.update) document.getElementById(opt.update).innerHTML = data;
			
			//if(div) document.getElementsByTagName("body")[0].removeChild(div); //Remove the loading indicator
			if(opt.loading) document.getElementById(opt.loading).style.display="none"; //Hide the given loading indicator.
			if(opt.onSuccess) opt.onSuccess(data);
		},opt.format,opt.method, opt);
	},
	init : function() {return this.getHTTPObject();}
}
