
// ------------------- Viewports
var wWidth;
var wHeight;

// the more standards compliant browsers
// (mozilla/netscape/opera/IE7) 
// use window.innerWidth and window.innerHeight
if(typeof window.innerWidth != 'undefined'){
   wWidth = window.innerWidth;
   wHeight = window.innerHeight;
// IE6 in standards compliant mode 
// (i.e. with a valid doctype as the first line in the document)
} else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
    wWidth = document.documentElement.clientWidth,
    wHeight = document.documentElement.clientHeight
// older versions of IE
} else {
    wWidth = document.getElementsByTagName('body')[0].clientWidth,
    wHeight = document.getElementsByTagName('body')[0].clientHeight
}
// document.write('<pre>Your viewport width is '+wWidth+'x'+wHeight+'</pre>');


//-------------------- Browser types 
var ua          = navigator.userAgent.toLowerCase();
var isIE        = (ua.indexOf("msie")      != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1);
var isOpera     = (ua.indexOf("opera")     != -1);
var isGecko     = (ua.indexOf("gecko")     != -1);
var isSafari    = (ua.indexOf("safari")    != -1);
var isKonqueror = (ua.indexOf("konqueror") != -1);
/*
alert(
      "isIE = " + isIE + "\n" +
      "isOpera = " + isOpera + "\n" +
      "isGecko = " + isGecko + "\n" +
      "isSafari = " + isSafari + "\n" +
      "isKonqueror = " + isKonqueror
);
*/


// ##########################################
// #### Window, page & scroll positions #####
// ##########################################

// ---------------------- Window page sizes
function ___getPageSize(){
   var xScroll, yScroll;
   if (window.innerHeight && window.scrollMaxY) {	
       xScroll = window.innerWidth + window.scrollMaxX;
       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
       if(document.documentElement.clientWidth){
           windowWidth = document.documentElement.clientWidth; 
       } else {
           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 = xScroll;		
   } else {
       pageWidth = windowWidth;
   }
   arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
   return arrayPageSize;
};

// -------------------- Scroller positions
function ___getPageScroll(){
   var xScroll, yScroll;
   if (self.pageYOffset) {
       yScroll = self.pageYOffset;
       xScroll = self.pageXOffset;
   } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
       yScroll = document.documentElement.scrollTop;
       xScroll = document.documentElement.scrollLeft;
   } else if (document.body) { // all other Explorers
       yScroll = document.body.scrollTop;
       xScroll = document.body.scrollLeft;	
   }
   arrayPageScroll = new Array(xScroll,yScroll) 
   return arrayPageScroll;
};

// ---------------------- Debug positions
function ___getWindowsScroll(){
    var arrPageScroll = ___getPageScroll();
    var arrPageSizes  = ___getPageSize();
    alert('Scroller in position - x:'+arrPageScroll[0]+', y:'+arrPageScroll[1]+
        '\n\nPage sizes - w:'+arrPageSizes[0]+', h:'+arrPageSizes[1]);
}

// ----------------------- Agreement confirm
function show_agreement(obj_id){
   var aid = obj_id.split('-');
   if(confirm('Материал является объектом авторского права и защищен Законом "Об авторских правах".\nЕго использование в коммерческих целях не разрешается без письменного согласия автора (издателя).')){
      location.replace('/articles/?aid='+aid[1]);
   }
}