var req;
var section2;
var section;

function changeLink(selId, linkId) {
	document.getElementById(linkId).href = document.getElementById(selId).value;
}

function loadXMLDoc(url,div) {
	
	section = div;

   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("POST", url, true);
      req.send(null);
   }
}

function clearDiv(div1,div2) {
	div1.innerHTML = "";
	div2.innerHTML = "";
	
}

function refreshAndLoad(url,div,url2,div2) {
	section = div;
	section2 = div2;

   // Internet Explorer - Thread 1
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }
   
   // Internet Explorer - Thread 2
   try { req2 = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req2 = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req2 = null; }
   }

   // Mozailla/Safari - Thread 2
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }
   
   // Mozailla/Safari - Thread 2
   if (!req2 && typeof XMLHttpRequest != "undefined") { req2 = new XMLHttpRequest(); }


   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
   
   // Call the processChange() function when the page has loaded
   if (req2 != null) {
      req2.onreadystatechange = processChange2;
      req2.open("GET", url2, true);
      req2.send(null);
   }
}

function processChange() {
	
   // The page has loaded and the HTTP status code is 200 OK
   if (req.readyState == 4 && req.status == 200) {

      // Write the contents of this URL to the searchResult layer
      getObject(section).innerHTML = req.responseText;
	}
}

function processChange2() {
	
   // The page has loaded and the HTTP status code is 200 OK
   if (req2.readyState == 4 && req2.status == 200) {

      // Write the contents of this URL to the searchResult layer
      getObject(section2).innerHTML = req2.responseText;
	}
}


function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name); 
   return false;
}

function get(obj) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
			if (obj.childNodes[i].type == "hidden") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         
      }
	  
	  var url = 'miniCart.php';
	  url += getstr;
	  url += 'insert=1';
	  //url += '&number=';
	  
	  //basket.innerHTML = url;
      loadXMLDoc(url, 'basket');
   }
   
   function email(obj) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
			if (obj.childNodes[i].type == "hidden") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         
      }
	  
	  var url = 'email.php';
	  url += getstr;
	  
	  //response.innerHTML = url;
      loadXMLDoc(url, 'response');
   }
   
   function validate_form ( )
			{
				valid = true;
			
					if ( document.frmEmail.Name.value == "" )
					{
							alert ( "Please fill in the 'Full Name' box." );
							valid = false;
					}
					if ( document.frmEmail.EmailAddress.value == "" )
					{
							alert ( "Please fill in the 'Email' box." );
							valid = false;
					}
					if ( document.frmEmail.Message.value == "" )
					{
							alert ( "Please fill in the 'Enquiry' box." );
							valid = false;
					}
					return valid;
			}