//var pp_currentTab="pp_overview"; 

function GetElement(id)
{
  if(document.getElementById)
    GetElement = function(id){ return document.getElementById(id); };
  else if(document.all)
    GetElement = function(id){ return document.all[id]; };
  else if(document.layers)
    GetElement = function(id){ return document.layers[id]; };
  else
    GetElement = function() { return null; }
  
  return GetElement(id);
}

  
function SendShowNode(nodeId)
{
  var obj = GetElement("node"+nodeId);
  var objItem = GetElement("item"+nodeId);

  if (obj.className=="tree_closed_ul")
  {
    obj.className="tree_opened_ul";
    objItem.style.display = "block";
  }
  else
  {
    obj.className="tree_closed_ul";
    objItem.style.display = "none";
  }

  // hide other nodes
/*  for (i=1;;i++)
  { 
    if (i==nodeId)
      continue;

    obj = GetElement("node"+i);
    objItem = GetElement("item"+i);

    if (!obj)
      break;

    obj.className="tree_closed_ul";
    objItem.style.display = "none";
  }*/
}




function GetXMLHTTPRequest()
{
  // массив функций
  var XMLHttpFactories = [
    function () {return new XMLHttpRequest()},
    function () {return new ActiveXObject("Microsoft.XMLHTTP")},
    function () {return new ActiveXObject("Msxml2.XMLHTTP")},
    function () {return new ActiveXObject("Msxml3.XMLHTTP")}
  ];

  var xmlhttp = null;
  for (var i=XMLHttpFactories.length-1; i>=0; i--) 
  {
    try 
    {
      xmlhttp = XMLHttpFactories[i]();
    }
    catch (e) 
    {
      continue;
    }

    return XMLHttpFactories[i]();
  }
}

var g_Req = GetXMLHTTPRequest();

function OnResponse()
{
  if (g_Req.readyState != 4) return;

  if (g_Req.status == 200 && g_Req.responseText != "") 
  {
    //alert(g_Req.responseText);
    eval(g_Req.responseText);
  } 
}

function Request(str)
{
  g_Req.open("POST", "/include/_support_utils.php", true);
  g_Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  g_Req.onreadystatechange = OnResponse;
  g_Req.send(str);
}


var g_VendorId = "";
var g_DeviceId = "";
var g_ProductId = "";

function OnSelectVendor()
{
  var id = GetElement("vendorid").value;

  if (g_VendorId != id)
  {
    g_VendorId = id;

    if (g_Req.readyState != 0)
      g_Req.abort();

    if (g_VendorId != "")
    {
      GetElement('img_deviceid').src="res/page/loading.gif"; 
      Request("vendorid="+id);
    }
    else
    {
      g_DeviceId = "*";
      g_ProductId = "*";

      GetElement('img_deviceid').src="res/page/dot_g.gif"; 

      var list = GetElement('deviceid'); 
      for (var i=list.options.length-1; i>=0; i--)
        list.options[i] = null;
      list.options.add(new Option("< Select vendor first>", ""));

      OnSelectDevice();
    }
  }
}

function OnSelectDevice()
{
  var id = GetElement("deviceid").value;

  if (g_DeviceId != id)
  {
    g_DeviceId = id;

    if (g_Req.readyState != 0)
      g_Req.abort();

    if (g_DeviceId != "")
    {
      GetElement('img_productid').src="res/page/loading.gif"; 
      Request("deviceid="+id);
    }
    else
    {
      g_ProductId = "*";
      GetElement('img_productid').src="res/page/dot_g.gif"; 

      var list = GetElement('productid'); 
      for (var i=list.options.length-1; i>=0; i--)
        list.options[i] = null;

      if (GetElement('deviceid').options.length > 1)
        list.options.add(new Option("< Select model first>", ""));
      else
        list.options.add(new Option("< Select vendor first>", ""));

      OnSelectProduct();
    }
  }
}

function OnSelectProduct()
{
  var id = GetElement("productid").value;

  if (g_ProductId != id)
  {
    g_ProductId = id;

    if (g_ProductId != "")
      GetElement('btn_go').style.display = ""; 
    else
      GetElement('btn_go').style.display = "none"; 
  }
}

