function BuscarCadenaEnCadena(mivalor,palabra)
	{
	alert(mivalor);
	alert(palabra);
	var mivalor = mivalor;
	var palabra = palabra;
	if(mivalor.indexOf(palabra)!=-1)
		{
			alert(mivalor.indexOf(palabra));
		}
	else
		{
			alert('La frase\n'+ mivalor +' \nNO Contiene la palabra\n'+palabra);
		}
}

function aleatorio(form1)
		{
			var Cadena;
			var Caracter;
			var i;
			var superior;
			var inferior;
			superior=90;
			inferior=48;
			Cadena='Z';
			if (form1.nif.value=='')
				{
				for (i=0;i<=19;i++)
					{
					    aleat= Math.round(Math.random()*(superior-inferior)+inferior);
	    					if (aleat>57 && aleat<65)
	    						{
	    							i=i-1;
	    						}
	    					else
	    						{
	    							Caracter=String.fromCharCode(aleat);
	    							Cadena=Cadena+Caracter;
	    							Caracter='';
	    						}
					}
	    		form1.nif.value=Cadena;
	    		}
		}
function aleatoriomini()
		{
			var Cadena;
			var Caracter;
			var i;
			var superior;
			var inferior;
			superior=57;
			inferior=48;
			Cadena='.';
				for (i=0;i<=3;i++)
					{
					    aleat= Math.round(Math.random()*(superior-inferior)+inferior);
						Caracter=String.fromCharCode(aleat);
	    				Cadena=Cadena+Caracter;
	    				Caracter='';
	    			}
	    		document.getElementById("nombreoperador").value=document.getElementById("nombreoperador").value+Cadena;
		}

function CambiarIdioma(Url, opcion)
{
	var str=String(Url);
	var Posicion;
	var Posicion2;
	var Idioma;
	var NuevaUrl;
	var NuevoIdioma;
	Posicion=str.search(/idioma=/)+7;
		/*if (Posicion!=6 && Posicion!=-1)
			{
				Posicion2=parseInt(Posicion)+3;
				Idioma=str.substr(Posicion, 3);
					if (Idioma!="esp" && opcion==0)
						{
							NuevoIdioma="gal";
						}
					else if (Idioma!="gal" && opcion==1)
						{
							NuevoIdioma="esp";
						}
					else if (Idioma!="ing" && opcion==2)
						{
							NuevoIdioma="ing";
						}
					else if (Idioma!="fra" && opcion==3)
						{
							NuevoIdioma="fra";
						}
					else if (Idioma!="ale" && opcion==4)
						{
							NuevoIdioma="ale";
						}
					else
						{
							NuevoIdioma=Idioma;
						}
					NuevaUrl=str.substr(0, Posicion)+NuevoIdioma+str.substr(Posicion2);
					location.replace(NuevaUrl);
			}
		else
			{*/
				if (opcion==0)
					{
						location.replace("index.php?idioma=esp");
					}
				else if (opcion==1)
					{
						location.replace("index.php?idioma=gal");
					}
				else if (opcion==2)
					{
						location.replace("index.php?idioma=ing");
					}
				else if (opcion==3)
					{
						location.replace("index.php?idioma=fra");
					}
				else if (opcion==4)
					{
						location.replace("index.php?idioma=ale");
					}
			//}
}


function ValidaOperador(form)
		{
			alert (form.esoperador.value);
			//if (form.esoperador.value==)
			if (vacio(form.nombreoperador.value)==false)
				{
					alert("Debe introducir un usuario");
					form.nombreoperador.focus();
				}
			else
				{
					if (form.clave.value==form.clave2.value)
						{
							form.submit();
						}
					else
						{
							alert("Debe introducir la misma clave en los dos campos");
							form.clave.value="";
							form.clave2.value="";
							form.clave.focus();
						}
				}
		}
function valida(form)
	{
	if (vacio(form.nombre.value)==false)
		{
			alert("Debe introducir un usuario");
			form.usuario.focus();
		}
	else
		{
			form.submit();
		}
	}
function vacio(q)
	{
	for ( i = 0; i < q.length; i++ )
		{
			if ( q.charAt(i)!= " ")
			{
				return true
			}
		}
	return false
	}

