/**
 * @author hugo
 */


var globAjax;
globAjax = buildAjax();
var httpPath = 'http://www.southtexasjobzone.com/';
var currentFrame = '';

var pulseGif = new Image();
pulseGif.src= httpPath + 'jz_pics/ajax-loader-bar.gif';
var pulserBar = '<img src="' + pulseGif.src + '" style="width:174px;" align="center" />';

function createPulser(style)
{
    return '<img src="' + pulseGif.src + '" style="'+style+'" align="center" />';
}

function deleteAll(listEl)
{
    var nodes = listEl.parentNode.childNodes;

    for(var count = 0; count < nodes.length; count++)
    {
        if(nodes[count] == listEl)
        {
            // This is pretty much the child node asking the
            // parent node to kill it.
            listEl.parentNode.removeChild(listEl);
        }
        else
        {
            nodes[count].getElementsByTagName('input')[0].click();
        }
    }
}

/**
 * This function erases alerts from the database
 * 
 * @param {listElement} listEl the list element to remove
 * @param {String} csvString A string with the db elements to delete
 */
function deleteAlert(listEl, csvString)
{
    var aHolder = listEl.firstChild.cloneNode(true);
    listEl.innerHTML = pulserBar;
    var ajaxObj = buildAjax();
    var csvArray = csvString.split(',');

    // okay, so we have an array filled with
    // userId,senderId,alertCode
    var url = httpPath + 'alertSys/eraseAlert.php?';
    url += 'userId=' + csvArray[0];
    url += '&senderId='+ csvArray[1];
    url += '&alertCode=' + csvArray[2];
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'success')
            {
                listEl.parentNode.removeChild(listEl);
            }
            else
            {
                listEl.replaceChild(aHolder, listEl.firstChild);
            }
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET', url, true);
    ajaxObj.send(null);
}

function deleteEmployerAlert(listEl, alertCode)
{
    var aHolder = listEl.innerHTML;

    listEl.innerHTML = pulserBar;
    var ajaxObj = buildAjax();

    // okay, so we have an array filled with
    // userId,senderId,alertCode
    var url = httpPath + 'alertSys/eraseEmployerAlert.php?';
    url += '&alertCode=' + alertCode;
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'success')
            {
                var parent = listEl.parentNode;
                listEl.parentNode.removeChild(listEl);
                if(parent.childNodes.length == 0)
                {
                    getId('rightRow').removeChild(parent.parentNode);
                }
            }
            else
            {
                listEl.innerHTML = aHolder;
            }
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET', url, true);
    ajaxObj.send(null);
}

/**
 * This function should prevent any key strokes that are not
 * numbers from being entered into the text box.
 * 
 * @param {Object} e The keystroke object to be process.
 * @param {Object} element The html text that's being typed into
 */
function numbersOnly(e, element)
{
    var keynum;
	
    // we get the key event
    if(window.event) // IE
    {
        keynum = window.event.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
	
    // We make sure that the key entered
    // is in fact a number and we execute the formatting code
    // the first condition is the number row above the keyboard letters
    // and the second condition is the key pad
	
    if((keynum >= 48 && keynum <= 57) || (keynum >= 96 && keynum <= 105) || keynum == 8)
    {
        return;
    }
    else
    {
        element.value = element.value.substr(0, element.value.length - 1);
    }
}

/*
* This will be a function to check most input elements during registrations.
* exception will be email, we need multiple errors here, and password confirmation,
* since we don't necessarily need to go all the way to the server to check this
* inputID: the ID of the HTML input tag
* 
* method: the method to get the info to PHP, GET or POST
* url: the url of the php page we want to validate against
* phpVarName: the name to use when calling $_REQUEST 
* errorMSG: the message to display in the error field
* 
* it returns false if validation was successful,
* and true if it wasn't. In this manner we can set a global equal to this function
* and not execute if the input has already been validated.
*/

function checkInput(inputID, method, url, phpVarName, errorMSG)
{
    var inputObj = document.getElementById(inputID);
    if (inputObj.title == 'select') // the input is a select statement.
    {
        inputString = encodeURIComponent(inputObj.options[inputObj.selectedIndex].value);
    }
    else
    {
        inputString = encodeURIComponent(inputObj.value);
    }
	
    var ajaxObj = buildAjax();

    if(ajaxObj == null)
    {
        return;
    }

    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'malformed')
            {
                displayError(errorMSG, inputID);
            }
            else if(ajaxObj.responseText == 'ok')
            {
                hideError(inputID);
            }
        }
    };
    ajaxObj.open(method, url + "?" + phpVarName + "=" + inputString, true);
    ajaxObj.send(null);
}


