/* Power Bolt and Tool - Javascript
By Hutz! Media! 
December 02, 2009 - <hutzmedia.com>
*/

// Main/Home functions

function searchFocus(obj) {
	if (obj.value == "Enter Category" || obj.value == "Enter Manufacturer") {
		obj.value = "";
	}
	obj.className = "search";
}

function searchBlur(obj, s) {
	obj.className = "search blur";
	if (obj.value == "") {
		obj.value = s;
	}
}

function searchGoTo(section, objname) {

	var obj = document.getElementById(objname);

	if (obj.selectedIndex > 0) {
	
		var url = obj[obj.selectedIndex].value;
		location.href = url;
		return false;
		
	} else {
	
		return false;
	
	}

}

function searchKeyUp(objType) {
	var options = document.getElementById(objType + '_category').options;
	var search = document.getElementById(objType + '_search').value;
	
	if (search != "") {
	
		var s = 0; // selected
		var l = options.length;
		for (var i=l-1;i>=0;i--) {
			if (options[i].value != 0) {
			
				if (options[i].text.toLowerCase().indexOf(search.toLowerCase()) == 0) {
					options[i].selected = true;
				}
			
			}
		}
		
	}
	
	return true;
	
}

function keywordSearchFocus(obj) {

	obj.style.textAlign = "left";
	obj.style.color = "#000000";
	
	if (obj.value == "Enter Keyword(s)" || obj.value == "Enter Product ID or UPC") {
		obj.value = "";
	}
	
	return false;

}

function keywordSearchBlur(obj, s) {

	if (obj.value.replace(/^\s+|\s+$/g, "") == "") {
		obj.value = "";
		
		obj.style.textAlign = "right";
		obj.style.color = "#9D9C98";
		obj.value = s;
	}
	

}

/* Class: menu */
function menuClass(url) {
	this.images = new Array();
	this.url = url;
	this.addImage("home1.png", "home2.png");
	this.addImage("about1.png", "about2.png");
	this.addImage("products1.png", "products2.png");
	this.addImage("account1.png", "account2.png");
	this.addImage("list1.png", "list2.png");
	this.addImage("credit1.png", "credit2.png");
	this.addImage("rewards1.png", "rewards2.png");
	this.addImage("contact1.png", "contact2.png");
	this.addImage("quote1.png", "quote2.png");
}
menuClass.prototype.over = function(i, objImg) {
	objImg.src = this.images[i][1].src;
	return true;
}
menuClass.prototype.out = function(i, objImg) {
	objImg.src = this.images[i][0].src;
	return true;
}
menuClass.prototype.addImage = function(image1, image2) {
	var i = this.images.length;
	this.images[i] = [
			new Image(),
			new Image()
		];
		
	this.images[i][0].src = this.url + image1;
	this.images[i][1].src = this.url + image2;
}

var menu = new menuClass('/images/');


/* Tools Javascript Functions */
function goTo(url, e) {

	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
		
		
	if (targ.className != "itemImage" && targ.className != "imagePreview") {
		window.open(url, '_self');
	}
	
	return false;
}
function enlarge(objName, url) {
	var obj = document.getElementById("imagePreview_" + objName);
	obj.innerHTML = "<a href=\"#\" onclick=\"return reduce(" + objName + ");\"><img class=\"itemImage\" style=\"max-height: 420px;\" border=\"0\" src=\"" + url + "\" /></a>";
	obj.style.display = "block";
	return false;
}
function reduce(objName) {
	var obj = document.getElementById("imagePreview_" + objName);
	obj.style.display = "none";
	return false;
}

function fullImage(imgURL) {

	var obj = document.getElementById("imagePreview");
	
	var html = "";
	html = html + "<div style=\"text-align: right; padding: 4px;\">Click anywhere to Close [X]</div><div style=\"padding: 16px; padding-top: 6px;\">";
	html = html + "<a href=\"#\" onclick=\"return closeImage();\"><img src=\"" + imgURL + "\" alt=\"Large Image Loading...\" /></a>";
	html = html + "</div>";
	
	obj.innerHTML = html;
	obj.style.display = "block";
	
	obj.style.left = "0px";
	obj.style.top = "0px";
	
	return false;

}

function closeImage() {
	var obj = document.getElementById("imagePreview");
	obj.style.display = "none";
	
	return false;
}