function RevisarProfesor(form)
	{
	if (vacio(form.nif.value)==false)
		{
			alert("Atencion: El NIF no puede estar en blanco");
			form.nif.focus;
		}
	else
		{
			if (form.esoperador.checked==true)
				{
					if (vacio(form.nombreoperador.value)==false)
						{
							alert("Debe introducir un usuario");
							form.nombreoperador.focus();
						}
					else
						{
							if (form.passoperador.value==form.passoperador2.value)
								{
									form.submit();
								}
							else
								{
									alert("Debe introducir la misma clave en los dos campos");
									form.passoperador.value="";
									form.passoperador2.value="";
									form.passoperador.focus();
								}
						}
				}
			else
			{
				form.submit();
			}
		}
	}

function RevisarOperador (form)
{
	if (form.passoperador.value==form.passoperador2.value)
	{
		form.submit();
	}
else
	{
		alert("Debe introducir la misma clave en los dos campos");
		form.passoperador.value="";
		form.passoperador2.value="";
		form.passoperador.focus();
	}
}

function UsuarioGrupo(form, numero)
	{
		var numero;
			if (numero==1)
				{
					if (document.form1.SiGrupo.checked==true)
						{
							document.form1.SiPersona.disabled=true;
						}
					else
						{
							document.form1.SiPersona.disabled=false;
						}
				}
			else
				{
					if (document.form1.SiPersona.checked==true)
						{
							document.form1.SiGrupo.disabled=true;
						}
					else
						{
							document.form1.SiGrupo.disabled=false;
						}
				}
	}

function EnviarMensaje(form)
	{
		var Mensaje;
		var Enviar;
		var entrar;
			if (document.form1.SiGrupo.checked==true)
				{
					Mensaje="a un grupo";
					Enviar=1;
				}
			else if (document.form1.SiPersona.checked==true)
				{
					Mensaje="a una persona";
						if (document.form1.movil.value!="")
							{
								Enviar=1;
							}
						else
							{
								Enviar=0;
							}
				}
			
			if (Enviar==1)
				{
					Mensaje="Atencion: Se enviara un mensaje "+Mensaje+" Desea continuar?";
					var entrar = confirm(Mensaje);
						if ( entrar )
							{
								if (document.form1.texto.value=="")
									{
										alert('No hay nada que enviar!');
										document.form1.texto.focus();
									}
								else
									{
										form.submit();
									}
							}
				}
			else
				{
					Mensaje="Tiene que seleccionar como destinatario a un grupo o a una persona!";
					alert (Mensaje);
				}
	}

