
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - orderablereference.js - */
// http://www.bmctv.com/portal_javascripts/orderablereference.js?original=1
function oref_top(obj){obj=(typeof obj=="string")?document.getElementById(obj):obj;if(obj.tagName.toLowerCase()!="select"&&obj.length<2)
return false;var elements=new Array();for(var i=0;i<obj.length;i++){if(obj[i].selected){elements[elements.length]=new Array((document.body.innerHTML?obj[i].innerHTML:obj[i].text),obj[i].value,obj[i].style.color,obj[i].style.backgroundColor,obj[i].className,obj[i].id,obj[i].selected)}}
for(i=0;i<obj.length;i++){if(!obj[i].selected){elements[elements.length]=new Array((document.body.innerHTML?obj[i].innerHTML:obj[i].text),obj[i].value,obj[i].style.color,obj[i].style.backgroundColor,obj[i].className,obj[i].id,obj[i].selected)}}
for(i=0;i<obj.length;i++){if(document.body.innerHTML) obj[i].innerHTML=elements[i][0];else obj[i].text=elements[i][0];obj[i].value=elements[i][1];obj[i].style.color=elements[i][2];obj[i].style.backgroundColor=elements[i][3];obj[i].className=elements[i][4];obj[i].id=elements[i][5];obj[i].selected=elements[i][6]}}
function oref_bottom(obj){obj=(typeof obj=="string")?document.getElementById(obj):obj;if(obj.tagName.toLowerCase()!="select"&&obj.length<2)
return false;var elements=new Array();for(var i=0;i<obj.length;i++){if(!obj[i].selected){elements[elements.length]=new Array((document.body.innerHTML?obj[i].innerHTML:obj[i].text),obj[i].value,obj[i].style.color,obj[i].style.backgroundColor,obj[i].className,obj[i].id,obj[i].selected)}}
for(i=0;i<obj.length;i++){if(obj[i].selected){elements[elements.length]=new Array((document.body.innerHTML?obj[i].innerHTML:obj[i].text),obj[i].value,obj[i].style.color,obj[i].style.backgroundColor,obj[i].className,obj[i].id,obj[i].selected)}}
for(i=obj.length-1;i>-1;i--){if(document.body.innerHTML) obj[i].innerHTML=elements[i][0];else obj[i].text=elements[i][0];obj[i].value=elements[i][1];obj[i].style.color=elements[i][2];obj[i].style.backgroundColor=elements[i][3];obj[i].className=elements[i][4];obj[i].id=elements[i][5];obj[i].selected=elements[i][6]}}
function oref_up(obj){var obj_string=obj;obj=(typeof obj=="string")?document.getElementById(obj):obj;if(obj.tagName.toLowerCase()!="select"&&obj.length<2)
return false;var sel=new Array();for(var i=0;i<obj.length;i++){if(obj[i].selected==true){sel[sel.length]=i}}
for(i in sel){if(sel[i]!=0){if(obj[sel[i]-1]){if(!obj[sel[i]-1].selected){var tmp=new Array((document.body.innerHTML?obj[sel[i]-1].innerHTML:obj[sel[i]-1].text),obj[sel[i]-1].value,obj[sel[i]-1].style.color,obj[sel[i]-1].style.backgroundColor,obj[sel[i]-1].className,obj[sel[i]-1].id);if(document.body.innerHTML) obj[sel[i]-1].innerHTML=obj[sel[i]].innerHTML;else obj[sel[i]-1].text=obj[sel[i]].text;obj[sel[i]-1].value=obj[sel[i]].value;obj[sel[i]-1].style.color=obj[sel[i]].style.color;obj[sel[i]-1].style.backgroundColor=obj[sel[i]].style.backgroundColor;obj[sel[i]-1].className=obj[sel[i]].className;obj[sel[i]-1].id=obj[sel[i]].id;if(document.body.innerHTML) obj[sel[i]].innerHTML=tmp[0];else obj[sel[i]].text=tmp[0];obj[sel[i]].value=tmp[1];obj[sel[i]].style.color=tmp[2];obj[sel[i]].style.backgroundColor=tmp[3];obj[sel[i]].className=tmp[4];obj[sel[i]].id=tmp[5];obj[sel[i]-1].selected=true;obj[sel[i]].selected=false}}}}
inout_selectAllWords(obj_string)}
function oref_down(obj){var obj_string=obj;obj=(typeof obj=="string")?document.getElementById(obj):obj;if(obj.tagName.toLowerCase()!="select"&&obj.length<2)
return false;var sel=new Array();for(var i=obj.length-1;i>-1;i--){if(obj[i].selected==true){sel[sel.length]=i}}
for(i in sel){if(sel[i]!=obj.length-1){if(obj[sel[i]+1]){if(!obj[sel[i]+1].selected){var tmp=new Array((document.body.innerHTML?obj[sel[i]+1].innerHTML:obj[sel[i]+1].text),obj[sel[i]+1].value,obj[sel[i]+1].style.color,obj[sel[i]+1].style.backgroundColor,obj[sel[i]+1].className,obj[sel[i]+1].id);if(document.body.innerHTML) obj[sel[i]+1].innerHTML=obj[sel[i]].innerHTML;else obj[sel[i]+1].text=obj[sel[i]].text;obj[sel[i]+1].value=obj[sel[i]].value;obj[sel[i]+1].style.color=obj[sel[i]].style.color;obj[sel[i]+1].style.backgroundColor=obj[sel[i]].style.backgroundColor;obj[sel[i]+1].className=obj[sel[i]].className;obj[sel[i]+1].id=obj[sel[i]].id;if(document.body.innerHTML) obj[sel[i]].innerHTML=tmp[0];else obj[sel[i]].text=tmp[0];obj[sel[i]].value=tmp[1];obj[sel[i]].style.color=tmp[2];obj[sel[i]].style.backgroundColor=tmp[3];obj[sel[i]].className=tmp[4];obj[sel[i]].id=tmp[5];obj[sel[i]+1].selected=true;obj[sel[i]].selected=false}}}}
inout_selectAllWords(obj_string)}
function inout_selectAllWords(theList){myList=document.getElementById(theList);for(var x=0;x<myList.length;x++){myList[x].selected="selected"}}
function inout_addNewKeyword(toList,newText,newValue){theToList=document.getElementById(toList);for(var x=0;x<theToList.length;x++){if(theToList[x].text==newText){return false}}
theLength=theToList.length;theToList[theLength]=new Option(newText);theToList[theLength].value=newValue}
function inout_moveKeywords(fromList,toList,selectThese){theFromList=document.getElementById(fromList);for(var x=0;x<theFromList.length;x++){if(theFromList[x].selected){inout_addNewKeyword(toList,theFromList[x].text,theFromList[x].value)}}
theToList=document.getElementById(fromList);for(var x=theToList.length-1;x>=0 ;x--){if(theToList[x].selected){theToList[x]=null}}
inout_selectAllWords(selectThese)}


