/******************************************************************************
 ** F U N C T I O N S   S I T E
 *
 * Autor: André Britto
 * Date: 16.08.2007
 * File: site.functions.js
 */

/**
 * Constants
 */
var IMG_PATH = './lib/img/';
 
/**
 * Function: Essentials functions
 */	
function E(id){
	return document.getElementById(id);
}
function setHtml(id, html){
	E(id).innerHTML = html;
}

function showLoading(){
  E('loading').style.display = 'block';
}
function hideLoading(idLoad){
  idLoad = (idLoad)?idLoad:'loading';
  E(idLoad).style.display = 'none';
}

/**
 * Function: HttpRequest
 */	
function reqNew() {
  var req;
  if(window.XMLHttpRequest){
    req = new XMLHttpRequest();
  }
  else {
    if(window.ActiveXObject)
      req = new ActiveXObject('Msxml2.XMLHTTP');
    else
      req = new ActiveXObject('Microsoft.XMLHTTP');
  }
  return req;
}

/**
 * Function: setContent HttpRequest
 */	
function setContent(contentPath){
	showLoading();
	
	var req = reqNew();
	req.onreadystatechange = function() {
	  if(req.readyState == 4) {
	    if(req.status == 200) {
			setHtml('content', req.responseText);
    	}else{
			alert(req.status+' '+req.statusText);
		}
		hideLoading();
	  }
	}
	req.open('POST', contentPath, true);
    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send("idContent=content");
}


/**
 * Function: showEvent
 */	

function showAlbum(album){
	showLoading();
  var req = reqNew();
  req.onreadystatechange = function() {
	  if(req.readyState == 4) {
	    if(req.status == 200) {
			E('content').innerHTML = req.responseText;
			Gallery.showEvt(album,1);
    	}else{
			alert(req.status+' '+req.statusText);
		}
	  }
  }

  req.open('POST', 'album.php', true);
  req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
  req.send('album='+album);

}
