function fabricSearch() {
	var fabric_string = "";
	$(".checkbox").each(function() {
		if( $(this).attr('src') == '/images/buttonsnsuch/checkboxn.png' ) {
			fabric_string = fabric_string + "^" + $(this).attr('id');
		}
	});
	var hash;
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("safari") != -1 && window.location.hash.indexOf("%7C") != -1) {
		hash = window.location.hash.replace("#","").split("%7C");
	} else {
		hash = window.location.hash.replace("#","").split("|");
	}
	if(fabric_string != "") {
		window.location="#" + hash[0] + "|" + hash[1] + "|all|" + hash[3] + "|" + hash[4] + "|" + hash[5] + "|" + fabric_string;
	}
}

function keywordSearch() {
	var keyword = $("#keywordsearch").val();
	//var hash = window.location.hash.replace("#","").split("|");
        var hash;
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("safari") != -1 && window.location.hash.indexOf("%7C") != -1) {
		hash = window.location.hash.replace("#","").split("%7C");
	} else {
		hash = window.location.hash.replace("#","").split("|");
	}
        
        window.location="/search.php#|||||" + keyword;
}

function historyChange(newLocation, historyData) {
	restoreHistory(newLocation);
}

function restoreHistory(hash) {
	var history = new Array();
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("safari") != -1 && hash.indexOf("%7C") != -1) {
		history = hash.replace("#","").split("%7C");
	} else {
		history = hash.replace("#","").split("|");
	}
	
	//history = hash.split("|");
	
	if(hash == "featured" || hash == undefined || hash == "") {
		$("#searchresults").html("<p class='style6'>Thank you for creating an account with offthefloornow.com!<br />To begin browsing, please select a category to the left.</p>");
	} else {
		//alert("/ajax/loadthumbs.php?category=" + history[0] + "&company=" + history[1] + "&limit=" + history[2] + "&start=" + history[3] + "&sort=" + history[4]);
		showLoading();
		$("#searchresults").load("/ajax/loadthumbs.php?category=" + history[0] + "&company=" + history[1] + "&limit=" + history[2] + "&start=" + history[3] + "&sort=" + history[4] + "&keyword=" + history[5] + "&fabricstring=" + history[6]);
	}
}

function jumpToPage(page) {
	page = page - 1;
	//load up the current hash
	//var hash = window.location.hash.replace("#","").split("|");
	var hash;
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("safari") != -1 && window.location.hash.indexOf("%7C") != -1) {
		hash = window.location.hash.replace("#","").split("%7C");
	} else {
		hash = window.location.hash.replace("#","").split("|");
	}
	//alert("#" + hash[0] + "|" + hash[1] + "|" + hash[2] + "|" + page + "|" + hash[4] + "|" + hash[5]);
	window.location="#" + hash[0] + "|" + hash[1] + "||" + page + "|" + hash[4] + "|" + hash[5];
}

function setSort(sortType) {
	//var hash = window.location.hash.replace("#","").split("|");
	var hash;
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("safari") != -1 && window.location.hash.indexOf("%7C") != -1) {
		hash = window.location.hash.replace("#","").split("%7C");
	} else {
		hash = window.location.hash.replace("#","").split("|");
	}
	window.location="#" + hash[0] + "|" + hash[1] + "|" + hash[2] + "|" + hash[3] + "|" + sortType + "|" + hash[5];
}

function setShowAll(showAll) {
	//var hash = window.location.hash.replace("#","").split("|");
	var hash;
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("safari") != -1 && window.location.hash.indexOf("%7C") != -1) {
		hash = window.location.hash.replace("#","").split("%7C");
	} else {
		hash = window.location.hash.replace("#","").split("|");
	}
	window.location="#" + hash[0] + "|" + hash[1] + "|" + showAll + "||" + hash[4] + "|" + hash[5];
}

function showLoading() {
	$("#searchresults").html('<img src="/images/OffTheFloorNow-Animation_loader.gif" width="125" height="100" /><p class="searchresults">LOADING RESULTS...</p>');
}

function EnterPressed(e) {
  var characterCode;
  if(e && e.which) {
    e = e;
    characterCode = e.which;
  } else {
    e = event;
    characterCode = e.keyCode;
  }
  if (characterCode == 13) {
	 return true;
  } else {
	 return false;
  }
}

function setupDefaults() {
	$(".rollover_image").mouseover(function() {
		$(this).attr('src',$(this).attr('src').replace(/f.jpg/,"n.jpg"));
	});
	$(".rollover_image").mouseout(function() {
		$(this).attr('src',$(this).attr('src').replace(/n.jpg/,"f.jpg"));
	});
	$(".checkbox").click(function() {
        	($(this).attr('src') == '/images/buttonsnsuch/checkboxn.png' ) ? $(this).attr('src','/images/buttonsnsuch/checkboxf.png') : $(this).attr('src','/images/buttonsnsuch/checkboxn.png');
		if($(this).attr('store') != "") {
			var store = $(this).attr('store');
			var set = $(this).attr('set');
			$("#" + store).val(set);
		}
        });
        $(".radiobutton").click(function() {
		var currentSrc = $(this).attr('src');
        	var currentOption = $(this).attr('option');
		var selector = "img[option='" + currentOption + "']";
		var store = $(this).attr('store');
		var set = $(this).attr('set');
		$("#" + store).val(set);
		$(selector).attr('src','/images/buttonsnsuch/radio_f.png');
		$(this).attr('src','/images/buttonsnsuch/radio_n.png');
        });
}

function StartCountDown(myDiv,myTargetDate)
  {
    var dthen	= new Date(myTargetDate);
    var dnow	= new Date();
    ddiff		= new Date(dthen-dnow);
    gsecs		= Math.floor(ddiff.valueOf()/1000);
    CountBack(myDiv,gsecs);
  }
  
  function Calcage(secs, num1, num2)
  {
    s = ((Math.floor(secs/num1))%num2).toString();
    if(s.length < 2 && num2 == 60){
	 s = "0" + s;
    }
    return (s);
  }
  
  function CountBack(myDiv, secs)
  {
    var DisplayStr;
    var DisplayFormat = "Reserve Expires in %%H%%:%%M%%:%%S%%";
    DisplayStr = DisplayFormat.replace(/%%H%%/g,		parseInt(Calcage(secs,86400,100000)) * 24 + parseInt(Calcage(secs,3600,24)));
    DisplayStr = DisplayStr.replace(/%%M%%/g,		Calcage(secs,60,60));
    DisplayStr = DisplayStr.replace(/%%S%%/g,		Calcage(secs,1,60));
    if(secs > 0)
    {
      document.getElementById(myDiv).innerHTML = DisplayStr;
      setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ");", 990);
    }
    else
    {
      document.getElementById(myDiv).innerHTML = "Hold Released";
    }
  }

