// JavaScript Document

function xNum()
{
  for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
  return true;
}

function xStr(s)
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xCamelize(cssPropStr)
{
  var i, c, a = cssPropStr.split('-');
  var s = a[0];
  for (i=1; i<a.length; ++i) {
    c = a[i].charAt(0);
    s += a[i].replace(c, c.toUpperCase());
  }
  return s;
}

function xGetComputedStyle(e, p, i)
{
  if(!(e=xGetElementById(e))) return null;
  var s, v = 'undefined', dv = document.defaultView;
  if(dv && dv.getComputedStyle){
    s = dv.getComputedStyle(e,'');
    if (s) v = s.getPropertyValue(p);
  }
  else if(e.currentStyle) {
    v = e.currentStyle[xCamelize(p)];
  }
  else return null;
  return i ? (parseInt(v) || 0) : v;
}

function xTop(e, iY)
{
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xStr(e.style.top)) {
    if(xNum(iY)) e.style.top=iY+'px';
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=xGetComputedStyle(e,'top',1);
      if(isNaN(iY)) iY=0;
    }
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(xNum(iY)) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  return iY;
}

function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

function moveMenu(menuBar, yEnd, totalTime)
{
	var ele = document.getElementById(menuBar);
	var yInit = xTop(ele);
	var disp = yEnd - yInit;
	var freq = Math.PI / (2 * totalTime);
	var startTime = new Date().getTime();
	var timer = setInterval(
		function() {
			var passedTime = new Date().getTime() - startTime;
			if (passedTime < totalTime) {
				var f = Math.abs(Math.sin(passedTime * freq));
				xTop(ele, Math.round(f * disp + yInit));
			}
			else {
				clearInterval(timer);
				xTop(ele, yEnd);
			}
		}, 10
	);
}

var menuIcon = ["Com", "Deal", "Con"];
var alreadyDown;
function menuPress(n) {
	for (i = 0; i < 3; i++) {
		if (i == n) {
			if (alreadyDown != n) {
				document.getElementById('Nav' + menuIcon[n] + "I").src="images/Nav" + menuIcon[n] + "Down.png";
				alreadyDown = n;
			}
			else {
				document.getElementById('Nav' + menuIcon[n] + "I").src="images/Nav" + menuIcon[n] + ".png";
				alreadyDown = null;
			}
		}
		else document.getElementById("Nav" + menuIcon[i] + "I").src="images/Nav" + menuIcon[i] + ".png";
	}
	return;
}
function getMerchantVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
}
function getMerchantType(merch) {
	var cookieValue = "";
	var name = merch + "=";
	var merchant = document.cookie;
	if (document.cookie.length > 0) {
		var offset = merchant.indexOf(merch);
		if (offset != -1) {
			offset += name.length;
			end = merchant.indexOf(";", offset);
			cookieValue = merchant.substring(offset);
		}
	}
	return cookieValue;
}

function setMerchantType(n, tout) {
	var expires = (tout) ? tout : (60*60*24*365*5);
	document.cookie = "merchant=" + n + "; max-age=" + expires + "; path=/";
}
function ShowSubMenu(menu) {
	document.getElementById(menu).style.display = 'block';
}function HideSubMenu(menu) {
	document.getElementById(menu).style.display = 'none';
}