
function assert(condition, message) {
  if(!condition) {
    alert('Assert: ' + message);
  }
}

function jiggle()
{
  if ( isIplatform != true ) { return; }
  document.body.scrollLeft = -1;
  document.body.scrollTop = -1;
}


function hasValue( parm )
{
  if ( typeof(parm) == "undefined" ) { return false; }
  if ( parm == null ) { return false; }
  if ( parm == "" ) { return false; }
  return true;
}


function removeTrailingSlash( str )
{
  if ( str.substr(str.length-1,1) == "/" )
  {
    str = str.substr(0,str.length-1);
  }
  
  return str;
}


function strStyleWidth( str, el  )
{
  var spn = document.createElement("SPAN");
  spn.style.visibility = "hidden";
  spn.style.fontFamily = el.style.fontFamily;
  spn.style.fontSize = el.style.fontSize;
  spn.style.fontWeight = el.style.fontWeight;
  spn.style.whiteSpace = el.style.whiteSpace;
  spn.style.width = "auto";
  spn.innerHTML = str;
  document.body.appendChild(spn);
  
  var retVal = xWidth(spn);
  spn.parentNode.removeChild(spn);
  
  return retVal;
}


function trim(str)
{
  return str.replace(/^\s+|\s+$/gi, '');
}


function nums(str)
{
  return str.replace(/[^0-9.]/g,"");
}


xAnimation.prototype.transformScale = function(e,startScale,endScale,t,a,b,oe)
{
  var i = this;
  
  i.axes(1);
  
  i.a[0].i = startScale;  
  i.a[0].t = endScale;
  
  i.init(e,t,h,h,oe,a,b);
  
  i.run();
  
  function h(i) 
  {
    i.e.style[transformPropertyName] = "scale(" + i.a[0].v + ")";
  }
};


// xAnimation.sizeLine r1, Copyright 2009-2010 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
/**
 @param e ID string or object reference of the element to be animated.
 @param s A "sequence" array.
 @param a Acceleration type.
 @param b Number of bounces.
 @param oe onEnd handler. Return true to repeat sequence.
*/
xAnimation.prototype.sizeLineMod = function(e,s,a,b,oe)
{
  var i = this, si = 0;
  i.axes(4); // axes: x, y, w and h
  prep();
  i.run();
  function h(i) { // onRun and onTarget
    // set position
    i.e.style.left = Math.round(i.a[0].v) + 'px';
    i.e.style.top = Math.round(i.a[1].v) + 'px';
    // set size
    xWidth(i.e, Math.round(i.a[2].v));
    //xHeight(i.e, Math.round(i.a[3].v));
  }
  // onEnd handler
  function end(i) {
    if (++si < s.length) {
      prep();
      return true; // start next animation in sequence
    }
    else {
      if (oe && oe(i)) {
        si = 0;
        prep();
        return true; // restart sequence
      }
      return false; // stop
    }
  }
  // prepare for the next animation in the sequence
  function prep() {
    // initial position
    i.a[0].i = xLeft(e);
    i.a[1].i = xTop(e);
    // target position
    i.a[0].t = Math.round(s[si][0]);
    i.a[1].t = Math.round(s[si][1]);
    // initial size
    i.a[2].i = xWidth(e);
    //i.a[3].i = xHeight(e);
    // target size
    i.a[2].t = Math.round(s[si][2]);
    i.a[3].t = Math.round(s[si][3]);
    i.init(e,s[si][4],h,h,end,a,b);
  }
};


function cancelEvent(e) 
{
	if (e == null)
	{
		e = window.event;
	}
	
  if (!window.attachEvent) 
  {
    e.stopPropagation();
    e.preventDefault();    
    return false
  }
  
  e.cancelBubble = true;
  e.returnValue=false
  
  return false
}


function hiTagZ()
{

	highestZ = 0;
	
	var tagArray = ["DIV","IFRAME","IMG","A","UL","LI","OBJECT"];
	
	for ( y = 0; y < tagArray.length; y++ )
	{
			var curTag = tagArray[y];
			var a = document.getElementsByTagName(curTag);
			for ( var z = 0; z < a.length; z++ )
			{
				var i = xGetComputedStyle(a[z],"z-index",true);
				if (i)
				{
					if (i > highestZ) { highestZ = i; }
				}
			}			
	}
		
}


