function brandChange(){
	var brand = $('#brand option:selected').text();
	$.getJSON(
		context+'/ajax/terminal/findTerminalsByBrand.do',
		{'brand':brand},
		function(data){
			terminals = data;
			jQuery.each($('#terminal option'),function(){
				$(this).remove();
			});
			$('<option value="">Selecciona un modelo:</option>').appendTo('#terminal')
			jQuery.each(data,function(){
				$('<option value="'+this.terminalName+'">'+this.terminalName+'</option>').appendTo('#terminal');
			});
		}
	);
}

function sendInformation(){
	if(isFormEmpty()){
		if(validForm()){
			showLoading();
			$.getJSON(context+'/sendInformation.do?'+$('#contactForm').serialize(),
				function(data){
					hideLoading();
					$('#_mensaje').html(data.msg);
					$('#cForm').css('display','none');
					$('#cConfirmationForm').css('display','');
				}
			);
		}
	}else{
		showMessage('error','Por favor, escribe todos los datos.');
	}
}

function validForm(){
	if(!/^[\da-zA-Z_\.]+@[a-zA-Z\d]+\.[a-zA-Z\.]+$/.test($('#email').val())){
		showMessage('error','El correo electr&oacute;nico es incorrecto.');
		return false;
	}

	if(!/^[A-Za-z\sáéíóúÁÉÍÓÚñÑ]{2,}$/.test($('#name').val())){
		showMessage('error','El nombre es incorrecto.');
		return false;
	}
	
	if(!/^\d{10}$/.test($('#phoneNumber').val())){
		showMessage('error','El n&uacute;mero telef&oacute;nico debe ser de 10 d&iacute;gitos.');
		return false;
	}
	
	return true;
}

function isFormEmpty(){
	if(
		$("#contactForm")[0].email.value!=''
		&& $("#contactForm")[0].name.value!=''
		&& $("#contactForm")[0].phoneNumber.value!=''
		&& $("#contactForm")[0].brand.value!=''
		&& $("#contactForm")[0].terminal.value!=''
		&& $("#contactForm")[0].state.value!=''
		&& $("#contactForm")[0].commentReference.value!=''
		&& $("#contactForm")[0].comment.value!=''
	)
		return true;
	else return false
}
/*
function showMessage(bgColor,msg){
		$('.alertBox').css('background-color',bgColor);
		$('#mensaje').text(msg);
		$('#mensajeBox').css('display','block');
		$('.alertBox').highlightFade({color:'#C4FF81',speed:500,iterator:'exponential'});
}
*/