// JavaScript Document<script type="text/javascript">
$(function() {
	$(".image").click(function() {
		var image = $(this).attr("rel");
		$('#image').hide();
		$('#image').fadeIn('slow');
		$('#image').html('<img src="' + image + '"/>');
		return false;
	});
	
	$(".buy_sandals").mouseover(function() {
		var pos = $(this).offset();

		$(".dm-buy-sandals").css("top",pos.top+26);
		$(".dm-buy-sandals").css("left",pos.left-15);		
		$(".dm-buy-sandals").show();
	});
	
	$(".cart_link").mouseover(function() {
		$(".dm-buy-sandals").hide();
	});
	$(".item_number").mouseover(function() {
		$(".dm-buy-sandals").hide();
	});
	$("#header .nav").mouseover(function() {
		$(".dm-buy-sandals").hide();
	});
	$(".dm-buy-sandals").mouseleave(function() {
		$(this).hide();
	});
});
	
	
function check_fields()
{
  if (document.f.shipping_same.checked) { autofill(); }

  ////////////////////////////////////////////////////////////////////////////////////////////

  if (!(check_input_text(document.f.first_name, "Billing First Name",        100, 1))) { return 0; }
  if (!(check_input_text(document.f.last_name,  "Billing Last Name",         100, 1))) { return 0; }
  if (!(check_input_text(document.f.phone,      "Billing Phone",             30,  1))) { return 0; }
  if (!(check_input_text(document.f.address,    "Billing Address",           255, 1))) { return 0; }
  if (!(check_input_text(document.f.city,       "Billing City",              100, 1))) { return 0; }
  if (!(check_input_text(document.f.zip,        "Billing Zip / Postal Code", 30,  1))) { return 0; }
  if (!(check_input_text(document.f.email,      "Billing Email",             255, 1))) { return 0; }

  if (document.f.state.options[document.f.state.selectedIndex].value == "") 
    { if (!(check_input_text(document.f.non_state, "Billing Non-US State / Prov", 100, 1))) { return 0; } }
  else
    { document.f.non_state.value=""; }

  if (document.f.state.options[document.f.state.selectedIndex].value == "" && document.f.country.options[document.f.country.selectedIndex].value == "US") 
    { alert("You cannot select both 'United States' and 'Outside US' for the same address."); return 0; }

  ////////////////////////////////////////////////////////////////////////////////////////////

  if (!(document.f.shipping_same.checked))
  {
    if (!(check_input_text(document.f.s_first_name, "Shipping First Name",        100, 1))) { return 0; }
    if (!(check_input_text(document.f.s_last_name,  "Shipping Last Name",         100, 1))) { return 0; }
    if (!(check_input_text(document.f.s_phone,      "Shipping Phone",             30,  1))) { return 0; }
    if (!(check_input_text(document.f.s_address,    "Shipping Address",           255, 1))) { return 0; }
    if (!(check_input_text(document.f.s_city,       "Shipping City",              100, 1))) { return 0; }
    if (!(check_input_text(document.f.s_zip,        "Shipping Zip / Postal Code", 30,  1))) { return 0; }
    if (!(check_input_text(document.f.s_email,      "Shipping Email",             255, 1))) { return 0; }

    if (document.f.s_state.options[document.f.s_state.selectedIndex].value == "") 
      { if (!(check_input_text(document.f.s_non_state, "Shipping Non-US State / Prov", 100, 1))) { return 0; } }
    else
      { document.f.s_non_state.value=""; }

    if (document.f.s_state.options[document.f.s_state.selectedIndex].value == "" && document.f.s_country.options[document.f.s_country.selectedIndex].value == "US") 
      { alert("You cannot select both 'United States' and 'Outside US' for the same address."); return 0; }
  }

  return 1;
}

function autofill()
{
  if (document.f.shipping_same.checked)
  {
    document.f.s_first_name.value=document.f.first_name.value;
    document.f.s_last_name.value=document.f.last_name.value;
    document.f.s_phone.value=document.f.phone.value;
    document.f.s_address.value=document.f.address.value;
    document.f.s_city.value=document.f.city.value;
    document.f.s_state.selectedIndex=document.f.state.selectedIndex;
    document.f.s_non_state.value=document.f.non_state.value;
    document.f.s_country.selectedIndex=document.f.country.selectedIndex;
    document.f.s_zip.value=document.f.zip.value;
    document.f.s_email.value=document.f.email.value;
  }
}

  function trim(str) 
  { 
    str.replace(/^\s*/, '').replace(/\s*$/, ''); 
    return str;
  } 

  function make_array()
  {
    for (i = 0; i < make_array.arguments.length; i++)
    {
        this[i] = make_array.arguments[i];
        this.length = make_array.arguments.length;
    }
  }

  function set_max(val1,val2)
  { if (val2 > val1) { return val2; } else { return val1; } }

  function check_input_text(element, name, max_length, not_null) 
  {
    if ((element.value).length > max_length) 
    {
      alert("Maximum length of the " + name + " is " + max_length + " characters.  You have entered " + (element.value).length + " characters.");
      element.focus();
      return false;
    }
    if (not_null && trim(element.value).length < 1) 
    {
      alert("The " + name + " is required.");
      element.focus();
      return false;
    }
    return true;
  }

  function check_input_number(element, name, max_magnitude, gt_zero, type) 
  {
    val = element.value;

    if (type == "integer") { num = parseInt(val); }
    else if (type == "decimal") { num = parseFloat(val); }

    if (isNaN(num))
    { 
      alert(name + " must be of type " + type);
      element.focus();
      return false; 
    }
    if (num != val) 
    { 
      alert(name + " must be of type " + type);
      element.focus();
      return false; 
    }
    if (num > max_magnitude || num < (-1 * max_magnitude))
    { 
      alert(name + " must have magnitude less than " + max_magnitude);
      element.focus();
      return false; 
    }
    if (num <= 0 && gt_zero)
    { 
      alert(name + " must be greater than zero.");
      element.focus();
      return false; 
    }
    
    return true;
  }

  function Make_Numeric(val)
  {
    var num = parseInt(val); 
    if (isNaN(num))
      { return 0; }
    if (num != val) 
      { return 0; }
    return num;
  }

  function Money(val) 
  {
    var num = parseFloat(val); 

    if (isNaN(num))
      { num = 0; }
    if (num != val) 
      { num = 0; }
    num = Math.round(num*100)/100
    num = "$" + num;

    var dot = num.indexOf(".");

    if (dot < 1) { num = num + ".00"; }
    else if (dot == (num.length-2)) { num = num + "0"; }
    else if (dot < (num.length-3)) { num = num.substring(0,dot+3); }

    return num;
  }

