$(document).ready(function(){
	$(".lsLegend").each(function(){
	    $(this).click(function(){
	        $(".mhc_popup_div").remove();
	        var strSimple = "<div class='mhc_popup_div'><div class='mhc_popup_inner'><img border='0' alt='Legendary Service' src='/images/legendary_service.gif' class='legServ'/>";
	        strSimple += "<p class='popup_close'><span>5-star Service Award</span>[ x ] <a href='#'>Close</a></p>";
	        strSimple += "<p class='legInfo'>The 5-star Service Award is granted to those Model Home Centers that have provided exemplary service to their customers.  They reflect Clayton's belief of informing the customer in every aspect of the construction of their home, setting realistic expectations and following through. Simply put, these builder/retailers strive to be customer driven. Your satisfaction is imperative to them.</p>";
	        strSimple += "</div></div>";
	        $("body").append(strSimple);
	        viewport.init(".mhc_popup_div");
	        //$(".mhc_popup_div").css({left: "275px", top: "175px"});
	        $(".mhc_popup_div").click(function(){
	            $(".mhc_popup_div").remove();
	            return false; 
	        });
	        return false;
	    });
	});
	$("form[name=search] select").bind('keyup',function(ev){
		if(ev.keyCode == 13)
			$("form[name=search]").trigger('submit');
	});
	$("form[name=search]").bind('submit',function(ev){
		var inputs = $("input,select",this)
		if( inputs.filter("input[name=city]").val().length > 0 && inputs.filter("select").val().length)
			return true;
		else if( inputs.filter("input[name=zip]").val().length > 0 )
			return true;
		else{
			alert( "Please enter a city and state or a zip code.");
			return false;
		}
	});
	
});

var viewport = {
    o: function() {
        if (self.innerHeight) {
			this.pageYOffset = self.pageYOffset;
			this.pageXOffset = self.pageXOffset;
			this.innerHeight = self.innerHeight;
			this.innerWidth = self.innerWidth;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			this.pageYOffset = document.documentElement.scrollTop;
			this.pageXOffset = document.documentElement.scrollLeft;
			this.innerHeight = document.documentElement.clientHeight;
			this.innerWidth = document.documentElement.clientWidth;
		} else if (document.body) {
			this.pageYOffset = document.body.scrollTop;
			this.pageXOffset = document.body.scrollLeft;
			this.innerHeight = document.body.clientHeight;
			this.innerWidth = document.body.clientWidth;
		}
		return this;
    },
    init: function(el) {
        $(el).css("left",Math.round(viewport.o().innerWidth/2) + viewport.o().pageXOffset - Math.round($(el).width()/2));
        $(el).css("top",Math.round(viewport.o().innerHeight/2) + viewport.o().pageYOffset - Math.round($(el).height()/2));
    }
};