/**************************************
Creado por: autosbol.com
Referencias a: webmaster@autosbol.com
**************************************/
var cabecera = "------------- SMS PLUS -------------\n\n";
var	fin = "\n---------------------------------";

function comprobarFormulario_nuevocontacto(form) {
	aviso = "";
	if (form.nick_contacto.value=="") {
		aviso += "- Ingrese el nick que asignara a su contacto.\n";
	}
	if((form.celular_contacto.length == 0) || form.celular_contacto.value == "número") {
		aviso += "- Ingrese el NÚMERO de celular.\n";

	}	else
		if (!checkLength("celular_contacto",8,8)) {
			aviso += "- Ingrese el NÚMERO con sus 8 digitos.\n";
		}
		else
			if (!verificarNumero(form.celular_contacto)) {
				aviso += "- El NÚMERO no debe tener letras.\n";
			}
			else
				if(!verificarCelular(form.celular_contacto.value)) {
					aviso += "- El NÚMERO de celular esta mal ingresado,\n  porque no corresponde a un\n  operador de telefonía nacional.\n";
				}
	if (form.nombre_contacto.value=="") {
		aviso += "- Ingrese el nombre de su contacto.\n";
	}
	if(aviso.length > 0) {
		alert(cabecera+aviso+fin);
		return false;
	}
	return true;
}

function comprobarFormulario_sms(form) {
	aviso = "";
	if (form.nombre.value=="") {
		aviso = "- Ingrese su NOMBRE.\n";
	}
	if((form.celular.length == 0) || form.celular.value == "número") {
		aviso += "- Ingrese el NÚMERO de celular.\n";
	}
	else
		if (!checkLength("celular",8,8)) {
			aviso += "- Ingrese el NÚMERO con sus 8 digitos.\n";
		}
		else
			if (!verificarNumero(form.celular)) {
				aviso += "- El NÚMERO no debe tener letras.\n";
			}
			else
				if(!verificarCelular(form.celular.value)) {
					aviso += "- El NÚMERO de celular esta mal ingresado,\n  porque no corresponde a un\n  operador de telefonía nacional.\n";
				}
	if((form.mensaje.value == "") || (form.mensaje.value == null)){
		aviso += "- Ingrese su MENSAJE.\n";
	}
	/*
	if (form.imagen_codigo.value == "") {
		aviso += "- Ingrese el código.\n";
	}
	else
		if (form.imagen_codigo.value.length != 5)
			aviso += "- El código debe tener 5 caracteres\n";
			*/
	if(aviso.length > 0) {
		alert(cabecera+aviso+fin);
		return false;
	}
	else {
		var t = Math.floor(Math.random()*1500);
		tiempo = 3500+t;
		if(form.micelu.value != null)
			tiempo = 4000+t;
		replaceChar(form.mensaje);
		document.getElementById('enproceso').style.display="block";
		document.getElementById('mensajesms').style.display="none";
		setTimeout("Registrados()",tiempo);
		
	}
}

function Registrados(){
	agregarRegistro();
	document.getElementById('enproceso').style.display="none";
	document.getElementById('mensajesms').style.display="block";
}

function agregarRegistro(){
	form = document.getElementById('formsoftbol');
	oper_celu = operadora(document.formsoftbol.celular.value);
	envio = '<div class="mensajeenviado"><b>Destino: </b>';
	envio += form.celular.value+"&nbsp;&nbsp;&nbsp;<b>Empresa: </b>"+oper_celu;
	if (document.formsoftbol.micelu.checked) {
		envio += "&nbsp;&nbsp;&nbsp;<b>CopySMSWEB</b>";
		document.formsoftbol.micelu.checked = false;
	}
	envio += '<br /><b>Mensaje: </b>'+form.nombre.value+"> "+form.mensaje.value+'</div>';
	cache = document.getElementById("mensajesms").innerHTML;
	document.getElementById("mensajesms").innerHTML = envio+cache;
}

function enviarSmsContacto(celular, nombre) {
	document.formsoftbol.contactocelular.value = celular;
	document.formsoftbol.contactonick.value = nombre;
	document.formsoftbol.submit();
}

