/* Livesearch */ 

function search_redirect () {
    if (document.searchform.SearchableText.value == "") {
        document.searchform.action = "lemill_search_form";
        document.searchform.submit();
    } else
        document.searchform.submit();
}
/*
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 Bitflux GmbH                                      |
// +----------------------------------------------------------------------+
// | Licensed under the Apache License, Version 2.0 (the "License");      |
// | you may not use this file except in compliance with the License.     |
// | You may obtain a copy of the License at                              |
// | http://www.apache.org/licenses/LICENSE-2.0                           |
// | Unless required by applicable law or agreed to in writing, software  |
// | distributed under the License is distributed on an "AS IS" BASIS,    |
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or      |
// | implied. See the License for the specific language governing         |
// | permissions and limitations under the License.                       |
// +----------------------------------------------------------------------+
// | Author: Bitflux GmbH <devel@bitflux.ch>                              |
// +----------------------------------------------------------------------+
*/

var liveSearchReq = false;
var t = null;
var liveSearchLast = "";
var queryTarget = "livesearch_reply?q=";

var searchForm = null;
var searchInput = null;

var isIE = false;

var _cache = new Object();

var widthOffset = 1;

function calculateWidth() {
}

function getElementDimensions(elemID) {
    var base = document.getElementById(elemID);
    var offsetTrail = base;
    var offsetLeft = 0;
    var offsetTop = 0;
    var width = 0;

    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 &&
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    if (!isIE)
        width = searchInput.offsetWidth-widthOffset*2;
    else
        width = searchInput.offsetWidth;
    return { left: offsetLeft,
             top: offsetTop,
             width: width,
             height: base.offsetHeight,
             bottom: offsetTop + base.offsetHeight,
             right: offsetLeft + width};
}

function liveSearchInit() {
    searchInput = document.getElementById('searchGadget');
    if (searchInput == null || searchInput == undefined)
        return
    // Only keypress catches repeats in moz/FF but keydown is needed for
    // khtml based browsers.
    if (navigator.userAgent.indexOf("KHTML") > 0) {
        searchInput.addEventListener("keydown",liveSearchKeyPress,false);
        searchInput.addEventListener("focus",liveSearchDoSearch,false);
        searchInput.addEventListener("keydown",liveSearchStart, false);
        searchInput.addEventListener("blur",liveSearchHideDelayed,false);
    } else if (searchInput.addEventListener) {
        searchInput.addEventListener("keypress",liveSearchKeyPress,false);
        searchInput.addEventListener("blur",liveSearchHideDelayed,false);
        searchInput.addEventListener("keypress",liveSearchStart, false);
    } else {
        searchInput.attachEvent("onkeydown",liveSearchKeyPress);
        searchInput.attachEvent("onkeydown",liveSearchStart);
        searchInput.attachEvent("onblur",liveSearchHideDelayed);
        isIE = true;
    }

    // Why doesn't this work in konq, setting it inline does.
    searchInput.setAttribute("autocomplete", "off");
    var pos = getElementDimensions('searchGadget');
    result = document.getElementById('LSResult');
    if ((typeof result.offsetParent != 'undefined') && (result.offsetParent != null)) {
        pos.left = pos.left - result.offsetParent.offsetLeft + pos.width;
    } else {
        pos.left = pos.left + pos.width;
    }
    result.style.display = 'none';
}


function liveSearchHideDelayed() {
    window.setTimeout("liveSearchHide()", 400);
}

function liveSearchHide() {
    document.getElementById("LSResult").style.display = "none";
    var highlight = document.getElementById("LSHighlight");
    if (highlight)
        highlight.removeAttribute("id");
}

function getFirstHighlight() {
    var set = getHits();
    return set[0];
}

function getLastHighlight() {
    var set = getHits();
    return set[set.length-1];
}

function getHits() {
    var res = document.getElementById("LSShadow");
    var set = res.getElementsByTagName('li');
    return set;
}

function findChild(object, specifier) {
    var cur = object.firstChild;
    try {
        while (cur != undefined) {
            cur = cur.nextSibling;
            if (specifier(cur) == true)
                return cur;
        }
    } catch(e) {};
    return null;
}