/**
 * this function builds and ajax object. you know for fun :P
 * @return {XMLHttpRequest} an object to communicate with your server
 */
function buildAjax()
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        xmlhttp = null;
    }
	
    return xmlhttp;
}


/*
 * Methods for displaying and hiding errors.
 * errMsg: the message to display
 * elID: The id of the tag to un/highlight
 */
function displayError(errMsg, elID)
{
    document.getElementById(elID + 'Err').style.visibility="visible";
    document.getElementById(elID + 'Err').innerHTML = errMsg;
    document.getElementById(elID).style.borderColor="#FAA";
    document.getElementById(elID).focus();
}

function hideError(elID)
{
    document.getElementById(elID + 'Err').style.visibility="hidden";
    document.getElementById(elID).style.borderColor = "#FFF";
}

function checkEmail()
{
    var inputObj = document.getElementById('email');
    var inputString = inputObj.value;
    var ajaxObj = buildAjax();
    if(ajaxObj == null)
    {
        return;
    }

    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'malformed')
            {
                displayError('Bad Email', 'email');
            }
            else if(ajaxObj.responseText == 'Existing_Email')
            {
                displayError('Email already exists', 'email');
            }
            else if(ajaxObj.responseText == 'OK')
            {
                hideError('email');
            }
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET',  httpPath+'ajax/checkEmployerEmail.php?email=' + inputString, true);
    ajaxObj.send(null);
}

function formatPhone(inputID, e)
{
    var elementObj = document.getElementById(inputID);
    var stroke = (window.event) ? event.keyCode : e.keyCode;
    if(8 == stroke)
    {
        return;
    }
    // We make sure that the key entered
    // is in fact a number and we execute the formatting code
    // the first condition is the number row above the keyboard letters
    // and the second condition is the key pad

    if(elementObj.value.length == 3)
    {
        elementObj.value = elementObj.value + '-';
    }

    if(elementObj.value.length == 7)
    {
        elementObj.value = elementObj.value + '-';
    }
}

function phoneBlur(inputId)
{
    if (getId(inputId).value.length != 12)
    {
        getId(inputId).value = 'XXX-XXX-XXXX';
    }
}

/*
 * This function creates the selects for the industry selection.
 * so, first we create the select.
 * we then pass the element to an ajax function to add the options
 * and then we add it to the span.
 */
function addIndustryLine()
{
    var spanElement = document.getElementById('industrySelect'); // this is what we'll add too
    var newDiv = document.createElement('div');
    var ajaxObj = buildAjax();
    var lineNum = document.getElementById('numRows').value++;
    newDiv.innerHTML = pulserBar;
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            newDiv.innerHTML = ajaxObj.responseText;
            spanElement.insertBefore(newDiv, document.getElementById('industAdd'));
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET',  httpPath+"getFunction/getIndustryType.php?lineNum=" + lineNum, true);
    ajaxObj.send(null);
}

/*
 * In this function we fill in 
 * the actual industry that they might want
 */
function addIndustrySelect(element)
{
    var ajaxObj = buildAjax();
    var indType = element[element.selectedIndex].value;
    element.nextSibling.innerHTML = pulserBar;
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if (ajaxObj.responseText != 'fail')
            {
                element.nextSibling.innerHTML = ajaxObj.responseText;
            }
            else
            {
                document.body.appendChild(createErrorBox('Could not get Industries'));
            }
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET', httpPath+"getFunction/getIndustries.php?IndType=" + indType, true);
    ajaxObj.send(null);
}

