var slideOffsets = new Array();

function addClass(obj, newClass)
{
  if(!contains(obj.className, newClass))
  {
    if(obj.className.length > 0)
    {
      obj.className = obj.className + " " + newClass;
    }
    else
    {
      obj.className = newClass;
    }
  }
}

function contains(subject, str)
{
  var result = false;
  if(subject.toLowerCase().indexOf(str) >= 0){
    result = true;
  }
  return result;
}

function textify(obj, eventType, defaultValue)
{
	if(obj.value == defaultValue && eventType == 'focus')
	{
		obj.value = '';
	}
	if(obj.value == '' && eventType == 'blur')
	{
		obj.value = defaultValue;
	}
}

function getCoords(e)
{
	var posX = 0;
	var posY = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posX = e.pageX;
		posY = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posX = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posY = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return Array(posX, posY);
}


function getObj(obj)
{
	return document.getElementById(obj);
}

function getStyle(obj, atr){
	var result = '';
	switch(atr){
		case 'opacity':
			result = obj.style.opacity * 100;
			break;
	}
	return result;
}

function hideTip()
{
	var tip = getObj('tooltip');
	setStyle(tip, 'display', 'none');
}

function initSlide(objs)
{
	var i;
	var temp;
	
	for(i = 0; i < objs.length; i++)
	{
		if(objs[i].style.display.length > 0)
		{
			temp = objs[i].style.display;
		}
		else
		{
			temp = 'none';
		}
		
		objs[i].style.display = 'block';
		slideOffsets.push(new Array(objs[i].id, objs[i].offsetHeight));
		objs[i].style.display = temp;
	}
}

function login()
{
	var passwordOne = getObj('passwordOne');
	var passwordTwo = getObj('passwordTwo');
	passwordTwo.value = hex_md5(passwordOne.value);
	passwordOne.value = '';
}

function loginBody()
{
	var passwordOne = getObj('passwordBodyOne');
	var passwordTwo = getObj('passwordBodyTwo');
	
	getObj('bodyLogin').value = 'true';
	passwordTwo.value = hex_md5(passwordOne.value);
	passwordOne.value = '';
}

function removeClass(obj, strClass)
{
  
  // if it is not the initial class it will have a space
  // we must check for this first, if not we will leave extra white space
  if(contains(obj.className, " " + strClass))
  {
    var newClass = strRemove(obj.className, " " + strClass);
    obj.className = newClass;
  }
  // check for our object to have an initial class
  if(contains(obj.className, strClass))
  {
    var newClass = strRemove(obj.className, strClass);
    obj.className = newClass;
  }
  
}

function setStyle(obj, atr, val)
{
	var temp;
	switch(atr)
  {
		case 'left':
			obj.style.left = val;
			break;
		case 'top':
			obj.style.top = val;
			break;
		case 'background':
			obj.style.background = val;
			break;
		case 'border':
			obj.style.border = val;
			break;
		case 'display':
			obj.style.display = val;
			break;
		case 'height':
			obj.style.height = val;
			break;
		case 'overflow':
			obj.style.overflow = val;
			break;
		case 'opacity':
			temp = val / 100;
			obj.style.opacity = temp;
			break;
		case 'filter':
		  obj.style.filter = 'alpha(opacity = ' + val + ')';
		  break;
	}
}

function showTip(e, msg)
{
	if(!e)
	{
		var e = window.event;
	}
	updateTip(e);
	var tip = getObj('tooltip');
	tip.innerHTML = msg;
	setStyle(tip, 'display', 'block');
}

function strRemove(s, t)
{
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + strRemove(s.substring(i + t.length), t);
  return r;
}

function updateCellAction(action)
{
	getObj('settingsCellAction').value = action;
	getObj('settingsCellForm').submit();
}

function updateTip(e)
{
	if(!e)
	{
		var e = window.event;
	}
	var coords = getCoords(e);
	var tip = getObj('tooltip');
	setStyle(tip, 'left', (coords[0] - 18) + 'px');
	setStyle(tip, 'top', (coords[1] + 18) + 'px');
}