function removeScript(scrName) {
  var a = document.getElementsByTagName("SCRIPT");
  for (var z = 0; z < a.length; z++) {
    if (a[z]["src"].toLowerCase().indexOf(scrName.toLowerCase()) > -1) 
    {
      a[z].parentNode.removeChild(a[z]);
    }
  }
}


// need to add error handling for bad URL
function injectJS(jsUrl, jsOnload, addRandomParam) 
{
  var _i = this;

  _i.scriptTag = null;
  
  _i.jsUrl = null;
  _i.jsOnload = null;
  _i.addRandomParam = null;
  

  _i.jsOnreadystate = function() {

    if ((_i.scriptTag.readyState == "loaded") || (_i.scriptTag.readyState == "complete")) 
    {
      _i.jsOnload();
    }

  }

  _i.constructor = function() {

    _i.jsUrl = jsUrl;
    _i.jsOnload = jsOnload;
    _i.addRandomParam = addRandomParam;
    
    removeScript(_i.jsUrl);

    var headID = document.getElementsByTagName("HEAD")[0];
    _i.scriptTag = document.createElement("SCRIPT");
    _i.scriptTag.type = 'text/javascript';

    if (_i.jsOnload != null) {
      _i.scriptTag.onload = _i.jsOnload;
      _i.scriptTag.onreadystatechange = _i.jsOnreadystate;
    }

    if ( _i.addRandomParam == true )
    {
      var concatChar = ( _i.jsUrl.indexOf("?") == -1 ) ? "?" : "&";
      _i.jsUrl += concatChar + "randomParam=" + Math.round(Math.random() * 100000);
    }
    
    _i.scriptTag.src = _i.jsUrl;
    headID.appendChild(_i.scriptTag);
  }


  _i.constructor();

}


function browserPlatformConstants()
{  
  isMacintosh = false;
  if (navigator.userAgent.indexOf("Macintosh") > -1) { isMacintosh = true; }
  
  isFirefox = false;
  if (navigator.userAgent.indexOf("Firefox") > -1) { isFirefox = true; }

  isOpera = false;
  if (navigator.userAgent.indexOf("Opera") > -1) { isOpera = true; }
  
  isIE = false;
  if (navigator.userAgent.indexOf("MSIE") > -1) { isIE = true; }
    
  isIE9 = false;
  if (navigator.userAgent.indexOf("MSIE 9") > -1) { isIE9 = true; }
  
  isChrome = false;
  if (navigator.userAgent.indexOf("Chrome") > -1) { isChrome = true; }
  
  isSafari = false;
  if ((navigator.userAgent.indexOf("Safari") > -1) && ( isChrome == false )) { isSafari = true; }
  
  isIplatform = false;
  if ((navigator.userAgent.toLowerCase().indexOf("ipod") > -1) ||
     (navigator.userAgent.toLowerCase().indexOf("iphone") > -1) ||
     (navigator.userAgent.toLowerCase().indexOf("ipad") > -1))
  {
    isIplatform = true;
  }


  fontFamilyAddendum = "";
  //if (navigator.userAgent.indexOf("MSIE 9") > -1 ) { fontFamilyAddendum = "MSIE9"; }
  //if (navigator.userAgent.indexOf("MSIE") > -1 ) { fontFamilyAddendum = "MSIE9"; }
  
  
  transformPropertyName = "";
  //if (navigator.userAgent.indexOf("MSIE 9") > -1 ) { transformPropertyName = "msTransform"; }
  if (navigator.userAgent.indexOf("Safari") > -1) { transformPropertyName = "WebkitTransform"; }
  if (navigator.userAgent.indexOf("Chrome") > -1) { transformPropertyName = "WebkitTransform"; }
  if (navigator.userAgent.indexOf("Opera") > -1 ) { transformPropertyName = "OTransform"; }
  if (navigator.userAgent.indexOf("Firefox") > -1 ) { transformPropertyName = "MozTransform"; }
}


function imgPreload( url, onload )
{
  var _i = this;
  
  _i.img = null;
  _i.onload = null;
  
  
  _i.imgOnload = function()
  {
    if ( _i.onload != null )
    {
      _i.onload();
    }
    
    _i.img.src = "";
    _i.img = null;
  }
  
  
  _i.constructor = function()
  {
    _i.onload = onload;
    
    _i.img = document.createElement("IMG");
    _i.img.onload = _i.imgOnload;
    _i.img.src = url;
  }
  
  _i.constructor();
}




