Event.observe(window, 'load', function() {
  var e = $A(document.getElementsByTagName('*')).find(function(e) {
    return (e.tagName.toUpperCase() == 'INPUT' && (e.type == 'text' || e.type == 'password'))
        || e.tagName.toUpperCase() == 'TEXTAREA' || e.tagName.toUpperCase() == 'SELECT';
  });
//  if (e) e.focus();
});

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var Application =  {
  lastId: 0,
  currentSampleNb: 0,

  getNewId: function() {
    Application.lastId++;
    return "window_id_" + Application.lastId;
  },
  
  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"});
    }
  },

	addTitle: function(title, id, image) {
	  Application.currentSampleNb++;
	  idButton = id + '_click_button';
	  
	  document.write("<h2>" + title + " <span class='title'  id='" + idButton + "' href='#' onmouseover=\"$('" + idButton + "').addClassName('selected')\" onmouseout=\"$('" + idButton + "').removeClassName('selected')\" onclick=\"Application.evalCode('" + id + "', true)\">" + image + "</span></h2>")
	},

	insertDocOverview: function() {
	  var div = $('Overview');
	  var html = "<table class='overview''><tr>";
	  
	  // Window
	  html += "<td>Window Class <ul>";
	  $$(".window").each(function(element){html += "- <a href='#" + element.title + "'>" + element.title + "</a><br/>"});
	  html += "</ul></td>";
	  
	  // Dialog
	  html += "<td>Dialog Module <ul>";
	  $$(".dialogmodule").each(function(element){html += "- <a href='#" + element.title + "'>" + element.title + "</a><br/>"});
	  html += "</ul></td>";
	  
	  // Windows
	  html += "<td>Windows Module <ul>";
	  $$(".windows").each(function(element){html += "- <a href='#" + element.title + "'>" + element.title + "</a><br/>"});
	  html += "</ul></td>";
		  
	  html += "</tr></table>"
	  div.innerHTML = html;
	}
	
}
function breakout_of_frame()
{
  // see http://www.thesitewizard.com/archive/framebreak.shtml
  // for an explanation of this script and how to use it on your
  // own website
  if (top.location != location) {
    top.location.href = document.location.href ;
  }
}
function bookmarkUs() {
	var url = "http://www.#{SITE_NAME}";
	var who = "#{SITE_ANME_WORDS}! Thousands of high-quality #{COMMUNITY} jobs."
	var ver = navigator.appName;
	var num = parseInt(navigator.appVersion);
	if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
	   window.external.AddFavorite(url,who);
	}else {
		alert('Bookmark Us!\nHit Ctrl+D if using a PC or\nCmd+D if using an Apple');
	}
}

function update_form_field(id,text) {
	$(id).value = text;
}

