﻿// JScript File

function setTab(tab) {
    if (document.getElementById('a' + tab)) {
        var aTab = document.getElementById('a' + tab);
        aTab.setAttribute('class','select');
        aTab.setAttribute('className','select');
    }
}
        
function addFav() {
	window.external.AddFavorite(this.location.href,document.title);
}

function searchKeyPress(keyEvt)
{
	var c = 0;
	if (document.layers)
		c = keyEvt.which;
	else if (document.all)
		c = event.keyCode;
	else 
		c = keyEvt.keyCode;

	if (c == 13) 
		searchData();
	else 
		return true;
}

function searchData()
{
	var keyWord  = document.getElementById('txtKeyword');
	window.location = '/News/search.aspx?keyword=' + keyWord.value;
}

function clear_textbox()
{
	document.getElementById('txtSub').value = '';
} 

function get_newsletters() {
	var email = document.getElementById('txtSub').value;
	if (email == '' || email == 'Your Email Here')  {
	    alert('Please provide your email address.');
	    document.getElementById('txtSub').focus();
	    return;       
	} else {
	    location.href = '/members/memberregister.aspx?SubEmail=' + email;
	}
}


function checkPwd(elem, pwd1Name, pwd2Name) {
	if (document.getElementById('divPwd')) {
		var divP = document.getElementById('divPwd');
		var divPB = document.getElementById('divPwdBG');
		var spnPT = document.getElementById('spnPwdText');

		var thisID = elem.id;
		var dnPre = '';
		if (thisID.lastIndexOf(pwd1Name) > 0) {
			dnPre = thisID.substr(0, thisID.lastIndexOf(pwd1Name));
		} else {
			dnPre = thisID.substr(0, thisID.lastIndexOf(pwd2Name));			
		}

		var txtP = document.getElementById(dnPre + pwd1Name);
		if (txtP.value.length < 8) {
			divP.className = 'pwdErr';
			spnPT.textContent = spnPT.innerText = 'Password must be at least 8 chars.';
			divPB.style.backgroundImage = 'url(/CustomUI/images/pwd_bg_r.gif)';
			divPB.style.width = txtP.value.length * 25 + 'px';
		} else {
			divPB.style.width = '198px';
			/* Add indexOf check for characters not matching properly with RegEx: ` ^ _ \ [ ] */
			var regPat = new RegExp('[^A-z]','ig');
			if (txtP.value.match(regPat) || txtP.value.indexOf('[') >= 0 || txtP.value.indexOf(']') >= 0 || txtP.value.indexOf('`') >= 0 || txtP.value.indexOf('_') >= 0 || txtP.value.indexOf('\\') >= 0  || txtP.value.indexOf('^') >= 0 ) {
				divP.className = 'pwdOK';
				spnPT.textContent = spnPT.innerText = 'You have provided a strong password.';
				divPB.style.backgroundImage = 'url(/CustomUI/images/pwd_bg_g.gif)';
			} else {
				divP.className = 'pwdWarn';
				spnPT.textContent = spnPT.innerText = 'Include at least 1 number or symbol.';
				divPB.style.backgroundImage = 'url(/CustomUI/images/pwd_bg_o.gif)';
			}
		}
				
		var divPC = document.getElementById('divPwdConfirm');
		var spnPCT = document.getElementById('spnPwdConfirmText');
		
		var txtPC = document.getElementById(dnPre + pwd2Name);
		if (txtPC.value.length > 0) {
			if (txtP.value == txtPC.value) {
				divPC.className = 'pwdOK';
				spnPCT.textContent = spnPCT.innerText = 'Passwords match.';
				divPC.style.backgroundImage = 'url(/CustomUI/images/pwd_bg_g.gif)';
			} else {
				divPC.className = 'pwdWarn';
				spnPCT.textContent = spnPCT.innerText = 'Passwords do not match.';
				divPC.style.backgroundImage = 'url(/CustomUI/images/pwd_bg_o.gif)';
			}
		}
	}
}


