var helpWindow;
function openHelpWindow()
{

	//if (helpWindow!=null &&  !helpWindow.closed)
	//{
		//helpWindow.focus();
		//return;
	//}
	
	helpWindow = window.open('displayHelp.x', 'HelpWindow', 'subwindow, scrollbars=yes, resizable=no, menubar=no, toolbar=no, status=no,, width=550, height=700');
	if (helpWindow.closed)
	{
		alert('Disable Popup Blocker to open new window');
   	} else {
		helpWindow.focus();
	}
}
	
// For opening the ESA Document in a new window with the following properties.
function openESAWindow(lang)
{	
	if ( lang == 'en' )
	{
		window.open('/esa_agreement.html', 'ESA', 'width=850, height=600, resizable=no, menubar=no, toolbar=no, status=no, copyhistory=no, directories=no, scrollbars=yes');		
	} else if ( lang == 'es' ) {
		window.open('/spanish_esa_agreement.html', 'ESA', 'width=850, height=600, resizable=no, menubar=no, toolbar=no, status=no, copyhistory=no, directories=no, scrollbars=yes');		
	}
	return false;
}	



function openContactUsWindow(){
window.open('/NwbhWeb/staticweb/displayEmailHelpPage.x', 'ContactUs', 'width=1000, height=900, resizable=no, menubar=no, toolbar=no, status=no, copyhistory=no, directories=no, scrollbars=yes');
}

/*
function portalSSO(appID,newWindow)
{
	if(newWindow) {
	   window.open('/NwbhWeb/content/protected/SSO?rType=NBHSSO&appId='+appID);
	} else {
	   window.location.href=("/NwbhWeb/content/protected/SSO?rType=NBHSSO&appId="+appID);
	}
}

function portalSSOOwens(appID,newWindow,lang)
{
	if(newWindow) {
	   window.open('/NwbhWeb/content/protected/SSO?rType=NBHSSO&appId='+appID+'&lang='+lang);
	} else {
	   window.location.href=("/NwbhWeb/content/protected/SSO?rType=NBHSSO&appId="+appID+'&lang='+lang);
	}
}
*/	
	
function portalSSO(appID,newWindow)
{
	if(newWindow) {
	   window.open('/NwbhWeb/content/ssoForward.x?appId='+appID);
	} else {
	   window.location.href=("/NwbhWeb/content/ssoForward.x?appId="+appID);
	}
}

function portalSSOTops()
{
	window.open('/NwbhWeb/content/ssoForward.x?appId=TOPS', 'PortalTopsWin');
}

function portalSSOOwens(appID,newWindow,lang)
{
	if(newWindow) {
	   window.open('/NwbhWeb/content/ssoForward.x?appId='+appID+'&lang='+lang);
	} else {
	   window.location.href=("/NwbhWeb/content/ssoForward.x?appId="+appID+'&lang='+lang);
	}
}


function portalHW(topicURL,newWindow)
{
  if(newWindow){
    window.open(topicURL);
  } else {
    window.location.href=topicURL;
  }
 }
 
// ONload function
function onLoadFuntion() 
{
	// set CSS display to None if right Nav is present
	elem = document.getElementById("rightNav");
	if(elem != null)
	{
		$('#rightNav ul:not(.subnav)').css('display','none');
	}	
}
 // Collapse Right Nav
function close_all(element_id) 
{
	if($(element_id).css('display')=='none')
	{
		$('#rightNav ul:not(.subnav)').hide('fast');						
	}									
}

function isEmpty(msg) 
{
	if ( msg == null || msg.length == 0 ) { return true; } else { return false; }	
}

function isValidReqDropDown(dropDownVal) 
{
	if ( dropDownVal == 'Select' || dropDownVal == null || dropDownVal.length == 0 ) { return false; } else { return true; }	
}

function isValidDate(dateValue) 
{
	dateMonth = "";
	dateDay = "";
	dateYear = "";
	dateIndex = 0;
	dateIndex2 = 0;

	dateIndex = dateValue.indexOf('/');
	
	if ( dateIndex == -1 || dateIndex > 2 ) { return false; }
	
	dateMonth = dateValue.substring(0, dateIndex);
	dateIndex2 = dateValue.indexOf('/', dateIndex+1);
	
	if ( dateIndex2 == -1  ) { return false; }
	
	dateDay = dateValue.substring(dateIndex+1, dateIndex2);
	dateYear = dateValue.substring(dateIndex2+1);
	
	if ( dateYear.length != 4 ) { return false; }
	
	if ( dateMonth > 0 && dateMonth < 13 && dateDay > 0 && dateDay < 32 && dateYear > 1900 ) { return true; }
	
	return false;
}

