//function ajaxObject is required
function update_info(funct, user_id, root, val1, val2, box_id){
	if(val1.indexOf('id:')!==-1){
		id1 = val1.replace('id:',''); 
		val1 = document.getElementById(id1).value;
	}
	if(val2.indexOf('id:')!==-1){
		id2 = val2.replace('id:','');			
		val2 = document.getElementById(id2).value;		
	}
	field = document.getElementById(box_id);
	loading_div = document.getElementById('loading_form'); // REQUIRED TAG
	button = document.getElementById('update_submit'); // REQUIRED TAG
	
	loading_div.style.display = 'block';
	button.style.display = 'none';

	var url = root+"/inc/update.php";
	val1=urlencode(encode_utf8(val1));
	val2=urlencode(encode_utf8(val2)); //alert(val2);
	var args = "function="+funct+"&user_id="+user_id+"&val1="+val1+"&val2="+val2;	
	
    var upObj = new ajaxObject('update_result', url);
    upObj.callback = function() { 
		rs = check_update_status();
		if(field){ 
			
			if(rs==0){ alert('Atnaujinimų nerasta'); 
				loading_div.style.display = 'none';
				button.style.display = 'block';
				}
			else if(rs==1){
				//field.style.visibility="visible";
				field.innerHTML = "Sėkmingai išsaugota";							
				//alert('Veikia:' + rs);
				//hide(box_id);
				close_msg(box_id);
				//var date = new Date();
				//setCookie('last_update-'+funct, date.getTime(), 1); 
			}else{ alert("Klaida: "+rs); }
		  }
	}
	
	upObj.update(args);
}
function check_update_status(){
		var info = document.getElementById('update_result');
		data = info.innerHTML; //alert(data);
		return data;
}
function update_info_old(funct, user_id, root, val1, val2, box_id){
		if(val1.indexOf('id:')!==-1){
			id1 = val1.replace('id:',''); 
			val1 = document.getElementById(id1).value;
		}
		if(val2.indexOf('id:')!==-1){
			id2 = val2.replace('id:','');			
			val2 = document.getElementById(id2).value;		
		}
		field = document.getElementById(box_id);
		loading = document.getElementById('loading_form'); // REQUIRED TAG
		button = document.getElementById('update_submit'); // REQUIRED TAG
		
		loading.style.display = 'block';
		button.style.display = 'none';
		
		var xmlhttp;  
		if (window.XMLHttpRequest)
		  {
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {
		  // code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
				{ //alert('Status: '+xmlhttp.status+' '+xmlhttp.responseText);
				if(xmlhttp.readyState==4)
				  {	
				  if(xmlhttp.status == 200){
					 // alert('test'+comments_containers);
					  
					  if(field){  
						if(xmlhttp.responseText==0){ alert('Atnaujinimų nerasta'); 
							loading.style.display = 'none';
							button.style.display = 'block';
							}
						else if(xmlhttp.responseText==1){
							//field.style.visibility="visible";
							field.innerHTML = "Sėkmingai išsaugota";							
							//alert('Veikia:' + xmlhttp.responseText);
							//hide(box_id);
							close_msg(box_id);
							var date = new Date();
							setCookie('last_update-'+funct, date.getTime(), 1); 
						}else{ alert("Klaida: "+xmlhttp.responseText); }
					  }
				 }else{
					 button.style.display = 'block';
				 	 alert('Klaida. Bandykite dar kartą'); }
				  
				  }
				}	
		var url = root+"/inc/update.php";
		val1=urlencode(encode_utf8(val1));
		val2=urlencode(encode_utf8(val2)); //alert(val2);
		url = url + "?function="+funct+"&user_id="+user_id+"&val1="+val1+"&val2="+val2;
		
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	
			
}	
function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}
function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}
function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}

function urldecode(str) {
str = str.replace('+', ' ');
str = unescape(str);
return str;
}

