//-----------------------------------------------------------------------------------------------------
//gen functions
//-----------------------------------------------------------------------------------------------------
function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}
//-----------------------------------------------------------------------------------------------------
function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}

//-----------------------------------------------------------------------------------------------------
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr));
}


// Validate Search ------------------------------------------------------------------------------------
function validateSearch()
{
	var obj = objSearch;
	if(obj.keywords.value == '')
	{
		alert("Please enter Search Keywords");
		obj.keywords.focus();
		return false;
	}

	//All fine
	return true;
}

// Validate Brach Login -------------------------------------------------------------------------------
function validateBranchLogin()
{
	var obj = objBranch;
	if(obj.LOGNID.value == '')
	{
		alert("Please enter Access ID");
		obj.LOGNID.focus();
		return false;
	}

	//All fine
	return true;
}

//Checks URL against pattern
function chkURL(tmpStr)
{
	var url_pat = /^(http|https|ftp):\/\/([\w-]+\.)+[\w-]+(\/[\w-\.\/?%&amp;,=#@\/:]*)?/;
	return(url_pat.test(tmpStr));
}

function popupCalcs(calc)
{
	 var calcWindow;
	 var left = (screen.availWidth) ? screen.availWidth - 430 : 10;

	if(null == arguments[0])
	{
		calc = 'index';
	}
	var target = 'http://cucalc.cuna.org/10373/'+calc+'.html';
	if(calcWindow && !calcWindow.closed)
		calcWindow.close();

	calcWindow = window.open(target,'calculator','HEIGHT=720,WIDTH=380,innerWidth=380,innerHeight=720,SCREENX='+left+',LEFT='+left+',SCREENY=90,TOP=90,SCROLLBARS=yes,RESIZABLE=yes,TOOLBAR=no,STATUS=no,LOCATION=no');
	if(!calcWindow.opener)
	  calcWindow.opener = window;
}

$(document).ready(function() {
	$('#LOGNID').bind('keypress', function(e) {
		var key = (e.keyCode ? e.keyCode : e.charCode);
		if(e.keyCode == 13) validateVirtualLogin();
	});
});

function validateVirtualLogin()
{
	if(document.getElementById('LOGNID').value == '')
	{
		alert('Please enter Login ID.');
		document.getElementById('LOGNID').focus();
		return false;
	}

	window.open('https://www.netit.financial-net.com/ttcu/cgi-bin/mfrqst?SPONID=3Z62V&CMD=002&SERVER=www.netit.financial-net.com&URL=https://www.netit.financial-net.com/ttcu/cgi-bin/ebs&LOGNID=' + document.getElementById('LOGNID').value);
	document.getElementById('LOGNID').value = '';
}


//Code to allow and disallow popup disclosure to certian links
$(document).ready(function(){

	$('a').click(function(){
			var tmpElement = $(this).attr('href');
			//Add here the links that you don't need the popup to show
			var arrAllowLinks = new Array(
				'https://www.netit.financial-net.com/ebsssi/gifs/mobiledraft.pdf',
				'https://www.netit.financial-net.com/ttcu/cgi-bin/ebs',
				'https://www.netit.financial-net.com/ttcu-loan/cgi-bin/ebs?OLB_CMD-SLN-164&loan_file=../loan_file0',
				'https://www.netit.financial-net.com/ttcu/cgi-bin/ebs?OLB_CMD-SMN-220'
				);
			var tempCheck = false;
			for(var z = 0; z < arrAllowLinks.length; z++)
			{
				if(tmpElement == arrAllowLinks[z])
					tempCheck = true;
			}
			if(tempCheck == false)
			{
				httpDomainAlias = tmpElement.substr(0, 10);
				httpsDomainAlias = tmpElement.substr(0, 11);
				if(httpDomainAlias == 'http://www' || httpsDomainAlias == 'https://www' || httpDomainAlias == 'http://por')
				{
					var confirmMsg = "You have clicked on a link that will take you off the TTCU web site."
					confirmMsg+= " Please note that Tuscaloosa Teachers Credit Union has no control of the accuracy of the information nor of the security of the site you are about to visit,";
					confirmMsg+= " and makes no warranty thereof. Thank you for visiting TTCU's website.";
					if(!confirm(confirmMsg))
						return false
				}
			}
		});


	$('#nav_menu ul li').hover(function(){
		$(this).find('ul:first').slideDown({
			duration:300,
			easing:"easeInCirc"
		});
	},function(){
		$(this).find('ul:first').fadeOut(10);
	})
});


function filterURL(tmpElement,check_isactive)
{
	//Add here the links that you don't need the popup to show
	var arrAllowLinks = new Array(
		'https://www.netit.financial-net.com/ebsssi/gifs/mobiledraft.pdf',
		'https://www.netit.financial-net.com/ttcu/cgi-bin/ebs',
		'https://www.netit.financial-net.com/ttcu-loan/cgi-bin/ebs?OLB_CMD-SLN-164&loan_file=../loan_file0',
		'https://www.netit.financial-net.com/ttcu/cgi-bin/ebs?OLB_CMD-SMN-220'
		);
	var tempCheck = false;
	for(var z = 0; z < arrAllowLinks.length; z++)
	{
		if(tmpElement == arrAllowLinks[z])
			tempCheck = true;
	}
	if(tempCheck == false)
	{
		httpAlias = tmpElement.substr(0, 7);
		httpsAlias = tmpElement.substr(0, 8);
		httpDomainAlias = tmpElement.substr(0, 10);
		httpsDomainAlias = tmpElement.substr(0, 11);
		if(httpAlias == 'http://' || httpsAlias == 'https://' || httpDomainAlias == 'http://www' || httpsDomainAlias == 'https://www' || httpDomainAlias == 'http://por' || tmpElement == 'http://main.acsevents.org/site/TR/RelayForLife/RFLFY11MS?sid=35436&type=fr_informational&pg=informational&fr_id=28692')
		{
			var confirmMsg = "You have clicked on a link that will take you off the TTCU web site."
			confirmMsg+= " Please note that Tuscaloosa Teachers Credit Union has no control of the accuracy of the information nor of the security of the site you are about to visit,";
			confirmMsg+= " and makes no warranty thereof. Thank you for visiting TTCU's website.";
			if(check_isactive == 'Y')
			{
				if(confirm(confirmMsg))
					self.location = tmpElement;
				else
					self.location = webServer;
			}
			else
			{
				self.location = tmpElement;
			}
		}
		else
		{
			self.location = tmpElement;
		}
	}
	if(tmpElement == 'https://www.netit.financial-net.com/ebsssi/gifs/mobiledraft.pdf')
		self.location = tmpElement;
}
