window.addEvent('domready', function() {
	var etichetta = {
		'true': '[apri]',
		'false': '[chiudi]'
	};
	
/*if($('divimgajax')!=null){




$('immaginiannuncio').addEvent('submit', function(e) {
				//Prevents the default submit event from loading a new page.
				e.stop();
				//Set the options of the form's Request handler. 
				//("this" refers to the $('myForm') element). headers:'multipart/form-data',
				this.set('send', { onComplete: function(response) { 
														
					$('anteprima').set('html', response);
					//chiudi.delay(2000);
				}});
				//Send the form.
				this.send();
			});
}*/

/*
$('immaginiannuncio').addEvent('submit', function(e){
		e.stop();
		
		
		getAjax('anteprima','http://milano.devel.bakeca.it/be/main.php?page=uploadimgajax&err=si');
		
		/*$('uploadimg').addEvent('change', function(file , ext){
			
			if (ext && /^(jpg|png|jpeg|gif)$/.test(ext)){
				this.setData({
					'key': 'This string will be send with the file'
				});
				
				$('#example2 .text').text('Uploading ' + file);	
			} else {
				
				// extension is not allowed
				$('#example2 .text').text('Error: only images are allowed');
				// cancel upload
				return false;				
			}

		})

		
		$('uploadimg').set('send', {onComplete: function(response) { 
					$('divimgajax').set('html', response);
					//chiudi.delay(2000);
				}});
				//Send the form.
		$('uploadimg').send();
		*/
		/*
		
		$('uploadimg').addEvent('submit', function(e) {
				//Prevents the default submit event from loading a new page.
				e.stop();
				
				//Set the options of the form's Request handler. 
				//("this" refers to the $('myForm') element).
				this.set('send', {onComplete: function(response) { 
					$('divimgajax').set('html', response);
					//chiudi.delay(2000);
				}});
				//Send the form.
				this.send();
			});
	});
}*/


/*upload immagini annuncio con ajax -.-*/	

	
	//-vertical

	
/*
	$('v_slidein').addEvent('click', function(e){
		e.stop();
		myVerticalSlide.slideIn();
	});

	$('v_slideout').addEvent('click', function(e){
		e.stop();
		myVerticalSlide.slideOut();
	});



	$('v_hide').addEvent('click', function(e){
		e.stop();
		myVerticalSlide.hide();
		$('vertical_status').set('html', status[myVerticalSlide.open]);
	});
	
	$('v_show').addEvent('click', function(e){
		e.stop();
		myVerticalSlide.show();
		$('vertical_status').set('html', status[myVerticalSlide.open]);
	});
*/
if($('divsegnala')!=null){
	var SlideSegnala = new Fx.Slide('divsegnala').hide();
		
	$('segnala').addEvent('click', function(e){
		e.stop();
		SlideSegnala.toggle();
	});



	
	$('sendsegnalazione').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop();
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function(response) { 
			$('divsegnala').set('html', response);
			chiudi.delay(2000);
		}});
		//Send the form.
		this.send();
	});

}

if($('divrisposta')!=null){
		if(erroririsposta){
			var SlideRisposta = new Fx.Slide('divrisposta').show();
		} else {
			var SlideRisposta = new Fx.Slide('divrisposta').hide();
		}
		
		$('chiudi').addEvent('click', function(e){
			e.stop();
			
			/*var comando = $('chiudi').get('text');
			if(comando =='[chiudi]'){
				
				$('chiudi').set('text', etichetta[myVerticalSlide.open]);
			} else { $('chiudi').set('text', etichetta[myVerticalSlide.open]); }*/
			
			SlideRisposta.toggle();
			$('chiudi').set('text', etichetta[SlideRisposta.open]);
		});
		


	//var SlideRisposta = new Fx.Slide('divrisposta').hide();
	
	$('toggle').addEvent('click', function(e){
		e.stop();
		
			var testo = $('toggle').get('value');
			if(testo == 'Scrivi qui la risposta a questo annuncio'){
				$('toggle').set('text', '');
	
			}
		
		SlideRisposta.slideIn();
		
		if($('chiudi').get('text') == '[apri]')$('chiudi').set('text', etichetta[SlideRisposta.open]);
	});
	
	$('toggle').addEvent('focus', function(e){
		e.stop();
			var testo = $('toggle').get('value');
			if(testo == 'Scrivi qui la risposta a questo annuncio'){
				$('toggle').set('text', '');
	
			}

		
		SlideRisposta.slideIn();
		if($('chiudi').get('text') == '[apri]')$('chiudi').set('text', etichetta[SlideRisposta.open]);
	});
	
}


