var defaultLocationValue;
var defaultKeywordValue;

/*** JOB ***/
function Job(hitId) {
    this.onMouseEnter = function(e) {
        if (this.alternatesButton) {
            addElementClass(this.alternatesButton, 'alternates_hover');
        }
        addElementClass(this.emailButton, 'email_job_hover');
    };
    
    this.onMouseLeave = function(e) {
        if (this.alternatesButton) {
            removeElementClass(this.alternatesButton, 'alternates_hover');
        }
        removeElementClass(this.emailButton, 'email_job_hover');
    };
    
    this.onOptionsEnter = function(e) {
        this.optionsTooltip.innerHTML = e.src().innerHTML;
    };
    
    this.onOptionsLeave = function(e) {
        this.optionsTooltip.innerHTML = '';
    };
    
    // Load DOM elements
    this.dtTitle = getElement('title-' + hitId);
    this.ddCompany = getElement('company-' + hitId);
    this.ddDescription = getElement('description-' + hitId);
    this.ddOptions = getElement('options-' + hitId);
    this.emailButton = getElement('email-' + hitId);
    this.alternatesButton = getElement('alternates-' + hitId);
    this.optionsTooltip = getElement('tooltip-' + hitId);
    
    // Bind CSS update events
    connect(this.dtTitle, 'onmouseover', this, 'onMouseEnter');
    connect(this.dtTitle, 'onmouseout', this, 'onMouseLeave');
    connect(this.ddCompany, 'onmouseover', this, 'onMouseEnter');
    connect(this.ddCompany, 'onmouseout', this, 'onMouseLeave');
    connect(this.ddDescription, 'onmouseover', this, 'onMouseEnter');
    connect(this.ddDescription, 'onmouseout', this, 'onMouseLeave');
    connect(this.ddOptions, 'onmouseover', this, 'onMouseEnter');
    connect(this.ddOptions, 'onmouseout', this, 'onMouseLeave');
    connect(this.emailButton, 'onmouseover', this, 'onOptionsEnter');
    connect(this.emailButton, 'onmouseout', this, 'onOptionsLeave');
    if (this.alternatesButton) {
        connect(this.alternatesButton, 'onmouseover', this, 'onOptionsEnter');
        connect(this.alternatesButton, 'onmouseout', this, 'onOptionsLeave');
    }
}

/*** ON DISTANCE CHANGE ***/
function onDistanceChange() {
    var r1 = document.getElementById('radius1');
    r1.value = document.getElementById('distanceSelectBox').value;
    try {
        if (r1.value == '20') {
            r1.parentNode.removeChild(r1);
        }
    } catch(e) {
    }
    document.forms[0].submit();
}

/*** SET FORM FIELD VALUE ***/
function initLocation(locationId,locationValue) {
    defaultLocationValue = locationValue;
    if (document.getElementById && locationId) {
        ele = document.getElementById(locationId);
        onLocationBlur(ele);
    }
}

function onLocationFocus(ele) {
    if (ele.value == defaultLocationValue) {
        ele.value = "";
        ele.style.color = '#000000';
    }
}

function onLocationBlur(ele) {
    if (ele.value.length == 0 || ele.value == defaultLocationValue) {
        ele.style.color = '#999999';
        if (defaultLocationValue) {
            ele.value = defaultLocationValue;
        }
    }
}

function initKeyword(keywordId,keywordValue) {
    defaultKeywordValue = keywordValue;
    if (document.getElementById && keywordId) {
        ele = document.getElementById(keywordId);
        onKeywordBlur(ele);
    }
}

function onKeywordFocus(ele) {
    if(ele.value == defaultKeywordValue) {
        ele.value = "";
        ele.style.color = '#000000';
    }
}

function onKeywordBlur(ele) {
    if (ele.value.length == 0 || ele.value == defaultKeywordValue) {
        ele.style.color = '#999999';
        if (defaultKeywordValue) {
            ele.value = defaultKeywordValue;
        }
    }
}

