var DSG_server = "http://www.kelloggs.com";
var DQM_codebase = DSG_server + "/us/"    // relative location of .js files

var plmenu1 = new Array();
var plmenu2 = new Array();

/******************************************************************************/

function plstringSplit(string, delimiter)
{
  if (string == null || string == "") {
    return null;
  }
  else if (string.split != null) {
    return string.split(delimiter);
  }
  else {
    var ar = new Array();
    var i = 0;
    var start = 0;
    while (start >= 0 && start < string.length) {
         var end = string.indexOf(delimiter, start);
         if( end >= 0 ) {
           ar[i++] = string.substring(start, end);
           start = end+1;
         }
         else {
           ar[i++] = string.substring(start, string.length);
           start = -1;
         }
    }
    return ar;
  }
}

/******************************************************************************/

function plCreateMenus () {

  for (var i = 0; i < info.length; i++) {
    plmenu1[i] = plstringSplit(info[i], '*' );
    plmenu2[i] = plstringSplit(plmenu1[i][1], '|' );
  }

  var mnuGroup = document.forms[0].Group;
  var mnuitem = document.forms[0].productid;
  
  mnuGroup.length = plmenu1.length;
  mnuitem.length = plmenu2[0].length / 2;

  for (var i = 0; i < plmenu1.length; i++) {
    mnuGroup.options[i].value = plmenu1[i][0];
    mnuGroup.options[i].text = plmenu1[i][0];
  }
  document.forms[0].Group.selected = 0;

  for (var x = 0; x < plmenu2[0].length; x = x + 2) {
  	 if(mnuitem.options[x / 2] != null)
	 {
   	 mnuitem.options[x / 2].text = plmenu2[0][x];
    	 mnuitem.options[x / 2].value = plmenu2[0][x + 1];
	 }
  }
  document.forms[0].productid.selected = 0;
}

/******************************************************************************/

function plupdateMenus(el)
{
  var ndx = el.selectedIndex;

  if (ndx >= 0 && ndx < plmenu1.length) {
    var temp = plmenu2[ndx];
  }
  else {
    var temp = new Array ();
  }

  el.form.productid.length = temp.length / 2;

  for (var i = 0; i < temp.length; i = i + 2) {
    el.form.productid.options[i / 2].text  = temp[i];
    el.form.productid.options[i / 2].value = temp[i + 1];
  }
  el.form.productid.selected = 0;
}
