// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Dynamic Help toolkit
var answers = new Array();
var seeMoreLinks = new Array();
var shownAnswer = -1;
var isSafari = navigator.userAgent.indexOf("Safari") > -1 || navigator.userAgent.indexOf("AppleWebKit") > -1;

function showInlineAnswer(whichOne) {
	if (shownAnswer != -1) {
    	var oldanswer = document.getElementById("faq" + shownAnswer + "a");    
    	oldanswer.style.backgroundColor   = "#FFFFEE";
    	oldanswer.innerHTML = seeMoreLinks[shownAnswer];
	}
	var answer = document.getElementById("faq" + whichOne + "a");
    new Effect.Highlight('faq0a');
	answer.style.backgroundColor   = "#FEFEC0";
	answer.innerHTML = answers[whichOne];
	shownAnswer = whichOne;
}

function switchText(obj, text1, text2) {
    if (document.getElementById(obj).innerHTML == text1) {
        document.getElementById(obj).innerHTML = text2;
    } else {
        document.getElementById(obj).innerHTML = text1;
    }
}

// set the radio button with the given value as being checked.
//  do nothing if there are no radio buttons.
// if the given value does not exist, all the radio buttons.
//  are reset to unchecked.
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

// shows/hides an element
function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
      e.style.display = 'none';
   else
      e.style.display = 'block';
}

// if we're doing international shipping, then we need to hide the state dropdown and show a freetext
function display_international_shipping_fields(country) {
   var internationalShipping = document.getElementById("international_shipping");
   var domesticShipping = document.getElementById("domestic_shipping");

   if (country.value == "" || country.value == "US" || country.value == "CA") {
     domesticShipping.style.display = 'block';
     internationalShipping.style.display = 'none';
   }
   else {
     domesticShipping.style.display = 'none';
     internationalShipping.style.display = 'block';
   }
}
