var uploadImageID;

function FileUpload(form){
	ShowProgress();
	
	form.action = 'includes/form/upload/upload.asp';
	form.uploadbutton.disabled = true;
	form.submit();
}

function ShowProgress(){
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	var objBody = document.getElementsByTagName("body").item(0);
	var objProgressImage = document.createElement("img");

	objProgressImage.src = 'includes/form/upload/progressbar.gif';
	objProgressImage.setAttribute('id','progress');
	objProgressImage.style.position = 'absolute';
	objProgressImage.style.display = 'block';
	objBody.appendChild(objProgressImage);
	objProgressImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - document.getElementById('progress').height) / 2) + 'px');
	objProgressImage.style.left = (((arrayPageSize[0] - 20 - document.getElementById('progress').width) / 2) + 'px');

	return false;
}


function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function MultiSelector(list_target, max){
	this.list_target = list_target;
	this.count = 0;
	this.id = 0;
	if( max ){
		this.max = max;
	} else {
		this.max = -1;
	};
	
	this.addElement = function( element ){
		if( element.tagName == 'INPUT' && element.type == 'file' ){
			element.name = 'file_' + this.id++;
			element.multi_selector = this;
			element.onchange = function(){
				var new_element = document.createElement( 'input' );
				new_element.type = 'file';
				this.parentNode.insertBefore( new_element, this );
				this.multi_selector.addElement( new_element );
				this.multi_selector.addListRow( this );
				this.style.position = 'absolute';
				this.style.left = '-1000px';
			};

			if( this.max != -1 && this.count >= this.max ){
				element.disabled = true;
			};

			this.count++;
			this.current_element = element;
		} else {
			alert( 'Error: not a file input element' );
		};
	};

	this.addListRow = function( element ){
		var new_row = document.createElement( 'div' );
		new_row.style.verticalAlign = 'middle';
		
		var new_row_button = document.createElement( 'input' );
		new_row_button.type = 'button';
		new_row_button.value = 'Delete';
		new_row.element = element;
		new_row_button.onclick= function(){
			this.parentNode.element.parentNode.removeChild( this.parentNode.element );
			this.parentNode.parentNode.removeChild( this.parentNode );
			this.parentNode.element.multi_selector.count--;
			this.parentNode.element.multi_selector.current_element.disabled = false;
			return false;
		};

		new_row.innerHTML = element.value + '&nbsp;';
		new_row.appendChild( new_row_button );
		this.list_target.appendChild( new_row );
	};
};