﻿function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}
function showHelp(helpId, e)
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	var text;
	switch (helpId)
	{
		case 0:
			text = 'For best results, use simple words. Do not use acronyms.'; break;
		case 1:
			text = 'Add states to the list on the right by selecting them from the dropdown, <br />or selecting them from the map.'; break;
		case 2:
			text = 'You may enter all or part of the company name. For best results, use a <br />unique word or phrase present in the name.'; break;
		case 3:
			text = 'Checking any of these boxes will severely limit the number of results returned.'; break;
		case 4:
			text = 'Add states to the list on the right by selecting them from the dropdown, <br />or selecting them from the map. After states are selected, you may add <br />chapters associated with those states.'; break;
		case 5:
			text = 'Use this section only if you are search for companies with specific gross volumes of business.'; break;
		case 6:
			text = 'Only use this section if you wish to limit your search to companies within <br />a specific set of counties. Seperate multiple zipcodes with spaces.'; break;
		case 7:
			text = 'Use this section if you wish to limit your search to companies within your <br />local area code. Field accepts a maximum of 3 digits.'; break;
	}

	var div = document.getElementById("help" + helpId);
	
	if (!div)
	{
		div = document.createElement("div");
		document.getElementsByTagName("body")[0].appendChild(div);
		div.innerHTML	 = text;
		div.className = "help"
		div.id = "help" + helpId;
		div.onmouseout = function(){ div.style.display = "none"; };
	}
	
	div.style.top = posy - 1;
	div.style.left = posx - (div.clientWidth / 2);
	div.style.display = "block";
	setTimeout(function(){ div.style.display = "none"; }, 5000);
	
	//Modal_Show("Help!", text, 0, null, 300, 100);
}
var selects = null;
function LoadSelects()
{
	if (selects == null)
	{
		selects = document.getElementsByTagName("select");
	}
}

var Modal_Function = "";

function Modal_Continue(cmd)
{
	var frm = document.getElementById("ifrmModalBody");

	if (frm != null)
	{
		frm.contentWindow.Continue(cmd);
	}
}
function Modal_Action(cmd)
{
	eval(Modal_Function + "(cmd)");
}
function Modal_Show(title, body, type, action, width, height)
{
	LoadControlsTop();
	
	var dvContainer = divModalConfirmation.getElementsByTagName("div")[1];

	divModalConfirmation.style.height = document.body.clientHeight;

	// hide normal scrollbar and show nonscrolling scrollbar
	var owB = document.body.clientWidth;
	document.body.style.overflow = "hidden";
	var owA = document.body.clientWidth;
	
	var dv = document.getElementById("sbDiv");
	dv.style.display = "inline";
	dv.style.top = document.body.scrollTop;
	
	form1.style.paddingRight = (owA - owB) + "px";
	// end scrollbar manip

	if (width != null)
	{
		dvContainer.style.width = width + "";
		dvContainer.getElementsByTagName("table")[0].style.left = ((Math.abs(width) * .5) * -1) + "";
	}
	else
	{
		dvContainer.style.width = "";
		dvContainer.getElementsByTagName("table")[0].style.left = "";
	}

	if (height != null)
	{
		dvContainer.style.height = height + "";
		dvContainer.getElementsByTagName("table")[0].style.top = ((Math.abs(height) * .5) * -1) + "";
	}
	else
	{
		dvContainer.style.height = "";
		dvContainer.getElementsByTagName("table")[0].style.top = "";
	}

	dvContainer.getElementsByTagName("table")[0].rows[0].cells[0].innerText = title;

	if (type < 2 || type == 3)
	{
		divModalConfirmation.getElementsByTagName("div")[1].getElementsByTagName("table")[0].rows[1].cells[0].innerHTML = body;
		
		BrowserDetect.init();
		if (BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6")
		{
			LoadSelects();
			for (i = 0; i < selects.length; i++)
			{
				selects[i].style.display = "none";
				
				var dv = document.createElement("input");
				dv.className = "dropdownlist";
				dv.style.width = selects[i].style.width;
				selects[i].parentNode.insertBefore(dv, selects[i]);
			}
		}
	}
	else if (type == 2 || type == 4)
	{
		divModalConfirmation.getElementsByTagName("div")[1].getElementsByTagName("table")[0].rows[1].cells[0].innerHTML = "<iframe id='ifrmModalBody' frameborder='0' style='width:100%;height:100%;' src='" + body + "'></iframe>";
	}

	var ButtonTable = divModalConfirmation.getElementsByTagName("div")[1].getElementsByTagName("table")[0].rows[2].cells[0].getElementsByTagName("table")[0];

	// re-enable all buttons
	ButtonTable.rows[1].cells[0].getElementsByTagName("input")[1].disabled = false;
	ButtonTable.rows[1].cells[0].getElementsByTagName("span")[0].disabled = false;
	ButtonTable.rows[1].cells[0].getElementsByTagName("input")[0].disabled = false;

	switch (type)
	{
		case 0:
		case 4:
			ButtonTable.rows[1].cells[0].getElementsByTagName("input")[1].value = " OK ";
			ButtonTable.rows[1].cells[0].getElementsByTagName("input")[1].style.width = "100";
			ButtonTable.rows[1].cells[0].getElementsByTagName("span")[0].style.display = "none";
			ButtonTable.rows[1].cells[0].getElementsByTagName("input")[0].style.display = "none";
			divModalConfirmation.getElementsByTagName("div")[1].getElementsByTagName("table")[0].rows[2].style.display = "";
			break;
		case 1:
		case 2:
			ButtonTable.rows[1].cells[0].getElementsByTagName("input")[1].value = "Cancel";
			ButtonTable.rows[1].cells[0].getElementsByTagName("span")[0].style.display = "inline";
			ButtonTable.rows[1].cells[0].getElementsByTagName("input")[0].style.display = "inline";
			divModalConfirmation.getElementsByTagName("div")[1].getElementsByTagName("table")[0].rows[2].style.display = "";
			//ButtonTable.rows[0].cells[1].childNodes[2].onclick = function(){eval(action + "(this)");};
			break;
		case 3:
			divModalConfirmation.getElementsByTagName("div")[1].getElementsByTagName("table")[0].rows[2].style.display = "none";
			break;
	}

	if (action != null)
	{
		Modal_Function = action;
	}

	divModalConfirmation.style.display = "block";
	divModalConfirmation.style.top = document.body.scrollTop;

	if (type == 3)
	{
		eval(action);
	}
}
function Modal_Hide()
{
	BrowserDetect.init();
	if (BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6")
	{
		LoadSelects();
		for (i = 0; i < selects.length; i++)
		{
			selects[i].style.display = "";
			if (selects[i].previousSibling != null && selects[i].previousSibling.className == "dropdownlist")
				selects[i].parentNode.removeChild(selects[i].previousSibling);
		}
	}
		
	if (divModalConfirmation != null)
	{
		divModalConfirmation.style.display = "none";
	}
	document.body.style.overflow = "auto";
	document.getElementById("sbDiv").style.display = "none";
	form1.style.paddingRight = "0px";
}
