function checkBrowse() {
	var table 			= document.getElementById("uploadManager").tBodies[0];
	var addNewUpload = true;
	var inputs = table.getElementsByTagName("input");
	
	var checkBox  = document.getElementById("defaultImageName");
	
	var arr = new Array();
	var length;
	
	var titleImages = new Array();
	
	for(var i=0; i<inputs.length; i++) {
		if (inputs[i].name=='imagesFile[]' && inputs[i].type=='file' && inputs[i].style.display=='') {
			if (inputs[i].value=='') {
				addNewUpload = false;
			} else {
				if (checkBox.checked) {
					//windows slash "\\"
					if (inputs[i].value.indexOf("\\")!=-1) {
						arr = inputs[i].value.split("\\");
						length = arr.length -1;
						titleImages[i] = arr[length];
						continue;
						//titleImages.push(arr[length]);
					}
					//linux slash "/"
					if (inputs[i].value.indexOf("/")!=-1) {
						arr = inputs[i].value.split("/");
						length = arr.length -1;
						titleImages[i] = arr[length];
						continue;
					}
					//titleImages.push(inputs[i].value);
					titleImages[i] = inputs[i].value;
				}
			}
		}
	}
	addTitle(titleImages);
	//if all browse fields not empty, add new upload image
	if (addNewUpload) {
		addUploadImage();
	}
}

function addTitle(titleImages) {
	var table  = document.getElementById("uploadManager").tBodies[0];
	var inputs = table.getElementsByTagName("input");
	var index;
	for(var i=0; i<inputs.length; i++) {
		if (inputs[i].name=='imagesTitle[]' && inputs[i].type=='text' && inputs[i].style.display=='') {
			index = i-1;
			if (typeof titleImages[index] != "undefined") {
				inputs[i].value = titleImages[index];
			}
		}
	}
}

function addUploadImage() {
	var table 			= document.getElementById("uploadManager").tBodies[0];
	var defaultTR 		= document.getElementById("defaultUploadImage");
	var newUploadImage 	= defaultTR.cloneNode(true);
	newUploadImage.id 	= '';
	newUploadImage.style.display = '';
	var inputs = newUploadImage.getElementsByTagName('input');
	inputs[0].style.display = '';
	table.appendChild(newUploadImage);
}

function uploadImages() {
	var table = document.getElementById("uploadManager").tBodies[0];
	var inputs = table.getElementsByTagName("input");
	var uploadImages = false;
	for(var i=0; i<inputs.length; i++) {
		if (inputs[i].name=='imagesFile[]' && inputs[i].type=='file' && inputs[i].style.display=='') {
			if (inputs[i].value!='') {
				uploadImages = true;
			}
		}
	}
	if (!uploadImages) {
		alert(SbGetLocaleByKey('IMAGES-UPLOAD-EMPTY'));
		return false;
	}
	var action	= document.getElementById('viewAction');
	var form 	= document.forms['SB_WizardForm'];
	form.action = action.value+'/Modules/ImageGallery/Image/Upload';

	top.sbApplyChangesObject.registerForcedSaving(); 
	sbNavigationObject.go();
}