
var SCENE7_part1 = 'http://s7ondemand1.scene7.com/is/image/FilaOnline/';
var SCENE7_part2 = '?layer=comp&wid=405&hei=276&fmt=jpeg&qlt=94,0&op_sharpen=1&resMode=sharp&op_usm=0.0,0.0,0,0&iccEmbed=0';


function flipContent(TAB_ID) {

  for (k=0;k<tabs.length;k++) {
    if (tabs[k] == TAB_ID) {
      document.getElementById(tabs[k]).style.display = "block";
      document.getElementById(tabs[k] + '_link').className = 'big_link_on';
    } else {
      document.getElementById(tabs[k]).style.display = "none";
      document.getElementById(tabs[k] + '_link').className = 'big_link';
    }
    // end else
  }
// end for k
}
// end flipContent();

function trim(strToTrim) {
	while (strToTrim.substring(0,1) == ' ') {
		strToTrim = strToTrim.substring(1,strToTrim.length);
	}
	while (strToTrim.substring(strToTrim.length -1,strToTrim.length) == ' ') {
		strToTrim = strToTrim.substring(0,strToTrim.length - 1);
	}
	return strToTrim;
}

function ShowImg(ID) {

  var pulldown = '';
  var c_pulldown = ''; 

  current_style_color = ID;
 
// create the color dropdown
  c_pulldown = document.buy_form.prod_color;
  c_pulldown.options.length = 0;
	for (i=0;i<colors.length;i++) {
	if (colors[i][2].length > 17) {
	// make an abbreviated color listing
		var parts = colors[i][2].split('/');
		var abbrev = '';
		var max = parts.length;
		if (max > 4) {
			max = 4
		}
		for (j = 0 ; j < max; j++) {
			parts[j] = trim(parts[j]);
			if (parts[j].length > 3) {
				abbrev = abbrev + parts[j].substring(0,3);
			} else {
				abbrev = abbrev + parts[j];
			}
			if (j + 1 < max) {
				abbrev = abbrev + ' / ';
			}
		}
	  c_pulldown.options[i] = new Option(abbrev,colors[i][0]);
  } else {
	  c_pulldown.options[i] = new Option(colors[i][2],colors[i][0]);
  }

	if (colors[i][0] == ID) {
			setPrice(i);

// change the color name
  document.getElementById("color_header").innerHTML = '<h4>' + colors[i][2] + '</h4>';


    c_pulldown.options[i].selected = true;

// create the dropdown box
    if (colors[i][5].length == 0) {
        document.getElementById("buy_button").style.display = 'none';
        document.getElementById("quantity_hr").style.display = 'none';
        document.getElementById("quantity").style.display = 'none';
    } else {
        document.getElementById("buy_button").style.display = 'block';
        document.getElementById("quantity_hr").style.display = 'block';
        document.getElementById("quantity").style.display = 'block';
    }
	if (do_size_pulldown) {
      pulldown = document.buy_form.prod_size;
      pulldown.options.length = 0;
      if (colors[i][5].length == 0) {
        document.getElementById("size_pulldown_hr").style.display = 'none';
        document.getElementById("size_pulldown").style.display = 'none';
      } else {
        document.getElementById("size_pulldown_hr").style.display = 'block';
        document.getElementById("size_pulldown").style.display = 'block';
        if (do_multi_price) {
	      pulldown.options[0] = new Option('SELECT AMOUNT','');
	    } else {
	      pulldown.options[0] = new Option('SELECT SIZE','');
	    }
        for (k=0;k<colors[i][5].length;k++) {
          pulldown.options[k+1] = new Option(colors[i][5][k][0],colors[i][5][k][0]);
          // handle single size default selection
        } // end for k
      }
      
      
	      
    } else {
      if (colors[i][5].length == 0) {
    	document.buy_form.prod_size.value = '';
      } else {
    	document.buy_form.prod_size.value = colors[i][5][0][0];
      }
    }

// set product number
	if (do_multi_price) {
	  document.buy_form.bag_prod_number.value = current_product_id;
	} else {
	  document.getElementById("item_number").innerHTML = 'ITEM# ' + current_product_id + ' - ' + ID;
	 }
  document.buy_form.bag_prod_color.value = ID;

  
  // clear otu item number
  document.getElementById("inv_item").value = "";

// set current color
  cur_color = i;

    // handle the size
    if (do_size_pulldown) {
      if (colors[i][5].length == 1) {
        pulldown.options[1].selected = true;
        showSize(colors[i][5][0][0]);
      } else {
        // set default shipping message
  	    showSize('');
      }
    }

  
// change the image
  current_image_filename = colors[i][1];
  document.getElementById("product_detail_image").src = SCENE7_part1 + current_image_filename + SCENE7_part2;

// set the current color text
current_color_name = colors[i][2];

  }
// end if colors[i][0] == ID
}
// end for i

}
// end function ShowImg()

