﻿
function photoview(text)
{
	//<img src="'+ spliter[0] +'" class="fixed" border="0" />
	var spliter = text.split('##');
	document.getElementById('viewphoto').innerHTML = '<img src="'+ spliter[0] +'" class="fixed" border="0" />';
	document.getElementById('legenda').innerHTML = '<b>Legenda: </b>' + spliter[1];
}

Function.prototype.bind=function(obj, args) { var metodo=this; return function() { return metodo.apply(obj, args); } }

function XMLHTTPRequest() 
{ 
	var tXHR=0; //Criação de objeto XMLHTTPRequest cross-browser
	if (window.XMLHttpRequest) { 
		tXHR=new XMLHttpRequest(); 
	} //Objeto nativo (FF/Safari/Opera7.6+)
	else {
		try { 
			tXHR = new ActiveXObject("Msxml2.XMLHTTP"); 
		} //activeX (IE5.5+/MSXML2+)
    catch(e) {
		try { 
			tXHR = new ActiveXObject("Microsoft.XMLHTTP");
		} //activeX (IE5+/MSXML1)
      catch(e) { /* O navegador não tem suporte */ 
		  tXHR=false; 
	  }
    }
  }
  return tXHR;
}
//void makeXHRCall : makes a XMLHTTPRequest and configure the callback function with optional parameters
//  object t(XHR)Object, string tURL, string tMethod ("POST" | "GET")
//  [, string tContents(ToSend) [, array tHeaders (array of arrays in pair format: "['name', 'value']")
//  [, function t(Callback)Function [, boolean tReturn(Type) [, array t(aditional)Params(ToCallBack) ]]] ]]
//    - tHeaders: an array containing other arrays with two indexes: 0) Header Name, and 1) Header Value
//    - tReturn(Type): 0 = responseText. 1 = responseXML.

function mostranoDiv(text)
{
	document.getElementById('div').innerHTML = text;
}

function makeXHRCall(tO, tU, tM, tC, tHs, tF, tR, tPs) 
{
	if (!tO || !tU) 
		return false; 
	if (!tHs) 
		tHs=[]; 
	var i, n;
	//verifica se exibe uma funcao
	if (tF) 
		tO.onreadystatechange = XHRStateChanged.bind(tO, [tF, tPs]);
	tO.open(((tM) ? tM : 'GET'), tU, true);
	for (i=0, n=tHs.length; i<n; i++) {
		tO.setRequestHeader(tHs[i][0], tHs[i][1]); 
	}
	tO.send((tC) ? tC : null);
	return void(null);
}
function XHRStateChanged(tF, tPs, tRT)
{ //function tFunction [, array Params [, boolean tReturnType]]
	if (this.readyState == 4) {
		if (this.status == 200) {
			tPs = tPs || Array(); 
			tPs.unshift((this[(tRT) ? 'responseHTML' : 'responseText' ]));
			tF.apply(window, tPs);
		} else { 
			return false; 
		}
	}
	return true;
} 

function tbphotos(text){
	document.getElementById('tbphotos').innerHTML = text;
}
function carregando(){
	var content = '<div id="load"><img src="imgs/load.gif" alt="carregando" /></div>';
	document.getElementById('legenda').innerHTML = '<b>Carregando...</b>';
	document.getElementById('viewphoto').innerHTML = content;
	document.getElementById('load').style.visibility = "visible";
}

function carregando2(){
	document.getElementById('tbphotos').innerHTML = '<div id="load2"><img src="imgs/load2.gif" alt="carregando" /></div>';
}

function exibePhoto(id){
	carregando();
	url = 'ViewPhotoFull.aspx?photoId=' + id;
	makeXHRCall(XMLHTTPRequest(), url, 'GET', false, false, photoview);
}

function getPage(npage, idgallery){
	carregando2();
	url = 'ajaxListPhotos.aspx?gid='+ idgallery +'&page='+ npage + '&s=ajax';
	makeXHRCall(XMLHTTPRequest(), url, 'GET', false, false, tbphotos);
}