function addDepartmentLine(spanElement,insertRef, dptName, posName)
{
    if(posName == null)
    {
        posName = '';
    }

    if(dptName == null)
    {
        dptName = '';
    }
	
    var newSpan = document.createElement('div');
    newSpan.style.marginTop = '5px';
    var ajaxObj = buildAjax();
	
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            newSpan.innerHTML = ajaxObj.responseText;
            spanElement.insertBefore(newSpan, insertRef );
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET', httpPath+"getFunction/getDepartments.php?"+posName+"&"+dptName, true);
    ajaxObj.send(null);
}

/*
 * In this function we fill in 
 * the actual industry that they might want
 * 
 * @param {HTMLElement} element the element that selects the department
 * @param {Integer} pos the default position
 * @param {boolean} filter whether to filter by the user
 * @param {Integer} posId the position we want to send over
 */
function addPositionSelect(element, pos, filter, posId)
{
    var ajaxObj = buildAjax();
    var deptType = element[element.selectedIndex].value;

    if(pos == null)
    {
        pos = '';
    }
    else
    {
        pos = '&'+pos;
    }

    if(posId == null)
    {
        var posId = '';
    }
    else
    {
        posId = '&PosId='+posId;
    }

    element.nextSibling.innerHTML = pulserBar;

    if(filter == undefined)
    {
        filter = false
    }

    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            element.nextSibling.innerHTML = ajaxObj.responseText;
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET', httpPath+"getFunction/getPositions.php?Department=" + deptType + pos + posId+'&userFilter=' + filter, true);
    ajaxObj.send(null);
}

/**
 * This function checks the validity of a single element
 * from an array of named elements.
 * 
 * @param {Integer} index the index location of the element to check
 * @param {String} name the name of the elements we need to check
 * @param {String} method the method to get the info to the server
 * @param {String} url the location of the server page 
 * @param {String} phpVarName the name of the serverside variable name
 * @param {String} errorMSG the error message to display
 * @param {String} errorId the id of the element to display the error in
 */
function checkSingleFromArray(index, name, method, url, phpVarName, errorMSG, errorId)
{

    var element = document.getElementsByName(name)[index];
    
    var inputString = '';
    if (element.title == 'select')
    {
        inputString = encodeURI(element.options[element.selectedIndex].value)
    }
    else
    {
        inputString = encodeURI(element.value);
    }

    var ajaxObj = buildAjax();

    if(ajaxObj == null)
    {
        return;
    }

    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'malformed')
            {
                displayErrorFromElement(errorMSG, errorId, element);
            }
            else if(ajaxObj.responseText == 'ok')
            {
                hideErrorFromElement(errorId, element);
            }
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(

    ajaxObj.open(method, httpPath+url + "?" + phpVarName + "=" + inputString, true);
    ajaxObj.send(null);
	
}

function checkState(state, stateId, country, errorMSG, errorId)
{
    var ajaxObj = buildAjax();
    
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'malformed')
            {
                displayErrorFromElement(errorMSG, errorId, stateId);
            }
            else if(ajaxObj.responseText == 'ok')
            {
                hideErrorFromElement(errorId, stateId);
            }
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(

    ajaxObj.open('GET', httpPath+'ajax/checkState.php?country='+country + "&state=" + state, true);
    ajaxObj.send(null);
}
/**
 * Great, another effin error function. this displays an error in
 * errBox and set focus to focusElement.
 * @param {String} errMsg The message to display
 * @param {Element} errBox The element to display the error in
 * @param {Element} focusElement The element to set focus to.
 */
function displayErrorFromElement(errMsg, errBox, focusElement)
{
    errBox.style.visibility="visible";
    errBox.innerHTML = errMsg;
    focusElement.style.borderColor="#FAA";
    focusElement.focus();
}

function hideErrorFromElement(errBox, focusElement)
{
    errBox.style.visibility="hidden";
    focusElement.style.borderColor = "#FFF";
}

function getId(element)
{
    return document.getElementById(element);
}

/**
 * This will replace the given submitElement
 * @param {HTML Element} submitElement the element to replace
 * @return {String} buttonId the id of the created button
 */
function replaceSubmit(submitElement)
{
    var newButton = document.createElement('input');
    var newId = 'submitBtn';
		
    newButton.setAttribute('type', 'button');
    newButton.setAttribute('id',newId);
    newButton.setAttribute('value', submitElement.value);
	
    submitElement.parentNode.insertBefore(newButton,submitElement);
    submitElement.parentNode.removeChild(submitElement);
	
    return newId;
}

