
	

 var idfichier=Math.random();

		/**
 * FancyUpload Showcase
 *
 * @license		MIT License
 * @author		Harald Kirschner <mail [at] digitarald [dot] de>
 * @copyright	Authors
 */
// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
  function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return 0;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
 function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
 var formupload2=true;
 var formupload=false;

 
 
 
 
 window.addEvent('domready', function() { // wait for the content

	// our uploader instance 
	
	var up = new FancyUpload2($('upload-status'), $('upload-list'), { // options object
		// we console.log infos, remove that in production!!
		
		verbose: true,
		// url is read from the form, so you just have to change one place
		url: 'js/fancyupload/script.php?idfichier='+idfichier,
		
		// path to the SWF file
		path: 'js/fancyupload/Swiff.Uploader.swf',
		onSelect:  function(){formupload=true;},
		onComplete:  function() {
			//alert('arf',formupload);
			$('formenvoiemail').submit();
			},
		//onComplete:  function() {$('formenvoiemail').submit();},
		//onComplete:  function() {if(formupload2==true){$('formenvoiemail').submit();}},
		//onComplete: ('btnSubmit').disabled = false;
			// remove that line to select all files, or edit it, add more items
		typeFilter: {
			'Documents (*.rar, *.zip,*.txt,*.jpg, *.jpeg, *.dxs, *.doc, *.dwg, *.docxn, *.pdf, *.xls)': '*.rar; *.zip; *.txt; *.jpg; *.jpeg; *.dxs; *.doc; *.dwg; *.docxn; *.pdf; *.xls'
			
		},
		
		// this is our browse button, *target* is overlayed with the Flash movie
		target: 'upload-browse',
		
		// graceful degradation, onLoad is only called if all went well with Flash
		onLoad: function() {
			$('upload-status').removeClass('hide'); // we show the actual UI
			$('upload-fallback').destroy(); // ... and hide the plain form
			
			// We relay the interactions with the overlayed flash to the link
			this.target.addEvents({
				click: function() {
					return false;
				},
				mouseenter: function() {
					this.addClass('hover');
				},
				mouseleave: function() {
					this.removeClass('hover');
					this.blur();
				},
				mousedown: function() {
					this.focus();
				}
			});

			// Interactions for the 2 other buttons
			
			$('upload-clear').addEvent('click', function() {
				up.remove(); // remove all files
				return false;
			});
			$('upload-browse').addEvent('click', function() {
				//alert('click');
				//formupload=true;
				return false;
			});

			$('btnsubmit').addEvent('click', function(){
				chai= new FormCheck('formenvoiemail', {
		display: {
			errorsLocation: 1,
			indicateErrors: 2,
			keepFocusOnError: 0,
			closeTipsButton: 1,
			showErrors: 1,
			flashTips: 1
		}
	});
	chai.onSubmit();
				if (Get_Cookie('idfichier') != 0) {
					if (formcheckvalide == true) {
						//('btnsubmit').disabled = true;
						//alert('formcheckdansbtnsubmit');
						if (formupload == true) {
							Set_Cookie('idfichier', idfichier, 20, '/', '', '');
							//alert('formupload');
							up.start();
							return false;
						}
						else {
							$('formenvoiemail').submit();
						}
					}
				}
				else {
					alert('antispam: Vous avez essaye d envoyer plusieurs devis trop rapidement...');
				}
			});
			
		},
		
		// Edit the following lines, it is your custom event handling
		
		/**
		 * Is called when files were not added, "files" is an array of invalid File classes.
		 * 
		 * This example creates a list of error elements directly in the file list, which
		 * hide on click.
		 */ 
		onSelectFail: function(files) {
			files.each(function(file) {
				new Element('li', {
					'class': 'validation-error',
					html: file.validationErrorMessage || file.validationError,
					title: MooTools.lang.get('FancyUpload', 'removeTitle'),
					events: {
						click: function() {
							this.destroy();
						}
					}
				}).inject(this.list, 'top');
			}, this);
		},
		
		/**
		 * This one was directly in FancyUpload2 before, the event makes it
		 * easier for you, to add your own response handling (you probably want
		 * to send something else than JSON or different items).
		 */
		onFileSuccess: function(file, response) {
			var json = new Hash(JSON.decode(response, true) || {});
			
			if (json.get('status') == '1') {
				file.element.addClass('file-success');
				file.info.set('html', '<strong>Image was uploaded:</strong> ' + json.get('width') + ' x ' + json.get('height') + 'px, <em>' + json.get('mime') + '</em>)');
			} else {
				file.element.addClass('file-failed');
				file.info.set('html', '<strong>An error occured:</strong> ' + (json.get('error') ? (json.get('error') + ' #' + json.get('code')) : response));
				formupload2=false;
			}
		},
		
		/**
		 * onFail is called when the Flash movie got bashed by some browser plugin
		 * like Adblock or Flashblock.
		 */
		onFail: function(error) {
			switch (error) {
				case 'hidden': // works after enabling the movie and clicking refresh
					alert('To enable the embedded uploader, unblock it in your browser and refresh (see Adblock).');
					break;
				case 'blocked': // This no *full* fail, it works after the user clicks the button
					alert('To enable the embedded uploader, enable the blocked Flash movie (see Flashblock).');
					break;
				case 'empty': // Oh oh, wrong path
					alert('A required file was not found, please be patient and we fix this.');
					break;
				case 'flash': // no flash 9+ :(
					alert('To enable the embedded uploader, install the latest Adobe Flash plugin.')
			}
		}
		
	});
	
});
window.addEvent('domready', function(){
	$$(".sexyform input", ".sexyform select", ".sexyform textarea").each(function(el){
		el.DoSexy();
	});
});
 window.addEvent('domready', function(){
	chai= new FormCheck('formenvoiemail', {
		display: {
			errorsLocation: 1,
			indicateErrors: 2,
			keepFocusOnError: 0,
			closeTipsButton: 1,
			showErrors: 1,
			flashTips: 1
		}
	})
});	

        