// JavaScript Document
function loadarticle() {
	var arrayPageSize = getPageSize();
	//alert(arrayPageSize);
	var winl = (arrayPageSize[2] - 600)/2;
	var wint = (arrayPageSize[3] - 300)/2
	document.getElementById('articlepop').style.top = wint;  
	document.getElementById('articlepop').style.left = winl;  
    document.getElementById('articlepop').style.display = 'block';  
}

function hidearticle() {
      document.getElementById('articlepop').style.display = 'none';
	  document.getElementById('articlepop').innerHTML = "";
	  
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) ;
	return arrayPageSize;
}

var url = "/ajax/getarticledetails.php?aid="; // The server-side script
function handleHttpResponse() {
  if (http.readyState < 4) {
	document.getElementById('articlepop').innerHTML = "<p id='blogloader'><img src='/images/misc/loader.gif'> loading post ...</p>";
    loadblog();
  }
  if (http.readyState == 4) {
    if (http.responseText.indexOf('invalid') == -1) {
      // Use the XML DOM to unpack the info
      //var xmlDocument = http.responseXML; 
     // var bdump = xmlDocument.getElementsByTagName('blog').item(0).firstChild.data;
	 // bdump = bdump.replace(/\n/, '<br />');
	  //bdump = bdump.replace(/\n/g, '<br />');
	  //alert (bdump);
	  document.getElementById('articlepop').innerHTML = http.responseText;
      loadarticle();
      isWorking = false;
    }
  }
}

var isWorking = false;
function updatearticle(loadarticleid) {
	  if (!isWorking && http) {
	    http.open("GET", url + escape(loadarticleid) + "&cc=" + new Date().getTime(), true);
	    http.onreadystatechange = handleHttpResponse;
	    isWorking = true;
	    http.send(null);
	  }
}
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml"); 
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object