function findNext(object, specifier) {
    var cur = object;
    try {
        while (cur != undefined) {
            cur = cur.nextSibling;
            if (cur.nodeType==3)
                cur=cur.nextSibling;
            if (cur != undefined) {
                if (specifier(cur) == true)
                    return cur;
            } else { break; }
        }
    } catch(e) {};
    return null;
}

function findPrev(object, specifier) {
    var cur = object;
    try {
        cur = cur.previousSibling;
        if (cur.nodeType == 3)
            cur = cur.previousSibling;
        if (cur != undefined) {
            if (specifier(cur) == true)
                return cur;
        }
    } catch(e) {};
    return null;
}

function liveSearchKeyPress(event) {
    var highlight = document.getElementById("LSHighlight");
    if (event.keyCode == 40 )
    //KEY DOWN
    {
        if (!highlight) {
            highlight = getFirstHighlight();
        } else {
            highlight.removeAttribute("id");
            highlight = findNext(highlight, function (o) {return o.className =="LSRow";});
        }
        if (highlight)
            highlight.setAttribute("id","LSHighlight");
        if (!isIE)
            event.preventDefault();
    }
    //KEY UP
    else if (event.keyCode == 38 ) {
        if (!highlight) {
            highlight = getLastHighlight();
        }
        else {
            highlight.removeAttribute("id");
            highlight = findPrev(highlight, function (o) {return o.className=='LSRow';});
        }
        if (highlight)
            highlight.setAttribute("id","LSHighlight");
        if (!isIE)
            event.preventDefault();
    }
    //ESC
    else if (event.keyCode == 27) {
        if (highlight)
            highlight.removeAttribute("id");
        document.getElementById("LSResult").style.display = "none";
    }
}

function liveSearchStart(event) {
    if (t) {
        window.clearTimeout(t);
    }
    var code = event.keyCode;
    if (code!=40 && code!=38 && code!=27 && code!=37 && code!=39) {
        t = window.setTimeout("liveSearchDoSearch()", 200);
    }
}

function liveSearchDoSearch() {
    if (typeof liveSearchRoot == "undefined") {
        if (typeof portal_url == "undefined") {
            liveSearchRoot = "";
        } else {
            if (portal_url[portal_url.length-1] == '/') {
                liveSearchRoot = portal_url;
            } else {
                liveSearchRoot = portal_url + '/';
            }
        }
    }
    if (typeof liveSearchRootSubDir == "undefined") {
        liveSearchRootSubDir = "";
    }
    if (liveSearchLast != searchInput.value) {
        if (liveSearchReq && liveSearchReq.readyState < 4) {
            liveSearchReq.abort();
        }
        if ( searchInput.value == "") {
            liveSearchHide();
            return false;
        }
        // Do nothing as long as we have less then two characters -
        // the search results makes no sense, and it's harder on the server.
        if ( searchInput.value.length < 2) {
            liveSearchHide();
            return false;
        }
        // Do we have cached results
        var result = _cache[searchInput.value];
        if (result) {
            showResult(result);
            return;
        }
        liveSearchReq = new XMLHttpRequest();
        liveSearchReq.onreadystatechange = liveSearchProcessReqChange;
        // Need to use encodeURIComponent instead of encodeURI, to escape +
        liveSearchReq.open("GET", liveSearchRoot + queryTarget + encodeURIComponent(searchInput.value));
        liveSearchLast = searchInput.value;
        liveSearchReq.send(null);
    }
}

function showResult(result) {
    var res = document.getElementById("LSResult");
    res.style.display = "block";
    var sh = document.getElementById("LSShadow");
    sh.innerHTML = result;
}

function liveSearchProcessReqChange() {
    if (liveSearchReq.readyState == 4) {
        try {
            if (liveSearchReq.status > 299 || liveSearchReq.status < 200  ||
                liveSearchReq.responseText.length < 10)
                return;
        } catch(e) {
            return;
        }
        showResult(liveSearchReq.responseText);
        _cache[liveSearchLast] = liveSearchReq.responseText;
    }
}

