/**
 * (c) InfoProjects bv. - www.infoprojects.nl
 *
 * $Revision: 1.3 $
 * $Date: 2011/03/10 14:46:22 $
 * $Author: jacob $
 */

function getClient() {
  // convert all characters to lowercase to simplify testing
  var agt=navigator.userAgent.toLowerCase();
  var apv=navigator.appVersion.toLowerCase();
  this.major = parseInt(navigator.appVersion, 10);
  this.minor = parseFloat(navigator.appVersion);
  // browserversion
  this.opera = (agt.indexOf('opera')!=-1);
  this.ns  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)));
  this.ns4 = (this.ns && (this.minor >= 4.03) && (this.major < 5));
  this.ns6 = (this.ns && (this.major == 5) || this.opera);
  this.gecko = (this.ns && (this.major >= 5));
  this.ie   = (agt.indexOf("msie") != -1);
  this.ie4  = (this.ie && (this.major == 3));
  this.ie45 = (agt.indexOf('msie 4.5') != -1);
  this.ie5  = (this.ie && (this.major == 4));
  // platform
  this.mac = (apv.indexOf("macintosh")>0);
  this.win = (apv.indexOf("win")>0);	
  // compatible browsers
  this.ie4comp = ((this.ie4 && !this.mac) || this.ie45 || this.ie5);
  this.ns4comp = (this.ns4);
  this.ns6comp = (this.gecko || this.ns6);
  this.comp = (this.ie4comp || this.ns4comp || this.ns6comp);
  return (this);
}

var is = new getClient();

function getImage(img) {
  return document.images[img];
}

function getForm(name) {
  return document.forms[name];
}

function getElt(id) {
  return document.getElementById(id);
}

// --- POSITION ---

function setEltPosition (elt, value) {
  if (!elt || elt == null) return;
  if (is.ns4comp) elt.position = value;
  else if (is.ie4comp) elt.style.position = value;
  else if (is.ns6comp) elt.style.position = value;
}

// --- DISPLAY ---

function setEltDisplay (elt, value) {
  if (!elt || elt == null) return;
  if (is.ns4comp) elt.display = value;
  else if (is.ie4comp) elt.style.display = value;
  else if (is.ns6comp) elt.style.display = value;
}

function getEltDisplay(elt) {
  if(!elt || elt == null) {
    return;
  }
  if(is.ns4comp) {
    return (elt.display);
  } else if(is.ie4comp) {
    return (elt.style.display);
  } else if(is.ns6comp) {
    return (elt.style.display);
  }
}

// --- VISIBILITY ---

function setEltVisibility (elt, value) {
  if (!elt || elt == null) return;
  if (is.ns4comp) elt.visibility = value;
  else if (is.ie4comp) elt.style.visibility = value;
  else if (is.ns6comp) elt.style.visibility = value;
}

// --- POSITION ---

function setEltLeft (elt, x) {
  if (!elt || elt == null) return;
  if (is.ns4comp)     elt.left=x;
  else if (is.ie4comp) elt.style.pixelLeft=x;
  else if (is.ns6comp) elt.style.left = (x + "px");
}

function setEltTop (elt, y) {
  if (!elt || elt == null) return;
  if (is.ns4comp)     elt.top=y;
  else if (is.ie4comp) elt.style.pixelTop=y;
  else if (is.ns6comp) elt.style.top= (y + "px");
}

function setEltHeight (elt, y) {
  if (!elt || elt == null) return;
  if (is.ns4comp)     elt.height=y;
  else if (is.ie4comp) elt.style.pixelHeight=y;
  else if (is.ns6comp) elt.style.height= (y + "px");
}

function getEltTop (elt) { 
  if (!elt || elt == null) return 0;
  if (is.ns4comp)     return (elt.top);
  else if (is.ie4comp) return (elt.style.pixelTop);
  else if (is.ns6comp) return (elt.offsetTop);
}

function getEltWidth (elt) { 
  if (!elt || elt == null) return 0;
  if (is.ns4comp) return(elt.document.width);
  else if (is.ie4comp) return (elt.offsetWidth);
  else if (is.ns6comp) return (elt.offsetWidth);
}

function getEltHeight (elt){ 
  if (!elt || elt == null) return 0;
  if (is.ns4comp) return(elt.document.height);
  else if (is.ie4comp) return (elt.clientHeight);
  else if (is.ns6comp) return (elt.offsetHeight);
}

// --- CLIPPING ---

function setEltClip (elt, cliptop, clipright, clipbottom, clipleft) 
{ if (is.ns4comp) {
    elt.clip.left   = clipleft;
    elt.clip.top    = cliptop;
    elt.clip.right  = clipright;
    elt.clip.bottom = clipbottom;
  }
  else if (is.ie4comp)  elt.style.clip = 'rect(' + cliptop + ' ' +  
       clipright + ' ' + clipbottom + ' ' + clipleft +')';
  else if (is.ns6comp)  elt.style.clip = 'rect(' + cliptop + ' ' +  
       clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

// --- WINDOW PROPERTIES ---

function getWinHeight() 
{ if (is.ns4comp) return(window.innerHeight);
  else if (is.ie4comp) return(document.body.clientHeight);
  else if (is.ns6comp) return(window.innerHeight);
}

function getWinScrollLeft()
{ if (is.ns4comp) return(window.pageXOffset);
  else if (is.ie4comp) return(document.body.scrollLeft);
  else if (is.ns6comp) return(window.pageXOffset);
}

function getWinScrollTop()
{ if (is.ns4comp) return(window.pageYOffset);
  else if (is.ie4comp) return(document.body.scrollTop);
  else if (is.ns6comp) return(window.pageYOffset);
}

// --- MOUSE EVENT PROPERTIES ---

function getMousePos(e) {
  curMouseX = getMouseWinLeft(e);
  curMouseY = getMouseWinTop(e);
}

var curMouseY = 0;
function getMouseWinTop(e) {
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageY)
	{
		posy = e.pageY;
	}
	else if (e.clientY)
	{
		posy = e.clientY + document.body.scrollTop;
	}
  curMouseY = posy;
  return posy;
}

var curMouseX = 0;
function getMouseWinLeft(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageX)
	{
		posx = e.pageX;
	}
	else if (e.clientX)
	{
		posx = e.clientX + document.body.scrollLeft;
	}
  curMouseX = posx;
  return posx;
}

// --- CLASS ---
function getEltClassName(elt) {
  return elt.className;
}

function setEltClassName(elt,val) {
  elt.className = val;
}

// --- BACKGROUND ---

function setEltBg(elt,val) {
  val = (val.indexOf("url(") != -1)?val:("url('"+val+"')");
  elt.style.backgroundImage = val;
}
