function checkValidBA(){
		var index = document.jobFinder.recBusinessArea.selectedIndex;
		var ba = document.jobFinder.recBusinessArea.options[index].value;
		if(ba==1010101010) {
			alert("You must select a valid BUSINESS AREA to search through");
		} else {
			document.jobFinder.submit();
		}
}

function grabRegionRole(url,region){
		var baindex = document.jobFinder.recBusinessArea.selectedIndex;
		var ba = document.jobFinder.recBusinessArea.options[baindex].value;
		//var roleindex = document.jobFinder.recRole.selectedIndex;
		//var role = document.jobFinder.recRole.options[roleindex].value;
		if(ba==1010101010) {
			alert("You must select a valid BUSINESS AREA to search through");
		} else {
			window.location=url + "?recRegion=" + region + "&recRole=0&recBusinessArea=" + ba;
		}
	}

function openNewWin(winURL,winName,winFeature){
    var newWin = window.open(winURL,winName,winFeature);
}

function changeButtonImage(butID, butImg) {
        document.getElementById(butID).src=butImg
}

function createPopup(title,width,height,url) {
	     var options = 'toolbar=no,titlebar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,fullscreen=no,scrollbars=yes,top=10,left=10,screenX=10,screenY=10,width=' + width + ',height=' + height;
	     window.open(url,title,options)
}
var nothingSelected = "OxyBox : Error:nPlease make sure you select an element beforenusing the management icons";
var alreadySelected = "OxyBox : Error:nThis already exists in the destination, we can'tnhave two the same now can we?";
var nonSelectable = "OxyBox : Error:nThis element is non-selectable. It cannot be added";
var unableToDelete = "OxyBox : Error:nThis element is unable to be removed from this area";
var cannotView = "OxyBox : Please Select a VALID Element before trying to view this preview";
var selectElementBeforeClick = "OxyBox : Please Select a VALID Element before pressing this button";
var oneSelectOnly = "OxyBox : You can only select ONE element for this menu. You already have an element in your destination window,nPlease remove it before trying to add another";
function CheckArray(source,value) {
		for(i=0; i<source.options.length; i++) {
			if (source.options[i].value == value) {intReturn=1; return true;}
		}
		intReturn=0;
		return false;
}
	function addOption(source,destination,hidden) { 
		var index = source.selectedIndex;
		with(source) {
			if(value!="" && value!=null) {
				destination[destination.length]= new Option(value,value);
				hidden.value+= "," + value; /* insert data into the hidden field lurking somewhere in the form */
				value="";
			}
			
		}
	} 
	function removeOption(hidden,source) {
		with(source) {
			if(selectedIndex>=0 ) {
				options[selectedIndex]=null;
				var hiddenStr = "";
				for(var i=0; i<source.options.length; i++) {
					hiddenStr = hiddenStr + source.options[i].value + ",";
				}
				hidden.value = hiddenStr;
			}
		}
	}
	function addElement(source,destination,hidden){
		var index = source.selectedIndex;
		var destination = destination;
		var hidden = hidden;
		if(index <0 ) {	// nothing selected
				alert(nothingSelected);
		} else {
		for(var i=0; i<source.options.length; i++) {
			if (source.options[i].selected) {
				var srcValue = source.options[i].value;
				var srcText = source.options[i].text;
					if (srcValue == "0") {
						alert(nonSelectable); 
						return;
					} else if (CheckArray(destination, srcValue)) {
						alert(alreadySelected); 
						return;
					}
				}
		}
		var objOption = new Option(source.options[index].text,source.options[index].value);
		destination.options[destination.options.length+1];
		destination.options[destination.options.length] = objOption;
		hidden.value+= "," + source.options[index].value; /* insert data into the hidden field lurking somewhere in the form */
		source.options[index] = null;
		}
}
function clearOptions(source) {
	for(i=source.options.length; i>-1; i--) {
		source.options[i] = null;
	}
}
function addHiddenVars(hidden,vars) {
	var hidden = hidden;
	var vars = vars;
	hidden.value=vars;
} 
function rmElement(source,destination,hidden){
	var index = source.selectedIndex;
	var hidden = hidden;
	if(index <0 ) {	// nothing selected
		alert(unableToDelete);
	} else {
		var objOption = new Option(source.options[index].text,source.options[index].value);
		destination.options[destination.options.length+1];
		destination.options[destination.options.length] = objOption;
		source.options[index] = null;
	}
	/* re-populate the hidden field with new shorted id array */
	var hiddenStr = "";
	for(var i=0; i<source.options.length; i++) {
		hiddenStr = hiddenStr + source.options[i].value + ",";
	}
	hidden.value= hiddenStr;
}
function changeIconStatus(statusChange,imageName,value,functionname) {
	var id=statusChange;
	 document.images[imageName].src=value;
   	if(functionname=='') {
   	 if (document.getElementById) {
     	x = document.getElementById(id);
        x.innerHTML = "<IMG SRC=" + value + ">";
     } else if (document.all) {
        x = document.all[id];
        x.innerHTML = "<IMG SRC=" + value + ">";
     } 
	setTimeout("submitOxyboxForm()",1000); 
	} else {
	eval(functionname);
	}
}
function submitOxyboxForm() {
	document.forms[0].submit();
}
function changeBackIconStatus(statusChange,imageName,value,url) {
	 var id=statusChange;
	 document.images[imageName].src=value;
   	 if (document.getElementById) {
     	x = document.getElementById(id);
        x.innerHTML = "<IMG SRC=" + value + ">";
     } else if (document.all) {
        x = document.all[id];
        x.innerHTML = "<IMG SRC=" + value + ">";
     } 
	window.location=url;
	
}
/* Load up the nav rollover images */
if (document.images){
  preload_image_object = new Image();
  // set image url
  image_url = new Array();
  image_url[0] = "/assets/1123/home_on.gif";
  image_url[1] = "/assets/1123/jobfinder_on.gif";
  image_url[2] = "/assets/1123/our_roles_on.gif";
  image_url[3] = "/assets/1123/about_us_on.gif";
  image_url[3] = "/assets/1123/about_you_on.gif";
  image_url[3] = "/assets/1123/downloads_on.gif";
   var i = 0;
   for(i=0; i<=3; i++) 
	 preload_image_object.src = image_url[i];
}


