﻿// returns [x,y] coordinates of objName
function findPos(objName) {
if (!document.getElementById(objName) && console.log) {console.log('findPos:: object not found: '+objName); }
	obj = document.getElementById(objName);
	var Left = 0;
	var Top = 0;
	if (obj.offsetParent) {
		do {
				Left += obj.offsetLeft;
				Top += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [Left,Top]; 
}

// Place objName at [x,y] coordinates
function placeObj(objName, Left, Top) { 
	obj = document.getElementById(objName);
	obj.style.position = "absolute";
	obj.style.top = Top+'px';
	obj.style.left = Left+'px';
}

function findPosX(objName) {
	obj = document.getElementById(objName);
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }  //ENDIF [obj.offsetParent]
            obj=obj.offsetParent;
        }  //ENDWHILE [obj.offsetParent]
    } else if (obj.x) {
        curleft+=obj.x;
    }  //ENDIF [obj.offsetParent]
    return curleft;
}

function findPosY(objName) {
	obj = document.getElementById(objName);
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

// 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;
}