function Continent(country)
{
	if ((country == "DZ") || (country == "AO") ||  (country == "BJ") || (country == "BW") || 
		(country == "BF") || (country == "BI") || (country == "CM") || (country == "CV") || 
		(country == "CF") || (country == "KY") || (country == "TD") || (country == "KM") || 
		(country == "CG") || (country == "CI") || (country == "DJ") || (country == "EG") || 
		(country == "ER") || (country == "ET") || (country == "GA") || (country == "GM") || 
		(country == "GH") || (country == "GN") || (country == "KE") || (country == "LS") || 
		(country == "LR") || (country == "LY") || (country == "MG") || (country == "MW") || 
		(country == "MV") || (country == "ML") || (country == "MR") || (country == "MU") || 
		(country == "MA") || (country == "MZ") || (country == "NA") || (country == "NE") || 
		(country == "NG") || (country == "RW") || (country == "SN") || (country == "SC") || 
		(country == "SL") || (country == "SB") || (country == "SO") || (country == "ZA") || 
		(country == "SD") || (country == "SZ") || (country == "TZ") || (country == "TG") || 
		(country == "TN") || (country == "UG") || (country == "EH") || (country == "ZR") || 
		(country == "ZW"))
	{	cont = "AFR"; }

	else if ((country =="AL") || (country == "AD") || (country == "BA") || (country == "BG") ||
		(country == "HR") || (country == "CY") || (country == "CZ") || (country == "DK") ||
		(country == "EE") || (country == "FI") || (country == "FR") || (country == "GE") ||
		(country == "DE") || (country == "GI") || (country == "GR") || (country == "GL") ||
		(country == "BA") || (country == "HU") || (country == "IS") || (country == "IE") ||
		(country == "IL") || (country == "LV") || (country == "LI") || (country == "LT") ||
		(country == "LU") || (country == "MD") || (country == "MC") || (country == "MS") || 
		(country == "NL") || (country == "NO") || (country == "PL") || (country == "PT") || 
		(country == "RO") || (country == "RU") || (country == "SK") || (country == "SI") ||
		(country == "ES") || (country == "SE") || (country == "CH") || (country == "TR") ||
		(country == "TC") || (country == "UA") || (country == "GB") || (country == "VA") ||
		(country == "YU"))
	{	cont = "EUR"; }

	else
	{	cont = "OTHER"; }

	return cont;
}

  // All shipping is by EMS Speedpost/USPS Global Priority from Nairobi
  // $6.80 plus $3.30 for each additional sandal [shipped to Africa]
  // $7.70 plus $3.60 for each additional sandal [shipped within Europe]
  // $8.80 plus $4.50 for each additional sandal [shipped anywhere else]
  // NOTE there is a php version of this in inc_functions_cmd.php

  function Calculate_Shipping(qty,country)
  {
    cont = Continent(country);

	if (cont == "AFR") 
    {
      shipping = 6.8; 
      if (qty>1) { shipping = shipping + (qty-1)*3.3; } 
    }
    else if (cont == "EUR") 
    {
      shipping = 7.7; 
      if (qty>1) { shipping = shipping + (qty-1)*3.6; } 
    }
    else 
    {
      shipping = 8.8; 
      if (qty>1) { shipping = shipping + (qty-1)*4.5; } 
    }
    return Math.round(shipping*100)/100;
  }

  // There are no taxes EXCEPT for sales to be SHIPPED to Washington state, which are taxed at a 6.5% rate. 
  // (The rate should exclude shipping.)
  // NOTE there is a php version of this in inc_functions_cmd.php
// MM -- change 5/12/04 -- no taxes (shipping directly from Kenya)
  function Calculate_Tax(subtotal,country,state)
  {
    { tax = 0; } 
    return Math.round(tax*100)/100;
  }
	
