var http = createRequestObject(); 

function createRequestObject()  {
  var request_o; 

  if(window.XMLHttpRequest)  { 
    try { 
      request_o = new XMLHttpRequest(); 
    } catch(e) { 
      window.location = "/site_map.html"
    } 
  } else if(window.ActiveXObject)  { 
    try { 
      request_o = new ActiveXObject("Msxml2.XMLHTTP"); 
    } catch(e) { 
      try { 
        request_o = new ActiveXObject("Microsoft.XMLHTTP"); 
      } catch(e) { 
        window.location = "/site_map.html"
      } 
    } 
  } 

  return request_o;
}

function processReq()  {
  if(http.readyState == 4)  {
    var response = http.responseXML.documentElement;
    var commands = response.getElementsByTagName('command');

    for(var i=0;i<commands.length;i++)  {
      method = commands[i].getAttribute('method');

      switch(method)  {
        case 'alert':
          var message = getNodeValue(commands[i],'message');
          window.alert(message);
          break;

         case 'setfocus':
           var target = getNodeValue(commands[i],'target');
           if(target)  {
             document.getElementById(target).focus();
           }
           break;

        case 'setdefault': 
          var target = getNodeValue(commands[i],'target'); 
          if(target)  { 
            document.getElementById(target).selectedIndex = 0; 
          } 
          break;

        case 'setlocation':
          var location  = getNodeValue(commands[i],'location');
          if(location)  {
            window.location = location;
          }
          break;

        case 'setvalue':
          var target = getNodeValue(commands[i],'target');
          var value  = getNodeValue(commands[i],'value');
          if(target)  {
            document.getElementById(target).value = value;
          }
          break;

        case 'setdisabled':
          var target = getNodeValue(commands[i],'target');
          if(target && value)  {
            document.getElementById(target).disabled = true;
          }
          break;

        case 'setenabled':
          var target = getNodeValue(commands[i],'target');
          if(target && value)  {
            document.getElementById(target).disabled = false;
          }
          break;

        case 'setcontent':
          var target  = getNodeValue(commands[i],'target');
          var content = getNodeValue(commands[i],'content');
          if(target && content)  {
            document.getElementById(target).innerHTML = content;
          }
          break;

        case 'setstyle':
          var target   = getNodeValue(commands[i],'target');
          var property = getNodeValue(commands[i],'property');
          var value    = getNodeValue(commands[i],'value');
          if(target && property && value)  {
            document.getElementById(target).style[property] = value;
          }
          break;

        case 'reload':
          window.location.href='/design_lab/lab.html';
          break;

      }
    }
  }
}

function getNodeValue(parent,tagName)  {
  var node = parent.getElementsByTagName(tagName)[0];
  return (node && node.firstChild) ? node.firstChild.nodeValue : false;
}

function confirmDelete(delUri,question) {
  if (!question) { question = 'Are you sure you want to delete this?'; }

  if (confirm(question)) {
    document.location = delUri;
  } else {
    return false;
  }
}