function showSize(SIZE) {
  if (!do_size_pulldown) {
    document.getElementById("inv_item").value = colors[cur_color][5][0][2];
  	return;
  }
   var found = false;
   var style_num =  null;
   var i = 0;
   var j = 0;
  for (i=0;i<colors[cur_color][5].length;i++) {
    if (colors[cur_color][5][i][0] == SIZE) {
      document.getElementById("stock_message").innerHTML = colors[cur_color][5][i][1];
      document.getElementById("inv_item").value = colors[cur_color][5][i][2];
      if (!do_multi_price) {
	    document.buy_form.bag_prod_size.value = SIZE;
      } else {
      	style_num = colors[cur_color][5][i][3];
      	for (j = 0; j <colors[cur_color][6].length; j++) {
      		if (colors[cur_color][6][j][0] == style_num) {
			 	document.getElementById("retail_price").innerHTML = colors[cur_color][6][j][1];
		      	document.getElementById("item_number").innerHTML = 'ITEM# ' + style_num + ' - 900';
				document.buy_form.bag_prod_number.value = style_num;
				document.buy_form.bag_prod_color.value = '900';
				document.buy_form.bag_prod_size.value = SIZE.substring(1,SIZE.length);
      		}
      	}
      }
      found = true;
    }
  }
  if (!found) {
    if (colors[cur_color][5].length == 0) {
	  document.getElementById("stock_message").innerHTML = "We're sorry, this item is no longer available.";
    } else {
	  document.getElementById("stock_message").innerHTML = "Select a size...";
	}
	document.getElementById("inv_item").value = "";
    if (do_multi_price) {
	  document.getElementById("item_number").innerHTML = "";
	  setPrice(cur_color);
	}
  }
  // end for i
}


function setPrice(cur_color) {

	var strikeout = '';
	var special_price = '';  

	if (colors[cur_color][4] != '') {
		// make first one strike out price
		strikeout = '<s>' + colors[cur_color][3] + '</s>';
		// make second one the special price
		special_price = ' &nbsp; <span class="color_price">' + colors[cur_color][4] + '</span>';
	} else {
		strikeout = colors[cur_color][3];
	}
 	document.getElementById("retail_price").innerHTML = strikeout + special_price;
 	
 }	


function AltView() {
  CURRENT_PATH = window.location.pathname;
  // see if it's a gift card
  checkgc =  /giftcard\/give/;
  CURRENT_PATH = CURRENT_PATH.replace(checkgc, "detail/giftcard");


  // see if the color code is in the path
  // and remove it
  checkre = /\/[0-9][0-9][0-9]$/;
  CURRENT_PATH = CURRENT_PATH.replace(checkre, "");

  // remove double slashes
  checksl = /\/\//;
  CURRENT_PATH = CURRENT_PATH.replace(checksl, "/");


  // replace detail with views
  // the details value
  re = /detail\//;
  CHANGED_PATH = CURRENT_PATH.replace(re, "views/");
  viewwin = window.open(CHANGED_PATH,"View_Win","width=580,height=500,scollbars=no");
  viewwin.focus();
}


// buy button form posting

function CheckForm(FORMNAME) {

    // did not select a size
    if (FORMNAME.prod_size.value == ""
    	&& do_size_pulldown) {
      alert ("Please select a size");
      FORMNAME.prod_size.focus();
      return false;
    }   
    if (document.getElementById("inv_item").value == "OUT") {
      alert ("This item is out of Stock");
      return false;
    }

    // package for ajax
    url = '/ajax/cart';
    poststring  = 'bagact=add';
    poststring += '&bag_prod_number=' + $('bag_prod_number').value;
    poststring += '&bag_prod_color='  + $('bag_prod_color').value;
    poststring += '&bag_prod_size='   + $('bag_prod_size').value;
    poststring += '&qty='             + $('qty').value;

	// populate gift message data from the other form
	if (document.getElementById("customization1") != null) {
		FORMNAME.customization1.value = document.getElementById("customization1").value;
		FORMNAME.customization2.value = document.getElementById("customization2").value;
		FORMNAME.customization3.value = document.getElementById("customization3").value;
    		poststring += '&customization1='  + $('customization1').value;
    		poststring += '&customization2='  + $('customization2').value;
    		poststring += '&customization3='  + $('customization3').value;
	}

    poststring += '&purchased_from='  + $('purchased_from').value;

    new Ajax.Request(url, { method: 'post', parameters: poststring, onSuccess: ShowLedger, onFailure: ShowFailure });
    return false;

}


function ShowLedger(OBJ) {
  if (OBJ != null) {
    success_message = OBJ.responseText;
    $('floating_ledger').innerHTML = success_message;
  } else {
    success_message = '';
  }

  Effect.toggle('floating_ledger_content','slide');
} // end function ShowLedger()

function ShowFailure(OBJ) {

//  failure_message  = '  <table>';
//  failure_message += '    <tr><td>Failed!</td></tr>';
//  failure_message += '    <tr><td><a href="" onclick="ShowFailure();return false" title="close">close</a></td></tr>';
//  failure_message += '  </table>';
  failure_message = OBJ.responseText;


  $('floating_ledger_content').innerHTML = failure_message;

  Effect.toggle('floating_ledger_content','slide');
  return false;
}


// email a friend

function EmailFriend(localeSignifier) {
  PRODURL = window.location.pathname;
  FORMURL = localeSignifier + '/email?productid=' + current_product_id + '&gender=' + current_gender + '&sport=' + current_sport;
  email_friend_win = window.open(FORMURL, 'friend_email', 'width=410,height=580,scrollbars=no');
  email_friend_win.focus();
}

