$(document).ready(function(){
	jQuery('#mmessage').one('focus', function() { $(this).val(''); });
});

function fronteretro( type ) {
	if (type == 1) {
		$('#div_colori_retro').show();
	} else {
		$('#div_colori_retro').hide();
		$('#colori_retro').val('');
	}
}

function fronteretro2( type ) {
	if (type == 1) {
		$('#div_colori_retro2').show();
	} else {
		$('#div_colori_retro2').hide();
		$('#colori_retro2').val('');
	}
}

function changeDelivery() {
	var value = $('#deliveryaddress2').attr('checked');
	//alert(value);
	if (value) {
		$('#other_address').show();
	} else {
		$('#other_address').hide();
	}
}

function change_fustella() {
	var id = $('#select_fustella').children('[@selected]').attr('id');
	id = id.substr( 7 );
	$.ajax({
		url: $('#url_fustella').val(),
		data: 'id=' + id,
		success: function(msg) {
			if (msg != "")
				$('#img_fustella').attr('src', msg );
		}
	});
}

function send_message() {
	$.ajax({
		url: $('#form_message').attr('action'),
		data: $('#form_message').serialize(),
		success: function(msg) {
			$('#form_message div:first').append(msg);
		}
	});
	return false; 
}

function initJS() {
	
	// add input type file
	$('a.option-show-bt').click(function(){
		$(this).parent().addClass('hide-option');
		$(this).parents('.option-cnt').children('option:last').attr("selected","selected");
		$(this).parents('.opuscoli-cnt').children('.first-choice').attr("disabled", true );
		$(this).next('.option-cnt').children('input[type=checkbox]').attr({checked:'checked'});
		//$(this).parents('.option-cnt').children('input[type=text, class*=required], textarea[class*=required], select[class*=required]').rules("remove");
		//$("option:first", "select#host_organization").attr("selected","selected");
		return false;	
	});
	// show options
	$('a.rimuovi').click(function(){
		$(this).parents('.opuscoli-cnt').removeClass('hide-option');
		$(this).parents('.option-cnt').children('input[type=text], textarea, select').val('');
		$(this).parents('.option-cnt').children('input[type=checkbox]').attr({checked:false});
		
		//$(this).parents('.option-cnt').children('input[type=text, class*=required], textarea[class*=required], select[class*=required]').rules("add", { required: true } );
		$(this).parents('.opuscoli-cnt').children('.first-choice').attr("disabled", false);
				
		return false;	
	});
	// add input type file
	var _inputFile = $('#input-file').html();
	$('#add-file').click(function(){
		$(_inputFile).appendTo('#input-file');
		$('#input-file input').each(function(i){
			$(this).attr('name','file'+i);
		})
		return false;
	});
	
	$('.registrati-btn').click(function(){
		$('#signup').toggleClass('open');
	});	
}
if (window.addEventListener)
	window.addEventListener("load", initJS, false);
else if (window.attachEvent)
	window.attachEvent("onload", initJS);

