/*******************************************/
/*                                          */
/*******************************************/
AIM = {

	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}

function startCallback() {
  // make something useful before submit (onStart)
  return true;
}

function completeCallback(response) {
   document.getElementById("cuerpoContenido").innerHTML=response;  
}

/*Función para la paginación de los articulos, pruebas,...*/
var paginaActual=1;
function irA(pagina){   
      AIM.submit(document.getElementById('formPaginacion'), {'onStart' : startCallback, 'onComplete' : completeCallback});
      document.getElementById('formPaginacion').paginaActual.value=pagina;
      paginaActual=pagina+1;
      document.getElementById('formPaginacion').submit(); 
}
function siguiente(total){ 
      AIM.submit(document.getElementById('formPaginacion'), {'onStart' : startCallback, 'onComplete' : completeCallback});
      if(total>paginaActual){
        document.getElementById('formPaginacion').paginaActual.value=paginaActual;
        paginaActual=paginaActual+1;
      }else{
        document.getElementById('formPaginacion').paginaActual.value=paginaActual-1;
      }
      document.getElementById('formPaginacion').submit(); 
}
function anterior(total){   
      AIM.submit(document.getElementById('formPaginacion'), {'onStart' : startCallback, 'onComplete' : completeCallback});
      if(paginaActual>1){
         document.getElementById('formPaginacion').paginaActual.value=paginaActual-2;
         paginaActual=paginaActual-1;
      }else{
        document.getElementById('formPaginacion').paginaActual.value=paginaActual-1;
      }
      document.getElementById('formPaginacion').submit(); 
}
/*Función para la galeria de imagnes,...*/
function backward(){
if (which>0){
	window.status='';
	which--;
	document.images.photoslider.src=photos[which];	
	document.getElementById('pieFoto').innerHTML=piephotos[which];
        document.getElementById('galeria').innerHTML=urlphotos[which];
}
}

function forward(){
if (which<photos.length-1){
which++;
document.images.photoslider.src=photos[which];
document.getElementById('pieFoto').innerHTML=piephotos[which];
document.getElementById('galeria').innerHTML=urlphotos[which];
}
else window.status='End of gallery';
}

function gallery(){
	if (which<photos.length-1){
		which++;
	}else{
		which = 0;
	}
	document.images.photoslider.src=photos[which];
   document.getElementById('pieFoto').innerHTML=piephotos[which];
   document.getElementById('galeria').innerHTML=urlphotos[which];
}

function backwardFicha(){
if (which>0){
	window.status='';
	which--;
	document.images.photoslider.src=photos[which];	
	document.getElementById('pieFoto').innerHTML=piephotos[which];
}
}

function forwardFicha(){
if (which<photos.length-1){
which++;
document.images.photoslider.src=photos[which];
document.getElementById('pieFoto').innerHTML=piephotos[which];
}
else window.status='End of gallery';
}

function galleryFicha(){
	if (which<photos.length-1){
		which++;
	}else{
		which = 0;
	}
	document.images.photoslider.src=photos[which];
   document.getElementById('pieFoto').innerHTML=piephotos[which];
}



/***********************************************************/
/*Funcion para validar un mail				   */
/***********************************************************/

function validarMail(valor) {

  if(valor=="")
  {
          return true;
  }
  else
  {
          tieneEspacio = false;
          tieneArroba = false;
          primeroArroba = 0;
          tienePunto = false;
          segundoPunto = 0;
          texArray = new Array();

          for (i = 0;  i < valor.length;  i++)
          {
                  if (valor.charAt(i) == ' ')
                  {
                          tieneEspacio = true;
                  }
                  else if (valor.charAt(i) == '@')
                  {
                          tieneArroba = true;
                          primeroArroba = i;
                  }
                  else if (valor.charAt(i) == '.')
                  {
                          tienePunto = true;
                          segundoPunto = i;
                  }
                  else
                  {
                          texArray[i]=0;
                  }
          }
          if ( (valor.length!=0) && ( texArray[primeroArroba-1]==0 ) && ( texArray[segundoPunto-1]==0 ) && ( texArray[segundoPunto+1]==0 ) && ( tieneEspacio == false )  &&  ( tieneArroba == true ) &&  ( tienePunto == true )  &&  ( primeroArroba<segundoPunto ) )
                  {
                          return true;
                  }
                  else  {
                          return false;
                  }
  }
}
		