/**
 * Never trust the comments, by the time you read this,
 * it'll have changed. But this is suppose to check the name
 * provided for accurate data, and submit the form if it is
 * good. The server is required to return either an ok or a
 * malformed.
 * 
 * @param {Object} form The form we need to submit
 * @param {Integer} index the index of the element we want to check
 * @param {String} name the name of the element array we want to check 
 * @param {String} method how to get our information to the server
 * @param {String} url  the server page we want to submit to
 * @param {String} phpVarName the variable name we want to use
 * @param {String} errorMSG the error message to display if it doesn't go well
 * @param {Object} errorBox the divition in which to display the message
 */
function checkAndSubmit(form, index, name, method, url, phpVarName, errorMSG, errorBox)
{
	
    var element = document.getElementsByName(name)[index];
	
    var inputString = encodeURIComponent(element.value);
	
    var ajaxObj = buildAjax();
	
    if (ajaxObj == null) {
        return;
    }
	
    ajaxObj.onreadystatechange = function()
    {
        if (ajaxObj.readyState == 4)
        {
            if (ajaxObj.responseText == 'malformed')
            {
                displayErrorFromElement(errorMSG, errorBox, element);
            }
            else if (ajaxObj.responseText == 'ok')
            {
                document.body.appendChild(createErrorBox('Information Changed'));
                form.submit();
            }
        }
    };
	
    ajaxObj.open(method, httpPath + url + "?" + phpVarName + "=" + inputString, true);
    ajaxObj.send(null);
}

// this function might not exist. if it doesn't
// we define it as an empty : P
if(typeof positionFocusFunction != 'function')
{
    function positionFocusFunction()
    {}
}

/**
 * This function re-constructs the options within
 * a day element to set the number of days as options
 * 
 * @param {Object} month
 * @param {Object} year
 * @param {Object} selectElement
 */
function changeDaysDropDown(month, year, selectElement)
{
    getId('errorBlock').innerHTML = '';
    var i = 0;
    for(i = selectElement.options.length - 1; i >= 0 ; i--)
    {
        selectElement.remove(i);
    }
	
    var totalDays = 32 - new Date(year, month, 32).getDate(); // I got this from the net

    for(i = 1; i <= totalDays; i++)
    {
        var option = document.createElement('option');
        option.setAttribute('value', i);
        option.text = i;
		
        if(option.text.length < 2)
        {
            option.text = '0'+option.text;
        }
		
        selectElement.add(option,null);
    }
}

function getStates()
{
    ajaxObj = buildAjax();
    var country = this.options[this.selectedIndex].value;
    var currStyle = getId('stateSelect').style; // this selection will be replaced by the server
    getId('stateContent').innerHTML = pulserBar;
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            getId('stateContent').innerHTML = ajaxObj.responseText;
            // We need to apply these to the newly created element
			
            getId('stateSelect').setAttribute('style', currStyle);
            getId('stateSelect').onfocus=function()
            {
                checkSingleFromArray(0,
                    'country',
                    'GET',
                    'ajax/checkCountry.php',
                    'country',
                    'Please Select a country',
                    getId('countryErr')
                    );
            }
            getId('stateSelect').focus();
			
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
	
    ajaxObj.open('GET', httpPath+"getFunction/getStates.php?country=" + country, true);
    ajaxObj.send(null);
}

 
function uncheckAll(name)
{
    var checks = document.getElementsByName(name);
    for (var i = 0; i < checks.length; i++)
    {
        checks[i].checked = false;
    }
}
 
function checkAll(name)
{
    var checks = document.getElementsByName(name);
    for (var i = 0; i < checks.length; i++)
    {
        checks[i].checked = true;
    }
}

function invertCheck(name)
{
    var checks = document.getElementsByName(name);
    for(var i = 0; i < checks.length; i++)
    {
        checks[i].checked = !checks[i].checked;
    }
}

/**
 * Apperantly this does some error checking when the only availabe choices
 * are radio buttons
 * @param {Object} inputName
 * @param {Object} method
 * @param {Object} url
 * @param {Object} phpVarName
 * @param {Object} errorMSG
 */
