function valClicked(id, lang){
    name = 'value_'+id+'_'+lang;
	elem = $('#'+name);
	text = elem.html();
	elem.unbind('onclick');
	elem.attr('onclick', '');
	eid = name;
	name = 'value['+id+']['+lang+']';
	sizeCols = 25;
	sizeRows = 4;
	sizeCols = Math.round(Math.sqrt(text.length))*4;
	sizeRows = Math.round(text.length/sizeCols);
	if (sizeRows==1){
		sizeRows=2;
	}else{
		sizeRows = sizeRows+2;
	}
	html = '<textarea cols="'+sizeCols+'" rows="'+sizeRows+'" id="f'+eid+'" name="'+name+'"></textarea>';
	elem.html(html);
	text = htmlspecialchars(text);
	$('#f'+eid).html(text);

   changed['f'+eid]= 'X';
}

function htmlspecialchars(str) {
    if(typeof str=="undefined") str="";
    var from=new Array(/&/g,/</g,/>/g);
    var to=new Array("&amp;","&lt;","&gt;");
    from.push(/'/g); to.push("&#039;");
    from.push(/"/g); to.push("&quot;");
    for(var i in from) str=str.replace(from[i],to[i]);
    return str;
}

var selType, selId;
var changed = new Array();

function blobWin(link, title){
  window.open(link, title, "menubar=no,width=950px,height=650px,toolbar=no, resizable=yes, scrollbars=yes, top=100px, left=100px ");
  return false;
}

function changePref(){
  form = document.getElementById('pref_form');
  form.submit();
}


function submitAllChanged(){
  form = document.getElementById("changedForm");
    for (x in changed){
      elem = document.getElementById(x);
      if(!isDefined(elem)){
        alert ('Not found '+x);
      }
      elem.parentNode.removeChild(elem);
      form.appendChild(elem);
    }
    form.submit();

}

function dropRes(rid, bid){
	if (confirm('Delete bundle resource?')){
		$.ajax({
			 type: "GET",
			 url: "/os/i18n/bundle-dropBRes/"+rid+"/"+bid,
			 success: function(msg){
				 document.location='/os/i18n/bundle-edit/'+bid;
		 	 }
		 });
	}
}

function isDefined(variable){
    if (variable == null) return false;
    return (typeof(variable) == "undefined")?  false: true;
}

function sureDialog(){
  return confirm("Think twice. Are you sure?")
}

function reviewResource(url){
  if (confirm('Sure you want to remove this translation?')){
     document.location = url;
  }
  return false;
}

function renameProp(id){
	img = $("img#pimg"+id);
	img.attr('border');
	value = $("input#pname"+id).val();
	$.ajax({
	 type: "POST",
	 url: "/os/i18n/Bundle-renameProp",
	 data: "id="+id+"&name="+value,
	 error: function(req, mess, exc){
		 alert(mess);
		 img = $("img#pimg"+id);
		 img.attr("class", "error")

	 },
	 success: function(msg){
		 img = $("img#pimg"+id);
		 if (msg !=''){
				alert(msg);
				img.attr("class", "error")
			}else{
				img.removeAttr("class");
				img.fadeOut("slow");
			}
	 }
 });

}

function enableIcon(id){
    img = $("img#pimg"+id);
    img.fadeIn("slow");
}