// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// add bookmark on IE and FF (Safari doesn't seem to work)
/*
function addBookmark() {
  title = "Whois.de!";
  url = "http://www.whois.de";

  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
  } else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title); }
  else if(window.opera && window.print) { // Opera Hotlist
    return true; }
}

Event.observe(window, 'load',
  // shows bookmark link only if supported by browser and javascript activated
  function () {if (window.external || window.sidebar || (window.opera && window.print)) {$$('.bookmark_link').each(function(e) {e.show();});}}
);
*/
Event.observe(window, 'load', initAll);

function initAll(){
	handleFlashMessages();
	if($("form_add_to_cart"))
		Event.observe("form_add_to_cart", 'submit', addToCart);
	
}
// morph flash messages
function handleFlashMessages()
{
  $$('.flash').each(
    function(flash)
    {
      flash.morph(  'morph',
        {duration: 2, delay: 1});
    }
  );
}

function addToCart(event){
  var list_dom = "" ;
  $$(".checkbox").each(function(el){
	  if($(el).checked == true){
		list_dom += $(el).getAttribute("id").split('domain_')[1].replace("_",".")+":1;";  
	  }
  });
  if(list_dom.length>0){
	  $("domains").value = list_dom;
  }else{
	  alert("You should adding last one domain to the cart before submition");
	  Event.stop(event);
  }
}