/****************************************************************************************
	CODE	property of Capitol Technologies all rights reserved. 
				code date: March 4/2008
				written by: Jack Ivanisevic
				revision date: March 25/2008
				revision done by: Jack Ivanisevic
				revision(s) performed: 
*****************************************************************************************/

var blnViewAll = false;	 // Boolean to check whether or not all the departments are selected.

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkemail(frmField){
e=frmField
var returnval=emailfilter.test(e.value)
return returnval
}


function searchOpts(intChk)
/****************************************************************************************
	Checks to job search form to see if the user wants to include all the departments 
	available. in their search. If they selcet view all then all the check boxes will 
	automatically be marked with a check mark. If they select a single department the 
	function makes sure that the view all check box is not checked and leaves any 
	other checkboxes in their current state.
****************************************************************************************/
{
var chkBoxes = document.frmSearch.chksearchDept.length - 1

if(intChk == chkBoxes)
{
		if(blnViewAll==false)
		{
		blnViewAll = true;	
		
		if(document.frmSearch.chksearchDept[chkBoxes].checked == true)
				{
		
					for(x=0;x<=chkBoxes;x++)
						{
							document.frmSearch.chksearchDept[x].checked = true
						}
				}
		}
		else
		{
			blnViewAll = false
			for(x=0;x<=chkBoxes;x++)
				{
					document.frmSearch.chksearchDept[x].checked = false
				}

		}
}
else
{
	document.frmSearch.chksearchDept[chkBoxes].checked = false
	blnViewAll = false;	
}
return true;
}
//***************************************************************************************

function searchOptsModal(intChk)
/****************************************************************************************
	Checks to job search form to see if the user wants to include all the departments 
	available. in their search. If they selcet view all then all the check boxes will 
	automatically be marked with a check mark. If they select a single department the 
	function makes sure that the view all check box is not checked and leaves any 
	other checkboxes in their current state.
****************************************************************************************/
{
var chkBoxes = document.frmSearchModal.chksearchDept.length - 1

if(intChk == chkBoxes)
{
		if(blnViewAll==false)
		{
		blnViewAll = true;	
		
		if(document.frmSearchModal.chksearchDept[chkBoxes].checked == true)
				{
		
					for(x=0;x<=chkBoxes;x++)
						{
							document.frmSearchModal.chksearchDept[x].checked = true
						}
				}
		}
		else
		{
			blnViewAll = false
			for(x=0;x<=chkBoxes;x++)
				{
					document.frmSearchModal.chksearchDept[x].checked = false
				}

		}
}
else
{
	document.frmSearchModal.chksearchDept[chkBoxes].checked = false
	blnViewAll = false;	
}
return true;
}
//***************************************************************************************

function chkFrm()
/****************************************************************************************
	Checks to job search form to see if a km distance range was selected. If it was
	then make sure that they have netered a starting postal code. If a postal code 
	has been entered then check to make sure that a km range has been selected.
****************************************************************************************/
{
if((document.frmSearch.optKM[0].checked || document.frmSearch.optKM[1].checked ||document.frmSearch.optKM[2].checked || document.frmSearch.optKM[3].checked ) && document.frmSearch.txtPostal.value.length == 0)
	/*	One of the distance ranges have been selected but no postal code has been entered */
	{
		alert("You must provide a starting point postal code to use the distance range functionality as search criteria.");
		document.frmSearch.txtPostal.focus();
		return false;
	}

if(document.frmSearch.txtPostal.value.length > 0 )
	/*	Postal code has been entered */
{
		if(document.frmSearch.txtPostal.value.indexOf(" ") > -1)
			/* Postal code has a space in it. Make sure it is 7 characters in length */
			{	
				if(document.frmSearch.txtPostal.value.length != 7)
					{
						alert("Please provide a valid starting point postal code to use this functionality.");
						document.frmSearch.txtPostal.focus();
						return false;
					}
			}
		else
		/* Postal code has no space in it. Make sure it is 6 characters in length */
			{
				if(document.frmSearch.txtPostal.value.length != 6 )
					{
						alert("Please provide a valid starting point postal code to use this functionality.");
						document.frmSearch.txtPostal.focus();
						return false;
					}
			}
			
		if(!document.frmSearch.optKM[0].checked && !document.frmSearch.optKM[1].checked && !document.frmSearch.optKM[2].checked && !document.frmSearch.optKM[3].checked)
		/* Postal code has a space in it. Make sure it is 7 characters in length */
							{
								alert("You must select a distance range to use this funcitonality as search criteria.");
								document.frmSearch.optKM[0].focus();
								return false;
							}
}

return true;
}
//***************************************************************************************

