// JavaScript Document


function toggleDeleteWarning (cmd) {
	var tmpObj;
	if (tmpObj = document.getElementById('info_box')) tmpObj.style.display = cmd == "on" ? 'none' : 'block';
	if (tmpObj = document.getElementById('delete_box')) tmpObj.style.display = cmd == "on" ? 'block' : 'none'; 		
}

function cycleFilez (action, form_obj) {
	var tmpObj;
	for (var i=0; i<form_obj.elements.length; i++) {
		tmpObj =  form_obj.elements[i];
		if (tmpObj.type == 'checkbox' && tmpObj.name.indexOf('m_filez[]') == 0) {
			
			switch (action) {
				case 'check':
				tmpObj.checked = true;
				break;
				
				case 'uncheck':
				tmpObj.checked = false;
				break;
			
				case 'validate':
				if (tmpObj.checked) return true;
				break;
			
			}
			
		}
	}
	
	if (action == 'validate') {
		return false;
	}

}

function handleForm (action, form_obj) {
	
	switch (action) {
	
		case "move":
		if (!cycleFilez ('validate', form_obj)) {
			alert('Please, select files to move');
			return false;
		}
		form_obj.action = 'images_move.php?album=' + album_id;
		break;
		
		case "delete":
		if (!cycleFilez ('validate', form_obj)) {
			alert('Please, select files to delete');
			return false;
		}
		if (!confirm('Are you sure you want to delete these files?')) return false;
		form_obj.action = 'delete.php?album=' + album_id;
		break;
		
	}
	
	form_obj.submit();
} 


function checkUncheck (checkbox_obj,rt) {
	var action = checkbox_obj.checked ? 'check' : 'uncheck';
	cycleFilez (action, checkbox_obj.form)
}


function validateMove (formObj) {
	if (typeof(formObj.target_album.length) == 'undefined') {
		if (formObj.target_album.checked) return true;  
	} else {
		for (var i=0; i < formObj.target_album.length; i++) {
			
			if (formObj.target_album[i].checked) return true;  
		}
	}
	alert('Please select destination');
	return false;
}

function showHideThumb (id, cmd) {
	var tmpObj;
	if (tmpObj = document.getElementById(id)) tmpObj.style.display = cmd =='show' ? 'block' : 'none';
}