﻿/* --== KIN-TEC JAVASCRIPT - ASL/JMM 5 Jun 2009 ==-- */
/* To be included at the bottom of the page - after ctrl.ClientID section */

var isIE=false;
if(document.all)isIE=true;

// Detects if the enter button was pressed
function enterPressed(event){ var kc=(isIE)?event.keyCode:event.which; return(kc==13); }

// Requires var txtENewsletter = document.getElementById('<%=txtENewsletter.ClientID%>') in the masterpage
function validateENewsleter()
{
	if(txtENewsletter.className.indexOf(' error')) txtENewsletter.className = txtENewsletter.className.replace(' error','');
	
	if(!isEmailAddress(txtENewsletter.value)){
		txtENewsletter.className += ' error';
		alert('Please enter a valid email address');
		txtENewsletter.focus();
		return false;
	}

	return true;
}

// Requires:
// var txtUsername = document.getElementById('<%=txtUsername.ClientID%>')
// var txtPassword = document.getElementById('<%=txtPassword.ClientID%>')
// var loginUrl = "???";
// in the masterpage.
function validateLogin()
{
	if(txtUsername.className.indexOf(' error'))
		txtUsername.className = txtUsername.className.replace(' error','');
		
	if(txtPassword.className.indexOf(' error'))
		txtPassword.className = txtPassword.className.replace(' error','');

	if(trim(txtUsername.value)==''){
		txtUsername.className += ' error';
		alert('Please enter a User Name');
		txtUsername.focus();
		return false;
	}

	if(trim(txtPassword.value)==''){
		txtPassword.className += ' error';
		alert('Please enter a Password');
		txtPassword.focus();
		return false;
	}

	if(typeof(loginUrl)=="undefined" || loginUrl==''){
		alert('Setup error - The login url has not been configured');
		return false;
	}

	// Generate a form and submit it!!!
	var submitForm = document.createElement("FORM");
	submitForm.method = "POST";
	submitForm.action = loginUrl;
	document.body.appendChild(submitForm);

	createNewFormElement(submitForm, "txtUsername", txtUsername.value);
	createNewFormElement(submitForm, "txtPassword", txtPassword.value);
	createNewFormElement(submitForm, "postForm", "1");

	submitForm.submit();	

	return false;  // Prevent the default form action...
}

// helper function to add elements to the form
// (http://en.allexperts.com/q/Javascript-1520/create-form-submit-fly.htm)
function createNewFormElement(inputForm, elementName, elementValue){
	var newElement = document.createElement("<input name=\""+elementName+"\" type=\"hidden\" />");
	inputForm.appendChild(newElement);
	newElement.value = elementValue;
	return newElement;
}


// Requires:
// var ddlDiscipline = document.getElementById('<%=ddlDiscipline.ClientID%>');
// var ddlIndustry = document.getElementById('<%=ddlIndustry.ClientID%>');
// var ddlLocation = document.getElementById('<%=ddlLocation.ClientID%>');
// var chkPermanent = document.getElementById('<%=chkPermanent.ClientID%>');
//	var chkContract = document.getElementById('<%=chkContract.ClientID%>');
// in the masterpage.
function submitSearchPanel(resultsPagePath)
{
	var discipline = ddlDiscipline.options[ddlDiscipline.selectedIndex].value;
	var industry = ddlIndustry.options[ddlIndustry.selectedIndex].value;
	var location = ddlLocation.options[ddlLocation.selectedIndex].value;
	var permanent = chkPermanent.checked ? 1 : '';
	var contract = chkContract.checked ? 1 : '';
	
	var resultsPagePath = resultsPagePath + '?industry=' + industry +  '&discipline=' + discipline + '&location=' + location + '&permanent=' + permanent + '&contract=' + contract;
	
	//alert('Redirect not ready:\n' + resultsPagePath + '?discipline=' + discipline + '&industry=' + industry + '&location=' + location + '&permanent=' + permanent + '&contract=' + contract);
	window.open( resultsPagePath, '_self' );
}

// jQuery Scrolling Jobs - requires jQuery.js to have already been imported into the page.
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function(){
  headline_count = $("div.jobsScrollerItem").size();
  $("div.jobsScrollerItem:eq("+current_headline+")").css('top', '5px');
  
  headline_interval = setInterval(headline_rotate,5000); 
  $('div#jobsScroller').hover(function() {
    clearInterval(headline_interval);
  }, function() {
    headline_interval = setInterval(headline_rotate,5000); 
    headline_rotate();
  });
});

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count; 
  $("div.jobsScrollerItem:eq(" + old_headline + ")")
    .animate({top: -205},"slow", function() {
      $(this).css('top', '210px');
    });
  $("div.jobsScrollerItem:eq(" + current_headline + ")")
    .animate({top: 5},"slow");  
  old_headline = current_headline;
}