var inputID = "queryTxt";//id of input box
var submitID = "submitBtn" //id of button to submit form
var defaultText = "Search AIF";



function showMap(){
	var mapDiv = document.getElementById("interactiveMap");
	mapDiv.style.display = "block";
	var browHeight = getBrowserHeight();
	var divTop = (browHeight.height / 2) - 300;
	var divLeft = (browHeight.width / 2) - 375;
	mapDiv.style.marginTop = divTop + "px";
	mapDiv.style.marginLeft = divLeft + "px";
	var fo = new FlashObject("/flash/map.swf", "intMap", "750", "600", "7");
	fo.addParam("quality", "high");
	fo.addParam("wmode", "transparent");
	fo.addParam("menu", "false");
	fo.addParam("align", "middle");
	fo.write("interactiveMap");
};

function init(){
	setupSearch();
	var mapBtn = document.getElementById("interactiveMapLink");
	mapBtn.href="#";
	mapBtn.onclick=showMap;
	var searchBtn = document.getElementById("srchBtn");
	var qText = document.getElementById("queryTxt");
	var searchForm = document.getElementById("searchForm");
	searchBtn.onclick=function(){
		if(qText.value != defaultText && qText.value.length > 1){
			searchForm.submit();
		}else{
			alert("Please Enter a Search Term");
		}
	}
};


function closeMap(){
	if(!mapDiv){
		var mapDiv = document.getElementById("interactiveMap");
	}
	mapDiv.style.display = "none";
}

function getBrowserHeight() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	var tmpObj = new Object();
	tmpObj.height = myHeight;
	tmpObj.width =  myWidth;
	return(tmpObj);
};

function setupSearch(){
	if (!document.getElementsByTagName){ return; }
	var searchBox = document.getElementById(inputID);
	searchBox.value = defaultText;
	searchBox.onfocus =function(){ focusHandler(this)};
	searchBox.onblur =function(){ blurHandler(this)};
}
function focusHandler(obj){
	if(obj.value == defaultText){
		obj.value = "";
	}
}
function blurHandler(obj){
	if(obj.value == "" || obj.value.length < 1){
		obj.value = defaultText;
	}
}


window.onload = function(){
	init();
}