﻿function searchWithForm(strCategoryElementID, strLocationElementID, strSalaryElementID, strContractTypeElementID, strHoursElementID) {

    var ddl_Category = document.getElementById(strCategoryElementID);
    var ddl_Location = document.getElementById(strLocationElementID);
    var ddl_Salary = document.getElementById(strSalaryElementID);
    var ddl_ContractType = document.getElementById(strContractTypeElementID)
    var ddl_Hours = document.getElementById(strHoursElementID)
    
    var strCategory = ddl_Category.options[ddl_Category.selectedIndex].value;
    var strLocation = ddl_Location.options[ddl_Location.selectedIndex].value;
    
    var strSalary;
    if (ddl_Salary != null) {
        strSalary = ddl_Salary.options[ddl_Salary.selectedIndex].value;
    }
    
    var strContractType;
    if (ddl_ContractType != null) {
        strContractType = ddl_ContractType.options[ddl_ContractType.selectedIndex].value;
    }
    
    var strHours;
    if (ddl_Hours != null) {
        strHours = ddl_Hours.options[ddl_Hours.selectedIndex].value;
    }
    
    search(strCategory, strLocation, strSalary, strContractType, strHours);
    
}

function search(strCategory, strLocation, strSalary, strContractType, strHours) {
    var strURL = '/' + strLocation + '/' + strCategory + '.html';
    
    var strQuery = '';
    
    if (strSalary != null && strSalary.length > 0) {
        if (strQuery.length == 0) strQuery = '?';
        else strQuery += '&';
        strQuery += 'salary=' + strSalary;
    }
      
    if (strContractType != null && strContractType.length > 0) {
        if (strQuery.length == 0) strQuery = '?';
        else strQuery += '&';
        strQuery += 'contract=' + strContractType;
    }
        
    if (strHours != null && strHours.length > 0) {
        if (strQuery.length == 0) strQuery = '?';
        else strQuery += '&';
        strQuery += 'fulltime=' + strHours;
    }
      
    top.location = strURL + strQuery;
}

function JumpToPage(intPage) {
    var strOldLocation;
    strOldLocation = new String(top.location);
    strOldLocation = strOldLocation.replace(/&page=\d*/,'&page=' + intPage);
    strOldLocation = strOldLocation.replace(/\?page=\d*/,'?page=' + intPage);
    if (strOldLocation.indexOf('page=') == -1) {
        if (strOldLocation.indexOf('?') == -1) {
            strOldLocation += '?page=' + intPage;
        } else {
            strOldLocation += '&page=' + intPage;
        }
    }
    top.location = strOldLocation;
}