function chkFrmModal()
/****************************************************************************************
	Checks to job search form to see if a km distance range was selected. If it was
	then make sure that they have netered a starting postal code. If a postal code 
	has been entered then check to make sure that a km range has been selected.
****************************************************************************************/
{
if((document.frmSearchModal.optKM[0].checked || document.frmSearchModal.optKM[1].checked ||document.frmSearchModal.optKM[2].checked || document.frmSearchModal.optKM[3].checked ) && document.frmSearchModal.txtPostal.value.length == 0)
	/*	One of the distance ranges have been selected but no postal code has been entered */
	{
		alert("You must provide a starting point postal code to use the distance range functionality as search criteria.");
		document.frmSearchModal.txtPostal.focus();
		return false;
	}

if(document.frmSearchModal.txtPostal.value.length > 0 )
	/*	Postal code has been entered */
{
		if(document.frmSearchModal.txtPostal.value.indexOf(" ") > -1)
			/* Postal code has a space in it. Make sure it is 7 characters in length */
			{	
				if(document.frmSearchModal.txtPostal.value.length != 7)
					{
						alert("Please provide a valid starting point postal code to use this functionality.");
						document.frmSearchModal.txtPostal.focus();
						return false;
					}
			}
		else
		/* Postal code has no space in it. Make sure it is 6 characters in length */
			{
				if(document.frmSearchModal.txtPostal.value.length != 6 )
					{
						alert("Please provide a valid starting point postal code to use this functionality.");
						document.frmSearchModal.txtPostal.focus();
						return false;
					}
			}
			
		if(!document.frmSearchModal.optKM[0].checked && !document.frmSearchModal.optKM[1].checked && !document.frmSearchModal.optKM[2].checked && !document.frmSearchModal.optKM[3].checked)
		/* Postal code has a space in it. Make sure it is 7 characters in length */
							{
								alert("You must select a distance range to use this funcitonality as search criteria.");
								document.frmSearchModal.optKM[0].focus();
								return false;
							}
}

return true;
}
//***************************************************************************************

function LoginPrompt(strFunction)
{
/****************************************************************************************
	Pops up the modal window for help topics and sign in. strFuntion is used for the
	title name of the help popup window.
****************************************************************************************/
	loginreqwindow=dhtmlmodal.open('loginreqbox', 'div', 'modalLogin', strFunction, 'width=400px,height=180px,left=250px,top=300px,center=1,resize=0,scrolling=0')
}
//****************************************************************************************

function SearchPrompt()
{
/****************************************************************************************
	Pops up the modal window for help topics and sign in. strFuntion is used for the
	title name of the help popup window.
****************************************************************************************/
	searchreqwindow=dhtmlmodal.open('searchbox', 'div', 'modalSearch', "Search Job Opportunities", 'width=400px,height=300px,left=250px,top=300px,center=1,resize=0,scrolling=0')
}
//****************************************************************************************

function chkLogin()
{
/****************************************************************************************
	Make sure that the login form has been filled out.
****************************************************************************************/
if(document.frmLogin.txtUName.value.length == 0)
	{
	// Make sure there is a username
		alert("Please enter your user name to log in. \n\nHint: your user name is your email address.");
		document.frmLogin.txtUName.focus();
		return false;
	}
	
if(document.frmLogin.txtUPass.value.length == 0 || document.frmLogin.txtUPass.value.length < 4 || document.frmLogin.txtUPass.value.length >12)
	{
	// Make sure there is a password
		alert("Your password must be between 4 and 12 characters in length. \n\nPlease enter your password or click on the forgot my password link below.");
		document.frmLogin.txtUPass.focus();
		return false;
	}
	
return true;
}
//***************************************************************************************

