var xmlhttp
thehost = window.location.hostname;

// hideTopSearchBar();
// function hideTopSearchBar(){
	// document.getElementById("livesearch").style.display="none";
// }

function showHint(str)
{
	document.getElementById("livesearch").style.display="block";
	document.getElementById("livesearch").style.visibility="visible";
	
	if (str.length==0)
	{
		document.getElementById("livesearch").innerHTML = "<div id=\"topsearchhintbar\"><h3 style=\"font:18pt arial;padding:0px;margin:0px;\">Helpful Search Tips</h3><br><font style=\"font-size:10pt;color:green;\">Important: Use <u>commas</u> to separate your values!</font><br><br><font style=\"font-size:10pt;\"><strong style=\"font-size:12pt;color:blue;\">Here Is An Example To Help You Out</strong><br><br>Brand - Finish - Hardware Search: <strong>Liberty, Stainless Steel, Pull</strong></font><br><br><center style=\"padding-top:10px\"><a href=\"#\" onclick=\"hidesearch();\" style=\"color:red\">Hide This Box</a></center></div>";
		return;
	}
	xmlhttp=GetXmlHttpObjectAdvanced();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	document.getElementById("livesearch").innerHTML = "<div id=\"topsearchhintbar\"><img src=\"http://" + thehost +"/images/ajax-loader.gif\" border=\"0\"></td><td valign=\"middle\" style=\"padding-top:10px;padding-left:10px;padding-bottom:10px;\">Searching...</div>";
	var url= "http://" + thehost + "/search_hint.php";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
/* ech */
function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObjectAdvanced()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}


// show finishes from finish page
function showFinishes(str)
{
	document.getElementById("finishresults").innerHTML="";
	document.getElementById("finishheader").innerHTML = "Finish Category: <u>" + str + "</u>";
	if (str.length==0)
	{
	return;
	}
	xmlhttp=GetXmlHttpObjectFinishGuide();
	if (xmlhttp==null)
	{
	alert ("Your browser does not support XMLHTTP!");
	return;
	}
	document.getElementById("finishresults").innerHTML="<table style=\"font:12pt arial;color:green;\"><tr><td valign=\"top\" width=\"100\"><img src=\"http://" + thehost +"/images/finish-loader.gif\" border=\"0\"></td><td valign=\"middle\" style=\"padding-top:10px;padding-left:10px;padding-bottom:10px;\">Loading Your Selected Finishes...<br>We Have Thousands of Beautiful Hardware Items To Choose From.<br>Please Contact Us If You Need Any Help. Thanks!</td></tr></table>";
	var url= "http://" + thehost + "/finish_guide.php";
	url=url+"?finish_cat="+str;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChangedFinishGuide;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
/* ech */
function stateChangedFinishGuide()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("finishresults").innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObjectFinishGuide()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}

function capitaliseFirstLetter(str){
	var words = str.split(" "); 
	for (var i=0 ; i < words.length ; i++){ 
	var testwd = words[i]; 
	var firLet = testwd.substr(0,1); 
	var rest = testwd.substr(1, testwd.length -1) 
	words[i] = firLet.toUpperCase() + rest 
	} 
 	return words.join(" "); 
}


