/* add image to js array */
jsImageArray = Array();

	function addImageToArray(img) {
	jsImageArray.push(img);
	}




/* tests form fields to gather images */
	function tester() {
	
	i = 0;
	
		while(document.getElementById("foo" + i) != undefined) {

			if(document.getElementById("foo" + i) != undefined) {
			/*alert("foo" + i + " is defined");
			alert(document.getElementById("foo"+i).value);*/
			addImageToArray(document.getElementById("foo" + i).value)
			} else {
			alert("foo" + i + " not");	
			}
		i++;
		}
	ajaxed();
	}
	
j = 0;	
	
	
	
	function ajaxed() {
	
		$.ajax({
		   type: "POST",
		   url: "inc.gallery.ajax.php",
		   data: "name="+jsImageArray[j],
		   success: function(html){
			 $("#imgjscontainer"+j).append(html);
			 
			 if(j < jsImageArray.length - 1) {
			 j++;
			  ajaxed();
			 }
			
		   }
		 });
		 
	}












function checkArchive(fileInput) {

	// check the extension of the chosen file, if it is a zip file
	// we want to disable the caption and description fields because

	var filePath = fileInput.value;
	var fileParts = new Array();
	var zipAlert = document.getElementById('zip-alert');

	fileParts = filePath.split('.');
	var fileExtension = fileParts[fileParts.length-1];

	if (fileExtension.toLowerCase() == 'zip') {
		document.getElementById('caption').value = '';
		document.getElementById('description').value = '';
		document.getElementById('caption').disabled = true;
		document.getElementById('description').disabled = true;
		document.getElementById('caption').style.background = "#999999";
		document.getElementById('description').style.background = "#999999";
		if (zipAlert != null) {
			zipAlert.style.display = '';
		}
	} else {
		document.getElementById('caption').disabled = false;
		document.getElementById('description').disabled = false;
		document.getElementById('caption').style.background = "#eeeeee";
		document.getElementById('description').style.background = "#eeeeee";
		if (zipAlert != null) {
			zipAlert.style.display = 'none';
		}
	}

}







	function deleteConfirmation(messiah, cat){ 
	
	var warningMessage = "";
	
		if(cat == "section") {
		var warningMessage = "WARNING: Deleting this or these sections will also permanently remove all the relative galleries and images. If confirmed, this operation will be immediate and will not be undoable.\n\nAre you sure you really want to proceed?";
		} else if(cat == "gallery") {
		var warningMessage = "WARNING: Deleting this or these galleries will also permanently remove all the relative images. If confirmed, this operation will be immediate and will not be undoable.\n\nAre you sure you really want to proceed?";
		} else if(cat == "image") {
		var warningMessage = "WARNING: Deleting this or these images will be permanent. If confirmed, this operation will be immediate and will not be undoable.\n\nAre you sure you really want to proceed?";
		}
		
	
	
		if(messiah != 0) {
			if (confirm(warningMessage)){ 
			document.galleryform.deleteId.value = messiah;
			document.galleryform.submit();
			}
		} else {
			if (confirm(warningMessage)){ 
			document.galleryform.deleteId.value = "checkbox";
			document.galleryform.submit();
			}
		} 
	}
	
	
	
	
	function moveMe(movefrom, moveto, cat) {
		
		if (confirm("Move "+cat+" from "+movefrom+" -> "+moveto+" ?")){ 
		document.galleryform.movefrom.value = movefrom;
		document.galleryform.moveto.value = moveto;
		document.galleryform.movecategory.value = cat;
		document.galleryform.submit();
		}
	}
	
	
	
	
	function toggleDisplay(id, id2, txtarea, txtareareset) {

	var idList = Array(id, id2);
	
		for(i=0; i<2; i++) {
		
		var state = document.getElementById(idList[i]).style.display;
		
			if (state == 'block') {
			document.getElementById(idList[i]).style.display = 'none';
			} else {
			document.getElementById(idList[i]).style.display = 'block';
			}
			
			if(txtareareset !== undefined)
			document.galleryform[txtarea].value = document.galleryform[txtareareset].value;
			
		}
	}
	
	
	
	
	function editField(type, field, id) {
	
		if(type == "gallery") {
			if(field == "name") { 
			document.galleryform.galleryrename.value = document.galleryform["name" + id].value;
			document.galleryform.fieldname.value = "galleryrename";
			} else if(field == "about") {
			document.galleryform.gallerynewdescr.value = document.galleryform["description" + id].value;
			document.galleryform.fieldname.value = "gallerynewdescr";
			}
		
		} else if(type == "image") {
			if(field == "name") { 
			document.galleryform.imagerename.value = document.galleryform["name" + id].value;
			document.galleryform.fieldname.value = "imagerename";
			} else if(field == "about") {
			document.galleryform.imagenewdescr.value = document.galleryform["description" + id].value;
			document.galleryform.fieldname.value = "imagenewdescr";
			}
		
		}
	
	document.galleryform.editID.value = id;
	document.galleryform.submit();
	
	}

