/upstream/templates/default_edit.tmpl
Type: /type/template
body: value: $def with (page)

$ _x = ctx.setdefault('bodyid', 'edit')

$var title: $_.edit_title(page.name)


<script type="text/javascript">
<!--
function changeTemplate() {
    var t = document.edit._type.value;
    document.location.href += '&t=' + t;
}

function moveup(e) {
    if (!e) e = window.event;
    if (e.preventDefault)
        e.preventDefault();
    
    var parents = \$(this).parents().filter("tr[@repeat]");
    var a = parents[0];
    var b = parents.prev()[0]
    swapvalues(a, b);
    return this.returnValue = false;
}

function movedown(e) {
    if (!e) e = window.event;
    if (e.preventDefault)
        e.preventDefault();
    
    var parents = \$(this).parents().filter("tr[@repeat]");
    var a = parents[0];
    var b = parents.next()[0]
    swapvalues(a, b);
    return this.returnValue = false;
}

function swapvalues(a, b) {
    var ia = \$(':input', a);
    var ib = \$(':input', b);
    
    for (var i=0; i<ia.length; i++)
        swap(ia[i], ib[i]);
}

function swap(a, b) {
    // probably this check must also be there for type radio
    if (a.nodeName.toLowerCase() == 'input' && a.type.toLowerCase() == 'checkbox') {
        var t = a.checked; 
        a.checked = b.checked; 
        b.checked = t; 
    }
    else {
        var t = a.value; 
        a.value = b.value; 
        b.value = t;         
    }
}
\$().ready(function(){
    \$("textarea").css("height","60px");
    \$("td.inputrow input[type=text]").attr("style","width:200px;");
});
//-->
</script>

$def display_multiple_row(property, value, index):
    $if index is None:
        $ attrs = 'id="row_%s" repeat="template"' % property.name
        $ prefix = '%s#[row_%s]' % (property.name, property.name)
    $else:
        $ attrs = 'repeat="%d""' % index
        $ prefix = '%s#%d' % (property.name, index)
        
    <tr $:attrs>
        $if property.expected_type.kind == "embeddable":
            $ count = len(property.expected_type.properties)
            $ klass = property.expected_type.key.split('/')[-1]
            $for p in property.expected_type.properties:
                <!-- $p.name $p.expected_type -->
                <td class="inputrow inputrow-$count $klass-$p.name">$:thinginput(value and value[p.name], name=prefix + "." + p.name, expected_type=p.expected_type)</td>
        $else:
            $ klass = page.type.key.split('/')[-1]
            <td class="inputrow $klass-$property.name">$:thinginput(value, name=prefix, expected_type=property.expected_type)</td>
        $:move_buttons(property.name)
    </tr>
$def display_header(property):
    $if property.expected_type.kind == "embeddable":
        <tr>
            $for p in property.expected_type.properties:
                <th class="inputrow" style="text-transform:capitalize;"><strong>$i18n.get(p.expected_type.key, p.name)</strong></th>
        </tr>

$def display_multiple(property, value):
    <table style="width:906px;">
        <thead>
            $:display_header(property)
        </thead>
        <tbody>
        $for i, v in enumerate(value):
            $:display_multiple_row(property, v, i)
        $:display_multiple_row(property, None, None)
        $:add_button(property)
        </tbody>
    </table>

$def display_regular(p, value):
    $:thinginput(value, p)
    
$def display(property, value):
    $if property.unique:
        $:display_regular(property, value)
    $else:
        $:display_multiple(property, value)
        
$def move_buttons(key):
    <td style="white-space: nowrap;">
        <button type="remove" template="row_$key" class="repeat plain larger red" title="Remove this">&#8856;</button>
    	<button type="move-up" template="row_$key" onclick="return moveup.apply(this, [event]);"  class="repeat plain large brown" title="Promote this">&#9650;</button>
    	<button type="move-down" template="row_$key" onclick="return movedown.apply(this, [event]);"  class="repeat plain large brown" title="Demote this">&#9660;</button>
    </td>

$def add_button(property):
    <tr>
    $if property.expected_type.kind == "embeddable":
        $for p in property.expected_type.properties:
            <td></td>
    $else:
        <td></td>
    <td style="padding:12px 0;"><button type="add" template="row_$property.name" class="repeat large">Add new</button></td>
    </tr>

$:render_template("lib/edit_head", page)

<div id="contentBody">
    <form name="edit" method="post" action="">

        <div class="formElement title">
            <div class="label">
                <label for="title">$_("Title")</label>
            </div>
            <div class="input">
                <input type="text" name="title" id="title" value="$page.title"/>
            </div>
        </div>

        $:macros.TypeChanger(page.type)

        <div class="clearfix"></div>
        
        $for p in page.type.properties:
            $ label = p.name
            $ value = page[p.name]
            $ klass = page.type.key.split("/")[-1] + "-" + p.name
            <div class="formElement">
                <div class="label" style="text-transform:capitalize;"><label>$label</label></div>
                <div class="input">
                    <table style="width:906px;">
                        <tbody>
                            <tr>
                                <td class="inputrow $klass">$:display(p, value)</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
    
    $:macros.EditButtons(comment=page.comment_)

    </form>
