// JavaScript Document


function AbrirVentanaLocalizacion ()
{

	var params='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=600,height=600';
	params += ',top=10, left=10';
	window.open ("/archivos/callejero/Plano-Callejero.gif", "nueva", params);
	
}

function VerNoticia (codigo)
{
	formulario = document.getElementById('formulario_'+codigo);
	formulario.submit();			
}

function DescargarNoticia (id, tienePdf)
{

	if (tienePdf == 1)
	{
		window.location.href = "/include/descargarNoticia.asp?id="+id;	
	}
	else
	{
		alert ('Noticia no disponible en Pdf')
	}

}

function DescargarCallejero ()
{
	window.location.href = "/include/descargarCallejero.asp";	
}

function CambiarIdioma(idioma)
{
	document.all.idioma.value=idioma;
	document.form_idioma.submit();
}

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 SplitCadena(cadena, separador,elemento){
//si elemento es -1 devuleve todo el array
   var a;
   // Split at each space character.
   a = cadena.split("-");
   if (elemento == -1){
      return(a);
   }
   else{
      return (a[elemento]);
   }
}

/*
 *funciones de validación de datos
 */
function cVacio(campo, nombre)
{
	if (trim(campo.value) == "")
	{
		campo.value = "";
		campo.focus();
		return true;

	}
	return false;
}
function Vacio(valor)
{
	if (trim(valor) == "")
	{
		return true;
	}
	return false;
}

function cNumeros(campo,descripcion,obligatorio)
{
	var Expresion_Regular; 
	if ((!obligatorio) && trim(campo.value) == "") return true;
	if (cVacio(campo, descripcion))  return false;
 
	Expresion_Regular = /^\d*$/ ; 
	if (Expresion_Regular.test(campo.value))
	{
		return true;
	}
	else{
		campo.value = "";
		campo.focus();
		return false;
	}
}

function cEmail(campo,descripcion,obligatorio)
{
	if ((!obligatorio) && trim(campo.value) == "") return true;
	if (cVacio(campo,descripcion))  return false;

	var Expresion_Regular; 
	Expresion_Regular = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	
	if (Expresion_Regular.test(campo.value)){
		return true;
	}
	else
	{
		campo.value = "";
		campo.focus();
		return false;
	}
}

function ElementoSeleccionado (campo, descripcion)
{
	var i;
	for (i=0; i<campo.length;i++)
	{
		if (campo.options[i].selected && campo.options[i].value != 0 && campo.options[i].value != -1 && campo.options[i].value != '')
		{
			return true
		}
	}
	return false;
}