function generic_test (checkMe,messtxt) {
	var theResult = true;
	if (checkMe.value == "" || checkMe.value == "undefined" || checkMe.value == "null") {
		alert(messtxt);
		theResult = false;
		checkMe.focus();
		checkMe.select();
	}
	return theResult;
}

function select_test (checkMe,messtxt) {
	var theResult = true;
	if (checkMe.value == "" || checkMe.value == "undefined" || checkMe.value == "null") {
		alert(messtxt);
		theResult = false;
		checkMe.focus();
	}
	return theResult;
}

function email_test (checkMe,messtxt) {
	var theResult = true;
	if (checkMe.value.indexOf('@') == -1 || checkMe.value.indexOf('.') == -1 || checkMe.value == "" || checkMe.value == "undefined" || checkMe.value == "null") {
		alert(messtxt);
		theResult = false;
		checkMe.focus();
		checkMe.select();
	}
	return theResult;
}

function numeric_test(checkMe,messtxt) {
	var theResult = true;
	if (checkMe.value == "" || checkMe.value == "undefined" || checkMe.value == "null" || isNaN(checkMe.value)) {
		alert(messtxt);
		theResult = false;
		checkMe.focus();
		checkMe.select();
	}
	return theResult;
}

function repassword_test (checkMe,recheckMe,messtxt) {
	var theResult = true;
	if (recheckMe.value == "" || recheckMe.value == "undefined" || recheckMe.value == "null" || recheckMe.value != checkMe.value) {
		alert(messtxt);
		theResult = false;
		recheckMe.focus();
		recheckMe.select();
	}
	return theResult;
}

function redirect(url) {
	window.location = url;
}

function getObj(obj) {
	return (document.getElementById(obj));
}

function replace(strOrig, strBuscar, strNew) {
	ret = strOrig;
	while (ret.indexOf(strBuscar) > -1)
	{
		pos = ret.indexOf(strBuscar);
		ret = "" + (ret.substring(0, pos) + strNew + ret.substring((pos + strBuscar.length), ret.length));
	}
	return ret;
}

//convierte a minusculas.
function low(val) {
	return (empty(val) ? val : val.toLowerCase());
}
//convierte a mayusculas.
function upp(val) {
	return (empty(val) ? val : val.toUpperCase());
}



// SORTORDER
function moveUp() {   
	var actual = document.combo_box.champs.selectedIndex;
	if (actual == -1) {
		alert("Please select an article before moving it.");}
		else {
			if (actual == 0) alert("Article is already at the top of the list");
				else {
					var value_actual = document.combo_box.champs.options[actual].value;
					var texto_actual = document.combo_box.champs.options[actual].text;
					var targetposition = actual - 1;
					var value_target = document.combo_box.champs.options[targetposition].value;
					var texto_target = document.combo_box.champs.options[targetposition].text;
					// poner el actual en target
					document.combo_box.champs.options[targetposition].value=value_actual;
					document.combo_box.champs.options[targetposition].text=texto_actual;
					
					//poner target en actual
					document.combo_box.champs.options[actual].value=value_target;
					document.combo_box.champs.options[actual].text=texto_target;
					document.combo_box.champs.options[targetposition].selected=true;
					
					// actualizar el hidden
					var reordena="";
					for (var i=0; i < document.combo_box.champs.length; i++) {
						reordena = reordena + document.combo_box.champs.options[i].value;
						if(i<document.combo_box.champs.length-1) {reordena=reordena + ",";}
					}
					document.combo_box.elements[0].value=reordena;
				}
		
		}
	}
	
function moveDown() {   
	var actual = document.combo_box.champs.selectedIndex;
	if (actual == -1) {
		alert("Please select an article before moving it.");}
		else {
			if (actual == document.combo_box.champs.length-1) alert("Article is already at the bottom of the list");
				else {
					var value_actual = document.combo_box.champs.options[actual].value;
					var texto_actual = document.combo_box.champs.options[actual].text;
					var targetposition = actual + 1;
					var value_target = document.combo_box.champs.options[targetposition].value;
					var texto_target = document.combo_box.champs.options[targetposition].text;
					// poner el actual en target
					document.combo_box.champs.options[targetposition].value=value_actual;
					document.combo_box.champs.options[targetposition].text=texto_actual;
					
					//poner target en actual
					document.combo_box.champs.options[actual].value=value_target;
					document.combo_box.champs.options[actual].text=texto_target;
					document.combo_box.champs.options[targetposition].selected=true;
					
					// actualizar el hidden
					var reordena="";
					for (var i=0; i < document.combo_box.champs.length; i++) {
						reordena = reordena + document.combo_box.champs.options[i].value;
						if(i<document.combo_box.champs.length-1) {reordena=reordena + ",";}

					}
					document.combo_box.elements[0].value=reordena;
				}
		
		}
	}