function SiNo(f)
{
	//var SN=document.getElementById("OperadorSiNo").value;
	//alert (SN);
	if (document.getElementById("esoperador").checked==true)
	//if (SN=='on')
		{
			document.getElementById("nombreoperador").disabled=false;
			document.getElementById("passoperador").disabled=false;
			document.getElementById("niveloperador").disabled=false;
			document.getElementById("nombreoperador").value=document.getElementById("nombre").value;
			aleatoriomini();
			//BuscarCadenaEnCadena(document.getElementById("apellidos").value, "");

		}
	else
		{
			document.getElementById("nombreoperador").disabled=true;
			document.getElementById("passoperador").disabled=true;
			document.getElementById("niveloperador").disabled=true;
		}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//NUEVAS FUNCIONES****************************************************************************************************************************
//FIN DE NUEVAS FUNCIONES****************************************************************************************************************************
	function abreventana(theURL,winName,features)
	{ //v2.0
		window.open(theURL,winName,features);
	}
	function Habla(form1, tipo)
	{
		if (tipo==1)
			{
				document.form1.prueba.value=document.form1.menu.options[document.form1.menu.selectedIndex].text;
			}
		else if (tipo==2)
			{
				document.form1.prueba.value=document.form1.menu.options[document.form1.menu.selectedIndex].text+" "+document.form1.submenu.options[document.form1.submenu.selectedIndex].text;
			}
		else
			{
				document.form1.prueba.value=document.form1.menu.options[document.form1.menu.selectedIndex].text+" "+document.form1.submenu.options[document.form1.submenu.selectedIndex].text+" "+document.form1.model_name.value;
			}
	}
	function RevisaAnunciante(busqueda_clientes)
	{
		if (document.busqueda_clientes.menu2.value!=-1)
			{
				busqueda_clientes.submit();
			}
		else
			{
				alert("Tiene que elegir una provincia y un cliente!");
			}
	}
	function fecha()
	{
		var mydate=new Date()
		var year=mydate.getYear()
		if (year < 1000)
		year+=1900
		var day=mydate.getDay()
		var month=mydate.getMonth()
		var daym=mydate.getDate()
		var dayarray=new Array("Domingo","Lunes","Martes","Mircoles","Jueves","Viernes","Sbado")
		var montharray=new Array("enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre")
		document.write("<font class='infosistema'>"+dayarray[day]+", "+daym+" de "+montharray[month]+" de "+year+"</font>")
	}
	function FechaPortada()
	{
		var mydate=new Date()
		var year=mydate.getYear()
		if (year < 1000)
		year+=1900
		var day=mydate.getDay()
		var month=mydate.getMonth()
		var daym=mydate.getDate()
		if (day<10)
		day="0"+day
		if (month<10)
		month="0"+month
		document.write("<label class='label2'>"+daym+"/"+month+"/"+year+"</font>")
	}
	function Confirma(form, opcion)
		{
			if (opcion==3)
			{
				var mensaje="ATENCION: Se eliminara un elemento\nDesea continuar?"

			}
			else if(opcion==2)
			{
				var mensaje="ATENCION: Se modificara un elemento\nDesea continuar?"
			}
			else if (opcion==1)
			{
				var mensaje="ATENCION: Asignar o no asignar funciones de profesor o padre a un usuario \n puede modificar sensiblemente la base de datos. \n Desea continuar?"
			}
			else if (opcion==4)
			{
				var mensaje="ATENCION: Emitirase un voto. So pode votar unha vez. \n Desexa continuar?"
			}
			var entrar = confirm(mensaje);
			if ( entrar )
				{
				form.submit();
				}

		}
	function FocoForm1(id)
		{
			if (id==52)
				{
					document.forms.form1.cliente.focus();
				}
		}
	function NuevoMenu(menu) {
    for (i=0; i<menu_principal.length; i++){
        if(menu_principal[i]['txt'] == menu){
            PopulateSubMenu(menu_principal[i]['submenu']);
        }
    }
    return;
}
function PopulateSubMenu(valores){
    document.forms[0].submenu.options.length=0
    for (j=0; j<valores.length; j++){
        document.forms[0].submenu.options[j]=valores[j];
    }
}

function NuevoMenu2(menu2) {
    for (i=0; i<menu_principal2.length; i++){
        if(menu_principal2[i]['txt'] == menu2){
            PopulateSubMenu2(menu_principal2[i]['submenu2']);
        }
    }
    return;
}
function PopulateSubMenu2(valores2){
    document.forms[1].id.options.length=0
    for (j=0; j<valores2.length; j++){
        document.forms[1].id.options[j]=valores2[j];
    }
}

function NuevoMenu3(menu) {
    for (i=0; i<menu_principal.length; i++){
        if(menu_principal[i]['txt'] == menu){
            PopulateSubMenu3(menu_principal[i]['submenu']);
        }
    }
    return;
}
function PopulateSubMenu3(valores){
    document.forms[2].submenu.options.length=0
    for (j=0; j<valores.length; j++){
        document.forms[2].submenu.options[j]=valores[j];
    }
}


function SituarFoco() {
if (document.forms.length > 0) {
var field = document.forms[0];
for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[0].elements[i].focus();
break;
         }
      }
   }
}

function FormatoMoneda(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+'.'+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-')+ num + ',' + cents + ' ');
}

function FormatoNumero(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+'.'+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-')+ num);
}

function refreshImg()
		{
			document.form1.picture.src = 'file:///'+ document.form1.imagen1.value;
		}