function isValidDOB(dobDateString) 
{
	var currentDate = new Date();
	var dobDateObj = new Date(dobDateString);
	if ( dobDateObj > currentDate ) { return false; } else { return true; }
}

function validateDate(SDate,EDate){
   var endDate = new Date(EDate);   
    var startDate= new Date(SDate);
    if(startDate > endDate){
     return false;
     }
     return true; 
 }
	
function isValidZIP(field)
{
	var valid = "0123456789-";
	var hyphencount = 0;
	
	if ( field.length != 5 && field.length != 10 ) { return 0; }
	
	for (var i=0; i < field.length; i++) 
	{
		temp = "" + field.substring(i, i+1);
		if (temp == "-") { hyphencount++; }
		if (valid.indexOf(temp) == "-1") { return 1; }			
		if ( (hyphencount > 1) || ( (field.length==10) && ""+field.charAt(5) != "-" ) ) { return 2; }
	}
}

function isValidCanadianZIP(zip)
{
	var validChars = /[^$A-Za-z0-9_\ \.]/;
	if ( validChars.test(zip) ) { return false; } else { return true; }
}

function isValidPhoneNumber(phoneNumber)
{
	if ( !isEmpty(phoneNumber) && ( isNaN(phoneNumber) || phoneNumber.length < 10 || phoneNumber.length > 10 ) ) { return false; } else { return true; }
}

