/* $Id: functions.js,v 1.01 */
	//
	function form_control(theForm) {
		if (theForm.email.value.length == 0 ) {
			alert( "Favor de ingresar el Email." );
			theForm.email.focus();
			return false;
		} else {
			if (!Verificar_email(theForm.email.value)) {
				alert("<< La Dirección de EMAIL no es válida. >>\n\nAsegúrese de introducir sólo letras minúsculas \ny de que el dato no este vacío.");
				theForm.email.focus();
				return false;
			}
		}

		if (!theForm.password.disabled) {				
			if ( theForm.password.value.length == 0 ) {
			  alert( "Favor de ingresar la Contraseña." );
			  theForm.password.focus();
			  return false;
			}
		}		
		//theForm.submit();
		return true;
	}
	// end function form_control
	//
	function form_control_lic(form_control) {
		var mensaje = "Por favor confirme los datos:\n\n";
		
		if ( form_control.serieG1.value.length == 0 ) {
			alert( "Favor de ingresar el No. de Serie.");
			form_control.serieG1.focus();
			return false;
		} else if ( form_control.serieG2.value.length == 0 ) {
			alert( "Favor de ingresar el No. de Serie." );
			form_control.serieG2.focus();
			return false;			  
		} else if ( form_control.serieG3.value.length == 0 ) {
			alert( "Favor de ingresar el No. de Serie." );
			form_control.serieG3.focus();
			return false;
		}
		
		if (form_control.name == "activacion" || form_control.name == "transferencia" ) {
			if ( form_control.noControl.value.length == 0 ) {
			  alert( "Favor de ingresar el No. de Control." );
			  form_control.noControl.focus();
			  return false;
			}			
		}
		
		if (form_control.name == "transferencia" ) {
			if (form_control.cveDesactivacion.value.length == 0){
				alert("Favor de ingresar la Clave de Desactivación");
				form_control.cveDesactivacion.focus();
				return false;
			}
		}				
		
		mensaje = mensaje +"No. Serie:   "+form_control.serieG1.value+"-"+form_control.serieG2.value+"-"+form_control.serieG3.value;		
		if (form_control.name == "activacion" || form_control.name == "transferencia" ) {
			mensaje = mensaje +"\nNo. Control:   "+form_control.noControl.value;
		}
		if (form_control.name == "transferencia" ) {
			mensaje = mensaje +"\nClave de Desactivacion:   "+form_control.cveDesactivacion.value;
		}
		mensaje = mensaje +"\n\n¿Son correctos?";
		
		if (!confirm(mensaje)) {
			return false;
		}
		
		form_control.submit();
		return true;	
	}
	// end function form_control_lic
	//
	function control_Solicitud(theForm) {
		
		if ( theForm.name.value.length == 0 ) {
			alert( "Favor de ingresar el Nombre." );
			theForm.name.focus();
			return false;
		}
		
		if ( theForm.apaterno.value.length == 0 ) {
			alert( "Favor de ingresar el Apellido Paterno." );
			theForm.apaterno.focus();
			return false;
		}

		if ( theForm.amaterno.value.length == 0 ) {
			alert( "Favor de ingresar el Apellido Materno." );
			theForm.amaterno.focus();
			return false;
		}
		//Registro ***
		if ( theForm.email ) {
			if ( theForm.email.value.length == 0 ) {
				alert( "Favor de ingresar el Email." );
				theForm.email.focus();
				return false;
			} else {
				if (!Verificar_email(theForm.email.value)) {
					alert("<< La Dirección de EMAIL no es válida. >>\n\nAsegúrese de introducir sólo letras minúsculas \ny de que el dato no este vacío.");
					theForm.email.focus();
					return false;
				}
			}
		}
		//Solicitud ***
		if ( theForm.txt_memo ) {
			if ( theForm.txt_memo.value.length == 0 ) {
				alert( "Favor de ingresar el detalle de su problema." );
				theForm.txt_memo.focus();
				return false;
			}
		}
		theForm.submit();
		return true;
	}
	//end function control_Solicitud()	
	//
	function control_busqueda(theForm) {
		var seleccionado = false;
		
		for ( i=0; i<theForm.RGtemas.length; i++ ) {
			if ( theForm.RGtemas[i].checked ) {
				seleccionado = true;
			}
		}

		if ( theForm.clave.value.length == 0 && seleccionado == false ) {						
			alert( "Introduzca una palabra clave o tema de su interes \npara realizar su busqueda." );
			theForm.clave.focus();
			return false;
		} else if (theForm.clave.value.length > 0 && seleccionado == true ) {
			alert( "Unicamente es posible realizar un tipo de busqueda a la vez.\n\n 1).- Búsqueda por palabra Clave. \n 2).- Búsqueda por Tema. \n\nPor favor intente nuevamente." );
			theForm.reset();
			return false;
		}
				
		theForm.submit();
		return true;		
	}
	//end function control_busqueda()
	//
	function remem_pw(theForm) {
		if ( theForm.email.value.length == 0 ) {
			alert( "Favor de ingresar el Email." );
			theForm.email.focus();
			return false;
		}
		theForm.submit();
		return true;
	}
	//end function remem_pw
	//
	function Verificar_email(email) {
		// var mayusculas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		 var minusculas = "abcdefghijklmnopqrstuvwxyz";
		 var numeros = "1234567890";
		 var especiales = "@_.-";
		 var valido = false;
		 var arrobas = 0;
		 var posicion_arroba = 0;
		 var puntos = 0;
		 var c = 0;
	
		for (n=0; n<email.length; n++) {
			if ((numeros.indexOf(email.charAt(n)) == -1)&&
				//(mayusculas.indexOf(email.charAt(n)) == -1)&&
				(minusculas.indexOf(email.charAt(n)) == -1)&&
				(especiales.indexOf(email.charAt(n)) == -1)) {
				return (valido);
			}
			if (email.charAt(n)=="@") {
				posicion_arroba = email.indexOf("@");
				arrobas++;
			}
			if (email.charAt(n)==".") {
				puntos++;
			}
		}
	 
		if (arrobas != 1) {
			return (valido);
		} else if (puntos < 1) {
			return (valido);
		} else if ((email.charAt(c) == "@")||
			(email.charAt(c) == "_")||
			(email.charAt(c) == ".")) {
			return (valido);
		} else {
			valido = true;
		}
		return (valido);
	}
//end function Verificar_email

	var isNN = (navigator.appName.indexOf("Netscape")!=-1);

	function autoTab(input,len, e) {
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		//alert(navigator.appName.indexOf("Netscape"));
		if(input.value.length >= len && !containsElement(filter,keyCode)) {
			input.value = input.value.toUpperCase();
			input.value = input.value.slice(0, len);
			//alert(input.form[(getIndex(input)+1) % input.form.length].type);
			input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		//alert(ele);
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input) index = i;
			else i++;
		return index;
	}
	return true;
}