// Smartbox 2 Library Module

Smartbox.host = "localhost";
Smartbox.port = 8080;

function Smartbox(host, port) {
  Smartbox.host = host;
  Smartbox.port = port;
}


Smartbox.parse = function(node, options) {
  var type = node.tagName;
  var boxType;

  // check for type override
  if(BrowserDetect.browser=="Firefox"){
    boxType = node.getAttributeNS(Smartbox.BoxNS,"type"); 
  } else { //ie doesn't support namespace for attributes, work around not working?
    boxType=node.getAttribute("box:type");
  }

  if( boxType!=null && boxType!="") {
    type = boxType;
  }

  // parse primitives and SmartboxId's;  try to order these most common first

  if(type=="String") {
    return SmartXML.getText(node);      // return node.textContent;
  } else if((type == 'Double') || (type=='Float')) {
    return parseFloat(node.getAttribute('value'));
  } else if((type=='Integer') || (type=='Short') || (type=='Byte') ) {
    return parseInt(node.getAttribute('value'));
  } else if(type=='Long') {
    // <<<< Very important! JavaScript integers only give 53 bits of precision!
    // Replace this someday with an actual Long class
    return parseInt(node.getAttribute('value'));
  } else if(type=='Boolean') {
    return (node.getAttribute('value')=='true')?true:false;
  } else if(type=='Exception') {
    // <<<< more tbd
    return new SmartboxException(); //  node.getChild('message').text;
  } else {
    return "UNKOWN";    // <<<< return new SmartboxObject(node);
  }
}


/** class SmartboxException
*/

function SmartboxException(message) {
  this.message = message;
}

SmartboxException.prototype.isException = function() {
  return true;
}

SmartboxException.prototype.toString = function() {
  return "Exception:" + this.message;
}
