//function mok3_getUrlParameter(param)
//{
//	var v = location.search.substring(1).split("&");
//  var n = v.length;
//	while(n--)
//	{
//		var p = v[n].split("=");
//		if (p[0] == param)
//			return unescape(p[1]);
//	}
//	return "";
//}

function mok3_getUrlParameter(param)
{
	var v = location.hash.substring(1).split("&");
  var n = v.length;
	while(n--)
	{
		var p = v[n].split("=");
		if (p[0] == param)
			return unescape(p[1]);
	}
	return "";
}

function mok3_setWidgetValue(widgetId, parameter, defaultValue)
{
	var widget = document.getElementById(widgetId);
	var paramVal = getUrlParameter(parameter)
	if (paramVal == "")
		widget.value = defaultValue;
	else
		widget.value = paramVal;
}

function mok3_getWidgetValue(widgetId, parameter)
{
	var widget = document.getElementById(widgetId);
	return widget.value;
}

function mok3_getWidgetValueAsParameter(widgetId, parameter)
{
	return parameter + "=" + escape(getWidgetValue(widgetId, parameter));
}

function mok3_getUniqueId()
{
	var timestamp = Date.parse(new Date());
	var randomNumber = Math.random();
	var uniqueId = "" + timestamp + randomNumber;
	return uniqueId;
}

function mok3_getStylePropertyForElement (element, cssPropertyName)
{
  if (!element)
    return null;

  if (window.getComputedStyle)
    return window.getComputedStyle(element,'').getPropertyValue(cssPropertyName.replace(/([A-Z])/g, "-$1").toLowerCase());
  else if (element.currentStyle)
    return element.currentStyle[cssPropertyName];
  return null;
}

function mok3_getStylePropertyForId (id, cssPropertyName)
{
  return mok3_getStylePropertyForElement(document.getElementById(id), cssPropertyName);
}

function mok3_setStylePropertyForElement (element, cssPropertyName, value)
{
  if (!element)
    return false;
    
  element.style[cssPropertyName] = value;
  return true;
}

function mok3_setStylePropertyForId (id, cssPropertyName, value)
{
  return mok3_setStylePropertyForElement(document.getElementById(id), cssPropertyName, value);
}

function mok3_getViewportWidth()
{
  if (window.innerWidth)
    return window.innerWidth;
  return document.documentElement.clientWidth;
}

function mok3_getViewportHeight()
{
  if (window.innerHeight)
    return window.innerHeight;
  return document.documentElement.clientHeight;
}

function mok3_pxToInt(px)
{
  return parseInt(px.substring(0, px.length - 2));
}

function mok3_intToPx(value)
{
  return value + 'px';
}

function mok3_getElementHeight(element)
{
  return mok3_pxToInt(mok3_getStylePropertyForElement(element, 'height'));
}

function mok3_getIdHeight(id)
{
  return mok3_getElementHeight(document.getElementById(id));
}

function mok3_getElementWidth(element)
{
  return mok3_pxToInt(mok3_getStylePropertyForElement(element, 'width'));
}

function mok3_getIdWidth(id)
{
  return mok3_getElementWidth(document.getElementById(id));
}

function mok3_setElementHeight(element, value)
{
  return mok3_setStylePropertyForElement(element, 'height', mok3_intToPx(value));
}

function mok3_setIdHeight(id, value)
{
  return mok3_setElementHeight(document.getElementById(id), value);
}

function mok3_setElementWidth(element, value)
{
  return mok3_setStylePropertyForElement(element, 'width', mok3_intToPx(value));
}

function mok3_setIdWidth(id, value)
{
  return mok3_setElementWidth(document.getElementById(id), value);
}

function mok3_setElementVisible(element, visible)
{
  if (!element)
    alert('mok3_setElementVisible - element missing');
  if (visible)
    mok3_setStylePropertyForElement(element, 'visibility', 'visible');
  else
    mok3_setStylePropertyForElement(element, 'visibility', 'hidden');
}

function mok3_setIdVisible(id, visible)
{
  mok3_setElementVisible(document.getElementById(id), visible);
}

function mok3_setElementDisplay(element, value)
{
  if (!element)
    alert('mok3_setElementDisplay - element missing');
  mok3_setStylePropertyForElement(element, 'display', value);
}

function mok3_setIdDisplay(id, value)
{
  mok3_setElementDisplay(document.getElementById(id), value);
}

function mok3_replaceElementContents(element, content)
{
  element.innerHTML = content;
}

function mok3_replaceIdContents(id, content)
{
	var element = document.getElementById(id);
	if (!element)
    alert('mok3_replaceIdContents - element missing\n' + id);
  element.innerHTML = content;
}

function mok3_setElementClass(element, cls)
{
  element.className = cls;
}

/// Set the element with id "id" to class "cls"
function mok3_setIdClass(id, cls)
{
  var elt = document.getElementById(id);
	if ( elt == null ) alert( 'cannot find elt ' + id );
	elt.className = cls;
}

/// Sets all elements with name "name" to class "cls"
/// Note: div's, according to the W3C specification, cannot
/// have names.  In FF it will find <div name="..."> but in IE
/// div's are ignored.
function mok3_setNameClass( name, cls )
{
	var elts = document.getElementsByName( name );
	for ( var i = 0; i < elts.length; ++i )
		elts[i].className = cls;
}

