var Application =  {
  lastId: 0,
  currentSampleNb: 0,

  getNewId: function() {
    Application.lastId++;
    return "window_id_" + Application.lastId;
  },
  
//  Check for valid code in page
  evalCode: function(id) {
    var pre = $(id);
    var code;
    if (pre.textarea && pre.textarea.visible)
      code = pre.textarea.value;
    else
      code = pre.innerHTML;
    
    code = code.gsub("&lt;", "<");
    code = code.gsub("&gt;", ">");
    
    try {
      eval(code);
    }
    catch (error) {
      Dialog.alert(" error accurs while interprating your javascript code <br/>" + error, {windowParameters: {width:300, showEffect:Element.show}, okLabel: "close"});
    }
  },

//This function adds the demo to the list
addDemo: function(title, id, linkName) {
	Application.currentSampleNb++;
	idLink = id + '_view_link';
	document.write("<span id='" + idLink + "' style='cursor:pointer;text-decoration:none;color:#003399;font-weight:bold;font-size:12px;' href='#' onmouseover=\"$('" + idLink + "').addClassName('selected')\" onmouseout=\"$('" + idLink + "').removeClassName('selected')\" onclick=\"Application.evalCode('" + id + "', true)\">" + linkName + "</span>")
	}
}
