function openChat(codSitio){
	var ancho = 330;
	var alto = 190;
	var izda = Math.ceil((screen.width-ancho)/2);
	var arri = Math.ceil((screen.height-alto)/2);
	window.open('chat/entradachat.jsp?si=' + codSitio,"Chat","scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,fullscreen=0,width="+ancho+",height="+alto+",left="+izda+",top="+arri);

	return false;
}

function asigna(origen,destino){
	destino.value = origen.checked?'S':'N';

}

function trim(inputString){

   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);

   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function compruebaEmail(direccion){

	//===============================================================================
    var CaracteresInvalidos = ' ºª\\!|"·#$~%€¬/()=?¿¡\'`^[+*]´{¨ç}ÇáéíóúÁÉÍÓÚäëïöüÄËÏÖÜ:;,<>ñÑ';
    var I , L;
	//===============================================================================
    var contieneArroba   = direccion.indexOf("@")>0;
	var unaSolaArroba    = direccion.indexOf("@")==direccion.lastIndexOf("@");
	var contienePunto    = direccion.indexOf(".")>0;
    //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
    //Contiene punto después de la arroba y al menos un caracter entre ambos*-*-*-*-*-
	var puntoTrasArroba  = contieneArroba && contienePunto
	                       && direccion.lastIndexOf(".")>direccion.lastIndexOf("@")+1;
    //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
    //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
	var noTerminaEnPunto = direccion.lastIndexOf(".")<(direccion.length-1)
	var sinCharsInvalidos = true;

	//===============================================================================
    for (I=0,L=CaracteresInvalidos.length;I<L && sinCharsInvalidos; I++)
	   sinCharsInvalidos = (direccion.indexOf(CaracteresInvalidos.substr(I,1))<0);
	//===============================================================================
    var valido= contieneArroba
	            && unaSolaArroba
				&& contienePunto
				&& puntoTrasArroba
				&& noTerminaEnPunto
				&& sinCharsInvalidos;

	//===============================================================================
	if (!valido){

	  var Errores = "";
	  Errores = (contieneArroba?   "":"\n\tNo Contiene Arroba")
		       +(unaSolaArroba?    "":"\n\tContiene Más de Una Arroba")
		       +(contienePunto?    "":"\n\tNo Contiene Ningún Punto")
		       +(puntoTrasArroba?  "":"\n\tNo Se Ha Especificado un Dominio")
		       +(noTerminaEnPunto? "":"\n\tNo Debe Terminar en Punto")
		       +(sinCharsInvalidos?"":"\n\tContiene Caracteres Inválidos\n\n\t\t"
			                           +"Los Caracteres Inválidos son\n\t"
									   +CaracteresInvalidos);
	  alert(direccion+"\n"+Errores);
	}

	return valido;

  }

function Comprobar(frm){

	var cadena;
//	frm.enviar.disabled = true;
	cadena = trim(frm.nombre.value);

	if (cadena.length == 0){

		alert('El nombre es un valor requerido');
		frm.nombre.focus();
//		frm.enviar.disabled = false;
		return false;
	}

	if (!compruebaEmail(frm.email.value)){

		frm.email.focus();
//		frm.enviar.disabled = false;

		return false;
	}

	cadena = trim(frm.telefono.value);

	if (cadena.length == 0){

		alert('El teléfono es un valor requerido');
		frm.telefono.focus();
//		frm.enviar.disabled = false;
		return false;
	}

	cadena = trim(frm.poblacion.value);

	if (cadena.length == 0){

		alert('La población es un valor requerido');
		frm.poblacion.focus();
//		frm.enviar.disabled = false;
		return false;
	}

	cadena = trim(frm.asunto.value);

	if (cadena.length == 0){

		alert('El texto del mensaje es un valor requerido');
		frm.asunto.focus();
//		frm.enviar.disabled = false;
		return false;

	}

	return true;

}