</div>

<script type="text/javascript">
<!--

if(!window.RepetitionElement||(document.implementation&&document.implementation.hasFeature&&!document.implementation.hasFeature("WebForms","2.0"))){var RepetitionElement={REPETITION_NONE:0,REPETITION_TEMPLATE:1,REPETITION_BLOCK:2,_initialized:false,_repetitionTemplates:[],_init_document:function(){if(RepetitionElement._initialized)
return;RepetitionElement._initialized=true;if(window.Element&&Element.prototype){Element.prototype.REPETITION_NONE=RepetitionElement.REPETITION_NONE;Element.prototype.REPETITION_TEMPLATE=RepetitionElement.REPETITION_TEMPLATE;Element.prototype.REPETITION_BLOCK=RepetitionElement.REPETITION_BLOCK;Element.prototype.repetitionType=RepetitionElement.REPETITION_NONE;Element.prototype.repetitionIndex=0;Element.prototype.repetitionTemplate=null;Element.prototype.repetitionBlocks=null;Element.prototype.repeatStart=1;Element.prototype.repeatMin=0;Element.prototype.repeatMax=Infinity;Element.prototype.addRepetitionBlock=RepetitionElement.addRepetitionBlock;Element.prototype.addRepetitionBlockByIndex=RepetitionElement.addRepetitionBlockByIndex;Element.prototype.moveRepetitionBlock=RepetitionElement.moveRepetitionBlock;Element.prototype.removeRepetitionBlock=RepetitionElement.removeRepetitionBlock;}
RepetitionElement._init_repetitionBlocks();RepetitionElement._init_repetitionTemplates();RepetitionElement._init_addButtons();RepetitionElement._init_removeButtons();RepetitionElement._init_moveUpButtons();RepetitionElement._init_moveDownButtons();RepetitionElement.__updateAddButtons();RepetitionElement.__updateMoveButtons();},_repetitionTemplate_constructor:function(){if(this._initialized)
return;this._initialized=true;this.style.display='none';this.repetitionType=RepetitionElement.REPETITION_TEMPLATE;this.repetitionIndex=0;this.repetitionTemplate=null;this.repetitionBlocks=[];var _attr;this.repeatStart=/^\d+\$/.test(_attr=this.getAttribute('repeat-start'))?parseInt(_attr):1;this.repeatMin=/^\d+\$/.test(_attr=this.getAttribute('repeat-min'))?parseInt(_attr):0;this.repeatMax=/^\d+\$/.test(_attr=this.getAttribute('repeat-max'))?parseInt(_attr):Infinity;if(!this.addRepetitionBlock)this.addRepetitionBlock=function(refNode,index){return RepetitionElement.addRepetitionBlock.apply(this,[refNode,index]);};if(!this.addRepetitionBlockByIndex)
this.addRepetitionBlockByIndex=this.addRepetitionBlock;var form=this;while(form=form.parentNode){if(form.nodeName.toLowerCase()=='form')
break;}
var _templateElements;if(form&&(_templateElements=RepetitionElement.__getElementsByTagNames.apply(this,['button','input','select','textarea','isindex'])).length){form.templateElements=_templateElements;for(var el,i=0;el=form.templateElements[i];i++)
el.disabled=true;if(form.templateElements[0].sourceIndex){form.templateElements.sort(function(a,b){return a.sourceIndex-b.sourceIndex;});}
else if(form.templateElements[0].compareDocumentPosition){form.templateElements.sort(function(a,b){return 3-(a.compareDocumentPosition(b)&6);});}}
var sibling=this;while(sibling=sibling.previousSibling){if(sibling.repetitionType==RepetitionElement.REPETITION_BLOCK&&!sibling.getAttribute('repeat-template')){sibling.repetitionTemplate=this;sibling.setAttribute('repeat-template',this.id);this.repetitionBlocks.unshift(sibling);}}
for(var i=0;i<Math.max(this.repeatStart,this.repeatMin);i++)
this.addRepetitionBlock();RepetitionElement._repetitionTemplates.push(this);this._initialized=true;},_init_repetitionTemplates:function(parentNode){var repetitionTemplates=RepetitionElement.__getElementsByNameAndAttribute.apply((parentNode||document.body),['*','repeat','template']);for(var i=0,rt;i<repetitionTemplates.length;i++)
RepetitionElement._repetitionTemplate_constructor.apply(repetitionTemplates[i]);},_repetitionBlock_constructor:function(){if(this._initialized)
return;this.style.display='';this.repetitionType=RepetitionElement.REPETITION_BLOCK;var _attr;this.repetitionIndex=/^\d+\$/.test(_attr=this.getAttribute('repeat'))?parseInt(_attr):0;this.repetitionBlocks=null;this.repetitionTemplate=null;var node;if((node=document.getElementById(this.getAttribute('repeat-template')))&&node.repetitionType==RepetitionElement.REPETITION_TEMPLATE)
{this.repetitionTemplate=node;}
else{node=this;while(node=node.nextSibling){if(node.repetitionType==RepetitionElement.REPETITION_TEMPLATE){this.repetitionTemplate=node;break;}}}
if(!this.removeRepetitionBlock)this.removeRepetitionBlock=function(){return RepetitionElement.removeRepetitionBlock.apply(this);};if(!this.moveRepetitionBlock)this.moveRepetitionBlock=function(distance){return RepetitionElement.moveRepetitionBlock.apply(this,[distance]);};this._initialized=true;},_init_repetitionBlocks:function(parentNode){var repetitionBlocks=RepetitionElement.__getElementsByNameAndAttribute.apply((parentNode||document.body),['*','repeat','template',true]);for(var i=0;i<repetitionBlocks.length;i++)
RepetitionElement._repetitionBlock_constructor.apply(repetitionBlocks[i]);},_addButton_constructor:function(){if(this._initialized)
return;this.htmlTemplate=RepetitionElement.__getHtmlTemplate(this);var rb;this.disabled=!(((rb=RepetitionElement.__getRepetitionBlock(this))&&rb.repetitionTemplate)||this.htmlTemplate);if(this.addEventListener)
this.addEventListener('click',RepetitionElement._addButton_click,false);else if(this.attachEvent)
this.attachEvent('onclick',RepetitionElement._addButton_click);else this.onclick=RepetitionElement._addButton_click;this._initialized=true;},_init_addButtons:function(parentNode){var addButtons=RepetitionElement.__getElementsByNameAndAttribute.apply((parentNode||document.body),['button','type','add']);for(var i=0;i<addButtons.length;i++)
RepetitionElement._addButton_constructor.apply(addButtons[i]);},_addButton_click:function(e){if(e&&e.preventDefault)
e.preventDefault();var btn;if(e&&e.target)
btn=e.target;else if(window.event)
btn=window.event.srcElement;else if(String(this.nodeName).toLowerCase()=='button')
btn=this;if(!btn.returnValue&&typeof(btn.returnValue)!='undefined'){btn.returnValue=undefined;return false;}
if((btn.onclick||btn._onclick)&&btn.hasAttribute&&!btn.hasAttribute("onclick")){if(btn.onclick)
btn._onclick=btn.onclick;btn.returnValue=btn._onclick(e);btn.onclick=null;if(!btn.returnValue&&typeof(btn.returnValue)!='undefined'){btn.returnValue=undefined;return false;}}
var rt;if(btn.htmlTemplate)
rt=btn.htmlTemplate;else{var block=RepetitionElement.__getRepetitionBlock(btn);if(block&&block.repetitionTemplate)
rt=block.repetitionTemplate;}
if(rt)
rt.addRepetitionBlock();else
btn.disabled=true;return true;},_removeButton_constructor:function(){if(this._initialized)
return;this.htmlTemplate=RepetitionElement.__getHtmlTemplate(this);if(this.addEventListener)
this.addEventListener('click',RepetitionElement._removeButton_click,false);else if(this.attachEvent)
this.attachEvent('onclick',RepetitionElement._removeButton_click);else this.onclick=RepetitionElement._removeButton_click;this._initialized=true;},_init_removeButtons:function(parentNode){var removeButtons=RepetitionElement.__getElementsByNameAndAttribute.apply((parentNode||document.body),['button','type','remove']);for(var i=0;i<removeButtons.length;i++)
RepetitionElement._removeButton_constructor.apply(removeButtons[i]);},_removeButton_click:function(e){if(e&&e.preventDefault)
e.preventDefault();this.disabled=!RepetitionElement.__getRepetitionBlock(this);var btn;if(e&&e.target)
btn=e.target;else if(window.event)
btn=window.event.srcElement;else if(String(this.nodeName).toLowerCase()=='button')
btn=this;if(!btn.returnValue&&typeof(btn.returnValue)!='undefined'){btn.returnValue=undefined;return false;}
if((btn.onclick||btn._onclick)&&btn.hasAttribute&&!btn.hasAttribute("onclick")){if(btn.onclick)
btn._onclick=btn.onclick;btn.returnValue=btn._onclick(e);btn.onclick=null;if(!btn.returnValue&&typeof(btn.returnValue)!='undefined'){btn.returnValue=undefined;return false;}}
var block=RepetitionElement.__getRepetitionBlock(btn);if(block)
block.removeRepetitionBlock();return false;},_moveUpButton_constructor:function(){if(this._initialized)
return;this.htmlTemplate=RepetitionElement.__getHtmlTemplate(this);this.disabled=!RepetitionElement.__getRepetitionBlock(this);if(this.addEventListener)
this.addEventListener('click',RepetitionElement._moveUpButton_click,false);else if(this.attachEvent)
this.attachEvent('onclick',RepetitionElement._moveUpButton_click);else this.onclick=RepetitionElement._moveUpButton_click;this._initialized=true;},_init_moveUpButtons:function(parentNode){var moveUpButtons=RepetitionElement.__getElementsByNameAndAttribute.apply((parentNode||document.body),['button','type','move-up']);for(var i=0;i<moveUpButtons.length;i++)
RepetitionElement._moveUpButton_constructor.apply(moveUpButtons[i]);},_moveUpButton_click:function(e){if(e&&e.preventDefault)
e.preventDefault();var btn;if(e&&e.target)
btn=e.target;else if(window.event)
btn=window.event.srcElement;else if(String(this.nodeName).toLowerCase()=='button')
btn=this;if(!btn.returnValue&&typeof(btn.returnValue)!='undefined'){btn.returnValue=undefined;return false;}
if((btn.onclick||btn._onclick)&&btn.hasAttribute&&!btn.hasAttribute("onclick")){if(btn.onclick)
btn._onclick=btn.onclick;btn.returnValue=btn._onclick(e);btn.onclick=null;if(!btn.returnValue&&typeof(btn.returnValue)!='undefined'){btn.returnValue=undefined;return false;}}
var block=RepetitionElement.__getRepetitionBlock(btn);if(block){block._clickedMoveBtn=btn;block.moveRepetitionBlock(-1);}
return false;},_moveDownButton_constructor:function(){if(this._initialized)
return;this.htmlTemplate=RepetitionElement.__getHtmlTemplate(this);this.disabled=!RepetitionElement.__getRepetitionBlock(this);if(this.addEventListener)
this.addEventListener('click',RepetitionElement._moveDownButton_click,false);else if(this.attachEvent)
this.attachEvent('onclick',RepetitionElement._moveDownButton_click);else this.onclick=RepetitionElement._moveDownButton_click;this._initialized=true;},_init_moveDownButtons:function(parentNode){var moveDownButtons=RepetitionElement.__getElementsByNameAndAttribute.apply((parentNode||document.body),['button','type','move-down']);for(var i=0;i<moveDownButtons.length;i++)
RepetitionElement._moveDownButton_constructor.apply(moveDownButtons[i]);},_moveDownButton_click:function(e){if(e&&e.preventDefault)
e.preventDefault();var btn;if(e&&e.target)
btn=e.target;else if(window.event)
btn=window.event.srcElement;else if(String(this.nodeName).toLowerCase()=='button')
btn=this;if(!btn.returnValue&&typeof(btn.returnValue)!='undefined'){btn.returnValue=undefined;return false;}
if((btn.onclick||btn._onclick)&&btn.hasAttribute&&!btn.hasAttribute("onclick")){if(btn.onclick)
btn._onclick=btn.onclick;btn.returnValue=btn._onclick(e);btn.onclick=null;if(!btn.returnValue&&typeof(btn.returnValue)!='undefined'){btn.returnValue=undefined;return false;}}
var block=RepetitionElement.__getRepetitionBlock(btn);if(block){block._clickedMoveBtn=btn;block.moveRepetitionBlock(1);}
return false;},addRepetitionBlock:function(refNode,index){if(refNode&&!refNode.nodeType)
throw Error("Exception: WRONG_ARGUMENTS_ERR");if(this.repetitionType!=RepetitionElement.REPETITION_TEMPLATE)
throw Error("DOMException: NOT_SUPPORTED_ERR");if(this.parentNode==null)
return;var node=this;while(node=node.parentNode){if(node.repetitionType==RepetitionElement.REPETITION_TEMPLATE)
return false;}
var sibling=this.previousSibling;var currentBlockCount=0;while(sibling!=null){if(sibling.repetitionType==RepetitionElement.REPETITION_BLOCK&&sibling.repetitionTemplate==this)
{this.repetitionIndex=Math.max(this.repetitionIndex,sibling.repetitionIndex+1);currentBlockCount++;}
sibling=sibling.previousSibling;}
if(this.repeatMax<=currentBlockCount)
return null;if(typeof index!='undefined'&&index>this.repetitionIndex)
this.repetitionIndex=index;var IDAttrName=this.getAttribute('id')?'id':this.getAttribute('name')?'name':'';var IDAttrValue=this.getAttribute(IDAttrName);var ignoreName=/\u005B|\u02D1|\u005D|\u00B7/.test(IDAttrValue);var boolProcessAttr=IDAttrValue&&!ignoreName;var block;var replaceValue=this.repetitionIndex;var reTemplateName=new RegExp("(\\[|\u02D1)"+IDAttrValue+"(\\]|\u00B7)",'g');function _processAttr(attrVal){if(!attrVal)
return attrVal;attrVal=attrVal.toString();if(attrVal.indexOf("\uFEFF")===0)
return attrVal.replace(/^\uFEFF/,'');return attrVal.replace(reTemplateName,replaceValue);}
var _customAttrs={'type':1,'template':1,'repeat':1,'repeat-template':1,'repeat-min':1,'repeat-max':1,'repeat-start':1,'value':1,'class':1,'required':1,'pattern':1,'form':1,'autocomplete':1,'autofocus':1,'inputmode':1};var _skippedAttrs={'name':1,'class':1,'for':1,'style':1,onadd:1,onremove:1,onmove:1,onmoved:1,onadded:1,onremoved:1,addRepetitionBlock:1,addRepetitionBlockByIndex:1,moveRepetitionBlock:1,removeRepetitionBlock:1,repetitionBlocks:1,_initialized:1};function _cloneNode(node){var clone,i,attr,el;if(node.nodeType==1){clone=node.name?RepetitionElement.__createElementWithName(node.nodeName,(boolProcessAttr?_processAttr(node.name):node.name)):document.createElement(node.nodeName);for(i=0;attr=node.attributes[i];i++){if((attr.specified||_customAttrs[attr.name])&&!_skippedAttrs[attr.name]){if((attr.name.indexOf("on")===0)&&(typeof node[attr.name]=='function')){var funcBody=_processAttr(node[attr.name].toString().match(/{((?:.|\n)+)}/)[1]);funcBody=_processAttr(funcBody);clone[attr.name]=new Function('event',funcBody);}
else{var attrValue=node.getAttribute(attr.name);attrValue=(boolProcessAttr?_processAttr(attrValue):attrValue);clone.setAttribute(attr.name,attrValue);}}}
if(node.className){var _className=(boolProcessAttr?_processAttr(node.className):node.className);if(clone.getAttributeNode('class')){for(i=0;i<clone.attributes.length;i++){if(clone.attributes[i].name=='class')
clone.attributes[i].value=_className;}}
else clone.setAttribute('class',_className);}
if(!/\bdisabled\b/.test(node.className))
clone.disabled=false;if(node.style){clone.style.cssText=_processAttr(node.style.cssText);}
if(node.nodeName.toLowerCase()=='label'&&node.htmlFor)
clone.htmlFor=(boolProcessAttr?_processAttr(node.htmlFor):node.htmlFor);for(i=0;el=node.childNodes[i];i++)
clone.appendChild(_cloneNode(el));}
else clone=node.cloneNode(true);return clone;}
block=_cloneNode(this);block._initialized=false;block.setAttribute('repeat',this.repetitionIndex);block.removeAttribute('repeat-min');block.removeAttribute('repeat-max');block.removeAttribute('repeat-start');if(IDAttrName){block.setAttribute('repeat-template',IDAttrValue);block.removeAttribute(IDAttrName);}
if(!refNode){var refNode=this;while(refNode.previousSibling&&refNode.previousSibling.repetitionType!=RepetitionElement.REPETITION_BLOCK)
refNode=refNode.previousSibling;this.parentNode.insertBefore(block,refNode);this.repetitionBlocks.push(block);}
else{refNode.parentNode.insertBefore(block,refNode.nextSibling);this.repetitionBlocks.push(block);if(this.repetitionBlocks[0].sourceIndex){this.repetitionBlocks.sort(function(a,b){return a.sourceIndex-b.sourceIndex;});}
else if(this.repetitionBlocks[0].compareDocumentPosition){this.repetitionBlocks.sort(function(a,b){return 3-(a.compareDocumentPosition(b)&6);});}}
this.repetitionIndex++;RepetitionElement._repetitionBlock_constructor.apply(block);RepetitionElement._init_repetitionTemplates(block);RepetitionElement._init_addButtons(block);RepetitionElement._init_removeButtons(block);RepetitionElement._init_moveUpButtons(block);RepetitionElement._init_moveDownButtons(block);if(RepetitionElement._initialized){RepetitionElement.__updateAddButtons(this);RepetitionElement.__updateMoveButtons(this.parentNode);}
var addEvt;try{if(document.createEvent)
addEvt=document.createEvent("UIEvents");else if(document.createEventObject)
addEvt=document.createEventObject();RepetitionEvent._upgradeEvent.apply(addEvt);addEvt.initRepetitionEvent("added",true,false,block);if(this.dispatchEvent)
this.dispatchEvent(addEvt);else if(this.fireEvent){}}
catch(err){addEvt=new Object();RepetitionEvent._upgradeEvent.apply(addEvt);addEvt.initRepetitionEvent("added",true,false,block);}
var onaddAttr=this.getAttribute('onadd')||this.getAttribute('onadded');if(onaddAttr&&(!this.onadd||typeof this.onadd!='function'))
this.onadd=new Function('event',onaddAttr);if(this.onadd)
this.onadd(addEvt);else if(this.onadded)
this.onadded(addEvt);return block;},addRepetitionBlockByIndex:function(refNode,index){RepetitionElement.addRepetitionBlock.apply(this,[refNode,index])},removeRepetitionBlock:function(){if(this.repetitionType!=RepetitionElement.REPETITION_BLOCK)
throw Error("DOMException: NOT_SUPPORTED_ERR");var parentNode=this.parentNode;var block=parentNode.removeChild(this);RepetitionElement.__updateMoveButtons(parentNode);if(this.repetitionTemplate!=null){for(var i=0;i<this.repetitionTemplate.repetitionBlocks.length;i++){if(this.repetitionTemplate.repetitionBlocks[i]==this){this.repetitionTemplate.repetitionBlocks.splice(i,1);break;}}}
if(this.repetitionTemplate!=null){var removeEvt;try{if(document.createEvent)
removeEvt=document.createEvent("UIEvents");else if(document.createEventObject)
removeEvt=document.createEventObject();RepetitionEvent._upgradeEvent.apply(removeEvt);removeEvt.initRepetitionEvent("removed",true,false,this);if(this.repetitionTemplate.dispatchEvent)
this.repetitionTemplate.dispatchEvent(removeEvt);else if(this.repetitionTemplate.fireEvent){}}
catch(err){removeEvt=new Object();RepetitionEvent._upgradeEvent.apply(removeEvt);removeEvt.initRepetitionEvent("removed",true,false,this);}
var onremoveAttr=this.repetitionTemplate.getAttribute('onremove')||this.repetitionTemplate.getAttribute('onremoved');if(onremoveAttr&&(!this.repetitionTemplate.onremove||typeof this.repetitionTemplate.onremove!='function'))
this.repetitionTemplate.onremove=new Function('event',onremoveAttr);if(this.repetitionTemplate.onremove)
this.repetitionTemplate.onremove(removeEvt);else if(this.repetitionTemplate.onremoved)
this.repetitionTemplate.onremoved(removeEvt);}
if(this.repetitionTemplate!=null){if(this.repetitionTemplate.repetitionBlocks.length<this.repetitionTemplate.repeatMin&&this.repetitionTemplate.repetitionBlocks.length<this.repetitionTemplate.repeatMax)
{this.repetitionTemplate.addRepetitionBlock();}
if(this.repetitionTemplate.repetitionBlocks.length<this.repetitionTemplate.repeatMax){var addBtns=RepetitionElement.__getElementsByNameAndAttribute.apply(document.body,['button','type','add']);for(i=0;i<addBtns.length;i++){if(addBtns[i].htmlTemplate==this.repetitionTemplate)
addBtns[i].disabled=false;}}}},moveRepetitionBlock:function(distance){if(this.repetitionType!=RepetitionElement.REPETITION_BLOCK)
throw Error("DOMException: NOT_SUPPORTED_ERR");if(distance==0||this.parentNode==null)
return;var target=this;if(this.repetitionTemplate){var pos=0;var rp=this.repetitionTemplate.repetitionBlocks;while(pos<rp.length&&rp[pos]!=this)
pos++;rp.splice(pos,1);rp.splice(distance<0?Math.max(pos+distance,0):Math.min(pos+distance,rp.length),0,this);}
if(distance<0){while(distance!=0&&target.previousSibling&&target.previousSibling.repetitionType!=RepetitionElement.REPETITION_TEMPLATE)
{target=target.previousSibling;if(target.repetitionType==RepetitionElement.REPETITION_BLOCK)
distance++;}}
else{while(distance!=0&&target.nextSibling&&target.nextSibling.repetitionType!=RepetitionElement.REPETITION_TEMPLATE){target=target.nextSibling;if(target.repetitionType==RepetitionElement.REPETITION_BLOCK)
distance--;}
target=target.nextSibling;}
this.parentNode.insertBefore(this,target);if(this._clickedMoveBtn){this._clickedMoveBtn.focus();this._clickedMoveBtn=null;}
if(this.repetitionTemplate!=null){var moveEvt;try{if(document.createEvent)
moveEvt=document.createEvent("UIEvents");else if(document.createEventObject)
moveEvt=document.createEventObject();RepetitionEvent._upgradeEvent.apply(moveEvt);moveEvt.initRepetitionEvent("moved",true,false,this);if(this.repetitionTemplate.dispatchEvent)
this.repetitionTemplate.dispatchEvent(moveEvt);else if(this.repetitionTemplate.fireEvent){}}
catch(err){moveEvt=new Object();RepetitionEvent._upgradeEvent.apply(moveEvt);moveEvt.initRepetitionEvent("moved",true,false,this);}
var onmoveAttr=this.repetitionTemplate.getAttribute('onmove')||this.repetitionTemplate.getAttribute('onmoved');var funcMatches;if(typeof onmoveAttr=='function'&&(funcMatches=onmoveAttr.toString().match(/^\s*function\s+anonymous\(\s*\)\s*\{((?:.|\n)+)\}\s*\$/))){this.repetitionTemplate.onmove=new Function('event',funcMatches[1]);}
if(onmoveAttr&&!this.repetitionTemplate.onmove)
this.repetitionTemplate.onmove=new Function('event',onmoveAttr);if(this.repetitionTemplate.onmove)
this.repetitionTemplate.onmove(moveEvt);else if(this.repetitionTemplate.onmoved)
this.repetitionTemplate.onmoved(moveEvt);}
RepetitionElement.__updateMoveButtons(this.parentNode);},__getRepetitionBlock:function(node){while(node=node.parentNode){if(node.repetitionType==RepetitionElement.REPETITION_BLOCK){return node;}}
return null;},__getHtmlTemplate:function(button){var attr=button.getAttribute('template');var node;if(attr&&(node=document.getElementById(attr))&&node.repetitionType==RepetitionElement.REPETITION_TEMPLATE)
return node;return null;},__updateAddButtons:function(rt){var repetitionTemplates=rt?[rt]:RepetitionElement._repetitionTemplates;var btns=RepetitionElement.__getElementsByNameAndAttribute.apply(document.body,['button','type','add']);for(var i=0;i<btns.length;i++){for(var t,j=0;t=repetitionTemplates[j];j++){if(btns[i].htmlTemplate==t&&t.repetitionBlocks.length>=t.repeatMax){btns[i].disabled=true;}}}},__updateMoveButtons:function(parentNode){var i;var repetitionBlocks=[];if(!parentNode){var visitedParents=[];var repetitionBlocks=RepetitionElement.__getElementsByProperty('repetitionType',RepetitionElement.REPETITION_BLOCK);for(i=0;block=repetitionBlocks[i];i++){if(!visitedParents.some(function(i){return i==block.parentNode})){RepetitionElement.__updateMoveButtons(block.parentNode);visitedParents.push(block.parentNode);}}
return;}
var j,btn,block;var child=parentNode.firstChild;while(child){if(child.repetitionType==RepetitionElement.REPETITION_BLOCK)
repetitionBlocks.push(child);child=child.nextSibling;}
for(i=0;block=repetitionBlocks[i];i++){var moveUpBtns=RepetitionElement.__getElementsByNameAndAttribute.apply(block,['button','type','move-up']);for(j=0;btn=moveUpBtns[j];j++){btn.disabled=!(rb=RepetitionElement.__getRepetitionBlock(btn))||(i==0);}
var moveDownBtns=RepetitionElement.__getElementsByNameAndAttribute.apply(block,['button','type','move-down']);for(j=0;btn=moveDownBtns[j];j++){btn.disabled=!(rb=RepetitionElement.__getRepetitionBlock(btn))||(i==repetitionBlocks.length-1);}}},__getElementsByProperty:function(propName,propValue){var els=[];var all=document.body.getElementsByTagName('*');for(i=0;i<all.length;i++){if(all[i][propName]==propValue)
els.push(all[i]);}
return els;},__getElementsByTagNames:function(){var results=[];for(var i=0;i<arguments.length;i++){var elements=this.getElementsByTagName(arguments[i]);for(var j=0;j<elements.length;j++){results.push(elements[j]);}}
return results;},__getElementsByNameAndAttribute:function(elName,attrName,attrValue,isNotEqual){var results=[];var all=this.getElementsByTagName(elName);for(var i=0;i<all.length;i++){var thisAttrNode=all[i].getAttributeNode(attrName);var thisAttrValue=all[i].getAttribute(attrName);if(thisAttrNode&&(typeof attrValue=='undefined'||(isNotEqual?thisAttrValue!=attrValue:thisAttrValue==attrValue))){results.push(all[i]);}}
return results;},__createElementWithName:function(type,name){throw Error("__createElementWithName not yet created. Browser-specific code defined immediately below.");}};(function(){try{var el=document.createElement('<div name="foo">');if(el.tagName.toLowerCase()=='div'||el.name!='foo'){throw'create element error';}
RepetitionElement.__createElementWithName=function(tag,name){return document.createElement('<'+tag+' name="'+name+'"></'+tag+'>');};}
catch(err){RepetitionElement.__createElementWithName=function(tag,name){var el=document.createElement(tag);el.setAttribute('name',name);return el;};}})();var RepetitionEvent={};RepetitionEvent._upgradeEvent=function(){this.initRepetitionEvent=RepetitionEvent.initRepetitionEvent;this.initRepetitionEventNS=RepetitionEvent.initRepetitionEventNS;};RepetitionEvent.initRepetitionEvent=function(typeArg,canBubbleArg,cancelableArg,elementArg){if(this.initEvent)
this.initEvent(typeArg,canBubbleArg,cancelableArg);else{this.type=typeArg;if(!this.preventDefault)
this.preventDefault=function(){this.returnValue=false;};if(!this.stopPropagation)
this.stopPropagation=function(){this.cancelBubble=true;};}
this.element=elementArg;this.relatedNode=elementArg;};RepetitionEvent.initRepetitionEventNS=function(namespaceURIArg,typeArg,canBubbleArg,cancelableArg,elementArg){throw Error("NOT IMPLEMENTED: RepetitionEvent.initRepetitionEventNS");};if(document.addEventListener){document.addEventListener("DOMContentLoaded",function(){RepetitionElement._init_document();},false);window.addEventListener("load",function(){RepetitionElement._init_document();},false);}
else if(window.onload){var oldonload=window.onload;window.onload=function(){RepetitionElement._init_document();oldonload();};}
else window.onload=function(){RepetitionElement._init_document();};if(/WebKit/i.test(navigator.userAgent)){var _timer=setInterval(function(){if(/loaded|complete/.test(document.readyState)){clearInterval(_timer);delete _timer;RepetitionElement._init_document();}},10);}
else if(/MSIE/i.test(navigator.userAgent)&&!document.addEventListener&&window.attachEvent){window.attachEvent("onload",function(){RepetitionElement._init_document();});var match,dirname='';var scripts=document.getElementsByTagName('head')[0].getElementsByTagName('script');for(var i=0;i<scripts.length;i++){if(match=scripts[i].src.match(/^(.*)repetition-model[^\/]+\$/))
dirname=match[1];}
document.write("<script defer src='"+dirname+"repetition-model-msie_init.js'><"+"/script>");document.write("<script id=__ie_onload defer src='//:'><\/script>");var script=document.getElementById("__ie_onload");script.onreadystatechange=function(){if(this.readyState=="complete"){RepetitionElement._init_document();this.parentNode.removeChild(this);if(RepetitionElement._repetitionTemplates.length==0)
RepetitionElement._initialized=false;}};script=null;}}
else if(document.addEventListener&&(typeof(RepetitionElement.oldEventModelEnabled)=='undefined'||RepetitionElement.oldEventModelEnabled)){RepetitionElement.oldEventModelEnabled=true;document.addEventListener("added",function(evt){if(!RepetitionElement.oldEventModelEnabled)
return;if(!evt.element&&evt.relatedNode)
evt.element=evt.relatedNode;if(!evt.element||!evt.element.repetitionTemplate)
return;var rt=evt.element.repetitionTemplate;var onaddAttr=rt.getAttribute('onadd')||rt.getAttribute('onadded');if(onaddAttr&&(!rt.onadd||typeof rt.onadd!='function'))
rt.onadd=new Function('event',onaddAttr);if(evt.element.repetitionTemplate.onadd)
evt.element.repetitionTemplate.onadd(evt);else if(evt.element.repetitionTemplate.onadded)
evt.element.repetitionTemplate.onadded(evt);},false);document.addEventListener("removed",function(evt){if(!RepetitionElement.oldEventModelEnabled)
return;if(!evt.element&&evt.relatedNode)
evt.element=evt.relatedNode;if(!evt.element||!evt.element.repetitionTemplate)
return;var rt=evt.element.repetitionTemplate;var onremoveAttr=rt.getAttribute('onremove')||rt.getAttribute('onremoved');if(onremoveAttr&&(!rt.onremove||typeof rt.onremove!='function'))
rt.onremove=new Function('event',onremoveAttr);if(evt.element.repetitionTemplate.onremove)
evt.element.repetitionTemplate.onremove(evt);else if(evt.element.repetitionTemplate.onremoved)
evt.element.repetitionTemplate.onremoved(evt);},false);document.addEventListener("moved",function(evt){if(!RepetitionElement.oldEventModelEnabled)
return;if(!evt.element&&evt.relatedNode)
evt.element=evt.relatedNode;if(!evt.element||!evt.element.repetitionTemplate)
return;var rt=evt.element.repetitionTemplate;var onmoveAttr=rt.getAttribute('onmove')||rt.getAttribute('onmoved');if(onmoveAttr&&(!rt.onmove||typeof rt.onmove!='function'))
rt.onmove=new Function('event',onmoveAttr);if(evt.element.repetitionTemplate.onmove)
evt.element.repetitionTemplate.onmove(evt);else if(evt.element.repetitionTemplate.onmoved)
evt.element.repetitionTemplate.onmoved(evt);},false);}
if(!Array.prototype.some)
{Array.prototype.some=function(fn,thisObj){var scope=thisObj||window;for(var i=0,j=this.length;i<j;++i){if(fn.call(scope,this[i],i,this)){return true;}}
return false;};}
//-->
</script>
plugin: upstream