  var browser     = '';
  var version     = '';
  // BROWSER?
  if (browser == '')
  {
    if (navigator.appName.indexOf('Microsoft') != -1)
      browser = 'IE'
  }
  if (version == '')
  {
    version= navigator.appVersion;
    paren = version.indexOf('(');
    whole_version = navigator.appVersion.substring(0,paren-1);
    version         = parseInt(whole_version);
  }
  
  function validate_form()
  {
    // Validate number of component
    if(component_count == 0)
    {
        alert("Please add at least 1 component to the form");
        return false;
    }
    // Validate form name
    if($("form_name").value == "")
    {
        alert("Form name can not be empty");
        $("form_name").focus();
        return false;
    }
    //Validate number of Contributor
    var contributor_count = 0;
    for(var i = 0; i < c_no; i++)
    {
        if($("component_" + i) && $("component_" + i).value == "contributor")
        {
            contributor_count += 1;
        }
        
        if($("ref_code_" + i) && $("ref_code_" + i).value == "")
        {
            alert("Reference code must not be empty");
            $("ref_code_" + i).focus();
            return false;
        }
    }
    if(contributor_count > 1)
    {
        alert("Form must have only 1 Contributor component");
        return false;
    }
    
    //Validate reference rule
    var no_rule = true;
    for(var i = 0; i <= rule_count; i++)
    {
      if($("rule_" + i) && $("rule_" + i).value != "")
      {
        no_rule = false;
      }
    }
    if(no_rule)
    {
      alert("Form must have at least 1 reference rule");
      return false;
    }
    
    return true;
  }
  
  function create_html_component()
  {
    var html = "";
    html += ("<div id='component_header_"+ c_no +"' style='display:none'>");
    html += ("<table width='100%'>");
    html += ("<tr>");
    html += ("<td width='1px' nowrap='nowrap'>");
    html += ("<strong><span id='display_label_"+ c_no +"'></span></strong>");
    html += (" [<span id='display_ref_code_"+ c_no +"' class='redText'></span>");
    html += (" - <em><span id='display_type_"+ c_no +"' class='blueText'></span></em>]");
    html += ("</td>");
    html += ("<td align='right' width='70px'><a href='#' onclick='$(\"component_body_" + c_no + "\").show();$(\"component_header_" + c_no + "\").hide(); return false;' class='collapsedLink'>Expand<\/a></td>");
    html += ("</tr></table></div><div id='component_body_"+ c_no +"'>");
    html += ("<table width='100%'><tr><td>");
    html += ("<a href='#' onclick='add_component("+ c_no +"); return false;' class='addLink'>Add another component<\/a>&nbsp;&nbsp;");
    html += ("<a href='#' onclick='clone_component("+ c_no +"); return false;' class='addLink'>Clone this component<\/a>&nbsp;&nbsp;");
    html += ("<a href='#' onclick='remove_component("+ c_no +"); return false;' class='removeLink'>Remove this component<\/a>");
    html += ("</td><td align='right'>");
    html += ("<a href='#' onclick='$(\"component_body_" + c_no + "\").hide();$(\"component_header_" + c_no + "\").show(); return false;' class='expandedLink'>Collapse<\/a>");
    html += ("</td></tr></table>");
    html += "<table>"
    html += ("<tr><td>Type:<\/td><td><select id='component_" + c_no + "' name='component_" + c_no + "' onchange='check_component_type(" + c_no +"); $(\"display_type_" + c_no +"\").innerHTML = getDropDownListDisplayText(this);'>");
    html += (myOption + "<\/select><\/td><\/tr>");
    html += ("<tr><td>Label:<\/td><td><input type='text' id='label_" + c_no + "' name='label_" + c_no + "' onchange='$(\"display_label_" + c_no +"\").innerHTML = this.value;'/><\/td><\/tr>");
    html += ("<tr><td>Select options:<\/td><td><input type='text' size='90' id='options_" + c_no + "' name='options_" + c_no + "' disabled='true' /><br/>(&lt;display|value&gt; pairs are seperated by ~)<\/td><\/tr>");
    html += ("<tr><td>Reference code:<\/td><td><input type='text' id='ref_code_" + c_no + "' class='ref_code' name='ref_code_" + c_no + "' onchange='$(\"display_ref_code_" + c_no +"\").innerHTML = this.value;'/><\/td><\/tr>");
    html += ("<tr><td>Length:<\/td><td><input type='text' id='length_" + c_no + "' name='length_" + c_no + "' maxlength='3' size='3' /> (applied for Text Input only, default is 60)<\/td><\/tr>");
    html += ("<tr><td>Required:<\/td><td><input type='checkbox' id='required_" + c_no + "' name='required_" + c_no + "' value='required'/> (applied for Text Input and Select List)<\/td><\/tr>");
    html += ("<tr><td>Disable abbreviation: <\/td><td><select id='disable_abbreviation_" + c_no + "' name='disable_abbreviation_" + c_no + "' >" + abbreviationOption + "</select><\/td><\/tr>");
    html += ("<tr><td>Optional:<\/td><td><input type='checkbox' id='optional_" + c_no + "' name='optional_" + c_no + "' value='optional' /> (User can choose to show/hide optional component)<\/td><\/tr>");
    html += ("<tr><td>Dependent ref code:<\/td><td><input type='text' id='dependent_" + c_no + "' name='dependent_" + c_no + "' value='' /> (separate by comma ',')<\/td><\/tr>");
    html += ("<tr><td>Option group:<\/td><td><input type='text' id='group_" + c_no + "' name='group_" + c_no + "' value='' /> (same name mean components are in same group)<\/td><\/tr>");
    html += ("<tr><td>Disable fields:<\/td><td><input type='text' id='disable_fields_" + c_no + "' name='disable_fields_" + c_no + "' value='' /> (disable fields when this option is selected)<\/td><\/tr>");
    html += ("<tr><td>Disable groups:</td><td><textarea id='disable_group_" + c_no + "' name='disable_group_" + c_no + "' rows='5' cols='45'></textarea><br/>(disable other groups when this group is selected, entomb in [])</td></tr>");
    html += ("<tr><td>Allow omit:<\/td><td><input type='checkbox' id='allow_omit_" + c_no + "' name='allow_omit_" + c_no + "' value='allow_omit' /> (allow this field to be marked as 'data missing')<\/td><\/tr>");
    html += ("<tr><td>Omit fields:</td><td><input type='text' id='omit_fields_" + c_no + "' name='omit_fields_" + c_no + "' value='' /> (omit fields when this option is omitted)</td></tr>");
    html += ("<tr><td>Default value:<\/td><td><input type='text' id='default_value_" + c_no + "' name='default_value_" + c_no + "' value='' /> (default value is used when data is missing)<\/td><\/tr>");
    html += ("<tr><td>Custom option wrapper:</td><td><input type='text' id='custom_wrapper_" + c_no + "' name='custom_wrapper_" + c_no + "' value='' disabled/> (use for wrapping 'other' value of custom select, separate begin & end tag by comma)</td></tr>");
    html += ("<tr><td>Numeric:<\/td><td><input type='checkbox' id='numeric_" + c_no + "' name='numeric_" + c_no + "' value='numeric'/> (applied for Text Input only)<\/td><\/tr>");
    html += ("<tr><td>Apply capitalized:<\/td><td><input type='checkbox' id='capitalized_" + c_no + "' name='capitalized_" + c_no + "' value='capitalized'/> (usually applied for Title only)<\/td><\/tr>");
    html += ("<tr><td>Scrape punctuation:<\/td><td><input type='checkbox' id='remove_end_punctuation_" + c_no + "' name='remove_end_punctuation_" + c_no + "' value='remove'  /> (usually applied for Title only)<\/td><\/tr>");
    html += ("<tr><td>Default end punctuation:</td><td><select id='default_end_" + c_no + "' name='default_end_" + c_no + "' >" + punctuationOption + "</select> (Apply to text input only, add a '.' to end of input if there is no punctuation)</td></tr>");
    html += ("<tr><td>Position index:<\/td><td><input type='text' id='index_" + c_no + "' name='index_" + c_no + "'  value='" + c_no + "' maxlength='3' size='3' /> (Smaller number = higher priority)<\/td><\/tr>");
    html += ("<tr><td>ISBN code:<\/td><td><select id='isbn_code_" + c_no + "' name='isbn_code_" + c_no + "'>" + isbnOption + "<\/select><\/td><\/tr>");
    html += ("<tr><td>Website code:<\/td><td><select id='website_code_" + c_no + "' name='website_code_" + c_no + "' >" + websiteOption + "<\/select><\/td><\/tr>");
    html += ("<tr><td>DOI code:<\/td><td><select id='doi_code_" + c_no + "' name='doi_code_" + c_no + "' >" + doiOption + "<\/select><\/td><\/tr>");
    html += ("<tr><td>ERIC code:<\/td><td><select id='eric_code_" + c_no + "' name='eric_code_" + c_no + "' >" + ericOption + "<\/select><\/td><\/tr>");
    html += ("<tr><td>Note text:<\/td><td><textarea id='note_text_" + c_no + "' name='note_text_" + c_no + "' rows='5' cols='45'></textarea><\/td><\/tr>");
    html += ("<tr><td>Disable component:</td><td><input type='checkbox' id='disable_" + c_no + "' name='disable_" + c_no + "'  value='disable'  \/><\/td><\/tr>");
    html += ("<tr><td>Allow second title:</td><td><input type='checkbox' id='allow_second_title_" + c_no + "' name='allow_second_title_" + c_no + "'  value='disable' /></td></tr>");
    html += ("<tr><td>Prefix rules:<\/td>");
    html += ("<td>");
    html += ("<input type='hidden' value='0' name='prefix_rules_count_" + c_no + "' id='prefix_rules_count_" + c_no + "'/>");
    html += ("<a href='#' onclick='add_component_prefix_rule(\"" + c_no + "\"); return false;' class='addLink'>Add<\/a>");
    html += ("<div id='prefix_rules_" + c_no + "'>");
    html += ("<\/div>");
    html += ("<\/td><\/tr>");
    html += ("<tr><td>Suffix rules:<\/td>");
    html += ("<td>");
    html += ("<input type='hidden' value='0' name='suffix_rules_count_" + c_no + "' id='suffix_rules_count_" + c_no + "'/>");
    html += ("<a href='#' onclick='add_component_suffix_rule(\"" + c_no + "\"); return false;' class='addLink'>Add<\/a>");
    html += ("<div id='suffix_rules_" + c_no + "'>");
    html += ("<\/div>");
    html += ("<\/td><\/tr>");
    html += "<\/table>"
    
    return html;
  }
  
  function add_component()
  {
    var html = create_html_component();
    var newDiv = document.createElement("div");
    newDiv.innerHTML = html;
    newDiv.id = "div_component_" + c_no;
    newDiv.style.border = "dashed gray 1px";
    newDiv.style.margin = "5px";
    newDiv.style.padding = "5px";
    $("div_components").appendChild(newDiv);
    $('component_' + c_no).onchange();
    
    newDiv.scrollTo();
    $('label_' + c_no).focus();
    c_no ++;
    component_count ++;
    $("c_no").value = c_no;
  }
  
  function add_component_from_template()
  {
    var newDiv = document.createElement("div");
    newDiv.id = "div_component_" + c_no;
    newDiv.style.display = "none";
    $("div_components").appendChild(newDiv);
    $('component_' + c_no).onchange();
    $('label_' + c_no).onchange();
    $('ref_code_' + c_no).onchange();
    $("div_id").value = "div_component_" + c_no;
    c_no ++;
    component_count ++;
    $("c_no").value = c_no;
  }
  
  function clone_component(source_cno)
  {
    var html = create_html_component();
    var newDiv = document.createElement("div");
    newDiv.innerHTML = html;
    newDiv.id = "div_component_" + c_no;
    newDiv.style.border = "dashed gray 1px";
    newDiv.style.margin = "5px";
    newDiv.style.padding = "5px";
    $("div_components").appendChild(newDiv);
    
    $('component_' + c_no).value = $('component_' + source_cno).value;
    $('component_' + c_no).onchange();
    $('label_' + c_no).value = $('label_' + source_cno).value + ' - Clone';
    $('label_' + c_no).onchange();
    $('ref_code_' + c_no).value = $('ref_code_' + source_cno).value;
    $('ref_code_' + c_no).onchange();
    $('length_' + c_no).value = $('length_' + source_cno).value;
    $('length_' + c_no).disabled = $('length_' + source_cno).disabled;
    $('required_' + c_no).checked = $('required_' + source_cno).checked;
    $('required_' + c_no).disabled = $('required_' + source_cno).disabled;
    $('optional_' + c_no).checked = $('optional_' + source_cno).checked;
    $('optional_' + c_no).disabled = $('optional_' + source_cno).disabled;
    $('group_' + c_no).value = $('group_' + source_cno).value;
    $('disable_abbreviation_' + c_no).value = $('disable_abbreviation_' + source_cno).value;
    $('disable_fields_' + c_no).value = $('disable_fields_' + source_cno).value;
    $('disable_group_' + c_no).value = $('disable_group_' + source_cno).value;
    $('allow_omit_' + c_no).checked = $('allow_omit_' + source_cno).checked;
    $('default_value_' + c_no).value = $('default_value_' + source_cno).value;
    $('numeric_' + c_no).checked = $('numeric_' + source_cno).checked;
    $('numeric_' + c_no).disabled = $('numeric_' + source_cno).disabled;
    $('capitalized_' + c_no).checked = $('capitalized_' + source_cno).checked;
    $('capitalized_' + c_no).disabled = $('capitalized_' + source_cno).disabled;
    $('index_' + c_no).value = $('index_' + source_cno).value;
    $('omit_fields_' + c_no).value = $('omit_fields_' + source_cno).value;
    $('isbn_code_' + c_no).value = $('isbn_code_' + source_cno).value;
    $('website_code_' + c_no).value = $('website_code_' + source_cno).value;
    $('note_text_' + c_no).value = $('note_text_' + source_cno).value;
    $('dependent_' + c_no).value = $('dependent_' + source_cno).value;
    $('default_end_' + c_no).value = $('default_end_' + source_cno).value;
    $('disable_' + c_no).checked = $('disable_' + source_cno).checked;
    $('allow_second_title_' + c_no).checked = $('allow_second_title_' + source_cno).checked;
    $('remove_end_punctuation_' + c_no).checked = $('remove_end_punctuation_' + source_cno).checked;
    
    newDiv.scrollTo();
    $('label_' + c_no).focus();
    
    var p_length = $("prefix_rules_" + source_cno).children.length;
    for (var i = 0; i < p_length; i++) {
      var p_child = $("prefix_rules_" + source_cno).children[i];
      add_component_prefix_rule(c_no, p_child.select('input')[0].value, p_child.select('input')[1].value, p_child.select('select')[0].value);
    }
    
    var s_length = $("suffix_rules_" + source_cno).children.length;
    for (var j = 0; j < s_length; j++) {
      var s_child = $("suffix_rules_" + source_cno).children[j];
      add_component_suffix_rule(c_no, s_child.select('input')[0].value, s_child.select('input')[1].value, s_child.select('select')[0].value);
    }
    
    c_no ++;
    component_count ++;
    $("c_no").value = c_no;
  }
  
  function remove_component(id)
  {
    var removedDiv = $("div_component_" + id);
    if (confirm("This action cannot be undone, are you sure you want to delete a component?")) {
      $("div_components").removeChild(removedDiv);
      component_count --;
    }
  }
  
  function check_component_type(index)
  {
    switch($("component_" + index).value)
    {
      case "text_input":
        $("options_" + index).disabled = true;
        $("length_" + index).disabled = false;
        $("required_" + index).disabled = false;
        $("numeric_" + index).disabled = false;
        $("capitalized_" + index).disabled = false;
        $("isbn_code_" + index).disabled = false;
        $("website_code_" + index).disabled = false;
        $("doi_code_" + index).disabled = false;
        $("allow_omit_" + index).disabled = false;
        $("default_value_" + index).disabled = false;
        $("custom_wrapper_" + index).disabled = true;
        break;
      case "select_list":
        $("options_" + index).disabled = false;
        $("length_" + index).disabled = true;
        $("required_" + index).disabled = false;
        $("numeric_" + index).disabled = true;
        $("capitalized_" + index).disabled = true;
        $("isbn_code_" + index).disabled = true;
        $("website_code_" + index).disabled = false;
        $("doi_code_" + index).disabled = false;
        $("allow_omit_" + index).disabled = false;
        $("default_value_" + index).disabled = false;
        $("custom_wrapper_" + index).disabled = true;
        break;
      case "radio_group":
        $("options_" + index).disabled = false;
        $("length_" + index).disabled = true;
        $("required_" + index).disabled = false;
        $("numeric_" + index).disabled = true;
        $("capitalized_" + index).disabled = true;
        $("isbn_code_" + index).disabled = true;
        $("website_code_" + index).disabled = false;
        $("doi_code_" + index).disabled = false;
        $("allow_omit_" + index).disabled = true;
        $("default_value_" + index).disabled = true;
        $("custom_wrapper_" + index).disabled = true;
        break;
      case "custom_select_list":
        $("options_" + index).disabled = false;
        $("length_" + index).disabled = true;
        $("required_" + index).disabled = false;
        $("numeric_" + index).disabled = true;
        $("capitalized_" + index).disabled = true;
        $("isbn_code_" + index).disabled = true;
        $("website_code_" + index).disabled = false;
        $("doi_code_" + index).disabled = false;
        $("allow_omit_" + index).disabled = true;
        $("default_value_" + index).disabled = true;
        $("custom_wrapper_" + index).disabled = false;
      case "select_text_field":
        $("options_" + index).disabled = false;
        $("length_" + index).disabled = true;
        $("required_" + index).disabled = false;
        $("numeric_" + index).disabled = true;
        $("capitalized_" + index).disabled = true;
        $("isbn_code_" + index).disabled = true;
        $("website_code_" + index).disabled = false;
        $("doi_code_" + index).disabled = false;
        $("allow_omit_" + index).disabled = true;
        $("default_value_" + index).disabled = true;
        $("custom_wrapper_" + index).disabled = false;
        break;
      case "day_input":
        $("options_" + index).disabled = false;
        $("length_" + index).disabled = true;
        $("required_" + index).disabled = false;
        $("numeric_" + index).disabled = true;
        $("capitalized_" + index).disabled = true;
        $("isbn_code_" + index).disabled = true;
        $("website_code_" + index).disabled = false;
        $("doi_code_" + index).disabled = false;
        $("allow_omit_" + index).disabled = true;
        $("default_value_" + index).disabled = true;
        $("custom_wrapper_" + index).disabled = true;
        break;
      case "month_input":
        $("options_" + index).disabled = false;
        $("length_" + index).disabled = true;
        $("required_" + index).disabled = false;
        $("numeric_" + index).disabled = true;
        $("capitalized_" + index).disabled = true;
        $("isbn_code_" + index).disabled = true;
        $("website_code_" + index).disabled = false;
        $("doi_code_" + index).disabled = false;
        $("allow_omit_" + index).disabled = true;
        $("default_value_" + index).disabled = true;
        $("custom_wrapper_" + index).disabled = true;
        break;
      case "date_input":
        $("options_" + index).disabled = true;
        $("length_" + index).disabled = true;
        $("required_" + index).disabled = true;
        $("numeric_" + index).disabled = true;
        $("capitalized_" + index).disabled = true;
        $("isbn_code_" + index).disabled = true;
        $("website_code_" + index).disabled = true;
        $("doi_code_" + index).disabled = true;
        $("allow_omit_" + index).disabled = true;
        $("default_value_" + index).disabled = true;
        $("custom_wrapper_" + index).disabled = true;
        break;
      case "contributor":
        $("options_" + index).disabled = true;
        $("length_" + index).disabled = true;
        $("required_" + index).disabled = true;
        $("numeric_" + index).disabled = true;
        $("capitalized_" + index).disabled = true;
        $("isbn_code_" + index).disabled = false;
        $("website_code_" + index).disabled = false;
        $("doi_code_" + index).disabled = false;
        $("allow_omit_" + index).disabled = true;
        $("default_value_" + index).disabled = true;
        $("custom_wrapper_" + index).disabled = true;
        break;
      default: break;
    }
  }

  function check_syntax(input)
  {
    if(count_char_appearance('{', input) != count_char_appearance('}', input))
    {
      return false;
    }
    if(count_char_appearance('[', input) != count_char_appearance(']', input))
    {
      return false;
    }
    
    return true;
  }
  
  function count_char_appearance(chr, input)
  {
    var length = input.length;
    var i;
    var char_count = 0;
    for(i=0; i < length; i++)
    {
      if(input.charAt(i) == chr)
      {
        char_count ++;
      }
    }
    return char_count;
  }
  
  function add_component_prefix_rule(component_index, add_value, check_com, select_value)
  {
    if (typeof add_value == 'undefined')
      add_value = '';
    if (typeof check_com == 'undefined')
      check_com = '';
    if (typeof select_value == 'undefined')
      select_value = '';
    
    var rules_td = $('prefix_rules_' + component_index);
    var prefix_rule_count = parseInt($('prefix_rules_count_' + component_index).value) + 1;
    var prefix_rule_div = document.createElement("div");
    prefix_rule_div.id = "prefix_rule_" + component_index + "_" + prefix_rule_count;
    var in_html = ("Add <input type='text' id='before_" + component_index + "_" + prefix_rule_count + "' name='before_" + component_index + "_" + prefix_rule_count + "'  value='" + add_value +"' size='15' /> before when <input type='text' id='before_com_" + component_index + "_" + prefix_rule_count + "' name='before_com_" + component_index + "_" + prefix_rule_count + "'  value='" + check_com + "' size='25' />");
    in_html += ("&nbsp;<select name='before_state_" + component_index + "_" + prefix_rule_count + "' id='before_state_" + component_index + "_" + prefix_rule_count + "'><option value='true'>presents<\/option><option value='false'>not presents<\/option><\/select>");
    in_html += ("&nbsp;<a href='#' onclick='remove_component_prefix_rule(\"prefix_rule_" + component_index + "_" + prefix_rule_count+ "\"); return false;' class='removeLink'>Remove<\/a>")
    
    prefix_rule_div.innerHTML = in_html;
    rules_td.appendChild(prefix_rule_div);
    $('before_state_' + component_index + '_' + prefix_rule_count).value = select_value;
    $('prefix_rules_count_' + component_index).value = prefix_rule_count;
  }
  
  function remove_component_prefix_rule(rule_id)
  {
    if($(rule_id))
      $(rule_id).remove();
  }
  
  function add_component_suffix_rule(component_index, add_value, check_com, select_value)
  {
    if (typeof add_value == 'undefined')
      add_value = '';
    if (typeof check_com == 'undefined')
      check_com = '';
    if (typeof select_value == 'undefined')
      select_value = '';
    
    var rules_td = $('suffix_rules_' + component_index);
    var suffix_rule_count = parseInt($('suffix_rules_count_' + component_index).value) + 1;
    var suffix_rule_div = document.createElement("div");
    suffix_rule_div.id = "suffix_rule_" + component_index + "_" + suffix_rule_count;
    var in_html = ("Add <input type='text' id='after_" + component_index + "_" + suffix_rule_count + "' name='after_" + component_index + "_" + suffix_rule_count + "'  value='"+ add_value + "' size='15' /> after when <input type='text' id='after_com_" + component_index + "_" + suffix_rule_count + "' name='after_com_" + component_index + "_" + suffix_rule_count + "'  value='" + check_com + "' size='25' />");
    in_html += ("&nbsp;<select name='after_state_" + component_index + "_" + suffix_rule_count + "' id='after_state_" + component_index + "_" + suffix_rule_count + "'><option value='true'>presents<\/option><option value='false'>not presents<\/option><\/select>");
    in_html += ("&nbsp;<a href='#' onclick='remove_component_suffix_rule(\"suffix_rule_" + component_index + "_" + suffix_rule_count+ "\"); return false;' class='removeLink'>Remove<\/a>")
    
    suffix_rule_div.innerHTML = in_html;
    rules_td.appendChild(suffix_rule_div);
    $('after_state_' + component_index + '_' + suffix_rule_count).value = select_value;
    $('suffix_rules_count_' + component_index).value = suffix_rule_count;
  }
  
  function remove_component_suffix_rule(rule_id)
  {
    if($(rule_id))
      $(rule_id).remove();
  }
  
  function increase_index()
  {
    var increment = parseInt($('pos_index_increment').value);
    var current_index = parseInt($('pos_index_increment_start').value);
    
    for(var i = 0; i <= c_no; i ++)
    {
      if($('index_' + i) && $('index_' + i).value == current_index)
      {
        $('index_' + i).value = parseInt($('index_' + i).value) + increment;
        current_index += 1;
      }
    }
  }
  
  var rule_html;
  function init_rule_template()
  {
    rule_html = $('div_rule_template').innerHTML;
  }
  function add_rule()
  {
    var newDiv = document.createElement('div');
    rule_count ++;
    var local_html = rule_html.replace(/_template/g, '_' + rule_count);
    local_html = local_html.replace(/Rule template/, 'Rule ' + rule_count);
    local_html = local_html.replace(/>(.*?)<\/textarea>/, '><\/textarea>');
    local_html = local_html.replace(/clone_rule\(template\)/, 'clone_rule(' + rule_count + ')');
    local_html = local_html.replace(/preview_rule\(template\)/, 'preview_rule(' + rule_count + ')');
    newDiv.id = 'div_rule_' + rule_count;
    newDiv.innerHTML = local_html;
    $('div_rules').appendChild(newDiv);
    $('rule_count').value = parseInt($('rule_count').value) + 1;
    $('rule_' + rule_count + '_name').value = '';
    $('rule_eric_' + rule_count).checked = false;
    $('rule_fix_pos_' + rule_count).checked = false;
    $('rule_' + rule_count).value = '';
    $('rule_id_' + rule_count).value = '';
    $("span_remove_" + rule_count).innerHTML = "<a href='#' onclick='remove_rule(" + rule_count + "); return false;' class='removeLink'>Remove<\/a>";
    $('rule_' + rule_count).focus();
  }
  
  function clone_rule(index)
  {
    var newDiv = document.createElement('div');
    rule_count ++;
    var local_html = rule_html.replace(/_template/g, '_' + rule_count);
    local_html = local_html.replace(/Rule template/, 'Rule ' + rule_count);
    local_html = local_html.replace(/clone_rule\(template\)/, 'clone_rule(' + rule_count + ')');
    local_html = local_html.replace(/preview_rule\(template\)/, 'preview_rule(' + rule_count + ')');
    newDiv.id = 'div_rule_' + rule_count;
    newDiv.innerHTML = local_html;
    $('div_rules').appendChild(newDiv);
    $('rule_count').value = parseInt($('rule_count').value) + 1;
    $('rule_' + rule_count + '_name').value = $('rule_' + index + '_name').value + " - Clone";
    $('rule_' + rule_count).value = $('rule_' + index).value;
    $('rule_eric_' + rule_count).checked = $('rule_eric_' + index).checked;
    $('rule_fix_pos_' + rule_count).checked = $('rule_fix_pos_' + index).checked;
    $('rule_id_' + rule_count).value = '';
    $("span_remove_" + rule_count).innerHTML = "<a href='#' onclick='remove_rule(" + rule_count + "); return false;' class='removeLink'>Remove<\/a>";
    $('rule_' + rule_count).focus();
  }

  function remove_rule(index)
  {
    var removedDiv = $('div_rule_' + index);
    var removedLink = $('rule_history_link_' + index);
    if(removedDiv)
      $('div_rules').removeChild(removedDiv);
    if(removedLink)
      $('div_rules').removeChild(removedLink);
  }
  
  function preview_rule(index)
  {
    var count = 0;
    var output = $('rule_' + index).value;
    for(count = 0; count <= c_no; count++)
    {
      if($("ref_code_" + count))
      {
        ref_code = $("ref_code_" + count).value;
        label = $("label_" + count).value;
        output = output.replace(new RegExp("{" + ref_code + "}","g"), "{" + label + "}");
      }
    }
    output = output.replace(new RegExp("<","g"), "&lt;");
    output = output.replace(new RegExp(">","g"), "&gt;");
    output = output.replace(new RegExp("&lt;b&gt;","g"), "<b>");
    output = output.replace(new RegExp("&lt;\/b&gt;","g"), "<\/b>");
    output = output.replace(new RegExp("&lt;u&gt;","g"), "<u>");
    output = output.replace(new RegExp("&lt;\/u&gt;","g"), "<\/u>");
    output = output.replace(new RegExp("&lt;i&gt;","g"), "<i>");
    output = output.replace(new RegExp("&lt;\/i&gt;","g"), "<\/i>");
    $("span_rule_preview_" + index).innerHTML = output;
  }
  function isNumeric(sText)
    {
       var ValidChars = '0123456789.';
       var IsNumber=true;
       var Char;


       for (i = 0; i < sText.length && IsNumber == true; i++) 
          { 
          Char = sText.charAt(i); 
          if (ValidChars.indexOf(Char) == -1) 
             {
             IsNumber = false;
             }
          }
       return IsNumber;
    }

    function isValidDate(field_name) {
        var myDayStr = document.getElementById(field_name + '_day').value;
        var myMonthStr = document.getElementById(field_name + '_month').selectedIndex;
        var myYearStr = document.getElementById(field_name + '_year').value;
        if(myYearStr == '')
        {
          return false;
        }
        var myDateStr = myDayStr + ' ' + myMonthStr + ' ' + myYearStr;

        /* Using form values, create a new date object
        using the setFullYear function */
        var myDate = new Date();
        myDate.setFullYear( myYearStr, myMonthStr, myDayStr );

        if(myDate.getMonth() != myMonthStr ) 
        {
          return false;
        } 
        else 
        {
          return true;
        }
    }

    function suggest_title_format(field_id)
    {
      var ele = document.getElementById(field_id);
      var arr = ele.value.split(':');
      var result = "";
      var temp_arr;
      var i;
      var res;
      for(i = 0; i < arr.length; i++)
      {
        res = '';
        temp_arr = arr[i].replace(/^\s+|\s+$/g, '').split(' ');
        for(var j = 0; j < temp_arr.length; j ++)
        {
          if(temp_arr[j] != '')
          {
            res += temp_arr[j] + ' ';
          }
        }
        arr[i] = res.replace(/^\s+|\s+$/g, '').capitalize();
      }
      result = arr.join(': ');
      ele.value = result;
    }

    function display_instruction(text)
    {
      if(text != '')
      {
        display_text = text.gsub('~rsquo;', '&rsquo;');
        display_text = display_text.gsub('~quot;', '&quot;');
        $('div_instruction').innerHTML = display_text;
        $('div_instruction').removeClassName('hidden');            
      }
      else
      {
        $('div_instruction').addClassName('hidden');            
      }
    }

    function hide_instruction()
    {
      $('div_instruction').addClassName('hidden');          
    }

    function toggle_require(id)
    {
      if ($('checkbox_omit_' + id) && $('checkbox_omit_' + id).checked && $('check_require_' + id))
      {
        $('check_require_' + id).value = 'uncheck';
      }
      if ($('checkbox_omit_' + id) && !$('checkbox_omit_' + id).checked && $('check_require_' + id))
      {
        $('check_require_' + id).value = 'check';
      }
    }
    
    function check_other(id)
    {
      if($(id + '_custom_select_other'))
      {
        if($(id + '_custom_select').value != 'custom_other_option')
        {
          $(id + '_custom_select_other').value = '';
          $(id + '_custom_select_other').disabled = true;
        }
        else
        {
          $(id + '_custom_select_other').disabled = false;
        }
      }
    }
    function toggle_disable(id)
    {
      if($(id))
      {
        if($(id).disabled)
          $(id).disabled = false;
        else
          $(id).disabled = true;
      }
      if($(id + '_select'))
      {
        if($(id + '_select').disabled)
          $(id + '_select').disabled = false;
        else
          $(id + '_select').disabled = true;
      }
    }

    function toggle_allow_omit(field_ids, check_box_ids)
    {
      var field_id_arr = field_ids.split(',');
      for(var i = 0; i < field_id_arr.length; i++)
      { 
        toggle_require(field_id_arr[i]);
        toggle_disable(field_id_arr[i]);
      }
      var check_box_id_arr = check_box_ids.split(',');
      for(var i = 0; i < check_box_id_arr.length; i++)
      {
        if($(check_box_id_arr[i]))
        {
          if($(check_box_id_arr[i]).disabled)
            $(check_box_id_arr[i]).disabled = false;
          else
            $(check_box_id_arr[i]).disabled = true;
        }
      }
    }
    
    function toggle_select_omit(select_list_id, field_ids, select_ids)
    {
      var missing = $(select_list_id).value == 'missing';
      var field_id_arr = field_ids.split(',');
      for(var i = 0; i < field_id_arr.length; i++)
      { 
        if ($('check_require_' + field_id_arr[i]))
          $('check_require_' + field_id_arr[i]).value = missing ? 'uncheck' : 'check';
        if($(field_id_arr[i]))
          $(field_id_arr[i]).disabled = missing;
        if($(field_id_arr[i] + '_select'))
          $(field_id_arr[i] + '_select').disabled = missing;
      }
      
      var check_box_id_arr = select_ids.split(',');
      for(var i = 0; i < check_box_id_arr.length; i++)
      {
        if($(check_box_id_arr[i]))
        {
            $(check_box_id_arr[i]).disabled = missing;
        }
      }
    }

    function toggle_second_title_field(div_id, second_title_field_id, link_id)
    {
      if($(div_id))
      {
        $(div_id).toggleClassName('hidden');
        $(second_title_field_id).value = '';
        $(link_id).toggleClassName('hidden');
      }
    }
    
    function toggle_advance_contributor_option(div_id, select_list_id, link_id)
    {
      if($(div_id))
      {
        $(div_id).toggleClassName('hidden');
        $(select_list_id).value = '';
        $(link_id).toggleClassName('hidden');
      }
    }
    
    function getCssRule(selectorText)
    {
      for (var i = 0; i < document.styleSheets.length; i++) {
        var styleSheet = document.styleSheets[i];
        for (var j = 0; j < styleSheet.cssRules.length; j++) {
          if (styleSheet.cssRules[j].selectorText == selectorText)
            return styleSheet.cssRules[j];
        }
      }
      return null;
    }
    
    var advance_option_visibility = 'block';
    function change_advance_option_visibility(selectorText, selectListClass, display)
    {
//      var rule = getCssRule(selectorText);
//      rule.style.display = display;
//      
      advance_option_visibility = display;
      $$(selectorText).each(function(e) {
        if (display == 'none') {
          e.addClassName('hidden');
        } else {
          e.removeClassName('hidden');
        }
      });
      if (display == "none")
        $$(selectListClass).forEach(function(e) {e.value = "";});
    }
      
    function add_subtitle(component_name, value, instruction)
    {
      if (typeof value == 'undefined')
        value = '';
      var subtitle_container = $(component_name + '_subtitle_container');
      var subtitle_count = parseInt($(component_name + '_subtitle_count').value) + 1;
      var subtitle_div = document.createElement("div");
      subtitle_div.id = component_name + "_subtitle_" + subtitle_count + "_div";
      var subtitle_id = component_name + "_subtitle_" + subtitle_count;
      var in_html = ("Enter your subtitle: <input id='" + subtitle_id + "' name='" + subtitle_id + "' value='" + value + "' type='text' onFocus='display_instruction(\"" + instruction + "\");' onBlur='hide_instruction();'>");
      in_html += ("<a href='#' class='removeLink' onclick='remove_subtitle(\"" + subtitle_div.id + "\"); return false;'>&nbsp;</a>")

      subtitle_div.innerHTML = in_html;
      subtitle_container.appendChild(subtitle_div);
      $(component_name + '_subtitle_count').value = subtitle_count;
    }

    function remove_subtitle(subtitle_div_id)
    {
      if($(subtitle_div_id))
        $(subtitle_div_id).remove();
    }
    
    function handle_hide_link_clicked(checkbox, hide_component_string, show_component_string)
    {
      var hide_component_arr = hide_component_string.split(',');
      var show_component_arr = show_component_string.split(',');
      
      if(checkbox.checked)
      {
        toggle_hide_link_component_arr(hide_component_arr, "hide");
        toggle_hide_link_component_arr(show_component_arr, "show");
        toggle_hide_component(checkbox.id, 'show');
      }
      else
      {
        toggle_hide_link_component_arr(hide_component_arr, "show");
        toggle_hide_link_component_arr(show_component_arr, "hide");
        toggle_hide_component(checkbox.id, 'hide');
      }
    }
    
    function toggle_hide_link_component_arr(arr, status)
    {
      for(var i = 0; i < arr.length; i ++)
      {
        toggle_hide_link_component(arr[i], status, "linkHideComponent");
      }
    }
    
    function toggle_hide_link_component_group(arr, status)
    {
      for(var i = 0; i < arr.length; i ++)
      {
        toggle_hide_link_component(arr[i], status, "linkHideComponentGroup");
      }
    }
    
    function toggle_hide_link_component(component_id, status, css_class)
    {
      var c_id = component_id;
      component_id = 'component_row_' + component_id.gsub('FC', '');
      
      if($(component_id))
      {
        if(status == "hide")
        {
          $(component_id).addClassName(css_class);
          
          if(is_option_checkbox(c_id))
          {
            var component_to_hide_str = field_enable_field_hash.get(c_id) || "";
            var component_to_hide_arr = component_to_hide_str.split(',');
            toggle_hide_link_component_group(component_to_hide_arr, "hide");
          }
        }
        else if(!check_hide_link_disable_exist(c_id))
        {
          $(component_id).removeClassName(css_class);

          if(is_option_checkbox(c_id))
          {
            var component_to_show_str = field_enable_field_hash.get(c_id) || "";
            var component_to_show_arr = component_to_show_str.split(',');
            toggle_hide_link_component_group(component_to_show_arr, "show");
            if($(c_id).checked)
              toggle_hide_link_component_arr(component_to_show_arr, "show");
            else
              toggle_hide_link_component_arr(component_to_show_arr, "hide");
          }
        }
        
        if(!$(component_id).hasClassName('hidden') && !$(component_id).hasClassName('linkHideComponentGroup') && !$(component_id).hasClassName('linkHideComponent'))
        {
          $(c_id + '_pass_value').value = "pass_value";
          if ($('check_require_' + c_id))
          {
            $('check_require_' + c_id).value = 'check';
          }
          if ($('check_numeric_' + c_id))
          {
            $('check_numeric_' + c_id).value = 'check';
          }
          if ($(c_id.gsub('FC', '') + '_check_visible'))
          {
            $(c_id.gsub('FC', '') + '_check_visible').checked = true;
          }
        }
        else
        {
          $(c_id + '_pass_value').value = "";
          if ($('check_require_' + c_id))
          {
            $('check_require_' + c_id).value = 'uncheck';
          }
          if ($('check_numeric_' + c_id))
          {
            $('check_numeric_' + c_id).value = 'uncheck';
          }
          if ($(c_id.gsub('FC', '') + '_check_visible'))
          {
            $(c_id.gsub('FC', '') + '_check_visible').checked = false;
          }
        }
      }
    }
    
    function is_option_checkbox(field_id)
    {
      return (check_option_check_box_hash.get(field_id) == "true")
    }

    function disable_field(field_id)
    {
      toggle_component_field(field_id, 'hide');
      if(is_option_checkbox(field_id))
      {
        var disable_field_str = field_disable_field_hash.get(field_id) || "";
        var enable_field_str = field_enable_field_hash.get(field_id) || "";
        var disable_field_arr = disable_field_str.split(',');
        var enable_field_arr = enable_field_str.split(',');

        var i = 0;

        for(i = 0; i < disable_field_arr.length; i ++)
        {
          if(check_basic_component('FC' + disable_field_arr[i].gsub('component_row_', '')))
            toggle_hide_link_component(disable_field_arr[i], 'show');
        }
        for(i = 0; i < enable_field_arr.length; i ++)
        {
          if(check_basic_component('FC' + enable_field_arr[i].gsub('component_row_', '')))
            toggle_hide_link_component(enable_field_arr[i], 'show');
        }
      }
    }

    function enable_field(field_id)
    {
      if(!check_field_disable_field_exist(field_id))
      {
        toggle_component_field(field_id, 'show');
        if(is_option_checkbox(field_id))
          handle_hide_link_clicked($(field_id), field_disable_field_hash.get(field_id) || "", field_enable_field_hash.get(field_id) || "");
      }
    }

    function toggle_component_field(f_id, status)
    {
      var row_id = f_id.gsub('FC', '');
      var c_id = 'FC' + row_id;

      if(status == 'show')
      {
        if ($('component_row_' + row_id))
        {
          $('component_row_' + row_id).removeClassName('hidden');
        }
        if ($(c_id + '_pass_value') && !$('hidden_html_link_' + row_id))
        {
          $(c_id + '_pass_value').value = 'pass_value';
        }
        if ($(f_id + '_check_visible'))
        {
          $(f_id + '_check_visible').checked = true;
        }
        if ($('check_require_' + c_id))
        {
          $('check_require_' + c_id).value = 'check';
        }
        if ($('check_numeric_' + c_id))
        {
          $('check_numeric_' + c_id).value = 'check';
        }
      }
      else
      {
        if ($('component_row_' + row_id))
        {
          $('component_row_' + row_id).addClassName('hidden');
        }
        if ($(c_id + '_pass_value'))
        {
          $(c_id + '_pass_value').value = '';
        }
        if ($(f_id + '_check_visible'))
        {
          $(f_id + '_check_visible').checked = false;
        }
        if ($('check_require_' + c_id))
        {
          $('check_require_' + c_id).value = 'uncheck';
        }
        if ($('check_numeric_' + c_id))
        {
          $('check_numeric_' + c_id).value = 'uncheck';
        }
      }
    }

    function toggle_checkbox_status(check_id, status)
    {
      if(check_id != '' && $(check_id))
      {
        if(status == 'disable')
        {
          $(check_id).checked = false;
          $(check_id).disabled = true;
        }
        else
        {
          $(check_id).disabled = false;
        }
      }
    }

    function handle_ticked_check_box(check_box_id)
    {
      var component_to_show_str = check_box_enable_field_hash.get(check_box_id) || '';
      var component_to_hide_str = check_box_disable_field_hash.get(check_box_id) || '';
      var check_box_to_disable_str = check_box_disable_check_box_hash.get(check_box_id) || '';

      var component_to_show_arr = component_to_show_str.split(',');
      var component_to_hide_arr = component_to_hide_str.split(',');
      var check_box_to_disable_arr = check_box_to_disable_str.split(',');
      for(var i = 0; i < component_to_hide_arr.length; i ++)
      {
        if(component_to_hide_arr[i] && !check_enable_exist(component_to_hide_arr[i], check_box_id)) {
          disable_field(component_to_hide_arr[i]);
        }
      }

      for(var i = 0; i < component_to_show_arr.length; i ++)
      {
        if(component_to_show_arr[i] && !check_disable_exist(component_to_show_arr[i], check_box_id))
          enable_field(component_to_show_arr[i]);
      }

      for(var i = 0; i < check_box_to_disable_arr.length; i ++)
      {
        if(check_box_to_disable_arr[i] != check_box_id)
          toggle_checkbox_status(check_box_to_disable_arr[i], 'disable');
      }
    }

    function handle_unticked_check_box(check_box_id)
    {
      var component_to_show_str = check_box_disable_field_hash.get(check_box_id) || '';
      var component_to_hide_str = check_box_enable_field_hash.get(check_box_id) || '';
      var check_box_to_disable_str = check_box_disable_check_box_hash.get(check_box_id) || '';

      var component_to_show_arr = component_to_show_str.split(',');
      var component_to_hide_arr = component_to_hide_str.split(',');
      var check_box_to_disable_arr = check_box_to_disable_str.split(',');
      for(var i = 0; i < component_to_hide_arr.length; i ++)
      {
        if(component_to_hide_arr[i] && !check_enable_exist(component_to_hide_arr[i], check_box_id))
          disable_field(component_to_hide_arr[i]);
      }

      for(var i = 0; i < component_to_show_arr.length; i ++)
      {
        if(component_to_show_arr[i] && ((check_enable_exist(component_to_show_arr[i], check_box_id) && !no_check_box_checked()) || check_basic_component(component_to_show_arr[i])))
          enable_field(component_to_show_arr[i]);
      }

      for(var i = 0; i < check_box_to_disable_arr.length; i ++)
      {
        if(!check_disable_check_box_exist(check_box_to_disable_arr[i]) && check_box_to_disable_arr[i] != check_box_id)
          toggle_checkbox_status(check_box_to_disable_arr[i], 'enable');
      }
      if(no_check_box_checked() && default_advance_con_option == 'no')
      {
        change_advance_option_visibility('.advanceOptionWrapper', '.advanceOptionSelect', 'none');
      }
      if(no_check_box_checked() && default_advance_con_option == 'yes')
      {
        change_advance_option_visibility('.advanceOptionWrapper', '.advanceOptionSelect', 'block');
      }
    }

    function update_status(check_box_id, allow_tertiary)
    {
      var c_box = $(check_box_id);

      if (c_box.checked)
      {
        handle_ticked_check_box(check_box_id);
        if(!check_box_ignore_tertiary_hash.get(check_box_id))
          if (allow_tertiary || check_enable_tertiary_exist(check_box_id))
            change_advance_option_visibility('.advanceOptionWrapper', '.advanceOptionSelect', 'block');
          else
            change_advance_option_visibility('.advanceOptionWrapper', '.advanceOptionSelect', 'none');
      }
      else
      {
        handle_unticked_check_box(check_box_id);
        if(!check_box_ignore_tertiary_hash.get(check_box_id))
          if (allow_tertiary && !no_check_box_checked())
            if(check_enable_tertiary_exist(check_box_id))
              change_advance_option_visibility('.advanceOptionWrapper', '.advanceOptionSelect', 'block');
            else
              change_advance_option_visibility('.advanceOptionWrapper', '.advanceOptionSelect', 'none');
      }
    }

    function check_enable_exist(component_id, ignore_check_box_id)
    {
      if(!component_id || component_id == '') {return false;}
      for(var i = 0; i < check_box_ids.length; i++)
      {
        if (check_box_ids[i] != ignore_check_box_id && $(check_box_ids[i]) && $(check_box_ids[i]).checked)
        {
          var component_to_show_str = check_box_enable_field_hash.get(check_box_ids[i]) || '';
          var component_to_show_arr = component_to_show_str.split(',');
          for(var j = 0; j < component_to_show_arr.length; j ++)
            if(component_to_show_arr[j] == component_id) {return true;}
        }
      }
      return false;
    }

    function check_disable_exist(component_id, ignore_check_box_id)
    {
      if(!component_id || component_id == '') {return false;}
      for(var i = 0; i < check_box_ids.length; i++)
      {
        if (check_box_ids[i] != ignore_check_box_id && $(check_box_ids[i]) && $(check_box_ids[i]).checked)
        {
          var component_to_hide_str = check_box_disable_field_hash.get(check_box_ids[i]) || '';
          var component_to_hide_arr = component_to_hide_str.split(',');
          for(var j = 0; j < component_to_hide_arr.length; j ++)
            if(component_to_hide_arr[j] == component_id) {return true;}
        }
      }
      return false;
    }

    function check_disable_check_box_exist(check_box_id)
    {
      if(!check_box_id || check_box_id == '') {return false;}
      for(var i = 0; i < check_box_ids.length; i++)
      {
        if (check_box_ids[i] != check_box_id && $(check_box_ids[i]) && $(check_box_ids[i]).checked)
        {
          var disabling_check_boxes = check_box_disable_check_box_hash.get(check_box_ids[i]) || '';
          var check_box_to_disable_arr = disabling_check_boxes.split(',');
          for(var j = 0; j < check_box_to_disable_arr.length; j ++)
            if(check_box_to_disable_arr[j] == check_box_id) {return true;}
        }
      }
      
      return  check_hide_link_disable_exist(check_box_id.gsub('_check_visible', ''));
    }
    
    function check_hide_link_disable_exist(component_id)
    {
      for(var i = 0; i < hide_link_components.length; i ++)
      {
        var hide_link_name = hide_link_components[i];
        var disable_check_box_str = option_checkbox_disable_checkbox_hash.get(hide_link_name) || "";
        var check_box_to_disable_arr = disable_check_box_str.split(',');
        
        var disable_field_str = field_disable_field_hash.get(hide_link_name) || "";
        var disable_field_str_arr = disable_field_str.split(',');
        var pass_value_id = hide_link_name + '_pass_value';
        if ($(pass_value_id) && $(pass_value_id).value == 'pass_value' && $(hide_link_components[i]).checked)
        {
          for(var j = 0; j < check_box_to_disable_arr.length; j ++)
              if(check_box_to_disable_arr[j] == component_id) {return true;}
            
          for(var j = 0; j < disable_field_str_arr.length; j ++)
              if(disable_field_str_arr[j] == component_id) {return true;}
        }
      }
      
      return false;
    }

    function check_basic_component(component_id)
    {
      for(var i = 0; i < basic_component_arr.length; i ++)
        if(basic_component_arr[i] == component_id) {return true;}
      return false
    }

    function check_enable_tertiary_exist(ignore_check_box_id)
    {
      for(var i = 0; i < check_box_ids.length; i++)
      {
        if (check_box_ids[i] != ignore_check_box_id && $(check_box_ids[i]) && $(check_box_ids[i]).checked)
        {
          var check_value = check_box_enable_tertiary_hash.get(check_box_ids[i]) || '';
          if(check_value == '1') {return true;}
        }
      }
      return false;
    }

    function check_field_disable_field_exist(field_name)
    {
      var return_val = false;
      if(no_check_box_checked())
      {
        field_disable_field_hash.each(function(key_value) {
          //alert(key_value.key);
          var temp_arr = key_value.value.split(',');
          var c_name = key_value.key.gsub("FC", "component_row_");
          for(var i = 0; i < temp_arr.length; i ++)
            if(temp_arr[i] == field_name && $(c_name) && is_visible(c_name) && $(key_value.key).checked) {return_val = true}
        });
      }
      return return_val;
    }

    function no_check_box_checked()
    {
      for(var i = 0; i < check_box_ids.length; i++)
      {
        if ($(check_box_ids[i]) && $(check_box_ids[i]).checked)
        {
          return false;
        }
      }
      return true;
    }

    function toggle_hide_component(component_name, status) {
      var group_string = option_checkbox_disable_checkbox_hash.get(component_name) || "";
      var groups = group_string.split(',');
      for (var i = 0; i < groups.length; i++) {
        var check_box_id = groups[i] + '_check_visible';
        if ($(check_box_id))
          if (status == 'show') {
            if($(check_box_id).checked)
              handle_unticked_check_box(check_box_id);
            $(check_box_id).checked = false;
            $(check_box_id).disabled = true;
          } else {
            if(!check_disable_check_box_exist(check_box_id))
              $(check_box_id).disabled = false;
          }
      }
    }
    
    function is_visible(field_name)
    {
      if($(field_name).hasClassName("hidden") || $(field_name).hasClassName("linkHideComponent") || $(field_name).hasClassName("linkHideComponentGroup") || $(field_name).hasClassName("hideRadio"))
      {
        return false;
      }
      return true;
    }
    
    function getDropDownListDisplayText(element) {
      return element.options[element.selectedIndex].text;
    }