var isIE = window.ActiveXObject?true:false;

//addEvent(window, 'load', startMouseTrack);

/*
Capturing The Mouse Position in IE4-6 and NS4-6
www.CodeLifter.com
edited by Dan Story; to get correct position when page is scrolled down and/orright with IE;
*/
var IE = document.all?true:false;

function startMouseTrack() { 
	if(!IE) { document.captureEvents(Event.MOUSEMOVE); }
	window.document.onmousemove = getMouseXY;
}

var mX = 0;
var mY = 0;

function getMouseXY(e) {
	if (IE) {
		mX = event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		mY = event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	} else {
		mX = e.pageX;
		mY = e.pageY;
	}
	if (mX < 0)
	{
		mX = 0;
	}
	if(mY < 0)
	{
		mY = 0;
	}

	return true;
}

function getPageScroll()
{
	offX = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	offY = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	return Array( offX, offY );
}
function setPageScroll( x, y )
{
	if( document.documentElement.scrollLeft != null ){ document.documentElement.scrollLeft = x; }else{ document.body.scrollLeft = x; }
	if( document.documentElement.scrollTop != null ){ document.documentElement.scrollTop = y; }else{ document.body.scrollTop = y; }
}
function addPageScroll( x, y )
{
	if( document.documentElement.scrollLeft != null ){ document.documentElement.scrollLeft += x; }else{ document.body.scrollLeft += x; }
	if( document.documentElement.scrollTop != null ){ document.documentElement.scrollTop += y; }else{ document.body.scrollTop += y; }
}

//
// 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;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function createElement( tagName )
{
	if( document.createElementNS ){ return document.createElementNS( 'http://www.w3.org/1999/xhtml', tagName ); } else {  return document.createElement( tagName ); }
}

function setOpacity( obj, opacity)
{
	if( opacity > 100 ){ opacity = 100; }else if(opacity < 0){ opacity = 0; }
		obj.style.opacity = opacity/100;
		obj.style.MozOpacity = opacity/100;
		obj.style.filter = 'alpha(opacity=' + opacity + ')';
}

// Event Listener
// by Scott Andrew - http://scottandrew.com
// edited by Mark Wubben, <useCapture> is now set to false
function addEvent(obj, evType, fn){
	if(obj!=null)
	{
		if(obj.addEventListener){
			obj.addEventListener(evType, fn, false);
			return true;
		} else if (obj.attachEvent){
			var r = obj.attachEvent('on'+evType, fn);
			return r;
		} else {
			return false;
		}
	}
}

function getEventObject(e)
{
	var objTarget = false;
	if (e.target){objTarget = e.target; }else if (e.srcElement){objTarget = e.srcElement;}
	return objTarget;
}

function setPNGBackground( layerObject, imgPath ) {	
	if (isIE) {
		layerObject.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgPath + "', sizingMethod='scale')";
	} else {
		layerObject.style.backgroundImage = 'url(' + imgPath + ')';
		}
}

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
