function trim(cadena) {
	var arreglo = cadena.split(" ");
	var cadena = "";

	for (var z=0; z<arreglo.length; z++) {
		cadena += arreglo[z];
		if (arreglo[z].length!=0) {
			if (z+1 < arreglo.length) {
				cadena += " ";
			}
		}
	}

	if (cadena.length>0) {
		if (cadena.charAt(cadena.length-1) == " ") {
			cadena = cadena.substr(0, cadena.length-1);
		}
	}

	return cadena;
}


function checkNumeroNextel(campo, alertVacio) {
	//var series = new Array("81", "83");
	var series = new Array("981", "982", "983","940","941","942");
	
	//var cant_digitos = 7;
	var cant_digitos = 8;

	if (trim(campo.value).length==0) {
		if(alertVacio) {
			alert("Ingrese un numero de telefono Nextel o elija un grupo (si lo tiene)");
			campo.focus();
			return false;
		} else {
			campo.value = "";
			return true;
		}
	}

	if (campo.value.indexOf(" ")!=-1 || campo.value.length!=cant_digitos) {
		alert("Numero erroneo");
		campo.focus();
		return false;
	} else {
		for (var i=0; i<campo.value.length; i++) {
			if (isNaN(campo.value.charAt(i))) {
				alert("Numero erroneo");
				campo.focus();
				return false;
			}
		}
	}

	var serie = campo.value.substr(0, cant_digitos - 5);

	for (var i=0; i<series.length; i++) {
		if (serie == series[i]) {
			return true;
		}
	}

	alert("El numero ingresado no es de las series nextel");
	campo.focus();
	return false;
}

function checkNumeroNextel_simple(campo) {
	//var series = new Array("81", "83");
	//var series = new Array("981", "982", "983","940","941","942");
	var series = new Array("9981", "9982", "9983","9940","9941","9942","9810","9811","9812","9813","9814","9815" );

	//var cant_digitos = 7;
	//var cant_digitos = 8;
	var cant_digitos = 9;

	if (trim(campo.value).length==0) {
		alert("Por favor ingrese un numero");
		campo.value = "";
		return false;
	}

	if (campo.value.indexOf(" ")!=-1 || campo.value.length!=cant_digitos) {
		alert("Numero erroneo");
		campo.focus();
		return false;
	} else {
		for (var i=0; i<campo.value.length; i++) {
			if (isNaN(campo.value.charAt(i))) {
				alert("Numero erroneo");
				campo.focus();
				return false;
			}
		}
	}

	var serie = campo.value.substr(0, cant_digitos - 5);

	for (var i=0; i<series.length; i++) {
		if (serie == series[i]) {
			return true;
		}
	}

	alert("El numero ingresado no es de las series Nextel");
	campo.focus();
	return false;
}

function buscarRepetidos(arreglo) {
	var cont = 0 ;
	for (var x=0; x<arreglo.length; x++) {
		cont = 0;
		for (var xx=0; xx<arreglo.length; xx++) {
			if(arreglo[x]==arreglo[xx]) {
				++cont;
			}
			if (cont>1) {
				return true;
			}
		}
	}

	return false;
}

/*
function isInteger(s){
	var i;
    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    for (i = 0; i < s.length; i++){
	var c = s.charAt(i);
	if (!isDigit(c)) return false;
	}
    return true;
}

function isDigit(c){
	return ((c >= "0") && (c <= "9"))
}

function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

*/


