
function F_JS_get_numeric_index_from_field_name(current_field, start_delim, end_delim, property_to_use)
{
 if (property_to_use == "ID")
    {iword = current_field.id;}
 else
    if (property_to_use == "VALUE")
       {iword = current_field.value;}
    else
       {iword = current_field.name;}
 <!-- alert("iword=" + iword); -->
 <!-- alert("start_delim=" + start_delim); -->
 istart_delim = start_delim;
 iend_delim   = end_delim;
 delimiter_found = false;

 if (iword.indexOf(istart_delim) >= 0)
    { 
     delimiter_found = true;
     istart =  iword.indexOf(istart_delim) + istart_delim.length;
     <!-- alert("istart=" + iword.indexOf(istart_delim) + "+" + istart_delim.length); -->
     if (iend_delim != "")
        iend   = iword.indexOf(iend_delim) - 1;
     else
        iend   = iword.length;

     <!-- alert("istart/iend=" + istart + "/" + iend); -->
     ilength = iend - istart + 1;
     if (istart < 0 || ilength < 0)
        index = -1;
     else
        index = iword.substr(istart, ilength);
     }
 else
     {
     <!-- alert("delim=" + start_delim + ", not found in word=" + iword); -->
	 index = -1;
	 }
	 
 <!--  alert("index returned=" + index);  -->
 return index;
}

function XX2F_JS_get_numeric_index_from_field_name(current_field, start_delim, end_delim, obj_name_or_id)
{
 if (obj_name_or_id == "id")
    { iword = current_field.id; }
 else
    { iword = current_field.name; }
 <!-- alert(iword); -->	
 istart_delim = start_delim;
 iend_delim   = end_delim;
 istart = iword.indexOf(istart_delim) + istart_delim.length;

 if (iend_delim == "")
     iend = iword.length - 1;
 else
     iend = iword.indexOf(iend_delim) - 1;

 ilength = iend - istart + 1;
 <!-- alert(iword); -->
 <!-- alert(istart + " " + iend + " " + ilength); -->
 if (istart < 0 || ilength < 0)
    index = -1;
 else
    index = iword.substr(istart, ilength);
	
 return index;
}

function XX1F_JS_get_numeric_index_from_field_name(current_field, start_delim, end_delim)
{

 iword = current_field.name;
  <!-- alert("iword=" + iword);  -->
  <!-- alert("start_delim=" + start_delim); -->
 istart_delim = start_delim;
 iend_delim   = end_delim;
 delimiter_found = false;

 if (iword.indexOf(istart_delim) >= 0)
    { 
     delimiter_found = true;
     istart =  iword.indexOf(istart_delim) + istart_delim.length;
     <!-- alert("istart=" + iword.indexOf(istart_delim) + "+" + istart_delim.length); -->
     if (iend_delim != "")
        iend   = iword.indexOf(iend_delim) - 1;
     else
        iend   = iword.length;

      <!-- alert("istart/iend=" + istart + "/" + iend); -->
     ilength = iend - istart + 1;
     if (istart < 0 || ilength < 0)
        index = -1;
     else
        index = iword.substr(istart, ilength);
     }
 else
     {
     <!-- alert("delim=" + start_delim + ", not found in word=" + iword); -->
	 index = -1;
	 }
	 
 <!--  alert("index returned=" + index);  -->
 return index;
}


function F_JS_get_attribute_value_from_option_value(attribute_name, option_field_value)
{
 tmpValue_topassback = "";
 split_delimiter = "~~";
 attribute_delimiter = ":";
 search_attribute_name = split_delimiter + attribute_name + attribute_delimiter;
 
 <!-- alert (option_field_value + " " + attribute_name); -->
 tmpValue = option_field_value;
 var tmpValueArray = tmpValue.split(search_attribute_name);
 <!-- alert ("val1[0]=" + tmpValueArray[0] + ", val1[1]=" + tmpValueArray[1]); -->
 <!-- alert ("l=" + tmpValueArray.length); -->
 if (tmpValueArray.length > 1)
    {
     var tmpValueArray2 = tmpValueArray[1].split(split_delimiter);
     <!-- alert ("l=" + tmpValueArray2.length); -->
     <!-- alert ("val2[0]=" + tmpValueArray2[0] + ", val2[1]=" + tmpValueArray2[1]); -->
	 tmpValue_topassback = tmpValueArray2[0];
	}
 else
    {
     alert ("There was a problem resolving a value in a dropdown list - contact support\n" + "l="+tmpValueArray.length+" v="+option_field_value + " a=" + attribute_name);
     tmpValue_topassback = "";
    }
	
 return tmpValue_topassback;
}

function F_JS_set_dropdown_selection_based_on_SelID_field(current_form, Sel_dropdown_field_obj, Sel_dropdown_ID_attribute_name_text, SelID_field_obj)
{
   j = 0;
   do 
     {
	  tmpOptionValue = F_JS_get_attribute_value_from_option_value(Sel_dropdown_ID_attribute_name_text, Sel_dropdown_field_obj.options[j].value);
      //alert ('/' + tmpOptionValue + '/' + SelID_field_obj.value + '/');

	  if (tmpOptionValue == SelID_field_obj.value)
		 {
		  Sel_dropdown_field_obj.options[j].selected = true;
		  <!-- F_JS_handle_change_to_address_country_list(Sel_dropdown_field_obj, current_form); -->
		  break;
		 }
	  j = j + 1;
	 }
   while (true)
}

function F_JS_set_SelID_field_based_on_dropdown_selection(current_form, Sel_dropdown_field_obj, Sel_dropdown_ID_attribute_name_text, start_delim_text, end_delim_text, obj_name_or_id_text, SelID_field_name_text)
{
 i = F_JS_get_numeric_index_from_field_name(Sel_dropdown_field_obj, start_delim_text, end_delim_text, obj_name_or_id_text);
 //alert (i);
 tmpIDValue  = F_JS_get_attribute_value_from_option_value(Sel_dropdown_ID_attribute_name_text, Sel_dropdown_field_obj.value);
 //alert (SelID_field_name_text);
 //REV20090101: changed document.all to document.getElementById(
 tmpID       = document.getElementById(SelID_field_name_text+i);
 tmpID.value = tmpIDValue;
}
