function showRates(ratesForm, thisRate) {
//alert("domes_ground");
  for (var i=0; i<document.forms[ratesForm].elements.length; i++)  { 
    if (document.forms[ratesForm].elements[i].value == thisRate) {
       document.getElementById(thisRate).className='infotable';
       document.getElementById(thisRate+"_buttons").style.display = "block"; 
       document.forms[ratesForm].elements[i].checked = true;
       var expdate = new Date(); 
       expdate.setTime(expdate.getTime() + (1 * 5 * 60 * 1000)); 
       setCookie('fedex_newcustomer_service_'+ratesForm, thisRate, expdate); 
       //return true;
    } else {
       document.getElementById(document.forms[ratesForm].elements[i].value).className='infotablehidden';
       document.getElementById(document.forms[ratesForm].elements[i].value+"_buttons").style.display = "none"; 
       document.forms[ratesForm].elements[i].checked = false;
    }
  }
}

function init() {
  for(var i=1; i<document.forms.length; i++) {
    document.forms[i].elements[0].checked = true; 
  }
}

function initDeliveryOptions() {
  var content;
  if(getCookie("fedex_newcustomer_service_USandInternationalServices")!=null){
    content = getCookie("fedex_newcustomer_service_USandInternationalServices");
  }
  if (window.location.href.lastIndexOf("?content=")>=0) { 
    if(window.location.href.substr(window.location.href.lastIndexOf("content=") + 8) == "international" ||window.location.href.substr(window.location.href.lastIndexOf("content=") + 8) == "freight"){
      content = window.location.href.substr(window.location.href.lastIndexOf("content=") + 8); 
    }
  } 
  if(content!=null && (content == "international" || content == "freight")){
    showRates('USandInternationalServices', content);
  } else {
    init();
  }
}

var sampleRatesArray = new Array("SampleUSRates", "SampleInternationalRates");
var sampleRatesGroundArray = new Array("domes_ground", "inter_ground");
function initSampleRates() {
  var formContent = new Array(sampleRatesArray.length);
  for (i=0; i<sampleRatesArray.length; i++) {
    formContent[i] = getCookie("fedex_newcustomer_service_"+sampleRatesArray[i]);
  }
  if (window.location.href.lastIndexOf("?content=")>=0&&window.location.href.substr(window.location.href.lastIndexOf("content=") + 8)=="ground") {
    for (i=0; i<sampleRatesArray.length; i++) {
      formContent[i] = sampleRatesGroundArray[i];
    }
  }
  for (i=0; i<sampleRatesArray.length; i++) {
    if(formContent[i]!=null){
      showRates(sampleRatesArray[i], formContent[i]);
    } else {
      document.forms[sampleRatesArray[i]].elements[0].checked = true;
    }
  }  
}
function setCookie(name, value, expires, path, domain, secure){
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name){
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1){
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }  else{
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}