
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function AbrirNoticia(noticia, ancho, alto) {

var url;

   url = "noticia" + noticia + ".html";

   window.open(url, "noticia", "width="+ancho+",height="+alto+",scrollbars=no,resizable=no,status=no");
}

function esDigito(sChr){
  var sCod = sChr.charCodeAt(0);
  
  return ((sCod > 47) && (sCod < 58));
}

function valSep(oTxt){
  var bOk = false;
  
  bOk = bOk || ((oTxt.charAt(2) == "-") && (oTxt.charAt(5) == "-"));
  bOk = bOk || ((oTxt.charAt(2) == "/") && (oTxt.charAt(5) == "/"));
  
  return bOk;
}

function finMes(oTxt){
  var nMes = parseInt(oTxt.substr(3, 2), 10);
  var nRes = 0;

  switch (nMes){
    case 1: nRes = 31; break;
    case 2: nRes = 29; break;
    case 3: nRes = 31; break;
    case 4: nRes = 30; break;
    case 5: nRes = 31; break;
    case 6: nRes = 30; break;
    case 7: nRes = 31; break;
    case 8: nRes = 31; break;
    case 9: nRes = 30; break;
    case 10: nRes = 31; break;
    case 11: nRes = 30; break;
    case 12: nRes = 31; break;
  }
 
  return nRes;
}

function valDia(oTxt){
  var bOk = false;
  var nDia = parseInt(oTxt.substr(0, 2), 10);

  bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));

  return bOk;
}

function valMes(oTxt){
  var bOk = false;
  var nMes = parseInt(oTxt.substr(3, 2), 10);

  bOk = bOk || ((nMes >= 1) && (nMes <= 12));

  return bOk;
}

function valAno(oTxt){
  var bOk = true;
  var nAno = oTxt.substr(6);

  bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));

  if (bOk){
    for (var i = 0; i < nAno.length; i++){
      bOk = bOk && esDigito(nAno.charAt(i));
    }
  }

  return bOk;
}

function valFecha(oTxt){
  var bOk = true;

  if (oTxt != ""){
    bOk = bOk && (valAno(oTxt));
    bOk = bOk && (valMes(oTxt));
    bOk = bOk && (valDia(oTxt));
    bOk = bOk && (valSep(oTxt));
  }
  
  return bOk;
}

function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";

	if (str.length == 0) 
		resultStr = "";
	else {	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
//	  	len = str.length - 1;
		len = str.length;
		
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;

   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
}

function TrimRight( str ) {
	var resultStr = "";
	var i = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
  	
  	return resultStr;  	
}


function trim( str ) {
	var resultStr = "";
	
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
}

function validar_envio_correo(formulario) {
  if (trim(formulario.txtnombre.value) == "") {
    alert("Escriba su nombre.");
	formulario.txtnombre.focus();
    return (false);
  }

  if (trim(formulario.txtemail.value) == "") {
    alert("Escriba una dirección de correo.");
	formulario.txtemail.focus();
    return (false);
  }
  
  if (trim(formulario.txtemail.value) != "") {
    if ((formulario.txtemail.value.indexOf ('@', 0) == -1)) { 
      alert("Escriba una dirección de correo válida."); 
      formulario.txtemail.focus();
      return (false); 
    }
  }
  
  if (trim(formulario.txttelefono.value) == "") {
    alert("Escriba su teléfono de contacto.");
	formulario.txttelefono.focus();
    return (false);
  }
  
  if (trim(formulario.txtasunto.value) == "") {
    alert("Escriba el asunto del mensaje.");
	formulario.txtasunto.focus();
    return (false);
  }

  return (true); 
}

function validar_form_noticias(formulario) {
  
  if (trim(formulario.txtdia.value) == "") {
    alert("Escriba el día.");
	formulario.txtdia.focus();
    return (false);
  }
  
  if (trim(formulario.txtmes.value) == "") {
    alert("Escriba el mes.");
	formulario.txtmes.focus();
    return (false);
  }
  
  if (trim(formulario.txtanio.value) == "") {
    alert("Escriba el año.");
	formulario.txtanio.focus();
    return (false);
  }
  
  var txtfecha = "";
  
  txtfecha = trim(formulario.txtdia.value) + "/" + trim(formulario.txtmes.value) + "/" + trim(formulario.txtanio.value);
  
  if (valFecha(txtfecha) == false) {
    alert("Escriba una fecha válida.");
	formulario.txtdia.focus();
    return (false);
  }
  
  if (trim(formulario.txttitulo.value) == "") {
    alert("Escriba el título.");
	formulario.txttitulo.focus();
    return (false);
  }

  if (trim(formulario.txtdesc.value) == "") {
    alert("Escriba una descripción.");
	formulario.txtdesc.focus();
    return (false);
  }
  
  if (trim(formulario.txttexto.value) == "") {
    alert("Escriba el texto.");
	formulario.txttexto.focus();
    return (false);
  }

  return (true); 
}
