/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
var mustTerm = new Array();
var mayTerm = new Array();
var notTerm = new Array();
function trim(inputString) {
// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
if (typeof inputString != "string") { return inputString; }
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") { // Check for spaces at the beginning of the string
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") { // Check for spaces at the end of the string
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings
}
return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
function init()
{
var kwdCookie = GetCookie( 'kwds' );
var locCookie = GetCookie( 'loc' );
if (kwdCookie != null)
{
if (kwdCookie != '')
{
var kwdList = CookieToList( kwdCookie );
var dest = document.getElementById( 'wizard_display_keywords' );
for (i = 0; i < kwdList.length ; i++ )
{
dest.options[ dest.options.length ] = new Option(kwdList[ i ][ 1 ], kwdList[ i ][ 0 ]);
var kwdCondition = kwdList[ i ][ 1 ];
var conditions = kwdCondition.split(':');
switch ( conditions[0] )
{
case 'Must Have':
mustTerm[ mustTerm.length ] = trim( conditions[1] );
break;
case 'May Have':
mayTerm[ mayTerm.length ] = trim( conditions[1] );
break;
case 'Must Not Have':
notTerm[ notTerm.length ] = trim( conditions[1] );
break;
}
}
}
}
if (locCookie != null)
{
if (locCookie != '')
{
var locList = CookieToList( locCookie );
var dest = document.getElementById( 'wizard_location_display' );
for (i = 0; i < locList.length ; i++ )
{
dest.options[ dest.options.length ] = new Option(locList[ i ][ 0 ], locList[ i ][ 1 ]);
dest.options[ dest.options.length - 1 ].id = locList[ i ][ 2 ];
}
}
drawLocationsSelect( 'wizard_location_display' );
}
}
function AddTerm( source, destination, type )
{
var src = document.getElementById( source );
var dest = document.getElementById( destination );
var mayCode = "| ";
var notCode = "- ";
var url = 'advanced_search_ajax.php?term_action=add&';
if (src.value != '')
{
var term = quotePhrases( src.value );
switch ( type )
{
case 'must':
mustTerm[ mustTerm.length ] = term;
dest.options[ dest.options.length ] = new Option( wizard_must_have + term, term );
url = url + 'value='+term.replace(/\+/g,"_plus_sign_")+'&inner='+wizard_must_have + term.replace(/\+/g,"_plus_sign_");
break;
case 'may':
mayTerm[ mayTerm.length ] = term;
dest.options[ dest.options.length ] = new Option( wizard_may_have + term, mayCode + term.replace(/\+/g,"_plus_sign_") );
url = url + 'value='+mayCode + term.replace(/\+/g,"_plus_sign_")+'&inner='+wizard_may_have + term.replace(/\+/g,"_plus_sign_");
break;
case 'not':
notTerm[ notTerm.length ] = term;
dest.options[ dest.options.length ] = new Option( wizard_must_not_have + term, notCode + term.replace(/\+/g,"_plus_sign_") );
url = url + 'value='+notCode + term.replace(/\+/g,"_plus_sign_")+'&inner='+wizard_must_not_have + term.replace(/\+/g,"_plus_sign_");
break;
}
src.value = '';
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updatePage;
// Send the request
xmlHttp.send(null);
}
else
{
alert( wizard_keywords_add_error );
}
}
function RemoveTerm( src )
{
var idx = src.selectedIndex;
clearArray(mustTerm, src.options[idx].value);
clearArray(mayTerm, src.options[idx].value);
clearArray(notTerm, src.options[idx].value);
var url = 'advanced_search_ajax.php?term_action=remove&value='+src.options[idx].value.replace(/\+/g,"_plus_sign_");
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updatePage;
// Send the request
xmlHttp.send(null);
src.options[ idx ] = null;
}
function ParseLocations( targetDiv )
{
var dest = document.getElementById( 'wizard_location_display' );
var editSpace = document.getElementById( targetDiv );
if (dest.options.length > 0)
{
var i;
for (i = 0; i < dest.options.length ; i++ )
{
//document.forms[0].elements[ document.forms[0].elements.length ] = new Input();
//document.forms[0].elements[ document.forms[0].elements.length ].type = 'hidden';
//document.forms[0].elements[ document.forms[0].elements.length ].name = 'locations[]';
//document.forms[0].elements[ document.forms[0].elements.length ].value = dest.options[ i ].value;
editSpace.innerHTML = editSpace.innerHTML + "";
}
}
else
{
//document.forms[0].elements[ document.forms[0].elements.length ] = new Hidden('locations[]', '');
editSpace.innerHTML = editSpace.innerHTML + "";
}
}
function ParseKeywords()
{
var keywords = '';
if ( mustTerm.length > 0 )
{
var i;
var j = 0;
for (i = 0; i < mustTerm.length ; i++ )
{
keywords = keywords + mustTerm[i];
if (j < (mustTerm.length - 1))
{
keywords = keywords + ' AND ';
}
j++;
}
}
if ( mayTerm.length > 0 )
{
var i;
for (i=0 ; i < mayTerm.length ; i++ )
{
var k;
var innerkeywords = '';
for (k = 0; k < mustTerm.length ; k++ )
{
innerkeywords = innerkeywords + ' AND (' + mustTerm[k] + ' OR ' + mayTerm[i] + ')';
}
keywords = keywords + innerkeywords;
}
}
if ( notTerm.length > 0 )
{
var i;
for (i=0 ; i < notTerm.length ; i++ )
{
keywords = keywords + ' NOT ' + notTerm[i];
}
}
var keywrds = document.getElementById('keywords');
keywrds.value = keywords.replace(/\+/g,"_plus_sign_");
}
function JumpOption(src, action)
{
var movedId;
var movedLabel;
var idx = src.selectedIndex;
movedId = src.options[ idx ].id;
movedValue = src.options[ idx ].value;
movedLabel = src.options[ idx ].text;
var url = 'advanced_search_ajax.php?movedId='+movedId+'&movedValue='+movedValue+'&movedLabel='+movedLabel;
switch ( action )
{
case 'add':
var dest = document.getElementById( 'wizard_location_display' );
src.options[ idx ] = null;
dest.options[ dest.options.length ] = new Option( movedLabel, movedValue );
dest.options[ dest.options.length - 1 ].id = movedId;
url = url + '&action=add';
break;
case 'remove':
var dest = document.getElementById( 'wizard_location_display' );
dest.options[ idx ] = null;
drawLocationsSelect('wizard_location_display');
url = url + '&action=remove';
break;
}
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updatePage;
// Send the request
xmlHttp.send(null);
}
function SetSession(kwdselect, locselect)
{
var keywordsSelect = document.getElementById( kwdselect );
var locationsSelect = document.getElementById( locselect );
var keywordsCookie = '';
var locationsCookie = '';
for (i = 0 ; i < keywordsSelect.options.length ; i++ )
{
keywordsCookie = keywordsCookie + keywordsSelect.options[ i ].value + '|' + keywordsSelect.options[ i ].text ;
if ( i < keywordsSelect.options.length -1)
{
keywordsCookie = keywordsCookie + ',';
}
}
keywordsCookie.replace(/\+/g,"_plus_sign_");
for (i = 0 ; i < locationsSelect.options.length ; i++ )
{
locationsCookie = locationsCookie + locationsSelect.options[ i ].text + '|' + locationsSelect.options[ i ].value + '|' + locationsSelect.options[ i ].id;
if ( i < locationsSelect.options.length -1)
{
locationsCookie = locationsCookie + ',';
}
}
document.cookie = "kwds="+escape(keywordsCookie);
document.cookie = "loc="+escape(locationsCookie);
}
function ValidateSelects()
{
var ageselect = document.getElementById('wizard_filter_date_select');
var jobtypeselect = document.getElementById('wizard_filter_jobtype_select');
var sortbyselect = document.getElementById('wizard_filter_sortby_select');
if (ageselect.value == 'x')
{
ageselect.value = 0;
}
if (jobtypeselect.value == 'x')
{
jobtypeselect.value = 0;
}
if (sortbyselect.value == 'x')
{
sortbyselect.value = 1;
}
}
function ValidateSelectsJBE()
{
var jobtypeselect = document.getElementById('wizard_filter_jobtype_select');
if (jobtypeselect.value == 'x')
{
jobtypeselect.value = 0;
}
}
function CheckEmail()
{
var emailfield = document.getElementById('wizard_email_input');
var errorspan = document.getElementById('wizard_email_error_span');
var emailposted = emailfield.value;
if ( emailposted == '')
{
errorspan.className = 'wizard_email_error_span_visible';
return false;
}
else
{
var emailpattern = /^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/;
return emailpattern.test(emailposted);
}
}
function drawLocationsSelect( name )
{
var selectedList = document.getElementById( name );
var selectedListLength = selectedList.options.length;
var omitList = new Array();
var i, j, k, m, n;
var found;
for (i = 0; i < selectedListLength ; i++ )
{
omitList[ i ] = selectedList.options[ i ].id;
}
// var debug = dumpArray( omitList );
// alert( debug );
var choiceList = document.getElementById( 'wizard_location_select' );
var choiceListLength = choiceList.options.length;
for (i = 0; i < choiceListLength; i++)
{
choiceList.options[0] = null;
}
k = 0;
for (i = 0; i < LocationsKeys.length; i++)
{
found = false;
for (m = 0; m < omitList.length; m++)
{
if (omitList[m] == "Locations[" + i + "][0][0]" )
{
found = true;
break;
}
}
if (found == false)
{
choiceList.options[k] = new Option( LocationsKeys[i], Locations[i][0][1] );
choiceList.options[k].id = "Locations[" + i + "][0][0]";
k++;
}
for (j = 1; j < Locations[i].length; j++)
{
found = false;
for (n = 0; n < omitList.length; n++)
{
if (omitList[n] == "Locations[" + i + "][" + j + "][1]" )
{
found = true;
break;
}
}
if (found == false)
{
choiceList.options[k] = new Option( "-- " + Locations[i][j][0], Locations[i][j][1] );
choiceList.options[k].id = "Locations[" + i + "][" + j + "][1]";
k++;
}
}
}
}
/*function drawLocationsSelectKP( name )
{
var selectedList = document.getElementById( name );
var selectedListLength = selectedList.options.length;
var omitList = new Array();
var i, j, k, m, n;
var found;
for (i = 0; i < selectedListLength ; i++ )
{
omitList[ i ] = selectedList.options[ i ].id;
}
//var debug = dumpArray( omitList );
//alert( debug );
var choiceList = document.getElementById( 'wizard_location_select' );
var choiceListLength = choiceList.options.length;
for (i = 0; i < choiceListLength; i++)
{
choiceList.options[0] = null;
}
k = 0;
for (i = 0; i < LocationsKeys.length; i++)
{
found = false;
for (m = 0; m < omitList.length; m++)
{
if (omitList[m] == "Locations[" + i + "][0][0]" )
{
found = true;
break;
}
}
if (found == false)
{
choiceList.options[k] = new Option( LocationsKeys[i], Locations[i][0][1] );
choiceList.options[k].id = "Locations[" + i + "][0][0]";
k++;
}
for (j = 1; j < Locations[i].length; j++)
{
found = false;
for (n = 0; n < omitList.length; n++)
{
if (omitList[n] == "Locations[" + i + "][" + j + "][1]" )
{
found = true;
break;
}
}
if (found == false)
{
choiceList.options[k] = new Option( "-- " + Locations[i][j][0], Locations[i][j][1] );
choiceList.options[k].id = "Locations[" + i + "][" + j + "][1]";
k++;
}
}
}
}
*/
function CheckEmailType()
{
if (document.forms[0].emailtype.value == 2)
{
document.forms[0].emailtype.value = 1;
}
}
function clearArray( keywordsarray, keyword )
{
var i = 0;
for (i=0; i < keywordsarray.length ; i++ )
{
if (keywordsarray[i] == keyword)
{
keywordsarray.splice(i, 1);
}
}
}
function CookieToList( cookie )
{
var output = new Array();
var preOutput = cookie.split(',');
for (i = 0; i < preOutput.length ; i++ )
{
output[ i ] = preOutput[ i ].split('|');
}
return output;
}
function quotePhrases( phrase )
{
var words = phrase.split(/\s+/);
if (words.length > 1)
{
var returnPhrase = '"';
for ( i=0 ; i < words.length ; i++ )
{
if (i == (words.length -1))
{
returnPhrase = returnPhrase + words[ i ];
}
else
{
returnPhrase = returnPhrase + words[ i ] + ' ';
}
}
returnPhrase = returnPhrase + '"';
return returnPhrase;
}
else
{
return phrase;
}
}
function dumpArray( keywordsarray )
{
var i;
var output = '';
for(i = 0; i < keywordsarray.length; i++)
{
output = output + keywordsarray[i] + ',';
}
return output;
}
function updatePage() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
//alert(response);
}
}