function checkMail(obj, descrip, l) {
	var x = obj.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)==false) {
		if(l==1) {
			alert("La dirección de " + descrip + " no es válida");
			} else { 
			alert("The " + descrip + " address is not valid");
			}
		obj.focus();
		return false;
		} else {
		return true;
		}
	}

function chk_clicked(obj_clicked, frm) {
	obj_off = eval("document."+frm.name+"."+obj_clicked+"_OFF");
	obj_on = eval("document."+frm.name+"."+obj_clicked+"_NUM");
	if (obj_off.checked==true) {
		obj_on.value = 1;
		}
	else {
		obj_on.value = 0;
		}
	}

function formatAsMoney(mnt) {
	mnt -= 0;
	mnt = (Math.round(mnt*100))/100;
	return (mnt == Math.floor(mnt)) ? mnt + '.00' 
			  : ( (mnt*10 == Math.floor(mnt*10)) ?
					   mnt + '0' : mnt);
	}

function is_numeric(obj, descrip, l) {
	if(l==1) { 
		m = "Por favor indique sólo números " + descrip;
		} else {
		m = "Please indicate only numbers " + descrip;
		}
	if(isNaN(obj.value)) {
		alert(m);
		obj.focus();
		return false;
		}
	}


function chk_dat(obj, descrip, l) {
	if(isdate(obj, l)==false) {
		if(l==1) {
			alert(descrip + " es incorrecta, el formato debe ser dd-mm-aaaa");
			} else {
			alert(descrip + " is incorrect, the format should be mm-dd-yyyy");
			}
		obj.focus();
		return false;
		}
	}

function chk_txt(obj, descrip, l) {
	if(obj.value.length == 0) {
		if(l==1) {
			alert("Por favor indique " + descrip);
			} else { 
			alert("Please indicate " + descrip);
			}
		obj.focus();
		return false;
		}
	}

function chk_int(obj, descrip, l) {
	if(obj.value.length == 0) {
		if(l==1) {
			alert("Por favor indique " + descrip);
			} else {
			alert("Please indicate " + descrip);
			}
		obj.focus();
		return false;
		}
	if(isinteger(obj.value) == false) {
		if(l==1) {
			alert("Por favor indique sólo números en este campo");
			} else {
			alert("Please indicate only numbers in this field");
			}
		obj.focus();
		return false;
		}
	}

function chk_rad(obj, descrip, l) {
	seleccionado = 0;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked=="1") seleccionado = 1;
		}
	if(seleccionado == 0) {
		if(l==1) {
			alert("Por favor indique " + descrip);
			} else {
			alert("Please indicate " + descrip);
			}
		obj[0].focus();
	//	self.scroll(0,-1)
		return false;
		}
	}

function chk_chk(obj, descrip, l) {
	seleccionado = 0;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked=="1") seleccionado = 1;
		}
	if(seleccionado == 0) {
		if(l==1) {
			alert("Por favor indique " + descrip);
			} else {
			alert("Please indicate " + descrip);
			}
		obj[0].focus();
	//	self.scroll(0,20);
		return false;
		}
	}

function chk_chk_sin_mensaje(obj) {
	seleccionado = 0;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked==true) seleccionado = 1;
		}
	if (seleccionado == 0) {
		return false;
		}
	return true;
	}


function chk_sel(obj, descrip, l) {
	if(obj.selectedIndex == -1) {
		if(l==1) {
			alert("Por favor indique " + descrip);
			} else {
			alert("Please indicate " + descrip);
			}
		obj.focus();
	//	self.scroll(0,-1);
		return false;
		}
	}

