var shop_by_type = {'Brand':['A-Z','Z-A'],

					'Price':['Low to High','High to Low','Closeouts Only','Largest Savings'],

					'Color':['Black','Red','Blue','Silver/Grey','Green','Yellow','White','Multi','Other'],

					'Size':['XXS-XS','Small','Medium','Large','X-Large','XXL+']

					};



var timeHnd;

var sel_helper = {1:false,2:false};



function get_position(o) { 

	var pos = new Object;

	tmp = o;

	pos.left = tmp.offsetLeft;

	pos.top = tmp.offsetTop;

	while ((tmp=tmp.offsetParent) != null) {

		pos.left += tmp.offsetLeft;

		pos.top += tmp.offsetTop;

	}

	return (pos);

}



function shop_by() {

	disable_hide_shop();

	var o = document.getElementById("shop_by");

	o.style.backgroundColor = "#000";

//	o.style.border = "1px solid #505050";

	pos = get_position(o);

	var helper = document.getElementById("shop_by_helper1");

	helper.style.left = pos.left+"px";

	helper.style.top = (pos.top+30)+"px";

	var txt = '<div class="shop_by_helper" id="all" onmouseover="disable_hide_shop();hide_helper();" onmouseout="set_hide_shop()"><a href="#" onclick="set_shop_by(\'Show All\',\'Show All\')">&nbsp;&nbsp;&nbsp;Show All</a></div>';

	for (var i in shop_by_type) {

		txt += '<div class="shop_by_helper" id="'+i+'" onmouseover="disable_hide_shop();shop_by_helper(\''+i+'\',this)" onmouseout="set_hide_shop()"><a href="#"> + '+i+'</a></div>';

	}

	helper.innerHTML = txt;

	helper.style.display = "block";

}



function shop_by_helper(type,sender) {

	disable_hide_shop();

	if (sel_helper[1] != false)

		document.getElementById(sel_helper[1]).firstChild.style.color = "#fff";

	var txt = '';

	var o = document.getElementById('shop_by_helper2');

	sel_helper[1] = sender.id;

	sender.firstChild.style.color = "#ff700d";

	pos = get_position(sender);

	o.style.left = (pos.left-138) + "px";

	o.style.top = pos.top + "px";

	for (i in shop_by_type[type]) {

		txt += '<div class="shop_by_helper" onmouseover="disable_hide_shop()" onmouseout="set_hide_shop()"><a href="#" onclick="set_shop_by(\''+type+'\',\''+shop_by_type[type][i].replace( "'", "\\'")+'\')">'+shop_by_type[type][i]+'</a></div>';

	}

	o.innerHTML = txt;

	o.style.display = "block";

}



function set_shop_by(action,value) {

	document.getElementById("shop_by_action").value = action;

	document.getElementById("shop_by_value").value = value;

	document.getElementById("shop_by_form").submit();

	

}



function set_hide_shop(helper_id) {

	timeHnd = setTimeout("hide_shop_by()",400);

}



function disable_hide_shop() {

	clearTimeout(timeHnd);

}



function hide_helper() {

	document.getElementById("shop_by_helper2").style.display = "none";

	if (sel_helper[1] != false)

		document.getElementById(sel_helper[1]).firstChild.style.color = "#fff";

	sel_helper[1] = false;

}



function hide_shop_by() {

	document.getElementById("shop_by_helper1").style.display = "none";

	document.getElementById("shop_by_helper2").style.display = "none";

	document.getElementById("shop_by").style.borderWidth = "0";

	document.getElementById("shop_by").style.backgroundColor = "";

}







function search_clean_txt() {

	if (document.getElementById("form1_txt").value == "Start new Search") {

		document.getElementById("form1_txt").value = "";

	}

}



function search_set_txt() {

	if (document.getElementById("form1_txt").value == "") {

		document.getElementById("form1_txt").value = "Start new Search";

	}

}



function search_submit() {

	document.getElementById( "search_working").style.display = "block";

	value = document.getElementById("form1_txt").value;

	if (value != "") {

		value = value.replace(/[\/\\]/g," ");

		value = value.replace(/\s+/g,"_");

		//value = value.replace(/[%"'\.?&,:;]/g,"");
		// Allow periods in the url
		value = value.replace(/[%"'?&,:;]/g,"");

		window.location.href="/search/"+value;

	}

}



function MM_openBrWindow(theURL,winName,features) {  

  window.open(theURL,winName,features);

  return false;

}

function log_out(){
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm('Are you sure you want to log out?')){
		return true;
	}else{
		ht[0].style.filter = "";
		return false;
	}
}

function maitanance_cart(){
	window.location.href="http://www.motorcyclecloseouts.com/shopping_cart?expired=_++_";
}