function eliminarContacto(cod, nombre) {
	if(confirm("Esta apunto de eliminar a "+nombre+", desea continuar?")) {
		document.formsoftbol.contactoeliminar.value = cod;
		document.formsoftbol.submit();
	}
}

function comprobarFormulario_agenda(form) {
	aviso = "";
	if (form.nombre.value=="") {
		aviso = "- Ingrese su NOMBRE.\n";
	}
	if((form.celular.length == 0) || form.celular.value == "número") {
		aviso += "- Ingrese el NÚMERO de celular.\n";

	}	else
		if (!checkLength("celular",8,8)) {
			aviso += "- Ingrese el NÚMERO con sus 8 digitos.\n";
		}
		else
			if (!verificarNumero(form.celular)) {
				aviso += "- El NÚMERO no debe tener letras.\n";
			}
			else
				if(!verificarCelular(form.celular.value)) {
					aviso += "- El NÚMERO de celular esta mal ingresado,\n  porque no corresponde a un\n  operador de telefonía nacional.\n";
				}
	if((form.mensaje.value == "") || (form.mensaje.value == null)){
		aviso += "- Ingrese su MENSAJE.\n";
	}
	if(aviso.length > 0) {
		alert(cabecera+aviso+fin);
		return false;
	}
	else {
		replaceChar(form.mensaje);
		document.getElementById('enproceso').style.display="block";
		document.getElementById('mensajesms').style.display="none";
		setTimeout("Registrados()",670);
	}
}

function comprobarFormulario(form) {
	var aviso = "";
	var tipo = 2; //email
	if (form.login.value.length == 0) {
		aviso += "- Ingrese su e-mail o número de celular.\n";
	}

	else {
		if (verificarNumero(form.login)) {
			tipo = 1; //celular
			if (!verificarCelular(form.login.value)) {
				aviso += "- El NÚMERO de celular esta mal ingresado,\n  porque no corresponde a un\n  operador de telefonía nacional.\n";
			}
		}
		else {
			if (!checkMail(form.login.value)) {
				aviso += "- El e-mail esta mal ingresado.\n";
			}
		}
	}
	if (form.password.value.length == 0) {
		aviso += "- Ingrese el password.\n";
	}
	if (aviso.length > 0) {
		alert(cabecera+aviso+fin);
		return false;
	}
	form.tipo.value = tipo;
	return true;
}

function comprobarFormulario_paso1(form) {
	var aviso = "";
	var tipo = 2; //email
	if (form.login.value.length == 0) {
		aviso += "- Ingrese su e-mail o número de celular.\n";
	}
	
	else {
		if (verificarNumero(form.login)) {
			tipo = 1; //celular
			if (!verificarCelular(form.login.value)) {
				aviso += "- El NÚMERO de celular esta mal ingresado,\n  porque no corresponde a un\n  operador de telefonía nacional.\n";
			}
		}
		else {
			if (!checkMail(form.login.value)) {
				aviso += "- El e-mail esta mal ingresado.\n";
			}
		}
	}
	if (form.imagen_codigo.value == "") {
		aviso += "- Ingrese el código.\n";
	}
	else
		if (form.imagen_codigo.value.length != 6)
			aviso += "- El código debe tener 6 caracteres\n";
	if (aviso.length > 0) {
		alert(cabecera+aviso+fin);
		return false;
	}
	form.tipo.value = tipo;
	return true;
}
function comprobarFormulario_paso3(form) {
	var aviso = "";
	if (form.password.value.length < 5) {
		aviso += "- Ingrese el password minimo de 5 caracteres.\n";
	}
	else
		if (form.password.value != form.repassword.value) {
			aviso += "- La repetición del password no coincide.\n";
		}
	if (form.nick.value.length == 0) {
		aviso += "- Ingrese su nick.\n";
	}
	if (form.nombre.value.length == 0) {
		aviso += "- Ingrese su nombre.\n";
	}
	if (aviso.length > 0) {
		alert(cabecera+aviso+fin);
		return false;
	}
	return true;
}

function checkMail(cadena) {
    if (cadena.indexOf("@") != -1)
		return true;
	else {
		return false;
	}
}

function verificarCelular(numero) {
	if ((numero<70000000) || ((numero>=74000000) && (numero <77000000)) || (numero>=78000000)) {
		return false;
	}
	return true;
}

