function go(form) {
   window.location = form.range.options[form.range.selectedIndex].value;

}
   
function preload_images () {
   var d = document;
	 if (!d.imgs) { d.imgs = new Array(); }
	 var j = d.imgs.length, args = preload_images.arguments, i;
	 for (i = 0; i < args.length; i++) {
		  d.imgs[j] = new Image;
			d.imgs[j].src = args[i];
			j++;
	 }
}


 function bookmark(title)
 {

   var urlAddress = location.href;
   var pageName = title;
   var browser = navigator.appName;

  if (browser == 'Microsoft Internet Explorer')
  {
     window.external.AddFavorite(urlAddress,pageName)
  }
  else if (browser == 'Netscape')
  { 
     alert("Your browser does not support this feature.  Use CTRL-D to bookmark this page");
  }
  else
  { 
   alert("Your browser does not support this feature.");
  }
 }

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Function added in lieu of cart.js - MS::NHS::20100824
function showFields(item,i,fields,args) {
  if(item.checked == true) { // Just in case.
    if(args != '' && args.length == 3) {
      // Form errored, extra fields were passed in:
      var savedCountry = args[0];
      var savedState = args[1];
      var savedZip = args[2];
    }
    if(fields == 'shipping') {
      sFieldName = 's_state'+i;
      cFieldName = 's_country'+i;
      zFieldName = 's_zip'+i;
    } else if(fields == 'member') {
      sFieldName = 'state';
      cFieldName = 'country';
      zFieldName = 'zip';
    } else {
      sFieldName = 'billing_state';
      cFieldName = 'billing_country';
      zFieldName = 'billing_zip';
    }
    if(item.value == 'dom') { // Domestic Options
      document.getElementById('stateCaption'+i).innerHTML = '<font color="#CC0000">*</font> State:';
      var statesField = '<select name="'+sFieldName+'" class="formtext" id="sStateField'+i+'">';
      for(var x=0,n=arStates.length;x<n;x++) {
        statesField += arStates[x]+'\n';
      }
      statesField += '</select>';
      document.getElementById('stateField'+i).innerHTML = statesField;
      if(typeof savedState != 'undefined') {
        document.getElementById('sStateField'+i).value = savedState;
        if(savedState == '') {
          document.getElementById('stateField'+i).innerHTML += ' <font color="#ff0000"><b>X</b></font>';
        }
      }
      document.getElementById('countryCaption'+i).innerHTML = '';
      document.getElementById('countryField'+i).innerHTML = '<input type="hidden" name="'+cFieldName+'" id="'+cFieldName+'" value="United States" />';
      if(typeof savedCountry != 'undefined') {
        var timeout = i * 500;
        setTimeout("getInfo('limit_shipping_method','Shipping_Class','limitMethods',document.getElementById('"+cFieldName+"'))",timeout);
      } else {
        getInfo('limit_shipping_method','Shipping_Class','limitMethods',document.getElementById(cFieldName));
      }
    } else {
      document.getElementById('stateCaption'+i).innerHTML = '<font color="#CC0000">*</font> Province:';
      document.getElementById('stateField'+i).innerHTML = '<input type="text" name="'+sFieldName+'" class="formtext" size="30" id="sStateField'+i+'">\n<input type="hidden" name="uk" value="y">';
      if(typeof savedState != 'undefined') {
        document.getElementById('sStateField'+i).value = savedState;
        if(savedState == '') {
          document.getElementById('stateField'+i).innerHTML += ' <font color="#ff0000"><b>X</b></font>';
        }
      }
      document.getElementById('countryCaption'+i).innerHTML = '<font color="#CC0000">*</font> Country:';
      var countryField = '<select name="'+cFieldName+'" class="formtext" id="sCountryField'+i+'" onchange="getInfo(\'limit_shipping_method\',\'Shipping_Class\',\'limitMethods\',this);">';
      for(var x=0,n=arCountries.length;x<n;x++) {
        countryField += arCountries[x]+'\n';
      }
      countryField += '</select>\n';
      document.getElementById('countryField'+i).innerHTML = countryField;
      if(typeof savedCountry != 'undefined') {
        document.getElementById('sCountryField'+i).value = savedCountry;
        var timeout = i * 500;
        setTimeout("getInfo('limit_shipping_method','Shipping_Class','limitMethods',document.getElementById('sCountryField"+i+"'))",timeout);
        if(savedCountry == '') {
          document.getElementById('countryField'+i).innerHTML += ' <font color="#ff0000"><b>X</b></font>';
        }
      }
    }
    document.getElementById('zipCaption'+i).innerHTML = '<font color="#CC0000">*</font> Zip/Postal Code:';
    document.getElementById('zipField'+i).innerHTML = '<input type="text" name="'+zFieldName+'" size="15" maxlength="15" class="formtext" id="sZipField'+i+'">';    if(typeof savedZip != 'undefined') {
      document.getElementById('sZipField'+i).value = savedZip;
      if(savedZip == '') {
        document.getElementById('zipField'+i).innerHTML += ' <font color="#ff0000"><b>X</b></font>';
      }
    }
  }
}

