<!--
// Script Library for General Use Javascript functions.
// All code remains the property of Kim Holland : info@tripleaxis.com for details

// Nav Bar Header Scripts...
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		homebutton_over = newImage("images/homebutton-over.jpg");
		searchbutton_over = newImage("images/searchbutton-over.jpg");
		registerbutton_over = newImage("images/registerbutton-over.jpg");
		detailsbutton_over = newImage("images/detailsbutton-over.jpg");
		agenciesbutton_over = newImage("images/agenciesbutton-over.jpg");
		advicebutton_over = newImage("images/advicebutton-over.jpg");
		faqbutton_over = newImage("images/faqbutton-over.jpg");
		contactbutton_over = newImage("images/contactbutton-over.jpg");
		preloadFlag = true;
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// End Nav Bar Header Scripts

function SSave(){
	if (arguments.length>0){
		QStr = "";
		for(i=0;i<arguments.length;i+=2) QStr+= arguments[i] + "=" + arguments[(i+1)] + "&";
		location='MySearches.asp?Action=Save&' + QStr;
	} else {
		alert('No search to save');
	}
}

function ChkUserForm(){
	var ErrorStr = '';
	var Obj = document.forms[0].elements;
	for (i=0;i<Obj.length;i++)
	{
		if ( Obj[i].value == '' &&
			 Obj[i].name != 'cv' ||
			 Obj[i].value == 'please select' ) ErrorStr += '• ' + Obj[i].name.replace(/_/g, ' ') + '\r';

		if ( Obj[i].name == 'Desired_Location' &&
			 Obj[i].value == '' &&
			 Obj.Desired_Location_Keyword.value == 'Enter Location Keyword' ) ErrorStr += '• Desired Location' + '\r';
	}

	// Check for valid email.
	if (!isEmail(Obj.Email_Address.value) && Obj.Email_Address.value) ErrorStr +=  '• Email Address is not a valid email address.\r'
	if (ErrorStr) {
		alert ('The following information was missing :\r\r' + ErrorStr);
		return false;
	}
	return true;
}

function ChkForm(){
	var ErrorStr = '';
		var Obj = document.forms[0].elements;
		for (i=0;i<Obj.length;i++){
			if (Obj[i].value == '' && Obj[i].type != 'hidden' && Obj[i].name != 'CharCount') {
				ErrorStr += '• ' + Obj[i].name.replace(/_/g, ' ') + '.\r';
			}
		}
		if (ErrorStr) {
			alert ('The following information was missing :\r\r' + ErrorStr);
			return false;
		}
		return true;
}

function ChkNewJobForm(){
	var ErrorStr = '';
	var Obj = document.forms[0].elements;
	var aExcludes = ['Duration','CharCount'];
	for (i=0;i<Obj.length;i++){
		var Xc = false;
		for (j=0;j<aExcludes.length;j++) if (Obj[i].name == aExcludes[j]) Xc = true;
		if (Obj[i].value == '' &&
			Obj[i].type != 'hidden' &&
			Obj[i].name != 'Desired_Location' &&
			Obj[i].name != 'final_locations' &&
			Obj[i].name != 'source_locations' &&
			!Xc ) ErrorStr += '• ' + Obj[i].name.replace(/_/g, ' ') + '.\r';

		if ( Obj[i].name == 'Desired_Location' &&
			 Obj[i].value == '' &&
			 Obj.Desired_Location_Keyword.value == 'Enter Location Keyword' ) ErrorStr += '• Desired Location' + '\r';
	}
	// Check for valid email.
	if ( Obj.Contact_Email.value && !isEmail(Obj.Contact_Email.value)) ErrorStr +=  '• Contact Email is not a valid email address.'
	if (ErrorStr) {
		alert ('The following information was incorrect / missing :\r\r' + ErrorStr);
		return false;
	}
	return true;
}

function ChkAdminAgencyForm(){
	var aExcludes = ['Address_Line_2','Address_Line_3'];
	var ErrorStr = '';
    var Obj = document.forms[0].elements;
		for (i=0;i<Obj.length;i++){
			var Xc = false;
			for (j=0;j<aExcludes.length;j++) if (Obj[i].name == aExcludes[j]) Xc = true;
			if (Obj[i].value == '' && Obj[i].type != 'hidden' && !Xc) {
				ErrorStr += '• ' + Obj[i].name.replace(/_/g, ' ') + '.\r';
			}
		}
		// Check for valid email.
		if (!isEmail(Obj.Main_Contact_Email.value) && Obj.Main_Contact_Email.value){
			ErrorStr +=  '• Main Contact Email is not a valid email address.\r'
		}
		// Password Check.
		var PStr = GoodPassword(Obj.Password.value);
		if (PStr && Obj.Password.value){
			ErrorStr +=  PStr;
		}
		if (ErrorStr) {
			alert ('The following information was incorrect / missing :\r\r' + ErrorStr);
			return false;
		}
		return true;
}