if($('divamico')!=null){

		if(erroriamico){
			var SlideAmico = new Fx.Slide('divamico').show();
		} else {
			var SlideAmico = new Fx.Slide('divamico').hide();
		}
	//var SlideAmico = new Fx.Slide('divamico').hide();
	
	$('amico').addEvent('click', function(e){
		e.stop();
		SlideAmico.toggle();
	});
}
/*
	//--horizontal
	var myHorizontalSlide = new Fx.Slide('divMessaggio', {mode: 'horizontal'}).hide();
	if($('linkcose')){
	$('linkcose').addEvent('click', function(e){
		e.stop();
		myHorizontalSlide.toggle();
	});
	}
	$('divMessaggio').setStyle('display','block');
	*/
/*
	$('h_slidein').addEvent('click', function(e){
		e.stop();
		myHorizontalSlide.slideIn();
	});

	$('h_slideout').addEvent('click', function(e){
		e.stop();
		myHorizontalSlide.slideOut();
	});

	
	$('h_hide').addEvent('click', function(e){
		e.stop();
		myHorizontalSlide.hide();
		$('horizontal_status').set('html', status[myHorizontalSlide.open]);
	});
	
	$('h_show').addEvent('click', function(e){
		e.stop();
		myHorizontalSlide.show();
		$('horizontal_status').set('html', status[myHorizontalSlide.open]);
	});
	
	var textarea = $('myEmail'), log = $('attivaMB');
	
	var highlight = new Fx.Morph(log, {
		duration: 1500,
		link: 'cancel',
		transition: 'quad:out'
	});
	
	textarea.addEvents({
		keyup: function() {
			// When user keyups we check if there are any of the magic words.
			// If yes, we fire our custom event burn with a different text for each one.
			if (validateEmail(textarea.value)) {
					textarea.fireEvent('burn');
					//$('attivaMB').setStyle('display','inline');
			}
			else $('attivaMB').set('text',''); 
		},
		
		burn: function() {
			// When the textarea contains one of the magic words
			// we reset textarea value and set the log with text
			//textarea.value = ''; log.set('html', text);
			getAjax('attivaMB','main.php?page=v_u_mb&email='+textarea.value,'inline');
			// then we start the highlight morphing
			highlight.start({
				backgroundColor: ['#fff', 'none'],
				opacity: [0.5, 1]
			});
		}
	});
	*/
	
	
/* DIV HELP per inserimento annuncio*/	
var SlideSegnala = new Fx.Slide('divhelp', {mode: 'horizontal'}).hide();


$('tit').addEvent('click', function(e) {
		e.stop();
		SlideSegnala.show();
		Slidetip.hide();
});
$('tit').addEvent('focus', function(e) {
		e.stop();
		SlideSegnala.show();
		Slidetip.hide();
});
$('tit').addEvent('blur', function(e) {
		e.stop();
		
		SlideSegnala.hide();
});


var Slidetip = new Fx.Slide('divhelptesto', {mode: 'horizontal'}).hide();

$('testoann').addEvent('click', function(e) {
		e.stop();
		Slidetip.show();
		SlideSegnala.hide();
});
$('testoann').addEvent('focus', function(e) {
		e.stop();
		Slidetip.show();
		SlideSegnala.hide();
});
$('testoann').addEvent('blur', function(e) {
		e.stop();
		Slidetip.hide();
		
});


var DivInsertImg = new Fx.Slide('visualizzainsert').hide();

$('imgbtn').addEvent('click', function(e) {
		e.stop();
		DivInsertImg.show();
		$('imgbtn').hide();
});

	
	
});

function chiudi(){
		var SlideSegna= new Fx.Slide('divsegnala');
		SlideSegna.slideOut();
	}

function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(email); 
}