$(document).ready(function() {
	$("#src_btn").click( function(){			 			
		if(($("#mansrc").val() == undefined || $("#mansrc").val() == "0") && ($("#catsrc").val() == undefined || $("#catsrc").val() == "0")){
			alert("You must select a manufacturer or a category to get started."); 
			return false;
		}else{			
			var web_path="http://www.tsaworld.com/";
			if($("#mansrc").val()!=undefined && $("#mansrc").val()!="0" && $("#modsrc").val()!=undefined && $("#modsrc").val()!="0" && ($("#catsrc").val() != undefined && $("#catsrc").val() != "0")){
				window.location=web_path+$("#mansrc").val()+'/'+$("#modsrc").val()+'/'+$("#catsrc").val();	
			}else if(($("#mansrc").val()!=undefined && $("#mansrc").val()!="0") && $("#modsrc").val()!=undefined && $("#modsrc").val()!="0"){
				window.location.href=web_path+$("#mansrc").val()+'/'+$("#modsrc").val();	
			}else if($("#mansrc").val()!=undefined && $("#mansrc").val()!="0"){
				if($("#catsrc").val() != undefined && $("#catsrc").val() != "0"){
					window.location=web_path+$("#mansrc").val()+'/'+$("#catsrc").val();
				}else{
					window.location=web_path+$("#mansrc").val();
				}
			}else if($("#catsrc").val() != undefined || $("#catsrc").val() != "0"){
					window.location=web_path+$("#catsrc").val();
			}
		}
	});
	$("#txt_btn").click( function(){
		var web_path="http://www.tsaworld.com/";
		window.location=web_path+'products/'+$("#partsrc").val();		
	});

	$("#mansrc").change(function(){
		if($("#mansrc").val()>'0'){
			$("#modsrc").html('<option value="0">Processing...</option>');
			var web_path="http://www.tsaworld.com/";
			$.post(web_path+"ajax/aj_template_search.php",{ 
		 			man: $("#mansrc").val()
			},function(data) {
				$("#modsrc").html(data);
			});
		}
	});
	$("#modsrc").change(function(){
		if($("#modsrc").val()>'0'){
			$("#catsrc").html('<option value="0">Processing...</option>');
			var web_path="http://www.tsaworld.com/";
			$.post(web_path+"ajax/aj_template_search.php",{ 
					man: $("#mansrc").val(),
		 			mod: $("#modsrc").val()
			},function(data) {
				$("#catsrc").html(data);		
			});
		}
	});
	$("#catsrc").change(function(){
		if($("#catsrc").val()>'0'){
			var web_path="http://www.tsaworld.com/";
			$.post(web_path+"ajax/aj_template_search.php",{ 
		 			cat: $("#catsrc").val()
			},function(data) {
				if($("#mansrc").val()!=undefined && $("#mansrc").val()!="0" && $("#modsrc").val()!=undefined && $("#modsrc").val()!="0" && ($("#catsrc").val() != undefined && $("#catsrc").val() != "0")){
					$("#src_btn").click();
				}
			});
		}
	});
	
	$("#partsrc").focus(function(){
		$("#partsrc").val('');
		$("#partsrc").unbind('focus');
	});
	$("#partsrc").change(function(){
		if($("#partsrc").val().length>'3'){
			var web_path="http://www.tsaworld.com/";
			$.post(web_path+"ajax/aj_template_search.php",{ 
	 			part: $("#partsrc").val()
			},function(data) {

			});
		}
	});
	
	$("#partsrc").keypress(function (e) {  
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
            $('#txt_btn').click();  
            return false;  
        } else {  
            return true;  
        }  
    });	
    
	$("#tplloginform input").keypress(function (e) {  
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
            $('#tplloginform input[type=submit]').click();  
            return false;  
        } else {  
            return true;  
        }  
    });
	$("#myloginform input").keypress(function (e) {  
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
            $('#myloginform input[type=submit]').click();  
            return false;  
        } else {  
            return true;  
        }  
    });
    
    $("#loginform input").keypress(function (e) {  
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
            $('#loginform input[type=submit]').click();  
            return false;  
        } else {  
            return true;  
        }  
    });
    
    $("#txtProductQuantity").keyup(function() {
		if($("#txtProductQuantity").val()!="") {
			var web_path="http://www.tsaworld.com/";
			$.post(web_path+"ajax/aj_get_product_price.php",{ 
		 			pid: $("#varProductId").val(),
		 			qty:  $("#txtProductQuantity").val()
			},function(data) {
				$("#lblProductCost").html(data);
			});
		}
	});
	
	 $("h2[id^='cat_header_']").toggle(function(){ $(this).next().show();}, function(){ $(this).next().hide();});
	
	
});