function check_qty (min, max) {

	if (min != false) {
		if (document.addtocart.quantity.value < min) {
			document.addtocart.quantity.value = min;
			alert ('The quantity you have entered is less than the minimum.\nThe quantity has been changed to ' + min + '.');
		}
	}

	if (max != false) {
		if (document.addtocart.quantity.value > max) {
			document.addtocart.quantity.value = max;
			alert ('The quantity you have entered is more than we have in stock.\nThe quantity has been changed to ' + max + '.');
		}
	}

}

function confirm_url (dog, cat) {

	confirm_box = confirm (cat);

	if (confirm_box == true) {

		location.href = dog;

	} else {

		location.href = location.href;

	}

}

function confirm_delete (dog, cat) {

	confirm_url (dog, "Warning: This will permanently delete this " + cat + ".\nDelete " + cat + "?");

}

function toggle_option (cat) {

	if (cat == 'select') {

		document.getElementById('on_price_row').style.display = 'none';
		document.getElementById('off_price_row').style.display = 'none';
		document.getElementById('options_row').style.display = '';

	} else {

		document.getElementById('on_price_row').style.display = '';
		document.getElementById('off_price_row').style.display = '';
		document.getElementById('options_row').style.display = 'none';

	}

	if (cat == 'yesno') {

		document.getElementById('initial_row').style.display = '';

	} else {

		document.getElementById('initial_row').style.display = 'none';

	}

	return false;

}

function switchImage (dog, cat, mouse) {

	document.getElementById(dog).src = cat;
	
	curimg_id = mouse;

	return false;

}

function gotoImage () {

	location.href = base + curimg_id;

}

function divsection (cat) {

	document.getElementById('dinfo').style.display = 'none';
	document.getElementById('dpricing').style.display = 'none';
	document.getElementById('doptions').style.display = 'none';
	document.getElementById('dimages').style.display = 'none';

	document.getElementById(cat).style.display = '';

}

function gotoid (cat, dog) {

	location.href = cat + document.getElementById(dog).value;
	return false;

}

function toggle (cat) {

	var div = document.getElementById (cat);

	div.style.display = (div.style.display == 'none') ? '' : 'none';

	return false;

}

function show (cat) {

	document.getElementById (cat).style.display = '';

	return false;

}


function addLoadEvent (func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload)
				oldonload ();
			func ();
		}
	}
}

function getElementsByClassName(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
  
function CountBack(myDiv, secs) {

  var DisplayStr = '';
  
  var days = ((Math.floor(secs/86400))%100000);
  if (days > 0) {
    DisplayStr = days.toString() + ' days ';
  }

  var hours = ((Math.floor(secs/3600))%24).toString();
  if (hours.length < 2)
    hours = "0" + hours;
  DisplayStr = DisplayStr + hours + ":";
  
  var minutes = ((Math.floor(secs/60))%60).toString();
  if (minutes.length < 2)
    minutes = "0" + minutes;
  DisplayStr = DisplayStr + minutes + ":";
  
  var seconds = ((Math.floor(secs/1))%60).toString();
  if (seconds.length < 2)
    seconds = "0" + seconds;
  DisplayStr = DisplayStr + seconds;

  DisplayStr = "Only " + DisplayStr + " remaining!";

  if(secs > 0) {	
  
    document.getElementById(myDiv).innerHTML = DisplayStr;
    setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ");", 990);
    
  } else {
    
    document.getElementById(myDiv).innerHTML = "Deal over";
    
  }

}

addLoadEvent(function () {

	var divs = getElementsByClassName("categories");
	for (var i = 0; i < divs.length; i++) {
		var div = divs[i];
		var links = div.getElementsByTagName("a");
		for (var j = 0; j < links.length; j++) {
			var link = links[j];
			if (document.location.href.substring(0, link.href.length) == link.href) {
				div.style.display = '';
			}
		}
	}

	var dates = getElementsByClassName("date-countdown");
	for (var i = 0; i < dates.length; i++) {

		var dthen = new Date(dates[i].title);
		var dnow = new Date();
		var ddiff = new Date(dthen-dnow);
		var gsecs = Math.floor(ddiff.valueOf()/1000);

		CountBack (dates[i].id, gsecs);

	}

});