function liveSearchSubmit() {
    var highlight = document.getElementById("LSHighlight");
    if (highlight) {
        var targets = highlight.getElementsByTagName('a');
        if (targets.length == 0)
            return true;
        var target = targets[0].href;
        if (!target)
            return true;
        if ((liveSearchRoot.length > 0) && (target.substring(0, liveSearchRoot.length) != liveSearchRoot)) {
            window.location = liveSearchRoot + liveSearchRootSubDir + target;
        } else {
            window.location = target;
        }
        return false;
    } else {
        return true;
    }
}

if (window.addEventListener)
    window.addEventListener("load", liveSearchInit, false);
else if (window.attachEvent)
    window.attachEvent("onload", liveSearchInit);


/* Functions used by login pages */

function cookiesEnabled() {
  // Test whether cookies are enabled by attempting to set a cookie and then change its value
  // set test cookie
  var c = "areYourCookiesEnabled=0";
  document.cookie = c;
  var dc = document.cookie;
  // cookie not set?  fail
  if (dc.indexOf(c) == -1) return 0;
  // change test cookie
  c = "areYourCookiesEnabled=1";
  document.cookie = c;
  dc = document.cookie;
  // cookie not changed?  fail
  if (dc.indexOf(c) == -1) return 0;
  // delete cookie
  document.cookie = "areYourCookiesEnabled=; expires=Thu, 01-Jan-70 00:00:01 GMT";
  return 1;
}

function setLoginVars(user_name_id, alt_user_name_id, password_id, empty_password_id, js_enabled_id, cookies_enabled_id) {
  // Indicate that javascript is enabled, set cookie status, copy username and password length info to 
  // alternative variables since these vars are removed from the request by zope's authentication mechanism.
  if (js_enabled_id) {
    el = document.getElementById(js_enabled_id);
    if (el) { el.value = 1; }
  }
  if (cookies_enabled_id) {
    el = document.getElementById(cookies_enabled_id);
    // Do a fresh cookies enabled test every time we press the login button
    //   so that we are up to date in case the user enables cookies after seeing
    //   the cookies message.
    if (el) { el.value = cookiesEnabled(); } 
  }
  if (user_name_id && alt_user_name_id) {
    user_name = document.getElementById(user_name_id)
    alt_user_name = document.getElementById(alt_user_name_id)
    if (user_name && alt_user_name) {
       alt_user_name.value = user_name.value;
    } 
  }
  if (password_id && empty_password_id) {
    password = document.getElementById(password_id)
    empty_password = document.getElementById(empty_password_id)
    if (password && empty_password) {
       if (password.value.length==0) {
          empty_password.value = '1';
       } else {
          empty_password.value = '0';
       }
    }
  }
  return 1;
}

function showCookieMessage(msg_id) {
  // Show the element with the given id if cookies are not enabled
  msg = document.getElementById(msg_id)
  if (msg) {
     if (cookiesEnabled()) {
        msg.style.display = 'none';
     } else {
        msg.style.display = 'block';
     }
  }
}



/* js_helpers.js */

var isNav4, isNav6, isIE4;
if (navigator.appVersion.charAt(0) == "4"){
    if (navigator.appName.indexOf("Explorer") >= 0){
        isIE4 = true;
    }
    else{
        isNav4 = true;
    }
}
else if (navigator.appVersion.charAt(0) > "4"){
    isNav6 = true;
}

var list_expanded=false;
function listtoggle(){
        var rlist="resource_list";
        var views_menu="views_menu";
    if(!list_expanded){
        document.getElementById(rlist).className="expanded";
        document.getElementById(views_menu).selectedIndex=1;
        list_expanded=true;
    }else{
        document.getElementById(rlist).className="cover";
        document.getElementById(views_menu).selectedIndex=0;
        list_expanded=false;
    }
}

function show_div(divid)
{
    document.getElementById(divid).style.display = 'block';
}

function hide_div(divid)
{
    document.getElementById(divid).style.display = 'none';
}

function next(id)
{
    steps=['selection'];
    for (i=0; i<steps.length; i=i+1){
        setIdProperty(steps[i], "display", "none");
    }
    setIdProperty(id, "display", "block");
}

