
/* -------------------------------------------------- *
 * Search - toggle between catalog and store
** -------------------------------------------------- */



function searchRadioChecked(inRadio)	{
	switch(inRadio.value)	{
		case "parts-store":
			var searchURL = "http://store.eurtonelectric.com/search.aspx?find=" + encodeURIComponent(document.getElementById("keywords").value),
				text = "Parts Store";
			break;
		case "motor-catalog":
			var searchURL = "http://eurtonelectric.com/",
				text = "Motor Catalog";
			break;
	}
	
	document.forms[0].action = searchURL;
	document.getElementById("search-label").innerHTML = text;
}

function keyDownSearchField(inInput)	{
	if(document.getElementById("parts-store").checked)	{ // When parts is checked, continually update our action. This is necessary if they press enter it won't do an onbeforesubmit. onsubmit changing the action only works if there's a delay
		document.forms[0].action = document.forms[0].action.replace(/\?find=.*/, "") + "?find=" + encodeURIComponent(inInput.value);
	}
}

var checkCorrectSearchLabel = function()	{
	var searchLabel = document.getElementById("search-label"),
		partsStoreRadio = document.getElementById("parts-store");
	
	if(!searchLabel || !partsStoreRadio)	{
		return setTimeout(checkCorrectSearchLabel, 5);
	}
	
	if(partsStoreRadio.checked)	{ // Sync up the label based on what's selected. Happened when I went back
		searchRadioChecked(partsStoreRadio);
	}
};
checkCorrectSearchLabel();





/* -------------------------------------------------- *
 * ToggleVal 2.1 - to clear searchbox
** -------------------------------------------------- */

(function($){$.fn.toggleVal=function(theOptions){if(!theOptions||typeof(theOptions)=="object"){theOptions=$.extend({focusClass:"tv-focused",changedClass:"tv-changed",populateFrom:"default",text:null,removeLabels:false},theOptions)}else if(typeof(theOptions)=="string"&&theOptions.toLowerCase()=="destroy"){var destroy=true}return this.each(function(){if(destroy){$(this).unbind("focus.toggleval").unbind("blur.toggleval").removeData("defText");return false}var defText="";switch(theOptions.populateFrom){case"alt":defText=$(this).attr("alt");$(this).val(defText);break;case"label":defText=$("label[for='"+$(this).attr("id")+"']").text();$(this).val(defText);break;case"custom":defText=theOptions.text;$(this).val(defText);break;default:defText=$(this).val()}$(this).addClass("toggleval").data("defText",defText);if(theOptions.removeLabels==true){$("label[for='"+$(this).attr("id")+"']").remove()}$(this).bind("focus.toggleval",function(){if($(this).val()==$(this).data("defText")){$(this).val("")}$(this).addClass(theOptions.focusClass).removeClass(theOptions.changedClass)}).bind("blur.toggleval",function(){if($(this).val()==""){$(this).val($(this).data("defText"))}$(this).removeClass(theOptions.focusClass);if($(this).val()!=$(this).data("defText")){$(this).addClass(theOptions.changedClass)}else{$(this).removeClass(theOptions.changedClass)}})})}})(jQuery);

$(function() {
	$("input[name='keywords']").toggleVal({
    focusClass: "hasFocus",
    changedClass: "isChanged"
	});
});

$(function() {
	$("input[name='cm-trkutr-trkutr']").toggleVal({
    focusClass: "hasFocus",
    changedClass: "isChanged"
	});
});



/*
* Collapse Toggler - http://www.sohtanaka.com/web-design/easy-toggle-jquery-tutorial/
*/

$(function() {

	$(".toggle_container").show(); 


	$("h5.trigger").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});

	$("h5.trigger").click(function(){
		$(this).next(".toggle_container").slideToggle("fast");
	});

});