// show hardware finishes
function hardwareFinishes(str,hardtype){

	document.getElementById("hardwarefinishes").innerHTML="";
	document.getElementById("hardwarefinishes").innerHTML = "You Are Viewing All of Our <u>" + str + "</u> Finishes";
	
	document.getElementById("thefintypename").innerHTML="";
	document.getElementById("thefintypename").innerHTML = str;
	
	var hardwareRemove = hardtype.replace(/-/g, " ");
	hardwareRemoveFinal = capitaliseFirstLetter(hardwareRemove);
	
	var finishRemove = str.replace(/ /g, "-");
	finishRemoveTwo = finishRemove.toLowerCase();
	
	document.getElementById("thefintypenamebutton").innerHTML="";
	document.getElementById("thefintypenamebutton").innerHTML = "<div id=\"finishredbox\"><form action=\"http://www.simplyknobsandpulls.com/" + hardtype + "/" + finishRemoveTwo + "-finishes\" method=\"get\"><input style=\"font-size:11pt;padding:8px;border-color: #696 #363 #363 #696;\" type=\"submit\" value=\"View All " + str + " " + hardwareRemoveFinal + " - Click Here!\"></form></div>";
	
	if (str.length==0){
	return;
	}
	xmlhttp=GetXmlHttpObjectHardwareFinishGuide();
	if (xmlhttp==null){
	alert ("Your browser does not support XMLHTTP!");
	return;
	}
	document.getElementById("hardwarefinishes").innerHTML="<table style=\"font:12pt arial;color:green;\"><tr><td valign=\"top\" width=\"100\"><img src=\"http://" + thehost +"/images/finish-loader.gif\" border=\"0\"></td><td valign=\"middle\" style=\"padding-top:10px;padding-left:10px;padding-bottom:10px;\">Loading Your Selected Finishes...<br>We Have Thousands of Beautiful Hardware Items To Choose From.<br>Please Contact Us If You Need Any Help. Thanks!</td></tr></table>";
	var url= "http://" + thehost + "/hardware_finish_guide.php";
	url=url+"?finish_cat="+str;
	url=url+"&hardtype="+hardtype;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChangedHardwareFinishGuide;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
/* ech */
function stateChangedHardwareFinishGuide()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("hardwarefinishes").innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObjectHardwareFinishGuide()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}






// show hardware finishes by brand
function hardwareFinishesBrand(str,hardtype,brand)
{
	document.getElementById("hardwarefinishesbrand").innerHTML="";
	document.getElementById("hardwarefinishesbrand").innerHTML = "You Are Viewing All of Our <u>" + str + "</u> Finishes";
	
	var brandRemove = brand.replace(/-/g, " ");
	brandRemoveFinal = capitaliseFirstLetter(brandRemove);
	
	var hardwareRemove = hardtype.replace(/-/g, " ");
	hardwareRemoveFinal = capitaliseFirstLetter(hardwareRemove);
	
	var finishRemove = str.replace(/ /g, "-");
	finishRemoveTwo = finishRemove.toLowerCase();
	
	document.getElementById("thefintypenamebutton").innerHTML="";
	if(brand == 'schaub-and-company'){
		document.getElementById("thefintypenamebutton").innerHTML = "<div id=\"finishredbox\"><form action=\"http://www.simplyknobsandpulls.com/" + brand + "/" + hardtype + "/" + finishRemoveTwo + "-finishes\" method=\"get\"><input style=\"font-size:10pt;padding:3px;border-color: #696 #363 #363 #696;\" type=\"submit\" value=\"View All " + brandRemoveFinal + " " + str + " " + hardwareRemoveFinal + " - Click Here!\"></form></div>";
	}else{
		document.getElementById("thefintypenamebutton").innerHTML = "<div id=\"finishredbox\"><form action=\"http://www.simplyknobsandpulls.com/" + brand + "/" + hardtype + "/" + finishRemoveTwo + "-finishes\" method=\"get\"><input style=\"font-size:11pt;padding:8px;border-color: #696 #363 #363 #696;\" type=\"submit\" value=\"View All " + brandRemoveFinal + " " + str + " " + hardwareRemoveFinal + " - Click Here!\"></form></div>";
	}
	
	if (str.length==0)
	{
	return;
	}
	xmlhttp=GetXmlHttpObjectHardwareFinishGuideBrand();
	if (xmlhttp==null)
	{
	alert ("Your browser does not support XMLHTTP!");
	return;
	}
	document.getElementById("hardwarefinishesbrand").innerHTML="<table style=\"font:12pt arial;color:green;\"><tr><td valign=\"top\" width=\"100\"><img src=\"http://" + thehost +"/images/finish-loader.gif\" border=\"0\"></td><td valign=\"middle\" style=\"padding-top:10px;padding-left:10px;padding-bottom:10px;\">Loading Your Selected Finishes...<br>We Have Thousands of Beautiful Hardware Items To Choose From.<br>Please Contact Us If You Need Any Help. Thanks!</td></tr></table>";
	var url= "http://" + thehost + "/hardware_finish_guide_brand.php";
	url=url+"?finish_cat="+str;
	url=url+"&hardtype="+hardtype;
	url=url+"&brand="+brand;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChangedHardwareFinishGuideBrand;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
/* ech */
function stateChangedHardwareFinishGuideBrand()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("hardwarefinishesbrand").innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObjectHardwareFinishGuideBrand()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}