function get_date(obj, l) {
	isplit = obj.value.indexOf('-');
	if(l==1) {
		sDay = obj.value.substring(0, isplit);
		if (sDay.length == 0) return false;
		} 
	else {
		sMonth = obj.value.substring(0, isplit);
		if(sMonth.length == 0) return false;
		}
	isplit = obj.value.indexOf('-', isplit + 1);
	if(l==1) {
		sMonth = obj.value.substring((sDay.length + 1), isplit);
		if(sMonth.length == 0) return false;
		} 
	else {
		sDay = obj.value.substring((sMonth.length + 1), isplit);
		if (sDay.length == 0) return false;
		}
	sYear = obj.value.substring(isplit + 1);
	fecha = new Date(sYear, sMonth, sDay);
	return fecha;
	}

function isdate(obj, l) {
	if(obj.value.length == 0)	return false;
	isplit = obj.value.indexOf('-');
	if(isplit == -1 || isplit == obj.value.length)	return false;
	if(l==1) {
		sDay = obj.value.substring(0, isplit);
		if(sDay.length == 0) return false;
		} else {
		sMonth = obj.value.substring(0, isplit);
		if(sMonth.length == 0) return false;
		}
	isplit = obj.value.indexOf('-', isplit + 1);
	if(isplit == -1 || (isplit + 1 ) == obj.value.length)	return false;
	if(l==1) {
		sMonth = obj.value.substring((sDay.length + 1), isplit);
		if(sMonth.length == 0)
			return false;
			} else {
			sDay = obj.value.substring((sMonth.length + 1), isplit);
			if(sDay.length == 0) return false;
			}
	sYear = obj.value.substring(isplit + 1);
	
	if(!isinteger(sMonth)) return false;//check month
	if(!chk_range(sMonth, 1, 12)) return false;//check month
	if(!isinteger(sYear)) return false;//check year
	if(!chk_range(sYear, 1850, 2100)) return false;//check year
	if(!isinteger(sDay)) return false;//check day
	if(!chk_day(sYear, sMonth, sDay)) return false;// check day
	return true;
	}


function isdate_fixed_a_m_d(obj) {
	if(obj.value.length == 0)	return false;
	isplit = obj.value.indexOf('-');
	if(isplit == -1 || isplit == obj.value.length)	return false;
	sYear = obj.value.substring(0, isplit);
	if(sYear.length == 0) return false;
	isplit = obj.value.indexOf('-', isplit + 1);
	if(isplit == -1 || (isplit + 1 ) == obj.value.length)	return false;
	sMonth = obj.value.substring((sYear.length + 1), isplit);
	if(sMonth.length == 0)	return false;
	sDay = obj.value.substring(isplit + 1);
	if(sDay.length == 0) return false;
	if(!isinteger(sMonth)) return false;//check month
	if(!chk_range(sMonth, 1, 12)) return false;//check month
	if (!isinteger(sYear)) return false;//check year
	if (!chk_range(sYear, 1850, 2100)) return false;//check year
	if (!isinteger(sDay)) return false;//check day
	if (!chk_day(sYear, sMonth, sDay)) return false;// check day
	return true;
	}	
	
function chk_day(checkYear, checkMonth, checkDay)  {
	maxDay = 31;
	if (checkMonth == 4 || checkMonth == 6 || checkMonth == 9 || checkMonth == 11) {
		maxDay = 30;
		} else {
		if (checkMonth == 2) {
			if (checkYear % 4 > 0) {
				maxDay =28;
				} else {
				if (checkYear % 100 == 0 && checkYear % 400 > 0) {
					maxDay = 28;
					} else {
					maxDay = 29;
					}
				}
			}
		}
	return chk_range(checkDay, 1, maxDay); //check day
}



function isinteger(object_value) {
	entero = "0123456789";
	for (var i = 0; i < object_value.length; i++) {
		check_char = entero.indexOf(object_value.charAt(i));
		if (check_char < 0) return false;
		}
	return true;
}

function chk_range(object_value, min_value, max_value) {
	// check minimum
	if (min_value != null) {
		if (object_value < min_value)
			return false;
		}
	// check maximum
	if (max_value != null) {
		if (object_value > max_value)
			return false;
		}
	return true;
	}