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(url,contextIdeas){
	if(isFormEmpty()){
		if(validForm()){
			showLoading();
			var sys = '10';
			var now = new Date();
			var leng = 'es_';
			var url_return = contextIdeas+'/emailSuccess.do';
			var url_error = contextIdeas+'/emailLimited.do';
			var email = document.getElementById('email').value;
			//var url = "http://<%= request.getServerName() %>:<%= request.getServerPort() %>/apps/servlet/CapturarForma";
			window.location=url+'?sys='+sys+'&url_retorno='+url_return+'&email='+email+'&url_error='+url_error+'&lenguaje='+leng+
								'&name='+document.getElementById("name").value+'&phoneNumber='+document.getElementById("phoneNumber").value+
								'&brand='+document.getElementById("brand").value+'&terminal='+document.getElementById("terminal").value+
								'&state='+document.getElementById("state").value+'&commentReference='+document.getElementById("commentReference").value+
								'&comment='+document.getElementById("comment").value+'&time='+new Date();
			
//			$.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'});
}
*/
