var ajaxReq;

function qfRefresh() {
   document.qf.submit();
}

function qfUpdate(i) {
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
	 else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
      if (i==1) { xmlhttp.open("GET","quickfind.php?flag=1&brand="+document.qf.qfBrand[document.qf.qfBrand.selectedIndex].text,false); }
      if (i==2) { xmlhttp.open("GET","quickfind.php?flag=2&brand="+document.qf.qfBrand[document.qf.qfBrand.selectedIndex].text+"&type="+document.qf.qfType[document.qf.qfType.selectedIndex].text,false); }
      xmlhttp.send(null);
      if (i==1) { document.getElementById("qfType_ID").innerHTML=xmlhttp.responseText; }
      if (i==2) { document.getElementById("qfProduct_ID").innerHTML=xmlhttp.responseText; }
}

function qfSubmit() {
gogo = new Array();
cnt = 0;
   if (document.qf.qfBrand[document.qf.qfBrand.selectedIndex].text != "" && document.qf.qfBrand[document.qf.qfBrand.selectedIndex].text != "--------" && document.qf.qfBrand[document.qf.qfBrand.selectedIndex].text != "Choose Brand") {
      gogo[cnt] = "brand="+document.qf.qfBrand[document.qf.qfBrand.selectedIndex].text;
      cnt++;
   }
   if (document.qf.qfType[document.qf.qfType.selectedIndex].text != "" && document.qf.qfType[document.qf.qfType.selectedIndex].text != "--------" && document.qf.qfType[document.qf.qfType.selectedIndex].text != "Choose Type") {
      gogo[cnt] = "category="+document.qf.qfType[document.qf.qfType.selectedIndex].text;
      cnt++;
   }
   if (document.qf.qfProduct[document.qf.qfProduct.selectedIndex].text != "" && document.qf.qfProduct[document.qf.qfProduct.selectedIndex].text != "--------" && document.qf.qfProduct[document.qf.qfProduct.selectedIndex].text != "Choose Product") {
      gogo[cnt] = "productNumber="+document.qf.qfProduct[document.qf.qfProduct.selectedIndex].text;
      cnt++;
   }
   
   yeah = "index.php?act=products";
   for (i=0; i<cnt; i++) {
      yeah = yeah + "&";
      yeah = yeah + gogo[i];
   }
   
   document.qf.action = yeah;
   document.qf.submit();
}

function actType() {
   if (ajaxReq.readyState==4) {
      document.getElementById("qfType_ID").innerHTML=ajaxReq.responseText;
   }
}

function actProduct() {
   if (ajaxReq.readyState==4) {
      document.getElementById("qfProduct_ID").innerHTML=ajaxReq.responseText;
   }
}

function getXMLHTTP() {
   if (window.XMLHttpRequest) {
      return new XMLHttpRequest();
   }
   if (window.ActiveXObject) {
      return new ActiveXObject("Microsoft.XMLHTTP");
   }
   return null;
}

function scrollToDiv(strDiv) {
   $('html, body').animate({scrollTop: $('#'+strDiv).offset().top}, 'slow');
}

function scrollToTop() {
   $('html, body').animate({scrollTop:0}, 'slow');
}

function toggleDiv(strDiv) {
   $("#"+strDiv).slideToggle("slow");
}

function sortProductListing(strSort,strSortBy) {
   if (strSort == "ASC") {
      strSort = "DESC";
   } else {
      strSort = "ASC";
   }
   document.productList.action = document.productList.action+"&sort="+strSort+"&sortby="+strSortBy;
   document.productList.submit();
}

function qtyStuff() {
   price = document.getElementById("thepriceqty").innerHTML;
   qty = parseInt(document.getElementById("qty").value);
   total = price * qty;
   total = total.toFixed(2);
   if (qty > 1) {
      document.getElementById("qtyTotal").style.visibility = "visible";
      document.getElementById("qtyTotal").innerHTML = " = $" + total;
   } else {
      document.getElementById("qtyTotal").style.visibility = "hidden";
      document.getElementById("qtyTotal").innerHTML = "";
   }
}
