/// <reference path="http://public.bullhornstaffing.com/CFIDE/scripts/cfform.js" />
/// <reference path="http://public.bullhornstaffing.com/CFIDE/scripts/masks.js" />

function _CF_checkRegisterCandidateForm(_CF_this)
{
    //reset on submit
    _CF_error_exists = false;
    _CF_error_messages = new Array();
    _CF_error_fields = new Object();
    _CF_FirstErrorField = null;
    
    //form element email required check
    if( !_CF_hasValue(_CF_this['EMAIL'], "TEXT", false ) )
    {
        _CF_onError(_CF_this, "EMAIL", _CF_this['EMAIL'].value, "The Email field is required.");
        _CF_error_exists = true;
    }
    else
    {
		if( !_CF_checkEmail(_CF_this['EMAIL'].value, true ) )
		{
			_CF_onError(_CF_this, "EMAIL", _CF_this['EMAIL'].value, "The Email field must be in a valid format.");
			_CF_error_exists = true;
		}
	}

	//form element password required check
	if( !_CF_hasValue(_CF_this['PASSWORD'], "TEXT", false ) )
	{
		_CF_onError(_CF_this, "PASSWORD", _CF_this['PASSWORD'].value, "A Password is required.");
		_CF_error_exists = true;
	}
	//password equals passwordVerify check
	else
	{
		if( _CF_this['PASSWORD'].value != _CF_this['passwordVerify'].value )
		{
		_CF_onError(_CF_this, "PASSWORD", _CF_this['email'].value, "The second Password does not match the first.");
		_CF_error_exists = true;
		}
	}

    //form element firstName required check
    if( !_CF_hasValue(_CF_this['FIRSTNAME'], "TEXT", false ) )
    {
        _CF_onError(_CF_this, "FIRSTNAME", _CF_this['FIRSTNAME'].value, "The First Name field is required.");
        _CF_error_exists = true;
    }

    //form element lastName required check
    if( !_CF_hasValue(_CF_this['LASTNAME'], "TEXT", false ) )
    {
        _CF_onError(_CF_this, "LASTNAME", _CF_this['LASTNAME'].value, "The Last Name field is required.");
        _CF_error_exists = true;
    }

    //display error messages and return success
    if( _CF_error_exists )
    {
        if( _CF_error_messages.length > 0 )
        {
            // show alert() message
            _CF_onErrorAlert(_CF_error_messages);
            // set focus to first form error, if the field supports js focus().
            if( _CF_this[_CF_FirstErrorField].type == "text" )
            {
				_CF_this[_CF_FirstErrorField].focus();
			}
        }
        return false;
    }
    else
    {
        // run userdefined onSubmit javascript.
        
        return true;
    }
}

function _CF_checkEditCandidateProfileForm(_CF_this)
{
    //reset on submit
    _CF_error_exists = false;
    _CF_error_messages = new Array();
    _CF_error_fields = new Object();
    _CF_FirstErrorField = null;

    //form element email required check
    if( !_CF_hasValue(_CF_this['EMAIL'], "TEXT", false ) )
    {
        _CF_onError(_CF_this, "EMAIL", _CF_this['EMAIL'].value, "The Email field is required.");
        _CF_error_exists = true;
    }
    else
    {
		if( !_CF_checkEmail(_CF_this['EMAIL'].value, true ) )
		{
			_CF_onError(_CF_this, "EMAIL", _CF_this['EMAIL'].value, "The Email field must be in a valid format.");
			_CF_error_exists = true;
		}
    }

    //password equals passwordVerify check
	if( _CF_this['PASSWORD'].value != _CF_this['passwordVerify'].value )
	{
		_CF_onError(_CF_this, "PASSWORD", _CF_this['email'].value, "The second Password does not match the first.");
		_CF_error_exists = true;
	}
	
    //form element firstName required check
    if( !_CF_hasValue(_CF_this['FIRSTNAME'], "TEXT", false ) )
    {
        _CF_onError(_CF_this, "FIRSTNAME", _CF_this['FIRSTNAME'].value, "The First Name field is required.");
        _CF_error_exists = true;
    }

    //form element lastName required check
    if( !_CF_hasValue(_CF_this['LASTNAME'], "TEXT", false ) )
    {
        _CF_onError(_CF_this, "LASTNAME", _CF_this['LASTNAME'].value, "The Last Name field is required.");
        _CF_error_exists = true;
    }

    //display error messages and return success
    if( _CF_error_exists )
    {
        if( _CF_error_messages.length > 0 )
        {
            // show alert() message
            _CF_onErrorAlert(_CF_error_messages);
            // set focus to first form error, if the field supports js focus().
            if( _CF_this[_CF_FirstErrorField].type == "text" )
            {
				_CF_this[_CF_FirstErrorField].focus();
			}
        }
        return false;
    }
    else
    {
        // run userdefined onSubmit javascript. 
        
        return true;
    }
}

function _CF_checkLoginForm(_CF_this)
{
    //reset on submit
    _CF_error_exists = false;
    _CF_error_messages = new Array();
    _CF_error_fields = new Object();
    _CF_FirstErrorField = null;
    //form element email required check
    if( !_CF_hasValue(_CF_this['EMAIL'], "TEXT", false ) )
    {
        _CF_onError(_CF_this, "EMAIL", _CF_this['EMAIL'].value, "Your Email is required to log in.");
        _CF_error_exists = true;
    }

    //form element password required check
    if( !_CF_hasValue(_CF_this['PASSWORD'], "TEXT", false ) )
    {
        _CF_onError(_CF_this, "PASSWORD", _CF_this['PASSWORD'].value, "Your Password is required to log in.");
        _CF_error_exists = true;
    }

    //display error messages and return success
    if( _CF_error_exists )
    {
        if( _CF_error_messages.length > 0 )
        {
            // show alert() message
            _CF_onErrorAlert(_CF_error_messages);
            // set focus to first form error, if the field supports js focus().
            if( _CF_this[_CF_FirstErrorField].type == "text" )
            { _CF_this[_CF_FirstErrorField].focus(); }
        }
        return false;
    }
    else
    {
        // run userdefined onSubmit javascript. 
        return true;
    }
}