function isValidEmail(email)
{
	var reg = /^([A-Za-z0-9_\-\.\,\!\#\$\%\&\*\+\-\/\=\?\^\_\`\{\|\}\~\'])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if ( !isEmpty(email) && !reg.test(email) ) { return false; } else { return true; }
}

function isValidPassword(password)
{
	var validNumeric = /[0-9]/;
	var validUpperCase = /[A-Z]/;	
	var validLowerCase = /[a-z]/;
	
	if ( !validNumeric.test(password)){
	  return false;
	 }
	 
	 if ( !validUpperCase.test(password)){
	 return false;
	 }
	 
	 if (!validLowerCase.test(password)) {
	  return false;
	  }
	  
	  return true;
	}

function isValidAlphaNumeric(field)
{
	var validChars = /[^A-Za-z0-9]/;
	if ( validChars.test(field) ) { return false; } else { return true; }
}

function beginsWithNumeral(alpNm)
{
	var regEx = /^[a-zA-Z][a-zA-Z0-9]/i;
	if ( regEx.test(alpNm) ) { return false; } else { return true; }
}

<!--Collapsable Section Script Begins-->
// pass in true for noBlock if being used with a non-block level tag
function dsp(loc, noBlock){
   if(document.getElementById){
      var foc=loc.firstChild;
      foc=loc.firstChild.innerHTML?
         loc.firstChild:
         loc.firstChild.nextSibling;
      foc.innerHTML=foc.innerHTML=='+'?'-':'+';
      foc=loc.parentNode.nextSibling.style?
         loc.parentNode.nextSibling:
         loc.parentNode.nextSibling.nextSibling;
         if (noBlock) {
      		foc.style.display=foc.style.display==''?'none':'';
      	} else {
      		foc.style.display=foc.style.display=='block'?'none':'block';
      	}
      }}

<!--Collapsable Section Script Ends-->

<!--Collapsable Section (no +/-) Script Begins-->
//pass in true for noBlock if being used with a non-block level tag
function dspnp(loc, noBlock){
if(document.getElementById){

    var foc=loc.firstChild;
    foc=loc.firstChild.innerHTML?
        loc.firstChild:	
        loc.firstChild.nextSibling;
        foc.innerHTML=foc.innerHTML=='+'?'-':'+';
        foc = loc.parentNode.nextSibling.nextSibling.nextSibling.nextSibling;
   	if (noBlock) {
   		foc.style.display=foc.style.display==''?'none':'';
   	  } else {
   		foc.style.display=foc.style.display=='block'?'none':'block';
   	  }
   }}

<!--Collapsable Section (no +/-) Script Ends-->

<!--Help Text Pop up Boxes-->
/** js/jquery function to display help text. Pass in parameters for box positioning, box width, and div names.
  note the script below should be placed on the jsp and a div structure with an id of 'helpDiv' is required.
  If multiple help boxes are required on the page, then you will need unique div ids and ids for the close a href.
  Currently, CSS styling only exists for the helpDiv div.

$(document).ready(function(){
	
  	$(function() {
		$('#hide').click(function() {
			$('#helpDiv').hide(400);
		});
   	});
 });
 */
 // function takes IE and FF left/top positions, text box width, div name of text box and an inner div name to 
 //display close link
function show_help(ieL, ieT, ffL, ffT, boxWidth, divName, innerDiv) {
   $(function() {
	
		if ( $.browser.msie ) {
			$(divName).css({ position: "absolute", left: ieL, top: ieT });
		} else {
			$(divName).css({ position: "absolute", left: ffL, top: ffT });
		}
		
		$(divName).width(boxWidth);
		$(innerDiv).width(30);
		$(innerDiv).css({ float: "right", margin: "8" });
		$(divName).show(400); //400 indicates milliseconds to open, increase/decrease to change effect
	 
   });
 }
 
 <!--End Help Text Pop up Boxes-->
 
 function showConfirm(employeeId, fName, lName, rel, hide, hideDob, language) {
	   var empId = document.getElementById('empId');
	   var firstName = document.getElementById('fName');
	   var lastName = document.getElementById('lName');
	   //HMA currently does not have relationship as part of registration (rel == 'none')
	   if (rel != "none") { 
		   var relationship = document.getElementById('rel');
	   }
	   var dobDay = document.ValidateUserInfoForm.dateOfBirthDd.value;
	   var dobYear = document.ValidateUserInfoForm.dateOfBirthYyyy.value;
	   
	   var fullTextMonth = getFullTextMonth(document.ValidateUserInfoForm.dateOfBirthMm.value, language);
	   var blank = '*********';
	   
	   document.ValidateUserInfoForm.backBtn.disabled = true;
	   
	   if (hide == "true") {
	   		empId.innerHTML=blank;
	   } else {
		   empId.innerHTML=employeeId;
	   }	
	   firstName.innerHTML=fName;
	   lastName.innerHTML=lName;
	   if (rel != "none") {
	   		relationship.innerHTML=rel;
 	   }
	   if (hideDob == "false") {
		   birthDate.innerHTML=fullTextMonth + ' ' + dobDay + ', ' + dobYear; 
	   }
 	   
	   document.getElementById('light').style.display='block';
	   document.getElementById('fade').className='black_overlay';
	   //IE 6.0 select box appearing on top regardless of z index fix
	   if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
		   if (rel != "none") { 
			   document.getElementById('relationship').style.display='none';
		   }
		   document.getElementById('suffixId').style.display='none';
	   }
	   		
	 }
 
 function closeBox(close, rel) {
	 document.ValidateUserInfoForm.backBtn.disabled = false;
	   
	   if (close) {
		   document.getElementById('light').style.display='none';
		   document.getElementById('fade').className='';
		   if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
			   if (rel == "yes") { 
				   document.getElementById('relationship').style.display='block';
			   }
			   document.getElementById('suffixId').style.display='block';
		   }
	   }
	   if (!close) {
		   document.getElementById('light').style.display='none';
		   document.getElementById('fade').className='';
		   if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
			   if (rel == "yes") { 
				   document.getElementById('relationship').style.display='block';
			   }
			   document.getElementById('suffixId').style.display='block';
		   }
		   document.getElementById('registerForm').submit();
		   
	   }
 }
 
 function getFullTextMonth(month, language) {
	 
	 if (language == 1) {
		 switch(month)
		 {
		 case '1':
		 case '01':
		   return 'January';
		   break;
		 case '2':
		 case '02':
		   return 'Februray';
		   break;
		 case '3':
		 case '03':
		   return 'March';
		   break;
		 case '4':
		 case '04':
		   return 'April';
		   break;
		 case '5':
		 case '05':
		   return 'May';
		   break;
		 case '6':
		 case '06':
		   return 'June';
		   break;
		 case '7':
		 case '07':
		   return 'July';
		   break;
		 case '8':
		 case '08':
		   return 'August';
		   break;
		 case '9':
		 case '09':
		   return 'September';
		   break;
		 case '10':
		   return 'October';
		   break;
		 case '11':
		   return 'November';
		   break;
		 case '12':
		   return 'December';
		   break;
		 default:
		   return 'Recheck month entered!';
		 }
	 }
	 
	 if (language == 2) {
		 switch(month)
		 {
		 case '1':
		 case '01':
		   return 'enero';
		   break;
		 case '2':
		 case '02':
		   return 'febrero';
		   break;
		 case '3':
		 case '03':
		   return 'marzo';
		   break;
		 case '4':
		 case '04':
		   return 'abril';
		   break;
		 case '5':
		 case '05':
		   return 'mayo';
		   break;
		 case '6':
		 case '06':
		   return 'junio';
		   break;
		 case '7':
		 case '07':
		   return 'julio';
		   break;
		 case '8':
		 case '08':
		   return 'agosto';
		   break;
		 case '9':
		 case '09':
		   return 'septiembre';
		   break;
		 case '10':
		   return 'octubre';
		   break;
		 case '11':
		   return 'noviembre';
		   break;
		 case '12':
		   return 'diciembre';
		   break;
		 default:
		   return 'Recheck month entered!';
		 }
	 }
	 
}
 