/*
 * Functions that get or set some properties
 */

function setIdProperty( id, property, value ){
    if (isNav6){
        var styleObject = document.getElementById( id );
        if (styleObject != null){
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }
    }
    else if (isNav4){
        document[id][property] = value;
    }
    else if (isIE4){
        document.all[id].style[property] = value;
    }
}

function getIdProperty( id, property )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            if (styleObject[property])
            {
                return styleObject[ property ];
            }
        }
        styleObject = getStyleBySelector( "#" + id );
        return (styleObject != null) ?
            styleObject[property] :
            null;
    }
    else if (isNav4)
    {
        return document[id][property];
    }
    else
    {
        return document.all[id].style[property];
    }
}

function getStyleBySelector( selector )
{
    if (!isNav6)
    {
        return null;
    }
    var sheetList = document.styleSheets;
    var ruleList;
    var i, j;

    /* look through stylesheets in reverse order that
       they appear in the document */
    for (i=sheetList.length-1; i >= 0; i--)
    {
        ruleList = sheetList[i].cssRules;
        for (j=0; j<ruleList.length; j++)
        {
            if (ruleList[j].type == CSSRule.STYLE_RULE ||
                    ruleList[j].selectorText == selector)
            {
                return ruleList[j].style;
            }
        }
    }
    return null;
}

/*
 * Functino that hides educational fields on base_metadata page
 */
function hide_educational()
{
    change_educational('none', 'block')
}

function show_educational()
{
    change_educational('block', 'none')
}

function change_educational(act1, act2)
{
    document.getElementById('archetypes-fieldname-learningResourceType').style.display = act1;
    document.getElementById('archetypes-fieldname-endUserRole').style.display = act1;
    document.getElementById('archetypes-fieldname-learningContext').style.display = act1;
    document.getElementById('archetypes-fieldname-educationalInfo').style.display = act2;
}

function setValue(elem_id, value)
{
    document.getElementById(elem_id).value = value;
}

var config_values = new Object;
function parseConfig() {
    dataelem = document.getElementById('dataisland');

    eles = dataelem.getElementsByTagName('configset')[0];
    dataelem = eles;
    for (var c=0; c<dataelem.childNodes.length; c++)
    {
        wele = dataelem.childNodes[c];
        if ( wele.nodeName.toLowerCase() == 'config' )
        {
            config_values[wele.getAttribute('id')] = wele.childNodes[0].nodeValue;
        }
    }
}

function getConfig(key) {
    
    if ( !config_values[key] )
        parseConfig();
    return config_values[key];
}

function search_for_pieces(event, index, search_type)
{
    results_box_ID = 'piece-search-results-'+index; // =piece-search-results

    div = document.getElementById(results_box_ID);
    div.style.display = 'block';

    search_box_id = 'piece-search-'+index; // =piece-search-
    val = document.getElementById(search_box_id).value;
    if (!val) {
        return;
    }    
    
    div2 = document.getElementById(results_box_ID + '-body');
    // Workaround for IE, delete already existing chilld not to get an error
    if (div2.childNodes.length>0)
    {
        div2.removeChild(div2.lastChild);
    }
    div2.innerHTML += '<b>Please wait while we process your query</b>';

    call_remote('js_queryForPieces', 'keyword='+val+','+search_type, ParseSearchResults, index, search_type);
}

function ParseSearchResults(response, index, search_type)
{
    results_box_ID = 'piece-search-results-'+index;
    pieces = eval(response);
    div = document.getElementById(results_box_ID);
    div.style.display = 'block';
    div = document.getElementById(results_box_ID+'-body');
    div.innerHTML = '';
    if (pieces.length==0){
        div.innerHTML = '<b>No results found</b>';      
        return ;
    }    
    // Workaround for IE, create new div and append it as a child - the only way it wanted to work
    var t = document.createElement('div');
    t.innerHTML = '<div class="piece_chooser">';
    for ( var i=0; i<pieces.length; i++) 
    {
        htm=''
        // pseudometadata = [r.UID, cover_url, r.Title, r.getPiece_type, image_url]
        link ='<a href="javascript:chapter_add_multimedia('+index+',\''+pieces[i][0]+'\',\''+pieces[i][1]+'\',\''+pieces[i][2]+'\',\''+pieces[i][3]+'\',\''+pieces[i][4]+'\');">';
        htm += '<dl><dt>'+link+'<img src="'+pieces[i][1]+'" /></a></dt>';
        htm += '<dd>'+link+pieces[i][2]+'</a></dd></dl>';
        t.innerHTML += htm;
    }
    t.innerHTML += '</div>';
    div.appendChild(t);
}