function checkRadios(inputName, method, url, phpVarName, errorMSG)
{
    var radios = document.getElementsByName(inputName);
    var i = 0;
    var value = '';
    var ajaxObj = buildAjax();
	
    for(i = 0; i < radios.length; i++)
    {
        if(radios[i].checked)
        {
            value = radios[i].value;
            break;
        }
    }
	
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'ok')
            {
                hideError(radios[0].id);
            }
            else
            {
                displayError(errorMSG, radios[0].id);
            }
        }
    };

    ajaxObj.open(method, url + '?'+ phpVarName + '=' + value, true);
    ajaxObj.send(null);
}


/**
 *  Returns the value a radio group.
 *  @param {String} inputName The name of the radio group
 */
function returnRadioValue(inputName)
{
    var radios = document.getElementsByName(inputName);

    for(var i = 0; i < radios.length; i++)
    {
        if(radios[i].checked)
        {
            // If one is checked, we return the value
            return radios[i].value;
        }
    }

    // If it makes it out of the loop, then it didn't return
    // thus, nothing was checked, and we return null.
    return '';
}

/*
 * I have to build an ajax object here because these are 
 * radio buttons as opposed to select or text boxes.
 */
function checkEmployed()
{
    checkRadios('employed', 'GET', httpPath + 'ajax/checkEmployed.php', 'employed', 'Select One');
}


function checkAltPhone()
{
    var inputObj = document.getElementById('phone1');
    var inputString = inputObj.value;
    var ajaxObj = buildAjax();
	
    if(ajaxObj == null)
    {
        return;
    }

    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'malformed')
            {
                displayError('Phone number not valid', 'phone1');
            }
            else if(ajaxObj.responseText == 'ok')
            {
                hideError('phone1');
                document.getElementById('contactForm').submit();
            }
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET', httpPath+'ajax/checkPhone.php?phone=' + inputString, true);
    ajaxObj.send(null);
}

/**
 * Removes a Job Seeker from an employer's watch list.
 * 
 * @param {Integer} seekerId The seeker we want to delete.
 * @param {Integer} employerId The employer we want to delete.
 * @param {HTMLElement} child The child we want to remove from the root table, like a tr of li element
 */
function deleteFromWatchList(seekerId, employerId, child)
{
    var ajaxObj = buildAjax();

    openLoad();
    openCssWindow();

    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            
            if(ajaxObj.responseText == 'success')
            {
                child.parentNode.removeChild(child);
                closeCssWindow();
            }
            else
            {
                closeCssWindow();
            }
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET', httpPath+'ajax/removeFromWatchList.php?seekerId=' + seekerId + '&employerId=' + employerId , true);
    ajaxObj.send(null);
}

/**
 * Does the same as above, but to the applicants in place of the watch list.
 *
 * @param {Integer} seekerId The seeker we want to delete.
 * @param {Integer} jobId The job id we want to delete.
 * @param {HTMLElement} buttonEl The button that the user clicked
 * @param {HTMLElement} removeChild The child we want to remove from the root table, like a tr of li element
 */
function deleteFromApplicants(seekerId, jobId, buttonEl, removeChild)
{
    var ajaxObj = buildAjax();
    
    buttonEl.value = 'Deleting...';

    var row = getId('resultTable').insertRow(removeChild.rowIndex);
    removeChild.style.display = 'none';
    var cell = row.insertCell(0);
    cell.setAttribute('colspan',removeChild.cells.length);
    cell.innerHTML = pulserBar;
    cell.height = removeChild.cells[0].height;
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'success')
            {
                removeChild.parentNode.removeChild(removeChild);
                row.parentNode.removeChild(row);
            }
            else
            {
                buttonEl.value = 'System Failure';
            }
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET', httpPath+'ajax/removeFromApplicants.php?seekerId=' + seekerId + '&jobId=' + jobId , true);
    ajaxObj.send(null);
}


/**
 * This funcion is used if a user clicks the pagination button
 *
 * @param {HTMLElement} buttonEl the button or link that the use clicks
 */
