/* You may edit these */
var maxFileSelectable = 20;
var selectedFiles 	= getObj ( 'selectedFiles' );
var fileSelect 		= getObj ( 'fileSelect' );
var fileSelectedStatus = getObj ( 'fileSelectedStatus' );
var uploadTo		 = getObj ( 'upload_to' );
var fileExistWarn	 = getObj ( 'fileExistsWarning' );
var fileNum 		= 0;
var fileSelected 	= 0;


if ( !selectedFiles || !fileSelect || !fileSelectedStatus ) throw 'Error! Could not find all the objects required.';



function isSelected ( f )
{
	for ( var i = 0; i < fileNum-1; i++ )
	{
		var x = getObj ( 'file' + i );
		if ( x  && x.value == f ) return true;
	}
	return false;
}

function checkFileExists ( )
{
	if ( !fileExistWarn ) return false;
	if ( !uploadTo ) return false;

	var files = fileSelect.getElementsByTagName ( 'input' );
	var fileNames = new Array();

	for ( i = 0; i < files.length; i++ )
	{
		if ( files[i].type == 'file' && files[i].value != '' )
		{
			fileNames['files['+i+']'] = basename ( files[i].value );
		}
		// folder
		fileNames['folder'] = uploadTo.value;
	}
	var checkFunc = function ( result )
	{
		if ( result != '' )
		{
			fileExistWarn.style.display = 'block';
			fileExistWarn.innerHTML = result;
		}
		else fileExistWarn.style.display = 'none';
	}
	xmlhttpPost(fileNames,'upload.php?action=check_file_exists',checkFunc);
}




fileSelect.appendChild ( newFileInput ( ) );