// JavaScript Document

//--><!--function to open image window for full view-->
function openPopWin(image){
    window.open(image,'runner','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=520,height=415,top=80,left=120');
}//-->

//--><!--function to open info window for full view--> 
function openInfoWin(image){
    window.open(image,'runner','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=335,height=150,top=300,left=340');
}//-->

//--><!--function to change location based on menu selection--> 
function MM_jumpMenu(targ,selObj,restore){
   if (selObj.options[selObj.selectedIndex].value==""){
  	if (restore) selObj.selectedIndex=0;
   }else{
  	//eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  	eval("self.location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
 }
}//-->

//--><!--function to change location based on menu selection-->
function goToLocation(destination) {
    location = destination; 
}//-->

//--><!--function to select all items availble for a given form item-->
function selectAllItemsInListbox() {
	for ( i=0;
		  i<document.form.email_to.options.length;
		  i++){
      document.form.email_to.options[i].selected = true;
      }
}//-->

//--><!--function to deselect all items availble for a given form item-->
function deselectAllItemsInListbox() {
  for ( i=0;
		  i<document.form.email_to.options.length;
		  i++){
      document.form.email_to.options[i].selected = false;
      }
}//-->

//--><!--function to change the order value if paypal payment selected-->
function updateOrderValue() {
	if (document.form.order_payment_method.value == "2") {
		var paypalValue = ((document.form.order_payment.value - ((document.form.order_payment.value / 100) * 3.4)) - 0.20) ;
    document.form.order_value.value = paypalValue.toFixed(2);
	}else{
    document.form.order_value.value = document.form.order_payment.value;
  }
}//-->

//--><!--functions to hide and reveal subcategory lists based on main category selection-->
function dynamicSelect(id1, id2) {
     if (document.getElementById && document.getElementsByTagName) {
         var sel1 = document.getElementById(id1);
         var sel2 = document.getElementById(id2);
         var clone = sel2.cloneNode(true);
         var clonedOptions = clone.getElementsByTagName("option");

         refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
         sel1.onchange = function() {
            refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
        };
    }
 }

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
     while (sel2.options.length) {
        sel2.remove(0);
    }
    
    if (sel1.options[sel1.selectedIndex].value == "") {
      document.form.product_subcategory.disabled = true;
    }else{
      document.form.product_subcategory.disabled = false;
    }
    
     var pattern1 = /( |^)(select)( |$)/;
     var pattern2 = new RegExp("( |^)(" +
          sel1.options[sel1.selectedIndex].value + ")( |$)");
     for (var i = 0; i < clonedOptions.length; i++) {
        if (clonedOptions[i].className.match(pattern1) ||
              clonedOptions[i].className.match(pattern2)) {
            sel2.appendChild(clonedOptions[i].cloneNode(true));
         }
   }
}// -->

//--><!--functions to hide and reveal stock level based on product_size selected-->
function revealContent(idParam,selObj) {
var string_array = selObj.options[selObj.selectedIndex].value.split("/");
var size_id = string_array[0];
var size = string_array[1];

document.getElementById(idParam + '/product_size_id').value=size_id;

	if(document.getElementById(idParam + '/' + size).style.display == "none") {
 		for (var i=0; i<selObj.length; i++){              
              var string_array_in_loop = selObj.options[i].value.split("/");
              var sizeInLoop = string_array_in_loop[1];
  	        	document.getElementById(idParam + '/' + sizeInLoop).style.display = "none";
 		}
    document.getElementById(idParam + '/' + size).style.display = "";
	}
}
//-->

//--><!--Simple JavaScript form submission function-->
function redirect ( product_qty, product_size_id, product_size, product_name )
{
 var destination="updateCartLineQty.do?product_qty=" + product_qty + "&product_size_id=" + product_size_id + "&product_size=" + product_size + "&product_name=" + product_name;
 location = destination; 
 }
//-->

//--><!--JavaScript bookmark function-->
function addToFavorites(urlAddress,pageName) { 
  if (window.external) { window.external.AddFavorite(urlAddress,pageName) 
  } else { alert("Sorry, your browser doesn't support this function."); 
  } 
} 
// -->

//--><!--JavaScript function to add line of dashes to notes field -->
function addLine() {
	var newtext =  "---------------------------------------------------------\n" + document.form.notes.value;	
  document.form.notes.value = "";
	document.form.notes.value = newtext;
}
// -->