/* ************************************************************************************************* */
/* Contains functions for upload modules
/* ************************************************************************************************* */

/* ************************************************************************************************* */
/* Function to check for correct fileextensions
/* ************************************************************************************************* */
function checkFileUpload(form,extensions) {
	document.ReturnValue = true;
	if (extensions && extensions != '') {
		for (var i = 0; i<form.elements.length; i++) {
			field = form.elements[i];

			if (field.type.toUpperCase() != 'FILE') continue;
			
			//If there aren't selected a file 
			if (field.value == '') {
				alert('File is required!');
				document.ReturnValue = false;field.focus();break;
			}
			
			//If the file type is not the right type
			if (extensions.toUpperCase().indexOf(getFileExtension(field.value).toUpperCase()) == -1) {
				alert('This file is not allowed for uploading!');
				document.ReturnValue = false;field.focus();break;
			} 
			
			//If the combobox i emty
			if((document.forms['imageform'].cbbalbum.value == "") && (document.forms['imageform'].rbalbum[1].checked == true)){
				alert('Please select a album or make a new one!');
				document.ReturnValue = false;document.forms['imageform'].cbbalbum.focus();break;
			}
			
			//If the new album textfield is emty
			if((document.forms['imageform'].txtalbum.value == "") && (document.forms['imageform'].rbalbum[0].checked == true)){
				alert('Please select a album or make a new one!');
				document.ReturnValue = false;document.forms['imageform'].txtalbum.focus();break;
			}
			
			/*
			re = new RegExp("[a-z0-9]- ");
			if(re.test(document.forms['imageform'].txtalbum.value) && (document.forms['imageform'].txtalbum.value != "") && (document.forms['imageform'].rbalbum[0].checked == true)) {
				//alert('only characters a-z 0-9 and - is allowed!');
				//document.ReturnValue = false;document.forms['imageform'].txtalbum.focus();break;
			}else{
				alert('only characters a-z 0-9 and - is allowed!');
				document.ReturnValue = false;document.forms['imageform'].txtalbum.focus();break;				
			}
			*/

		} 
	}	
}

/* ************************************************************************************************* */
/* Function to make sure that it's only possible to either make a new album, or to use an existing one
/* ************************************************************************************************* */
function checkalbums() {

	if((document.forms['imageform'].rbalbum[0].checked == true)){
		document.forms['imageform'].cbbalbum.disabled = true;
	}else{
		document.forms['imageform'].cbbalbum.disabled = false;
	}
	
	if((document.forms['imageform'].rbalbum[1].checked == true)){
		document.forms['imageform'].txtalbum.disabled = true;
		document.forms['imageform'].txtalbum.value = "";
	}else{
		document.forms['imageform'].txtalbum.disabled = false;
	}	
        
}
