if ( typeof(xajax) != 'undefined' ) {
	var uploadStr = '';

    xajax.initFileInputs = function ()
    {
        inputs = document.getElementsByTagName('input');
        for( var i=0; i < inputs.length; i++)
        {
            inp=inputs[i];
            if (!inp.className)
                continue; //doesnt have a class defined
            if (inp.className.indexOf('xajax_file')==-1)
                continue; //not an xajax file upload
            if (inp.style.visibility=='hidden')
                continue; //already converted this file upload
            xajax.newFileUpload(inp.id, inp.id+'-'+xajax.workId);
            inp.style.visibility = 'hidden';
            inp.style.height = '0';
            inp.style.width = '0';
        } 
    }
    xajax.newFileUpload = function(sParentId, sId, folder, showName, multiple, module, module_id, people_id, oldName, field, reload )
    {
		 if( checkIt( 'msie' ) ) {
			 newFrame = document.createElement( 'iframe' );
			 newFrame.id=sId;
		 } else {
			 xajax.insertAfter(sParentId, 'iframe', sId);
			 newFrame = xajax.$(sId);
		 }
        newFrame.setAttribute( 'id', sId );
        newFrame.style.height="35px";
        newFrame.style.width="400px";
        newFrame.style.overflow="hidden";
        newFrame.position="relative";
        newFrame.scrolling="no";
        newFrame.allowtransparency=true;
        newFrame.style.backgroundColor="transparent";
		  if( checkIt( 'msie' ) ) {
			  	if( location.href.indexOf( 'https://' ) > -1 )
					var domain = 'https://' + location.href.substr( location.href.indexOf( '//' ) + 2, location.href.substr( 8 ).indexOf( '/' ) );
				else
					var domain = 'http://' + location.href.substr( location.href.indexOf( '//' ) + 2, location.href.substr( 7 ).indexOf( '/' ) );
			  	newFrame.setAttribute( 'frameborder', 0 );
				newFrame.src = domain + '/source/system/file/blank.php';
				document.getElementById( sParentId ).appendChild( newFrame );
		  }
        //need to wait for Mozilla to notice there's an iframe
        setTimeout('xajax._fileUploadContinue("' + sId + '","' + folder + '","' + showName + '","' + multiple + '","' +
			  											module + '","' + module_id + '","' + people_id + '","' + oldName + '","' +
														field + '","' + reload + '");', 200);
    }
    xajax._fileUploadContinue = function(sId, folder, showName, multiple, module, module_id, people_id, oldName, field, reload ){
        //uploadIframe = window.frames[sId];
        uploadIframe = xajax.$(sId);

		  if( typeof( uploadIframe ) == 'object' ) {
			  //fix for internet explorer
			  if( !uploadIframe.contentDocument ) {
					uploadIframe.contentDocument = window.frames[sId].document;
					if( !uploadIframe.contentDocument )
						uploadIframe.contentDocument = document.getElementById( sId ).document;
			  }

			  if( !uploadIframe.contentDocument.body )
					setTimeout('xajax._fileUploadContinue("' + sId + '","' + folder + '","' + showName + '","' + multiple +
																	'","' + module + '","' + module_id + '","' + people_id + '","' +
																	oldName + '","' + field + '","' + reload + '");', 200);
			  else {
					uploadIframe.contentDocument.body.style.backgroundColor="transparent";
					uploadIframe.contentDocument.xajax=this;
					uploadIframe.contentDocument.body.innerHTML=
							createShowPage( xajax.workId, xajaxRequestUri, sId, folder, showName, multiple, module, module_id, people_id, oldName, field, reload );
					uploadIframe.style.border='0px';
			  }
		 }
	 }
    xajax._fileUploading = function(sId, showName )
    {
		 if( validChangeDoc( sId, showName ) ) {
        uploadIframe = xajax.$(sId);
        xajax.insertAfter(sId, 'div', sId+'-progress');
        uploadProgress = xajax.$(sId+'-progress');
		  uploadIframe.style.visibility='hidden';
        uploadIframe.style.width='0px';
        uploadIframe.style.height='0px';
        uploadProgress.innerHTML='0min. 0sec. 0';
        uploadProgress.style.fontSize="18px";
        setTimeout('xajax._fileProgressCheck("'+sId+'");', 100);
		 }
    }
    xajax._fileProgressCheck = function(sId)
    {
        uploadIframe = xajax.$(sId);
        if (!uploadIframe.contentDocument)
        {
            //fix for internet explorer
            uploadIframe.contentDocument = window.frames[sId].document;
				if( !uploadIframe.contentDocument )
					uploadIframe.contentDocument = document.getElementById( sId ).document;
        }
        uploadProgress = xajax.$(sId+'-progress');

        if( uploadStr.indexOf('UPLOAD DONE') !== -1) {
				//this isn't a proper detection, but we'll work on it later
				//uploadProgress.innerHTML='Upload Finished';
				finishUpload( uploadStr, sId );

		  } else if( uploadStr.indexOf('Fatal error') !== -1 ||
		  				uploadStr.indexOf('Notice') !== -1 )
				alert( uploadStr );
		  else {
			  setNewUploadTime( uploadProgress, uploadStr );
			  setTimeout('xajax._fileProgressCheck("'+sId+'");', 100);
        }
    }
}

