// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Checkbox
// ==================================
function checkboxIDs(form, div, path, total, url_params, message, select){
	
	var cids = "";
	var checkbox = "";
	var count = "";
	
	for(i=0;i<total;i++){
		var checkbox = form["cb"+i]
		if(checkbox.checked == true){
			cids += checkbox.value + ",";
			count++;
		}
	}
	cids = cids.substring(0,cids.length-1);
	
	
	switch(select)
	{
	case '0':
		break;
	case '1':
		/* DELETE */
		if(count > 0){
			if(confirm(message)){
				/* confirm! */	
				new Ajax.Updater(div, path, {method:'post', postBody:'select='+select+'&cids='+cids+url_params});
			}
		}
		else { 
			/* no checkboxes selected? */
			alert('Selecteer eerst de vakjes');
		}
		break;
	default:
		if(count > 0){
			new Ajax.Updater(div, path, {method:'post', postBody:'select='+select+'&cids='+cids+url_params});
		}
		else {
			/* no checkboxes selected? */
			alert('Selecteer eerst de vakjes');
		}
	}
}


function turnCheckbox(form, total, value) {
	for(i=0;i<total;i++) {
		form["cb"+i].checked = value;
	}
}

// ArrowSwitch
// ==================================
function openArrow(element){
	$(element).style.background='url(/images/admin/icons/arrow.png) no-repeat left';
}

function closeArrow(element){
	$(element).style.background='url(/images/admin/icons/arrow.png) no-repeat right';
}

function arrowIcon(element_id, switch_id){
	Element.visible(element_id) ? closeArrow(switch_id) : openArrow(switch_id);
}

// ArrowSwitch 2
// ==================================
function openArrow2(element){
	$(element).style.background='url(/images/admin/icons/arrow2.png) no-repeat left';
}

function closeArrow2(element){
	$(element).style.background='url(/images/admin/icons/arrow2.png) no-repeat right';
}

function arrowIcon2(element_id, switch_id){
	Element.visible(element_id) ? openArrow2(switch_id) : closeArrow2(switch_id);
}

// Labels: create & update
// ==================================
function createLabel(path, message)
{
	var name = prompt (message, '');
	if (!name.match(/^ /)) {
		new Ajax.Updater('secondContent', path, {method:'post', postBody:name});
	}
}

function updateLabel(id, path, message)
{
	var name = prompt (message, '');
	if (!name.match(/^ /)) {	
		new Ajax.Updater('secondContent', path+"/"+id, {method:'post', postBody:name});
	}
}