function hideFinishes(){
	document.getElementById("morefinishes").innerHTML = "";
	document.getElementById("seemore").style.visibility = "visible";
	document.getElementById("hidemore").style.visibility = "hidden";
}

// show hardware finishes by brand
function showMoreFinishes(str)
{
	document.getElementById("morefinishes").innerHTML="";
	if (str.length==0)
	{
	return;
	}
	xmlhttp=GetXmlHttpObjectshowMoreFinishes();
	if (xmlhttp==null)
	{
	alert ("Your browser does not support XMLHTTP!");
	return;
	}
	document.getElementById("morefinishes").innerHTML = "<img src=\"http://" + thehost +"/images/ajax-loader.gif\" border=\"0\">";
	var url= "http://" + thehost + "/more_finishes.php";
	url=url+"?hardware="+str;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=showMoreFinishesState;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function showMoreFinishesState()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("morefinishes").innerHTML=xmlhttp.responseText;
		document.getElementById("seemore").style.visibility = "hidden";
		document.getElementById("seemore").style.height = "0px";
		document.getElementById("hidemore").style.visibility = "visible";
	}
}
function GetXmlHttpObjectshowMoreFinishes()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}


// show hardware finishes by brand
function showMoreFinishesBrand(brand,str)
{
	document.getElementById("morefinishes").innerHTML="";
	if (str.length==0)
	{
	return;
	}
	xmlhttp=GetXmlHttpObjectshowMoreFinishesBrand();
	if (xmlhttp==null)
	{
	alert ("Your browser does not support XMLHTTP!");
	return;
	}
	document.getElementById("morefinishes").innerHTML = "<img src=\"http://" + thehost +"/images/ajax-loader.gif\" border=\"0\">";
	var url= "http://" + thehost + "/more_finishes_brand.php";
	url=url+"?hardware="+str;
	url=url+"&brand="+brand;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=showMoreFinishesStateBrand;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function showMoreFinishesStateBrand()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("morefinishes").innerHTML=xmlhttp.responseText;
		document.getElementById("seemore").style.visibility = "hidden";
		document.getElementById("seemore").style.height = "0px";
		document.getElementById("hidemore").style.visibility = "visible";
	}
}
function GetXmlHttpObjectshowMoreFinishesBrand()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}

function hideHoles(){
	document.getElementById("moreholes").innerHTML = "";
	document.getElementById("seemoreholes").style.visibility = "visible";
	document.getElementById("hidemoreholes").style.visibility = "hidden";
}


// show hardware finishes by brand
function showMoreHoles(str)
{
	document.getElementById("moreholes").innerHTML="";
	if (str.length==0)
	{
	return;
	}
	xmlhttp=GetXmlHttpObjectShowMoreHolesState();
	if (xmlhttp==null)
	{
	alert ("Your browser does not support XMLHTTP!");
	return;
	}
	document.getElementById("moreholes").innerHTML = "<img src=\"http://" + thehost +"/images/ajax-loader.gif\" border=\"0\">";
	var url= "http://" + thehost + "/more_holes.php";
	url=url+"?hole="+str;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=showMoreHolesState;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function showMoreHolesState()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("moreholes").innerHTML=xmlhttp.responseText;
		document.getElementById("seemoreholes").style.visibility = "hidden";
		document.getElementById("seemoreholes").style.height = "0px";
		document.getElementById("hidemoreholes").style.visibility = "visible";
	}
}
function GetXmlHttpObjectShowMoreHolesState()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}

function hideFinishesHoles(){
	document.getElementById("moreFinishesHoles").innerHTML = "";
	document.getElementById("seeMoreHoles").style.visibility = "visible";
	document.getElementById("hideMoreHoles").style.visibility = "hidden";
}

