function show_hide(nm){
  obj = document.getElementById(nm);
  if(obj.style.display == 'block')
    obj.style.display = 'none';
  else
    obj.style.display = 'block';
  return false;
}
function mydebug(mytext){
  debugdiv = document.getElementById('debug');
  if(debugdiv)
    debugdiv.innerHTML += mytext + '<br />';
  else
    alert(mytext);
}
function MainMenuInit() {
   var builder = new DomMenuBuilder();
   builder.setSettings(new Hash(
           'openMouseoverMenuDelay', 1,
           'closeMouseoverMenuDelay', 1,
           'expandMenuArrowUrl', '/site/images/sub_menu_off.gif',
           'menuBarClass', 'domMenuMain_menuBar',
           'menuElementClass', 'domMenuMain_menuElement',
           'menuElementHoverClass', 'domMenuMain_menuElementHover',
           'menuElementActiveClass', 'domMenuMain_menuElementHover',
           'subMenuBarClass', 'domMenuMain_subMenuBar',
           'subMenuElementClass', 'domMenuMain_subMenuElement',
           'subMenuElementHoverClass', 'domMenuMain_subMenuElementHover',
           'subMenuElementActiveClass', 'domMenuMain_subMenuElementHover',
           'subMenuElementHeadingClass', 'domMenuMain_subMenuElementHeading'
	       ));
   builder.replace('domMenu_main');
}

function sync(useDvSide) {
  var horz = document.getElementById("dvData").scrollLeft;
  var vert = document.getElementById("dvData").scrollTop;
  var navDOM = window.innerHeight;
  if(navDOM) {
    DocWidth = document.width;
  } else {
    DocWidth = document.body.clientWidth;
  }
  if((useDvSide==1)) {
    document.getElementById("dvData").style.width = (DocWidth-457)+"px";
    document.getElementById("dvHeaderCover").style.width = (DocWidth-457)+"px";
  }
  if(horz>=0){
    if((useDvSide==1)) {
      document.getElementById("dvHeader").style.left=(-horz)+"px";
      document.getElementById("dvHeader").style.width=(DocWidth+horz)+"px";
    } else {
      document.getElementById("dvHeader").style.left=(-horz)+"px";
      document.getElementById("dvHeader").style.width=(DocWidth+horz)+"px";
    }
  }
  if((vert>=0)&&(useDvSide==1)){
    document.getElementById("dvSide").style.height=(parseInt(document.getElementById("dvSideCover").style.height)+vert)+"px";
    document.getElementById("dvSide").style.top=(-vert)+"px";
  }
}
function init(){
  login_input = document.getElementById('name');
  if(login_input){
    document.getElementById('name').focus();
  }
  setTimeout('hidePageLoadingInfo()',500);
}
function hidePageLoadingInfo() {
  document.getElementById('PageLoadingInfo').style.visibility = 'hidden';
}
function ResizeHeight(ElementId,plus){
  var frame = document.getElementById(ElementId);
  var htmlheight = document.documentElement.clientHeight;//document.body.parentNode.scrollHeight;
  var windowheight = window.innerHeight;
  if(htmlheight < windowheight) {
    document.body.style.height = windowheight + "px";
    if(frame) frame.style.height = windowheight+plus + "px";
  } else {
    document.body.style.height = htmlheight + "px";
    if(frame) frame.style.height = htmlheight+plus + "px";
  }
}
function openlive(id,col){
	document.location.href="setlive.php?id="+id+"&col="+col+"&scroll="+document.body.scrollTop
}
function closelive(id,col){
	document.location.href="closelive.php?id="+id+"&col="+col+"&scroll="+document.body.scrollTop
}
function popup(id){
	var root="./popup.php?id="+id;
	//window.open(root,"Product Info","scrollbars=no,resizable=no,status=no,toolbar=no,width=400,height=300");
	window.open(root,"my_new_window","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=yes, width=400, height=400");

}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


var isIE = true;
if (!document.all) {
  isIE = false;
}
// used in edit_recyclers. Sources from recycler_arrays
function update_recyclers_by_material(material){
  activities = document.getElementById('plant_activities');
  emptyList(activities);
  if(recyclers_activities[material[material.selectedIndex].value] && recyclers_activities[material[material.selectedIndex].value].length > 0){
    fillList(activities,recyclers_activities[material[material.selectedIndex].value],0,-1);
    //activities.style.display = 'inline';
  }else{
    //activities.style.display = 'none';
  }

  qualities = document.getElementById('qualities');
  emptyList(qualities);
  if(recyclers_qualities[material[material.selectedIndex].value] && recyclers_qualities[material[material.selectedIndex].value].length > 0){
    fillList(qualities,recyclers_qualities[material[material.selectedIndex].value],0,-1);
    //qualities.style.display = 'inline';
  }else{
    //qualities.style.display = 'none';
  }
}

/**
 * check_select is for control if selected item has value
 * created by Ondrej Letacek <Ondrej@nestdesign.com>
 **/

function fillList( box, arr, defaultValue, DselectedIndex) {
  if(DselectedIndex == undefined)
    DselectedIndex = 0;
  for (key in arr) {
    option = new Option( arr[key],key);
    if(key == defaultValue){
      DselectedIndex = box.length;
    }
    box.options[box.length] = option;
  }
  box.selectedIndex=DselectedIndex;
}
function emptyList( box ) {
  if(box!=null){
    while ( box.options.length ) box.options[0] = null;
  }
}
