
  function jsAction(action)
  {
    switch(action)
    {
      case ACTION_jsTestAction: //test action
        testAction(action);
        break;
      case ACTION_jsExecuteQuery: //execute query
        executeQuery(action);
        break;
      case ACTION_jsUserRegister: //send registration data
        registerUser(action);
        break;
      case ACTION_jsGetNextObject: //get objects list
        getNextObject(action, 0);
        break;
      case ACTION_jsGetObjectInfo: //get object info
        getObjectInfo(action);
        break;    
      case ACTION_jsSysAddObject: //add new object
        sysAddObject(action);
        break;
      case ACTION_jsSysUpdateObject: //update object information
        sysUpdateObject(action);
        break;    
      case ACTION_jsSysRemoveObject: //remove object
        sysRemoveObject(action);
        break;
    }
  }
  
  function testAction(action)
  {
    var req = new Subsys_JsHttpRequest_Js();
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
      {
        if(req.responseJS) 
        {
					document.getElementById('test').innerHTML = req.responseJS.res;
        }
      }
		}
    req.caching = true;
    req.open('POST', 'http://' + top.location.host + '/phpactions.php?test=abc', true);
    req.send({action: action, param: 127});   
  }
  
  function executeQuery(action)
  {
    var req = new Subsys_JsHttpRequest_Js();
    var query = document.getElementById('jsSQLQuery').value;
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
      {
        if(req.responseJS) 
        {
					document.getElementById('jsSQLResult').src = 
            'sqlresult.php?query=' + req.responseJS.md5;
        }
      }
		}
    req.caching = false;
    req.open('POST', 'http://' + top.location.host + '/phpactions.php?test=abc', true);
    req.send({action: action, query: query});   
  }
  
  function registerUser(action)
  {
    var req = new Subsys_JsHttpRequest_Js();
    var name = document.getElementById('regUserName').value;
    var password = document.getElementById('regUserPass').value;
    var mail = document.getElementById('regUserMail').value;
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
      {
        //alert(req.responseText);
        if(req.responseJS) 
        {
					document.getElementById('regForm').innerHTML += 
            "\n" + req.responseJS.msg;
        }
      }
		}
    req.caching = false;
    req.open('POST', 'http://' + top.location.host + '/phpactions.php?test=abc', true);
    req.send({action: action, name: name, password: password, mail: mail});   
  }

  function getNextObject(action, callcnt)
  {
    var objecttype = document.getElementById('objectType').value;
    var req = new Subsys_JsHttpRequest_Js();
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
      {
        if(req.responseJS) 
        {
            objLst = document.getElementById('objectList');
            if(callcnt == 0)
            {
              //first call
              objLst.options.length = 0;
              objLst.options[0] = new Option("Select object ...", " ", true, false);
            }
            if(req.responseJS.last != 1)
            {
              objLst.options[objLst.options.length] 
                = new Option(req.responseJS.name, req.responseJS.id);
              if(callcnt < 10) //return only first 10 entries
              {
                getNextObject(action, callcnt + 1);
              }
            }
            else
            {
              if(callcnt == 0)
              {
                //empty list
                objLst.options[objLst.options.length] 
                  = new Option(req.responseJS.name, req.responseJS.id);                
              }
            }
        }
      }
		}
    req.caching = false;
    req.open('POST', 'http://' + top.location.host + '/phpactions.php?test=abc', true);
    req.send({action: action, objecttype: objecttype, callcnt: callcnt});
    jsAction(ACTION_jsGetObjectInfo);   
  }

  function getObjectInfo(action)
  {
    objList = document.getElementById('objectList');
    objectid  = objList.value;

    var req = new Subsys_JsHttpRequest_Js();
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
      {
        //alert(req.responseText);
        if(req.responseJS) 
        {
					document.getElementById('objectInfo').src = 
            'dynamic.php?action='+ action +'&query=' + req.responseJS.md5;        
        }
      }
		}
    req.caching = true;
    req.open('POST', 'http://' + top.location.host + '/phpactions.php?test=abc', true);
    req.send({action: action, objectid: objectid});
  }
  
  function sysAddObject(action)
  {
    //type - DOM element which contents type info
    type = document.getElementById('objectType'); 
    info = document.getElementById('objectInfo');
    infoElement = info.contentDocument.getElementById("objectInfo");
    infoValue = infoElement.value;
    
    var req = new Subsys_JsHttpRequest_Js();    
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
      {
        //alert(req.responseText);
        if(req.responseJS) 
        {
          infoElement.value = "New object added \n" + req.responseJS.result;
          //objs = document.getElementById('objectList');
          //objs.value = req.responseJS.id;
        }
      }
		}
    req.caching = true;
    req.open('POST', 'http://' + top.location.host + '/phpactions.php?test=abc', true);
    req.send({action: action, type: type.value, info: infoValue});
  }
  
  function sysUpdateObject(action)
  {
    var info = document.getElementById('objectInfo');
    var infoElement = info.contentDocument.getElementById("objectInfo");
    var id = document.getElementById('objectList').value;
    var infoValue = infoElement.value;
    
    var req = new Subsys_JsHttpRequest_Js();    
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
      {
        //alert(req.responseText);
        if(req.responseJS) 
        {
          infoElement.value = "Object updated \n" + req.responseJS.result;
        }
      }
		}
    req.caching = true;
    req.open('POST', 'http://' + top.location.host + '/phpactions.php?test=abc', true);
    req.send({action: action, id: id, info: infoValue});  
  }
  
  function sysRemoveObject(action)
  {
    var id = document.getElementById('objectList').value;
    var info = document.getElementById('objectInfo');
    var infoElement = info.contentDocument.getElementById("objectInfo");
    
    var req = new Subsys_JsHttpRequest_Js();    
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) 
      {
        if(req.responseJS) 
        {
          infoElement.value = "Object deleted \n" + req.responseJS.id;
          jsAction(ACTION_jsGetNextObject);
        }
      }
		}
    req.caching = true;
    req.open('POST', 'http://' + top.location.host + '/phpactions.php?test=abc', true);
    req.send({action: action, id: id});  
  }

/**/
