// Sets the gradient background for the menu & tbl heading class
// ======================================
// NOT USED

function setMenuBackgroundStyle() {
isIE = document.all ? true : false;
document.write('<style type="text/css">');
if (isIE) {
  document.write(".menu_item {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/gradient_background.png',sizingMethod='scale')}");
}
else {
  document.write(".menu_item {background-image: url(/images/gradient_background.png); background-repeat: repeat-x;}");
}
document.write('</style>');
}

// Function: detectMouseOnLayer
// ======================================
// Returns true if the mouse is positioned over the specified element

function detectMouseOnLayer(elementName,e) {
  if (!e) e = window.event;
  element = document.getElementById(elementName);
  elementStartX = findPosX(element);
  elementStartY = findPosY(element);
  elementEndX = elementStartX + element.offsetWidth;  
  elementEndY = elementStartY + element.offsetHeight;  
  mouseX = getMouseX(e);
  mouseY = getMouseY(e); 
  scrollY = document.body.scrollTop || window.pageYOffset || document.documentElement.scrollTop;

  if (mouseX > elementStartX && mouseX < elementEndX)
    if (mouseY > (elementStartY - scrollY) && mouseY < (elementEndY - scrollY))
	  return true;
	  
  return false;  
}

function getMouseX(e) {
  isIE = document.all ? true : false;
  return (isIE ? event.clientX : e.clientX);
}

function getMouseY(e) {
  isIE = document.all ? true : false;
  return (isIE ? event.clientY : e.clientY);
}


// ####################### GENERAL FUNCTIONS #######################
// =================================================================

// Function: deleteChildren
// ======================================
// Deletes all the children possessed by an element.

function deleteChildren(parentName) {
  parentNode = document.getElementById(parentName);
  children = parentNode.childNodes; 
  for (i = 0; i< children.length; i++) {
	parentNode.removeChild(children[i]);
	i--;
  }	
}

function getScreenDimensions() {
  if (document.all) {
    SCREEN_WIDTH = document.body.clientWidth;
    SCREEN_HEIGHT = document.body.clientHeight;
  } else {
    SCREEN_WIDTH = innerWidth;
    SCREEN_HEIGHT = innerHeight;
  } 
}

// Function: getStyle
// ======================================
// Determines the value of the specified style for a given element

function getStyle(elementName, style, element) {
  if (!element)
    element = document.getElementById(elementName);
  value = element.style[toCamelCase(style)];
  if(!value) {
    if(document.defaultView) {
      value = document.defaultView.getComputedStyle(element, "").getPropertyValue(style);
    } 
    else if(element.currentStyle) {
      value = element.currentStyle[toCamelCase(style)];
	}
  }
  return value;
}

// Function: toCamelCase
// ======================================
// Converts a string to camel case: ie. background-color to backgroundColor

function toCamelCase(s) {
  for(var exp = toCamelCase.exp; 
	exp.test(s); s = s.replace(exp, RegExp.$1.toUpperCase()) );
  return s;
}
toCamelCase.exp = /-([a-z])/;

// Function: toProperCase
// ======================================
// Converts a string to 'proper case': ie. times new roman to Times New Roman

function toProperCase(string,splitBy,separator) {
  separator ? '' : separator = ' ';
  stringArray = string.split(splitBy);
  newString = '';
  for (a=0; a < stringArray.length; a++) {
	a > 0 ? newString += separator : newString += '';	  
	for (b=0; b<stringArray[a].length; b++) {
	  b == 0 ? newString += stringArray[a].charAt(b).toUpperCase() : newString += stringArray[a].charAt(b);
	}
  }	
  return newString;
}

function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    if ( obj != null )
      curleft += obj.offsetLeft;
  }
  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;
    }
    if ( obj != null )
      curtop += obj.offsetTop;
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}

