$(document).ready(function() {
    //zip code form
    $("div.locationform .location-search").val("enter zip code");
    $("div.locationform .location-search").click(function() {
	if($(this).val() == "enter zip code") $(this).val("");
    });
    $("div.locationform .location-search").blur(function() {
	if($(this).val() == "") $(this).val("enter zip code");
    });
});

if (window.captureEvents){
    window.captureEvents(Event.KEYDOWN);
    window.onkeydown = CheckKeyPress;    
} else {
   document.onkeydown = CheckKeyPress;
}

function CheckKeyPress(e){
    var el = (typeof event!=='undefined')? event.keyCode: e.which;
    //alert(el);
    if(el == 13){
        return false;
    }
    else{
        return true;
    }
}

function encodeMyHtml(htmlToEncode) {
    encodedHtml = escape(htmlToEncode);
    encodedHtml = encodedHtml.replace(/\//g,"%2F");
    encodedHtml = encodedHtml.replace(/\?/g,"%3F");
    encodedHtml = encodedHtml.replace(/=/g,"%3D");
    encodedHtml = encodedHtml.replace(/&/g,"%26");
    encodedHtml = encodedHtml.replace(/@/g,"%40");
    return encodedHtml;
}

$(function() 
{
	//Function called on the "Enter" keyup event
	$(".location-search").keyup(function(event)
	{
	    if(event.keyCode == 13)
	    {
	        $('.location-submit').click();                    
	    }
	});

	//Click function to load the map and the SimpleModal Plugin
	$('.location-submit').click(function(){
		//var src = 'http://www.batchgeo.com/map/?i=76b6d1d868cdccd813a36a50e5b46f0b&q=' + encodeMyHtml($(".location-search").val());
                var src = 'http://www.batchgeo.com/map/?i=3a96524c50455fec054725e17835426f&q=' + encodeMyHtml($(".location-search").val());
		$.modal('<div><div class="MapLinks"><a class="Close" href="#">Close</a></div><iframe id="MapFrame" name="MapFrame" src="' + src + '" height="500" width="800" style="border:0"></div>', {
        	closeClass: "Close",
		opacity:60,
		overlayCss: {backgroundColor:"#fff"},
		containerCss:{
			backgroundColor:"#006666",
			borderColor:"#006666",
			height:500,
			padding:25,
			width:800
		},
		overlayClose:true
		});
            return false;
	});
});
