// stores the reference to the XMLHttpRequest object 
var xmlHttp = createXmlHttpRequestObject();  
// retrieves the XMLHttpRequest object 
function createXmlHttpRequestObject()  
{  
  // will store the reference to the XMLHttpRequest object 
  var xmlHttp; 
  // if running Internet Explorer 
  if(window.ActiveXObject) 
  { 
    try 
    { 
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    catch (e)  
    { 
      xmlHttp = false; 
    } 
  } 
  // if running Mozilla or other browsers 
  else 
  { 
    try  
    { 
      xmlHttp = new XMLHttpRequest(); 
    } 
    catch (e)  
    { 
      xmlHttp = false; 
    } 
  } 
  // return the created object or display an error message 
  if (!xmlHttp) alert("Error creating the XMLHttpRequest object."); 
  else  
    return xmlHttp; 
}

var pager = {
    pagerId : '',
    sections : [],
	callback : '',
	prepare : function(i){
        if(!this.sections[this.pagerId]){
		    this.sections[this.pagerId] = new Object();
			this.sections[this.pagerId].page = 1;
			this.sections[this.pagerId].max = document.getElementById(this.pagerId).getAttribute('maxPageNum');
		}
		this.current = this.sections[this.pagerId];
		var next = (i == 1) ? this.sections[this.pagerId].page + 1 : this.sections[this.pagerId].page - 1;
		if(next < 1) return this.goToPage(1);	
		else if(next > this.sections[this.pagerId].max) return this.goToPage(this.sections[this.pagerId].max);	
        else return this.goToPage(next);	
	},
    next : function(pagerId,callback){
	    this.pagerId = pagerId;
		this.callback = callback;
	    return this.prepare(1);
	},
	previous : function(pagerId,callback){
	    this.pagerId = pagerId;
		this.callback = callback;
	    return this.prepare(-1);
	},
    goToPage : function(i){
	    if(i == this.sections[this.pagerId].page) return;
        this.sections[this.pagerId].page = i;
		eval(this.callback + '('+ i +')');
	},
	goDirectTo : function(){
	
	}
}
function loadError(){
    alert('The page could not be loaded at the moment please try again later.');
}

function simpleXHR(url,callback,error){

	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = function(){
		    if(xmlHttp.readyState == 4){
			    if(xmlHttp.status == 200){
			        eval(callback + '('+ xmlHttp.responseText +')');
				}
				else eval(error + '()');
			}
		};
		xmlHttp.send(null);
	}
	else setTimeout('simpleXHR(\''+url+'\',\''+callback+'\',\''+error+'\')',1000);	
}

function changeClass(id,class1,class2){
    var currClass = document.getElementById(id).className;
	var currClassArray = currClass.split(' ');
		
	var newClass = ''; 

	for(var i = 0; i < currClassArray.length; i++){
	    if (currClassArray[i] == class1)newClass += class2;		
		else newClass += currClassArray[i];
		if (i != currClassArray.length) newClass += ' ';
	}
	document.getElementById(id).className = newClass;
}
function expand(id){
    var currDisplay = document.getElementById(id).style.display;
	var v = (currDisplay == 'none') ? 'block' : 'none';
	document.getElementById(id).style.display = v;
}

function fadeObject(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function link(){}
function about(){
	alert('Soft-and-smart Technologies. Responsive web solutions engineers.\n\nE-mail: info@softandsmart.com\nTel: +234 805 305 0903\n');
}
var popup = {
   open : function(id){
       var object = document.getElementById(id);
	   object.style.display = 'block';
   },
   close : function(id){
	  document.getElementById(id).style.display = 'none';
   }
}
function doGlobalAlert(text){
   popup.open('global_alert');
   document.getElementById('global_alert_body').innerHTML = text;
}