/* - ++resource++bmctv.video.js - */
// constants
// var FLASH_OBJECT_PARAM = '<param name="flashvars" value="autostart=false& brandname=bmc.tv& brandlink=http%3A%2F%2Fwww.bmctv.com& thumb=${thumb_url}%2Fvideo_image" />';
var FLASH_OBJECT_PARAM = '<param name="flashvars" value="autostart=false&brandname=bmctv&brandlink=http://www.bmctv.com&thumb=${url}/video_image" />';
var NEW_FLASH_OBJECT_PARAM = '<param name="flashvars" value="thumb=${url}/video_image" />';

var FLASH_OBJECT_PARAM_WMODE = '<param name="wmode" value="transparent" />';

// var FLASH_EMBED_ATTR = 'flashvars="autostart=false& brandname=bmc.tv& brandlink=http%3A%2F%2Fwww.bmctv.com& thumb=${thumb_url}%2Fvideo_image"';
var FLASH_EMBED_ATTR = 'flashvars="autostart=false&brandname=bmctv&brandlink=http://www.bmctv.com&thumb=${url}/video_image"';
var NEW_FLASH_EMBED_ATTR = 'flashvars="thumb=${url}/video_image"';

var FLASH_EMBED_ATTR_WMODE = 'wmode="transparent"';

var FLASH_WIDTH_ATTR = '${width}';
var FLASH_HEIGHT_ATTR = '${height}';

var OBJECT_ELEMENT = '<object type="application/x-shockwave-flash" data="${url}" allowfullscreen="true"  id="showplayer" height="390" width="640"><param name="allowscriptaccess" value="always" /><param name="movie" value="${url}" /><param name="wmode" value="transparent" />';

