function carregapagina(conteudo, url) {
  $(conteudo).update('<br><br><img height="2" width="300" src="images/loader.gif" alt="carregando" />');
  new Ajax.Updater(conteudo, url);
	navega.addPoint(url,conteudo);
}


function carregaalbum(conteudo, url) {
  new Ajax.Updater(conteudo, url);
}

function envia_formulario(id, url, resposta) {
  f = $(id);
	el = $(id).serialize(true);
	//if(valida_formulario(el)) {
	if(true) {
    $(resposta).update('<br><br><img height="2" width="300" src="images/loader.gif" alt="carregando" />');
    new Ajax.Updater(resposta, url, { parameters:  el }	);
	}
}

function envia_formulario_album(id, conteudo, url) {
  $(id).request({
    onComplete: function(){ carregapagina(conteudo, url); }
  })
}

function valida_formulario(el) {
	for(k in el) {
	 c = $(k).classNames();
	 v = $(k).getValue();
	 t = $(k).readAttribute('title');
	 
	 if(c == 'required') {
	   if(v.blank()) {
		   alert(':: ' + t + ' ::' + '\npreenchimento obrigatório');
		   $(k).focus();
		   return false
		 }
	 }
	}
	return true
}


/**********************************************/
/* Navegação                                   /
/**********************************************/

var History_Browser = Class.create();  
History_Browser.prototype = {
//construtor padrão  
  initialize: function(content) {  
    this._url = new Array();
	  this._content = new Array();
	  this._current = -1;

  },
//adiciona um ponto de navegação 
	addPoint: function(url, content) {
	  if(content == null) content = this._content;
		this._url.push(url);
		this._content.push(content);
		this._current ++;
	},
//retorna a url atual ou da posição dada	
	getUrl: function(pos) {
	  if(pos == null) pos=this._current;
		return this._url[pos];
	},
//recua o ponteiro
  prev: function() {
			this._current --;
      if(this._current < 0) this._current =0;
			$(this._content[this._current]).update('<br><br><img height="2" width="300" src="images/loader.gif" alt="carregando" />');
      new Ajax.Updater(this._content[this._current], this._url[this._current]);

	
	},
//avança o ponteiro
  next: function() {
			this._current ++;
      if(this._current > this._content.size()-1) this._current = this._content.size() -1;
			$(this._content[this._current]).update('<br><br><img height="2" width="300" src="images/loader.gif" alt="carregando" />');
      new Ajax.Updater(this._content[this._current], this._url[this._current]);
	}	

}
navega = new History_Browser();