function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}

/* Registration scripts */

function killEnter(e){
e = e? e : window.event;
var k = e.keyCode? e.keyCode : e.which? e.which : null;
if (k == 13){
if (e.preventDefault)
e.preventDefault();
return false;
};
return true;
};
if(typeof document.addEventListener!='undefined')
document.addEventListener('keydown', killEnter, false);
else if(typeof document.attachEvent!='undefined')
document.attachEvent('onkeydown', killEnter);
else{
if(document.onkeydown!=null){
var oldOnkeydown=document.onkeydown;
document.onkeydown=function(e){
oldOnkeydown(e);
killEnter(e);
};}
else
document.onkeydown=killEnter;
}


function checkUserName(userName){
    var ajaxRequest;  // The variable that makes Ajax possible!    
	document.getElementById('spinner').style.display='block';
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("There seems to be an issue with your browser");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
	       document.getElementById('spinner').style.display='none';
            if(ajaxRequest.responseText.search(/OK/)==2){
            	document.getElementById('response').innerHTML = "";
				ReverseDisplay('regStage02');
				ReverseDisplay('regStage03');           
	       } else {
	           document.getElementById('response').innerHTML = ajaxRequest.responseText;
	       }
        }
    }
    var queryString = "?userName=" + userName +"&rand="+ Math.floor(Math.random() * 9999);
    var queryFile = "/admin/tmp/tmp.html" + queryString;
    ajaxRequest.open("GET", queryFile, true);
    ajaxRequest.send(null); 
}


function validate_required(field,alerttxt){
	with (field){
	   if (value==null||value==""){
	       alert(alerttxt);
	       return false;
	   } else {
	       return true
	   }
	}
}


