// JavaScript Document
Ajax.Responders.register({
  onCreate: function() {
    document.body.style.cursor = 'wait';
  },
  onComplete: function() {
    document.body.style.cursor = 'default';
  }
});

/* generic function for stepping through any element group which can be defined by a CSS rule */
function protostep(css, id) {
	$$(css).each( function(el) {
		el.hide();
	});
	$(id).show();
	return false;
}

function switchSiblingClass(css, classNamed, el) {
	$$(css).each( function(sibling) {
		sibling.removeClassName(classNamed);
	});
	$(el).addClassName(classNamed);
	return true;
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height) {
	if (popUpWin) {
		if (!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function sortCategories () {
	new Ajax.Request ('/manager/modal/.category-sort.php', {
		method : 'post',
		parameters : Sortable.serialize('categoryMenu'),
		onSuccess : disableSorting,
		onFailure: function (r) { alert ('Server-side failure. Please try again.'); },
		onException: function (r) { alert ('Client-side failure. Please try again.'); },
		on404: function (r) { alert ('Page not found. Report to webmaster.'); }
	});
}

function enableSorting () {
	new Ajax.Updater ('categoryMenu', '/manager/modal/.category-html.inc.php?sortable=true', {
		onComplete: function() {
			Sortable.create('categoryMenu', { onUpdate: sortCategories });
		}
	});
}

function disableSorting () {
	new Ajax.Updater ('categoryMenu', '/manager/modal/.category-html.inc.php');
}

function toggleChildren (catId) {
	/*if (Element.visible('children['+catId+']')) {
		var toggleImageSrc = '/images/store/expand.gif';
	} else {
		var toggleImageSrc = '/images/store/collapse.gif';
	}
	$('toggleImage['+catId+']').src = toggleImageSrc;*/
	Element.toggle('children['+catId+']');
}

