
function checkEmpty(id){
	if ($('#'+id).val() == ""){
		$('#'+id).css('background-color', '#ff5555');
		return false;
	}
	return true;
}

function checkRadio(name){
	
	var checked = false;
	$('input[name='+name+']').each(function (i){
		checked = checked || this.checked;	
	});
	
	if (!checked){
		$('#'+name).addClass('radioSelected');
	}
	
	return checked;
}

function checkFields(){
	$('input[type=text]').css('background-color', 'white');
	$('.radioSelected').removeClass('radioSelected');
	
	var res = true;
	
	res = res & checkEmpty('nombre');
	res = res & checkEmpty('empresa');
	res = res & checkEmpty('sector');
	res = res & checkEmpty('web');
	res = res & checkEmpty('telefono');
	res = res & checkEmpty('email');
	res = res & checkEmpty('diayhora');
	
	/* res = res & checkRadio('check1');
	res = res & checkRadio('check2');
	res = res & checkRadio('check3');
	res = res & checkRadio('check4');
	res = res & checkRadio('check5');
	res = res & checkRadio('check6');
	res = res & checkRadio('check7'); */
	
	return res;
}

function submitForm(url){
	
	if (!checkFields()){
		return;
	}
	
	$('#resMsg').html('<image src=images/ajxindicator.gif />');	
	
	$.post('oferta-form', $('#requestForm').serialize(), function(data){
		
		$('#resMsg').html(data.message);

		if (data.error){
			return;
		}		
		
		window.location = 'oferta-gracias';
		
	}, 'json');
	
	return false;
	
}