function validatePwd(field) {
	var invalid = " "; // Invalid character is a space
	var valid = "0123456789"; // Invalid character is a space
	var minLength = 8; // Minimum length

	// check for minimum length
	if (field.value.length < minLength) {
		alert('Your password must be at least ' + minLength + ' characters long.');
		return false;
	}
	// check for spaces
	if (field.value.indexOf(invalid) > -1) {
		alert("Your password must not contain spaces.");
		return false;
	}
	if (!(field.value.search(/[0-9]+/) > -1)) {
		alert("Your password must contain at least one number.");
		return false;
	}
	return true;
}
function validateSearch(f){
	if(f.sector_1.value == '' && f.county_1.value == ''){
		alert('Please select an occupation and/or location.');
		f.sector_1.focus();
		return false;
	}
	return true;
}
function validateSignup(f){
	if(f.company && f.company.value == ''){
		alert('Please enter your company name.');
		f.company.focus();
		return false;
	}
	
	if(f.contact.value == ''){
		alert('Please enter your full name.');
		f.contact.focus();
		return false;
	}
	
	if(f.address1.value == ''){
		alert('Please enter your address.');
		f.address1.focus();
		return false;
	}
	
	if(f.county.value == ''){
		alert('Please select a county.');
		f.county.focus();
		return false;
	}
	
	if(f.postcode.value == ''){
		alert('Please enter your postcode.');
		f.postcode.focus();
		return false;
	}
	
	if(f.telephone.value == ''){
		alert('Please enter your telephone number.');
		f.telephone.focus();
		return false;
	}
	
	if(f.email.value == ''){
		alert('Please enter your E-mail address.');
		f.email.focus();
		return false;
	}
	
	if(f.confirm_email.value == '' || f.confirm_email.value != f.email.value){
		alert('Please confirm your E-mail address.');
		f.confirm_email.focus();
		return false;
	}
	
	if(f.password.value == ''){
		alert('Please enter your password.');
		f.password.focus();
		return false;
	}
	else if(validatePwd(f.password) == false){
		return false;
	}
	
	if(f.confirm_password.value == '' || f.confirm_password.value != f.password.value){
		alert('Please confirm your password.');
		f.password.focus();
		return false;
	}
	
	if(!captcha_approved){
		alert('Please enter the anti-spam code.');
		return false;
	}
	return true;
}

function validateEmployeeSignupConf(f){
	if(f.sector_1.value == ''){
		alert('Please select first choice occupation.');
		f.sector_1.focus();
		return false;
	}

	if(f.county_1.value == ''){
		alert('Please select first choice location.');
		f.county_1.focus();
		return false;
	}
	
	if(f.details.value == '' || f.details.value == 'Use this space to emphasise your experience!'){
		alert('Please enter your career summary.');
		f.details.focus();
		return false;
	}
	
	if(f.salary.value == ''){
		alert('Please enter salary required.');
		f.salary.focus();
		return false;
	}

	if(f.comments.value == ''){
		alert('Please enter salary comments.');
		f.comments.focus();
		return false;
	}
	return true;
}

function validateEmployerSignupConf(f){
	
	if(f.ref.value == ''){
		alert('Please enter your reference.');
		f.ref.focus();
		return false;
	}
	
	if(f.sector_1.value == ''){
		alert('Please select an occupation.');
		f.sector_1.focus();
		return false;
	}
	
	if(f.county_1.value == ''){
		alert('Please select a location.');
		f.county_1.focus();
		return false;
	}
	
	if(f.details.value == ''){
		alert('Please enter your vacancy details.');
		f.details.focus();
		return false;
	}
	
	if(f.salary.value == ''){
		alert('Please enter salary offered.');
		f.salary.focus();
		return false;
	}
	
	if(f.period.value == ''){
		alert('Please enter the salary period.');
		f.period.focus();
		return false;
	}

	if(f.comments.value == ''){
		alert('Please enter your salary comments.');
		f.comments.focus();
		return false;
	}
	return true;
}

function validateLogin(f){

	if((f.email.value == '' || f.email.value == 'User Name') && (f.password.value == '' || f.password.value == 'Password')){
		alert('Please enter your log-in details.');
		f.email.focus();
		return false;
	}
	
	if(f.email.value == '' || f.email.value == 'User Name'){
		alert('Please enter your E-mail Address.');
		f.email.focus();
		return false;
	}
	
	if(f.password.value == '' || f.password.value == 'Password'){
		alert('Please enter your password.');
		f.password.focus();
		return false;
	}
	
	if(f.login_type.options[f.login_type.selectedIndex].value == ''){
		alert('Please select job seeker or employer.');
		f.login_type.focus();
		return false;
	}
	return true;
}

function addScript(url){
	var sc = document.createElement("script");
	sc.src = url;
	document.getElementsByTagName('head')[0].appendChild(sc);
}

function minimise(span_name) {
	eval("document.getElementById('"+span_name+"').style.display = 'none';");
	eval("document.getElementById('"+span_name+"').style.visibility = 'hidden';");
}

function maximise(span_name) {
	eval("document.getElementById('"+span_name+"').style.display = 'block';");
	eval("document.getElementById('"+span_name+"').style.visibility = 'visible';");
}
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function
