function toggleDisplay(i,j,L) {
	for (var x = 0; x < j; x++) {
    	element = document.getElementById(L+x).style;
    	x == i ? element.display = 'block' : 
			element.display='none';
    }
}

function dropDown(i,j) {
	element = document.getElementById(i).style;
    element.display = 'block';
    element = document.getElementById(j).style;
    element.display = 'none';
}

function turnOff(i) {
	element = document.getElementById(i).style;
    element.display = 'none';
}

function turnOn(i) {
	element = document.getElementById(i).style;
    element.display = 'block';
}

function changeBox(i,DPID,other) {
	element = document.getElementById('InfoBox').style;
    element.borderColor = '#000000';
    element = document.getElementById('InfoL').style;
    element.backgroundColor = '#000000';
    element = document.getElementById('InfoR').style;
    element.backgroundColor = '#000000';
    element = document.getElementById('InfoTop').style;
    element.display = 'block';
    element = document.getElementById('GreyLine').style;
    element.display = 'block';
    getTab(i,DPID,other);
}

function changeBoxSimple() {
	element = document.getElementById('InfoBox').style;
    element.borderColor = '#000000';
    element = document.getElementById('InfoL').style;
    element.backgroundColor = '#000000';
    element = document.getElementById('InfoR').style;
    element.backgroundColor = '#000000';
    element = document.getElementById('InfoTop').style;
    element.display = 'block';
    element = document.getElementById('GreyLine').style;
    element.display = 'block';
}

function getCart(ErrorURL,DPID) {
  var http = false;

  if(navigator.appName == "Microsoft Internet Explorer") {
    http = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    http = new XMLHttpRequest();
  }
  http.abort();
  http.open("GET", "/includes/naughty/products/ProductTab.php?tab=11&DPID=" + DPID + "&rand=" + Date() + Math.random(), true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      if (http.responseText == "NOCOOKIES") {
      	window.location=ErrorURL;
      }
      var clist=http.responseText.split("_");
      document.getElementById('ShippingText').innerHTML = clist[1];
    }
  }
  http.send(null);
}

function newCartItem(DPID) {
  var http = false;

  if(navigator.appName == "Microsoft Internet Explorer") {
    http = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    http = new XMLHttpRequest();
  }
  Quantity = document.getElementById('ProductQuantity').value; 
  http.abort();
  http.open("GET", "/includes/naughty/products/ProductTab.php?tab=10&Quantity=" + Quantity + "&DPID=" + DPID + "&rand=" + Date() + Math.random(), true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      var clist=http.responseText.split("_");
      document.getElementById('CheckoutButton').style.display = 'block';
      document.getElementById('Cart1').innerText = clist[0];
      document.getElementById('Cart1').textContent = clist[0];
      document.getElementById('Cart2').innerHTML = clist[0];
      document.getElementById('ShippingText').innerHTML = clist[1];
      toggleDisplay(5,7,'B');
      toggleDisplay(5,7,'BI');
      changeBox(5,DPID,'');
    }
  }
  http.send(null);
}

function newCouponItem(DPID) {
  var http = false;

  if(navigator.appName == "Microsoft Internet Explorer") {
    http = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    http = new XMLHttpRequest();
  }
  Code = document.getElementById('Coupon').value; 
  http.abort();
  http.open("GET", "/includes/naughty/products/ProductTab.php?tab=12&DCID=" + Code + "&rand=" + Date() + Math.random(), true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      if (http.responseText.length>0) {
        document.getElementById('CouponError').innerHTML = http.responseText;
      } else {
        toggleDisplay(5,6,'B');
        toggleDisplay(5,6,'BI');
        changeBox(5,DPID,'');
      }
    }
  }
  http.send(null);
}

function deleteCouponItem(Code,DPID) {
  var http = false;

  if(navigator.appName == "Microsoft Internet Explorer") {
    http = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    http = new XMLHttpRequest();
  }
  http.abort();
  http.open("GET", "/includes/naughty/products/ProductTab.php?tab=13&DCID=" + Code + "&rand=" + Date() + Math.random(), true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      toggleDisplay(5,6,'B');
      toggleDisplay(5,6,'BI');
      changeBox(5,DPID,'');
    }
  }
  http.send(null);
}

function getTab(i,DPID,other) {
  document.getElementById('InfoBox').innerHTML = "<div style=\"text-align:center; padding:10px;\"><img src=\"/images/naughty/products/wait22.gif\" width=\"22\" height=\"22\" alt=\"\" /></div>";
	
  var http = false;

  if(navigator.appName == "Microsoft Internet Explorer") {
    http = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    http = new XMLHttpRequest();
  }
  http.abort();
  if (i==5 || i==3) {
  	http.open("GET", "/includes/naughty/products/ProductTab.php?tab=" + i + "&DPID=" + DPID + other + "&rand=" + Date() + Math.random(), true);
  }
  else {
  	http.open("GET", "/includes/naughty/products/ProductTab.php?tab=" + i + "&DPID=" + DPID + other, true);
  }
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      if (i==3) {
        var clist=http.responseText.split("_");
        document.getElementById('InfoBox').innerHTML = clist[0];
        document.getElementById('ShippingText').innerHTML = clist[1];
	  }
	  else {   
      	document.getElementById('InfoBox').innerHTML = http.responseText;
      }
    }
  }
  http.send(null);
}

function searchResults(p) {
	getTab(4,0,"&page="+p+"&Terms="+document.getElementById('SearchQuery').value);
}

function continueSearchResults(p,t) {
	getTab(4,0,"&page="+p+"&Terms="+t);
}

function continueSearchResultsNew(p,t) {
    toggleDisplay(4,6,'B');
    toggleDisplay(4,6,'BI');
	getTab(4,0,"&page="+p+"&Terms="+t);
}

function continueRecommendations(d,n,p) {
	getTab(1,0,"&Page="+p+"&DPID="+d+"&DPIDName="+n);
}

function deleteQuantity(DPID,CDPID) {
	document.getElementById('QuantityUpdate'+DPID).value = 0;
	updateQuantity(DPID,CDPID);
}

function updateQuantity(DPID,CDPID) {
  var http = false;

  if(navigator.appName == "Microsoft Internet Explorer") {
    http = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    http = new XMLHttpRequest();
  }
  Quantity = document.getElementById('QuantityUpdate'+DPID).value;
  http.abort();
  http.open("GET", "/includes/naughty/products/ProductTab.php?tab=10&Update=1&Quantity=" + Quantity + "&DPID=" + DPID + "&CDPID=" + CDPID + "&rand=" + Date() + Math.random(), true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      var clist=http.responseText.split("_");
      document.getElementById('Cart1').innerText = clist[0];
      if(clist[0]=='Cart (0 Items)') {
      	document.getElementById('CheckoutButton').style.display = 'none';
      }
      document.getElementById('Cart1').textContent = clist[0];
      document.getElementById('Cart2').innerHTML = clist[0];
      document.getElementById('ShippingText').innerHTML = clist[1];
      toggleDisplay(5,6,'B');
      toggleDisplay(5,6,'BI');
      changeBox(5,CDPID,'');
    }
  }
  http.send(null);
}

function updateZip(DPID) {
	getTab(3,DPID,"&zip="+document.getElementById('ZipCode').value);
}

function highlightRating(i) {
	for (var x = 1; x <= i; x++) {
    	element = document.getElementById("R"+x).src="/images/naughty/products/ratingplus.gif";
    }
}
function clearRating() {
	for (var x = 1; x <= 5; x++) {
    	element = document.getElementById("R"+x).src="/images/naughty/products/ratingadd.gif";
    }
}