function validar_oferta()
{
	var sw=0;
	var error = "";
	if ((vacio(document.ofertar.fecha_fin_contrato.value) == false) || ((document.ofertar.fecha_fin_contrato.value) == 'dd-mm-yyyy')){
		error = error + '- El campo fecha no es correcto' + '\n';	
		sw = 1;
	}
	if (vacio(document.ofertar.ficha.value) == false){
		error = error + '- El campo prima fichaje no es correcto' + '\n';	
		sw = 1;
	}
	if (vacio(document.ofertar.sueldo.value) == false){
		error = error + '- El campo sueldo semanal no es correcto' + '\n';	
		sw = 1;
	}
	if (vacio(document.ofertar.clausula.value) == false){
		error = error + '- El campo clausula no es correcto' + '\n';	
		sw = 1;
	}
	if (((document.ofertar.ficha.value) == 0) && ((document.ofertar.sueldo.value) == 0) && ((document.ofertar.clausula.value) > 2500))
	{
		error = error + '- Con las caracteristicas del contrato' + '\n' + 'la clausula no puede ser mayor a 2.500 L$';	
		sw = 1;
	} else if (((document.ofertar.ficha.value) > 0) || ((document.ofertar.sueldo.value) > 0)){
		var str=document.ofertar.fecha_fin_contrato.value;
		var day = parseInt(str.slice(0,2));
		var month = parseInt(str.slice(3,5));
		var year = parseInt(str.slice(6));
		var date = new Date();
		date.setMonth(month-1,day);
		date.setFullYear(year);
		var now = new Date();
		var diff = date.getTime() - now.getTime();
		var days = Math.floor(diff / (1000 * 60 * 60 * 24))
		var weeks = Math.floor(days/7);
		if (weeks == 0){weeks = 1};
		var ficha = parseInt(document.ofertar.ficha.value);
		var sueldo = parseInt(document.ofertar.sueldo.value)*weeks;
		var clausula = (ficha+sueldo)+((ficha+sueldo) * 20)/100;
		if ((document.ofertar.clausula.value) > clausula ){
			error = error + '- Con las caracteristicas del contrato' + '\n' + 'la clausula no puede ser mayor a '+ clausula +' L$';	
			sw = 1;
		}
	}
	
	if(sw==0){
		document.ofertar.submit();
	}
	else {
		alert(error);	
	}
}

function vacio(q) {
for ( i = 0; i < q.length; i++ ){
	if ( q.charAt(i) != " " ){
		return true//true no esta vacio
		}
	}
	return false// false el campo esta vacio
}

function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	
	return true;
}

function limitChars(textid, limit, infodiv)
{
var text = $('#'+textid).val(); 
var textlength = text.length;
if(textlength > limit)
	{
	$('#' + infodiv).html('No puedes escribir m&aacute;s de '+limit+' caracteres!');
	$('#' + textid).val(text.substr(0,limit));
	return false;
	}
	else
	{
	$('#' + infodiv).html('Te quedan '+ (limit - textlength) +' caracteres para escribir.');
	return true;
	}
}