function chapter_add_multimedia(index, uid, cover_url, title, piece_type, image_url)
{
    // place image to background
    if (piece_type=='image'){
        div = document.getElementById('piece-edit-box-'+index);
        div.style.backgroundImage = 'url('+image_url+')';            
        div = document.getElementById('piece-media-box-'+index);
        div.innerHTML = '';
        div = document.getElementById('piece-controls-edit-'+index);
        div.className='contrast';
    }
    else if (piece_type=='cover_image'){
    // place coverimage to box
        div = document.getElementById('piece-media-box-'+index);
        div.innerHTML = '<img src="'+cover_url+'"><br/>';
    }
    else {
    // place coverimage to box
        div = document.getElementById('piece-edit-box-'+index);
        div.style.backgroundImage = 'none';            
        div = document.getElementById('piece-media-box-'+index);
        div.innerHTML = '<img src="'+cover_url+'"><br/><b>'+title+'</b>';
        div = document.getElementById('piece-controls-edit-'+index);
        div.className='';
    }

    reference = document.getElementById('bodyText_'+index);
    reference.value = uid;
    div = document.getElementById('piece-search-results-'+index);
    div.style.display = 'none';
}

/*
* receiving_end - method to call on server.
* data - arguments to method
*/
function call_remote(receiving_end, data, next_action, attr1, attr2)
{
    var xmlObj = null;
    if ( window.XMLHttpRequest ) {
        xmlObj = new XMLHttpRequest();
    } else if ( window.ActiveXObject ) {
        xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        return;
    }

    xmlObj.onreadystatechange = function()
    {
        if(xmlObj.readyState == 4)
        {
            next_action(xmlObj.responseText, attr1, attr2);
        }
    }

    xmlObj.open('POST', receiving_end, true);
    xmlObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlObj.send(data);
}

function edit_slide(index){
    document.getElementById('bodyText_edited').value=index;
    document.getElementById('edit_button_'+index).style.display='none';
    document.getElementById('save_button_'+index).style.display='inline';
    document.getElementById('piece-controls-edit-'+index).style.display='block';
    document.getElementById('piece-controls-view-'+index).style.display='none';
    document.getElementById('caption_edit_'+(parseInt(index)+1)).style.display='block';
    document.getElementById('caption_view_'+(parseInt(index)+1)).style.display='none';
}

function SWFtimerFnc(args){
    try{
        var width = args[1].TGetProperty('/', 8);
        var height = args[1].TGetProperty('/', 9);
        if(width != undefined && height != undefined){
            clearInterval(eval(args[0]));
            if(width > 500){
                args[1].setAttribute('width', 500);
                args[1].setAttribute('height', 500 * height / width);
            }
            else{
                args[1].setAttribute('width', width);
                args[1].setAttribute('height', height);
            }
        }
    }
    catch (ex){}
}

function delItem(deltext){
    del_text = document.getElementById(deltext).innerHTML
    return confirm(del_text)
}


/* AC_RunActiveContent.js */

//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.
// Removed stupid url suffix functionality, LeMill team, 2007
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, "", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function SWFtimerFnc(){
    try{
        var width = window.document.swfPiece.TGetProperty('/', 8);
        var height = window.document.swfPiece.TGetProperty('/', 9);
        if(width != undefined && height != undefined){
            clearInterval(SWFtimer);
            if(width > 500){
                window.document.swfPiece.setAttribute('width', 500);
                window.document.swfPiece.setAttribute('height', 500 * height / width);
            }
            else{
                window.document.swfPiece.setAttribute('width', width);
                window.document.swfPiece.setAttribute('height', height);
            }
        }
    }
    catch (ex){}
}



