	
	//---------------------------------------------------------------
	
	//default parameters
	
	//form name
	//form_name = "forms[0]";
	form_name = "form_upl";
	
	// size of standard preview....	
	preview_size=100;

	// number of photos to upload...
	photo_number = 3;
	
	// file field & preview field names
	file_field = 'upload';
	preview_field = 'preview';

	// sources of images to upload
	imgsrc = new Array();
	
	// timing for testing... in milliseconds
	timing = 1000;
	
	//try to catch platform...
	isLinuxBased = false;
	
	//proceed?
	go = true;
	
	//---------------------------------------------------------------
	
	function setParams( fm, ps, pn, ff, pf, t  ){
		//form name
		form_name = fm;
		
		// size of standard preview....	
		preview_size=ps;
	
		// number of photos to upload...
		photo_number = pn;
		
		// file field & preview field names
		file_field = ff;
		preview_field = pf;
	
		// timing for testing... in milliseconds
		timing = t;

	}
	//---------------------------------------------------------------
	
	function test_browser(){

		str = "";
		with (navigator){
			str += "APPNAME : " + appName + "\n";
			str += "APPCODENAME : " + appCodeName + "\n";
			str += "APPVERSION : " + appVersion + "\n";
			str += "USERAGENT : " + userAgent;
		}
		//alert (str);
		
		// find win,mac or linux platform in appversion....
		appv = navigator.appVersion;
		usera = navigator.userAgent;
		
		w = appv.indexOf('W');
		a = appv.lastIndexOf('M');
		l = usera.indexOf('L');

		if (w>1){
			//alert ("FOUND W at POS " + w);
			if (appv.charAt(w+1)=='i' && appv.charAt(w+2)=='n'){
				//alert ("I SUPPOSE YOU ARE USING WINDOWS :-) ");
				isLinuxBased = false;
				return;
			}
		}
		
		if (a>1){
			//alert ("FOUND M at POS " + a);
			if (appv.charAt(a+1)=='a' && appv.charAt(a+2)=='c'){
				//alert ("I SUPPOSE YOU ARE USING MAC :-) ");
				isLinuxBased = true;
				go = false;
				return;
			}
		}	

		if (l>1){
			//alert ("FOUND L at POS " + l);
			if (usera.charAt(l+1)=='i' && usera.charAt(l+2)=='n'){
				//alert ("I SUPPOSE YOU ARE USING LINUX!!!  :-) GOOD :-) ");
				isLinuxBased = true;
				return;
			}
		}
		
		// setting to standard!!
		isLinuxBased = false;
	}
	
	//---------------------------------------------------------------
	
	// storing data value for each file fields....
	function init(){
		if (go){
			for (i=1;i<=photo_number;i++){
				imgsrc[i] = "";
			}
			timer();
		}
	}
	
	//---------------------------------------------------------------

	var status = 0;
	//0 = valid
	//1 = wrong
	//2 = empty

	// check if somethings is changed
	function timer(){

    var totSize = 0;

		for (i=1;i<=photo_number;i++){
			src = eval ('document.' + form_name + '.' + file_field + i + '.value');

			if( src == "" ){
			  status = 2;
			}else{
			  fileType = src.substring( src.lastIndexOf(".")+1 ).toLowerCase();
			  if( fileType == "jpg" || fileType == "jpeg" ){
			    status = 0;
			  }else{
			    status = 1;
			  }
			}

			if (imgsrc[i] != src){

        if (isLinuxBased){
          src = "file://" + src;
        }else{
          src = "file:///" + src;
        }

        imgsrc[i] = src;

        if( status == 1 ){
          //wrong
          imgsrc[i] = "/app/themes/mwire/default/formato_non_corretto.gif";
        }else if( status == 2 ){
          //empty
          imgsrc[i] = "/app/themes/mwire/default/spaziatore.jpg";
        }

				eval ('document.images["' + preview_field + i + '"].src = imgsrc[' + i + ']');
				eval ('document.images["' + preview_field + i + '"].width = preview_size');
				//eval ('document.images["' + preview_field + i + '"].height = preview_size');

				/* INIZIO DEMO */

        if ((browserName == "Microsoft Internet Explorer") && (browserVer >= 4)){
          var appo = eval ('document.images["' + preview_field + i + '"].fileSize');
          var imgSize = parseInt(appo / 1000);
          if(status == 0){
            eval('img_size_' + i + '.innerText=' + imgSize + ' + "Kb"');
          }else{
            eval('img_size_' + i + '.innerText=""');
            imgSize = 0;
          }
          totSize += imgSize;
          tot_size1.innerText = "Peso totale foto selezionate: "+ totSize + " Kb";
          //tot_size2.innerText = "Tempo Max di trasferimento: "+ Math.round((totSize * 1000 * 8 / 20000 / 60) + .49) +" Min.";
        }

        /* FINE DEMO */
			}
		}
		setTimeout('timer()',timing);			
	}

	//---------------------------------------------------------------
	
	test_browser();
	
	//---------------------------------------------------------------