function getSearchFromLink(buttonEl)
{
    //Send the proper header information along with the request
    //getId('results').innerHTML = 'Loading...';
    var ajaxObj = buildAjax();
    var searchPath = buttonEl.title;

    buttonEl.value = 'Loading...';
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            getId('results').innerHTML = ajaxObj.responseText;
        }
    }
    ajaxObj.open('GET', searchPath, true);
    ajaxObj.send(null);
}

function getEmployerJobView(jobId, anchorTag)
{
    var ajaxObj = buildAjax();
    
    if(getId('containJob'))
    {
        document.removeChild(getId('containJob'));
    }


    var btnCancel = document.createElement('input');
    btnCancel.setAttribute('type', 'button');
    btnCancel.setAttribute('value', 'Cancel');
    btnCancel.onclick=function()
    {
        ajaxObj.abort();
        document.body.removeChild(container);
    }


    var innerWindow = document.createElement('div');
    innerWindow.innerHTML = pulserBar;
    innerWindow.appendChild(btnCancel);
    innerWindow.setAttribute('class', 'jobView');
    innerWindow.className = 'jobView';
    
    var container = document.createElement('div');
    container.setAttribute('class', 'cssWindowContainer');
    container.className = 'cssWindowContainer';
    container.setAttribute('id', 'containJob');
    container.appendChild(innerWindow);

    document.body.appendChild(container);

    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            if(ajaxObj.responseText == 'fail')
            {
                innerWindow.innerHTML = 'System Not Available';
            }
            else
            {
                innerWindow.innerHTML = ajaxObj.responseText;
                getId('JViewRenew').onclick=function()
                {
                    processJob(anchorTag, jobId, 'renew');
                    document.body.removeChild(container);
                }

                getId('JViewClose').onclick=function()
                {
                    processJob(anchorTag, jobId, 'close');
                    document.body.removeChild(container);
                }
            }
        }
    }
    ajaxObj.open('GET', httpPath + 'employActs/EmployerViewJob.php?jobId='+jobId, true);
    ajaxObj.send(null);
}

function getEmployerSeekerView(seekerId, buttons)
{
    if(getId('containSeeker'))
    {
        document.body.removeChild(getId('containSeeker'));
    }

    // we must set this to have access to it later.
    if(getId('hdnValue') != null)
    {
        getId('hdnValue').value = seekerId;
    }

    openLoad();
    openCssWindow();

    var innerWindow = document.createElement('div');
    innerWindow.setAttribute('class', 'jobView');
    innerWindow.className = 'jobView';

    var container = document.createElement('div');
    container.setAttribute('class', 'cssWindowContainer');
    container.className = 'cssWindowContainer';
    container.setAttribute('id', 'containSeeker');
    container.style.height = document.body.clientHeight+'px';
    container.appendChild(innerWindow);

    var actionTable = document.createElement('div');
    actionTable.setAttribute('id', 'actionButtons');
    for(var i = 0; i < buttons.length; i++)
    {
        actionTable.appendChild(buttons[i]);
    }
    container.appendChild(actionTable);
   
    globAjax.onreadystatechange=function()
    {
        if(globAjax.readyState == 4)
        {
            innerWindow.innerHTML = globAjax.responseText;
            // this is set here so that the innerWindow.innerHTML won't over write the buttons
            innerWindow.appendChild(actionTable);
            closeCssWindow();
            document.body.appendChild(container);
        }
    }
    globAjax.open('GET', httpPath + 'employActs/displaySeekerInfo.php?seekerId='+seekerId, true);
    globAjax.send(null);
}

function changeCellColor(cells, foreground, background)
{
    if(foreground == null)
    {
        foreground = '#000';
    }

    if(background == null)
    {
        background = '#FFF';
    }

    for(var i = 0; i < cells.length; i++)
    {
        cells[i].style.backgroundColor = background;
        cells[i].style.color = foreground;
    }
}

function rotateFields(dropDown)
{
    for(var i = 0; i < dropDown.options.length; i++)
    {
        getId(dropDown.options[i].value).style.display = 'none';
    }
    getId(dropDown.options[dropDown.selectedIndex].value).style.display = 'block';
}

