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

// addLoadEvent JS
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//addClass JS
function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

//insertAfter JS
function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}


//	startLinks JS (fixes CSS Dropdown menu display for IE 5/6)
function startList() 
{
	if (!document.getElementById || !document.getElementsByTagName) return false;
	if (document.all && document.getElementById) 
	{
    var navRoot = document.getElementById("menu");
    for (i=0; i<navRoot.childNodes.length; i++) 
    {
    	node = navRoot.childNodes[i];
    	if (node.nodeName == "LI") 
    	{
    		node.onmouseover = function() 
    		{
    			this.className+=" over";
    		}
    		node.onmouseout = function() 
    		{
    			this.className = this.className.replace
    				(" over", "");
    		}
    	}
    }
  }
}
// addLoadEvent(startList);


// alternative way of hiding/showing submenus
// taken from http://tutorials.alsacreations.com/deroulant/menu-horizontal.htm

function hideSubMenu(id) 
{
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) 
	{
	  if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
	if (d) {d.style.display='block';}
}

// addLoadEvent(hideSubMenu);

/* ==========================
 	 fade flashes automatically
	 ==========================	*/
Event.observe(window, 'load', function() { 
  $A(document.getElementsByClassName('flash')).each(function(o) {
    o.opacity = 100.0
    Effect.Fade(o, {duration: 10.0})
  });
});


/* =========================================
 	 toggle/display of shipping address fields
	 =========================================	*/
Event.observe(window, 'load', function() {
  // $('my_shipping_address').hide();
  Event.observe('change_shipping_address', 'click', function() {
     $('my_shipping_address').toggle();
  });
});


jQuery.noConflict();

/* Add PayPal subscription buttons to the Kit Club page
--------------------------------------------------------------- */
jQuery(document).ready(function() {
  // set vars
  var paypal = jQuery("h3:contains('If you would like to sign up via PAYPAL')");
  var form_domestic = "<h4 style='margin:20px 0 0; font-weight:bold;'>US Domestic Member Signup</h4><form id='paypal_domestic' style='margin:10px 0;' action='https://www.paypal.com/cgi-bin/webscr' method='post'><input type='hidden' name='cmd' value='_s-xclick'><input type='hidden' name='hosted_button_id' value='10384016'><input type='image' src='https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'><img alt='' border='0' src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1' /></form>";
    var form_domestic_price26 = "<h4 style='margin:20px 0 0; font-weight:bold;'>US Domestic Member Signup</h4><form id='paypal_domestic' style='margin:10px 0;' action='https://www.paypal.com/cgi-bin/webscr' method='post'> <input type='hidden' name='cmd' value='_s-xclick'><input type='hidden' name='hosted_button_id' value='10384016'><input type='image' src='https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'><img alt='' border='0' src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1'></form>"
  var form_international = "<h4 style='margin:20px 0 0; font-weight:bold;'>International Member Signup</h4><form id='paypal_international' style='margin:10px 0;' action='https://www.paypal.com/cgi-bin/webscr' method='post'><input type='hidden' name='cmd' value='_s-xclick'><input type='hidden' name='hosted_button_id' value='10458215'><input type='image' src='https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'><img alt='' border='0' src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1' /></form>";
  // insert paypal domestic form after the h3 heading
  paypal.after(form_domestic_price26);
  // insert paypal international form after domestic form
  jQuery("form#paypal_domestic").after(form_international);
});
