
/* HELP HINTS */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	// repeat the same tests as above for selects
	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}
addLoadEvent(prepareInputsForHints);


/* AJAX DIV SWAPPING */

var http = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
} 

/* REPLACE FOR SELECTS */
function divReplace(loc,place) {
	if(navigator.appName == "Microsoft Internet Explorer") 
	{	
		var fileName = loc.value;
	  http.open("GET", fileName, true);
	  http.onreadystatechange=function() {
	    if(http.readyState == 4) {
	      document.getElementById(place).innerHTML = http.responseText;
	    }
	  }
	  http.send(null);
	  /*window.location.reload(false);*/
	}
	else
	{
		/*alert("Not Internet Explorer - " + loc.value);*/
		/*var fileName = loc.options[loc.selectedIndex].value;*/
		var fileName = loc.value;
	  http.open("GET", fileName, true);
	  http.onreadystatechange=function() {
	    if(http.readyState == 4) {
	      document.getElementById(place).innerHTML = http.responseText;
	    }
	  }
	  http.send(null);
	}
}


/* REPLACE FOR NON SELECTS */
function divAjaxReplace(loc,place) {
	if(document.getElementById("id_dcode")){
		//if we have the input element
		//append the input value as part of the query string
		//we can use server side scripting to evaluate the discount_code value
		loc = loc + "?discount_code=" + document.getElementById("id_dcode").value;
		//alert(loc);
	}
  http.open("GET", loc, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById(place).innerHTML = http.responseText;
    }
  }
  http.send(null);
}