function ChkAgencyForm(){
	var aExcludes = ['Address_Line_2','Address_Line_3','Switchboard_tel'];
	var ErrorStr = '';
    var Obj = document.forms[0].elements;
		for (i=0;i<Obj.length;i++){
			var Xc = false;
			for (j=0;j<aExcludes.length;j++) if (Obj[i].name == aExcludes[j]) Xc = true;
			if (Obj[i].value == '' && Obj[i].type != 'hidden' && !Xc) {
				ErrorStr += '• ' + Obj[i].name.replace(/_/g, ' ') + '.\r';
			}
		}

		// Check at least one industry sector is checked
		var chks = String( document.forms[0].chks.value ).split( "," );
		var checked = false;
		while( chks.length ){
			if ( eval( 'document.forms[0].' + chks.pop() ).checked ) checked = true;
		}
		if ( !checked ) ErrorStr += '• You must select at least one Industry Sector' + '.\r';
		// Check passwords match up.
		if (Obj.Retype_Password.value  && Obj.Retype_Password.value.toLowerCase() != Obj.Password.value.toLowerCase()){
			ErrorStr += '• Entered passwords are different' + '.\r';
		}
		// Check for valid Password.
		var PStr = GoodPassword(Obj.Password.value);
		if (PStr && Obj.Password.value){
			ErrorStr +=  PStr;
		}
		// Check for valid email.
		if (!isEmail(Obj.Main_Contact_Email.value) && Obj.Main_Contact_Email.value){
			ErrorStr +=  '• Main Contact Email is not a valid email address.'
		}
		if (ErrorStr) {
			alert ('The following information was incorrect / missing :\r\r' + ErrorStr);
			return false;
		}
		return true;
}

function isEmail(str) {
	  // are regular expressions supported?
	  var supported = 0;
	  if (window.RegExp) {
		    var tempStr = "a";
		    var tempReg = new RegExp(tempStr);
		    if (tempReg.test(tempStr)) supported = 1;
	  }
	  if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	  return (!r1.test(str) && r2.test(str));
}

function GoodPassword(str){
	  if (str.replace(/[^a-zA-Z0-9]/g,'').length != str.length) return '• Password contains invalid characters.\r';
	  if (str.length<6) return '• Password must be at least 6 characters long.\r';
	  return false;
}

function CheckEmail(val){
	if (isEmail(val)){
		return true;
	} else {
		alert('• Email address is not a valid email address.');
		return false;
	}
}

function CountChars ( field ){
	var Count = eval( 'document.forms[0].' + field ).value.length;
	eval( 'document.forms[0].' + field + '_Count' ).value = Count;
	return Count;
}

function CheckChars( limit, field ){
	if ( CountChars( field ) >= limit ){
		eval( 'document.forms[0].' + field ).value = eval( 'document.forms[0].' + field ).value.substr(0,limit);
	}
}

function _OpenBrWindow(theurl,winname,features) {
  window.open(theurl,winname,features);
}
// declare the global popup window variable name.
var nWin;

function OpenBrWindow (u, w, h, scrollers, resizable) {
	if ( nWin ) nWin.close();
   	var xWin = (screen.width - w)/2;
	var yWin = (screen.height - h)/2;
	var Props = 'width='+w+',height='+h+',resizable=' + resizable + ',scrollbars=';
	Props +=    scrollers + ',screenX='+xWin+',screenY='+yWin+',top='+yWin+',left='+xWin+'\'';
	if ( !scrollers ) scrollers = 0;
	if ( !resizable ) resizable = 'no';
	nWin  = window.open(u,'fileWindow',Props);
	nWin.focus();
};


function addLoc(){
	var Obj = document.forms[0].elements;
	var s1 = Obj.source_locations;
	var s2 = Obj.final_locations;

	if ( s1.selectedIndex == -1 ){
		alert( "Please select a location to add" );
		return;
	}

	var val = s1.options[ s1.selectedIndex ].value;
	var isAdded = false;
	for ( var i=0;i<s2.options.length;i++ ) {
		if( s2.options[i].value == val ){
			alert( "This location has already been added" );
			return;
		}
	}

	var tOption = new Option( val, val );

	if ( s2.options[0].value == "please select" ){
		s2.options[0] = tOption;
	} else {
		s2.options[ s2.options.length ] = tOption;
	}
	Obj.Desired_Location.value += ( Obj.Desired_Location.value == "" ) ? val : "," + val;
};


function remLoc(){
	var Obj = document.forms[0].elements;
	var s1 = Obj.source_locations;
	var s2 = Obj.final_locations;
	var s3 = Obj.Desired_Location;

	if ( s2.selectedIndex == -1 ){
		alert( "Please select a location to remove" );
		return;
	}

	if ( s2.options[ s2.selectedIndex ].value == "please select" ){
		alert( "Unable to remove this item" );
		return;
	}

	var val = s2.options[ s2.selectedIndex ].value;
	if ( s2.options.length > 1 ){
		s2.options[ s2.selectedIndex ] = null;
	} else {
		s2.options[0] = new Option( "please select", "please select" );
	}

	s3.value = s3.value.replace( val, "" );
	if ( s3.value.length > 3 ) s3.value = s3.value.substr( 0, s3.value.length-1 );
};

function clearField( fieldObj, defaultValue ){
	if ( fieldObj.value == defaultValue ) fieldObj.value = "";
};
function setField( fieldObj, defaultValue ){
	if ( fieldObj.value == defaultValue ) return;
	if ( fieldObj.value.replace( /\s/g, "" ).length == 0 ) fieldObj.value = defaultValue;
};
//-->