window.addEvent('domready', function(e){
	$$('a.editCateg').each(function(element){
		element.removeEvents('click');
		element.addEvent("click",function(e){
			editCateg(element, e);
		}.bindWithEvent(this));
	});
});

function editCateg( element, e ){
	bmid = element.getAttribute('bmid');
	new Event(e).stop();
	var url = '/bookmarks/edit.php?bmid=' + bmid + '&editable';
	var jSonRe = new Json.Remote(url, {
		onComplete: function(req){
			if(req.isEditable != 'false'){
				new newModal({
					title:"Edit Category",
					width: 425,
					contentURL:'/bookmarks/edit.php?bmid=' + bmid,
					method:'get',
					evalScripts:true,
					onContentLoaded:function(sHtml){
						$('submitForm').addEvent('submit', function(e){
							e = new Event(e).stop();
							url = '/bookmarks/edit.php?' + $('submitForm').toQueryString();
							var jSonRequest = new Json.Remote(url, {onComplete: function(req){
								if(req.status=="yes"){
									$('boxUrl').setStyles({'display':'none'});
									$('goUrl').innerHTML='';
									var a = new Element('a').injectInside($('goUrl'));
									a.appendText(req.formatPath);
									this.autoClose(5);
									this.windowAdjust();
								}else if(req.error=='ok'){
									errors = "";
									req.status.arr.each(function(sError){
										errors+= "<img src='/img/error.gif' class='imgError'>"+sError+'<br>';
									});
									$('errorEditLink').setHTML(errors);
									this.windowAdjust();
								}
							}.bind(this)}).send();
						}.bind(this));
					}
				});
			}else{ 
				if(req.msg){
					 ShowAlert(req.msg,"error");
				}else{
					ShowAlert("You can not edit this item.","error");
				}
			}
		}
	}).send();
}