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

function hide_or_show( content_name )
{
  content = document.getElementById( content_name )

  if( content )
  {
    if( content.style.display == 'none' )
    {
        Effect.BlindDown( content_name, {duration: 0.6} )
    }
    else
    {
        Effect.BlindUp( content_name, {duration: 0.5})
    }
  }
  else
  {
    alert( 'Error' );
  }
}

function showAllByClassName( class_name )
{
	areas = document.getElementsByClassName( class_name );

	var i=0;
	for( i=0; i < areas.length; i++ )
	{
		if( areas[i].style.display == 'none' )
		{
			Element.show(areas[i].id);
		}
	}
}

function enableRowSpanHover( first_product_id, current_product_id, is_value_pack )
{
  var id_array = new Array(
    first_product_id + '_td_a',  // Price
    first_product_id + '_td_b',  // Coupons
    first_product_id + '_td_c',  // Merchant
    current_product_id + '_td_d',  // Picture
    current_product_id + '_td_e', // Description
    current_product_id + '_td_f', // Icon
    current_product_id + '_td_g' ); // Buy
	
	for( i=0; i < id_array.length; i++ )
	{
		var element = $(id_array[i])
		if(element)
		{
			var search = "hover_off";
      var replace = "hover_on";
			
			if( is_value_pack )
			{
				search = 'hover_off_valuepack';
				replace = 'hover_on_valuepack';
			}
			
			element.className = element.className.replace(search,replace);
		}
	}
}

function disableRowSpanHover( first_product_id, current_product_id, is_value_pack )
{
  var id_array = new Array(
    first_product_id + '_td_a',  // Price
    first_product_id + '_td_b',  // Coupons
    first_product_id + '_td_c',  // Merchant
    current_product_id + '_td_d',  // Picture
    current_product_id + '_td_e', // Description
    current_product_id + '_td_f', // Icon
    current_product_id + '_td_g' ); // Buy
	
	for( i=0; i < id_array.length; i++ )
	{
		var element = $(id_array[i])
		if(element)
		{
			var search = "hover_on";
      		var replace = "hover_off";
			
			if( is_value_pack )
			{
				search = 'hover_on_valuepack';
				replace = 'hover_off_valuepack';
			}
			
			element.className = element.className.replace(search,replace);
		}
	}
}

function append_flag( field_id, flag_name )
{
	f = $(field_id);
	
	f.value += '<img src="/images/flag/' + flag_name + '.gif"';
	
	if( flag_name == 'us' )
	{
		f.value += ' title="Ships to USA"> ';
	}
	else if( flag_name == 'ca' )
	{
		f.value += ' title="Ships to Canada"> ';
	}
	else if( flag_name == 'gb' )
	{
		f.value += ' title="Ships to U.K."> ';
	}
	else if( flag_name == 'mx' )
	{
		f.value += ' title="Ships to Mexico"> ';
	}
	else if( flag_name == 'pr' )
	{
		f.value += ' title="Ships to Puerto Rico"> ';
	}
	else if( flag_name == 'europeanunion' )
	{
		f.value += ' title="Ships to Europe"> ';
	}
	else if( flag_name == 'world' )
	{
		f.value += ' title="Ships Internationally"> ';
	}
	else
	{
		f.value += ' title="' + flag_name + '"> ';
	}
}