function operadora(numero) {
	if((numero>=70000000) && (numero<70900000)) {
		//operador: viva || prefijo 700 a 708
		return "Viva";
	}
	else
		if((numero>=70900000) && (numero<71000000)) {
			//operador: cotas || prefijo 709
			return "Cotas";
		}
		else
			if((numero>=71000000) && (numero<74000000)) {
				//operador: entel || prefijo 710 a 739
				return "Entel";
			}
			else
				if((numero>=77000000) && (numero<78000000)) {
					//operador: telecel || prefijo 770 a 779
					return "Telecel";
				}
}
function verificarNumero(n) {
	var digitos = "0123456789";
	var num_celular = n.value;
	var valid = true;
	for (i = 0;  i < num_celular.length;  i++)
	{
		ch = num_celular.charAt(i);
		for (j = 0;  j < digitos.length;  j++)
			if (ch == digitos.charAt(j))
				break;
		if (j == digitos.length)
		{
			valid = false;
			break;
		}
	}
	return valid;
}
function checkLength (fieldName, minNumDigits, maxNumDigits) {
		field = eval("document.formsoftbol." + fieldName + ".value");
		if (field.length < minNumDigits) {
			return false;
		}
		if (field.length > maxNumDigits) {
			return false;
		}
		return true;
	}

function revisarSms(obj) {
		c = obj.value.length;
		t = 118;
		if (c > t ) {
			obj.value = obj.value.substring(0,t);
			contador = 0;
		}
		else contador = t - c;
		document.formsoftbol.contador.value = contador;
	}
	
function replaceChar(obj){
	var str = obj.value;
	str = str.replace(/á/g,'a');
	str = str.replace(/é/g,'e');
	str = str.replace(/í/g,'i');
	str = str.replace(/ó/g,'o');
	str = str.replace(/ú/g,'u');
	str = str.replace(/Á/g,'A');
	str = str.replace(/É/g,'E');
	str = str.replace(/Í/g,'I');
	str = str.replace(/Ó/g,'O');
	str = str.replace(/Ú/g,'U');
	str = str.replace(/Ñ/g,'n');
	str = str.replace(/ñ/g,'n');
	str = str.replace(/\n/g,' ');
	obj.value = str;
}

function validarCelular(form) {
	numerocelular = form.celular.value;
	if(((numerocelular.length < 1) && (numerocelular.length > 7)) || (numerocelular == "número")) {
		form.celular.value='';
	}
}

function comentarioAmor(form) {
	var tipocontenido=new Array("[--- Sección Amor ---]","te amo","eres mi todo","tu y yo juntos por siempre","desde que te ví no dejo de pensar ni un solo momento en tí");
	seleccionNombres=eval("tipocontenido");
	cuantos_add=seleccionNombres.length;
	form.comentario.length=cuantos_add;
	for(i=0;i<cuantos_add;i++){
		form.comentario.options[i].value=i;
		form.comentario.options[i].text=seleccionNombres[i];
		if (seleccionNombres[i]=="<!-- STATEID -->") 
		{
			form.comentario.options[i].selected = true;
		}
	}
}
function comentarioEspecial(form) {
	var tipocontenido=new Array("[--- Sección Especial ---]","superfiesta, rebuena honda no faltes","apuesto a que mi equipazo gana!!!","ven te esperamos en");
	seleccionNombres=eval("tipocontenido");
	cuantos_add=seleccionNombres.length;
	form.comentario.length=cuantos_add;
	for(i=0;i<cuantos_add;i++){
		form.comentario.options[i].value=i;
		form.comentario.options[i].text=seleccionNombres[i];
		if (seleccionNombres[i]=="<!-- STATEID -->") 
		{
			form.comentario.options[i].selected = true;
		}
	}
}
function agregarComentario(form) {
	msg = form.mensaje.value;
	if(msg.length != 0) {
		msg = msg+" ";
	}
	num = form.comentario.value;
	texto = form.comentario.options[num].text;
	form.mensaje.value = msg+texto;
}
function copiarCelular(form) {
	form.celular.value = form.copy_celu.value;
}
/*
*/
