// $Id: lookupSupportTemplates.js,v 1.24 2009/03/06 15:31:46 dnicks Exp $

// return a string containing the template specified by template key with the
// provided parameters filled in
function renderLookupToolTemplate(templatekey, parameters) {
  var result = oLookupTemplates[templatekey];
  if (parameters) {
    for (var n = 0; n < parameters.length; n++) {
      result = result.replace(new RegExp("\\$" + n, "g"), parameters[n]);
    }
  }
  return result;
}

// this object contains all the lookup tool templates
var oLookupTemplates = new Object();
oLookupTemplates.render = renderLookupToolTemplate;

// here are the templates

// this template starts the element that contains an entire row of controls for a lookup tool (criteria)
oLookupTemplates.lookupRow = "<div class='lookupRow' id='$0_$1'>";

// this template is the logic selector used on rows of criteria other than the first
oLookupTemplates.logicSelectorOr = "<div style='display: inline;'><select id='$0_lookupLogic_$1' size='1' style='width:45px;'><option value='and' selected='true'>and</option><option value='or'>or</option><option value='not'>not</option></select></div>";
oLookupTemplates.logicSelectorAnd = "<div style='display: inline;'><select id='$0_lookupLogic_$1' size='1' style='width:45px;'><option value='or'>or</option><option value='and' selected='true'>and</option><option value='not'>not</option></select></div>";
oLookupTemplates.logicSelectorNot = "<div style='display: inline;'><select id='$0_lookupLogic_$1' size='1' style='width:45px;'><option value='or'>or</option><option value='and'>and</option><option value='not' selected='true'>not</option></select></div>";

// this template starts the element containing a single control in a row of controls in the lookup tool
oLookupTemplates.lookupControlElementStart = "<div class='$2' id='$0_$1'>";

// this template is the same as the previous but is used when the control starts out hidden
oLookupTemplates.lookupControlElementStartHidden = "<div class='$2' id='$0_$1' style='display: none;'>";

// this template is the match type selector (e.g. contains, starts with, etc...)
oLookupTemplates.matchTypeSelectorRow =  "<select name='$0MatchType' id='$1_MatchType_CONtrol_$2' size='1' class='lookupControl_box_three' onchange='matchTypeSelectorChanged(this, \"$1\", $2)'><option value='c' $3 >Contains</option><option value='s' $4 >Starts With</option><option value='a' $5 >All</option></select>";
oLookupTemplates.altMatchTypeSelectorRow =  "<select name='$0MatchType' id='$1_MatchType_CONtrol_$2' size='1' class='lookupControl_box_three' onchange='matchTypeSelectorChanged(this, \"$1\", $2)'><option value='c' $3 >Contains</option><option value='a' $5 >All</option></select>";

// this template is the start of the select tag for a control in a lookup tool
oLookupTemplates.lookupSelectControl = "<select name='$0' style='$4' class='$5' id='$1_CONtrol_$2' size='1' onchange='$3lookupSelectChanged(\"$1\", $2)'>";

// this template is used for a single option in a select control on a lookup tool
oLookupTemplates.lookupSelectOption = "<option value='$0' $2 >$1</option>";

// this template ends a select control in a lookup tool
oLookupTemplates.lookupSelectControlEnd = "</select>";

// this template is an text input control in a lookup tool
oLookupTemplates.lookupTextControl = "<input type='text' name='$0' style='$5' class='$7' id='$1_CONtrol_$2' $3 $4 $6 onKeyPress='checkForKeySubmit(event)' onblur='saveTextValue(this)'/>";

// this template ends the element around a single control in the lookup tool
oLookupTemplates.lookupControlElementEnd = "</div>";

// this template is the add/remove buttons for a row of criteria on a lookup tool (not first row, see below for first row)
oLookupTemplates.addRemoveCriteriaRow = "<div class='lookup_addDeleteRow'><input class='input_btn' type='image' border='0' alt='Add' src='images/btn_plus.gif' onclick='addCriteria(\"$0\")'/><input class='input_btn' type='image' border='0' alt='Minus' src='images/btn_minus.gif' onclick='removeCriteria(\"$0\", $1)' /></div>";

// this template is the add/remove buttons for a row of criteria on a lookup tool (first row special version)
oLookupTemplates.addRemoveCriteriaRowFirst = "<div class='lookup_addDeleteRow'><input class='input_btn' type='image' border='0' alt='Add' src='images/btn_plus.gif' onclick='addCriteria(\"$0\")'/><img class='input_btn' style='margin-left:3px; font-size:.75em;' border='0' alt='Minus' src='images/btn_minus_off.gif' /></div>";

// this template closes the element that contains an entire row of controls for a lookup tool (row of criteria controls)
oLookupTemplates.lookupRowEnd = "</div>";

// this template is inside the outer *_ROWS element/table and contains the first row of criteria controls
oLookupTemplates.emptyRowContainer = "<div style='display: none;' id='$0_Container_$1'></div>";

// this template is used to render an empty element as needed (e.g. first row, logic selector)
oLookupTemplates.emptyElement = "<div id='$0_emptyelement_$1' style='display: none; width: 48px;'><img src='../images/spacer.gif' width='48' height='1'/></div>";

// these templates are used for the HTML for the submit controls span (multi election cycles)
oLookupTemplates.submitSpanStart = "<div class='lookupSubmitControlsMultiEC'><a href='javascript:popupMultiECIDSelector()'>Edit</a> ";
oLookupTemplates.submitSpanEnd = "</div>";