// show hardware finishes by brand
function showMoreFinishesHoles(spacing,hardware,finish)
{
	document.getElementById("moreFinishesHoles").innerHTML="";
	if (spacing.length==0)
	{
	return;
	}
	xmlhttp=GetXmlHttpObjectshowMoreFinishesHoles();
	if (xmlhttp==null)
	{
	alert ("Your browser does not support XMLHTTP!");
	return;
	}
	document.getElementById("moreFinishesHoles").innerHTML = "<img src=\"http://" + thehost +"/images/ajax-loader.gif\" border=\"0\">";
	var url= "http://" + thehost + "/more_finishes_holes.php";
	url=url+"?spacing="+spacing;
	url=url+"&hardware="+hardware;
	url=url+"&finish="+finish;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=showMoreFinishesStateHoles;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function showMoreFinishesStateHoles()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("moreFinishesHoles").innerHTML=xmlhttp.responseText;
		document.getElementById("seeMoreHoles").style.visibility = "hidden";
		document.getElementById("seeMoreHoles").style.height = "0px";
		document.getElementById("hideMoreHoles").style.visibility = "visible";
	}
}
function GetXmlHttpObjectshowMoreFinishesHoles()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}


// show hardware finishes by brand
function showFinishHint(brand,hardware,finish)
{
	if (finish.length == 0)
	{
		return;
	}
	xmlhttp=GetXmlHttpObjectTheFinishHint();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	if(finish.length <= 1){
		document.getElementById("finishhint").style.visibility = "hidden";
	}
	if(finish.length >= 2){
		document.getElementById("finishhint").style.visibility = "visible";
		document.getElementById("finishhint").innerHTML = "<div id=\"finishhintcard\"><h3 style=\"padding:0px;margin:0px;\">Loading...<br><img src=\"http://" + thehost +"/images/ajax-loader.gif\" border=\"0\"><br><a onclick=\"hideFinishHint()\" style=\"color:red;cursor: pointer; cursor: hand;\"></h3></div>";
	}
	var url= "http://" + thehost + "/finish_hint.php";
	url=url+"?finish="+finish;
	url=url+"&brand="+brand;
	url=url+"&hardware="+hardware;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=theFinishHint;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function theFinishHint()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("finishhint").innerHTML=xmlhttp.responseText;
	}
}
function GetXmlHttpObjectTheFinishHint()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}

function hideFinishHint(){
	document.getElementById("finishhint").style.visibility = "hidden";
}

function showHardware(str,strdiv){
	
	thediv = 'hintssubfinish_' + strdiv;
	document.getElementById(thediv).style.display = 'block';
	
	document.getElementById(thediv).innerHTML = '<li>Loading Hardware Types...</li>';
	
	if (window.XMLHttpRequest){
            xmlhttpc=new XMLHttpRequest();
	}else{
        xmlhttpc=new ActiveXObject("Microsoft.XMLHTTP");
    }
	xmlhttpc.onreadystatechange=function(){
		if (xmlhttpc.readyState==4 && xmlhttpc.status==200){
			
			theclosediv = 'hintssubfinishclose_' + strdiv;
			document.getElementById(theclosediv).style.display = 'block';
			
			theopendiv = 'hintssubfinishopen_' + strdiv;
			document.getElementById(theopendiv).style.display = 'none';
			
			document.getElementById(thediv).innerHTML = xmlhttpc.responseText;
			
		}
	}
    xmlhttpc.open("GET","http://www.simplyknobsandpulls.com/ajax/searchhint_showhardware.php?str="+str,true);
    xmlhttpc.send();
	
}

function showHardwareClose(str,strdiv){
	
	theclosediv = 'hintssubfinishclose_' + strdiv;
	document.getElementById(theclosediv).style.display = 'none';
	
	theopendiv = 'hintssubfinishopen_' + strdiv;
	document.getElementById(theopendiv).style.display = 'block';
	
	thediv = 'hintssubfinish_' + strdiv;
	document.getElementById(thediv).style.display = 'none';
	
}

