
function AddLocationToLightboxFolder(location_id, lightboxfolder_id, category_id){
	
	//would like to change the colour of locations added
	
	
	
	if (PerformLocationSelectorAction(location_id, lightboxfolder_id, category_id, 'add', false)){
		//alert('all good');
		document.getElementById('imagesinfolder_' + location_id).innerHTML = document.getElementById('imagestotal_' + location_id).innerHTML;
		document.getElementById('imageblock_' + location_id).style.borderColor = 'red';
		document.getElementById('checkout').value = "<a href=login.php>Checkout</a>";
	} else {
		//alert('dammit');
	}
}

function RemoveLocationFromLightboxFolder(location_id, lightboxfolder_id, category_id){
	PerformLocationSelectorAction(location_id, lightboxfolder_id, category_id, 'remove', true);
	document.getElementById('imagesinfolder_' + location_id).innerHTML = '0';
	document.getElementById('imageblock_' + location_id).style.borderColor = '#8B9DAE';
}

function PerformLocationSelectorAction(location_id, lightboxfolder_id, category_id, action, asynchronous){

	// Start up the XMLHttpRequest object.

	if (window.XMLHttpRequest) {
		var req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		var isIE = true;
		var req = new ActiveXObject("Microsoft.XMLHTTP");
	}

	req.open('POST','lightbox_edit_locationselector_action.php',asynchronous);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	
	poststring = 'action=' + action;
	poststring = poststring + '&lightboxfolder_id=' + lightboxfolder_id;
	poststring = poststring + '&location_id=' + location_id;
	poststring = poststring + '&category_id=' + category_id;
	
	req.send(poststring);
	
	if (! asynchronous){

		if (req.status != 200){
	
			// alert('not 200 = ' + req.responseText);
			return false;
	
		} else {
	
			// alert('200 = ' + req.responseText);
			return true;
		}	

	}

}

function CheckAllCheckboxesInDiv(divid){

	var element = document.getElementById(divid);
	var ImageCheckboxArray = element.getElementsByTagName('input');

	// Turn the checkboxes on if they are off.

	for(var i = 0, arrLen = ImageCheckboxArray.length; i < arrLen; i++){
		if ( ImageCheckboxArray[i].type == 'checkbox' && ! ImageCheckboxArray[i].checked){
			ImageCheckboxArray[i].checked = true;
		}
	}

}

function UncheckAllCheckboxesInDiv(divid){

	var element = document.getElementById(divid);
	var ImageCheckboxArray = element.getElementsByTagName('input');

	// Turn the checkboxes on if they are off.

	for(var i = 0, arrLen = ImageCheckboxArray.length; i < arrLen; i++){
		if ( ImageCheckboxArray[i].type == 'checkbox' && ImageCheckboxArray[i].checked){
			ImageCheckboxArray[i].checked = false;
		}
	}

}

function changeCategory(URL) {
	selectList = document.getElementById('changeCategoryList');
	document.location = URL+'&CATEGORY_id='+selectList.value;
}