function openCssWindow(userId, cell)
{
    if(typeof(userId) == 'undefined' && typeof(cell) == 'undefined')
    {
        getId('popContain').style.display = 'block';
        return;
    }

    getId('coords').value = cell.parentNode.rowIndex + ',' + (cell.cellIndex);
    getId('hdnValue').value = userId;
    getId('popContain').style.display = 'block';
}

function openLoad()
{

    //<!-- chngName, frmPositions, profileView-->
    if(getId('banner') != null)
    {
        getId('banner').style.visibility = 'hidden';
    }
    
    if(getId('chngName') != null)
    {
        getId('chngName').style.display = 'none';
    }

    if(getId('frmPositions').style.display != 'none')
    {
        currentFrame = 'frmPositions';
        getId('frmPositions').style.display = 'none';
    }

    if(getId('profileView').style.display != 'none')
    {
        currentFrame = 'profileView';
        getId('profileView').style.display = 'none';
    }

    getId('loading').style.display = 'block';
}

function closeLoad()
{
    getId('banner').style.visibility = 'visible';
    if(getId('chngName') != null)
    {
        getId('chngName').style.display = 'block';
    }
    getId('loading').style.display = 'none';
    getId(currentFrame).style.display = 'block';
}

function closeCssWindow()
{
    getId('popContain').style.display='none';
    closeLoad();
}

function setOrder(column)
{

    // in case this gets mistaken for a mouse click
    if(column == getId('hiddenColumn').value)
    {
        switch(getId('hiddenOrder').value)
        {
            case 'ascend' :
                getId('hiddenOrder').value = 'descend';
                break;
            case 'descend' :
                getId('hiddenOrder').value = 'none';
                break;
            case 'none' :
            default :
                getId('hiddenOrder').value = 'ascend';
        }
    }
    else
    {
        getId('hiddenColumn').value = column;
    }
    submitFilters();
}

function getWatchPositions(dropList, Id, Name, type)
{
    var departmentId = dropList.options[dropList.selectedIndex].value;
    getId('Apply').disabled = true;
    dropList.nextSibling.innerHTML = pulserBar;
    if(typeof(Id) == 'null')
    {
        Id ='';
    }
    else
    {
        Id = 'posId='+Id;
    }

    if(typeof(Name) == 'null')
    {
        Name = '';
    }
    else
    {
        Name = 'posName='+Name;
    }

    globAjax.onreadystatechange=function()
    {
        if(globAjax.readyState == 4)
        {
            dropList.nextSibling.innerHTML = globAjax.responseText;
            getId('Apply').disabled = false;
        }
    };

    type = '&type='+type;

    // unfortunately, this function cannot run asynchonosly :'(
    globAjax.open('GET', httpPath + 'getFunction/getWatchPositions.php?departmentId=' + departmentId + '&' + Name+ '&' + Id + type, true);
    globAjax.send(null);
}

function checkPassTwo()
{
    if(getId('passOne').value == getId('passTwo').value)
    {
        var ajaxObj = buildAjax();
        ajaxObj.onreadystatechange=function()
        {
            if(ajaxObj.readyState == 4)
            {
                alert(httpPath+"ajax/checkPassword.php?password="+ encodeURIComponent(getId('passTwo').value));
                if(ajaxObj.responseText == 'malformed')
                {
                    displayError('Password is not valid', 'passTwo');
                }
                else if(ajaxObj.responseText == 'ok')
                {
                    hideError('passTwo');
                    getId('employerForm').submit();
                }
            }
        };

        // unfortunately, this function cannot run asynchonosly :'(
        ajaxObj.open('GET', httpPath+"ajax/checkPassword.php?password="+ encodeURIComponent(getId('passTwo').value), true);
        ajaxObj.send(null);
    }
    else
    {
        displayError('Passwords do not Match', 'passTwo');
    }
}