function Process_Login(whichbutton)
/****************************************************************************************
	Process the data that the user entered when trying to login
****************************************************************************************/
{
	if (whichbutton=="L")
		{
		document.location.href = "register.asp"
		}
	if (whichbutton=="login")	
		{
		document.location.href = "login.asp"
		}
	loginreqwindow.hide()
}
//****************************************************************************************


function HelpPrompt(strFunction,intTopic)
{
/*****************************************************************************************
	Popup help window. 
	strFunction = Title bar of the window, usually what you are looking for help with.
	intTopic = which help text to display
******************************************************************************************/
	strFunction =strFunction + "  -  Help";
	HelpWindow=dhtmlmodal.open('helpwindow', 'div', 'modalHelpDiv', strFunction, 'width=400px,height=250px,left=250px,top=300px,center=1,resize=0,scrolling=0')
	document.getElementById('HelpContents').innerHTML = ""
	switch (intTopic) 
	{ 
   		case 1 :  			// Search Help
      		document.getElementById('HelpContents').innerHTML = '<img src="images/Question.gif" align="absmiddle">&nbsp;<span class="normal">The advanced search options allow you to further filter the results that are returned when searching for a career.<BR><BR>Position/Title : You may enter a position or title name or any part of either<BR><BR>Distance Options: Select a distance by clicking on one of the predefined ranges then enter a postal code as the center point for the distance radius. Your home postal code is a suggested starting point.</p></span>'
      		break; 

		case 2 : 			// 
      		document.getElementById('HelpContents').innerHTML = '<img src="images/Question.gif" align="absmiddle">&nbsp;<span class="normal"> </span>'
      		break; 
			
		case 3 : 			// Logoff page form submission incomplete
      		document.getElementById('HelpContents').innerHTML = '<img src="images/Critical.gif" align="absmiddle">&nbsp;<span class="normal">Please enter your comments and/or suggestions prior to trying to submit this form.</span>'
      		break; 
			
		case 4 : 			// Contact us page form submission incomplete
      		document.getElementById('HelpContents').innerHTML = '<img src="images/Critical.gif" align="absmiddle">&nbsp;<span class="normal">Please fill out all the fields, your name, your email address and the question or comment that you have for us prior to trying to submit this form.</span>'
      		break; 

		case 5 : 			// Contact us page form submission incomplete email address problem
      		document.getElementById('HelpContents').innerHTML = '<img src="images/Critical.gif" align="absmiddle">&nbsp;<span class="normal">You must provide us with a valid email address for yourself to send a question or comment to us. <BR><BR>You have either forgotten to enter your email address or the one you have supplied does not seem to be valid. <BR><BR>Please enter or fix your emaill addresss and try again.<BR></span>'
      		break; 
			
		default :
			break;
	}

}
//****************************************************************************************


function chkContact()
/*****************************************************************************************
	Check the contact us page form submission
******************************************************************************************/
{
	if (document.frmContact.txtName.value.length==0)
		{
			HelpPrompt("Data Missing",4)
			return false;
		}
	if(document.frmContact.txtEmail.value.length==0)
		{
			HelpPrompt("Data Missing",5)
			return false;
		}
	blnEmail = checkemail(document.frmContact.txtEmail)
	if (blnEmail == false)
		{
			HelpPrompt("Data Missing",5)
			return false;
		}
	if(document.frmContact.txtQuestion.value.length==0)
		{
			HelpPrompt("Data Missing",4)
			return false;
		}		
	return true;
}
//****************************************************************************************


/*****************************************************************************************
	Macromedia added functions
*****************************************************************************************/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//*****************************************************************************************

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characters remaining on your input limit'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  left=(screen.availWidth - width) / 2
  top = (screen.availHeight - height) /2
  
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
