// Subnavigation on mainnav
function showMenu(getMenu)
{
	var submenu = document.getElementById(getMenu);
	submenu.className = "subNavShow";
}
function hideMenu(getMenu)
{
	var submenu = document.getElementById(getMenu);
	submenu.className = "subNavHide";
}

function focusBlur(getFld,getVal,getAction)
{
	theFld = document.getElementById(getFld);
	if (getAction == 'f')
	{
		if (theFld.value == getVal)
		{
			theFld.value = '';
		}
	}
	if (getAction == 'b')
	{
		if (theFld.value == '')
		{
			theFld.value = getVal;
		}
	}
}

function sendRequest(getUrl,getResponse)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = getUrl;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = getResponse;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetXmlHttpObject()
{
	var xmlHttp = null;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}

function PopupWin(pagefile,winname,w,h,scroller)
{ 
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+'resizable=0,scrollbars='+scroller;
	window.open(pagefile,winname,winprops);
}

function hideEmail(getEmail,getHost,getText)
{
	if (getText == 0)
	{
		document.write("<a href=" + "mail" + "to:" + getEmail + "@" + getHost+ ">" + getEmail + "@" + getHost+ "</a>");
	}
	else
	{
		document.write("<a href=" + "mail" + "to:" + getEmail + "@" + getHost+ ">" + getText + "</a>");
	}
}

$(document).ready(function()
{
	// External links
	$(".external").click(function()
	{
		var getLink = $(this).attr('href');
		window.open(getLink,'saga');
		return false;
	});
	
	// Show/hide joint app fields on form
	$("#appType").change(function()
	{
		if ($(this).val() == 'Joint')
		{
			$(".joint").css({'display':'block'});
		}
		else
		{
			$(".joint").css({'display':'none'});
		}
	});
	
	// Life insurance help popups
	$(".what").click(function()
	{
		var pagefile = $(this).attr('href');
		PopupWin(pagefile, 'help', 600, 400, 'yes');
		return false;
	});
});