function getSeekerEmployerProfile(employerId, buttons, cell)
{
    if(getId('containSeeker'))
    {
        document.removeChild(getId('containSeeker'));
    }

    // we must set this to have access to it later.
    if(getId('hdnValue') != null)
    {
        getId('hdnValue').value = employerId;
    }

    openLoad();
    openCssWindow(employerId, cell);

    var innerWindow = document.createElement('div');
    innerWindow.setAttribute('class', 'jobView');
    innerWindow.className = 'jobView';
    
    var container = document.createElement('div');
    container.setAttribute('class', 'cssWindowContainer');
    container.className = 'cssWindowContainer';
    container.setAttribute('id', 'containEmployer');
    container.appendChild(innerWindow);

    var actionTable = document.createElement('div');
    actionTable.setAttribute('id', 'actionButtons');
    for(var i = 0; i < buttons.length; i++)
    {
        actionTable.appendChild(buttons[i]);
    }
    container.appendChild(actionTable);

    globAjax.onreadystatechange=function()
    {
        if(globAjax.readyState == 4)
        {
            innerWindow.innerHTML = globAjax.responseText;
            // this is set here so that the innerWindow.innerHTML won't over write the buttons
            innerWindow.appendChild(actionTable);
            closeCssWindow();
            document.body.appendChild(container);
        }
    }
    globAjax.open('GET', httpPath + 'Seekers/dispEmployerProf.php?employerId='+employerId, true);
    globAjax.send(null);
}

function getSeekerJobView(jobId, buttons, cell)
{
    if(getId('containSeeker'))
    {
        document.removeChild(getId('containSeeker'));
    }

    // we must set this to have access to it later.
    if(getId('hdnValue') != null)
    {
        getId('hdnValue').value = jobId;
    }

    openLoad();
    openCssWindow(jobId, cell);

    var innerWindow = document.createElement('div');
    innerWindow.setAttribute('class', 'jobView');
    innerWindow.className = 'jobView';

    var container = document.createElement('div');
    container.setAttribute('class', 'cssWindowContainer');
    container.className = 'cssWindowContainer';
    
    container.setAttribute('id', 'containJob');
    container.appendChild(innerWindow);

    var actionTable = document.createElement('div');
    actionTable.setAttribute('id', 'actionButtons');
    for(var i = 0; i < buttons.length; i++)
    {
        actionTable.appendChild(buttons[i]);
    }
    container.appendChild(actionTable);

    globAjax.onreadystatechange=function()
    {
        if(globAjax.readyState == 4)
        {
            innerWindow.innerHTML = globAjax.responseText;
            // this is set here so that the innerWindow.innerHTML won't over write the buttons
            innerWindow.appendChild(actionTable);
            closeCssWindow();
            document.body.appendChild(container);
        }
    }
    globAjax.open('GET', httpPath + 'Seekers/viewJob.php?jobId='+ jobId, true);
    globAjax.send(null);
}

function sendRes(jobId, row)
{
    openLoad();
    openCssWindow();
    var ajaxObj = buildAjax();
    var url =   httpPath+'ajax/addCandidate.php?jobId='+ jobId;
    var val = this.value;
    this.value = 'Loading...';
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            var errorMsg = '';
            if(ajaxObj.responseText == 'Success')
            {
                closeLoad();
                closeCssWindow();
                row.parentNode.deleteRow(row.rowIndex);
                errorMsg = 'Success!';
            }
            else if(ajaxObj.responseText == 'Not_Approved')
            {
                closeLoad();
                closeCssWindow();
                errorMsg = 'Resume Needs Approval';
            }
            else
            {
                closeLoad();
                closeCssWindow();
                errorMsg = 'System Error: ' + ajaxObj.responseText;
            }
            this.value = val;
            document.body.appendChild(createErrorBox(errorMsg));
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET',url, true);
    ajaxObj.send(null);
}

/**
 *
 */
function changeEmployJobDpt(select, posName, posId)
{
    var ajaxObj = buildAjax();
    var value = select.options[select.selectedIndex].value;
    select.nextSibling.innerHTML = pulserBar;
    ajaxObj.onreadystatechange=function()
    {
        if(ajaxObj.readyState == 4)
        {
            select.nextSibling.innerHTML = ajaxObj.responseText;
        }
    };

    // unfortunately, this function cannot run asynchonosly :'(
    ajaxObj.open('GET',httpPath + 'getFunction/getEmployerJobPos.php?jobId='+ value +'&id='+ posId+'&name='+posName, true);
    ajaxObj.send(null);
}
