// ---- Begin - set base url for accessing the MivaScript file that builds the XML (make sure to include the store code)
var baseurl = location.protocol + '//' + location.hostname + '/Merchant2/4.24/hcuajax.mvc?Store_Code=hcu&Screen=';
// ---- End - set base url for accessing the MivaScript file that builds the XML

      function handleHttpResponse() {
        if (http.readyState == 4) {
          if (http.responseText.indexOf('invalid') == -1) {

            // Use the XML DOM to unpack the city and state data 
            var xmlDocument = http.responseXML; 
            var basketcount = getInnerText(xmlDocument.getElementsByTagName('basketcount').item(0));
            var loggedin = getInnerText(xmlDocument.getElementsByTagName('loggedin').item(0));
            var firstname = getInnerText(xmlDocument.getElementsByTagName('firstname').item(0));
						if (loggedin == 1)
							document.getElementById('welcome').innerHTML = "Welcome Back, " + firstname + "!";
            isWorking = false;
          }
        }
      }

      var isWorking = false;
      function checkCart() {
        if (document.getElementById("ajax-screen"))
          var screenValue = document.getElementById("ajax-screen").innerHTML;
        else
          var screenValue = 'none';

        if (document.getElementById("ajax-ctgy"))
          var ctgyValue = document.getElementById("ajax-ctgy").innerHTML;
        else
          var ctgyValue = 'none';
					
        if (!isWorking && http) {
          fullurl = baseurl + escape(screenValue) + '&Category_Code=' + escape(ctgyValue);
          http.open("GET", fullurl, true);
          http.onreadystatechange = handleHttpResponse;
          isWorking = true;
          http.send(null);
        }
      }

      function getHTTPObject() {
        var xmlhttp;
        /*@cc_on
        @if (@_jscript_version >= 5)
          try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
            try {
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
              xmlhttp = false;
            }
          }
        @else
        xmlhttp = false;
        @end @*/
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
          try {
            xmlhttp = new XMLHttpRequest();
          } catch (e) {
            xmlhttp = false;
          }
        }
        return xmlhttp;
      }

// Helper function to return text (no tags) contained within a node
function getInnerText(node) { 
	if (typeof node.textContent != 'undefined') { 
		return node.textContent; 
	} 
	else if (typeof node.innerText != 'undefined') { 
		return node.innerText; 
	} 
	else if (typeof node.text != 'undefined') { 
		return node.text; 
	} 
	else { 
		switch (node.nodeType) { 
			case 3: 
			case 4: 
				return node.nodeValue; 
				break; 
			case 1: 
			case 11: 
				var innerText = ''; 
				for (var i = 0; i < node.childNodes.length; i++) { 
					innerText += getInnerText(node.childNodes[i]); 
				} 
				return innerText; 
				break; 
			default: 
				return ''; 
		} 
	} 
} 

// Helper function to return XML contained within a node
function serializeNode(node) { 
	if (typeof XMLSerializer != 'undefined') {
		return new XMLSerializer().serializeToString(node);
	}
	if (typeof node.xml != 'undefined') { 
		return node.xml; 
	} 
} 

var http = getHTTPObject(); // We create the HTTP Object