function ComprobarVehiculo(form1, tipo)
{
	var EnviarFormulario=true;
	var Error='';
	var Entrada=0;
	if (isNaN(document.form1.price1.value)==false)
		{
			Entrada=1;
		}
	else
		{
			Error="Precio\n";
		}
	if (isNaN(document.form1.car_engine.value)==false)
		{
			Entrada=Entrada+1;
		}
	else
		{
			Error=Error + "Potencia\n";
		}
	if (isNaN(document.form1.mileage.value)==false)
		{
		Entrada=Entrada+1;
		}
	else
		{
			Error=Error + "Kilmetros";
		}
	if (Entrada==3)
	{
			if (document.form1.menu.value=='')
				{
					Error="Marca de vehculo\n";
					EnviarFormulario=false;
				}
			if (document.form1.submenu.value=='')
				{
					Error=Error + "Modelo de vehculo\n";
					EnviarFormulario=false;
				}
			if (document.form1.user_id.value=='')
				{
					Error=Error + "Nombre de cliente\n";
					EnviarFormulario=false;
				}
			if (document.form1.tipo_vehiculo.value=='')
				{
					Error=Error + "Tipo de vehculo\n";
					EnviarFormulario=false;
				}
			if (tipo==0)
				{
				if (document.form1.imagen1.value=='')
					{
						Error=Error + "Imagen Principal";
						EnviarFormulario=false;
					}
				}
			if (EnviarFormulario==false)
				{
					alert("ATENCIN: Error en campo(s) requerido(s):\n"+Error);
				}
			else
				{
					form1.submit();
				}
	}
	else
	{
		alert("ATENCIN: Error en campo(s) NUMRICO(S):\n"+Error);
	}
}

function CargarImagen()
	{
		var logo;
		logo=document.form1.posicion.value;
		document.form1.vistaposicion.src="../images/publicidad/posiciones/"+logo+".gif";
	}
function CargarImagen2(imagen, ruta)
	{
		var imagen2;
		imagen2=ruta+imagen;
		document['fotocentral'].src=imagen2;
	}
function jooImage(target,fname)
{
    document[target].src=fname;
}
function ComprobarNumero(text)
{
	if((text>=48 && text<=57) || (text>=96 && text<=105) || (text==9) || (text==8))
	{}
	else
	{
		alert("CAMPO NUMRICO!")
	}

}

function ValidaContacto(form, tipo)
{
	var EnviarFormulario=0;
	var Error='';
	var Nombre;
	var Email;
	var Telf;
	if (tipo==1)
		{
			Nombre=document.form1.nombre.value;
			Email=document.form1.email.value;
			Telf=document.form1.telf.value;
		}
	else
		{
			Nombre=document.form2.nombre.value;
			Email=document.form2.email.value;
			Telf=document.form2.telf.value;
		}
	if (Nombre=='')
		{
			Error="- Nombre de contacto\n";
			EnviarFormulario=1;
		}
	if (Email=='')
		{
			Error=Error +"- Email\n";
			EnviarFormulario=EnviarFormulario+0.5;
		}
	else
		{
			if (tipo==1)
				{
				emailCheck(document.form1.email.value);
				}
			else
				{
				emailCheck(document.form2.email.value);
				}
			EnviarFormulario=EnviarFormulario+0.5;
		}
	if (Telf=='')
		{
			Error=Error +"- Telefono\n";
			EnviarFormulario=EnviarFormulario+0.5;
		}
	if (EnviarFormulario<1)
		{
			form.submit();
		}
	else
		{
			alert("ATENCIN: Error en campo(s) requerido(s):\n"+Error+"Tenga en cuenta que necesitamos su email o telfono para contactar con usted");
		}
}

function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("La direccin de correo parece incorrecta (verifique @ y .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("El nombre de usuario contiene caracteres no vlidos");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Este nombre de dominio contiene caracteres no vlidos");
return false;
   }
}

// See if "user" is valid

if (user.match(userPat)==null) {

// user is not valid

alert("El nombre de usuario no parece vlido");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("La direccin IP de destino no es vlida");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("El nombre de dominio no parece vlido");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("La direccin de correo no parece vlida");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("Error no especificado en la direccin de correo");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//  End -->