// Functions from aj.js - MS::NHS::20100824
function XMLHttpObj() {
  var xmlHttp = false;
  var theType = false;
  var theParams = false;

  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHttp");
    } catch (e) {
      try {
        xmlHttp=new ActiveXObject("Microsoft.XMLHttp");
      } catch (e) {
        // no workie
      }
    }
  }
  return xmlHttp;
}

/******************************************
 * AJAX FUNCTIONS
 ******************************************/

function getInfo(typ,theclass,func,params) {
  theType = typ;  // type of request so this can be used for more than one thing
  theParams = params;  // parameters for function call,other info
  // request dynamic information
  switch (typ) {
  case 'refined':
    var url = "/services/ajax/get_info.php?keywords="+params.value+"&class="+theclass+"&function="+func; 
    break;
  case 'limit_shipping_method':
    var url = "/services/ajax/get_info.php?keywords="+params.value+"&class="+theclass+"&function="+func; 
    break;
  case 'suggested_search':
    var url = "/services/ajax/get_info.php?keywords="+params.value+"&class="+theclass+"&function="+func; 
    break;
  }

  // call server
  XMLCall = new XMLHttpObj;
  XMLCall.open("GET",url,true);
  XMLCall.onreadystatechange = checkReadyState;
  XMLCall.send(null);
}

function checkReadyState() {
  // wait for server response
  if (XMLCall.readyState==4) {
    // ready to do stuff
    response = XMLCall.responseText;
    switch (theType) {
    case 'refined':
      refinedSearch(response);
      break;
    case 'limit_shipping_method':
      limitShippingMethods(response);
      break;
    case 'suggested_search':
      suggestedSearch(response);
      break;
    }
    delete XMLCall;
  }
}

/******************************************
 * SITE FUNCTIONS
 ******************************************/

function refinedSearch(response) {
  // get the next field name
  var get_id = theParams.name.split('_');

  if (response != '') {
    var id = get_id[0]+'_'+get_id[1]+'_'+get_id[2]+'_'+(parseInt(get_id[3])+1);
    var select_box = document.getElementById(id);
    var new_options = response.split('\|');

    // clear the current options except for the title
    if (select_box.options.length > 0) { 
      for(var i=1;i<select_box.options.length;i=1) { 
        select_box.options[i] = null; 
      }
    }

    // add the new options 
    var len = new_options.length;
    for (var i=0;i<len;i++) {
      var opts = new_options[i].split('::');
      if (typeof opts[0] != 'undefined' && typeof opts[1] != 'undefined') {
        select_box.options[select_box.options.length] = new Option(opts[1],opts[0],false,false);
      }
    }
    // enable the select box
    select_box.disabled = false;
  } else {
    // forward to category or prod detail list
    window.location = '/search_redirect/'+theParams.value+'/f';
  }
}

function limitShippingMethods(response) {
  // find the name for the method selection
  var method_id = theParams.name.replace('country','method');

  // get the method selection information and current value
  if (typeof document.getElementById(method_id) == 'undefined' || document.getElementById(method_id) == null) {
    return false;
  }
  var select_box = document.getElementById(method_id);
  var selected = select_box.value;

  // clear the current options except for the title
  if (select_box.options.length > 0) { 
    for(var i=0;i<select_box.options.length;i=0) { 
      select_box.options[i] = null; 
    }
  }

  // add the new options 
  var new_options = response.split('\|');
  var len = new_options.length;
  for (var i=0;i<len;i++) {
    var opt = new_options[i];
    if (typeof opt != 'undefined') {
      var sel = false;
      if (selected == opt) {
        sel = true;
      }
      select_box.options[select_box.options.length] = new Option(opt,opt,false,sel);
    }
  }
}

function suggestedSearch(response) {
  // clear the current values of suggestion box
  var suggest_box = document.getElementById('suggestions');
  document.getElementById('suggestions').className = '';
  suggest_box.innerHTML = '';

  // get the suggested search vars
  if (response != '') {
    document.getElementById('suggestions').className = 'suggestions';
    var suggestions = response.split('\|');

    // add new options to suggestion box
    for(var i=0;i<suggestions.length;i++) {
      var suggestion = '<div class="suggestion" id="suggestion_' + i + '" onMouseOver="javascript:suggestedSearchField(this,\'over\');" onMouseOut="javascript:suggestedSearchField(this,\'out\');" onClick="javascript:suggestedSearchField(this,\'click\');">' + suggestions[i] + '</div>';
      suggest_box.innerHTML += suggestion;
    }
  }
}