function mok3_hasCookie( name )
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return false;
	}
	return true;
}

function mok3_getCookie(name)
 {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
    }
    else
    {
      begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
      end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

// expires: if null, session cookie
//          if "", infinite cookie
//          else cookie expires on date specified
function mok3_setCookie(name, value, expires, path, domain, secure)
{
	var expirationDate;
	if ( expires == null )
	{
		expirationDate = null;
	}
	else if ( expires == "" )
	{
    expirationDate = new Date( "Jan 17, 2038 19:14:07" );
	}
	else
	  expirationDate = expires;
	
  document.cookie= name + "=" + escape(value) +
      ((expirationDate) ? "; expires=" + expirationDate.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
}

// Same as above, but with an expiration time is seconds
function mok3_setCookie2(name, value, expiresInSeconds, path, domain, secure)
{
  if (expiresInSeconds != null &&
      expiresInSeconds != "")
  {
    var expiration = (new Date()).getTime() + expiresInSeconds * 1000;
    var expirationDate = new Date();
    expirationDate.setTime(expiration);  
    mok3_setCookie(name, value, expirationDate, path, domain, secure);
  }
  else
    mok3_setCookie(name, value, expiresInSeconds, path, domain, secure);
}

/// Remember some browser remember cookies even after deletion-- until browser is restarted.
function mok3_deleteCookie( name, path, domain )
{
	if ( mok3_hasCookie( name ) )
	{
		var old = new Date( "Jan 1, 1970" );
		mok3_setCookie( name, "", old, path, domain );
	}
}

/// Extract the selected value in a combobox with name 'combobox_name'.
/// Returns null if nothing selected (or there were no options)
function mok3_getSelectedValueInComboBox( combobox_name )
{
	var cb = document.getElementById( combobox_name );
	if ( cb.selectedIndex < 0 )
		return null;
	return cb.options[ cb.selectedIndex ].value;
}

/// Trims whitespace around keyword, makes everything lower case, allows only alphanumeric characters
function mok3_cleanUpKeywordString( keys )
{
	var lowerKeys = keys.toLowerCase().replace( /[^a-z0-9 ]/g, '' );
	if ( lowerKeys.indexOf(' ') != -1)
	{
		var newKeys = '';
    var keysArray = lowerKeys.split(' ');
    for ( var i = 0; i < keysArray.length; ++i )
		{
			if ( keysArray[ i ].length == 0 )
				continue;
			if ( newKeys.length > 0 )
				newKeys += ' ';
			newKeys += keysArray[ i ];
		}
    return newKeys;
  }
	return lowerKeys;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function mok3_isIE()
{
  return (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
}

function mok3_isWin()
{
  return (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
}

function mok3_isFx()
{
  return ( navigator.userAgent.indexOf( "Firefox") != -1 ) ? true : false;
}

function mok3_isOpera()
{
  return (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
}

function mok3_isMacIE()
{
  return (navigator.userAgent.indexOf("Mac_PowerPC") != -1) &&
         (navigator.userAgent.indexOf("MSIE") != -1);
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function mok3_hasAtLeastFlashVersion(reqMajorVer, reqMinorVer, reqRevision) 
{
  var requiredVersion = new deconcept.PlayerVersion([reqMajorVer, reqMinorVer, reqRevision]);
  var currentVersion = deconcept.SWFObjectUtil.getPlayerVersion();
  return currentVersion.versionIsValid(requiredVersion);
}

// Window resizes itself to iWidth x iHeight.  May come up to the front if desired
// Set bFocus to boolean to bring the window up and front and make it completely visible
function mok3_resizeSelf( iWidth, iHeight, bFocus )
{
	window.resizeTo( iWidth + 200, iHeight + 200 );
	var myW = 0, myH = 0, d = document.documentElement, b = document.body;
	if( window.innerWidth ) { myW = window.innerWidth; myH = window.innerHeight; }
	else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
	else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
	//Opera 6- adds on 16 pixels for the non-existent scrollbar
	if( window.opera && !document.childNodes ) { myW += 16; }
	if ( window.navigator ) { myH -= 1; }
	window.resizeTo( iWidth + ( ( iWidth + 200 ) - myW ), iHeight + ( ( iHeight + 200 ) - myH ) );
	
	if ( bFocus && this.focus ) { this.focus(); }
}

function mok3_showFloatingDiv( divName, shimName )
{
	var divElt = document.getElementById( divName );
	var shim = document.getElementById( shimName );
 
  divElt.style.display = 'block';

	shim.style.width = divElt.offsetWidth;
  shim.style.height = divElt.offsetHeight;
	shim.style.top = divElt.style.top;
	shim.style.left = divElt.style.left;
	shim.style.right = divElt.style.right;
	shim.style.zIndex = divElt.style.zIndex - 1;
	shim.style.display = 'block';
//	alert( shim.style.width+' ' +shim.style.height+' / ' + shim.style.bottom+ ' / ' + shim.style.zIndex );
}

function mok3_hideFloatingDiv( divName, shimName )
{
	document.getElementById( divName ).style.display = 'none';
	document.getElementById( shimName ).style.display = 'none';
}
