function SelectComboBoxCreateOptionDOM(el,optionhtml)
{
   optionvalue = '';
   optiontext = '...';
   optionstr = optionhtml;
   indexofvalueparam = optionstr.indexOf('value="',0);
   if (indexofvalueparam >= 0) {
      indexofvalueparam = indexofvalueparam + 7;
      indexofendvalueparam = optionstr.indexOf('"', indexofvalueparam+1);
	  if (indexofendvalueparam > 0) {
	     optionvalue = optionstr.slice(indexofvalueparam, indexofendvalueparam);
	  }
   }
   indexoftextparam = optionstr.indexOf('>',0);
   if (indexoftextparam >= 0) {
      indexoftextparam = indexoftextparam + 1;
      indexofendtextparam = optionstr.indexOf('<', indexoftextparam+1);
	  if (indexofendtextparam > 0) {
	     optiontext = optionstr.slice(indexoftextparam, indexofendtextparam);
	  }
   }
   var newOption = new Option(optiontext, optionvalue);
   el.options[el.options.length] = newOption;
}

function SelectComboBoxCreateOptionsDOM(el,optionshtml)
{
el.options.length = 0;
var optionsarr = optionshtml.split("<OPTION");
for ( keyVar in optionsarr ) {
   if (optionsarr[keyVar] != '') {
   optionsarr[keyVar] = "<OPTION" + optionsarr[keyVar];
   SelectComboBoxCreateOptionDOM(el,optionsarr[keyVar]);
   }   
}
}

function SelectComboBoxRefresh(el)
{
tmpvalue = el.value;
refreshurl = el.getAttribute("RefreshURL");

dinamicparamsresult = '';
refreshurlarray = refreshurl.split('!DINAMICPARAMS?');
refreshurl = refreshurlarray[0];
if (refreshurlarray[1] != null) {
  dinamicparams = refreshurlarray[1];
  dinamicparamsarray = dinamicparams.split('&');
  for (i = 0; i < dinamicparamsarray.length; i++)
  {
    dinamicparam = dinamicparamsarray[i].split('=');
    name = dinamicparam[0];
    value = dinamicparam[1];
    if (value.substr(0,1) == '!') {
       value = value.substr(1,value.length-2);
       resultvalue = document.getElementById(value).value;
       dinamicparamsresult = dinamicparamsresult + "&" + name + '=' + resultvalue;
    } else {
    }
  }
} else {
  dinamicparams = '';
}
el.options.length = 0;
var newOption = new Option('loading...', '');
el.options[el.options.length] = newOption;
selectoptions = makeRequestSynch(refreshurl, '&selectedvalue=' + tmpvalue + '&' + dinamicparamsresult);
SelectComboBoxCreateOptionsDOM(el,selectoptions);
}

function SelectComboBoxCreate(el, SelectComboBoxScriptFN)
{
tmpvalue = el.value;
if (el.getAttribute("onChange") == null) {
onchangeevent = "";
} else {
onchangeevent = String(el.getAttribute("onChange"));
onchangeevent = onchangeevent.replace("function anonymous()","");
}
refreshurl = SelectComboBoxScriptFN;
dinamicparamsresult = '';
refreshurlarray = refreshurl.split('!DINAMICPARAMS?');
refreshurl = refreshurlarray[0];
if (refreshurlarray[1] != null) {
  dinamicparams = refreshurlarray[1];
  dinamicparamsarray = dinamicparams.split('&');
  for (i = 0; i < dinamicparamsarray.length; i++)
  {
    dinamicparam = dinamicparamsarray[i].split('=');
    name = dinamicparam[0];
    value = dinamicparam[1];
    if (value.substr(0,1) == '!') {
       value = value.substr(1,value.length-2);
       resultvalue = document.getElementById(value).value;
       dinamicparamsresult = dinamicparamsresult + "&" + name + '=' + resultvalue;
    } else {
    }
  }
} else {
  dinamicparams = '';
}

selectoptions = makeRequestSynch(refreshurl, '&selectedvalue=' + tmpvalue + '&' + dinamicparamsresult);
tmps = "<select class=\"" + el.className + "\" name=\"" + el.getAttribute("name") + "\" id=\"" + el.getAttribute("id") + "\" dataFld=\"" + el.getAttribute("dataFld") + "\" dataType=\"" + el.getAttribute("dataType") + "\" onChange=\"" + onchangeevent + "\" RefreshURL=\"" + SelectComboBoxScriptFN + "\">";
tmps = tmps + selectoptions + "</select>";
el.parentNode.innerHTML = tmps;
}