function validate_email(field,alerttxt){
	with (field){
	   apos=value.indexOf("@");
	   dotpos=value.lastIndexOf(".");
	   if (apos<1||dotpos-apos<2) {
	       alert(alerttxt);
	       return false;
	   } else {
	       return true;
	   }
	}
}

function appStage02(){
	var lc= theForm.userName.value;
	var lcemail=lc.toLowerCase();
	theForm.userName.value = lcemail;
	var lc= theForm.verify_userName.value;
	var lcemail=lc.toLowerCase();
	theForm.verify_userName.value = lcemail;
	with (theForm){
	   if(validate_required(userName,"Please enter your email address")==false){
	       userName.focus();
	       return false;
	   } else if(validate_required(verify_userName,"Please verify your email address")==false){
	       verify_userName.focus();
	       return false;
	   } else if(validate_email(userName,"Your email is not a valid e-mail address!")==false){
	       userName.focus();
	       return false;
	   } else if(theForm.userName.value!=theForm.verify_userName.value){
	       alert("The email addresses you entered do not match");
	       userName.focus();
	       return false;
	   } else if(validate_required(passWord,"Please enter your password")==false){
	       passWord.focus();
	       return false;
	   } else if(validate_required(verify_passWord,"Please verify your password")==false){
	       verify_passWord.focus();
	       return false;
	   } else if(theForm.passWord.value!=theForm.verify_passWord.value){
	       alert("The passwords you entered do not match");
	       passWord.focus();
	       return false;
	   } else if(validate_required(preferredName,"Please enter your first name")==false){
	       preferredName.focus();
	       return false;
	   } else if(validate_required(surname,"Please enter your surname")==false){
	       surname.focus();
	       return false;
	   } else if(validate_required(passWordReminder,"Please enter a password reminder")==false){
	       passWordReminder.focus();
	       return false;
	   } 
	} 
	checkUserName(theForm.userName.value);	
}

function appStage03(){
	with (theForm){
	       
	   if(validate_required(app_12,"Please enter your  address")==false){
	       app_12.focus();
	       return false;
	   } else if(validate_required(app_13,"Please enter your town")==false){
	       app_13.focus();
	       return false;
	   } else if(validate_required(app_15,"Please enter your postcode")==false){
	       app_15.focus();
	       return false;
	   } else if(validate_required(app_55,"Please enter a contact number")==false){
	       app_55.focus();
	       return false;
	   } else if(!theForm.app_57[0].checked&&!theForm.app_57[1].checked){
	       alert("Please tell us if you have applied in the past");
	       elements["app_57"][1].focus();
	       return false;
	   } else if(!theForm.app_59[0].checked&&!theForm.app_59[1].checked){
	       alert("Please tell us if we have employed you previously");
	       elements["app_59"][1].focus();
	       return false;
	   } else if(!theForm.app_61[0].checked&&!theForm.app_61[1].checked){
	       alert("Please let us know if you require a permit to work in the EU");
	       elements["app_61"][1].focus();
	       return false;
	   } else if(!theForm.app_65[0].checked&&!theForm.app_65[1].checked){
	       alert("Please confirm that you are over 16");
	       elements["app_65"][1].focus();
	       return false;
	   } else if(validate_required(app_347,"Please state your current/last employer")==false){
	       app_347.focus();
	       return false;
	   } else if(validate_required(app_348,"Please state your current/last job title ")==false){
	       app_348.focus();
	       return false;
	   } else if(validate_required(app_81,"Please state your current/last salary")==false){
	       app_81.focus();
	       return false;
	   } 
	} 
	ReverseDisplay('regStage03');
	ReverseDisplay('regStage04');
}

function appStage04(){
	with (theForm){
	   if(validate_required(recCVUpload,"Please upload your CV")==false){
	       recCVUpload.focus();
	       return false;
	   } 
	
	} 
	ReverseDisplay('regStage04');
	ReverseDisplay('regStage05');
}

function submitApp(){
	document.profileform.submit();
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 
window.onload = externalLinks;