kukit.actionsGlobalRegistry.register("bmctv-fixFlashCode", function(oper) {
    oper.evaluateParameters(['code', 'id'], {'condition':''}, 'bmctv-fixFlashCode action');

    var code = oper.parms.code;
    var id = oper.parms.id;
    var condition = oper.parms.condition;

    // test for flash video type == condition
    // test for object's <param name="movie">, it's value must contain condition string
    // and for embed's attribute src, must contain condition string
    if (condition != '') {
        var re1 = new RegExp('<object[^>]*data=[\'\"]?'+condition+'\S*[\'\"]?[^>]*>', 'i');
        var re2 = new RegExp('<embed[^>]*src=[\'\"]?'+condition+'\S*[\'\"]?[^>]*>', 'i');
        if (!(re1.test(code) || re2.test(code))) {
            return false;
        }
    }

    var element = document.getElementById(id);
    if (typeof(element) == "undefined") {
        return false;
    }

    var fixedCode = code;

    // check whether we have <embed> element with src attribute containing "http://blip.tv/play"
    // and without <object> element
    if (!(/<object /i).test(fixedCode) && (/<embed\s+([^>]*)src=['"]?http\:\/\/blip\.tv\/play/i).test(fixedCode)) {
        var url = (/<embed\s+[^>]*src=['"]?([^'"]+)['"]?/i).exec(code);
        fixedCode = OBJECT_ELEMENT.replace(/\$\{url\}/g, url[1]) + fixedCode + '</object>';
    }

    // add flashvars param only to old-fashioned embed/object elements
    if (!(/<embed\s+([^>]*)src=['"]?http\:\/\/blip\.tv\/play/i).test(fixedCode)) {
        var flash_obj_parm = FLASH_OBJECT_PARAM;
        var flash_embed_attribute = FLASH_EMBED_ATTR;
    } else {
        var flash_obj_parm = NEW_FLASH_OBJECT_PARAM;
        var flash_embed_attribute = NEW_FLASH_EMBED_ATTR;
    }

    // insert flashvars into object as <param />
    if (!(/<object([\s\S]*)<param\s+[^>]*name=['"]?flashvars['"]?/i).test(fixedCode)) {
        if ((/<embed\s+/i).test(fixedCode)) {
            fixedCode = fixedCode.replace(/(<embed\s+)/i, ' ' + flash_obj_parm + '$1');
        } else {
            fixedCode = fixedCode.replace(/<\/object>/i, ' ' + flash_obj_parm + '$1');
        }
    } else {                    // temporary for fix bug: spaces in flashvars parameter value
        fixedCode = fixedCode.replace(/<param\s+[^>]*name=['"]?flashvars\b['"]?[^>]*\/?>/i, flash_obj_parm);
    }

    // insert flashvars into embed as attribute
    if (!(/<embed\s+([^>]*)flashvars=[^>]*\/?>/i).test(fixedCode)) {
        if ((/<embed\s+/i).test(fixedCode)) {
            fixedCode = fixedCode.replace(/(<embed\s+)/i, '$1 ' + flash_embed_attribute + ' ');
        }
    } else {                    // temporary for fix bug: spaces in flashvars attribute value
        fixedCode = fixedCode.replace(/(<embed\s+[^>]*)flashvars=['"]?[^'"]+['"]?([^>]*\/?>)/i, '$1' + flash_embed_attribute + '$2');
    }

    // insert width placeholder into object tag
    if ((/(<object[^>]*width=)['"]?[^\s>'"]*['"]?([^>]*>)/i).test(fixedCode)) {
        fixedCode = fixedCode.replace(/(<object[^>]*width=)['"]?[^\s>'"]*['"]?([^>]*>)/i, '$1"'+FLASH_WIDTH_ATTR+'"$2');
    } else {
        fixedCode = fixedCode.replace(/(<object)/i, '$1 width="'+FLASH_WIDTH_ATTR+'" ');
    }

    // insert height placeholder into object tag
    if ((/(<object[^>]*height=)['"]?[^\s>'"]*['"]?([^>]*>)/i).test(fixedCode)) {
        fixedCode = fixedCode.replace(/(<object[^>]*height=)['"]?[^\s>'"]*['"]?([^>]*>)/i, '$1"'+FLASH_HEIGHT_ATTR+'"$2');
    } else {
        fixedCode = fixedCode.replace(/(<object)/i, '$1 height="'+FLASH_HEIGHT_ATTR+'" ');
    }

    // insert width placeholder into embed tag
    if ((/(<embed[^>]*width=)['"]?[^\s>'"]*['"]?([^>]*>)/i).test(fixedCode)) {
        fixedCode = fixedCode.replace(/(<embed[^>]*width=)['"]?[^\s>'"]*['"]?([^>]*>)/i, '$1"'+FLASH_WIDTH_ATTR+'"$2');
    } else {
        fixedCode = fixedCode.replace(/(<embed)/i, '$1 width="'+FLASH_WIDTH_ATTR+'" ');
    }

    // insert height placeholder into embed tag
    if ((/(<embed[^>]*height=)['"]?[^\s>'"]*['"]?([^>]*>)/i).test(fixedCode)) {
        fixedCode = fixedCode.replace(/(<embed[^>]*height=)['"]?[^\s>'"]*['"]?([^>]*>)/i, '$1"'+FLASH_HEIGHT_ATTR+'"$2');
    } else {
        fixedCode = fixedCode.replace(/(<embed)/i, '$1 height="'+FLASH_HEIGHT_ATTR+'" ');
    }

    // insert wmode into object as <param />
    if (!(/<object([\s\S]*)<param\s+[^>]*name=['"]?wmode['"]?/i).test(fixedCode)) {
        if ((/<embed\s+/i).test(fixedCode)) {
            fixedCode = fixedCode.replace(/(<embed\s+)/i, ' '+FLASH_OBJECT_PARAM_WMODE+'$1');
        } else {
            fixedCode = fixedCode.replace(/(<\/object>)/i, ' '+FLASH_OBJECT_PARAM_WMODE+'$1');
        }
    }

    // insert wmode into embed as attribute
    if (!(/<embed\s+([^>]*)wmode=[^>]*\/?>/i).test(fixedCode)) {
        if ((/<embed\s+/i).test(fixedCode)) {
            fixedCode = fixedCode.replace(/(<embed\s+)/i, '$1 '+FLASH_EMBED_ATTR_WMODE+' ');
        }
    }

    element.value = fixedCode;

});

kukit.commandsGlobalRegistry.registerFromAction('bmctv-fixFlashCode', kukit.cr.makeSelectorCommand);

kukit.actionsGlobalRegistry.register("bmctv-registerFlashFix", function(oper) {
    oper.evaluateParameters(['type', 'id'], {'condition': ''}, 'bmctv-registerFlashFix action');

    var type = oper.parms.type;
    var form = document.getElementById(type + '-base-edit');
    if (typeof(form) == 'undefined' || form == null) {
        return false;
    }

    registerEventListener(form, 'submit', function(event) {
        // prepare oper for fix flash code action
        oper.node = document.getElementById(oper.parms.id);
        if (typeof(oper.node) == 'undefined' || oper.node == null) {
            return true;
        }

        delete oper.parms.type;
        var pp = new kukit.pr.CurrentFormVarPP();
        oper.parms.code = pp.eval([oper.parms.id], oper.node);
        oper.componentName = 'bmctv-fixFlashCode action';
        kukit.actionsGlobalRegistry.BBB_classParms(oper);
        kukit.actionsGlobalRegistry.get('bmctv-fixFlashCode')(oper);

        return true;
    });

});

kukit.commandsGlobalRegistry.registerFromAction('bmctv-registerFlashFix', kukit.cr.makeSelectorCommand);

kukit.actionsGlobalRegistry.register("bmctv-addFixLink", function(oper) {
    oper.evaluateParameters(['type', 'id'], {'condition':''}, 'bmctv-addFixLink action');

    var field_name = oper.parms.id;
    var field = document.getElementById(field_name + '_help');
    if (typeof(field) == 'undefined' || field == null) {
        return false;
    }

    var link = document.createElement('A');
    link.className = 'fix-' + field_name + '-link';
    link.id = 'fix_' + field_name + '_link';
    link.href = '#';
    link.title = 'Fix code';
    link.appendChild(document.createTextNode('Fix video source'));
    link.onclick = function(event) {
        // prepare oper for fix flash code action
        oper.node = document.getElementById(oper.parms.id);
        if (typeof(oper.node) == 'undefined' || oper.node == null) {
            return false;
        }

        delete oper.parms.type;
        var pp = new kukit.pr.CurrentFormVarPP();
        oper.parms.code = pp.eval([field_name], oper.node);
        oper.componentName = 'bmctv-fixFlashCode action';
        kukit.actionsGlobalRegistry.BBB_classParms(oper);
        kukit.actionsGlobalRegistry.get('bmctv-fixFlashCode')(oper);

        return false;
    };

    field.parentNode.insertBefore(link, field);

});

kukit.commandsGlobalRegistry.registerFromAction('bmctv-addFixLink', kukit.cr.makeSelectorCommand);

kukit.actionsGlobalRegistry.register('replaceInnerHTML-string', function(oper) {
/*
*  accepts both string and dom.
*/
;;; oper.componentName = '[replaceInnerHTML-string] action';
    oper.evaluateParameters(['html'], {'withKssSetup': true});
    oper.evalBool('withKssSetup');
    var node = oper.node;
    var insertedNodes;

    if (typeof(oper.parms.html) != 'string') {
        oper.parms.html = kukit.dom.forceToDom(oper.parms.html);
        var root = document.createElement("DIV");
        children = kukit.dom.appendChildren(oper.parms.html.childNodes, root);
        oper.parms.html = root.innerHTML;
    }

    node.innerHTML = oper.parms.html;
    insertedNodes = [];
    for (var i=0; i<node.childNodes.length; i++) {
        insertedNodes.push(node.childNodes[i]);
    }

    kukit.logDebug(insertedNodes.length + ' nodes inserted.');
    if (oper.parms.withKssSetup) {
        kukit.engine.setupEvents(insertedNodes);
    }
});
kukit.commandsGlobalRegistry.registerFromAction('replaceInnerHTML-string', kukit.cr.makeSelectorCommand);

